From: Michael Brown Date: Wed, 7 May 2025 12:07:56 +0000 (+0100) Subject: [riscv] Move prefix system reset code to libprefix.S X-Git-Tag: rolling/bin~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72c81419b126ddc73b2c7e9a9385fcc6faa687a8;p=thirdparty%2Fipxe.git [riscv] Move prefix system reset code to libprefix.S Signed-off-by: Michael Brown --- diff --git a/src/arch/riscv/prefix/libprefix.S b/src/arch/riscv/prefix/libprefix.S index 4d36ba9dc..1a2b992d6 100644 --- a/src/arch/riscv/prefix/libprefix.S +++ b/src/arch/riscv/prefix/libprefix.S @@ -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 diff --git a/src/arch/riscv/prefix/sbiprefix.S b/src/arch/riscv/prefix/sbiprefix.S index a02d66bd6..34766d53a 100644 --- a/src/arch/riscv/prefix/sbiprefix.S +++ b/src/arch/riscv/prefix/sbiprefix.S @@ -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 */