xref: /openbmc/linux/arch/arm/kernel/debug.S (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
1d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds *  linux/arch/arm/kernel/debug.S
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds *  Copyright (C) 1994-1999 Russell King
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds *  32-bit debugging code
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds#include <linux/linkage.h>
106f6f6a70SRob Herring#include <asm/assembler.h>
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds		.text
131da177e4SLinus Torvalds
141da177e4SLinus Torvalds/*
151da177e4SLinus Torvalds * Some debugging routines (useful if you've got MM problems and
161da177e4SLinus Torvalds * printk isn't working).  For DEBUGGING ONLY!!!  Do not leave
171da177e4SLinus Torvalds * references to these in a production kernel!
181da177e4SLinus Torvalds */
191da177e4SLinus Torvalds
2091a9fec0SRob Herring#if !defined(CONFIG_DEBUG_SEMIHOSTING)
2191a9fec0SRob Herring#include CONFIG_DEBUG_LL_INCLUDE
2291a9fec0SRob Herring#endif
231da177e4SLinus Torvalds
240ea12930SJeremy Kerr#ifdef CONFIG_MMU
250ea12930SJeremy Kerr		.macro	addruart_current, rx, tmp1, tmp2
26639da5eeSNicolas Pitre		addruart	\tmp1, \tmp2, \rx
270ea12930SJeremy Kerr		mrc		p15, 0, \rx, c1, c0
280ea12930SJeremy Kerr		tst		\rx, #1
290ea12930SJeremy Kerr		moveq		\rx, \tmp1
300ea12930SJeremy Kerr		movne		\rx, \tmp2
310ea12930SJeremy Kerr		.endm
320ea12930SJeremy Kerr
330ea12930SJeremy Kerr#else /* !CONFIG_MMU */
340ea12930SJeremy Kerr		.macro	addruart_current, rx, tmp1, tmp2
357505f042SStefan Agner		addruart	\rx, \tmp1, \tmp2
360ea12930SJeremy Kerr		.endm
370ea12930SJeremy Kerr
380ea12930SJeremy Kerr#endif /* CONFIG_MMU */
390ea12930SJeremy Kerr
401da177e4SLinus Torvalds/*
411da177e4SLinus Torvalds * Useful debugging routines
421da177e4SLinus Torvalds */
431da177e4SLinus TorvaldsENTRY(printhex8)
441da177e4SLinus Torvalds		mov	r1, #8
451da177e4SLinus Torvalds		b	printhex
4693ed3970SCatalin MarinasENDPROC(printhex8)
471da177e4SLinus Torvalds
481da177e4SLinus TorvaldsENTRY(printhex4)
491da177e4SLinus Torvalds		mov	r1, #4
501da177e4SLinus Torvalds		b	printhex
5193ed3970SCatalin MarinasENDPROC(printhex4)
521da177e4SLinus Torvalds
531da177e4SLinus TorvaldsENTRY(printhex2)
541da177e4SLinus Torvalds		mov	r1, #2
55e11d1314SNicolas Pitreprinthex:	adr	r2, hexbuf_rel
56e11d1314SNicolas Pitre		ldr	r3, [r2]
57e11d1314SNicolas Pitre		add	r2, r2, r3
581da177e4SLinus Torvalds		add	r3, r2, r1
591da177e4SLinus Torvalds		mov	r1, #0
601da177e4SLinus Torvalds		strb	r1, [r3]
611da177e4SLinus Torvalds1:		and	r1, r0, #15
621da177e4SLinus Torvalds		mov	r0, r0, lsr #4
631da177e4SLinus Torvalds		cmp	r1, #10
641da177e4SLinus Torvalds		addlt	r1, r1, #'0'
651da177e4SLinus Torvalds		addge	r1, r1, #'a' - 10
661da177e4SLinus Torvalds		strb	r1, [r3, #-1]!
671da177e4SLinus Torvalds		teq	r3, r2
681da177e4SLinus Torvalds		bne	1b
691da177e4SLinus Torvalds		mov	r0, r2
701da177e4SLinus Torvalds		b	printascii
7193ed3970SCatalin MarinasENDPROC(printhex2)
721da177e4SLinus Torvalds
73e11d1314SNicolas Pitre		.pushsection .bss
74e11d1314SNicolas Pitrehexbuf_addr:	.space 16
75e11d1314SNicolas Pitre		.popsection
76e11d1314SNicolas Pitre		.align
77e11d1314SNicolas Pitrehexbuf_rel:	.long	hexbuf_addr - .
78b55fa188SAfzal Mohammed
791da177e4SLinus Torvalds		.ltorg
801da177e4SLinus Torvalds
819b5a146aSNicolas Pitre#ifndef CONFIG_DEBUG_SEMIHOSTING
829b5a146aSNicolas Pitre
831da177e4SLinus TorvaldsENTRY(printascii)
840ea12930SJeremy Kerr		addruart_current r3, r1, r2
852a14b80cSNicolas Pitre1:		teq	r0, #0
86e44fc388SStefan Agner		ldrbne	r1, [r0], #1
871da177e4SLinus Torvalds		teqne	r1, #0
882a14b80cSNicolas Pitre		reteq	lr
892a14b80cSNicolas Pitre2:		teq     r1, #'\n'
902a14b80cSNicolas Pitre		bne	3f
912a14b80cSNicolas Pitre		mov	r1, #'\r'
92*4df24fefSLinus Walleij#ifdef CONFIG_DEBUG_UART_FLOW_CONTROL
932c50a570SLinus Walleij		waituartcts r2, r3
94*4df24fefSLinus Walleij#endif
952c50a570SLinus Walleij		waituarttxrdy r2, r3
962a14b80cSNicolas Pitre		senduart r1, r3
972a14b80cSNicolas Pitre		busyuart r2, r3
982a14b80cSNicolas Pitre		mov	r1, #'\n'
99*4df24fefSLinus Walleij3:
100*4df24fefSLinus Walleij#ifdef CONFIG_DEBUG_UART_FLOW_CONTROL
101*4df24fefSLinus Walleij		waituartcts r2, r3
102*4df24fefSLinus Walleij#endif
1032c50a570SLinus Walleij		waituarttxrdy r2, r3
1042a14b80cSNicolas Pitre		senduart r1, r3
1052a14b80cSNicolas Pitre		busyuart r2, r3
1062a14b80cSNicolas Pitre		b	1b
10793ed3970SCatalin MarinasENDPROC(printascii)
1081da177e4SLinus Torvalds
1091da177e4SLinus TorvaldsENTRY(printch)
1100ea12930SJeremy Kerr		addruart_current r3, r1, r2
1111da177e4SLinus Torvalds		mov	r1, r0
1121da177e4SLinus Torvalds		mov	r0, #0
1132a14b80cSNicolas Pitre		b	2b
11493ed3970SCatalin MarinasENDPROC(printch)
1159b5a146aSNicolas Pitre
116a73b59c5SUwe Kleine-König#ifdef CONFIG_MMU
117e5c5f2adSRob HerringENTRY(debug_ll_addr)
118e5c5f2adSRob Herring		addruart r2, r3, ip
119e5c5f2adSRob Herring		str	r2, [r0]
120e5c5f2adSRob Herring		str	r3, [r1]
1216ebbf2ceSRussell King		ret	lr
122e5c5f2adSRob HerringENDPROC(debug_ll_addr)
123a73b59c5SUwe Kleine-König#endif
124e5c5f2adSRob Herring
1259b5a146aSNicolas Pitre#else
1269b5a146aSNicolas Pitre
1279b5a146aSNicolas PitreENTRY(printascii)
1289b5a146aSNicolas Pitre		mov	r1, r0
1299b5a146aSNicolas Pitre		mov	r0, #0x04		@ SYS_WRITE0
1309b5a146aSNicolas Pitre	ARM(	svc	#0x123456	)
131ee3eaee6SNicolas Pitre#ifdef CONFIG_CPU_V7M
132ee3eaee6SNicolas Pitre	THUMB(	bkpt	#0xab		)
133ee3eaee6SNicolas Pitre#else
1349b5a146aSNicolas Pitre	THUMB(	svc	#0xab		)
135ee3eaee6SNicolas Pitre#endif
1366ebbf2ceSRussell King		ret	lr
1379b5a146aSNicolas PitreENDPROC(printascii)
1389b5a146aSNicolas Pitre
1399b5a146aSNicolas PitreENTRY(printch)
140e11d1314SNicolas Pitre		adr	r1, hexbuf_rel
141e11d1314SNicolas Pitre		ldr	r2, [r1]
142e11d1314SNicolas Pitre		add	r1, r1, r2
1439b5a146aSNicolas Pitre		strb	r0, [r1]
1449b5a146aSNicolas Pitre		mov	r0, #0x03		@ SYS_WRITEC
1459b5a146aSNicolas Pitre	ARM(	svc	#0x123456	)
146ee3eaee6SNicolas Pitre#ifdef CONFIG_CPU_V7M
147ee3eaee6SNicolas Pitre	THUMB(	bkpt	#0xab		)
148ee3eaee6SNicolas Pitre#else
1499b5a146aSNicolas Pitre	THUMB(	svc	#0xab		)
150ee3eaee6SNicolas Pitre#endif
1516ebbf2ceSRussell King		ret	lr
1529b5a146aSNicolas PitreENDPROC(printch)
1539b5a146aSNicolas Pitre
154e5c5f2adSRob HerringENTRY(debug_ll_addr)
155e5c5f2adSRob Herring		mov	r2, #0
156e5c5f2adSRob Herring		str	r2, [r0]
157e5c5f2adSRob Herring		str	r2, [r1]
1586ebbf2ceSRussell King		ret	lr
159e5c5f2adSRob HerringENDPROC(debug_ll_addr)
160e5c5f2adSRob Herring
1619b5a146aSNicolas Pitre#endif
162