blob: ea9646cc2a0ed7eba2fa4f7f7638c0802642edcc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/linkage.h>
Rob Herring6f6f6a72012-03-10 10:30:31 -060013#include <asm/assembler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
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
Rob Herring91a9fec2012-08-31 00:03:46 -050023#if !defined(CONFIG_DEBUG_SEMIHOSTING)
24#include CONFIG_DEBUG_LL_INCLUDE
25#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Jeremy Kerr0ea12932010-07-06 18:30:06 +080027#ifdef CONFIG_MMU
28 .macro addruart_current, rx, tmp1, tmp2
Nicolas Pitre639da5e2011-08-31 22:55:46 -040029 addruart \tmp1, \tmp2, \rx
Jeremy Kerr0ea12932010-07-06 18:30:06 +080030 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
Stefan Agner7505f042015-05-20 00:03:50 +020038 addruart \rx, \tmp1, \tmp2
Jeremy Kerr0ea12932010-07-06 18:30:06 +080039 .endm
40
41#endif /* CONFIG_MMU */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
44 * Useful debugging routines
45 */
46ENTRY(printhex8)
47 mov r1, #8
48 b printhex
Catalin Marinas93ed3972008-08-28 11:22:32 +010049ENDPROC(printhex8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51ENTRY(printhex4)
52 mov r1, #4
53 b printhex
Catalin Marinas93ed3972008-08-28 11:22:32 +010054ENDPROC(printhex4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56ENTRY(printhex2)
57 mov r1, #2
58printhex: adr r2, hexbuf
59 add r3, r2, r1
60 mov r1, #0
61 strb r1, [r3]
621: and r1, r0, #15
63 mov r0, r0, lsr #4
64 cmp r1, #10
65 addlt r1, r1, #'0'
66 addge r1, r1, #'a' - 10
67 strb r1, [r3, #-1]!
68 teq r3, r2
69 bne 1b
70 mov r0, r2
71 b printascii
Catalin Marinas93ed3972008-08-28 11:22:32 +010072ENDPROC(printhex2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Afzal Mohammedb55fa182011-10-20 19:32:07 +010074hexbuf: .space 16
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 .ltorg
77
Nicolas Pitre9b5a1462012-02-22 21:58:03 +010078#ifndef CONFIG_DEBUG_SEMIHOSTING
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080ENTRY(printascii)
Jeremy Kerr0ea12932010-07-06 18:30:06 +080081 addruart_current r3, r1, r2
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 b 2f
831: waituart r2, r3
84 senduart r1, r3
85 busyuart r2, r3
86 teq r1, #'\n'
87 moveq r1, #'\r'
88 beq 1b
892: teq r0, #0
90 ldrneb r1, [r0], #1
91 teqne r1, #0
92 bne 1b
Russell King6ebbf2c2014-06-30 16:29:12 +010093 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010094ENDPROC(printascii)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96ENTRY(printch)
Jeremy Kerr0ea12932010-07-06 18:30:06 +080097 addruart_current r3, r1, r2
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 mov r1, r0
99 mov r0, #0
100 b 1b
Catalin Marinas93ed3972008-08-28 11:22:32 +0100101ENDPROC(printch)
Nicolas Pitre9b5a1462012-02-22 21:58:03 +0100102
Uwe Kleine-Königa73b59c2013-01-16 15:32:06 +0100103#ifdef CONFIG_MMU
Rob Herringe5c5f2a2012-10-22 11:42:54 -0600104ENTRY(debug_ll_addr)
105 addruart r2, r3, ip
106 str r2, [r0]
107 str r3, [r1]
Russell King6ebbf2c2014-06-30 16:29:12 +0100108 ret lr
Rob Herringe5c5f2a2012-10-22 11:42:54 -0600109ENDPROC(debug_ll_addr)
Uwe Kleine-Königa73b59c2013-01-16 15:32:06 +0100110#endif
Rob Herringe5c5f2a2012-10-22 11:42:54 -0600111
Nicolas Pitre9b5a1462012-02-22 21:58:03 +0100112#else
113
114ENTRY(printascii)
115 mov r1, r0
116 mov r0, #0x04 @ SYS_WRITE0
117 ARM( svc #0x123456 )
118 THUMB( svc #0xab )
Russell King6ebbf2c2014-06-30 16:29:12 +0100119 ret lr
Nicolas Pitre9b5a1462012-02-22 21:58:03 +0100120ENDPROC(printascii)
121
122ENTRY(printch)
123 adr r1, hexbuf
124 strb r0, [r1]
125 mov r0, #0x03 @ SYS_WRITEC
126 ARM( svc #0x123456 )
127 THUMB( svc #0xab )
Russell King6ebbf2c2014-06-30 16:29:12 +0100128 ret lr
Nicolas Pitre9b5a1462012-02-22 21:58:03 +0100129ENDPROC(printch)
130
Rob Herringe5c5f2a2012-10-22 11:42:54 -0600131ENTRY(debug_ll_addr)
132 mov r2, #0
133 str r2, [r0]
134 str r2, [r1]
Russell King6ebbf2c2014-06-30 16:29:12 +0100135 ret lr
Rob Herringe5c5f2a2012-10-22 11:42:54 -0600136ENDPROC(debug_ll_addr)
137
Nicolas Pitre9b5a1462012-02-22 21:58:03 +0100138#endif