Skip to content
Snippets Groups Projects
Verified Commit 5656f36c authored by Recolic Keghart's avatar Recolic Keghart
Browse files

> Manual commit: [DO NOT BUILD] debugging

U201614531
recolic
Linux RECOLICPC 5.4.2-arch1-1 #1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000 x86_64 GNU/Linux
 02:28:37 up 2 days,  7:36,  1 user,  load average: 1.26, 1.14, 0.98
891cd7f6081506f251fda067a38894cb71507ef
parent ea852ccb
No related branches found
No related tags found
No related merge requests found
...@@ -37,4 +37,6 @@ inline std::string num2hex(uint32_t n) { ...@@ -37,4 +37,6 @@ inline std::string num2hex(uint32_t n) {
return ss.str(); return ss.str();
} }
#include <rlib/stdio.hpp>
#endif #endif
...@@ -22,6 +22,10 @@ typedef struct { ...@@ -22,6 +22,10 @@ typedef struct {
char str[OP_STR_SIZE]; char str[OP_STR_SIZE];
} Operand; } Operand;
inline std::ostream & operator<< (std::ostream &os, const Operand &operand) {
return os << "Operand{type=" << operand.type << ",width=" << operand.width << ",union{reg/addr/imm/simm}=" << std::hex << operand.reg << ",val=" << operand.val << std::dec << ",str=" << operand.str << "}";
}
typedef struct { typedef struct {
uint32_t opcode; uint32_t opcode;
vaddr_t seq_eip; // sequential eip vaddr_t seq_eip; // sequential eip
......
...@@ -21,6 +21,10 @@ static inline void interpret_rtl_mv(rtlreg_t* dest, const rtlreg_t *src1) { ...@@ -21,6 +21,10 @@ static inline void interpret_rtl_mv(rtlreg_t* dest, const rtlreg_t *src1) {
*dest = *src1; *dest = *src1;
} }
// TODO: Optimize: change rtlreg_t* to rtlreg_t&, which barries the compiler optimization.
// TODO: Optimize: DO NOT use `at` register in `addi`/subi... instructions. It's unnecessarily slow.
#define make_rtl_arith_logic(name) \ #define make_rtl_arith_logic(name) \
static inline void concat(interpret_rtl_, name) (rtlreg_t* dest, const rtlreg_t* src1, const rtlreg_t* src2) { \ static inline void concat(interpret_rtl_, name) (rtlreg_t* dest, const rtlreg_t* src1, const rtlreg_t* src2) { \
*dest = concat(c_, name) (*src1, *src2); \ *dest = concat(c_, name) (*src1, *src2); \
...@@ -158,16 +162,20 @@ static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) { ...@@ -158,16 +162,20 @@ static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) {
TODO(); TODO();
} }
template <int OperandBytes>
static inline void rtl_push(const rtlreg_t* src1) { static inline void rtl_push(const rtlreg_t* src1) {
// esp <- esp - 4 // esp <- esp - 4
// M[esp] <- src1 // M[esp] <- src1
TODO(); rtl_subi(&cpu.esp, &cpu.esp, OperandBytes);
interpret_rtl_sm(&cpu.esp, src1, OperandBytes);
} }
template <int OperandBytes>
static inline void rtl_pop(rtlreg_t* dest) { static inline void rtl_pop(rtlreg_t* dest) {
// dest <- M[esp] // dest <- M[esp]
// esp <- esp + 4 // esp <- esp + 4
TODO(); interpret_rtl_lm(dest, &cpu.esp, OperandBytes);
rtl_addi(&cpu.esp, &cpu.esp, OperandBytes);
} }
static inline void rtl_setrelopi(uint32_t relop, rtlreg_t *dest, static inline void rtl_setrelopi(uint32_t relop, rtlreg_t *dest,
......
...@@ -9,4 +9,10 @@ ...@@ -9,4 +9,10 @@
#define concat4(x, y, z, w) concat3(concat(x, y), z, w) #define concat4(x, y, z, w) concat3(concat(x, y), z, w)
#define concat5(x, y, z, v, w) concat4(concat(x, y), z, v, w) #define concat5(x, y, z, v, w) concat4(concat(x, y), z, v, w)
#ifdef DEBUG
#define RLIB_MACRO_DEBUG_ASSERT(expr) assert(expr)
#else
#define RLIB_MACRO_DEBUG_ASSERT(expr)
#endif
#endif #endif
...@@ -42,7 +42,7 @@ static inline make_DopHelper(SI) { ...@@ -42,7 +42,7 @@ static inline make_DopHelper(SI) {
* *
op->simm = ??? op->simm = ???
*/ */
TODO(); op->simm = instr_fetch(eip, op->width);
rtl_li(&op->val, op->simm); rtl_li(&op->val, op->simm);
......
...@@ -6,3 +6,10 @@ make_EHelper(operand_size); ...@@ -6,3 +6,10 @@ make_EHelper(operand_size);
make_EHelper(inv); make_EHelper(inv);
make_EHelper(nemu_trap); make_EHelper(nemu_trap);
make_EHelper(ret);
make_EHelper(call);
make_EHelper(push);
make_EHelper(pop);
//make_EHelper();
//make_EHelper();
...@@ -26,13 +26,41 @@ make_EHelper(jmp_rm) { ...@@ -26,13 +26,41 @@ make_EHelper(jmp_rm) {
make_EHelper(call) { make_EHelper(call) {
// the target address is calculated at the decode stage // the target address is calculated at the decode stage
TODO(); const bool near = true;
if(near) {
if(decoding.is_operand_size_16) {
throw std::runtime_error("call operand size 16 not implemented.");
}
else {
// operand size 32b
rlib::println("debug: call touched.", std::hex);
rtl_push<4>(&cpu.eip);
rlib::println("debug: idsrc.val=", id_src->val, "eip from=", cpu.eip);
rtl_add(&cpu.eip, &cpu.eip, &id_src->val);
rlib::println("debug: idsrc.val=", id_src->val, "eip to=", cpu.eip);
}
}
// TODO: support far call
// TODO();
print_asm("call %x", decoding.jmp_eip); print_asm("call %x", decoding.jmp_eip);
} }
make_EHelper(ret) { make_EHelper(ret) {
TODO(); const bool near = true;
if(near) {
if(decoding.is_operand_size_16) {
throw std::runtime_error("call operand size 16 not implemented.");
}
else {
// operand size 32b
rtl_pop<4>(&cpu.eip);
}
rlib::println("debug: decoding.src=", decoding.src);
}
// TODO: support far ret
// TODO();
print_asm("ret"); print_asm("ret");
} }
......
...@@ -6,13 +6,29 @@ make_EHelper(mov) { ...@@ -6,13 +6,29 @@ make_EHelper(mov) {
} }
make_EHelper(push) { make_EHelper(push) {
TODO(); static_assert(sizeof(paddr_t) * 8 == 32);
if(decoding.is_operand_size_16) {
// 16b push
rtl_push<2>(&id_src->val);
}
else {
// 32b push
rtl_push<4>(&id_src->val);
}
print_asm_template1(push); print_asm_template1(push);
} }
make_EHelper(pop) { make_EHelper(pop) {
TODO(); static_assert(sizeof(paddr_t) * 8 == 32);
if(decoding.is_operand_size_16) {
// 16b
rtl_pop<2>(&id_src->val);
}
else {
// 32b
rtl_pop<4>(&id_src->val);
}
print_asm_template1(pop); print_asm_template1(pop);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
typedef struct { typedef struct {
DHelper decode; DHelper decode;
EHelper execute; EHelper execute;
int width; int width; // ByteWidth. If width is 0, using its default value: OperandSize (2Byte or 4Byte)
} opcode_entry; } opcode_entry;
#define IDEXW(id, ex, w) {make_DHelper_funcname(id), make_EHelper_funcname(ex), w} #define IDEXW(id, ex, w) {make_DHelper_funcname(id), make_EHelper_funcname(ex), w}
...@@ -120,7 +120,7 @@ opcode_entry opcode_table [512] = { ...@@ -120,7 +120,7 @@ opcode_entry opcode_table [512] = {
/* 0xb4 */ IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1), /* 0xb4 */ IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1), IDEXW(mov_I2r, mov, 1),
/* 0xb8 */ IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), /* 0xb8 */ IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov),
/* 0xbc */ IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), /* 0xbc */ IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov), IDEX(mov_I2r, mov),
/* 0xc0 */ IDEXW(gp2_Ib2E, gp2, 1), IDEX(gp2_Ib2E, gp2), EMPTY, EMPTY, /* 0xc0 */ IDEXW(gp2_Ib2E, gp2, 1), IDEX(gp2_Ib2E, gp2), IDEX(I, ret), EX(ret),
/* 0xc4 */ EMPTY, EMPTY, IDEXW(mov_I2E, mov, 1), IDEX(mov_I2E, mov), /* 0xc4 */ EMPTY, EMPTY, IDEXW(mov_I2E, mov, 1), IDEX(mov_I2E, mov),
/* 0xc8 */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xc8 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xcc */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xcc */ EMPTY, EMPTY, EMPTY, EMPTY,
...@@ -130,7 +130,7 @@ opcode_entry opcode_table [512] = { ...@@ -130,7 +130,7 @@ opcode_entry opcode_table [512] = {
/* 0xdc */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xdc */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xe0 */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xe0 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xe4 */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xe4 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xe8 */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xe8 */ IDEX(J, call), EMPTY, EMPTY, EMPTY,
/* 0xec */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xec */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xf0 */ EMPTY, EMPTY, EMPTY, EMPTY, /* 0xf0 */ EMPTY, EMPTY, EMPTY, EMPTY,
/* 0xf4 */ EMPTY, EMPTY, IDEXW(E, gp3, 1), IDEX(E, gp3), /* 0xf4 */ EMPTY, EMPTY, IDEXW(E, gp3, 1), IDEX(E, gp3),
......
...@@ -19,10 +19,12 @@ void paddr_write(paddr_t addr, uint32_t data, int len) { ...@@ -19,10 +19,12 @@ void paddr_write(paddr_t addr, uint32_t data, int len) {
memcpy(guest_to_host(addr), &data, len); memcpy(guest_to_host(addr), &data, len);
} }
// len is Bytes.
uint32_t vaddr_read(vaddr_t addr, int len) { uint32_t vaddr_read(vaddr_t addr, int len) {
return paddr_read(addr, len); return paddr_read(addr, len);
} }
// len is Bytes.
void vaddr_write(vaddr_t addr, uint32_t data, int len) { void vaddr_write(vaddr_t addr, uint32_t data, int len) {
paddr_write(addr, data, len); paddr_write(addr, data, len);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment