diff --git a/code/os/11-syscall/entry.S b/code/os/11-syscall/entry.S index 4759321..1fd9a7c 100644 --- a/code/os/11-syscall/entry.S +++ b/code/os/11-syscall/entry.S @@ -1,6 +1,12 @@ +#ifdef CONFIG_RV64 +#define LOAD ld +#define STORE sd +#define SIZE_REG 8 +#else #define LOAD lw #define STORE sw #define SIZE_REG 4 +#endif # Save all General-Purpose(GP) registers to context. # struct context *base = &ctx_task; diff --git a/code/os/11-syscall/mem.S b/code/os/11-syscall/mem.S index 5dede60..3d3341d 100644 --- a/code/os/11-syscall/mem.S +++ b/code/os/11-syscall/mem.S @@ -1,4 +1,8 @@ +#ifdef CONFIG_RV64 +#define SIZE_PTR .dword +#else #define SIZE_PTR .word +#endif .section .rodata .global HEAP_START diff --git a/code/os/11-syscall/riscv.h b/code/os/11-syscall/riscv.h index 051749a..01d82e8 100644 --- a/code/os/11-syscall/riscv.h +++ b/code/os/11-syscall/riscv.h @@ -93,8 +93,13 @@ static inline void w_mie(reg_t x) } /* Machine-mode Cause Masks */ +#ifdef CONFIG_RV64 +#define MCAUSE_MASK_INTERRUPT (reg_t)0x8000000000000000 +#define MCAUSE_MASK_ECODE (reg_t)0x7FFFFFFFFFFFFFFF +#else #define MCAUSE_MASK_INTERRUPT (reg_t)0x80000000 #define MCAUSE_MASK_ECODE (reg_t)0x7FFFFFFF +#endif static inline reg_t r_mcause() { diff --git a/code/os/11-syscall/types.h b/code/os/11-syscall/types.h index f2497fe..0162166 100644 --- a/code/os/11-syscall/types.h +++ b/code/os/11-syscall/types.h @@ -9,7 +9,12 @@ typedef unsigned long long uint64_t; /* * Register Width */ +#ifdef CONFIG_RV64 +typedef uint64_t reg_t; +typedef uint64_t ptr_t; +#else typedef uint32_t reg_t; typedef uint32_t ptr_t; +#endif #endif /* __TYPES_H__ */ diff --git a/code/os/common.mk b/code/os/common.mk index 11feb45..c81ecc3 100644 --- a/code/os/common.mk +++ b/code/os/common.mk @@ -2,15 +2,25 @@ # This file will be included by the Makefile of each project. # Custom Macro Definition (Common part) +ARCH = RV64 include ../defines.mk DEFS += CROSS_COMPILE = riscv64-unknown-elf- CFLAGS += -nostdlib -fno-builtin -g -Wall +ifeq (${ARCH}, RV64) +CFLAGS += -march=rv64g -mabi=lp64 -mcmodel=medany +else CFLAGS += -march=rv32g -mabi=ilp32 +endif +ifeq (${ARCH}, RV64) +QEMU = qemu-system-riscv64 +else QEMU = qemu-system-riscv32 +endif + QFLAGS = -nographic -smp 1 -machine virt -bios none GDB = gdb-multiarch diff --git a/code/os/defines.mk b/code/os/defines.mk index ca9b040..016b3bc 100644 --- a/code/os/defines.mk +++ b/code/os/defines.mk @@ -2,6 +2,13 @@ # Support customization in the Makefile files for each project separately. # And also support customization in common.mk +ifeq (${ARCH}, RV64) +DEFS += -DCONFIG_RV64 +else +# RV32 or default is 32bit +DEFS += -DCONFIG_RV32 +endif + ifeq (${SYSCALL}, y) DEFS += -DCONFIG_SYSCALL endif