diff --git a/.gitignore b/.gitignore index c4e93345..3adafb58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .idea/* os/target/* os/.idea/* +os/Cargo.lock os/src/link_app.S user/target/* -user/.idea/* \ No newline at end of file +user/.idea/* +user/Cargo.lock diff --git a/bootloader/rustsbi-k210.bin b/bootloader/rustsbi-k210.bin index 5a9fa7d1..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 1fdc888b..5ccab433 100755 Binary files a/bootloader/rustsbi-qemu.bin and b/bootloader/rustsbi-qemu.bin differ diff --git a/os/Cargo.lock b/os/Cargo.lock deleted file mode 100644 index 85e21762..00000000 --- a/os/Cargo.lock +++ /dev/null @@ -1,132 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "aho-corasick" -version = "0.7.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" -dependencies = [ - "memchr", -] - -[[package]] -name = "bare-metal" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" -dependencies = [ - "rustc_version", -] - -[[package]] -name = "bit_field" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] - -[[package]] -name = "memchr" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" - -[[package]] -name = "os" -version = "0.1.0" -dependencies = [ - "lazy_static", - "riscv", -] - -[[package]] -name = "regex" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", - "thread_local", -] - -[[package]] -name = "regex-syntax" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" - -[[package]] -name = "riscv" -version = "0.6.0" -source = "git+https://github.com/rcore-os/riscv#21e32ee1dc786cc0d5006ceee0040ce4f8398575" -dependencies = [ - "bare-metal", - "bit_field", - "bitflags", - "riscv-target", -] - -[[package]] -name = "riscv-target" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222" -dependencies = [ - "lazy_static", - "regex", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] 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 20aba22e..e50175a0 100644 --- a/os/src/config.rs +++ b/os/src/config.rs @@ -1,7 +1,7 @@ pub const USER_STACK_SIZE: usize = 4096 * 2; pub const KERNEL_STACK_SIZE: usize = 4096 * 2; pub const MAX_APP_NUM: usize = 4; -pub const APP_BASE_ADDRESS: usize = 0x80100000; +pub const APP_BASE_ADDRESS: usize = 0x80400000; pub const APP_SIZE_LIMIT: usize = 0x20000; #[cfg(feature = "board_k210")] 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..8348a385 --- /dev/null +++ b/os/src/linker-qemu.ld @@ -0,0 +1,45 @@ +OUTPUT_ARCH(riscv) +ENTRY(_start) +BASE_ADDRESS = 0x80200000; + +SECTIONS +{ + . = BASE_ADDRESS; + skernel = .; + + stext = .; + .text : { + *(.text.entry) + *(.text .text.*) + } + + . = ALIGN(4K); + etext = .; + srodata = .; + .rodata : { + *(.rodata .rodata.*) + } + + . = ALIGN(4K); + erodata = .; + sdata = .; + .data : { + *(.data .data.*) + } + + . = ALIGN(4K); + edata = .; + .bss : { + *(.bss.stack) + sbss = .; + *(.bss .bss.*) + } + + . = ALIGN(4K); + ebss = .; + ekernel = .; + + /DISCARD/ : { + *(.eh_frame) + } +} \ No newline at end of file diff --git a/user/Cargo.lock b/user/Cargo.lock deleted file mode 100644 index e28c9137..00000000 --- a/user/Cargo.lock +++ /dev/null @@ -1,5 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "user_lib" -version = "0.1.0" diff --git a/user/build.py b/user/build.py index b558177a..23c6d052 100644 --- a/user/build.py +++ b/user/build.py @@ -1,6 +1,6 @@ import os -base_address = 0x80100000 +base_address = 0x80400000 step = 0x20000 linker = 'src/linker.ld' diff --git a/user/src/linker.ld b/user/src/linker.ld index 1c64a19b..d3f023d2 100644 --- a/user/src/linker.ld +++ b/user/src/linker.ld @@ -2,7 +2,7 @@ OUTPUT_ARCH(riscv) ENTRY(_start) -BASE_ADDRESS = 0x80100000; +BASE_ADDRESS = 0x80400000; SECTIONS {