4 * Implementation of the observer handling all traps, e.g.,
5 * system calls. Also, this observer handles Fiasco JDB
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.
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,
28 Romain::Thread_group *tg,
31 if (t->vcpu()->r()->trapno == 6) {
32 ERROR() << "Invalid opcode @ " << std::hex << t->vcpu()->r()->ip;
33 enter_kdebug("invalid opcode");
36 if (!entry_reason_is_int3(t->vcpu(), inst, a)) {
37 return Romain::Observer::Ignored;
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;
45 case 0xEB: // jmp -> enter_kdebug(text)
47 unsigned len = *(unsigned char*)(local+1);
49 memcpy(strbuf, (unsigned char*)local+2, len);
51 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << strbuf;
52 enter_kdebug("enter_kdebug issued");
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;
60 //t->vcpu()->r()->ip -= 1;
63 case 0x3C: // outhex() & co.
65 unsigned char out_op = *(unsigned char*)(local+1);
68 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << (char)(t->vcpu()->r()->ax & 0xFF);
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");
81 INFO() << TrapObserver::jdb_out_prefix << "JDB:" << TrapObserver::jdb_out_suffix << " " << std::hex << t->vcpu()->r()->ax;
84 ERROR() << "unhandled out op: " << std::hex << (int)out_op;
91 ERROR() << "Unhandled JDB opcode: 0x" << std::hex << op;
94 return Romain::Observer::Ignored;
98 //enter_kdebug("int 3");
99 return Romain::Observer::Replicatable;