1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-23 18:06:20 +04:00

Change C++ to Rust

This commit is contained in:
Stephen Marz 2019-10-12 21:32:57 -04:00
parent 1411743210
commit e82192913f
3 changed files with 21 additions and 5 deletions

View File

@ -81,7 +81,7 @@ m_trap_vector:
.endr
3:
# Go to C++
# Go to Rust
# usize trap_handler(mepc, mcause)
# trap_handler returns the new mepc
# via a0
@ -182,7 +182,7 @@ s_trap_vector:
.endr
3:
# Go to C++
# Go to Rust
# usize trap_handler(mepc, mcause)
# trap_handler returns the new mepc
# via a0

View File

@ -255,7 +255,7 @@ extern "C" fn kinit() -> usize {
// space application requires services. Since the user space application
// only knows virtual addresses, we have to translate silently behind
// the scenes.
let p = 0x8005_7000 as usize;
let p = 0x0200_0000 as usize;
let m = page::virt_to_phys(&root, p).unwrap_or(0);
println!("Walk 0x{:x} = 0x{:x}", p, m);
// When we return from here, we'll go back to boot.S and switch into
@ -298,6 +298,10 @@ extern "C" fn kmain() {
let sparkle_heart = String::from_utf8(sparkle_heart).unwrap();
println!("String = {}", sparkle_heart);
}
unsafe {
let val = 0x0200_0000 as *mut u32;
val.write_volatile(1);
}
// If we get here, the Box, vec, and String should all be freed since
// they go out of scope. This calls their "Drop" trait.
// Now see if we can read stuff:

View File

@ -3,14 +3,26 @@
// Stephen Marz
// 10 October 2019
extern "C" {
static KERNEL_TABLE: usize;
}
#[no_mangle]
extern "C"
fn s_trap(epc: usize, tval: usize, cause: usize) -> usize {
epc
println!("STRAP (cause: 0x{:x} @ 0x{:x})", cause, epc);
unsafe {
// Switch to kernel's page table.
// table / 4096 Sv39
let satp = KERNEL_TABLE >> 12 | 8 << 60;
asm!("csrw satp, $0" :: "r"(satp));
}
epc + 4
}
#[no_mangle]
extern "C"
fn m_trap(epc: usize, tval: usize, cause: usize, hart: usize) -> usize {
epc
println!("MTRAP (cause: 0x{:x} @ 0x{:x})", cause, epc);
epc + 4
}