Code for adding serial debug capabilities into init.s

Code for adding serial debug capabilities into init.s I was taking a look in the NetArm boot loader for uClinux and its serial capability make me a little “jealous”. I decided to write printch and printascii functions for GHS3.5 assembler and I created a new function for printing hexa numbers. I am posting them here to help that poor guys in troubles related to initialization code (like me) :slight_smile: These functions don’t use stack or memory, only registers, and I have configured the second serial port as the default output port. The end of lines were changed to
(Ruindows), my board (Net50) has a 18.432MHz clock and serial port configuration is 9600/8N1. The original code for configuration, printch and printascii was done by Joe deBlaquiere, file inux/arch/armnommu/kernel/head-arm-netarm.S, with copyright belonging to NETSilicon and RedHat. As I will not use these functions in my final code, I am not considering legal questions related to GPL license. Printhex function was entirely done by me and it is totally free (citation will make me happy :slight_smile: ). Marcelo ---------------[examples]--------------------- BL debug_serial_init LDR R0, =bootmsg BL printascii_debug MOV R0, PC BL printhex_debug MOV R0, ‘\r’ BL printch_debug ;; put at the end of file bootmsg .ascii “My bootloader.\r\0” ---------------[functions]--------------------- .globl debug_serial_init debug_serial_init NETARM_GEN_MODULE_BASE = 0xFFB00000 NETARM_PORTA_CONF = 0xefe000ff NETARM_PORTB_CONF = 0xaaf500aa NETARM_GEN_PORTA = 0x20 NETARM_GEN_PORTB = 0x24 NETARM_GEN_PORTC = 0x28 NETARM_SER_MODULE_BASE = 0xFFD00000 NETARM_SER_CH1_CTRL_A = 0x00 NETARM_SER_CH2_CTRL_A = 0x40 NETARM_SER_CH1_RX_MATCH = 0x1c NETARM_SER_CH2_RX_MATCH = 0x5c NETARM_SER_CH1_BITRATE = 0x0C NETARM_SER_CH2_BITRATE = 0x4C NETARM_SER_BR_X16 = 0x8000000B NETARM_SER_CH1_RX_BUF_TMR = 0x14 NETARM_SER_CH2_RX_BUF_TMR = 0x54 NETARM_SER_RXGAP = 0x8000000f NETARM_SER_CTLB_UART_MODE = 0x00000000 NETARM_SER_CH1_CTRL_B = 0x04 NETARM_SER_CH2_CTRL_B = 0x44 NETARM_SER_CTLA_CONF = 0x83030000 NETARM_SER_STATA_TX_RDY = 0x00000008 NETARM_SER_CH1_FIFO = 0x10 NETARM_SER_CH2_FIFO = 0x50 NETARM_SER_CH1_STATUS_A = 0x08 NETARM_SER_CH2_STATUS_A = 0x48 ;; configuring ports ldr r4, =NETARM_GEN_MODULE_BASE ldr r1, =NETARM_PORTB_CONF str r1,[r4, NETARM_GEN_PORTA] str r1,[r4, NETARM_GEN_PORTB] ldr r4, =NETARM_SER_MODULE_BASE ;; turning off and cleaning mov r1, #0 str r1, [r4, NETARM_SER_CH1_CTRL_A] str r1, [r4, NETARM_SER_CH2_CTRL_A] str r1, [r4, NETARM_SER_CH1_RX_MATCH] str r1, [r4, NETARM_SER_CH2_RX_MATCH] ;; 9600 ldr r1, =NETARM_SER_BR_X16 str r1, [r4, NETARM_SER_CH1_BITRATE] str r1, [r4, NETARM_SER_CH2_BITRATE] ;; setup rx buffer gap timer for 2 characters ldr r1, =NETARM_SER_RXGAP str r1, [r4, NETARM_SER_CH1_RX_BUF_TMR] str r1, [r4, NETARM_SER_CH2_RX_BUF_TMR] ;; serial port configured for 8N1 mov r1, NETARM_SER_CTLB_UART_MODE str r1, [r4, NETARM_SER_CH1_CTRL_B] str r1, [r4, NETARM_SER_CH2_CTRL_B] ldr r1, =NETARM_SER_CTLA_CONF str r1, [r4, NETARM_SER_CH1_CTRL_A] str r1, [r4, NETARM_SER_CH2_CTRL_A] mov pc, lr .size debug_serial_init,.-debug_serial_init ;; --------------------------------------------------------- .globl printch_debug printch_debug ldr r3, =NETARM_SER_MODULE_BASE mov r1, r0 mov r0, #0 b lab01 .size printch_debug,.-printch_debug .globl printascii_debug printascii_debug ldr r3, =NETARM_SER_MODULE_BASE b lab03 lab01 ldr r2, [r3, NETARM_SER_CH2_STATUS_A] tst r2, NETARM_SER_STATA_TX_RDY beq lab01 strb r1, [r3, NETARM_SER_CH2_FIFO] teq r1, ‘\r’ moveq r1, ’
’ beq lab01 lab03 teq r0, #0 ldrneb r1, [r0], #1 teqne r1, #0 bne lab01 mov pc, lr .size printascii_debug,.-printascii_debug ;; ----------------------------------------------------- .globl printhex_debug printhex_debug ; save return addr mov r6, lr ; save a copy of the value to print mov r4, r0 ; number of shifts mov r5, #28 ; cosmetic mov r0, ‘0’ bl printch_debug mov r0, ‘x’ bl printch_debug NextNib ; get nibble mov r0, r4 lsr r5 ; mask it and r0, r0, #15 ; check: r0 < 10 -> +‘0’ else +(‘A’ - 10) cmp r0, #10 addlt r0, r0, #48 addge r0, r0, #55 ; obs: r1,r2,r3 are used by printch_debug bl printch_debug ; next nibble subs r5, r5, #4 bge NextNib ; returning mov pc, r6 .size printhex_debug,.-printhex_debug