Browse Source

32-bit test kernel on qemu

luojia65 4 years ago
parent
commit
78afd5442f
3 changed files with 48 additions and 0 deletions
  1. 5 0
      test-kernel/.cargo/config.toml
  2. 5 0
      test-kernel/build.rs
  3. 38 0
      test-kernel/src/linker32.ld

+ 5 - 0
test-kernel/.cargo/config.toml

@@ -2,3 +2,8 @@
 rustflags = [
     "-C", "link-arg=-Tlinker64.ld",
 ]
+
+[target.riscv32imac-unknown-none-elf]
+rustflags = [
+    "-C", "link-arg=-Tlinker32.ld",
+]

+ 5 - 0
test-kernel/build.rs

@@ -11,8 +11,13 @@ fn main() {
         .unwrap()
         .write_all(include_bytes!("src/linker64.ld"))
         .unwrap();
+    fs::File::create(out_dir.join("linker32.ld"))
+        .unwrap()
+        .write_all(include_bytes!("src/linker32.ld"))
+        .unwrap();
     println!("cargo:rustc-link-search={}", out_dir.display());
 
     println!("cargo:rerun-if-changed=build.rs");
     println!("cargo:rerun-if-changed=src/linker64.ld");
+    println!("cargo:rerun-if-changed=src/linker32.ld");
 }

+ 38 - 0
test-kernel/src/linker32.ld

@@ -0,0 +1,38 @@
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+
+BASE_ADDRESS = 0x80400000;
+
+SECTIONS
+{
+    /* Load the kernel at this address: "." means the current address */
+    . = BASE_ADDRESS;
+    start = .;
+
+    .text : ALIGN(4K) {
+        _stext = .;
+        *(.text.entry)
+        *(.text .text.*)
+        _etext = .;
+    }
+
+    .rodata : ALIGN(4K) {
+        _srodata = .;
+        *(.rodata .rodata.*)
+        _erodata = .;
+    }
+
+    .data : ALIGN(4K) {
+        _sdata = .;
+        *(.data .data.*)
+        _edata = .;
+    }
+
+    .bss (NOLOAD) : ALIGN(4K)  {
+        _sbss = .;
+        *(.sbss .bss .bss.*)
+        _ebss = .;
+    }
+
+    PROVIDE(end = .);
+}