]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[riscv] Move prefix system reset code to libprefix.S
authorMichael Brown <mcb30@ipxe.org>
Wed, 7 May 2025 12:07:56 +0000 (13:07 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 7 May 2025 12:10:40 +0000 (13:10 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/prefix/libprefix.S
src/arch/riscv/prefix/sbiprefix.S

index 4d36ba9dc156a521bcf3ec60bad0a52b285d87bb..1a2b992d660f4381b9064441ccfb3b01de7ef39d 100644 (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
index a02d66bd6a25f64c4bccc72223563c165a5b9682..34766d53a16829d091011ee3b4880ed85e83f920 100644 (file)
        .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 */