HomeFreeBSD

MFC 354719,354720,354721,354722,357480: OpenSBI support.

Description

MFC 354719,354720,354721,354722,357480: OpenSBI support.

354719:
RISC-V: pass arg6 in sbi_call

Allow for an additional argument to sbi_call which will be passed in a6.
This is required for SBI spec 0.2 support, as a6 will indicate the SBI
function ID.

While here, introduce some macros to clean up the calls.

354720:
RISC-V: add support for SBI spec v0.2

The Supervisor Binary Interface (SBI) specification v0.2 is a backwards
incompatible update to the SBI call interface for kernels running in
supervisor mode. The goal of this update was to make it easier for new
and optional functionality to be added to the SBI.

SBI functions are now called by passing an "extension ID" and a
"function ID" which are passed in a7 and a6 respectively. SBI calls
will also return an error and value in the following struct:

struct sbi_ret {

long error;
long value;

}

This version introduces several new functions under the "base"
extension. It is expected that all SBI implementations >= 0.2 will
support this base set of functions, as they implement some essential
services such as obtaining the SBI version, CPU implementation info, and
extension probing.

Existing SBI functions have been designated as "legacy". For the time
being they will remain implemented, but it is expected that in the
future their functionality will be duplicated or replaced by new SBI
extensions. Each legacy function has been assigned its own extension ID,
and for now we simply probe and assert for their existence.

Compatibility with legacy SBI implementations (such as BBL) is
maintained by checking the output of sbi_get_spec_version(). This
function is guaranteed to succeed by the new spec, but will return an
error in legacy implementations. We use this as an indicator of whether
or not we can rely on the new SBI base extensions.

For further info on the Supervisor Binary Interface, see:
https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc

354721:
Add missing files from r354720

354722:
RISC-V: Print SBI info at startup

SBI version 0.2 introduces functions for obtaining the details of the
SBI implementation, such as version and implemntation ID. Print this
info at startup when it is available.

357480:
Set the LMA of the riscv kernel to the OpenSBI jump target by default

This allows us to boot FreeBSD RISCV on QEMU using the -kernel command line
options. When using that option, QEMU maps the kernel ELF file to the
addresses specified in the LMAs in the program headers.

Since version 4.2 QEMU ships with OpenSBI fw_jump by default so this allows
booting FreeBSD using the following command line:
qemu-system-riscv64 -bios default -kernel /.../boot/kernel/kernel -nographic -M virt

Without this change the -kernel option cannot be used since the LMAs start
at address zero and QEMU already maps a ROM to these low physical addresses.

For targets that require a different kernel LMA the make variable
KERNEL_LMA can be overwritten in the config file. For example, adding
makeoptions KERNEL_LMA=0xc0200000 will create an ELF file that will be
loaded at 0xc0200000.

Before:
There are 4 program headers, starting at offset 64

Program Headers:

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x001000 0xffffffc000000000 0x0000000000000000 0x75e598 0x8be318 RWE 0x1000
DYNAMIC        0x71fb20 0xffffffc00071eb20 0x000000000071eb20 0x000100 0x000100 RW  0x8
GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
NOTE           0x693400 0xffffffc000692400 0x0000000000692400 0x000024 0x000024 R   0x4

After:

There are 4 program headers, starting at offset 64

Program Headers:

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x001000 0xffffffc000000000 0x0000000080200000 0x734198 0x893e18 RWE 0x1000
DYNAMIC        0x6f7810 0xffffffc0006f6810 0x00000000808f6810 0x000100 0x000100 RW  0x8
GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
NOTE           0x66ca70 0xffffffc00066ba70 0x000000008086ba70 0x000024 0x000024 R   0x4

Details

Provenance
jhbAuthored on
Parents
rS360807: Fix the sys.geom.class.multipath.misc.fail_on_error test on stable/12
Branches
Unknown
Tags
Unknown