]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/fault_handlers/trap_observer.cc
cff0e1953b9c9d9ab0949d23e506d198bcd49944
[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 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::App_model *a)
29 {
30         if (t->vcpu()->r()->trapno == 6) {
31                 enter_kdebug("invalid opcode");
32         }
33
34         if (!entry_reason_is_int3(t->vcpu(), inst, a)) {
35                 return Romain::Observer::Ignored;
36         }
37
38         // address is already 1 _behind_ the INT3 opcode
39         l4_addr_t local = a->rm()->remote_to_local(t->vcpu()->r()->ip, inst->id());
40         unsigned op = *(unsigned char*)local;
41
42         switch(op) {
43                 case 0xEB: // jmp -> enter_kdebug(text)
44                         {
45                                 unsigned len = *(unsigned char*)(local+1);
46                                 char strbuf[len+1];
47                                 memcpy(strbuf, (unsigned char*)local+2, len);
48                                 strbuf[len] = 0;
49                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << strbuf;
50                                 enter_kdebug("enter_kdebug issued");
51
52 #if 0
53                                 DEBUG() << std::hex << t->vcpu()->r()->ip;
54                                 t->vcpu()->r()->ip += len;
55                                 t->vcpu()->r()->ip += 2;
56                                 DEBUG() << std::hex << t->vcpu()->r()->ip;
57 #endif
58                                 //t->vcpu()->r()->ip -= 1;
59                         }
60                         break;
61                 case 0x3C: // outhex() & co.
62                         {
63                                 unsigned char out_op = *(unsigned char*)(local+1);
64                                 switch(out_op) {
65                                         case 0: // outchar
66                                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << (char)(t->vcpu()->r()->ax & 0xFF);
67                                                 break;
68                                         case 2: // outstring
69                                                 {
70                                                         char buf[80];
71                                                         snprintf(buf, 80, "%s", (char*)a->rm()->remote_to_local(t->vcpu()->r()->ax, inst->id()));
72                                                         INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << buf;
73                                                         if (buf[strlen(buf)-1] == '\n') {
74                                                                 enter_kdebug("jdb newline");
75                                                         }
76                                                 }
77                                                 break;
78                                         case 5: // outhex32
79                                                 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << std::hex << t->vcpu()->r()->ax;
80                                                 break;
81                                         default: 
82                                                 ERROR() << "unhandled out op: " << std::hex << (int)out_op;
83                                                 break;
84                                 };
85                         }
86                         break;
87                 default:
88 #if 0
89                         ERROR() << "Unhandled JDB opcode: 0x" << std::hex << op;
90                         break;
91 #else
92                         return Romain::Observer::Ignored;
93 #endif
94         }
95
96         //enter_kdebug("int 3");
97         return Romain::Observer::Replicatable;
98 }