From 46f8f48c39874558b5ffe51e275d3efdac26a93c Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Fri, 27 Aug 2021 17:16:41 +0800 Subject: [PATCH] code: add linux-lab support this commit allows rvos code work in linux-lab without additional tools. 1. let our code use riscv64-linux-gnu-gcc and gdb-multiarch pre-installed in linux-lab. 2. fix up the issues while compiling with riscv64-linux-gnu-gcc * the kernel binary should be compiled without PIE, disalbe PIE which has been enabled by default for gcc in modern linux distributions * use the global variables provided in os.ld directly instead of saving them in .rodata section riscv64-linux-gnu-gcc doesn't resolve the addresses in .rodata during linking but riscv64-unknown-elf-gcc does, we just not save the addresses in .rodata, but using them directly via using their pointers 3. ignore the coredump files Signed-off-by: Wu Zhangjin --- .gitignore | 2 +- code/asm/header.mk | 35 +++++++++++++++++++++++++++++++ code/asm/rule.mk | 14 ++++--------- code/os/00-bootstrap/Makefile | 11 +--------- code/os/01-helloRVOS/Makefile | 11 +--------- code/os/02-memanagement/Makefile | 14 ++----------- code/os/02-memanagement/mem.S | 30 -------------------------- code/os/02-memanagement/mem.h | 25 ++++++++++++++++++++++ code/os/02-memanagement/page.c | 15 +------------ code/os/03-contextswitch/Makefile | 12 +---------- code/os/03-contextswitch/mem.S | 30 -------------------------- code/os/03-contextswitch/mem.h | 25 ++++++++++++++++++++++ code/os/03-contextswitch/page.c | 15 +------------ code/os/04-multitask/Makefile | 12 +---------- code/os/04-multitask/mem.S | 30 -------------------------- code/os/04-multitask/mem.h | 25 ++++++++++++++++++++++ code/os/04-multitask/page.c | 15 +------------ code/os/05-traps/Makefile | 12 +---------- code/os/05-traps/mem.S | 30 -------------------------- code/os/05-traps/mem.h | 25 ++++++++++++++++++++++ code/os/05-traps/page.c | 15 +------------ code/os/06-interrupts/Makefile | 12 +---------- code/os/06-interrupts/mem.S | 30 -------------------------- code/os/06-interrupts/mem.h | 25 ++++++++++++++++++++++ code/os/06-interrupts/page.c | 15 +------------ code/os/07-hwtimer/Makefile | 12 +---------- code/os/07-hwtimer/mem.S | 30 -------------------------- code/os/07-hwtimer/mem.h | 25 ++++++++++++++++++++++ code/os/07-hwtimer/page.c | 15 +------------ code/os/08-preemptive/Makefile | 12 +---------- code/os/08-preemptive/mem.S | 30 -------------------------- code/os/08-preemptive/mem.h | 25 ++++++++++++++++++++++ code/os/08-preemptive/page.c | 15 +------------ code/os/09-lock/Makefile | 12 +---------- code/os/09-lock/mem.S | 30 -------------------------- code/os/09-lock/mem.h | 25 ++++++++++++++++++++++ code/os/09-lock/page.c | 15 +------------ code/os/10-swtimer/Makefile | 12 +---------- code/os/10-swtimer/mem.S | 30 -------------------------- code/os/10-swtimer/mem.h | 25 ++++++++++++++++++++++ code/os/10-swtimer/page.c | 15 +------------ code/os/11-syscall/Makefile | 15 ++----------- code/os/11-syscall/mem.S | 30 -------------------------- code/os/11-syscall/mem.h | 25 ++++++++++++++++++++++ code/os/11-syscall/page.c | 15 +------------ code/os/header.mk | 1 + 46 files changed, 315 insertions(+), 584 deletions(-) create mode 100644 code/asm/header.mk delete mode 100644 code/os/02-memanagement/mem.S create mode 100644 code/os/02-memanagement/mem.h delete mode 100644 code/os/03-contextswitch/mem.S create mode 100644 code/os/03-contextswitch/mem.h delete mode 100644 code/os/04-multitask/mem.S create mode 100644 code/os/04-multitask/mem.h delete mode 100644 code/os/05-traps/mem.S create mode 100644 code/os/05-traps/mem.h delete mode 100644 code/os/06-interrupts/mem.S create mode 100644 code/os/06-interrupts/mem.h delete mode 100644 code/os/07-hwtimer/mem.S create mode 100644 code/os/07-hwtimer/mem.h delete mode 100644 code/os/08-preemptive/mem.S create mode 100644 code/os/08-preemptive/mem.h delete mode 100644 code/os/09-lock/mem.S create mode 100644 code/os/09-lock/mem.h delete mode 100644 code/os/10-swtimer/mem.S create mode 100644 code/os/10-swtimer/mem.h delete mode 100644 code/os/11-syscall/mem.S create mode 100644 code/os/11-syscall/mem.h create mode 120000 code/os/header.mk diff --git a/.gitignore b/.gitignore index 387fd41..d4a07aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.o *.bin *.elf - +core diff --git a/code/asm/header.mk b/code/asm/header.mk new file mode 100644 index 0000000..64aa72d --- /dev/null +++ b/code/asm/header.mk @@ -0,0 +1,35 @@ +CROSS_COMPILE = riscv64-unknown-elf- +CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall + +QEMU = qemu-system-riscv32 +QFLAGS = -nographic -smp 1 -machine virt -bios none + +CC_LIST := riscv64-unknown-elf- riscv64-linux-gnu- +CROSS_COMPILE := $(shell for cc in $(CC_LIST); do which $${cc}gcc >/dev/null 2>&1 && echo $${cc} && break; done) + +ifneq ($(CROSS_COMPILE),) + GCC = ${CROSS_COMPILE}gcc + ifeq ($(CROSS_COMPILE),riscv64-linux-gnu-) + # make sure PIE disabled for kernel-like binaries + CFLAGS += -fno-PIE -mcmodel=medany + endif + + GDB_LIST = ${CROSS_COMPILE}gdb gdb-multiarch + GDB = $(shell for gdb in $(GDB_LIST); do which $${gdb} >/dev/null 2>&1 && echo $${gdb} && break; done) +endif + +CC = $(GCC) +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump + +ifeq ($(GCC),) + $(error Please install one of $(addsuffix gcc,$(CC_LIST))) +else + ifeq ($(GDB),) + $(error Please install one of $(GDB_LIST)) + endif +endif + +ifneq ($(shell which $(QEMU) >/dev/null 2>&1; echo $$?),0) + $(error Please install $(QEMU)) +endif diff --git a/code/asm/rule.mk b/code/asm/rule.mk index 6d73fac..6270ebc 100644 --- a/code/asm/rule.mk +++ b/code/asm/rule.mk @@ -1,15 +1,9 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb +include ../header.mk .DEFAULT_GOAL := all all: - @$(CROSS_COMPILE)gcc $(CFLAGS) ${SRC} -Ttext=0x80000000 -o $(EXEC).elf - @$(CROSS_COMPILE)objcopy -O binary $(EXEC).elf $(EXEC).bin + @$(GCC) $(CFLAGS) ${SRC} -Ttext=0x80000000 -o $(EXEC).elf + @$(OBJCOPY) -O binary $(EXEC).elf $(EXEC).bin .PHONY : run run: all @@ -27,7 +21,7 @@ debug: all .PHONY : code code: all - @$(CROSS_COMPILE)objdump -S $(EXEC).elf | less + @$(OBJDUMP) -S $(EXEC).elf | less .PHONY : hex hex: all diff --git a/code/os/00-bootstrap/Makefile b/code/os/00-bootstrap/Makefile index f5dbaa7..de8c770 100644 --- a/code/os/00-bootstrap/Makefile +++ b/code/os/00-bootstrap/Makefile @@ -1,13 +1,4 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ diff --git a/code/os/01-helloRVOS/Makefile b/code/os/01-helloRVOS/Makefile index 288c319..f900ccc 100644 --- a/code/os/01-helloRVOS/Makefile +++ b/code/os/01-helloRVOS/Makefile @@ -1,13 +1,4 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ diff --git a/code/os/02-memanagement/Makefile b/code/os/02-memanagement/Makefile index 26d9b3a..bf9b32e 100644 --- a/code/os/02-memanagement/Makefile +++ b/code/os/02-memanagement/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ - start.S \ - mem.S \ + start.S SRCS_C = \ kernel.c \ diff --git a/code/os/02-memanagement/mem.S b/code/os/02-memanagement/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/02-memanagement/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/02-memanagement/mem.h b/code/os/02-memanagement/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/02-memanagement/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/02-memanagement/page.c b/code/os/02-memanagement/page.c index addf097..2c1d024 100644 --- a/code/os/02-memanagement/page.c +++ b/code/os/02-memanagement/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/03-contextswitch/Makefile b/code/os/03-contextswitch/Makefile index 40800ab..5b89dad 100644 --- a/code/os/03-contextswitch/Makefile +++ b/code/os/03-contextswitch/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/03-contextswitch/mem.S b/code/os/03-contextswitch/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/03-contextswitch/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/03-contextswitch/mem.h b/code/os/03-contextswitch/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/03-contextswitch/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/03-contextswitch/page.c b/code/os/03-contextswitch/page.c index addf097..2c1d024 100644 --- a/code/os/03-contextswitch/page.c +++ b/code/os/03-contextswitch/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/04-multitask/Makefile b/code/os/04-multitask/Makefile index 6f15006..7dce82b 100644 --- a/code/os/04-multitask/Makefile +++ b/code/os/04-multitask/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/04-multitask/mem.S b/code/os/04-multitask/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/04-multitask/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/04-multitask/mem.h b/code/os/04-multitask/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/04-multitask/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/04-multitask/page.c b/code/os/04-multitask/page.c index addf097..2c1d024 100644 --- a/code/os/04-multitask/page.c +++ b/code/os/04-multitask/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/05-traps/Makefile b/code/os/05-traps/Makefile index 7e4b9c4..0e51bf5 100644 --- a/code/os/05-traps/Makefile +++ b/code/os/05-traps/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/05-traps/mem.S b/code/os/05-traps/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/05-traps/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/05-traps/mem.h b/code/os/05-traps/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/05-traps/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/05-traps/page.c b/code/os/05-traps/page.c index addf097..2c1d024 100644 --- a/code/os/05-traps/page.c +++ b/code/os/05-traps/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/06-interrupts/Makefile b/code/os/06-interrupts/Makefile index 136fd40..22f8b78 100644 --- a/code/os/06-interrupts/Makefile +++ b/code/os/06-interrupts/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/06-interrupts/mem.S b/code/os/06-interrupts/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/06-interrupts/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/06-interrupts/mem.h b/code/os/06-interrupts/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/06-interrupts/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/06-interrupts/page.c b/code/os/06-interrupts/page.c index addf097..2c1d024 100644 --- a/code/os/06-interrupts/page.c +++ b/code/os/06-interrupts/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/07-hwtimer/Makefile b/code/os/07-hwtimer/Makefile index 69e47ee..8c2b1f3 100644 --- a/code/os/07-hwtimer/Makefile +++ b/code/os/07-hwtimer/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/07-hwtimer/mem.S b/code/os/07-hwtimer/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/07-hwtimer/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/07-hwtimer/mem.h b/code/os/07-hwtimer/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/07-hwtimer/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/07-hwtimer/page.c b/code/os/07-hwtimer/page.c index addf097..2c1d024 100644 --- a/code/os/07-hwtimer/page.c +++ b/code/os/07-hwtimer/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/08-preemptive/Makefile b/code/os/08-preemptive/Makefile index 69e47ee..8c2b1f3 100644 --- a/code/os/08-preemptive/Makefile +++ b/code/os/08-preemptive/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/08-preemptive/mem.S b/code/os/08-preemptive/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/08-preemptive/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/08-preemptive/mem.h b/code/os/08-preemptive/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/08-preemptive/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/08-preemptive/page.c b/code/os/08-preemptive/page.c index addf097..2c1d024 100644 --- a/code/os/08-preemptive/page.c +++ b/code/os/08-preemptive/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/09-lock/Makefile b/code/os/09-lock/Makefile index 5cb1101..d1c3524 100644 --- a/code/os/09-lock/Makefile +++ b/code/os/09-lock/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/09-lock/mem.S b/code/os/09-lock/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/09-lock/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/09-lock/mem.h b/code/os/09-lock/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/09-lock/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/09-lock/page.c b/code/os/09-lock/page.c index addf097..2c1d024 100644 --- a/code/os/09-lock/page.c +++ b/code/os/09-lock/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/10-swtimer/Makefile b/code/os/10-swtimer/Makefile index 5cb1101..d1c3524 100644 --- a/code/os/10-swtimer/Makefile +++ b/code/os/10-swtimer/Makefile @@ -1,17 +1,7 @@ -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump +include ../header.mk SRCS_ASM = \ start.S \ - mem.S \ entry.S \ SRCS_C = \ diff --git a/code/os/10-swtimer/mem.S b/code/os/10-swtimer/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/10-swtimer/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/10-swtimer/mem.h b/code/os/10-swtimer/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/10-swtimer/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/10-swtimer/page.c b/code/os/10-swtimer/page.c index addf097..2c1d024 100644 --- a/code/os/10-swtimer/page.c +++ b/code/os/10-swtimer/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/11-syscall/Makefile b/code/os/11-syscall/Makefile index 967a174..2237a21 100644 --- a/code/os/11-syscall/Makefile +++ b/code/os/11-syscall/Makefile @@ -1,24 +1,13 @@ -SYSCALL = y +include ../header.mk -CROSS_COMPILE = riscv64-unknown-elf- -CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall +SYSCALL = y ifeq ($(SYSCALL), y) CFLAGS += -D CONFIG_SYSCALL endif - -QEMU = qemu-system-riscv32 -QFLAGS = -nographic -smp 1 -machine virt -bios none - -GDB = ${CROSS_COMPILE}gdb -CC = ${CROSS_COMPILE}gcc -OBJCOPY = ${CROSS_COMPILE}objcopy -OBJDUMP = ${CROSS_COMPILE}objdump - SRCS_ASM = \ start.S \ - mem.S \ entry.S \ usys.S diff --git a/code/os/11-syscall/mem.S b/code/os/11-syscall/mem.S deleted file mode 100644 index 93ba0d6..0000000 --- a/code/os/11-syscall/mem.S +++ /dev/null @@ -1,30 +0,0 @@ -.section .rodata -.global HEAP_START -HEAP_START: .word _heap_start - -.global HEAP_SIZE -HEAP_SIZE: .word _heap_size - -.global TEXT_START -TEXT_START: .word _text_start - -.global TEXT_END -TEXT_END: .word _text_end - -.global DATA_START -DATA_START: .word _data_start - -.global DATA_END -DATA_END: .word _data_end - -.global RODATA_START -RODATA_START: .word _rodata_start - -.global RODATA_END -RODATA_END: .word _rodata_end - -.global BSS_START -BSS_START: .word _bss_start - -.global BSS_END -BSS_END: .word _bss_end diff --git a/code/os/11-syscall/mem.h b/code/os/11-syscall/mem.h new file mode 100644 index 0000000..fa90666 --- /dev/null +++ b/code/os/11-syscall/mem.h @@ -0,0 +1,25 @@ +/* + * Following global vars are provided by os.ld + */ + +extern uint32_t _heap_start; +extern uint32_t _heap_size; +extern uint32_t _text_start; +extern uint32_t _text_end; +extern uint32_t _data_start; +extern uint32_t _data_end; +extern uint32_t _rodata_start; +extern uint32_t _rodata_end; +extern uint32_t _bss_start; +extern uint32_t _bss_end; + +#define HEAP_START ((uint32_t)&_heap_start) +#define HEAP_SIZE ((uint32_t)&_heap_size) +#define TEXT_START ((uint32_t)&_text_start) +#define TEXT_END ((uint32_t)&_text_end) +#define DATA_START ((uint32_t)&_data_start) +#define DATA_END ((uint32_t)&_data_end) +#define RODATA_START ((uint32_t)&_rodata_start) +#define RODATA_END ((uint32_t)&_rodata_end) +#define BSS_START ((uint32_t)&_bss_start) +#define BSS_END ((uint32_t)&_bss_end) diff --git a/code/os/11-syscall/page.c b/code/os/11-syscall/page.c index addf097..2c1d024 100644 --- a/code/os/11-syscall/page.c +++ b/code/os/11-syscall/page.c @@ -1,18 +1,5 @@ #include "os.h" - -/* - * Following global vars are defined in mem.S - */ -extern uint32_t TEXT_START; -extern uint32_t TEXT_END; -extern uint32_t DATA_START; -extern uint32_t DATA_END; -extern uint32_t RODATA_START; -extern uint32_t RODATA_END; -extern uint32_t BSS_START; -extern uint32_t BSS_END; -extern uint32_t HEAP_START; -extern uint32_t HEAP_SIZE; +#include "mem.h" /* * _alloc_start points to the actual start address of heap pool diff --git a/code/os/header.mk b/code/os/header.mk new file mode 120000 index 0000000..50931ae --- /dev/null +++ b/code/os/header.mk @@ -0,0 +1 @@ +../asm/header.mk \ No newline at end of file -- Gitee