[riscv] Move prefix system reset code to libprefix.S

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-05-07 13:07:56 +01:00
parent 764183504c
commit 72c81419b1
2 changed files with 43 additions and 16 deletions

View File

@@ -608,3 +608,45 @@ enable_paging_32_done:
/* Ensure that transition code did not cross an alignment boundary */
.section ".bss.enable_paging_32_xcheck", "aw", @nobits
.org . + enable_paging_32_xalign - enable_paging_32_xlen
/*****************************************************************************
*
* Reset (or lock up) system
*
*****************************************************************************
*
* Reset via system via SBI, as a means of exiting from a prefix that
* has no other defined exit path. If the reset fails, lock up the
* system since there is nothing else that can sensibly be done.
*
* This function does not require a valid stack pointer.
*
* Parameters: none
*
* Returns: n/a (does not return)
*
*/
/* SBI system reset extension */
#define SBI_SRST ( ( 'S' << 24 ) | ( 'R' << 16 ) | ( 'S' << 8 ) | 'T' )
#define SBI_SRST_SYSTEM_RESET 0x00
#define SBI_RESET_COLD 0x00000001
.section ".prefix.reset_system", "ax", @progbits
.globl reset_system
reset_system:
/* Register usage: irrelevant (does not return) */
progress "\niPXE->SBI reset\n"
/* Attempt reset */
li a7, SBI_SRST
li a6, SBI_SRST_SYSTEM_RESET
li a0, SBI_RESET_COLD
mv a1, zero
ecall
/* If reset failed, lock the system */
progress "(reset failed)\n"
1: wfi
j 1b
.size reset_system, . - reset_system

View File

@@ -32,11 +32,6 @@
.section ".note.GNU-stack", "", @progbits
.text
/* SBI system reset extension */
#define SBI_SRST ( ( 'S' << 24 ) | ( 'R' << 16 ) | ( 'S' << 8 ) | 'T' )
#define SBI_SRST_SYSTEM_RESET 0x00
#define SBI_RESET_COLD 0x00000001
/* ELF machine type */
#define EM_RISCV 243
@@ -104,17 +99,7 @@ _sbi_start:
* Attempt a system reset, since there is nothing else we can
* viably do at this point.
*/
progress "\niPXE->SBI reset\n"
li a7, SBI_SRST
li a6, SBI_SRST_SYSTEM_RESET
li a0, SBI_RESET_COLD
mv a1, zero
ecall
/* If reset failed, lock the system */
progress "(reset failed)\n"
1: wfi
j 1b
j reset_system
.size _sbi_start, . - _sbi_start
/* File split information for the compressor */