diff --git a/nemu/.config.old b/nemu/.config.old deleted file mode 100644 index 1a17e6e..0000000 --- a/nemu/.config.old +++ /dev/null @@ -1,74 +0,0 @@ -# -# Automatically generated file; DO NOT EDIT. -# NEMU Configuration Menu -# -# CONFIG_ISA_x86 is not set -# CONFIG_ISA_mips32 is not set -CONFIG_ISA_riscv=y -# CONFIG_ISA_loongarch32r is not set -CONFIG_ISA="riscv32" - -# -# ISA-dependent Options for riscv -# -# CONFIG_RV64 is not set -# CONFIG_RVE is not set -# end of ISA-dependent Options for riscv - -CONFIG_ENGINE_INTERPRETER=y -CONFIG_ENGINE="interpreter" -CONFIG_MODE_SYSTEM=y -CONFIG_TARGET_NATIVE_ELF=y -# CONFIG_TARGET_SHARE is not set -# CONFIG_TARGET_AM is not set - -# -# Build Options -# -CONFIG_CC_GCC=y -# CONFIG_CC_GPP is not set -# CONFIG_CC_CLANG is not set -CONFIG_CC="gcc" -# CONFIG_CC_O0 is not set -# CONFIG_CC_O1 is not set -CONFIG_CC_O2=y -# CONFIG_CC_O3 is not set -CONFIG_CC_OPT="-O2" -# CONFIG_CC_LTO is not set -# CONFIG_CC_DEBUG is not set -# CONFIG_CC_ASAN is not set -# end of Build Options - -# -# Testing and Debugging -# -CONFIG_TRACE=y -CONFIG_TRACE_START=0 -CONFIG_TRACE_END=10000 -CONFIG_ITRACE=y -CONFIG_ITRACE_COND="true" -# CONFIG_DIFFTEST is not set -CONFIG_DIFFTEST_REF_PATH="none" -CONFIG_DIFFTEST_REF_NAME="none" -# end of Testing and Debugging - -# -# Memory Configuration -# -CONFIG_MBASE=0x80000000 -CONFIG_MSIZE=0x8000000 -CONFIG_PC_RESET_OFFSET=0 -# CONFIG_PMEM_MALLOC is not set -CONFIG_PMEM_GARRAY=y -CONFIG_MEM_RANDOM=y -# end of Memory Configuration - -# CONFIG_DEVICE is not set - -# -# Miscellaneous -# -CONFIG_TIMER_GETTIMEOFDAY=y -# CONFIG_TIMER_CLOCK_GETTIME is not set -CONFIG_RT_CHECK=y -# end of Miscellaneous diff --git a/nemu/.gitignore b/nemu/.gitignore index 7faa353..77fe490 100644 --- a/nemu/.gitignore +++ b/nemu/.gitignore @@ -5,6 +5,7 @@ build/ .cache/ .direnv/ .config +.config.old .envrc compile_commands.json diff --git a/nemu/src/monitor/sdb/addrexp.y b/nemu/src/monitor/sdb/addrexp.y index 6aadc7a..3040872 100644 --- a/nemu/src/monitor/sdb/addrexp.y +++ b/nemu/src/monitor/sdb/addrexp.y @@ -1,3 +1,6 @@ +%code requires { + #include +} %{ #include #include @@ -10,7 +13,7 @@ %token NUMBER HEX_NUMBER %start input -%define api.value.type { uint32_t } +%define api.value.type { word_t } %parse-param { uint32_t *result } %left '-' '+' %left '*' '/' diff --git a/nemu/src/monitor/sdb/expr.c b/nemu/src/monitor/sdb/expr.c deleted file mode 100644 index 45d6483..0000000 --- a/nemu/src/monitor/sdb/expr.c +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************************** -* Copyright (c) 2014-2022 Zihao Yu, Nanjing University -* -* NEMU is licensed under Mulan PSL v2. -* You can use this software according to the terms and conditions of the Mulan PSL v2. -* You may obtain a copy of Mulan PSL v2 at: -* http://license.coscl.org.cn/MulanPSL2 -* -* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -* -* See the Mulan PSL v2 for more details. -***************************************************************************************/ - -#include - -/* We use the POSIX regex functions to process regular expressions. - * Type 'man regex' for more information about POSIX regex functions. - */ -#include - -enum { - TK_NOTYPE = 256, TK_EQ, TK_NUMBER, - LEX_GROUP_OPERATOR, LEX_GROUP_DIGIT -}; - -static struct rule { - const char *regex; - int token_type; -} rules[] = { - {"[ \t]+", TK_NOTYPE}, - {"==", TK_EQ}, - {"[0-9]+", LEX_GROUP_DIGIT}, - {"[\\+-*/()", LEX_GROUP_OPERATOR}, -}; - -#define NR_REGEX ARRLEN(rules) - -static regex_t re[NR_REGEX] = {}; - -/* Rules are used for many times. - * Therefore we compile them only once before any usage. - */ -void init_regex() { - int i; - char error_msg[128]; - int ret; - - for (i = 0; i < NR_REGEX; i ++) { - ret = regcomp(&re[i], rules[i].regex, REG_EXTENDED); - if (ret != 0) { - regerror(ret, &re[i], error_msg, 128); - panic("regex compilation failed: %s\n%s", error_msg, rules[i].regex); - } - } -} - -typedef struct token { - int type; - char str[32]; -} Token; - -static Token tokens[32] __attribute__((used)) = {}; -static int nr_token __attribute__((used)) = 0; - -static bool make_token(char *e) { - int position = 0; - int i; - regmatch_t pmatch; - - nr_token = 0; - - while (e[position] != '\0') { - /* Try all rules one by one. */ - for (i = 0; i < NR_REGEX; i ++) { - if (regexec(&re[i], e + position, 1, &pmatch, 0) == 0 && pmatch.rm_so == 0) { - char *substr_start = e + position; - int substr_len = pmatch.rm_eo; - - Log("match rules[%d] = \"%s\" at position %d with len %d: %.*s", - i, rules[i].regex, position, substr_len, substr_len, substr_start); - - position += substr_len; - - /* TODO: Now a new token is recognized with rules[i]. Add codes - * to record the token in the array `tokens'. For certain types - * of tokens, some extra actions should be performed. - */ - - switch (rules[i].token_type) { - case LEX_GROUP_OPERATOR: - tokens[nr_token].type = *substr_start; - tokens[nr_token].str[0] = '\0'; - nr_token++; - break; - case LEX_GROUP_DIGIT: - tokens[nr_token].type = TK_NUMBER; - nr_token++; - break; - case TK_NOTYPE: break; - default: TODO(); - } - - break; - } - } - - if (i == NR_REGEX) { - printf("no match at position %d\n%s\n%*.s^\n", position, e, position, ""); - return false; - } - } - - return true; -} - - -word_t expr(char *e, bool *success) { - if (!make_token(e)) { - *success = false; - return 0; - } - - /* TODO: Insert codes to evaluate the expression. */ - TODO(); - - return 0; -} diff --git a/nemu/src/monitor/sdb/sdb.h b/nemu/src/monitor/sdb/sdb.h index d2800d1..e94846c 100644 --- a/nemu/src/monitor/sdb/sdb.h +++ b/nemu/src/monitor/sdb/sdb.h @@ -18,6 +18,4 @@ #include -word_t expr(char *e, bool *success); - #endif diff --git a/nemu/test b/nemu/test deleted file mode 100755 index 74295cc..0000000 Binary files a/nemu/test and /dev/null differ diff --git a/nemu/test.c b/nemu/test.c deleted file mode 100644 index caaed92..0000000 --- a/nemu/test.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -int main() { - uint32_t result = (0xdU) * (31U / ((((0x45U)) - 75U)) * (0x41U) + 53U / (0xaU) - (0x50U)); - printf("%u", result); - return 0; -} -