Skip to contentSkip to conversation

add -semihosting-config option

PATCH Superseded Liviu Ionescu 2 participants 4 messages Nov 18, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add -semihosting-config option

The usual semihosting behaviour is to process the system calls locally and return; unfortuantelly the initial implementation dinamically changed the target to GDB during debug sessions, which, for the usual arm-none-eabi-gdb, is not implemented. The result was that during debug sessions the semihosting calls were discarded.

This patch adds a configuration variable and an option to set it on the command line:

-semihosting-config [enable=on|off,]target=native|gdb|auto

This option enables semihosting and defines where the semihosting calls will be addressed, to QEMU ('native') or to GDB ('gdb'). The default is auto, which means 'gdb' during debug sessions and 'native' otherwise.

Liviu Ionescu (1):
add semihosting-config option

 gdbstub.c               | 12 ++++++++++++
 include/sysemu/sysemu.h |  6 ++++++
 qemu-options.hx         | 12 +++++++++++-
 vl.c                    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.3 (Apple Git-50)
#1 lore raw

PATCH 1/1 add semihosting-config option

- allow to define where the semihosting calls will be addressed

---
 gdbstub.c               | 12 ++++++++++++
 include/sysemu/sysemu.h |  6 ++++++
 qemu-options.hx         | 12 +++++++++++-
 vl.c                    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
gdbstub.c +12 -0
index 0faca56..372aa67 100644
@@ -355,6 +355,18 @@ static enum {
    remote gdb syscalls.  Otherwise use native file IO.  */
 int use_gdb_syscalls(void)
 {
+    if (semihosting_target == SEMIHOSTING_TARGET_NATIVE) {
+        if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
+            gdb_syscall_mode = GDB_SYS_DISABLED;
+        }
+        return FALSE;
+    } else if (semihosting_target == SEMIHOSTING_TARGET_GDB) {
+        if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
+            gdb_syscall_mode = GDB_SYS_ENABLED;
+        }
+        return TRUE;
+    }
+
     if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
         gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED
                                             : GDB_SYS_DISABLED);
include/sysemu/sysemu.h +6 -0
index 9fea3bc..c145d94 100644
@@ -127,7 +127,13 @@ extern int cursor_hide;
 extern int graphic_rotate;
 extern int no_quit;
 extern int no_shutdown;
+
 extern int semihosting_enabled;
+extern int semihosting_target;
+#define SEMIHOSTING_TARGET_AUTO     0
+#define SEMIHOSTING_TARGET_NATIVE   1
+#define SEMIHOSTING_TARGET_GDB      2
+
 extern int old_param;
 extern int boot_menu;
 extern bool boot_strict;
qemu-options.hx +11 -1
index da9851d..3e81222 100644
@@ -3216,7 +3216,17 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting,
 STEXI
 @item -semihosting
 @findex -semihosting
-Semihosting mode (ARM, M68K, Xtensa only).
+Enable semihosting mode (ARM, M68K, Xtensa only).
+ETEXI
+DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config,
+    "-semihosting-config [enable=on|off,]target=native|gdb|auto   semihosting configuration\n",
+QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32)
+STEXI
+@item -semihosting-config [enable=on|off,]target=native|gdb|auto
+@findex -semihosting-config
+Enable semihosting and define where the semihosting calls will be addressed,
+to QEMU (@code{native}) or to GDB (@code{gdb}). The default is @code{auto}, which means
+@code{gdb} during debug sessions and @code{native} otherwise (ARM, M68K, Xtensa only).
 ETEXI
 DEF("old-param", 0, QEMU_OPTION_old_param,
     "-old-param      old param mode\n", QEMU_ARCH_ARM)
vl.c +49 -0

73 lines not on this page · raw message

Signature · 1 line
1.9.3 (Apple Git-50)
#2 lore raw

Re: [Qemu-devel] [PATCH] add semihosting-config option

Quoted 9 lines · Liviu Ionescu

- allow to define where the semihosting calls will be addressed

---
 gdbstub.c               | 12 ++++++++++++
 include/sysemu/sysemu.h |  6 ++++++
 qemu-options.hx         | 12 +++++++++++-
 vl.c                    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)

Thanks for sending this as a standalone patch. It looks pretty good, there are just a few nits:

gdbstub.c static enum { · line 355

Quoted 7 lines
gdbstub.c +0 -0
index 0faca56..372aa67 100644
@@ -355,6 +355,18 @@ static enum {
    remote gdb syscalls.  Otherwise use native file IO.  */

The comment here ^^ is now out of date...

gdbstub.c static enum { · line 366

Quoted 11 lines
gdbstub.c +9 -0
 int use_gdb_syscalls(void)
 {
+    if (semihosting_target == SEMIHOSTING_TARGET_NATIVE) {
+        if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
+            gdb_syscall_mode = GDB_SYS_DISABLED;
+        }
+        return FALSE;
+    } else if (semihosting_target == SEMIHOSTING_TARGET_GDB) {
+        if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
+            gdb_syscall_mode = GDB_SYS_ENABLED;
+        }

...and there isn't much point in these if()s I think since we will never look at gdb_syscall_mode if the semihosting_target is not auto; so we needn't set it.

gdbstub.c static enum { · line 367

Quoted 1 line
gdbstub.c +1 -0
+        return TRUE;

Also we prefer 'true' and 'false' to TRUE and FALSE.

If you like I can just fix these minor things and put the patch into my target-arm queue, or you could reroll the patch yourself if you prefer that.
(The change won't hit master until after we release 2.2 in early December, so there's no immediate hurry either way.)

(PS: if you're sending a single standalone patch you don't need to send a cover letter mail as well; the cover letter is really for providing an overall description of a multi-patch email series.)

-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH] add semihosting-config option

Quoted 1 line · Peter Maydell

...and there isn't much point in these if()s

right, removed

Quoted 1 line

Also we prefer 'true' and 'false' to TRUE and FALSE.

fixed

Quoted 2 lines

(The change won't hit master until after we release 2.2 in early December, so there's no immediate hurry either way.)

ok, I'll resume work on the rest of the patches then.

Quoted 1 line

no need to send a cover letter mail

ok

regards,

Liviu