diff --git a/bootloader/rustsbi-k210.bin b/bootloader/rustsbi-k210.bin index 160e2439..e696137a 100755 Binary files a/bootloader/rustsbi-k210.bin and b/bootloader/rustsbi-k210.bin differ diff --git a/bootloader/rustsbi-qemu.bin b/bootloader/rustsbi-qemu.bin index 54329fcb..5ccab433 100755 Binary files a/bootloader/rustsbi-qemu.bin and b/bootloader/rustsbi-qemu.bin differ diff --git a/os/Makefile b/os/Makefile index b55c71f6..e9292ede 100644 --- a/os/Makefile +++ b/os/Makefile @@ -3,13 +3,20 @@ TARGET := riscv64gc-unknown-none-elf MODE := release KERNEL_ELF := target/$(TARGET)/$(MODE)/os KERNEL_BIN := $(KERNEL_ELF).bin -KERNEL_ENTRY_PA := 0x80020000 DISASM_TMP := target/$(TARGET)/$(MODE)/asm # BOARD BOARD ?= qemu SBI ?= rustsbi BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin +K210_BOOTLOADER_SIZE := 131072 + +# KERNEL ENTRY +ifeq ($(BOARD), qemu) + KERNEL_ENTRY_PA := 0x80200000 +else ifeq ($(BOARD), k210) + KERNEL_ENTRY_PA := 0x80020000 +endif # Run K210 K210-SERIALPORT = /dev/ttyUSB0 @@ -35,7 +42,10 @@ $(KERNEL_BIN): kernel kernel: @cd ../user && make build + @echo Platform: $(BOARD) + @cp src/linker-$(BOARD).ld src/linker.ld @cargo build --release --features "board_$(BOARD)" + @rm src/linker.ld clean: @cargo clean @@ -59,7 +69,7 @@ ifeq ($(BOARD),qemu) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) else @cp $(BOOTLOADER) $(BOOTLOADER).copy - @dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=131072 seek=1 + @dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(K210_BOOTLOADER_SIZE) seek=1 @mv $(BOOTLOADER).copy $(KERNEL_BIN) @sudo chmod 777 $(K210-SERIALPORT) python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(KERNEL_BIN) diff --git a/os/src/config.rs b/os/src/config.rs index 8350d205..15f7b1c7 100644 --- a/os/src/config.rs +++ b/os/src/config.rs @@ -1,7 +1,13 @@ pub const USER_STACK_SIZE: usize = 4096 * 2; pub const KERNEL_STACK_SIZE: usize = 4096 * 2; pub const KERNEL_HEAP_SIZE: usize = 0x20_0000; + +#[cfg(feature = "board_k210")] pub const MEMORY_END: usize = 0x80600000; + +#[cfg(feature = "board_qemu")] +pub const MEMORY_END: usize = 0x80800000; + pub const PAGE_SIZE: usize = 0x1000; pub const PAGE_SIZE_BITS: usize = 0xc; diff --git a/os/src/linker.ld b/os/src/linker-k210.ld similarity index 100% rename from os/src/linker.ld rename to os/src/linker-k210.ld diff --git a/os/src/linker-qemu.ld b/os/src/linker-qemu.ld new file mode 100644 index 00000000..6b06e916 --- /dev/null +++ b/os/src/linker-qemu.ld @@ -0,0 +1,50 @@ +OUTPUT_ARCH(riscv) +ENTRY(_start) +BASE_ADDRESS = 0x80200000; + +SECTIONS +{ + . = BASE_ADDRESS; + skernel = .; + + stext = .; + .text : { + *(.text.entry) + . = ALIGN(4K); + strampoline = .; + *(.text.trampoline); + . = ALIGN(4K); + *(.text .text.*) + } + + . = ALIGN(4K); + etext = .; + srodata = .; + .rodata : { + *(.rodata .rodata.*) + } + + . = ALIGN(4K); + erodata = .; + sdata = .; + .data : { + *(.data .data.*) + } + + . = ALIGN(4K); + edata = .; + sbss_with_stack = .; + .bss : { + *(.bss.stack) + sbss = .; + *(.bss .bss.*) + } + + . = ALIGN(4K); + ebss = .; + ekernel = .; + + /DISCARD/ : { + *(.eh_frame) + } +} \ No newline at end of file