Skip to content

Commit 0e87c40

Browse files
a3fsaschahauer
authored andcommitted
ARM: semihosting: add DEBUG_LL implementation
Both OpenOCD and QEMU have a semihosting implementation that provides a console suitable for low level debugging. Add a DEBUG_LL implementation that is usable when QEMU is called with --semihosting-config chardev=serial0 or following OpenOCD is executed: arm semihosting enable Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240611065923.2900168-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
1 parent 5f87fad commit 0e87c40

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

arch/arm/include/asm/debug_ll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include <mach/layerscape/debug_ll.h>
3636
#endif
3737

38+
#ifdef CONFIG_DEBUG_SEMIHOSTING
39+
#include <debug_ll/semihosting.h>
40+
#endif
41+
3842
#ifdef CONFIG_DEBUG_QEMU_ARM64_VIRT
3943
#define DEBUG_LL_UART_ADDR 0x9000000
4044
#include <debug_ll/pl011.h>

arch/arm/include/asm/semihosting.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,37 @@
44
#define __ASM_ARM_SEMIHOSTING_H
55

66
#include <asm-generic/semihosting.h>
7+
#include <asm/unified.h>
8+
9+
static inline void semihosting_putc(void *unused, int c)
10+
{
11+
/* We may not be relocated yet here, so we push
12+
* to stack and take address of that
13+
*/
14+
#ifdef CONFIG_CPU_64
15+
asm volatile (
16+
"stp %0, xzr, [sp, #-16]!\n"
17+
"mov x1, sp\n"
18+
"mov x0, #0x03\n"
19+
"hlt #0xf000\n"
20+
"add sp, sp, #16\n"
21+
: /* No outputs */
22+
: "r" ((long)c)
23+
: "x0", "x1", "x2", "x3", "x12", "memory"
24+
);
25+
#else
26+
asm volatile (
27+
"push {%0}\n"
28+
"mov r1, sp\n"
29+
"mov r0, #0x03\n"
30+
ARM( "bkpt #0x123456\n")
31+
THUMB( "bkpt #0xAB\n")
32+
"pop {%0}\n"
33+
: /* No outputs */
34+
: "r" (c)
35+
: "r0", "r1", "r2", "r3", "r12", "memory"
36+
);
37+
#endif
38+
}
739

840
#endif

common/Kconfig.debug_ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,19 @@ config DEBUG_QEMU_ARM64_VIRT
337337
bool "QEMU ARM64 Virt PL011 console"
338338
depends on ARCH_ARM64_VIRT
339339

340+
config DEBUG_SEMIHOSTING
341+
bool "Semihosting console"
342+
depends on SEMIHOSTING
343+
help
344+
Semihosting enables code to use the I/O facilities on a
345+
host debugger/emulator through a simple supervisor call.
346+
The host debugger or emulator must have semihosting enabled
347+
for the supervisor call to be trapped, otherwise barebox
348+
will crash.
349+
350+
Say Y here if you want low-level debugging support
351+
using semihosting writec.
352+
340353
endchoice
341354

342355
config DEBUG_LL_NS16550

drivers/firmware/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ menu "Firmware Drivers"
33

44
config SEMIHOSTING
55
bool
6+
select HAS_DEBUG_LL
67

78
config FIRMWARE_ALTERA_SERIAL
89
bool "Altera SPI programming"

include/debug_ll/semihosting.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef __DEBUG_LL_SEMIHOSTING_H
3+
#define __DEBUG_LL_SEMIHOSTING_H
4+
5+
#include <asm/semihosting.h>
6+
#include <linux/stddef.h>
7+
8+
#ifdef CONFIG_DEBUG_SEMIHOSTING
9+
static inline void PUTC_LL(char c)
10+
{
11+
semihosting_putc(NULL, c);
12+
}
13+
#endif
14+
15+
#endif /* __DEBUG_LL_ARM_SEMIHOSTING_H */

0 commit comments

Comments
 (0)