summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-03-31 18:41:36 -0400
committerstefan <stefan@s00.xyz>2023-03-31 18:41:36 -0400
commit598b964ee3c1fab162bfc85fa3725501ab238881 (patch)
tree4f6129b1fce2b6b6705ffb465b830c3a3e6953b4
parent13726e79ad71d4620b5bbc60c6ff2f3527de84ce (diff)
downloadsv-598b964ee3c1fab162bfc85fa3725501ab238881.tar.gz
entry.s and kernel.ld
-rw-r--r--kernel/boot/entry.S36
-rw-r--r--kernel/lds/kernel.ld47
2 files changed, 83 insertions, 0 deletions
diff --git a/kernel/boot/entry.S b/kernel/boot/entry.S
new file mode 100644
index 0000000..4c977a3
--- /dev/null
+++ b/kernel/boot/entry.S
@@ -0,0 +1,36 @@
+.section .text.init
+
+.globl _start
+_start:
+ csrw satp, zero
+ csrw sie, zero
+ csrw sip, zero
+
+ .option push
+ .option norelax
+ la gp, __global_pointer$
+ .option pop
+
+ la sp, __stack_start
+ mv t0, a0
+ li t1, PAGE_SIZE
+ mul t0, t0, t1
+ add sp, sp, t0
+
+ li a2, 1
+ lla a3, _boot_hart
+ amoswap.w, a3, a2, (a3)
+ bnez a3, mp_entry
+
+ la a2, __bss_start
+ la a3, __bss_end
+1:
+ sd zero, (a2)
+ addi a2, a2, __SIZEOF_POINTER__
+ blt a2, a3, 1b
+
+ call boot
+
+_boot_hart:
+ .dword 0
+
diff --git a/kernel/lds/kernel.ld b/kernel/lds/kernel.ld
new file mode 100644
index 0000000..052aa32
--- /dev/null
+++ b/kernel/lds/kernel.ld
@@ -0,0 +1,47 @@
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+
+SECTIONS
+{
+ . = LOAD_ADDR;
+ . = ALIGN(PAGE_SIZE);
+
+ .text :
+ {
+ provide(__text_start = .);
+ *(.text.init)
+ *(.text .text.*)
+ . = ALIGN(8);
+ PROVIDE(__text_end = .);
+ }
+ . = ALIGN(PAGE_SIZE);
+
+ PROVIDE(__global_pointer$ = .);
+
+ .rodata :
+ {
+ PROVIDE(__rodata_start = .);
+ *(.rodata .rodata.*)
+ . = ALIGN(8);
+ PROVIDE(__rodata_end = .);
+ }
+
+ . = ALIGN(PAGE_SIZE);
+
+ .data :
+ {
+ PROVIDE(__data_start = .);
+ *(.sdata .sdata.*)
+ *(.data .data.*)
+ *(.readmostly.data)
+ *(*.data)
+ . = ALIGN(8);
+ PROVIDE(__data_end = .);
+ }
+
+ . = ALIGN(PAGE_SIZE);
+
+ PROVIDE(__stack_start = .);
+ PROVIDE(__stack_end = __stack_start + (PAGE_SIZE * NPROC));
+ PROVIDE(__heap_start = __stack_end);
+}