User:Demindiro/SBI

From OSDev.wiki
Revision as of 04:54, 14 August 2021 by osdev>Demindiro (Add to RISC-V category)
Jump to navigation Jump to search
This page is a stub.
You can help the wiki by accurately adding more contents to it.
This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.


The RISC-V SBI (Supervisor Binary Interface) defines a common interface for RISC-V platforms for OSes. It hides platform-specific implementation details such that OSes are more portable.

Notably, it adds methods to facilitate IPI (Inter-Processor Interrupts).

The reference implementation is OpenSBI.

OpenSBI on QEMU

To run OpenSBI on QEMU, download the source and compile with make PLATFORM=generic CROSS_COMPILE=riscv64-your-os-. Then add -bios path/to/opensbi/build/platform/generic/firmware/fw_jump.bin

fw_jump vs fw_payload vs fw_dynamic

  • fw_jump should be used in conjunction with QEMU's -kernel option
  • fw_payload should directly include the kernel binary.
  • fw_dynamic should be used if you use another bootloader that passes more information to OpenSBI.


Interface

The calling convention is the RISC-V ELF psABI. This means you'll need to save caller-saved registers!

The main difference is that the EID (Extension ID) goes into a7 and FID (Function ID) into a6.


Extensions

Avoid the legacy extensions (EID 0x00 - 0xFF) as those are deprecated.

Timer (0x54494D45)

The timer extension has a single function sbi_set_timer with FID 0x00. It takes a single uint64_t argument.

Before calling it, ensure that STIE is cleared! Otherwise you may get sporadic interrupts. i.e:

li	s0, 1 << 5
csrc	sie, s0
li	a7, 0x54494d45
li	a6, 0
ecall	
csrs	sie, s0


See Also

External Links