RISC-V: Difference between revisions

678 bytes added ,  23 days ago
no edit summary
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 53:
==== Changing privilege ====
In RISC-V, the privilege mode of a ''hart'' can be changed by:
* A trap or interrupt innin the thread caught by a higher privilege mode
* The execution of the `mret` or `sret` instructions
* Intervention by a hardware debugger
* A hart being reset (it always starts in Machine mode)
When a trap or interrupt occurs, the ''hart'' determines which privilege mode will catch this exception and jump to the address stored in <code>mtvec</code> or <code>stvec</code>, possibly with an offset, for exceptions caught by Machine and Supervisor mode respectively. This mode with an offset into an [https://en.wikipedia.org/wiki/Interrupt_vector_table interrupt vector table] is called vectored interrupts. RISC-V traps do not use an offset. This has the side effect of making the interrupt vector table a table of jump instructions as opposed to a table of addresses.
The `mret` and `sret` instructions update the privilege mode to that specified by `mstatus` or `sstatus` before resuming in said mode at `mepc` or `sepc` respectively. These instructions are intended for returning from trap/interrupt handlers and explicit privilege mode switches.
 
The `<code>mret`</code> and `<code>sret`</code> instructions update the privilege mode to that specified by `<code>mstatus`</code> or `<code>sstatus`</code> respectively before resuming in said mode at `the address stored in <code>mepc`</code> or `<code>sepc`</code> respectively. These instructions are intended for returning from trap/interrupt handlers and explicit privilege mode switches.
 
 
 
3

edits