Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nemu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions nemu/include/rtl/pseudo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __RTL_PSEUDO_H__
#define __RTL_PSEUDO_H__

#include <rtl/rtl.h>

#ifndef __RTL_RTL_H__
#error "Should be only included by <rtl/rtl.h>"
#endif
Expand Down
80 changes: 2 additions & 78 deletions nemu/include/rtl/rtl.h
Original file line number Diff line number Diff line change
@@ -1,84 +1,8 @@
#ifndef __RTL_RTL_H__
#define __RTL_RTL_H__

#include <cpu/decode.h>

// 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 <rtl/rtl_.h>
#include <rtl-basic.h>
//#include <rtl/pseudo.h>
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 <cpu/decode.h>

#endif
49 changes: 49 additions & 0 deletions nemu/include/rtl/rtl_.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef __RTL_RTL__H__
#define __RTL_RTL__H__

#include <common.h>
#include <cpu/decode.h>

#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
1 change: 1 addition & 0 deletions nemu/src/isa/x86/exec/all-instr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../local-include/rtl.h"
#include "../local-include/decode.h"

#include "arith.h"
#include "control.h"
Expand Down
1 change: 0 additions & 1 deletion nemu/src/isa/x86/exec/exec.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <cpu/exec.h>
#include "../local-include/decode.h"
#include "all-instr.h"

static inline void set_width(DecodeExecState *s, int width) {
Expand Down
8 changes: 7 additions & 1 deletion nemu/src/isa/x86/local-include/decode.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <cpu/exec.h>
#ifndef _X86_DECODE_H__
#define _X86_DECODE_H__

#include "rtl.h"
#include <cpu/exec.h>
#include "rtl/pseudo.h"

void read_ModR_M(DecodeExecState *s, Operand *rm, bool load_rm_val, Operand *reg, bool load_reg_val);

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion nemu/src/isa/x86/local-include/rtl.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef __X86_RTL_H__
#define __X86_RTL_H__

#include <rtl/rtl.h>
#include "reg.h"
#include <rtl/rtl.h>
#include <rtl/pseudo.h>

/* RTL pseudo instructions */

Expand Down