SlideShare a Scribd company logo
5
Most read
6
Most read
8
Most read
Introduction to OpenSBI
I’m Nylon Chen
Work for Andes Tech
Hello!
Outline
• SBI
• OpenSBI
• How to add a new SBI call
Ring 2
Ring 1
Ring 0
Least Privileged
Most Privileged
User Space (U-Mode)
Operating System (S-Mode)
Hypervisor(H-Mode)
Firmware(M-Mode)
RISC-V Privilege Modes
X-86 Protection ring
User Space (EL0)
Operating System
(EL1)
Hypervisor(EL2)
Firmware(EL3)
ARM64 Exception Levels
SBI
• SBI stands for RISC-V Supervisor Binary Interface
• The System call type interface layer between Firmware
runtime, M-Mode to Operating system(S-Mode)
• Avoid fragmentation of various OEM silicon providers
specific runtime firmware implementations
• Standard, generic runtime firmware interface
specification across all OSes, different cpu and silicon
platforms
• Specification in SBI v0.2 in usage
• Documentation available at
– https://github.com/riscv/riscv-sbi-doc
App 1 App 2 App 3
ABI ABI ABI
OS (S-Mode)
Open SBI (M-Mode)
SBI
OpenSBI
• Berkeley Boot Loader(BBL)
• OpenSBI is an open-source implementation of the RISC-
V Supervisor Binary Interface (SBI) specifications
• Aimed at providing RUNTIME services in M-mode
• Provides support for reference platforms
• Platforms supports Andes AE350, Ariane FPGA, Kendryte
K210, Nuclei ux600, SiFive U540, Thead c910, QEMU
• firmware implementations
– FW_PAYLOAD
– FW_JUMP
– FW_DYNAMIC
OpenSBI Calling Convention
• S mode traps into M mode using ecall instructions
• Arguments are passed via registers a0-a5
• a7 encodes the SBI extension ID
• a6 encodes the Function ID
• SBI functions must return a pair of values in a0 & a1
• Unsupported SBI returns -2 (SBI_ENOTSUPP in
Linux) [arch/riscv/include/asm/sbi.h]
…
#define SBI_SUCCESS 0
#define SBI_ERR_FAILURE -1
#define SBI_ERR_NOT_SUPPORTED -2
...
struct sbiret {
long error;
long value;
};
SBI Call
[arch/riscv/kernel/sbi.c]
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
unsigned long arg1, unsigned long arg2,…)
{
…
register uintptr_t a6 asm ("a6") = (uintptr_t)(fid);
register uintptr_t a7 asm ("a7") = (uintptr_t)(ext);
asm volatile ("ecall"
: "+r" (a0), "+r" (a1)
: "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
: "memory");
ret.error = a0;
ret.value = a1;
return ret;
}
Linux kernel
User mode
Supervisor mode
Machine mode
mret
sret
ecall
sbi_trap_handl
e
mtvec
SBI Call (Cont’)
[lib/sbi/sbi_ecall.c]
int sbi_ecall_handler(struct sbi_trap_regs *regs)
{
…
unsigned long extension_id = regs->a7
unsigned long func_id = regs->a6;
unsigned long args[6];
args[0] = regs->a0;
…
ext = sbi_ecall_find_extension(extension_id);
if (ext && ext->handle) {
ret = ext->handle(extension_id, func_id,
args, &out_val, &trap);
….
}
regs->a0 = ret;
if (!is_0_1_spec)
regs->a1 = out_val;
}
User mode
Supervisor mode
Machine mode
mret
sret
ecall
mepc
OpenSBI
Legacy SBI Extension
BBL & SBI-v0.1
Function Name Function ID Extension ID Replacement Extension
sbi_set_timer 0 0x00 N/A
sbi_console_putchar 0 0x01 N/A
sbi_console_getchar 0 0x02 N/A
sbi_clear_ipi 0 0x03 N/A
sbi_send_ipi 0 0x04 N/A
sbi_remote_fence_i 0 0x05 N/A
sbi_remote_sfence_vma 0 0x06 N/A
sbi_remote_sfence_vma_asid 0 0x07 N/A
sbi_shutdown 0 0x08 N/A
RESERVED 0x09-0x0F
SBI Base Functionality
Function Name Function ID Extension ID
sbi_get_sbi_spec_version 0 0x10
sbi_get_sbi_impl_id 1 0x10
sbi_get_sbi_impl_version 2 0x10
sbi_probe_extension 3 0x10
sbi_get_mvendorid 4 0x10
sbi_get_marchid 5 0x10
sbi_get_mimpid 6 0x10
Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 ~ 0x09FFFFFF
sbi_get_mvendorid = 0x31e
andes’s extension ID = 0x0900031E
RFENCE Extension
Function Name Function ID Extension ID
sbi_remote_fence_i 0 0x52464E43
sbi_remote_sfence_vma 1 0x52464E43
sbi_remote_sfence_vma_asid 2 0x52464E43
sbi_remote_hfence_gvma_vmid 3 0x52464E43
sbi_remote_hfence_gvma 4 0x52464E43
sbi_remote_hfence_vvma_asid 5 0x52464E43
sbi_remote_hfence_vvma 6 0x52464E43
Function Name Function ID Extension ID
sbi_set_timer 0 0x54494D45
Function Name Function ID Extension ID
sbi_send_ipi 0 0x735049
LinuxKernel>=5.7
Function Name Function ID Extension ID
sbi_hart_start 0 0x48534D
sbi_hart_stop 1 0x48534D
sbi_hart_get_status 2 0x48534D
Timer, IPI, Hart State Management
Extension
How to Add a New SBI Call
• Platform-specific: If the platform has an extension ID, you can direct-
contribute to OpenSBI mailing list
• Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 through
0x09FFFFFF
• Step 1. Check Low bits from mvendorid
–e.g. andes’s mvendorid = 0x31e -> 0x0900031E
• Step 2. Add sbi_ext_id to Linux
• Step 3. Add a new enum about platform SBI call’s number to Linux
• Step 4. Add platform’s SBI function call by sbi_ecall()
–e.g. sbi_ecall(Platform’s sbi_ext_id, Platform’s sbi number, 0, 0, 0…);
• Step 5. Add hook function to your platform’s SBI handler
–e.g. .vendor_ext_provider = platform_vendor_ext_provider
Add Extension & Function ID
[arch/riscv/include/asm/sbi.h]
enum sbi_ext_id {
#ifdef CONFIG_RISCV_SBI_V01
SBI_EXT_0_1_SET_TIMER = 0x0,
SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1,
SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2,
SBI_EXT_0_1_CLEAR_IPI = 0x3,
SBI_EXT_0_1_SEND_IPI = 0x4,
SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6,
SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7,
SBI_EXT_0_1_SHUTDOWN = 0x8,
#endif
SBI_EXT_BASE = 0x10,
SBI_EXT_TIME = 0x54494D45,
SBI_EXT_IPI = 0x735049,
SBI_EXT_RFENCE = 0x52464E43,
SBI_EXT_HSM = 0x48534D,
SBI_EXT_ANDES = 0x0900031E,
};
enum sbi_ext_andes_fid {
SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS = 0
….
}
[include/sbi/sbi_ecall_interface.h]
/* SBI Extension IDs */
#define SBI_EXT_0_1_SET_TIMER 0x0
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2
#define SBI_EXT_BASE 0x10
#define SBI_EXT_TIME 0x54494D45
#define SBI_EXT_IPI 0x735049
#define SBI_EXT_RFENCE 0x52464E43
#define SBI_EXT_HSM 0x48534D
….
/* SBI function IDs for HSM extension */
#define SBI_EXT_HSM_HART_START 0x0
#define SBI_EXT_HSM_HART_STOP 0x1
#define SBI_EXT_HSM_HART_GET_STATUS 0x2
…
#define SBI_EXT_VENDOR_START 0x09000000
#define SBI_EXT_VENDOR_END 0x09FFFFFF
Linux kernel
OpenSBI
R
Add Hook Function to SBI Handler
[platform/andes/ae350/platform.c]
…
/* Vendor-Specific SBI handler */
static int ae350_vendor_ext_provider(long extid, long funcid,
unsigned long *args, unsigned long *out_value,
struct sbi_trap_info *out_trap)
{
int ret = 0;
switch (funcid) {
case SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS:
*out_value = csr_read(CSR_MCACHECTL);
break;
…
default:
sbi_printf("Unsupported vendor sbi call : %ldn", funcid);
}
…
return ret;
}
const struct sbi_platform_operations platform_ops = {
…
.vendor_ext_provider = ae350_vendor_ext_provider
…
}
OpenSBI
R
How to add a new SBI call
• non-platform-specific:
–Think about whether it fits into an existing extension or
else create a new extension
–Think about all of the details of the behaviour and
error cases
–Document that in a patch for the SBI document
–Send it to the (Mailing List] (You need to be subscribed
to be able to post) and create a PR on GitHub
–Argue for it
• How to decide Extension ID
–TIME: 0x54, 0x49, 0x4D, 0x45 - by ASCII
How to add a new SBI call
References
• Working experience on RISC-V
• SBI
• OpenSBI
• Atish Patra “RISC-V Boot Process: One step at a time”
• Atish Patra “Fixing the boot process in RISC-V”
• Anup Patel “Xvisor: Embedded Hypervisor for RISC-V”
• Anup Patel “OpenSBI Deep Dive”
• Jagan Teki “An Introduction to RISC-V Boot flow: Overview, Blob vs
Blobfree standards”

