diff options
| author | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2023-12-13 01:38:14 +0100 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2024-04-02 23:17:31 +0200 |
| commit | 36137438446c1754a522c5b3cc3aff92c43ac1ee (patch) | |
| tree | f7358ef0aec7023321e52e116f94fba95e52611f /src/arch/riscv64 | |
X86/X86_64 debug/release WORKING
riscv64 WORKING uart
idk
Diffstat (limited to 'src/arch/riscv64')
| -rw-r--r-- | src/arch/riscv64/boot/entry.S | 37 | ||||
| -rw-r--r-- | src/arch/riscv64/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/arch/riscv64/io/uart.rs | 27 | ||||
| -rw-r--r-- | src/arch/riscv64/mod.rs | 2 |
4 files changed, 68 insertions, 0 deletions
diff --git a/src/arch/riscv64/boot/entry.S b/src/arch/riscv64/boot/entry.S new file mode 100644 index 0000000..f5fa092 --- /dev/null +++ b/src/arch/riscv64/boot/entry.S @@ -0,0 +1,37 @@ +.section .init + +.option norvc + +.type start, @function +.global start +start: + .cfi_startproc + +.option push +.option norelax + la gp, global_pointer +.option pop + + /* Reset satp */ + csrw satp, zero + + /* Setup stack */ + la sp, stack_top + + /* Clear the BSS section */ + la t5, bss_start + la t6, bss_end +bss_clear: + sd zero, (t5) + addi t5, t5, 8 + bltu t5, t6, bss_clear + + la t0, kernel_main + csrw sepc, t0 + + /* Jump to kernel! */ + tail kernel_main + + .cfi_endproc + +.end diff --git a/src/arch/riscv64/io/mod.rs b/src/arch/riscv64/io/mod.rs new file mode 100644 index 0000000..6d91cab --- /dev/null +++ b/src/arch/riscv64/io/mod.rs @@ -0,0 +1,2 @@ +mod uart; +pub use uart::*; diff --git a/src/arch/riscv64/io/uart.rs b/src/arch/riscv64/io/uart.rs new file mode 100644 index 0000000..7aafeef --- /dev/null +++ b/src/arch/riscv64/io/uart.rs @@ -0,0 +1,27 @@ +use core::fmt; +use core::fmt::Write; + +pub fn _print(args: fmt::Arguments) { + // Not thread safe but no dependencies + let mut stdout = Stdout; + fmt::write(&mut stdout, args); +} + +struct Stdout; +impl Write for Stdout { + fn write_str(&mut self, s: &str) -> fmt::Result { + print_string(s); + Ok(()) + } +} + +pub fn print_string(s: &str) { + let uart_base = 0x10000000 as *mut u8; + while unsafe { uart_base.add(5).read_volatile() } & 0x20 == 0 {} + + for c in s.chars() { + unsafe { + uart_base.write_volatile(c as u8); + } + } +} diff --git a/src/arch/riscv64/mod.rs b/src/arch/riscv64/mod.rs new file mode 100644 index 0000000..608d4e1 --- /dev/null +++ b/src/arch/riscv64/mod.rs @@ -0,0 +1,2 @@ +mod io; +pub use io::*; |
