Skip to content

Commit 95ad7e0

Browse files
committed
Merge branch 'for-next/semihosting' into next
2 parents 6ffdcf2 + 1d2df6d commit 95ad7e0

File tree

18 files changed

+227
-88
lines changed

18 files changed

+227
-88
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ config ARM_UNWIND
372372

373373
config ARM_SEMIHOSTING
374374
bool "enable ARM semihosting support"
375-
depends on !CPU_V8
375+
select SEMIHOSTING
376376
help
377377
This option enables ARM semihosting support in barebox. ARM
378378
semihosting is a communication discipline that allows code

arch/arm/cpu/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ obj-pbl-y += setupc_$(S64_32).o cache_$(S64_32).o
2323

2424
obj-$(CONFIG_ARM_PSCI_CLIENT) += psci-client.o
2525

26+
obj-$(CONFIG_ARM_SEMIHOSTING) += semihosting-trap_$(S64_32).o
27+
2628
#
2729
# Any variants can be called as start-armxyz.S
2830
#
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* SPDX-FileCopyrightText: 2015 Zodiac Inflight Innovations */
33

44
/*
5-
* semihosting-trap.S -- Assembly code needed to make a semihosting call
5+
* semihosting-trap_32.S -- Assembly code needed to make a semihosting call
66
*
77
* Author: Andrey Smirnov <andrew.smirnov@gmail.com>
88
*/

arch/arm/cpu/semihosting-trap_64.S

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#include <linux/linkage.h>
4+
#include <asm/unified.h>
5+
6+
.section .text.semihosting_trap
7+
ENTRY(semihosting_trap)
8+
hlt #0xf000
9+
ret
10+
ENDPROC(semihosting_trap)

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: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,38 @@
33
#ifndef __ASM_ARM_SEMIHOSTING_H
44
#define __ASM_ARM_SEMIHOSTING_H
55

6-
int semihosting_open(const char *fname, int flags);
7-
int semihosting_close(int fd);
8-
int semihosting_writec(char c);
9-
int semihosting_write0(const char *str);
10-
ssize_t semihosting_write(int fd, const void *buf, size_t count);
11-
ssize_t semihosting_read(int fd, void *buf, size_t count);
12-
int semihosting_readc(void);
13-
int semihosting_isatty(int fd);
14-
int semihosting_seek(int fd, loff_t pos);
15-
int semihosting_flen(int fd);
16-
int semihosting_remove(const char *fname);
17-
int semihosting_rename(const char *fname1, const char *fname2);
18-
int semihosting_errno(void);
19-
int semihosting_system(const char *command);
6+
#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+
}
2039

2140
#endif

arch/arm/lib32/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pbl-y += runtime-offset.o
2323
obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memcpy.o
2424
obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memset.o
2525
obj-$(CONFIG_ARM_UNWIND) += unwind.o
26-
obj-$(CONFIG_ARM_SEMIHOSTING) += semihosting-trap.o semihosting.o
2726
obj-$(CONFIG_MODULES) += module.o
2827
obj-$(CONFIG_ARM_MODULE_PLTS) += module-plts.o
2928
extra-y += barebox.lds

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
menu "Firmware Drivers"
33

4+
config SEMIHOSTING
5+
bool
6+
select HAS_DEBUG_LL
7+
48
config FIRMWARE_ALTERA_SERIAL
59
bool "Altera SPI programming"
610
depends on OFDEVICE

drivers/firmware/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2+
obj-$(CONFIG_SEMIHOSTING) += semihosting.o
23
obj-$(CONFIG_FIRMWARE_ALTERA_SERIAL) += altera_serial.o
34
obj-$(CONFIG_FIRMWARE_ALTERA_SOCFPGA) += socfpga.o socfpga_sdr.o
45
obj-$(CONFIG_FIRMWARE_ZYNQMP_FPGA) += zynqmp-fpga.o

0 commit comments

Comments
 (0)