> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.1.71 #1-NixOS SMP PREEMPT_DYNAMIC Fri Jan  5 14:18:41 UTC 2024 x86_64 GNU/Linux
 22:17:14  up 2 days 11:12,  2 users,  load average: 1.39, 0.69, 0.39
This commit is contained in:
tracer-ysyx 2024-01-15 22:17:14 +08:00 committed by xinyangli
parent f5cdb499b8
commit c995a80ce8
7 changed files with 815 additions and 4 deletions

11
nemu/.vscode/property.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"toolChain": "xilinx",
"prjName": {
"PL": "template"
},
"soc": {
"core": "none"
},
"enableShowLog": false,
"device": "none"
}

View file

@ -66,7 +66,8 @@ include $(NEMU_HOME)/tests/Makefile
all-tests: TEST_OBJS = $(filter-out $(OBJ_DIR)/src/nemu-main.o, $(OBJS))
all-tests: CFLAGS += $(shell pkg-config --cflags check)
all-tests: LDFLAGS += $(shell pkg-config --libs check)
all-tests: INC_PATH += $(NEMU_HOME)/src/isa/$(GUEST_ISA)/local-include
all-tests: $(TEST_SRCS:%.c=$(OBJ_DIR)/%)
test: $(addprefix $(OBJ_DIR), $(TEST_NAMES))
test: all-tests
@$(OBJ_DIR)/tests/expr_test

File diff suppressed because one or more lines are too long

View file

@ -36,5 +36,15 @@ void isa_reg_display() {
}
word_t isa_reg_str2val(const char *s, bool *success) {
assert(s);
int i;
for (i = 0; i < 32 && strcmp(s, regs[i]) != 0; i++)
;
if (i == 32) {
success = false;
return 0;
}
return gpr(i);
}

View file

@ -7,7 +7,7 @@
%%
$?[a-zA-Z]{2,3} { yylval = isa_reg_str2val(yytext, &success); if(!success) { return YYerror; } }
$$?[a-zA-Z]{2,3} { yylval = isa_reg_str2val(yytext + 1, &success); if(!success) { return YYerror; } }
0[xX][0-9a-fA-F]+ { yylval = strtoul(yytext, NULL, 16); return HEX_NUMBER; }
[0-9]+ { yylval = strtoul(yytext, NULL, 10); return NUMBER; }
[+\-*/()] { return *yytext; }

View file

@ -1,7 +1,7 @@
TEST_SRCS += tests/expr_test.c
YACC = bison
$(OBJ_DIR)/% %: %.c $(TEST_OBJS) app
$(OBJ_DIR)/%: %.c $(TEST_OBJS) app
@mkdir -p $(dir $@)
@echo + CC $<
@$(CC) $(CFLAGS) -o $@.o -c $<

View file

@ -1,3 +1,4 @@
#include "macro.h"
#include "sys/types.h"
#include <unistd.h>
#include <assert.h>
@ -9,6 +10,7 @@
#include <time.h>
#include <addrexp.h>
#include <addrexp_lex.h>
#include <reg.h>
char buf[65536] = {}, ref_buf[65536] = {};
static char code_buf[65536 + 128] = {}; // a little larger than `buf`
@ -162,6 +164,22 @@ START_TEST(test_expr_negative_operand) {
}
END_TEST
extern const char *regs[];
START_TEST(test_expr_plain_register) {
int i;
char buf[5] = {};
// NOTE: need to fix this if want to support more arch
buf[0] = '$';
for (i = 0; i < 32; i++) {
strcpy(buf + 1, regs[i]);
gpr(i) = i;
}
for (i = 1; i < 5; i++) {
buf[i] = '\0';
}
}
END_TEST
START_TEST(test_expr_register) {
yy_scan_string(reg_exprs[_i].expr);
uint32_t value;
@ -184,6 +202,8 @@ Suite *expr_suite(void) {
tcase_add_loop_test(tc_core, test_expr_random_100, 0, 20);
tcase_add_loop_test(tc_core, test_expr_negative_operand, 0,
sizeof(exprs) / sizeof(exprs[0]));
tcase_add_loop_test(tc_core, test_expr_plain_register, 0,
sizeof(reg_exprs) / sizeof(reg_exprs[0]));
tcase_add_loop_test(tc_core, test_expr_register, 0,
sizeof(reg_exprs) / sizeof(reg_exprs[0]));
suite_add_tcase(s, tc_core);