Debug 4.98 KB
Newer Older
Jeffrey Lee's avatar
Jeffrey Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
; Copyright 2009 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;

        GET     Hdr:ListOpts
        GET     Hdr:Macros
        GET     Hdr:System
        GET     Hdr:Machine.<Machine>
        GET     Hdr:ImageSize.<ImageSize>
        GET     Hdr:Proc

        GET     Hdr:OSEntries

        GET     hdr.omap3530
        GET     hdr.UART
        GET     hdr.StaticWS

        EXPORT  HAL_DebugTX
        EXPORT  HAL_DebugRX
31
 [ Debug
32 33
        EXPORT  DebugHALPrint
        EXPORT  DebugHALPrintReg
34 35
        EXPORT  DebugMemDump
 ]
Jeffrey Lee's avatar
Jeffrey Lee committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

        AREA    |Asm$$Code|, CODE, READONLY, PIC

 [ Debug

DebugUART       *       L4_UART3
DebugUART_Log   *       L4_UART3_Log

; No initialisation; assumes we've booted from x-loader and thus the serial
; port is already set up

; in: a1 = character to TX
HAL_DebugTX
        CMP     sb, #0 ; Use hardware address if sb is 0 (pre-MMU debug output)
        LDRNE   a2, DebugUART_Log
        CMPNE   a2, #0 ; Also use hardware address if logical ptr is null (to catch the debug message between RISCOS_Start and HAL_Init in the test kernel; but this will obviously fail on real kernels since the MMU would be enabled at that point)
        LDREQ   a2, =DebugUART
HAL_DebugTX_Loop
        LDRB    a3, [a2, #UART_LSR]
        TST     a3, #THRE
        BEQ     HAL_DebugTX_Loop
        STRB    a1, [a2, #UART_THR]
        MOV     pc, lr

; out: a1 = character, or -1 if none available
HAL_DebugRX     ROUT
        CMP     sb, #0
        LDRNE   a2, DebugUART_Log
        CMPNE   a2, #0
        LDREQ   a2, =DebugUART
        LDRB    a1, [a2, #UART_LSR]
        TST     a1, #DR
        MOVEQ   a1, #-1
        LDRNEB  a1, [a2, #UART_RBR]
        MOV     pc, lr

72 73 74 75 76 77 78 79
DebugHALPrint
        Push    "a1-a4,v1"
        MOV     v1, lr
10      LDRB    a1, [v1], #1
        TEQ     a1, #0
        BEQ     %FT20
        BL      HAL_DebugTX
        B       %BT10
80
20      ADD     v1, v1, #3
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        BIC     lr, v1, #3
        Pull    "a1-a4,v1"
        MOV     pc, lr

DebugHALPrintReg ; Output number on top of stack to the serial port
        Push    "a1-a4,v1"
        LDR     a1, [sp,#5*4]
        CMP     sb, #0
        LDRNE   a2, DebugUART_Log
        CMPNE   a2, #0
        LDREQ   a2, =DebugUART
        ADR     a3, hextab
        MOV     a4, #8
10
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT10
        LDRB    v1, [a3, a1, LSR #28]
        STRB    v1, [a2, #UART_THR]
        MOV     a1, a1, LSL #4
        SUBS    a4, a4, #1
        BNE     %BT10
20
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT20
        MOV     v1, #13
        STRB    v1, [a2, #UART_THR]
30
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT30
        MOV     v1, #10
        STRB    v1, [a2, #UART_THR]

        Pull    "a1-a4,v1"
        ADD     sp, sp, #4
        MOV     pc, lr

hextab  DCB "0123456789abcdef"

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
DebugMemDump ; r0 = start, r1 = size
        Push    "a1-a4,v1-v3,lr"
        MOV     v2, a1
        MOV     v3, a2
        CMP     sb, #0
        LDRNE   a2, DebugUART_Log
        CMPNE   a2, #0
        LDREQ   a2, =DebugUART
        ADR     a3, hextab
100
        ; Print addr
        MOV     a1, v2
        MOV     a4, #8
10
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT10
        LDRB    v1, [a3, a1, LSR #28]
        STRB    v1, [a2, #UART_THR]
        MOV     a1, a1, LSL #4
        SUBS    a4, a4, #1
        BNE     %BT10
20
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT20
        MOV     v1, #32
        STRB    v1, [a2, #UART_THR]

        ; Print value
        LDR     a1, [v2]
        MOV     a4, #8
10
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT10
        LDRB    v1, [a3, a1, LSR #28]
        STRB    v1, [a2, #UART_THR]
        MOV     a1, a1, LSL #4
        SUBS    a4, a4, #1
        BNE     %BT10
20
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT20
        MOV     v1, #13
        STRB    v1, [a2, #UART_THR]
30
        LDRB    v1, [a2, #UART_LSR]
        TST     v1, #THRE
        BEQ     %BT30
        MOV     v1, #10
        STRB    v1, [a2, #UART_THR]

        ADD     v2, v2, #4 ; Counter dodgy exception vector
        SUBS    v3, v3, #4
        BGT     %BT100
        Pull    "a1-a4,v1-v3,pc"

Jeffrey Lee's avatar
Jeffrey Lee committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
 | ; Debug

HAL_DebugRX
        MOV     a1, #-1
        ; fall through
HAL_DebugTX
        MOV     pc, lr

 ] ; Debug

;        EXPORT  |_dprintf|
;|_dprintf|
;        B       printf

        END