mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Rework host/target interface to use ecall and proper syscalls instead of CSRs
This commit is contained in:
parent
a305fce466
commit
751f068486
26 changed files with 360 additions and 364 deletions
|
|
@ -9,26 +9,27 @@ use core::panic::PanicInfo;
|
|||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
// startup code
|
||||
global_asm!(include_str!("../../crt0.s"));
|
||||
global_asm!(include_str!("../../crt0.S"));
|
||||
|
||||
fn println(message: &str) {
|
||||
fn syscall(id: u32, n: u32) -> u32 {
|
||||
let mut value;
|
||||
unsafe {
|
||||
asm!(
|
||||
"csrw {i}, {x}",
|
||||
i = const IOREQ_PRINTLN,
|
||||
x = in(reg) message.as_ptr(),
|
||||
asm!("ecall",
|
||||
in("a0") n,
|
||||
in("a7") id,
|
||||
lateout("a1") value,
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
fn println(message: &str) {
|
||||
let addr_value = message.as_ptr() as u32;
|
||||
syscall(IOREQ_PRINTLN, addr_value);
|
||||
}
|
||||
|
||||
fn printd(n: u32) {
|
||||
unsafe {
|
||||
asm!(
|
||||
"csrw {i}, {x}",
|
||||
i = const IOREQ_PRINTD,
|
||||
x = in(reg) n,
|
||||
);
|
||||
}
|
||||
syscall(IOREQ_PRINTD, n);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
@ -36,7 +37,7 @@ pub extern "C" fn main() {
|
|||
for i in 0..10 {
|
||||
printd(i);
|
||||
}
|
||||
println("Hello, world!");
|
||||
println("Hello, world!\0");
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue