1 # RISC-V architecture documentation
3 This section contains documentation about coreboot on RISC-V architecture.
6 All stages run in M mode.
8 Payloads have a choice of managing M mode activity: they can control
11 Payloads run from the romstage (i.e. rampayloads) are started in M mode.
12 The payload must, for example, prepare and install its own SBI.
14 Payloads run from the ramstage are started in S mode, and trap delegation
15 will have been done. These payloads rely on the SBI and can not replace it.
17 ## Stage handoff protocol
18 On entry to a stage or payload (including SELF payloads),
19 * all harts are running.
21 * A1 is the pointer to the Flattened Device Tree (FDT).
22 * A2 contains the additional program calling argument:
23 - cbmem_top for ramstage
24 - the address of the payload for opensbi
26 ## Additional payload handoff requirements
27 The location of cbmem should be placed in a node in the FDT.
30 In case the payload doesn't install it's own SBI, like the [RISCV-PK] does,
31 [OpenSBI] can be used instead.
32 It's loaded into RAM after coreboot has finished loading the payload.
33 coreboot then will jump to OpenSBI providing a pointer to the real payload,
34 which OpenSBI will jump to once the SBI is installed.
36 Besides providing SBI it also sets protected memory regions and provides
37 a platform independent console.
39 The OpenSBI code is always run in M mode.
42 Traps are delegated to the payload.
45 At the beginning of each stage, all harts save 0 are spinning in a loop on
46 a semaphore. At the end of the stage harts 1..max are released by changing
49 A possible way to do this is to have a pointer to a struct containing
54 void (*fn)(); // never returns
58 The hart blocks until fn is non-null, and then calls it. If fn returns, we
59 will panic if possible, but behavior is largely undefined.
61 Only hart 0 runs through most of the code in each stage.
63 [RISCV-PK]: https://github.com/riscv/riscv-pk
64 [OpenSBI]: https://github.com/riscv/opensbi