2018-09-18 11:29:24 +02:00
|
|
|
# RISC-V architecture documentation
|
2018-09-15 14:21:45 +02:00
|
|
|
|
2018-09-18 11:29:24 +02:00
|
|
|
This section contains documentation about coreboot on RISC-V architecture.
|
2018-09-15 14:21:45 +02:00
|
|
|
|
|
|
|
## Mode usage
|
|
|
|
All stages run in M mode.
|
|
|
|
|
|
|
|
Payloads have a choice of managing M mode activity: they can control
|
|
|
|
everything or nothing.
|
|
|
|
|
|
|
|
Payloads run from the romstage (i.e. rampayloads) are started in M mode.
|
|
|
|
The payload must, for example, prepare and install its own SBI.
|
|
|
|
|
|
|
|
Payloads run from the ramstage are started in S mode, and trap delegation
|
|
|
|
will have been done. These payloads rely on the SBI and can not replace it.
|
|
|
|
|
|
|
|
## Stage handoff protocol
|
2019-06-14 05:16:13 +02:00
|
|
|
On entry to a stage or payload (including SELF payloads),
|
2018-09-15 14:21:45 +02:00
|
|
|
* all harts are running.
|
2018-09-18 11:29:24 +02:00
|
|
|
* A0 is the hart ID.
|
2018-09-15 14:21:45 +02:00
|
|
|
* A1 is the pointer to the Flattened Device Tree (FDT).
|
|
|
|
|
|
|
|
## Additional payload handoff requirements
|
|
|
|
The location of cbmem should be placed in a node in the FDT.
|
|
|
|
|
2019-08-05 08:23:52 +02:00
|
|
|
## OpenSBI
|
|
|
|
In case the payload doesn't install it's own SBI, like the [RISCV-PK] does,
|
|
|
|
[OpenSBI] can be used instead.
|
|
|
|
It's loaded into RAM after coreboot has finished loading the payload.
|
|
|
|
coreboot then will jump to OpenSBI providing a pointer to the real payload,
|
|
|
|
which OpenSBI will jump to once the SBI is installed.
|
|
|
|
|
|
|
|
Besides providing SBI it also sets protected memory regions and provides
|
|
|
|
a platform independent console.
|
|
|
|
|
|
|
|
The OpenSBI code is always run in M mode.
|
|
|
|
|
2018-09-15 14:21:45 +02:00
|
|
|
## Trap delegation
|
2019-08-05 08:23:52 +02:00
|
|
|
Traps are delegated to the payload.
|
2018-09-15 14:21:45 +02:00
|
|
|
|
|
|
|
## SMP within a stage
|
2018-09-18 11:29:24 +02:00
|
|
|
At the beginning of each stage, all harts save 0 are spinning in a loop on
|
|
|
|
a semaphore. At the end of the stage harts 1..max are released by changing
|
|
|
|
the semaphore.
|
2018-09-15 14:21:45 +02:00
|
|
|
|
2018-09-18 11:29:24 +02:00
|
|
|
A possible way to do this is to have a pointer to a struct containing
|
|
|
|
variables, e.g.
|
2018-09-15 14:21:45 +02:00
|
|
|
|
|
|
|
```c
|
|
|
|
struct blocker {
|
|
|
|
void (*fn)(); // never returns
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-09-18 11:29:24 +02:00
|
|
|
The hart blocks until fn is non-null, and then calls it. If fn returns, we
|
|
|
|
will panic if possible, but behavior is largely undefined.
|
2018-09-15 14:21:45 +02:00
|
|
|
|
|
|
|
Only hart 0 runs through most of the code in each stage.
|
2019-08-05 08:23:52 +02:00
|
|
|
|
|
|
|
[RISCV-PK]: https://github.com/riscv/riscv-pk
|
|
|
|
[OpenSBI]: https://github.com/riscv/opensbi
|