]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[riscv] Move prefix debug message printing to libprefix.S
authorMichael Brown <mcb30@ipxe.org>
Tue, 6 May 2025 15:35:19 +0000 (16:35 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 6 May 2025 16:28:14 +0000 (17:28 +0100)
Create a prefix library function print_message() to print text to the
SBI debug console.  Use the "write byte" SBI call (rather than "write
string") so that the function remains usable even after enabling
paging.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/prefix/libprefix.S
src/arch/riscv/prefix/sbiprefix.S

index 43a92330300faa44fc0a0097d570164cded545d2..21b39526fcfd259de21c33743b8342d1d90929dc 100644 (file)
@@ -41,6 +41,68 @@ prefix_virt:
        .dword  _prefix
        .size   prefix_virt, . - prefix_virt
 
+/*****************************************************************************
+ *
+ * Print message to debug console
+ *
+ *****************************************************************************
+ *
+ * Print a NUL-terminated string to the debug console.
+ *
+ * This function prints one character at a time via the "write byte"
+ * call (rather than using "write string"), since this avoids any need
+ * to know the current virtual-physical address translation.  It does
+ * not require a valid stack.
+ *
+ * Note that the parameter is passed in register t0 (rather than a0)
+ * and all non-temporary registers are preserved.
+ *
+ * Parameters:
+ *
+ *   t0 - Pointer to string
+ *
+ * Returns: none
+ *
+ */
+
+/* SBI debug console extension */
+#define SBI_DBCN ( ( 'D' << 24 ) | ( 'B' << 16 ) | ( 'C' << 8 ) | 'N' )
+#define SBI_DBCN_WRITE_BYTE 0x02
+
+       .section ".prefix.print_message", "ax", @progbits
+       .globl  print_message
+print_message:
+       /* Register usage:
+        *
+        * t0 - character pointer
+        * a0 - current character
+        * t1 - preserved a0
+        * t2 - preserved a1
+        * t3 - preserved a6
+        * t4 - preserved a7
+        */
+       mv      t1, a0
+       mv      t2, a1
+       mv      t3, a6
+       mv      t4, a7
+
+1:     /* Print each character in turn */
+       lbu     a0, (t0)
+       addi    t0, t0, 1
+       beqz    a0, 2f
+       li      a7, SBI_DBCN
+       li      a6, SBI_DBCN_WRITE_BYTE
+       ecall
+       j       1b
+2:
+       /* Restore registers and return */
+       mv      a7, t4
+       mv      a6, t3
+       mv      a1, t2
+       mv      a0, t1
+       ret
+       .size   print_message, . - print_message
+
 /*****************************************************************************
  *
  * Apply compressed relocation records
index c26c1713c7e6380cc712c9137602141939251028..6bac315403288f9773094a2de78070a0333ff154 100644 (file)
        .section ".note.GNU-stack", "", @progbits
        .text
 
-/* SBI debug console extension */
-#define SBI_DBCN ( ( 'D' << 24 ) | ( 'B' << 16 ) | ( 'C' << 8 ) | 'N' )
-#define SBI_DBCN_WRITE 0x00
-
 /* SBI system reset extension */
 #define SBI_SRST ( ( 'S' << 24 ) | ( 'R' << 16 ) | ( 'S' << 8 ) | 'T' )
 #define SBI_SRST_SYSTEM_RESET 0x00
 #ifndef NDEBUG
        .section ".rodata", "a", @progbits
 progress_\@:
-       .ascii  "\message"
-       .equ    progress_\@_len, . - progress_\@
+       .asciz  "\message"
        .size   progress_\@, . - progress_\@
        .previous
-       li      a7, SBI_DBCN
-       li      a6, SBI_DBCN_WRITE
-       li      a0, progress_\@_len
-       la      a1, progress_\@
-       mv      a2, zero
-       ecall
+       la      t0, progress_\@
+       call    print_message
 #endif
        .endm