xref: /openbmc/linux/arch/arm/kernel/debug.S (revision ee3eaee6a1dafb7ed7213ec2fad22552b4d58ed1)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds *  linux/arch/arm/kernel/debug.S
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds *  Copyright (C) 1994-1999 Russell King
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify
71da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as
81da177e4SLinus Torvalds * published by the Free Software Foundation.
91da177e4SLinus Torvalds *
101da177e4SLinus Torvalds *  32-bit debugging code
111da177e4SLinus Torvalds */
121da177e4SLinus Torvalds#include <linux/linkage.h>
136f6f6a70SRob Herring#include <asm/assembler.h>
141da177e4SLinus Torvalds
151da177e4SLinus Torvalds		.text
161da177e4SLinus Torvalds
171da177e4SLinus Torvalds/*
181da177e4SLinus Torvalds * Some debugging routines (useful if you've got MM problems and
191da177e4SLinus Torvalds * printk isn't working).  For DEBUGGING ONLY!!!  Do not leave
201da177e4SLinus Torvalds * references to these in a production kernel!
211da177e4SLinus Torvalds */
221da177e4SLinus Torvalds
2391a9fec0SRob Herring#if !defined(CONFIG_DEBUG_SEMIHOSTING)
2491a9fec0SRob Herring#include CONFIG_DEBUG_LL_INCLUDE
2591a9fec0SRob Herring#endif
261da177e4SLinus Torvalds
270ea12930SJeremy Kerr#ifdef CONFIG_MMU
280ea12930SJeremy Kerr		.macro	addruart_current, rx, tmp1, tmp2
29639da5eeSNicolas Pitre		addruart	\tmp1, \tmp2, \rx
300ea12930SJeremy Kerr		mrc		p15, 0, \rx, c1, c0
310ea12930SJeremy Kerr		tst		\rx, #1
320ea12930SJeremy Kerr		moveq		\rx, \tmp1
330ea12930SJeremy Kerr		movne		\rx, \tmp2
340ea12930SJeremy Kerr		.endm
350ea12930SJeremy Kerr
360ea12930SJeremy Kerr#else /* !CONFIG_MMU */
370ea12930SJeremy Kerr		.macro	addruart_current, rx, tmp1, tmp2
387505f042SStefan Agner		addruart	\rx, \tmp1, \tmp2
390ea12930SJeremy Kerr		.endm
400ea12930SJeremy Kerr
410ea12930SJeremy Kerr#endif /* CONFIG_MMU */
420ea12930SJeremy Kerr
431da177e4SLinus Torvalds/*
441da177e4SLinus Torvalds * Useful debugging routines
451da177e4SLinus Torvalds */
461da177e4SLinus TorvaldsENTRY(printhex8)
471da177e4SLinus Torvalds		mov	r1, #8
481da177e4SLinus Torvalds		b	printhex
4993ed3970SCatalin MarinasENDPROC(printhex8)
501da177e4SLinus Torvalds
511da177e4SLinus TorvaldsENTRY(printhex4)
521da177e4SLinus Torvalds		mov	r1, #4
531da177e4SLinus Torvalds		b	printhex
5493ed3970SCatalin MarinasENDPROC(printhex4)
551da177e4SLinus Torvalds
561da177e4SLinus TorvaldsENTRY(printhex2)
571da177e4SLinus Torvalds		mov	r1, #2
581da177e4SLinus Torvaldsprinthex:	adr	r2, hexbuf
591da177e4SLinus Torvalds		add	r3, r2, r1
601da177e4SLinus Torvalds		mov	r1, #0
611da177e4SLinus Torvalds		strb	r1, [r3]
621da177e4SLinus Torvalds1:		and	r1, r0, #15
631da177e4SLinus Torvalds		mov	r0, r0, lsr #4
641da177e4SLinus Torvalds		cmp	r1, #10
651da177e4SLinus Torvalds		addlt	r1, r1, #'0'
661da177e4SLinus Torvalds		addge	r1, r1, #'a' - 10
671da177e4SLinus Torvalds		strb	r1, [r3, #-1]!
681da177e4SLinus Torvalds		teq	r3, r2
691da177e4SLinus Torvalds		bne	1b
701da177e4SLinus Torvalds		mov	r0, r2
711da177e4SLinus Torvalds		b	printascii
7293ed3970SCatalin MarinasENDPROC(printhex2)
731da177e4SLinus Torvalds
74b55fa188SAfzal Mohammedhexbuf:		.space 16
75b55fa188SAfzal Mohammed
761da177e4SLinus Torvalds		.ltorg
771da177e4SLinus Torvalds
789b5a146aSNicolas Pitre#ifndef CONFIG_DEBUG_SEMIHOSTING
799b5a146aSNicolas Pitre
801da177e4SLinus TorvaldsENTRY(printascii)
810ea12930SJeremy Kerr		addruart_current r3, r1, r2
821da177e4SLinus Torvalds		b	2f
831da177e4SLinus Torvalds1:		waituart r2, r3
841da177e4SLinus Torvalds		senduart r1, r3
851da177e4SLinus Torvalds		busyuart r2, r3
861da177e4SLinus Torvalds		teq	r1, #'\n'
871da177e4SLinus Torvalds		moveq	r1, #'\r'
881da177e4SLinus Torvalds		beq	1b
891da177e4SLinus Torvalds2:		teq	r0, #0
901da177e4SLinus Torvalds		ldrneb	r1, [r0], #1
911da177e4SLinus Torvalds		teqne	r1, #0
921da177e4SLinus Torvalds		bne	1b
936ebbf2ceSRussell King		ret	lr
9493ed3970SCatalin MarinasENDPROC(printascii)
951da177e4SLinus Torvalds
961da177e4SLinus TorvaldsENTRY(printch)
970ea12930SJeremy Kerr		addruart_current r3, r1, r2
981da177e4SLinus Torvalds		mov	r1, r0
991da177e4SLinus Torvalds		mov	r0, #0
1001da177e4SLinus Torvalds		b	1b
10193ed3970SCatalin MarinasENDPROC(printch)
1029b5a146aSNicolas Pitre
103a73b59c5SUwe Kleine-König#ifdef CONFIG_MMU
104e5c5f2adSRob HerringENTRY(debug_ll_addr)
105e5c5f2adSRob Herring		addruart r2, r3, ip
106e5c5f2adSRob Herring		str	r2, [r0]
107e5c5f2adSRob Herring		str	r3, [r1]
1086ebbf2ceSRussell King		ret	lr
109e5c5f2adSRob HerringENDPROC(debug_ll_addr)
110a73b59c5SUwe Kleine-König#endif
111e5c5f2adSRob Herring
1129b5a146aSNicolas Pitre#else
1139b5a146aSNicolas Pitre
1149b5a146aSNicolas PitreENTRY(printascii)
1159b5a146aSNicolas Pitre		mov	r1, r0
1169b5a146aSNicolas Pitre		mov	r0, #0x04		@ SYS_WRITE0
1179b5a146aSNicolas Pitre	ARM(	svc	#0x123456	)
118*ee3eaee6SNicolas Pitre#ifdef CONFIG_CPU_V7M
119*ee3eaee6SNicolas Pitre	THUMB(	bkpt	#0xab		)
120*ee3eaee6SNicolas Pitre#else
1219b5a146aSNicolas Pitre	THUMB(	svc	#0xab		)
122*ee3eaee6SNicolas Pitre#endif
1236ebbf2ceSRussell King		ret	lr
1249b5a146aSNicolas PitreENDPROC(printascii)
1259b5a146aSNicolas Pitre
1269b5a146aSNicolas PitreENTRY(printch)
1279b5a146aSNicolas Pitre		adr	r1, hexbuf
1289b5a146aSNicolas Pitre		strb	r0, [r1]
1299b5a146aSNicolas Pitre		mov	r0, #0x03		@ SYS_WRITEC
1309b5a146aSNicolas Pitre	ARM(	svc	#0x123456	)
131*ee3eaee6SNicolas Pitre#ifdef CONFIG_CPU_V7M
132*ee3eaee6SNicolas Pitre	THUMB(	bkpt	#0xab		)
133*ee3eaee6SNicolas Pitre#else
1349b5a146aSNicolas Pitre	THUMB(	svc	#0xab		)
135*ee3eaee6SNicolas Pitre#endif
1366ebbf2ceSRussell King		ret	lr
1379b5a146aSNicolas PitreENDPROC(printch)
1389b5a146aSNicolas Pitre
139e5c5f2adSRob HerringENTRY(debug_ll_addr)
140e5c5f2adSRob Herring		mov	r2, #0
141e5c5f2adSRob Herring		str	r2, [r0]
142e5c5f2adSRob Herring		str	r2, [r1]
1436ebbf2ceSRussell King		ret	lr
144e5c5f2adSRob HerringENDPROC(debug_ll_addr)
145e5c5f2adSRob Herring
1469b5a146aSNicolas Pitre#endif
147