7 * Basic definition of an instruction emulator. Used
8 * by the framework to emulate memory write instructions.
10 * (c) 2011-2012 Björn Döbel <doebel@os.inf.tu-dresden.de>,
11 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
17 #include <l4/vcpu/vcpu>
22 * Address translation abstraction.
24 struct AddressTranslator
26 virtual l4_addr_t translate(l4_addr_t orig) const = 0;
27 virtual ~AddressTranslator() {}
30 struct IdentityTranslator : public AddressTranslator
32 virtual l4_addr_t translate(l4_addr_t orig) const { return orig; }
36 //#include "app_loading"
38 #include <libudis86/types.h>
39 #include <libudis86/extern.h>
40 #include <libudis86/itab.h>
51 InterruptFlag = 0x200,
52 DirectionFlag = 0x400,
63 Romain::AddressTranslator const * _translator;
64 l4_addr_t _local_ip; // XXX: abstraction fault
67 void value_to_operand(l4_umword_t val, ud_operand *op);
68 int offset_from_operand(ud_operand *op);
70 l4_umword_t register_to_value(ud_type op);
71 void value_to_register(l4_umword_t val, ud_type op);
74 virtual l4_addr_t ip() { return _vcpu->r()->ip; }
75 l4_addr_t local() { return _local_ip; }
76 l4_umword_t ilen() { return ud_insn_len(&_ud); }
79 l4_umword_t operand_to_value(ud_operand *op);
80 void write_target(l4_addr_t address, l4_umword_t value, l4_size_t size)
84 *(unsigned char*)address = (unsigned char)value;
87 *(unsigned short*)address = (unsigned short)value;
90 *(l4_umword_t*)address = value;
95 ERROR() << std::hex << address << ", "
96 << value << ", " << size << "\n";
103 Emulator_base(L4vcpu::Vcpu *, Romain::AddressTranslator const *);
105 Emulator_base() // XXX: needed?
106 : _vcpu(0), _translator(new IdentityTranslator()), _local_ip(0)
109 void print_instruction();
113 class InstructionPrinter : public Emulator_base
117 InstructionPrinter(l4_addr_t local, l4_addr_t remote)
125 virtual l4_addr_t ip() { return _remote; }
129 class WriteEmulator : public Emulator_base
139 enum ArithmeticOperations {
148 void handle_arithmetics(ArithmeticOperations o);
151 WriteEmulator(L4vcpu::Vcpu *vcpu,
152 Romain::AddressTranslator const *trans)
153 : Emulator_base(vcpu, trans)
157 void emulate(/*l4_addr_t remote_addr*/);