Merge tag 'for-5.1-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[sfrench/cifs-2.6.git] / arch / arm / kernel / debug.S
1 /*
2  *  linux/arch/arm/kernel/debug.S
3  *
4  *  Copyright (C) 1994-1999 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  32-bit debugging code
11  */
12 #include <linux/linkage.h>
13 #include <asm/assembler.h>
14
15                 .text
16
17 /*
18  * Some debugging routines (useful if you've got MM problems and
19  * printk isn't working).  For DEBUGGING ONLY!!!  Do not leave
20  * references to these in a production kernel!
21  */
22
23 #if !defined(CONFIG_DEBUG_SEMIHOSTING)
24 #include CONFIG_DEBUG_LL_INCLUDE
25 #endif
26
27 #ifdef CONFIG_MMU
28                 .macro  addruart_current, rx, tmp1, tmp2
29                 addruart        \tmp1, \tmp2, \rx
30                 mrc             p15, 0, \rx, c1, c0
31                 tst             \rx, #1
32                 moveq           \rx, \tmp1
33                 movne           \rx, \tmp2
34                 .endm
35
36 #else /* !CONFIG_MMU */
37                 .macro  addruart_current, rx, tmp1, tmp2
38                 addruart        \rx, \tmp1, \tmp2
39                 .endm
40
41 #endif /* CONFIG_MMU */
42
43 /*
44  * Useful debugging routines
45  */
46 ENTRY(printhex8)
47                 mov     r1, #8
48                 b       printhex
49 ENDPROC(printhex8)
50
51 ENTRY(printhex4)
52                 mov     r1, #4
53                 b       printhex
54 ENDPROC(printhex4)
55
56 ENTRY(printhex2)
57                 mov     r1, #2
58 printhex:       adr     r2, hexbuf_rel
59                 ldr     r3, [r2]
60                 add     r2, r2, r3
61                 add     r3, r2, r1
62                 mov     r1, #0
63                 strb    r1, [r3]
64 1:              and     r1, r0, #15
65                 mov     r0, r0, lsr #4
66                 cmp     r1, #10
67                 addlt   r1, r1, #'0'
68                 addge   r1, r1, #'a' - 10
69                 strb    r1, [r3, #-1]!
70                 teq     r3, r2
71                 bne     1b
72                 mov     r0, r2
73                 b       printascii
74 ENDPROC(printhex2)
75
76                 .pushsection .bss
77 hexbuf_addr:    .space 16
78                 .popsection
79                 .align
80 hexbuf_rel:     .long   hexbuf_addr - .
81
82                 .ltorg
83
84 #ifndef CONFIG_DEBUG_SEMIHOSTING
85
86 ENTRY(printascii)
87                 addruart_current r3, r1, r2
88 1:              teq     r0, #0
89                 ldrbne  r1, [r0], #1
90                 teqne   r1, #0
91                 reteq   lr
92 2:              teq     r1, #'\n'
93                 bne     3f
94                 mov     r1, #'\r'
95                 waituart r2, r3
96                 senduart r1, r3
97                 busyuart r2, r3
98                 mov     r1, #'\n'
99 3:              waituart r2, r3
100                 senduart r1, r3
101                 busyuart r2, r3
102                 b       1b
103 ENDPROC(printascii)
104
105 ENTRY(printch)
106                 addruart_current r3, r1, r2
107                 mov     r1, r0
108                 mov     r0, #0
109                 b       2b
110 ENDPROC(printch)
111
112 #ifdef CONFIG_MMU
113 ENTRY(debug_ll_addr)
114                 addruart r2, r3, ip
115                 str     r2, [r0]
116                 str     r3, [r1]
117                 ret     lr
118 ENDPROC(debug_ll_addr)
119 #endif
120
121 #else
122
123 ENTRY(printascii)
124                 mov     r1, r0
125                 mov     r0, #0x04               @ SYS_WRITE0
126         ARM(    svc     #0x123456       )
127 #ifdef CONFIG_CPU_V7M
128         THUMB(  bkpt    #0xab           )
129 #else
130         THUMB(  svc     #0xab           )
131 #endif
132                 ret     lr
133 ENDPROC(printascii)
134
135 ENTRY(printch)
136                 adr     r1, hexbuf_rel
137                 ldr     r2, [r1]
138                 add     r1, r1, r2
139                 strb    r0, [r1]
140                 mov     r0, #0x03               @ SYS_WRITEC
141         ARM(    svc     #0x123456       )
142 #ifdef CONFIG_CPU_V7M
143         THUMB(  bkpt    #0xab           )
144 #else
145         THUMB(  svc     #0xab           )
146 #endif
147                 ret     lr
148 ENDPROC(printch)
149
150 ENTRY(debug_ll_addr)
151                 mov     r2, #0
152                 str     r2, [r0]
153                 str     r2, [r1]
154                 ret     lr
155 ENDPROC(debug_ll_addr)
156
157 #endif