* [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option.
@ 2014-11-18 20:19 Liviu Ionescu
2014-11-19 10:31 ` Peter Maydell
0 siblings, 1 reply; 5+ messages in thread
From: Liviu Ionescu @ 2014-11-18 20:19 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, ilg
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.
Signed-off-by: Liviu Ionescu <ilg@livius.net>
---
gdbstub.c | 13 +++++++++++--
include/sysemu/sysemu.h | 6 ++++++
qemu-options.hx | 12 +++++++++++-
vl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/gdbstub.c b/gdbstub.c
index 0faca56..982f039 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -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);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 9fea3bc..c145d94 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -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;
diff --git a/qemu-options.hx b/qemu-options.hx
index da9851d..3e81222 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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)
diff --git a/vl.c b/vl.c
index f4a6e5e..8844983 100644
--- a/vl.c
+++ b/vl.c
@@ -172,6 +172,7 @@ const char *watchdog;
QEMUOptionRom option_rom[MAX_OPTION_ROMS];
int nb_option_roms;
int semihosting_enabled = 0;
+int semihosting_target = SEMIHOSTING_TARGET_AUTO;
int old_param = 0;
const char *qemu_name;
int alt_grab = 0;
@@ -554,6 +555,22 @@ static QemuOptsList qemu_icount_opts = {
},
};
+static QemuOptsList qemu_semihosting_config_opts = {
+ .name = "semihosting-config",
+ .implied_opt_name = "enable",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head),
+ .desc = {
+ {
+ .name = "enable",
+ .type = QEMU_OPT_BOOL,
+ }, {
+ .name = "target",
+ .type = QEMU_OPT_STRING,
+ },
+ { /* end of list */ }
+ },
+};
+
/**
* Get machine options
*
@@ -2811,6 +2828,7 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_name_opts);
qemu_add_opts(&qemu_numa_opts);
qemu_add_opts(&qemu_icount_opts);
+ qemu_add_opts(&qemu_semihosting_config_opts);
runstate_init();
@@ -3618,6 +3636,37 @@ int main(int argc, char **argv, char **envp)
break;
case QEMU_OPTION_semihosting:
semihosting_enabled = 1;
+ semihosting_target = SEMIHOSTING_TARGET_AUTO;
+ break;
+ case QEMU_OPTION_semihosting_config:
+ semihosting_enabled = 1;
+ opts = qemu_opts_parse(qemu_find_opts("semihosting-config"),
+ optarg, 0);
+ if (opts != NULL) {
+ semihosting_enabled = qemu_opt_get_bool(opts, "enable",
+ true);
+ const char *target = qemu_opt_get(opts, "target");
+ if (target != NULL) {
+ if (strcmp("native", target) == 0) {
+ semihosting_target = SEMIHOSTING_TARGET_NATIVE;
+ } else if (strcmp("gdb", target) == 0) {
+ semihosting_target = SEMIHOSTING_TARGET_GDB;
+ } else if (strcmp("auto", target) == 0) {
+ semihosting_target = SEMIHOSTING_TARGET_AUTO;
+ } else {
+ fprintf(stderr, "Unsupported semihosting-config"
+ " %s\n",
+ optarg);
+ exit(1);
+ }
+ } else {
+ semihosting_target = SEMIHOSTING_TARGET_AUTO;
+ }
+ } else {
+ fprintf(stderr, "Unsupported semihosting-config %s\n",
+ optarg);
+ exit(1);
+ }
break;
case QEMU_OPTION_tdf:
fprintf(stderr, "Warning: user space PIT time drift fix "
--
1.9.3 (Apple Git-50)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option.
2014-11-18 20:19 [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option Liviu Ionescu
@ 2014-11-19 10:31 ` Peter Maydell
2014-11-20 15:22 ` Peter Maydell
0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2014-11-19 10:31 UTC (permalink / raw)
To: Liviu Ionescu; +Cc: QEMU Developers
On 18 November 2014 20:19, Liviu Ionescu <ilg@livius.net> wrote:
> 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.
>
> Signed-off-by: Liviu Ionescu <ilg@livius.net>
Applied to target-arm.next, thanks.
-- PMM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option.
2014-11-19 10:31 ` Peter Maydell
@ 2014-11-20 15:22 ` Peter Maydell
2014-11-20 15:35 ` Liviu Ionescu
0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2014-11-20 15:22 UTC (permalink / raw)
To: Liviu Ionescu; +Cc: QEMU Developers
On 19 November 2014 10:31, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 18 November 2014 20:19, Liviu Ionescu <ilg@livius.net> wrote:
>> 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.
>>
>> Signed-off-by: Liviu Ionescu <ilg@livius.net>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option.
2014-11-20 15:22 ` Peter Maydell
@ 2014-11-20 15:35 ` Liviu Ionescu
2014-11-20 15:43 ` Peter Maydell
0 siblings, 1 reply; 5+ messages in thread
From: Liviu Ionescu @ 2014-11-20 15:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: QEMU Developers
On 20 Nov 2014, at 17:22, Peter Maydell <peter.maydell@linaro.org> wrote:
> ... 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option.
2014-11-20 15:35 ` Liviu Ionescu
@ 2014-11-20 15:43 ` Peter Maydell
0 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2014-11-20 15:43 UTC (permalink / raw)
To: Liviu Ionescu; +Cc: QEMU Developers
On 20 November 2014 15:35, Liviu Ionescu <ilg@livius.net> wrote:
>
> On 20 Nov 2014, at 17:22, Peter Maydell <peter.maydell@linaro.org> wrote:
>
>> ... 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-11-20 15:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-18 20:19 [Qemu-devel] [PATCH v2] Add the "-semihosting-config" option Liviu Ionescu
2014-11-19 10:31 ` Peter Maydell
2014-11-20 15:22 ` Peter Maydell
2014-11-20 15:35 ` Liviu Ionescu
2014-11-20 15:43 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).