ch1:First instruction in kernel

This commit is contained in:
Tateisi 2025-08-02 15:42:14 +08:00
parent ad42f53386
commit 5de7bac424
4 changed files with 61 additions and 1 deletions

View file

@ -1,2 +1,7 @@
[build] [build]
target = "riscv64gc-unknown-none-elf" target = "riscv64gc-unknown-none-elf"
[target.riscv64gc-unknown-none-elf]
rustflags = [
"-Clink-arg=-Tsrc/linker.ld", "-Cforce-frame-pointers=yes"
]

4
src/entry.asm Normal file
View file

@ -0,0 +1,4 @@
.section .text.entry
.globl _start
_start:
li x1, 100

48
src/linker.ld Normal file
View file

@ -0,0 +1,48 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
BASE_ADDRESS = 0x80200000;
SECTIONS
{
. = BASE_ADDRESS;
skernel = .;
stext = .;
.text : {
*(.text.entry)
*(.text .text.*)
}
. = ALIGN(4K);
etext = .;
srodata = .;
.rodata : {
*(.data .rodata.*)
*(.srodata .srodata.*)
}
. = ALIGN(4K);
erodata = .;
sdata = .;
.data : {
*(.data .data.*)
*(.sdata .sdata.*)
}
. = ALIGN(4K);
edata = .;
.bss : {
*(.bss.stack)
sbss = .;
*(.bss .bss.*)
*(.sbss .sbss.*)
}
. = ALIGN(4K);
ebss = .;
ekernel = .;
/DISCARD/ : {
*(.eh_frame)
}
}

View file

@ -2,3 +2,6 @@
#![no_main] #![no_main]
mod lang_items; mod lang_items;
use core::arch::global_asm;
global_asm!(include_str!("entry.asm"));