diff --git a/nemu/include/cpu/rtl.h b/nemu/include/cpu/rtl.h index 1e029edaa6d02beb432d24a851a7d54941ef5441..4dd9aac5131ac9768bad082e9e15d7e54648fde6 100644 --- a/nemu/include/cpu/rtl.h +++ b/nemu/include/cpu/rtl.h @@ -217,7 +217,7 @@ static inline void rtl_update_ZF(const rtlreg_t* result, int width) { // eflags.ZF <- is_zero(result[width * 8 - 1 .. 0]) RLIB_MACRO_DEBUG_ASSERT((unsigned)width < 5); static const uint32_t niddles [5] {0, 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff}; - cpu_eflags::get<cpu_eflags::ZF>() = (*result & niddles[width]); + cpu_eflags::get<cpu_eflags::ZF>() = !(*result & niddles[width]); } static inline void rtl_update_SF(const rtlreg_t* result, int width) { diff --git a/nemu/src/cpu/decode/decode.cc b/nemu/src/cpu/decode/decode.cc index ecd0665f7c24898bd243bad3f792cc5f6f233c0e..73aab67913feaad87d508f6ad4033a54db8b63b6 100644 --- a/nemu/src/cpu/decode/decode.cc +++ b/nemu/src/cpu/decode/decode.cc @@ -282,6 +282,8 @@ make_DHelper(a2O) { make_DHelper(J) { make_DopHelper_funcname(SI)(eip, id_dest, false); + rlib::println("debug: J decoder: id_dest=", *id_dest); + rtl_sext(&id_dest->imm, &id_dest->imm, id_dest->width); // the target address can be computed in the decode stage decoding.jmp_eip = id_dest->simm + *eip; } diff --git a/nexus-am/Makefile.compile b/nexus-am/Makefile.compile index ea0da9d5fe5bfd958993e06ca25971ac86a50d98..2b3409963624dd1a8f46aee74bd39a850b699e70 100644 --- a/nexus-am/Makefile.compile +++ b/nexus-am/Makefile.compile @@ -19,8 +19,8 @@ ISA_DEF = __ISA_$(shell echo $(ISA) | tr a-z A-Z)__ INCLUDES = $(addprefix -I, $(INC_DIR)) -I$(AM_HOME)/am/ INCLUDES += -I$(AM_HOME)/am/arch/$(ARCH)/include -CFLAGS += -std=gnu11 -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) -D$(ISA_DEF) -fno-builtin -CXXFLAGS += -std=c++11 -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) -D$(ISA_DEF) -fno-builtin +CFLAGS += -std=gnu11 -O2 -MMD -Wall -ggdb $(INCLUDES) -D$(ISA_DEF) -fno-builtin +CXXFLAGS += -std=c++11 -O2 -MMD -Wall -ggdb $(INCLUDES) -D$(ISA_DEF) -fno-builtin ASFLAGS += -MMD $(INCLUDES) -D$(ISA_DEF) ifeq ($(ISA), native) diff --git a/nexus-am/tests/cputest/tests/r.c b/nexus-am/tests/cputest/tests/r.c new file mode 100644 index 0000000000000000000000000000000000000000..ca756700f451a916b07f3f740e93a11657241c98 --- /dev/null +++ b/nexus-am/tests/cputest/tests/r.c @@ -0,0 +1,24 @@ +#include "trap.h" + +int add(int a, int b) { + int c = a + b; + return c; +} + +int test_data[] = {0, 1, 2}; +int ans[] = {0, 1, 2,1,2,3,2,3,4}; + +#define NR_DATA (sizeof(test_data) / sizeof(test_data[0])) + +int main() { + int i, j, ans_idx = 0; + for(i = 0; i < NR_DATA; i ++) { + for(j = 0; j < NR_DATA; j ++) { + nemu_assert(1); + } + nemu_assert(j == NR_DATA); + } + nemu_assert(i == NR_DATA); + + return 0; +}