Skip to content

Commit 6a8eb99

Browse files
committed
xtensa: ISS: add GDBIO implementation to semihosting interface
Add GDBIO implementation for the xtensa semihosting interface. It offers less functions than the simcall interface, so make some semihosting functions optional and return error when implementation is not available. Add Kconfig menu to select semihosting implementation and add simcall and GDBIO choices there. Signed-off-by: Max Filippov <[email protected]>
1 parent 54467c1 commit 6a8eb99

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

arch/xtensa/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,28 @@ config PARSE_BOOTPARAM
393393

394394
If unsure, say Y.
395395

396+
choice
397+
prompt "Semihosting interface"
398+
default XTENSA_SIMCALL_ISS
399+
depends on XTENSA_PLATFORM_ISS
400+
help
401+
Choose semihosting interface that will be used for serial port,
402+
block device and networking.
403+
404+
config XTENSA_SIMCALL_ISS
405+
bool "simcall"
406+
help
407+
Use simcall instruction. simcall is only available on simulators,
408+
it does nothing on hardware.
409+
410+
config XTENSA_SIMCALL_GDBIO
411+
bool "GDBIO"
412+
help
413+
Use break instruction. It is available on real hardware when GDB
414+
is attached to it via JTAG.
415+
416+
endchoice
417+
396418
config BLK_DEV_SIMDISK
397419
tristate "Host file-based simulated block device support"
398420
default n
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2021 Cadence Design Systems Inc. */
3+
4+
#ifndef _XTENSA_PLATFORM_ISS_SIMCALL_GDBIO_H
5+
#define _XTENSA_PLATFORM_ISS_SIMCALL_GDBIO_H
6+
7+
/*
8+
* System call like services offered by the GDBIO host.
9+
*/
10+
11+
#define SYS_open -2
12+
#define SYS_close -3
13+
#define SYS_read -4
14+
#define SYS_write -5
15+
#define SYS_lseek -6
16+
17+
static int errno;
18+
19+
static inline int __simc(int a, int b, int c, int d)
20+
{
21+
register int a1 asm("a2") = a;
22+
register int b1 asm("a6") = b;
23+
register int c1 asm("a3") = c;
24+
register int d1 asm("a4") = d;
25+
__asm__ __volatile__ (
26+
"break 1, 14\n"
27+
: "+r"(a1), "+r"(c1)
28+
: "r"(b1), "r"(d1)
29+
: "memory");
30+
errno = c1;
31+
return a1;
32+
}
33+
34+
#endif /* _XTENSA_PLATFORM_ISS_SIMCALL_GDBIO_H */

arch/xtensa/platforms/iss/include/platform/simcall.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@
1212
#ifndef _XTENSA_PLATFORM_ISS_SIMCALL_H
1313
#define _XTENSA_PLATFORM_ISS_SIMCALL_H
1414

15+
#include <linux/bug.h>
16+
17+
#ifdef CONFIG_XTENSA_SIMCALL_ISS
1518
#include <platform/simcall-iss.h>
19+
#endif
20+
#ifdef CONFIG_XTENSA_SIMCALL_GDBIO
21+
#include <platform/simcall-gdbio.h>
22+
#endif
1623

1724
static inline int simc_exit(int exit_code)
1825
{
26+
#ifdef SYS_exit
1927
return __simc(SYS_exit, exit_code, 0, 0);
28+
#else
29+
WARN_ONCE(1, "%s: not implemented\n", __func__);
30+
return -1;
31+
#endif
2032
}
2133

2234
static inline int simc_open(const char *file, int flags, int mode)
@@ -31,7 +43,12 @@ static inline int simc_close(int fd)
3143

3244
static inline int simc_ioctl(int fd, int request, void *arg)
3345
{
46+
#ifdef SYS_ioctl
3447
return __simc(SYS_ioctl, fd, request, (int) arg);
48+
#else
49+
WARN_ONCE(1, "%s: not implemented\n", __func__);
50+
return -1;
51+
#endif
3552
}
3653

3754
static inline int simc_read(int fd, void *buf, size_t count)
@@ -46,9 +63,14 @@ static inline int simc_write(int fd, const void *buf, size_t count)
4663

4764
static inline int simc_poll(int fd)
4865
{
66+
#ifdef SYS_select_one
4967
long timeval[2] = { 0, 0 };
5068

5169
return __simc(SYS_select_one, fd, XTISS_SELECT_ONE_READ, (int)&timeval);
70+
#else
71+
WARN_ONCE(1, "%s: not implemented\n", __func__);
72+
return -1;
73+
#endif
5274
}
5375

5476
static inline int simc_lseek(int fd, uint32_t off, int whence)
@@ -58,17 +80,31 @@ static inline int simc_lseek(int fd, uint32_t off, int whence)
5880

5981
static inline int simc_argc(void)
6082
{
83+
#ifdef SYS_iss_argc
6184
return __simc(SYS_iss_argc, 0, 0, 0);
85+
#else
86+
WARN_ONCE(1, "%s: not implemented\n", __func__);
87+
return 0;
88+
#endif
6289
}
6390

6491
static inline int simc_argv_size(void)
6592
{
93+
#ifdef SYS_iss_argv_size
6694
return __simc(SYS_iss_argv_size, 0, 0, 0);
95+
#else
96+
WARN_ONCE(1, "%s: not implemented\n", __func__);
97+
return 0;
98+
#endif
6799
}
68100

69101
static inline void simc_argv(void *buf)
70102
{
103+
#ifdef SYS_iss_set_argv
71104
__simc(SYS_iss_set_argv, (int)buf, 0, 0);
105+
#else
106+
WARN_ONCE(1, "%s: not implemented\n", __func__);
107+
#endif
72108
}
73109

74110
#endif /* _XTENSA_PLATFORM_ISS_SIMCALL_H */

0 commit comments

Comments
 (0)