From: Michael Brown Date: Tue, 6 May 2025 15:35:19 +0000 (+0100) Subject: [riscv] Move prefix debug message printing to libprefix.S X-Git-Tag: rolling/bin~322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc9e6f0edf1ffd7c88c6112c638e7a2b013cf89a;p=thirdparty%2Fipxe.git [riscv] Move prefix debug message printing to libprefix.S 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 --- diff --git a/src/arch/riscv/prefix/libprefix.S b/src/arch/riscv/prefix/libprefix.S index 43a923303..21b39526f 100644 --- a/src/arch/riscv/prefix/libprefix.S +++ b/src/arch/riscv/prefix/libprefix.S @@ -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 diff --git a/src/arch/riscv/prefix/sbiprefix.S b/src/arch/riscv/prefix/sbiprefix.S index c26c1713c..6bac31540 100644 --- a/src/arch/riscv/prefix/sbiprefix.S +++ b/src/arch/riscv/prefix/sbiprefix.S @@ -32,10 +32,6 @@ .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 @@ -51,16 +47,11 @@ #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