4 * Implementation of the observer handling all traps, e.g.,
5 * system calls. Also, this observer handles Fiasco JDB
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.
15 #include "../app_loading"
16 #include "observers.h"
18 char const * const Romain::TrapObserver::jdb_out_prefix = "\033[32;1m";
19 char const * const Romain::TrapObserver::jdb_out_suffix = "\033[0m";
21 DEFINE_EMPTY_STARTUP(TrapObserver)
23 void Romain::TrapObserver::status() const { }
25 Romain::Observer::ObserverReturnVal
26 Romain::TrapObserver::notify(Romain::App_instance *inst,
27 Romain::App_thread *t,
30 if (t->vcpu()->r()->trapno == 6) {
31 enter_kdebug("invalid opcode");
34 if (!entry_reason_is_int3(t->vcpu(), inst, a)) {
35 return Romain::Observer::Ignored;
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;
43 case 0xEB: // jmp -> enter_kdebug(text)
45 unsigned len = *(unsigned char*)(local+1);
47 memcpy(strbuf, (unsigned char*)local+2, len);
49 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << strbuf;
50 enter_kdebug("enter_kdebug issued");
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;
58 //t->vcpu()->r()->ip -= 1;
61 case 0x3C: // outhex() & co.
63 unsigned char out_op = *(unsigned char*)(local+1);
66 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << (char)(t->vcpu()->r()->ax & 0xFF);
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");
79 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << std::hex << t->vcpu()->r()->ax;
82 ERROR() << "unhandled out op: " << std::hex << (int)out_op;
89 ERROR() << "Unhandled JDB opcode: 0x" << std::hex << op;
92 return Romain::Observer::Ignored;
96 //enter_kdebug("int 3");
97 return Romain::Observer::Replicatable;