Prechádzať zdrojové kódy

Add write function for {u,s}{cause,tval} registers

luojia65 4 rokov pred
rodič
commit
fec65d8e37

+ 36 - 0
src/register/scause.rs

@@ -115,3 +115,39 @@ impl Scause {
 }
 
 read_csr_as!(Scause, 0x142, __read_scause);
+write_csr!(0x142, __write_scause);
+
+/// Writes the CSR
+pub unsafe fn write(bits: usize) {
+    _write(bits)
+}
+
+/// Set supervisor cause register to corresponding cause.
+pub unsafe fn set(cause: Trap) {
+    let bits = match cause {
+        Trap::Interrupt(i) => match i {
+            Interrupt::UserSoft => 0,
+            Interrupt::SupervisorSoft => 1,
+            Interrupt::UserTimer => 4,
+            Interrupt::SupervisorTimer => 5,
+            Interrupt::UserExternal => 8,
+            Interrupt::SupervisorExternal => 9,
+            Interrupt::Unknown => panic!("unknown interrupt")
+        }, 
+        Trap::Exception(e) => (match e {
+            Exception::InstructionMisaligned => 0,
+            Exception::InstructionFault => 1,
+            Exception::IllegalInstruction => 2,
+            Exception::Breakpoint => 3,
+            Exception::LoadFault => 5,
+            Exception::StoreMisaligned => 6,
+            Exception::StoreFault => 7,
+            Exception::UserEnvCall => 8,
+            Exception::InstructionPageFault => 12,
+            Exception::LoadPageFault => 13,
+            Exception::StorePageFault => 15,
+            Exception::Unknown => panic!("unknown exception")
+        } | (1 << (size_of::<usize>() * 8 - 1))),
+    };
+    _write(bits);
+}

+ 6 - 0
src/register/stval.rs

@@ -1,3 +1,9 @@
 //! stval register
 
 read_csr_as_usize!(0x143, __read_stval);
+write_csr!(0x143, __write_stval);
+
+/// Writes the CSR
+pub unsafe fn write(bits: usize) {
+    _write(bits)
+}

+ 6 - 0
src/register/ucause.rs

@@ -15,3 +15,9 @@ impl Ucause {
 }
 
 read_csr_as!(Ucause, 0x042, __read_ucause);
+write_csr!(0x042, __write_ucause);
+
+/// Writes the CSR
+pub unsafe fn write(bits: usize) {
+    _write(bits)
+}

+ 6 - 0
src/register/utval.rs

@@ -1,3 +1,9 @@
 //! utval register
 
 read_csr_as_usize!(0x043, __read_utval);
+write_csr!(0x043, __write_utval);
+
+/// Writes the CSR
+pub unsafe fn write(bits: usize) {
+    _write(bits)
+}