diff options
| author | Michael Brown | 2025-05-25 10:28:11 +0200 |
|---|---|---|
| committer | Michael Brown | 2025-05-25 11:43:39 +0200 |
| commit | 8d88870da59e93202d1cff4504f2fd2d2fa139cd (patch) | |
| tree | f74931b3fbc35e6766c5feb827831dbae6a8868b /src/arch/riscv/include | |
| parent | [memmap] Rename addr/last fields to min/max for clarity (diff) | |
| download | ipxe-8d88870da59e93202d1cff4504f2fd2d2fa139cd.tar.gz ipxe-8d88870da59e93202d1cff4504f2fd2d2fa139cd.tar.xz ipxe-8d88870da59e93202d1cff4504f2fd2d2fa139cd.zip | |
[riscv] Support older SBI implementations
Fall back to attempting the legacy SBI console and shutdown calls if
the standard calls fail.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/riscv/include')
| -rw-r--r-- | src/arch/riscv/include/ipxe/sbi.h | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/src/arch/riscv/include/ipxe/sbi.h b/src/arch/riscv/include/ipxe/sbi.h index 44685cc87..aaab3a355 100644 --- a/src/arch/riscv/include/ipxe/sbi.h +++ b/src/arch/riscv/include/ipxe/sbi.h @@ -73,7 +73,7 @@ sbi_ecall_0 ( int eid, int fid ) { * * @v eid Extension ID * @v fid Function ID - * @v param0 Parameter 0 + * @v p0 Parameter 0 * @ret ret Return value */ static inline __attribute__ (( always_inline )) struct sbi_return @@ -98,8 +98,8 @@ sbi_ecall_1 ( int eid, int fid, unsigned long p0 ) { * * @v eid Extension ID * @v fid Function ID - * @v param0 Parameter 0 - * @v param1 Parameter 1 + * @v p0 Parameter 0 + * @v p1 Parameter 1 * @ret ret Return value */ static inline __attribute__ (( always_inline )) struct sbi_return @@ -124,9 +124,9 @@ sbi_ecall_2 ( int eid, int fid, unsigned long p0, unsigned long p1 ) { * * @v eid Extension ID * @v fid Function ID - * @v param0 Parameter 0 - * @v param1 Parameter 1 - * @v param2 Parameter 2 + * @v p0 Parameter 0 + * @v p1 Parameter 1 + * @v p2 Parameter 2 * @ret ret Return value */ static inline __attribute__ (( always_inline )) struct sbi_return @@ -148,9 +148,51 @@ sbi_ecall_3 ( int eid, int fid, unsigned long p0, unsigned long p1, return ret; } +/** + * Call supervisor with no parameters + * + * @v fid Legacy function ID + * @ret ret Return value + */ +static inline __attribute__ (( always_inline )) long +sbi_legacy_ecall_0 ( int fid ) { + register unsigned long a7 asm ( "a7" ) = ( ( long ) fid ); + register unsigned long a0 asm ( "a0" ); + + __asm__ __volatile__ ( "ecall" + : "=r" ( a0 ) + : "r" ( a7 ) + : "memory" ); + return a0; +} + +/** + * Call supervisor with one parameter + * + * @v fid Legacy function ID + * @v p0 Parameter 0 + * @ret ret Return value + */ +static inline __attribute__ (( always_inline )) long +sbi_legacy_ecall_1 ( int fid, unsigned long p0 ) { + register unsigned long a7 asm ( "a7" ) = ( ( long ) fid ); + register unsigned long a0 asm ( "a0" ) = p0; + + __asm__ __volatile__ ( "ecall" + : "+r" ( a0 ) + : "r" ( a7 ) + : "memory" ); + return a0; +} + /** Convert an SBI error code to an iPXE status code */ #define ESBI( error ) EPLATFORM ( EINFO_EPLATFORM, error ) +/** Legacy extensions */ +#define SBI_LEGACY_PUTCHAR 0x01 /**< Console Put Character */ +#define SBI_LEGACY_GETCHAR 0x02 /**< Console Get Character */ +#define SBI_LEGACY_SHUTDOWN 0x08 /**< System Shutdown */ + /** System reset extension */ #define SBI_SRST SBI_EID ( 'S', 'R', 'S', 'T' ) #define SBI_SRST_SYSTEM_RESET 0x00 /**< Reset system */ |
