]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/fault_handlers/trap_observer.cc
update
[l4.git] / l4 / pkg / plr / server / src / fault_handlers / trap_observer.cc
1 /*
2  * trap_observer.cc --
3  *
4  *     Implementation of the observer handling all traps, e.g.,
5  *     system calls. Also, this observer handles Fiasco JDB
6  *     traps.
7  *
8  * (c) 2011-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
9  *     economic rights: Technische Universität Dresden (Germany)
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  */
14
15 #include "../app_loading"
16 #include "observers.h"
17
18 char const * const Romain::TrapObserver::jdb_out_prefix = "\033[32;1m";
19 char const * const Romain::TrapObserver::jdb_out_suffix = "\033[0m";
20
21 DEFINE_EMPTY_STARTUP(TrapObserver)
22
23 void Romain::TrapObserver::status() const { }
24
25 Romain::Observer::ObserverReturnVal
26 Romain::TrapObserver::notify(Romain::App_instance *inst,
27                              Romain::App_thread *t,
28                              Romain::Thread_group *tg,
29                              Romain::App_model *a)
30 {
31         if (t->vcpu()->r()->trapno == 6) {
32                 ERROR() << "Invalid opcode @ " << std::hex << t->vcpu()->r()->ip;
33                 enter_kdebug("invalid opcode");
34         }
35
36         if (!entry_reason_is_int3(t->vcpu(), inst, a)) {
37                 return Romain::Observer::Ignored;
38         }
39
40         // address is already 1 _behind_ the INT3 opcode
41         l4_addr_t local = a->rm()->remote_to_local(t->vcpu()->r()->ip, inst->id());
42         unsigned op = *(unsigned char*)local;
43
44         switch(op) {
45                 case 0xEB: // jmp -> enter_kdebug(text)
46                         {
47                                 unsigned len = *(unsigned char*)(local+1);
48                                 char strbuf[len+1];
49                                 memcpy(strbuf, (unsigned char*)local+2, len);
50                                 strbuf[len] = 0;
51                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << strbuf;
52                                 enter_kdebug("enter_kdebug issued");
53
54 #if 0
55                                 DEBUG() << std::hex << t->vcpu()->r()->ip;
56                                 t->vcpu()->r()->ip += len;
57                                 t->vcpu()->r()->ip += 2;
58                                 DEBUG() << std::hex << t->vcpu()->r()->ip;
59 #endif
60                                 //t->vcpu()->r()->ip -= 1;
61                         }
62                         break;
63                 case 0x3C: // outhex() & co.
64                         {
65                                 unsigned char out_op = *(unsigned char*)(local+1);
66                                 switch(out_op) {
67                                         case 0: // outchar
68                                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << (char)(t->vcpu()->r()->ax & 0xFF);
69                                                 break;
70                                         case 2: // outstring
71                                                 {
72                                                         char buf[80];
73                                                         snprintf(buf, 80, "%s", (char*)a->rm()->remote_to_local(t->vcpu()->r()->ax, inst->id()));
74                                                         INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << buf;
75                                                         if (buf[strlen(buf)-1] == '\n') {
76                                                                 enter_kdebug("jdb newline");
77                                                         }
78                                                 }
79                                                 break;
80                                         case 5: // outhex32
81                                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << std::hex << t->vcpu()->r()->ax;
82                                                 break;
83                                         default: 
84                                                 ERROR() << "unhandled out op: " << std::hex << (int)out_op;
85                                                 break;
86                                 };
87                         }
88                         break;
89                 default:
90 #if 0
91                         ERROR() << "Unhandled JDB opcode: 0x" << std::hex << op;
92                         break;
93 #else
94                         return Romain::Observer::Ignored;
95 #endif
96         }
97
98         //enter_kdebug("int 3");
99         return Romain::Observer::Replicatable;
100 }