diff --git a/nemu/Makefile b/nemu/Makefile index a8bb52bb..f98275fc 100644 --- a/nemu/Makefile +++ b/nemu/Makefile @@ -100,7 +100,7 @@ GEN_EXPR_CMD := GEN_TEST_CASE := endif -$(BINARY): $(OBJS) +$(BINARY): $(OBJS) $(EXPR_FLAG) $(call git_commit, "compile") @echo + LD $@ @$(LD) -O2 -rdynamic $(SO_LDLAGS) -o $@ $^ $(LD_LIBS) diff --git a/nemu/include/rtl/pseudo.h b/nemu/include/rtl/pseudo.h index 2d01fbfc..03b1695d 100644 --- a/nemu/include/rtl/pseudo.h +++ b/nemu/include/rtl/pseudo.h @@ -1,6 +1,8 @@ #ifndef __RTL_PSEUDO_H__ #define __RTL_PSEUDO_H__ +#include + #ifndef __RTL_RTL_H__ #error "Should be only included by " #endif diff --git a/nemu/include/rtl/rtl.h b/nemu/include/rtl/rtl.h index b5bfa78f..33cd9a4c 100644 --- a/nemu/include/rtl/rtl.h +++ b/nemu/include/rtl/rtl.h @@ -1,84 +1,8 @@ #ifndef __RTL_RTL_H__ #define __RTL_RTL_H__ -#include - -// id_src1 id_src2 id_dest are the address of the operand objs. -#define id_src1 (&s->src1) -#define id_src2 (&s->src2) -#define id_dest (&s->dest) - -#define dsrc1 (id_src1->preg) -#define dsrc2 (id_src2->preg) -#define ddest (id_dest->preg) -#define s0 (&s->tmp_reg[0]) -#define s1 (&s->tmp_reg[1]) -#define s2 (&s->tmp_reg[2]) -#define t0 (&s->tmp_reg[3]) - -extern const rtlreg_t rzero; -#define rz (&rzero) - -#define def_rtl(name, ...) void concat(rtl_, name)(DecodeExecState *s, __VA_ARGS__) - -void rtl_exit(int state, vaddr_t halt_pc, uint32_t halt_ret); - -// relation operation -enum { - // +-- unsign - // | +-- sign - // | | +-- equal - // | | | +-- invert - // | | | | - RELOP_FALSE = 0 | 0 | 0 | 0, - RELOP_TRUE = 0 | 0 | 0 | 1, - RELOP_EQ = 0 | 0 | 2 | 0, - RELOP_NE = 0 | 0 | 2 | 1, - - RELOP_LT = 0 | 4 | 0 | 0, - RELOP_LE = 0 | 4 | 2 | 0, - RELOP_GT = 0 | 4 | 2 | 1, - RELOP_GE = 0 | 4 | 0 | 1, - - RELOP_LTU = 8 | 0 | 0 | 0, - RELOP_LEU = 8 | 0 | 2 | 0, - RELOP_GTU = 8 | 0 | 2 | 1, - RELOP_GEU = 8 | 0 | 0 | 1, -}; - +#include #include -//#include -static inline def_rtl(li, rtlreg_t* dest, const rtlreg_t imm) { - rtl_addi(s, dest, rz, imm); -} - -static inline def_rtl(mv, rtlreg_t* dest, const rtlreg_t *src1) { - if (dest != src1) rtl_add(s, dest, src1, rz); -} - -static inline def_rtl(not, rtlreg_t *dest, const rtlreg_t* src1) { - // dest <- ~src1 - TODO(); -} - -static inline def_rtl(neg, rtlreg_t *dest, const rtlreg_t* src1) { - // dest <- -src1 - TODO(); -} - -static inline def_rtl(sext, rtlreg_t* dest, const rtlreg_t* src1, int width) { - // dest <- signext(src1[(width * 8 - 1) .. 0]) - TODO(); -} - -static inline def_rtl(zext, rtlreg_t* dest, const rtlreg_t* src1, int width) { - // dest <- zeroext(src1[(width * 8 - 1) .. 0]) - TODO(); -} - -static inline def_rtl(msb, rtlreg_t* dest, const rtlreg_t* src1, int width) { - // dest <- src1[width * 8 - 1] - TODO(); -} +#include #endif diff --git a/nemu/include/rtl/rtl_.h b/nemu/include/rtl/rtl_.h new file mode 100644 index 00000000..042250aa --- /dev/null +++ b/nemu/include/rtl/rtl_.h @@ -0,0 +1,49 @@ +#ifndef __RTL_RTL__H__ +#define __RTL_RTL__H__ + +#include +#include + +#define id_src1 (&s->src1) +#define id_src2 (&s->src2) +#define id_dest (&s->dest) + +#define dsrc1 (id_src1->preg) +#define dsrc2 (id_src2->preg) +#define ddest (id_dest->preg) +#define s0 (&s->tmp_reg[0]) +#define s1 (&s->tmp_reg[1]) +#define s2 (&s->tmp_reg[2]) +#define t0 (&s->tmp_reg[3]) + +extern const rtlreg_t rzero; +#define rz (&rzero) + +#define def_rtl(name, ...) void concat(rtl_, name)(DecodeExecState *s, __VA_ARGS__) + +void rtl_exit(int state, vaddr_t halt_pc, uint32_t halt_ret); + +// relation operation +enum { + // +-- unsign + // | +-- sign + // | | +-- equal + // | | | +-- invert + // | | | | + RELOP_FALSE = 0 | 0 | 0 | 0, + RELOP_TRUE = 0 | 0 | 0 | 1, + RELOP_EQ = 0 | 0 | 2 | 0, + RELOP_NE = 0 | 0 | 2 | 1, + + RELOP_LT = 0 | 4 | 0 | 0, + RELOP_LE = 0 | 4 | 2 | 0, + RELOP_GT = 0 | 4 | 2 | 1, + RELOP_GE = 0 | 4 | 0 | 1, + + RELOP_LTU = 8 | 0 | 0 | 0, + RELOP_LEU = 8 | 0 | 2 | 0, + RELOP_GTU = 8 | 0 | 2 | 1, + RELOP_GEU = 8 | 0 | 0 | 1, +}; + +#endif diff --git a/nemu/src/isa/x86/exec/all-instr.h b/nemu/src/isa/x86/exec/all-instr.h index 523bb909..6a2c39ec 100644 --- a/nemu/src/isa/x86/exec/all-instr.h +++ b/nemu/src/isa/x86/exec/all-instr.h @@ -1,4 +1,5 @@ #include "../local-include/rtl.h" +#include "../local-include/decode.h" #include "arith.h" #include "control.h" diff --git a/nemu/src/isa/x86/exec/exec.c b/nemu/src/isa/x86/exec/exec.c index 10c3750b..4e0bfcc7 100644 --- a/nemu/src/isa/x86/exec/exec.c +++ b/nemu/src/isa/x86/exec/exec.c @@ -1,5 +1,4 @@ #include -#include "../local-include/decode.h" #include "all-instr.h" static inline void set_width(DecodeExecState *s, int width) { diff --git a/nemu/src/isa/x86/local-include/decode.h b/nemu/src/isa/x86/local-include/decode.h index 17287135..bae7ff92 100644 --- a/nemu/src/isa/x86/local-include/decode.h +++ b/nemu/src/isa/x86/local-include/decode.h @@ -1,5 +1,9 @@ -#include +#ifndef _X86_DECODE_H__ +#define _X86_DECODE_H__ + #include "rtl.h" +#include +#include "rtl/pseudo.h" void read_ModR_M(DecodeExecState *s, Operand *rm, bool load_rm_val, Operand *reg, bool load_reg_val); @@ -296,3 +300,5 @@ static inline void operand_write(DecodeExecState *s, Operand *op, rtlreg_t* src) else if (op->type == OP_TYPE_MEM) { rtl_sm(s, s->isa.mbase, s->isa.moff, src, op->width); } else { assert(0); } } + +#endif diff --git a/nemu/src/isa/x86/local-include/rtl.h b/nemu/src/isa/x86/local-include/rtl.h index 45f9c893..42e964b3 100644 --- a/nemu/src/isa/x86/local-include/rtl.h +++ b/nemu/src/isa/x86/local-include/rtl.h @@ -1,8 +1,9 @@ #ifndef __X86_RTL_H__ #define __X86_RTL_H__ -#include #include "reg.h" +#include +#include /* RTL pseudo instructions */