aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-08-03 09:00:58 -0400
committerBrian Cully <bjc@kublai.com>2022-08-03 09:00:58 -0400
commit17cac5fe6421e144619f4828409e8174986f3e3b (patch)
treeeb34f3af60fa95ec7ca53ac9acf0704dd250e07b /src
downloadluchie-17cac5fe6421e144619f4828409e8174986f3e3b.tar.gz
luchie-17cac5fe6421e144619f4828409e8174986f3e3b.zip
Initial bootstrap into ‘main’.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100755
index 0000000..0f77639
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,38 @@
+#![feature(naked_functions)]
+
+#![no_std]
+#![no_main]
+
+use core::arch::asm;
+
+#[no_mangle]
+fn main(_hartid: usize) -> ! {
+ loop {}
+}
+
+#[naked]
+#[link_section = ".text.init"]
+#[export_name = "_start"]
+unsafe extern "C" fn _start() -> ! {
+ // At boot, the hart is in privilege mode M, mstatus fields MIE
+ // and MPRV are 0, the pc is set to a reset vector, the mcause
+ // register specifies why the reset occurred.
+ // c.f.: [^super::rism2] § 3.4 (Reset)
+ asm!(
+ ".option push",
+ ".option norelax",
+ "la gp, __global_pointer$",
+ ".option pop",
+
+ "csrr a0, mhartid",
+ "la sp, _stack_top",
+
+ "j main",
+ options(noreturn)
+ )
+}
+
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}