More Related Content

PDF
Block Drivers
PDF
LCU14 302- How to port OP-TEE to another platform
PDF
Linux Porting
PDF
Arm device tree and linux device drivers
PDF
Trusted firmware deep_dive_v1.0_
PPTX
Linux I2C
PDF
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
PDF
Fun with Network Interfaces
Block Drivers
LCU14 302- How to port OP-TEE to another platform
Linux Porting
Arm device tree and linux device drivers
Trusted firmware deep_dive_v1.0_
Linux I2C
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
Fun with Network Interfaces

What's hot (20)

PPTX
Linux kernel debugging
PPTX
Linux Initialization Process (2)
PDF
Network Drivers
PPTX
An Introduction to RISC-V bootflow
PDF
PCI Drivers
PDF
from Binary to Binary: How Qemu Works
PDF
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
PDF
ARM Trusted FirmwareのBL31を単体で使う!
PDF
BusyBox for Embedded Linux
PDF
Linux Kernel - Virtual File System
PDF
Run Qt on Linux embedded systems using Yocto
PDF
Splash screen for Embedded Linux 101: How to customize your boot sequence
PPT
linux device driver
PDF
Introduction to Linux Drivers
PDF
USB Drivers
PPT
Linux Kernel Image
PDF
Decompressed vmlinux: linux kernel initialization from page table configurati...
PPTX
The TCP/IP Stack in the Linux Kernel
PDF
Qemu Introduction
PPTX
Linux PCI device driver
Linux kernel debugging
Linux Initialization Process (2)
Network Drivers
An Introduction to RISC-V bootflow
PCI Drivers
from Binary to Binary: How Qemu Works
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
ARM Trusted FirmwareのBL31を単体で使う!
BusyBox for Embedded Linux
Linux Kernel - Virtual File System
Run Qt on Linux embedded systems using Yocto
Splash screen for Embedded Linux 101: How to customize your boot sequence
linux device driver
Introduction to Linux Drivers
USB Drivers
Linux Kernel Image
Decompressed vmlinux: linux kernel initialization from page table configurati...
The TCP/IP Stack in the Linux Kernel
Qemu Introduction
Linux PCI device driver
Ad

