Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Masahiro Yamada | 59cbe79 | 2014-09-01 11:06:32 +0900 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/kernel/debug.S |
| 4 | * |
| 5 | * Copyright (C) 1994-1999 Russell King |
| 6 | * |
Masahiro Yamada | 59cbe79 | 2014-09-01 11:06:32 +0900 | [diff] [blame] | 7 | * 32-bit debugging code |
| 8 | */ |
| 9 | #include <linux/linkage.h> |
| 10 | #include <asm/assembler.h> |
| 11 | |
| 12 | .text |
| 13 | |
| 14 | /* |
| 15 | * Some debugging routines (useful if you've got MM problems and |
| 16 | * printk isn't working). For DEBUGGING ONLY!!! Do not leave |
| 17 | * references to these in a production kernel! |
| 18 | */ |
| 19 | |
| 20 | #if !defined(CONFIG_DEBUG_SEMIHOSTING) |
| 21 | #include CONFIG_DEBUG_LL_INCLUDE |
| 22 | #endif |
| 23 | |
| 24 | #ifdef CONFIG_MMU |
| 25 | .macro addruart_current, rx, tmp1, tmp2 |
| 26 | addruart \tmp1, \tmp2, \rx |
| 27 | mrc p15, 0, \rx, c1, c0 |
| 28 | tst \rx, #1 |
| 29 | moveq \rx, \tmp1 |
| 30 | movne \rx, \tmp2 |
| 31 | .endm |
| 32 | |
| 33 | #else /* !CONFIG_MMU */ |
| 34 | .macro addruart_current, rx, tmp1, tmp2 |
Masahiro Yamada | 4cb23ab | 2014-09-01 11:06:35 +0900 | [diff] [blame] | 35 | addruart \rx, \tmp1, \tmp2 |
Masahiro Yamada | 59cbe79 | 2014-09-01 11:06:32 +0900 | [diff] [blame] | 36 | .endm |
| 37 | |
| 38 | #endif /* CONFIG_MMU */ |
| 39 | |
| 40 | /* |
| 41 | * Useful debugging routines |
| 42 | */ |
| 43 | ENTRY(printhex8) |
| 44 | mov r1, #8 |
| 45 | b printhex |
| 46 | ENDPROC(printhex8) |
| 47 | |
| 48 | ENTRY(printhex4) |
| 49 | mov r1, #4 |
| 50 | b printhex |
| 51 | ENDPROC(printhex4) |
| 52 | |
| 53 | ENTRY(printhex2) |
| 54 | mov r1, #2 |
| 55 | printhex: adr r2, hexbuf |
| 56 | add r3, r2, r1 |
| 57 | mov r1, #0 |
| 58 | strb r1, [r3] |
| 59 | 1: and r1, r0, #15 |
| 60 | mov r0, r0, lsr #4 |
| 61 | cmp r1, #10 |
| 62 | addlt r1, r1, #'0' |
| 63 | addge r1, r1, #'a' - 10 |
| 64 | strb r1, [r3, #-1]! |
| 65 | teq r3, r2 |
| 66 | bne 1b |
| 67 | mov r0, r2 |
| 68 | b printascii |
| 69 | ENDPROC(printhex2) |
| 70 | |
| 71 | hexbuf: .space 16 |
| 72 | |
| 73 | .ltorg |
| 74 | |
| 75 | #ifndef CONFIG_DEBUG_SEMIHOSTING |
| 76 | |
| 77 | ENTRY(printascii) |
| 78 | addruart_current r3, r1, r2 |
| 79 | b 2f |
| 80 | 1: waituart r2, r3 |
| 81 | senduart r1, r3 |
| 82 | busyuart r2, r3 |
| 83 | teq r1, #'\n' |
| 84 | moveq r1, #'\r' |
| 85 | beq 1b |
| 86 | 2: teq r0, #0 |
| 87 | ldrneb r1, [r0], #1 |
| 88 | teqne r1, #0 |
| 89 | bne 1b |
| 90 | mov pc, lr |
| 91 | ENDPROC(printascii) |
| 92 | |
| 93 | ENTRY(printch) |
| 94 | addruart_current r3, r1, r2 |
| 95 | mov r1, r0 |
| 96 | mov r0, #0 |
| 97 | b 1b |
| 98 | ENDPROC(printch) |
| 99 | |
| 100 | #ifdef CONFIG_MMU |
| 101 | ENTRY(debug_ll_addr) |
| 102 | addruart r2, r3, ip |
| 103 | str r2, [r0] |
| 104 | str r3, [r1] |
| 105 | mov pc, lr |
| 106 | ENDPROC(debug_ll_addr) |
| 107 | #endif |
| 108 | |
| 109 | #else |
| 110 | |
| 111 | ENTRY(printascii) |
| 112 | mov r1, r0 |
| 113 | mov r0, #0x04 @ SYS_WRITE0 |
| 114 | ARM( svc #0x123456 ) |
| 115 | THUMB( svc #0xab ) |
| 116 | mov pc, lr |
| 117 | ENDPROC(printascii) |
| 118 | |
| 119 | ENTRY(printch) |
| 120 | adr r1, hexbuf |
| 121 | strb r0, [r1] |
| 122 | mov r0, #0x03 @ SYS_WRITEC |
| 123 | ARM( svc #0x123456 ) |
| 124 | THUMB( svc #0xab ) |
| 125 | mov pc, lr |
| 126 | ENDPROC(printch) |
| 127 | |
| 128 | ENTRY(debug_ll_addr) |
| 129 | mov r2, #0 |
| 130 | str r2, [r0] |
| 131 | str r2, [r1] |
| 132 | mov pc, lr |
| 133 | ENDPROC(debug_ll_addr) |
| 134 | |
| 135 | #endif |