.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
.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