-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.rs
95 lines (87 loc) · 1.93 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#![no_std]
#![no_main]
#[macro_use]
extern crate opensbi_rt;
use riscv::register::scause::{Exception as E, Trap};
use riscv::register::{scause, stval};
use trapframe::{GeneralRegs, TrapFrame, UserContext};
use core::arch::asm;
#[no_mangle]
extern "C" fn main() {
unsafe {
trapframe::init();
}
println!("Hello, OpenSBI!");
let mut regs = UserContext {
general: GeneralRegs {
zero: 0,
ra: 1,
sp: 0x8080_0000,
gp: 3,
tp: 4,
t0: 5,
t1: 6,
t2: 7,
s0: 8,
s1: 9,
a0: 10,
a1: 11,
a2: 12,
a3: 13,
a4: 14,
a5: 15,
a6: 16,
a7: 17,
s2: 18,
s3: 19,
s4: 20,
s5: 21,
s6: 22,
s7: 23,
s8: 24,
s9: 25,
s10: 26,
s11: 27,
t3: 28,
t4: 29,
t5: 30,
t6: 31,
},
sstatus: 0xdead_beaf,
sepc: user_entry as usize,
};
println!("Go to user: {:#x?}", regs);
regs.run();
let scause = scause::read();
let stval = stval::read();
println!(
"Back from user: {:?}, stval={:#x}\n{:#x?}",
scause.cause(),
stval,
regs
);
unsafe {
asm!("ebreak");
}
println!("Exit...");
}
#[no_mangle]
extern "C" fn trap_handler(tf: &mut TrapFrame) {
let scause = scause::read();
let stval = stval::read();
match scause.cause() {
Trap::Exception(E::Breakpoint) => {
println!("TRAP: Breakpoint");
tf.sepc += 2;
}
_ => panic!(
"TRAP: scause={:?}, stval={:#x}, tf={:#x?}",
scause.cause(),
stval,
tf
),
}
}
unsafe extern "C" fn user_entry() {
opensbi_rt::sbi::legacy::console_putchar(1);
}