From f2231da199aae89c3356a6bd21623da8d3053a4e Mon Sep 17 00:00:00 2001 From: Zhou Yaoyang Date: Sun, 15 Nov 2020 17:02:31 +0800 Subject: [PATCH] Migrate to CPP --- Makefile | 11 ++- include/rtl/rtl.h | 1 + src/device/device.c | 2 +- src/device/keyboard.c | 93 ++++++++++++++++++- src/device/timer.c | 2 +- src/isa/riscv64/clint.c | 2 +- src/isa/riscv64/reg.c | 10 +- src/isa/riscv64/softfloat/platform.h | 3 +- src/isa/riscv64/softfloat/s_add128.c | 8 ++ src/isa/riscv64/softfloat/s_add256M.c | 8 ++ .../riscv64/softfloat/s_approxRecipSqrt32_1.c | 8 ++ .../riscv64/softfloat/s_countLeadingZeros16.c | 8 ++ .../riscv64/softfloat/s_countLeadingZeros32.c | 8 ++ .../riscv64/softfloat/s_countLeadingZeros64.c | 8 ++ src/isa/riscv64/softfloat/s_eq128.c | 8 ++ src/isa/riscv64/softfloat/s_le128.c | 8 ++ src/isa/riscv64/softfloat/s_lt128.c | 8 ++ src/isa/riscv64/softfloat/s_mul128By32.c | 8 ++ src/isa/riscv64/softfloat/s_mul128To256M.c | 8 ++ .../softfloat/s_mul64ByShifted32To128.c | 8 ++ src/isa/riscv64/softfloat/s_mul64To128.c | 8 ++ .../riscv64/softfloat/s_shiftRightJam128.c | 8 ++ .../softfloat/s_shiftRightJam128Extra.c | 8 ++ .../riscv64/softfloat/s_shiftRightJam256M.c | 8 ++ src/isa/riscv64/softfloat/s_shiftRightJam32.c | 8 ++ src/isa/riscv64/softfloat/s_shiftRightJam64.c | 8 ++ .../softfloat/s_shiftRightJam64Extra.c | 8 ++ .../riscv64/softfloat/s_shortShiftLeft128.c | 8 ++ .../riscv64/softfloat/s_shortShiftRight128.c | 8 ++ .../softfloat/s_shortShiftRightJam128.c | 8 ++ .../softfloat/s_shortShiftRightJam128Extra.c | 8 ++ .../softfloat/s_shortShiftRightJam64.c | 8 ++ src/isa/riscv64/softfloat/s_sub128.c | 8 ++ src/isa/riscv64/softfloat/s_sub256M.c | 8 ++ src/main.c | 5 + src/memory/paddr.c | 6 +- src/monitor/cpu-exec.c | 2 +- 37 files changed, 324 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 7be0bb30..f3bd8d0f 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ $(info Building $(ISA)-$(NAME)-$(ENGINE)) endif -INC_DIR += ./include ./src/engine/$(ENGINE) +INC_DIR += ./include ./src/engine/$(ENGINE) ./src/isa/riscv64/softfloat BUILD_DIR ?= ./build ifdef SHARE @@ -61,14 +61,14 @@ include Makefile.git .DEFAULT_GOAL = app # Compilation flags -CC = gcc -LD = gcc +CC = g++ +LD = g++ INCLUDES = $(addprefix -I, $(INC_DIR)) CFLAGS += -O2 -MMD -Wno-format -Wall \ -ggdb3 $(INCLUDES) \ -D__ENGINE_$(ENGINE)__ \ - -Wc++-compat \ -D__ISA__=$(ISA) -D__ISA_$(ISA)__ -D_ISA_H_=\"isa/$(ISA).h\" + # -Wc++-compat \ # Files to be compiled SRCS = $(shell find src/ -name "*.c" | grep -v "isa\|engine") @@ -80,7 +80,7 @@ OBJS = $(SRCS:src/%.c=$(OBJ_DIR)/%.o) $(OBJ_DIR)/isa/riscv64/softfloat/%.o: src/isa/riscv64/softfloat/%.c @mkdir -p $(dir $@) - @$(CC) $(CFLAGS) -w -fPIC -c -o $@ $< + @$(CC) $(CFLAGS) -D__cplusplus -w -fPIC -c -o $@ $< $(OBJ_DIR)/%.o: src/%.c @echo + CC $< @@ -106,6 +106,7 @@ NEMU_EXEC := $(BINARY) $(ARGS) $(IMG) $(BINARY): $(OBJS) $(call git_commit, "compile") @echo + LD $@ + @echo + LD inputs $^ @$(LD) -O2 -rdynamic $(SO_LDLAGS) -o $@ $^ -lSDL2 -lreadline -ldl run-env: $(BINARY) $(DIFF_REF_SO) diff --git a/include/rtl/rtl.h b/include/rtl/rtl.h index d551852e..5a479c9d 100644 --- a/include/rtl/rtl.h +++ b/include/rtl/rtl.h @@ -1,6 +1,7 @@ #ifndef __RTL_RTL_H__ #define __RTL_RTL_H__ +#include #include #define id_src1 (&s->src1) diff --git a/src/device/device.c b/src/device/device.c index c74937ab..8fe8da5f 100644 --- a/src/device/device.c +++ b/src/device/device.c @@ -60,7 +60,7 @@ void init_device() { init_i8042(); init_audio(); - add_alarm_handle(set_device_update_flag); + add_alarm_handle((void *)set_device_update_flag); init_alarm(); } #else diff --git a/src/device/keyboard.c b/src/device/keyboard.c index cee35824..5ed4e88c 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -6,7 +6,7 @@ #define I8042_DATA_MMIO 0xa1000060 #define KEYBOARD_IRQ 1 -static uint32_t *i8042_data_port_base = NULL; +static uint32_t *i8042_data_port_base = (uint32_t *) nullptr; // Note that this is not the standard #define _KEYS(f) \ @@ -26,9 +26,94 @@ enum { }; #define SDL_KEYMAP(k) [concat(SDL_SCANCODE_, k)] = concat(_KEY_, k), -static uint32_t keymap[256] = { - MAP(_KEYS, SDL_KEYMAP) -}; +static uint32_t keymap[256]; + +void init_keymap() { + + keymap[SDL_SCANCODE_ESCAPE] = _KEY_ESCAPE; + keymap[SDL_SCANCODE_F1] = _KEY_F1; + keymap[SDL_SCANCODE_F2] = _KEY_F2; + keymap[SDL_SCANCODE_F3] = _KEY_F3; + keymap[SDL_SCANCODE_F4] = _KEY_F4; + keymap[SDL_SCANCODE_F5] = _KEY_F5; + keymap[SDL_SCANCODE_F6] = _KEY_F6; + keymap[SDL_SCANCODE_F7] = _KEY_F7; + keymap[SDL_SCANCODE_F8] = _KEY_F8; + keymap[SDL_SCANCODE_F9] = _KEY_F9; + keymap[SDL_SCANCODE_F10] = _KEY_F10; + keymap[SDL_SCANCODE_F11] = _KEY_F11; + keymap[SDL_SCANCODE_F12] = _KEY_F12; + keymap[SDL_SCANCODE_GRAVE] = _KEY_GRAVE; + keymap[SDL_SCANCODE_1] = _KEY_1; + keymap[SDL_SCANCODE_2] = _KEY_2; + keymap[SDL_SCANCODE_3] = _KEY_3; + keymap[SDL_SCANCODE_4] = _KEY_4; + keymap[SDL_SCANCODE_5] = _KEY_5; + keymap[SDL_SCANCODE_6] = _KEY_6; + keymap[SDL_SCANCODE_7] = _KEY_7; + keymap[SDL_SCANCODE_8] = _KEY_8; + keymap[SDL_SCANCODE_9] = _KEY_9; + keymap[SDL_SCANCODE_0] = _KEY_0; + keymap[SDL_SCANCODE_MINUS] = _KEY_MINUS; + keymap[SDL_SCANCODE_EQUALS] = _KEY_EQUALS; + keymap[SDL_SCANCODE_BACKSPACE] = _KEY_BACKSPACE; + keymap[SDL_SCANCODE_TAB] = _KEY_TAB; + keymap[SDL_SCANCODE_Q] = _KEY_Q; + keymap[SDL_SCANCODE_W] = _KEY_W; + keymap[SDL_SCANCODE_E] = _KEY_E; + keymap[SDL_SCANCODE_R] = _KEY_R; + keymap[SDL_SCANCODE_T] = _KEY_T; + keymap[SDL_SCANCODE_Y] = _KEY_Y; + keymap[SDL_SCANCODE_U] = _KEY_U; + keymap[SDL_SCANCODE_I] = _KEY_I; + keymap[SDL_SCANCODE_O] = _KEY_O; + keymap[SDL_SCANCODE_P] = _KEY_P; + keymap[SDL_SCANCODE_LEFTBRACKET] = _KEY_LEFTBRACKET; + keymap[SDL_SCANCODE_RIGHTBRACKET] = _KEY_RIGHTBRACKET; + keymap[SDL_SCANCODE_BACKSLASH] = _KEY_BACKSLASH; + keymap[SDL_SCANCODE_CAPSLOCK] = _KEY_CAPSLOCK; + keymap[SDL_SCANCODE_A] = _KEY_A; + keymap[SDL_SCANCODE_S] = _KEY_S; + keymap[SDL_SCANCODE_D] = _KEY_D; + keymap[SDL_SCANCODE_F] = _KEY_F; + keymap[SDL_SCANCODE_G] = _KEY_G; + keymap[SDL_SCANCODE_H] = _KEY_H; + keymap[SDL_SCANCODE_J] = _KEY_J; + keymap[SDL_SCANCODE_K] = _KEY_K; + keymap[SDL_SCANCODE_L] = _KEY_L; + keymap[SDL_SCANCODE_SEMICOLON] = _KEY_SEMICOLON; + keymap[SDL_SCANCODE_APOSTROPHE] = _KEY_APOSTROPHE; + keymap[SDL_SCANCODE_RETURN] = _KEY_RETURN; + keymap[SDL_SCANCODE_LSHIFT] = _KEY_LSHIFT; + keymap[SDL_SCANCODE_Z] = _KEY_Z; + keymap[SDL_SCANCODE_X] = _KEY_X; + keymap[SDL_SCANCODE_C] = _KEY_C; + keymap[SDL_SCANCODE_V] = _KEY_V; + keymap[SDL_SCANCODE_B] = _KEY_B; + keymap[SDL_SCANCODE_N] = _KEY_N; + keymap[SDL_SCANCODE_M] = _KEY_M; + keymap[SDL_SCANCODE_COMMA] = _KEY_COMMA; + keymap[SDL_SCANCODE_PERIOD] = _KEY_PERIOD; + keymap[SDL_SCANCODE_SLASH] = _KEY_SLASH; + keymap[SDL_SCANCODE_RSHIFT] = _KEY_RSHIFT; + keymap[SDL_SCANCODE_LCTRL] = _KEY_LCTRL; + keymap[SDL_SCANCODE_APPLICATION] = _KEY_APPLICATION; + keymap[SDL_SCANCODE_LALT] = _KEY_LALT; + keymap[SDL_SCANCODE_SPACE] = _KEY_SPACE; + keymap[SDL_SCANCODE_RALT] = _KEY_RALT; + keymap[SDL_SCANCODE_RCTRL] = _KEY_RCTRL; + keymap[SDL_SCANCODE_UP] = _KEY_UP; + keymap[SDL_SCANCODE_DOWN] = _KEY_DOWN; + keymap[SDL_SCANCODE_LEFT] = _KEY_LEFT; + keymap[SDL_SCANCODE_RIGHT] = _KEY_RIGHT; + keymap[SDL_SCANCODE_INSERT] = _KEY_INSERT; + keymap[SDL_SCANCODE_DELETE] = _KEY_DELETE; + keymap[SDL_SCANCODE_HOME] = _KEY_HOME; + keymap[SDL_SCANCODE_END] = _KEY_END; + keymap[SDL_SCANCODE_PAGEUP] = _KEY_PAGEUP; + keymap[SDL_SCANCODE_PAGEDOWN] = _KEY_PAGEDOWN; + +} #define KEY_QUEUE_LEN 1024 static int key_queue[KEY_QUEUE_LEN] = {}; diff --git a/src/device/timer.c b/src/device/timer.c index a52ee81e..f90e5889 100644 --- a/src/device/timer.c +++ b/src/device/timer.c @@ -32,5 +32,5 @@ void init_timer() { rtc_port_base = (uint32_t *)new_space(16); add_pio_map("rtc", RTC_PORT, (uint8_t *)rtc_port_base, 16, rtc_io_handler); add_mmio_map("rtc", RTC_MMIO, (uint8_t *)rtc_port_base, 16, rtc_io_handler); - add_alarm_handle(timer_intr); + add_alarm_handle((void *)timer_intr); } diff --git a/src/isa/riscv64/clint.c b/src/isa/riscv64/clint.c index f659e159..30a9ca0f 100644 --- a/src/isa/riscv64/clint.c +++ b/src/isa/riscv64/clint.c @@ -27,5 +27,5 @@ static void clint_io_handler(uint32_t offset, int len, nemu_bool is_write) { void init_clint(void) { clint_base = (uint64_t *)new_space(0x10000); add_mmio_map("clint", CLINT_MMIO, (uint8_t *)clint_base, 0x10000, clint_io_handler); - add_alarm_handle(clint_intr); + add_alarm_handle((void *) clint_intr); } diff --git a/src/isa/riscv64/reg.c b/src/isa/riscv64/reg.c index 2b4b54bc..799281ec 100644 --- a/src/isa/riscv64/reg.c +++ b/src/isa/riscv64/reg.c @@ -63,13 +63,15 @@ rtlreg_t isa_reg_str2val(const char *s, nemu_bool *success) { rtlreg_t csr_array[4096] = {}; #define CSRS_DEF(name, addr) \ - concat(name, _t)* const name = (void *)&csr_array[addr]; + concat(name, _t)* const name = (concat(name, _t) *)&csr_array[addr]; MAP(CSRS, CSRS_DEF) -#define CSRS_EXIST(name, addr) [addr] = 1, -static nemu_bool csr_exist[4096] = { +static nemu_bool csr_exist[4096]; +#define CSRS_EXIST(name, addr) csr_exist[addr] = 1; + +void init_csr_exist() { MAP(CSRS, CSRS_EXIST) -}; +} static inline word_t* csr_decode(uint32_t addr) { assert(addr < 4096); diff --git a/src/isa/riscv64/softfloat/platform.h b/src/isa/riscv64/softfloat/platform.h index 03dd429f..f31e850e 100755 --- a/src/isa/riscv64/softfloat/platform.h +++ b/src/isa/riscv64/softfloat/platform.h @@ -38,11 +38,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *----------------------------------------------------------------------------*/ #define LITTLEENDIAN 1 -#define INLINE_LEVEL 5 +#define INLINE_LEVEL 0 #define SOFTFLOAT_FAST_INT64 #define SOFTFLOAT_FAST_DIV64TO32 /*---------------------------------------------------------------------------- *----------------------------------------------------------------------------*/ +// #define INLINE static inline #define INLINE static inline diff --git a/src/isa/riscv64/softfloat/s_add128.c b/src/isa/riscv64/softfloat/s_add128.c index 8065656a..fa360268 100755 --- a/src/isa/riscv64/softfloat/s_add128.c +++ b/src/isa/riscv64/softfloat/s_add128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_add128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_add128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) { @@ -51,5 +55,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_add256M.c b/src/isa/riscv64/softfloat/s_add256M.c index d07b0046..ea6baf1a 100755 --- a/src/isa/riscv64/softfloat/s_add256M.c +++ b/src/isa/riscv64/softfloat/s_add256M.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_add256M +#ifdef __cplusplus +extern "C" { +#endif + void softfloat_add256M( const uint64_t *aPtr, const uint64_t *bPtr, uint64_t *zPtr ) @@ -61,5 +65,9 @@ void } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_approxRecipSqrt32_1.c b/src/isa/riscv64/softfloat/s_approxRecipSqrt32_1.c index 2ab71a25..a0528d53 100755 --- a/src/isa/riscv64/softfloat/s_approxRecipSqrt32_1.c +++ b/src/isa/riscv64/softfloat/s_approxRecipSqrt32_1.c @@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extern const uint16_t softfloat_approxRecipSqrt_1k0s[]; extern const uint16_t softfloat_approxRecipSqrt_1k1s[]; +#ifdef __cplusplus +extern "C" { +#endif + uint32_t softfloat_approxRecipSqrt32_1( unsigned int oddExpA, uint32_t a ) { int index; @@ -69,5 +73,9 @@ uint32_t softfloat_approxRecipSqrt32_1( unsigned int oddExpA, uint32_t a ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_countLeadingZeros16.c b/src/isa/riscv64/softfloat/s_countLeadingZeros16.c index 950db6c8..c1923c0b 100755 --- a/src/isa/riscv64/softfloat/s_countLeadingZeros16.c +++ b/src/isa/riscv64/softfloat/s_countLeadingZeros16.c @@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define softfloat_countLeadingZeros16 softfloat_countLeadingZeros16 #include "primitives.h" +#ifdef __cplusplus +extern "C" { +#endif + uint_fast8_t softfloat_countLeadingZeros16( uint16_t a ) { uint_fast8_t count; @@ -56,5 +60,9 @@ uint_fast8_t softfloat_countLeadingZeros16( uint16_t a ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_countLeadingZeros32.c b/src/isa/riscv64/softfloat/s_countLeadingZeros32.c index fbf8ab6a..a32d34f6 100755 --- a/src/isa/riscv64/softfloat/s_countLeadingZeros32.c +++ b/src/isa/riscv64/softfloat/s_countLeadingZeros32.c @@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define softfloat_countLeadingZeros32 softfloat_countLeadingZeros32 #include "primitives.h" +#ifdef __cplusplus +extern "C" { +#endif + uint_fast8_t softfloat_countLeadingZeros32( uint32_t a ) { uint_fast8_t count; @@ -60,5 +64,9 @@ uint_fast8_t softfloat_countLeadingZeros32( uint32_t a ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_countLeadingZeros64.c b/src/isa/riscv64/softfloat/s_countLeadingZeros64.c index 00457418..9bc80167 100755 --- a/src/isa/riscv64/softfloat/s_countLeadingZeros64.c +++ b/src/isa/riscv64/softfloat/s_countLeadingZeros64.c @@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define softfloat_countLeadingZeros64 softfloat_countLeadingZeros64 #include "primitives.h" +#ifdef __cplusplus +extern "C" { +#endif + uint_fast8_t softfloat_countLeadingZeros64( uint64_t a ) { uint_fast8_t count; @@ -69,5 +73,9 @@ uint_fast8_t softfloat_countLeadingZeros64( uint64_t a ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_eq128.c b/src/isa/riscv64/softfloat/s_eq128.c index 625ef002..112a55bb 100755 --- a/src/isa/riscv64/softfloat/s_eq128.c +++ b/src/isa/riscv64/softfloat/s_eq128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_eq128 +#ifdef __cplusplus +extern "C" { +#endif + bool softfloat_eq128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) { @@ -47,5 +51,9 @@ bool softfloat_eq128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_le128.c b/src/isa/riscv64/softfloat/s_le128.c index 7261012f..1823af84 100755 --- a/src/isa/riscv64/softfloat/s_le128.c +++ b/src/isa/riscv64/softfloat/s_le128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_le128 +#ifdef __cplusplus +extern "C" { +#endif + bool softfloat_le128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) { @@ -47,5 +51,9 @@ bool softfloat_le128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_lt128.c b/src/isa/riscv64/softfloat/s_lt128.c index 0d461c36..073ad333 100755 --- a/src/isa/riscv64/softfloat/s_lt128.c +++ b/src/isa/riscv64/softfloat/s_lt128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_lt128 +#ifdef __cplusplus +extern "C" { +#endif + bool softfloat_lt128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) { @@ -47,5 +51,9 @@ bool softfloat_lt128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_mul128By32.c b/src/isa/riscv64/softfloat/s_mul128By32.c index 6e71dd0c..879c8ae4 100755 --- a/src/isa/riscv64/softfloat/s_mul128By32.c +++ b/src/isa/riscv64/softfloat/s_mul128By32.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_mul128By32 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_mul128By32( uint64_t a64, uint64_t a0, uint32_t b ) { struct uint128 z; @@ -54,5 +58,9 @@ struct uint128 softfloat_mul128By32( uint64_t a64, uint64_t a0, uint32_t b ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_mul128To256M.c b/src/isa/riscv64/softfloat/s_mul128To256M.c index fccc2a69..cdbd05ab 100755 --- a/src/isa/riscv64/softfloat/s_mul128To256M.c +++ b/src/isa/riscv64/softfloat/s_mul128To256M.c @@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define softfloat_mul128To256M softfloat_mul128To256M #include "primitives.h" +#ifdef __cplusplus +extern "C" { +#endif + void softfloat_mul128To256M( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0, uint64_t *zPtr ) @@ -67,5 +71,9 @@ void } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_mul64ByShifted32To128.c b/src/isa/riscv64/softfloat/s_mul64ByShifted32To128.c index f7e7104e..de134575 100755 --- a/src/isa/riscv64/softfloat/s_mul64ByShifted32To128.c +++ b/src/isa/riscv64/softfloat/s_mul64ByShifted32To128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_mul64ByShifted32To128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_mul64ByShifted32To128( uint64_t a, uint32_t b ) { uint_fast64_t mid; @@ -52,5 +56,9 @@ struct uint128 softfloat_mul64ByShifted32To128( uint64_t a, uint32_t b ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_mul64To128.c b/src/isa/riscv64/softfloat/s_mul64To128.c index 6620a20b..31ba311b 100755 --- a/src/isa/riscv64/softfloat/s_mul64To128.c +++ b/src/isa/riscv64/softfloat/s_mul64To128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_mul64To128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b ) { uint32_t a32, a0, b32, b0; @@ -62,5 +66,9 @@ struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam128.c b/src/isa/riscv64/softfloat/s_shiftRightJam128.c index 8d2b91e8..74e5d992 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam128.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_shiftRightJam128( uint64_t a64, uint64_t a0, uint_fast32_t dist ) { @@ -65,5 +69,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam128Extra.c b/src/isa/riscv64/softfloat/s_shiftRightJam128Extra.c index 4e1293c7..27fd576d 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam128Extra.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam128Extra.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam128Extra +#ifdef __cplusplus +extern "C" { +#endif + struct uint128_extra softfloat_shiftRightJam128Extra( uint64_t a64, uint64_t a0, uint64_t extra, uint_fast32_t dist ) @@ -73,5 +77,9 @@ struct uint128_extra } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam256M.c b/src/isa/riscv64/softfloat/s_shiftRightJam256M.c index 04cd1e50..da36826d 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam256M.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam256M.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam256M +#ifdef __cplusplus +extern "C" { +#endif + static void softfloat_shortShiftRightJamM( @@ -122,5 +126,9 @@ void } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam32.c b/src/isa/riscv64/softfloat/s_shiftRightJam32.c index fbc3aa01..ae5d632c 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam32.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam32.c @@ -39,6 +39,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam32 +#ifdef __cplusplus +extern "C" { +#endif + uint32_t softfloat_shiftRightJam32( uint32_t a, uint_fast16_t dist ) { @@ -47,5 +51,9 @@ uint32_t softfloat_shiftRightJam32( uint32_t a, uint_fast16_t dist ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam64.c b/src/isa/riscv64/softfloat/s_shiftRightJam64.c index 34edd7bf..e8517d43 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam64.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam64.c @@ -39,6 +39,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam64 +#ifdef __cplusplus +extern "C" { +#endif + uint64_t softfloat_shiftRightJam64( uint64_t a, uint_fast32_t dist ) { @@ -47,5 +51,9 @@ uint64_t softfloat_shiftRightJam64( uint64_t a, uint_fast32_t dist ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shiftRightJam64Extra.c b/src/isa/riscv64/softfloat/s_shiftRightJam64Extra.c index 4d787122..e45cabcc 100755 --- a/src/isa/riscv64/softfloat/s_shiftRightJam64Extra.c +++ b/src/isa/riscv64/softfloat/s_shiftRightJam64Extra.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shiftRightJam64Extra +#ifdef __cplusplus +extern "C" { +#endif + struct uint64_extra softfloat_shiftRightJam64Extra( uint64_t a, uint64_t extra, uint_fast32_t dist ) @@ -58,5 +62,9 @@ struct uint64_extra } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shortShiftLeft128.c b/src/isa/riscv64/softfloat/s_shortShiftLeft128.c index 9b7c0672..2276d2e0 100755 --- a/src/isa/riscv64/softfloat/s_shortShiftLeft128.c +++ b/src/isa/riscv64/softfloat/s_shortShiftLeft128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shortShiftLeft128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_shortShiftLeft128( uint64_t a64, uint64_t a0, uint_fast8_t dist ) { @@ -51,5 +55,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shortShiftRight128.c b/src/isa/riscv64/softfloat/s_shortShiftRight128.c index 28c39bb2..c6b64d8d 100755 --- a/src/isa/riscv64/softfloat/s_shortShiftRight128.c +++ b/src/isa/riscv64/softfloat/s_shortShiftRight128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shortShiftRight128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_shortShiftRight128( uint64_t a64, uint64_t a0, uint_fast8_t dist ) { @@ -51,5 +55,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shortShiftRightJam128.c b/src/isa/riscv64/softfloat/s_shortShiftRightJam128.c index 3eb0dd40..ffbfcbea 100755 --- a/src/isa/riscv64/softfloat/s_shortShiftRightJam128.c +++ b/src/isa/riscv64/softfloat/s_shortShiftRightJam128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shortShiftRightJam128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_shortShiftRightJam128( uint64_t a64, uint64_t a0, uint_fast8_t dist ) @@ -56,5 +60,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shortShiftRightJam128Extra.c b/src/isa/riscv64/softfloat/s_shortShiftRightJam128Extra.c index 13692a0d..04841e8d 100755 --- a/src/isa/riscv64/softfloat/s_shortShiftRightJam128Extra.c +++ b/src/isa/riscv64/softfloat/s_shortShiftRightJam128Extra.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shortShiftRightJam128Extra +#ifdef __cplusplus +extern "C" { +#endif + struct uint128_extra softfloat_shortShiftRightJam128Extra( uint64_t a64, uint64_t a0, uint64_t extra, uint_fast8_t dist ) @@ -55,5 +59,9 @@ struct uint128_extra } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_shortShiftRightJam64.c b/src/isa/riscv64/softfloat/s_shortShiftRightJam64.c index 7e93cd4f..37fba81e 100755 --- a/src/isa/riscv64/softfloat/s_shortShiftRightJam64.c +++ b/src/isa/riscv64/softfloat/s_shortShiftRightJam64.c @@ -39,6 +39,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_shortShiftRightJam64 +#ifdef __cplusplus +extern "C" { +#endif + uint64_t softfloat_shortShiftRightJam64( uint64_t a, uint_fast8_t dist ) { @@ -46,5 +50,9 @@ uint64_t softfloat_shortShiftRightJam64( uint64_t a, uint_fast8_t dist ) } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_sub128.c b/src/isa/riscv64/softfloat/s_sub128.c index ed86e100..9defc732 100755 --- a/src/isa/riscv64/softfloat/s_sub128.c +++ b/src/isa/riscv64/softfloat/s_sub128.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_sub128 +#ifdef __cplusplus +extern "C" { +#endif + struct uint128 softfloat_sub128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) { @@ -51,5 +55,9 @@ struct uint128 } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/isa/riscv64/softfloat/s_sub256M.c b/src/isa/riscv64/softfloat/s_sub256M.c index c07b45ea..8aba0e8e 100755 --- a/src/isa/riscv64/softfloat/s_sub256M.c +++ b/src/isa/riscv64/softfloat/s_sub256M.c @@ -40,6 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef softfloat_sub256M +#ifdef __cplusplus +extern "C" { +#endif + void softfloat_sub256M( const uint64_t *aPtr, const uint64_t *bPtr, uint64_t *zPtr ) @@ -61,5 +65,9 @@ void } +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/main.c b/src/main.c index b86a2327..9a7619e5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,6 @@ void init_monitor(int, char *[]); +void init_csr_exist(); +void init_keymap(); void engine_start(); int goodtrap(void); int is_batch_mode(); @@ -7,6 +9,9 @@ int main(int argc, char *argv[]) { /* Initialize the monitor. */ init_monitor(argc, argv); + init_csr_exist(); + init_keymap(); + /* Start engine. */ engine_start(); diff --git a/src/memory/paddr.c b/src/memory/paddr.c index cec763f9..70f4a927 100644 --- a/src/memory/paddr.c +++ b/src/memory/paddr.c @@ -9,7 +9,7 @@ static uint8_t pmem[PMEM_SIZE] PG_ALIGN = {}; nemu_bool pmem_dirty[PMEM_SIZE] PG_ALIGN = {0}; void* guest_to_host(paddr_t addr) { return &pmem[addr]; } -paddr_t host_to_guest(void *addr) { return (void *)pmem - addr; } +paddr_t host_to_guest(void *addr) { return (uint8_t *)pmem - (uint8_t *)addr; } IOMap* fetch_mmio_map(paddr_t addr); @@ -78,12 +78,12 @@ void rtl_sfence() { /* Memory accessing interfaces */ -inline word_t paddr_read(paddr_t addr, int len) { +word_t paddr_read(paddr_t addr, int len) { if (in_pmem(addr)) return pmem_read(addr, len); else return map_read(addr, len, fetch_mmio_map(addr)); } -inline void paddr_write(paddr_t addr, word_t data, int len) { +void paddr_write(paddr_t addr, word_t data, int len) { if (in_pmem(addr)) pmem_write(addr, data, len); else map_write(addr, data, len, fetch_mmio_map(addr)); } diff --git a/src/monitor/cpu-exec.c b/src/monitor/cpu-exec.c index b62c684f..f35cd5cc 100644 --- a/src/monitor/cpu-exec.c +++ b/src/monitor/cpu-exec.c @@ -19,7 +19,7 @@ CPU_state cpu; NEMUState nemu_state = {.state = NEMU_STOP}; static uint64_t g_nr_guest_instr = 0; -const rtlreg_t rzero = 0; +extern const rtlreg_t rzero = 0; void asm_print(vaddr_t ori_pc, int instr_len, nemu_bool print_flag); -- GitLab