Skip to contentSkip to conversation

Add the "-semihosting-config" option.

PATCH Applied Liviu Ionescu 2 participants 5 messages Nov 18, 2014 – Nov 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add the "-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.

---
 gdbstub.c               | 13 +++++++++++--
 include/sysemu/sysemu.h |  6 ++++++
 qemu-options.hx         | 12 +++++++++++-
 vl.c                    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 3 deletions(-)
gdbstub.c +11 -2
index 0faca56..982f039 100644
@@ -351,10 +351,19 @@ static enum {
     GDB_SYS_DISABLED,
 } gdb_syscall_mode;
 
-/* If gdb is connected when the first semihosting syscall occurs then use
-   remote gdb syscalls.  Otherwise use native file IO.  */
+/* Decide if either remote gdb syscalls or native file IO should be used. */
 int use_gdb_syscalls(void)
 {
+    if (semihosting_target == SEMIHOSTING_TARGET_NATIVE) {
+        /* -semihosting-config target=native */
+        return false;
+    } else if (semihosting_target == SEMIHOSTING_TARGET_GDB) {
+        /* -semihosting-config target=gdb */
+        return true;
+    }
+
+    /* -semihosting-config target=auto */
+    /* On the first call check if gdb is connected and remember. */
     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)
#1 lore raw
Quoted 9 lines · Liviu Ionescu

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:

Quoted 7 lines

-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.

Applied to target-arm.next, thanks.

-- PMM

#2 lore raw
Quoted 12 lines · Peter Maydell
Quoted 11 lines · Liviu Ionescu

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

Quoted 7 lines
Quoted 5 lines

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.

Applied to target-arm.next, thanks.

...but I should have tested it a bit better. I had to move the declaration and definition of semihosting_target to gdbstub.h and gdbstub.c, because otherwise the linux-user targets won't compile. (They don't compile vl.c.)

thanks
-- PMM

#3 lore raw
Quoted 4 lines · Peter Maydell

... I had to move the
declaration and definition of semihosting_target to gdbstub.h and gdbstub.c, because otherwise the linux-user targets won't compile. (They don't compile vl.c.)

:-(

please let me know when the changes are functional in your repo.

Liviu

#4 lore raw
Quoted 11 lines · Liviu Ionescu
Quoted 4 lines · Peter Maydell

... I had to move the
declaration and definition of semihosting_target to gdbstub.h and gdbstub.c, because otherwise the linux-user targets won't compile. (They don't compile vl.c.)

:-(

please let me know when the changes are functional in your repo.

I have pushed the minor change to my target-arm.next branch.

-- PMM