Similar to Introduction to open_sbi (20)

PDF
The future of RISC-V Supervisor Binary Interface(SBI)
PDF
The role of_open_source_firmware_in_risc-v
PDF
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
PPTX
RISC-V Boot Process: One Step at a Time
PDF
ISA_databook_for_verification_121414.pdf
PDF
Xvisor: embedded and lightweight hypervisor
PDF
BlueHat v18 || Hardening hyper-v through offensive security research
PPTX
Linux Improvements in Memory Corruption Based Protections
PPTX
Rsockets ofa12
PDF
XS Boston 2008 Paravirt Ops in Linux IA64
ODP
Abus at a glance
PPTX
Memory Corruption: from sandbox to SMM
PPTX
Slideshare - PCIe
PPTX
C++ and Assembly: Debugging and Reverse Engineering
PDF
Introduction to the IBM AS/400
PDF
What C and C++ Can Do and When Do You Need Assembly? by Alexander Krizhanovsky
PDF
D1 t2 jonathan brossard - breaking virtualization by switching to virtual 8...
PDF
HW-SW Co-Verification: A Constrained Random Approach
PPT
Slimline Open Firmware
PDF
Blackfin Device Drivers
The future of RISC-V Supervisor Binary Interface(SBI)
The role of_open_source_firmware_in_risc-v
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
RISC-V Boot Process: One Step at a Time
ISA_databook_for_verification_121414.pdf
Xvisor: embedded and lightweight hypervisor
BlueHat v18 || Hardening hyper-v through offensive security research
Linux Improvements in Memory Corruption Based Protections
Rsockets ofa12
XS Boston 2008 Paravirt Ops in Linux IA64
Abus at a glance
Memory Corruption: from sandbox to SMM
Slideshare - PCIe
C++ and Assembly: Debugging and Reverse Engineering
Introduction to the IBM AS/400
What C and C++ Can Do and When Do You Need Assembly? by Alexander Krizhanovsky
D1 t2 jonathan brossard - breaking virtualization by switching to virtual 8...
HW-SW Co-Verification: A Constrained Random Approach
Slimline Open Firmware
Blackfin Device Drivers
Ad

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
top salesforce developer skills in 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Softaken Excel to vCard Converter Software.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
top salesforce developer skills in 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Odoo Companies in India – Driving Business Transformation.pdf
Nekopoi APK 2025 free lastest update
Understanding Forklifts - TECH EHS Solution
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms I-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo POS Development Services by CandidRoot Solutions
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

