aboutsummaryrefslogtreecommitdiff
path: root/src/arch/riscv64/io
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2023-12-13 01:38:14 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2024-04-02 23:17:31 +0200
commit36137438446c1754a522c5b3cc3aff92c43ac1ee (patch)
treef7358ef0aec7023321e52e116f94fba95e52611f /src/arch/riscv64/io
Initial commitHEADmaster
X86/X86_64 debug/release WORKING riscv64 WORKING uart idk
Diffstat (limited to 'src/arch/riscv64/io')
-rw-r--r--src/arch/riscv64/io/mod.rs2
-rw-r--r--src/arch/riscv64/io/uart.rs27
2 files changed, 29 insertions, 0 deletions
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);
+ }
+ }
+}