Introduction to open_sbi

  • 2. I’m Nylon Chen Work for Andes Tech Hello!
  • 3. Outline • SBI • OpenSBI • How to add a new SBI call
  • 4. Ring 2 Ring 1 Ring 0 Least Privileged Most Privileged User Space (U-Mode) Operating System (S-Mode) Hypervisor(H-Mode) Firmware(M-Mode) RISC-V Privilege Modes X-86 Protection ring User Space (EL0) Operating System (EL1) Hypervisor(EL2) Firmware(EL3) ARM64 Exception Levels
  • 5. SBI • SBI stands for RISC-V Supervisor Binary Interface • The System call type interface layer between Firmware runtime, M-Mode to Operating system(S-Mode) • Avoid fragmentation of various OEM silicon providers specific runtime firmware implementations • Standard, generic runtime firmware interface specification across all OSes, different cpu and silicon platforms • Specification in SBI v0.2 in usage • Documentation available at – https://github.com/riscv/riscv-sbi-doc App 1 App 2 App 3 ABI ABI ABI OS (S-Mode) Open SBI (M-Mode) SBI
  • 6. OpenSBI • Berkeley Boot Loader(BBL) • OpenSBI is an open-source implementation of the RISC- V Supervisor Binary Interface (SBI) specifications • Aimed at providing RUNTIME services in M-mode • Provides support for reference platforms • Platforms supports Andes AE350, Ariane FPGA, Kendryte K210, Nuclei ux600, SiFive U540, Thead c910, QEMU • firmware implementations – FW_PAYLOAD – FW_JUMP – FW_DYNAMIC
  • 7. OpenSBI Calling Convention • S mode traps into M mode using ecall instructions • Arguments are passed via registers a0-a5 • a7 encodes the SBI extension ID • a6 encodes the Function ID • SBI functions must return a pair of values in a0 & a1 • Unsupported SBI returns -2 (SBI_ENOTSUPP in Linux) [arch/riscv/include/asm/sbi.h] … #define SBI_SUCCESS 0 #define SBI_ERR_FAILURE -1 #define SBI_ERR_NOT_SUPPORTED -2 ... struct sbiret { long error; long value; };
  • 8. SBI Call [arch/riscv/kernel/sbi.c] struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2,…) { … register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); asm volatile ("ecall" : "+r" (a0), "+r" (a1) : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) : "memory"); ret.error = a0; ret.value = a1; return ret; } Linux kernel User mode Supervisor mode Machine mode mret sret ecall sbi_trap_handl e mtvec
  • 9. SBI Call (Cont’) [lib/sbi/sbi_ecall.c] int sbi_ecall_handler(struct sbi_trap_regs *regs) { … unsigned long extension_id = regs->a7 unsigned long func_id = regs->a6; unsigned long args[6]; args[0] = regs->a0; … ext = sbi_ecall_find_extension(extension_id); if (ext && ext->handle) { ret = ext->handle(extension_id, func_id, args, &out_val, &trap); …. } regs->a0 = ret; if (!is_0_1_spec) regs->a1 = out_val; } User mode Supervisor mode Machine mode mret sret ecall mepc OpenSBI
  • 10. Legacy SBI Extension BBL & SBI-v0.1 Function Name Function ID Extension ID Replacement Extension sbi_set_timer 0 0x00 N/A sbi_console_putchar 0 0x01 N/A sbi_console_getchar 0 0x02 N/A sbi_clear_ipi 0 0x03 N/A sbi_send_ipi 0 0x04 N/A sbi_remote_fence_i 0 0x05 N/A sbi_remote_sfence_vma 0 0x06 N/A sbi_remote_sfence_vma_asid 0 0x07 N/A sbi_shutdown 0 0x08 N/A RESERVED 0x09-0x0F
  • 11. SBI Base Functionality Function Name Function ID Extension ID sbi_get_sbi_spec_version 0 0x10 sbi_get_sbi_impl_id 1 0x10 sbi_get_sbi_impl_version 2 0x10 sbi_probe_extension 3 0x10 sbi_get_mvendorid 4 0x10 sbi_get_marchid 5 0x10 sbi_get_mimpid 6 0x10 Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 ~ 0x09FFFFFF sbi_get_mvendorid = 0x31e andes’s extension ID = 0x0900031E
  • 12. RFENCE Extension Function Name Function ID Extension ID sbi_remote_fence_i 0 0x52464E43 sbi_remote_sfence_vma 1 0x52464E43 sbi_remote_sfence_vma_asid 2 0x52464E43 sbi_remote_hfence_gvma_vmid 3 0x52464E43 sbi_remote_hfence_gvma 4 0x52464E43 sbi_remote_hfence_vvma_asid 5 0x52464E43 sbi_remote_hfence_vvma 6 0x52464E43
  • 13. Function Name Function ID Extension ID sbi_set_timer 0 0x54494D45 Function Name Function ID Extension ID sbi_send_ipi 0 0x735049 LinuxKernel>=5.7 Function Name Function ID Extension ID sbi_hart_start 0 0x48534D sbi_hart_stop 1 0x48534D sbi_hart_get_status 2 0x48534D Timer, IPI, Hart State Management Extension
  • 14. How to Add a New SBI Call • Platform-specific: If the platform has an extension ID, you can direct- contribute to OpenSBI mailing list • Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 through 0x09FFFFFF • Step 1. Check Low bits from mvendorid –e.g. andes’s mvendorid = 0x31e -> 0x0900031E • Step 2. Add sbi_ext_id to Linux • Step 3. Add a new enum about platform SBI call’s number to Linux • Step 4. Add platform’s SBI function call by sbi_ecall() –e.g. sbi_ecall(Platform’s sbi_ext_id, Platform’s sbi number, 0, 0, 0…); • Step 5. Add hook function to your platform’s SBI handler –e.g. .vendor_ext_provider = platform_vendor_ext_provider
  • 15. Add Extension & Function ID [arch/riscv/include/asm/sbi.h] enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5, SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, SBI_EXT_0_1_SHUTDOWN = 0x8, #endif SBI_EXT_BASE = 0x10, SBI_EXT_TIME = 0x54494D45, SBI_EXT_IPI = 0x735049, SBI_EXT_RFENCE = 0x52464E43, SBI_EXT_HSM = 0x48534D, SBI_EXT_ANDES = 0x0900031E, }; enum sbi_ext_andes_fid { SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS = 0 …. } [include/sbi/sbi_ecall_interface.h] /* SBI Extension IDs */ #define SBI_EXT_0_1_SET_TIMER 0x0 #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 #define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 #define SBI_EXT_BASE 0x10 #define SBI_EXT_TIME 0x54494D45 #define SBI_EXT_IPI 0x735049 #define SBI_EXT_RFENCE 0x52464E43 #define SBI_EXT_HSM 0x48534D …. /* SBI function IDs for HSM extension */ #define SBI_EXT_HSM_HART_START 0x0 #define SBI_EXT_HSM_HART_STOP 0x1 #define SBI_EXT_HSM_HART_GET_STATUS 0x2 … #define SBI_EXT_VENDOR_START 0x09000000 #define SBI_EXT_VENDOR_END 0x09FFFFFF Linux kernel OpenSBI R
  • 16. Add Hook Function to SBI Handler [platform/andes/ae350/platform.c] … /* Vendor-Specific SBI handler */ static int ae350_vendor_ext_provider(long extid, long funcid, unsigned long *args, unsigned long *out_value, struct sbi_trap_info *out_trap) { int ret = 0; switch (funcid) { case SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS: *out_value = csr_read(CSR_MCACHECTL); break; … default: sbi_printf("Unsupported vendor sbi call : %ldn", funcid); } … return ret; } const struct sbi_platform_operations platform_ops = { … .vendor_ext_provider = ae350_vendor_ext_provider … } OpenSBI R
  • 17. How to add a new SBI call • non-platform-specific: –Think about whether it fits into an existing extension or else create a new extension –Think about all of the details of the behaviour and error cases –Document that in a patch for the SBI document –Send it to the (Mailing List] (You need to be subscribed to be able to post) and create a PR on GitHub –Argue for it • How to decide Extension ID –TIME: 0x54, 0x49, 0x4D, 0x45 - by ASCII
  • 18. How to add a new SBI call
  • 19. References • Working experience on RISC-V • SBI • OpenSBI • Atish Patra “RISC-V Boot Process: One step at a time” • Atish Patra “Fixing the boot process in RISC-V” • Anup Patel “Xvisor: Embedded Hypervisor for RISC-V” • Anup Patel “OpenSBI Deep Dive” • Jagan Teki “An Introduction to RISC-V Boot flow: Overview, Blob vs Blobfree standards”