semihosting cleanup and re-factor
cover semihosting cleanup and re-factor
Hi,
This collects together some fixes from last weeks RFC clean-up patch as well as a generalised version of the chardev console tweak I made last week for testing/next. As it happens it only really made sense for ARM and MIPs logging semihost calls but there is certainly scope for handling all the semihost syscalls in a more common way. I didn't make the changes to xtensa as that already has a bi-directional console-via-chardev setup and that would be quite a bit of extra work to support.
I've added myself to the MAINTAINERS section for the common code but my focus at the moment is really just to improve the use of semihosting in our expanding system tests. Hopefully this is enough to ensure future enhancements (common open/read/write/close?) can be done and easily enabled for all semihost targets.
Please review.
Alex Bennée (11):
semihosting: move semihosting configuration into its own directory
semihosting: introduce CONFIG_SEMIHOSTING
semihosting: implement a semihosting console
semihosting: enable chardev backed output for console target/arm: fixup some of the commentary for arm-semi target/arm: use the common interface for WRITE0/WRITEC in arm-semi target/arm: add LOG_UNIMP messages to arm-semi target/arm: correct return values for WRITE/READ in arm-semi target/mips: only build mips-semi for softmmu target/mips: convert UHI_plog to use common semihosting code
MAINTAINERS: update for semihostings new home
MAINTAINERS | 7 +
default-configs/arm-softmmu.mak | 1 +
default-configs/lm32-softmmu.mak | 2 +
default-configs/m68k-softmmu.mak | 2 +
default-configs/mips-softmmu-common.mak | 1 +
default-configs/nios2-softmmu.mak | 2 +
default-configs/xtensa-softmmu.mak | 2 +
gdbstub.c | 7 +-
hw/Kconfig | 1 +
hw/Makefile.objs | 1 +
hw/mips/mips_malta.c | 2 +-
hw/semihosting/Kconfig | 3 +
hw/semihosting/Makefile.objs | 2 +
hw/semihosting/config.c | 186 ++++++++++++++++++++
hw/semihosting/console.c | 77 ++++++++
include/exec/gdbstub.h | 11 ++
include/hw/semihosting/console.h | 38 ++++
include/{exec => hw/semihosting}/semihost.h | 17 +-
include/sysemu/sysemu.h | 1 +
linux-user/Makefile.objs | 2 +
linux-user/arm/semihost.c | 24 +++
qemu-options.hx | 6 +-
stubs/Makefile.objs | 1 +
stubs/semihost.c | 70 ++++++++
target/arm/arm-semi.c | 98 ++++++-----
target/arm/helper.c | 2 +-
target/arm/translate-a64.c | 2 +-
target/arm/translate.c | 2 +-
target/lm32/helper.c | 2 +-
target/m68k/op_helper.c | 2 +-
target/mips/Makefile.objs | 3 +-
target/mips/helper.h | 2 +
target/mips/mips-semi.c | 14 +-
target/mips/translate.c | 10 +-
target/nios2/helper.c | 2 +-
target/xtensa/translate.c | 2 +-
target/xtensa/xtensa-semi.c | 2 +-
vl.c | 128 +-------------
38 files changed, 545 insertions(+), 192 deletions(-)
create mode 100644 hw/semihosting/Kconfig
create mode 100644 hw/semihosting/Makefile.objs
create mode 100644 hw/semihosting/config.c
create mode 100644 hw/semihosting/console.c
create mode 100644 include/hw/semihosting/console.h
rename include/{exec => hw/semihosting}/semihost.h (78%)
create mode 100644 linux-user/arm/semihost.c
create mode 100644 stubs/semihost.cSignature · 1 line
2.20.1
RFC PATCH 1/11 semihosting: move semihosting configuration into its own directory
In preparation for having some more common semihosting code let's excise the current config magic from vl.c into its own file. We shall later add more conditionals to the build configurations so we can avoid building this if we don't need it.
---
gdbstub.c | 2 +-
hw/Makefile.objs | 1 +
hw/mips/mips_malta.c | 2 +-
hw/semihosting/Makefile.objs | 1 +
hw/semihosting/config.c | 160 ++++++++++++++++++++
include/{exec => hw/semihosting}/semihost.h | 10 +-
include/sysemu/sysemu.h | 1 +
target/arm/arm-semi.c | 2 +-
target/arm/helper.c | 2 +-
target/arm/translate-a64.c | 2 +-
target/arm/translate.c | 2 +-
target/lm32/helper.c | 2 +-
target/m68k/op_helper.c | 2 +-
target/mips/mips-semi.c | 2 +-
target/mips/translate.c | 2 +-
target/nios2/helper.c | 2 +-
target/xtensa/translate.c | 2 +-
target/xtensa/xtensa-semi.c | 2 +-
vl.c | 126 +--------------
19 files changed, 186 insertions(+), 139 deletions(-)
create mode 100644 hw/semihosting/Makefile.objs
create mode 100644 hw/semihosting/config.c
rename include/{exec => hw/semihosting}/semihost.h (85%)gdbstub.c +1 -1
@@ -37,7 +37,7 @@#include "qemu/sockets.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/exec-all.h" #ifdef CONFIG_USER_ONLY
hw/Makefile.objs +1 -0
@@ -36,6 +36,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ +devices-dirs-y += semihosting/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y)
hw/mips/mips_malta.c +1 -1
@@ -55,7 +55,7 @@#include "qemu/error-report.h" #include "hw/empty_slot.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "hw/mips/cps.h" #define ENVP_ADDR 0x80002000l
hw/semihosting/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +common-obj-$(CONFIG_SOFTMMU) += config.o
hw/semihosting/config.c new file +160 -0
160 lines not on this page · raw message
include/hw/semihosting/semihost.h renamed from include/exec/semihost.h +7 -3
@@ -51,12 +51,16 @@ static inline const char *semihosting_get_cmdline(void) {return NULL ; } -#else +#else /* !CONFIG_USER_ONLY */ bool semihosting_enabled (void );SemihostingTarget semihosting_get_target (void );const char *semihosting_get_arg (int i);int semihosting_get_argc (void );const char *semihosting_get_cmdline (void ); -#endif +void semihosting_arg_fallback (const char *file,const char *cmd); +/* for vl.c hooks */ +void qemu_semihosting_enable (void ); +int qemu_semihosting_config_options (const char *opt); +#endif /* CONFIG_USER_ONLY */ -#endif +#endif /* SEMIHOST_H */
include/sysemu/sysemu.h +1 -0
@@ -193,5 +193,6 @@ extern QemuOptsList qemu_nic_opts;extern QemuOptsList qemu_net_opts;extern QemuOptsList qemu_global_opts;extern QemuOptsList qemu_mon_opts; +extern QemuOptsList qemu_semihosting_config_opts;#endif
target/arm/arm-semi.c +1 -1
@@ -21,7 +21,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #ifdef CONFIG_USER_ONLY #include "qemu.h"
target/arm/helper.c +1 -1
@@ -16,7 +16,7 @@#include "exec/cpu_ldst.h" #include "arm_ldst.h" #include <zlib.h> /* For crc32 */ -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h"
target/arm/translate-a64.c +1 -1
@@ -29,7 +29,7 @@#include "qemu/host-utils.h" #include "qemu/qemu-print.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/gen-icount.h" #include "exec/helper-proto.h"
target/arm/translate.c +1 -1
@@ -30,7 +30,7 @@#include "qemu/bitops.h" #include "qemu/qemu-print.h" #include "arm_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/helper-proto.h" #include "exec/helper-gen.h"
target/lm32/helper.c +1 -1
@@ -22,7 +22,7 @@#include "exec/exec-all.h" #include "qemu/host-utils.h" #include "sysemu/sysemu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/log.h" int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw,
target/m68k/op_helper.c +1 -1
@@ -21,7 +21,7 @@#include "exec/helper-proto.h" #include "exec/exec-all.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY )
target/mips/mips-semi.c +1 -1
@@ -22,7 +22,7 @@#include "qemu/log.h" #include "exec/helper-proto.h" #include "exec/softmmu-semi.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" typedef enum UHIOp { UHI_exit = 1,
target/mips/translate.c +1 -1
@@ -32,7 +32,7 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "target/mips/trace.h" #include "trace-tcg.h"
target/nios2/helper.c +1 -1
@@ -26,7 +26,7 @@#include "exec/cpu_ldst.h" #include "exec/log.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY )
target/xtensa/translate.c +1 -1
@@ -38,7 +38,7 @@#include "qemu/qemu-print.h" #include "sysemu/sysemu.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/translator.h" #include "exec/helper-proto.h"
target/xtensa/xtensa-semi.c +1 -1
@@ -29,7 +29,7 @@#include "cpu.h" #include "chardev/char-fe.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "qapi/error.h" #include "qemu/log.h" #include "sysemu/sysemu.h"
vl.c +3 -123
152 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 01/11] semihosting: move semihosting configuration into its own directory
Quoted 6 lines · Alex Bennée
In preparation for having some more common semihosting code let's excise the current config magic from
vl.cinto its own file. We shall later add more conditionals to the build configurations so we can avoid building this if we don't need it.Signed-off-by Alex Bennée <[email protected]>
Quoted 578 lines
--- gdbstub.c | 2 +- hw/Makefile.objs | 1 + hw/mips/mips_malta.c | 2 +- hw/semihosting/Makefile.objs | 1 + hw/semihosting/config.c | 160 ++++++++++++++++++++ include/{exec => hw/semihosting}/semihost.h | 10 +- include/sysemu/sysemu.h | 1 + target/arm/arm-semi.c | 2 +- target/arm/helper.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 2 +- target/lm32/helper.c | 2 +- target/m68k/op_helper.c | 2 +- target/mips/mips-semi.c | 2 +- target/mips/translate.c | 2 +- target/nios2/helper.c | 2 +- target/xtensa/translate.c | 2 +- target/xtensa/xtensa-semi.c | 2 +- vl.c | 126 +-------------- 19 files changed, 186 insertions(+), 139 deletions(-) create mode 100644 hw/semihosting/Makefile.objs create mode 100644 hw/semihosting/config.c rename include/{exec => hw/semihosting}/semihost.h (85%)gdbstub.c +1
-1@@ -37,7 +37,7 @@#include "qemu/sockets.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/exec-all.h" #ifdef CONFIG_USER_ONLY hw/Makefile.objs +1
-0@@ -36,6 +36,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ +devices-dirs-y += semihosting/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y)hw/mips/mips_malta.c +1
-1@@ -55,7 +55,7 @@#include "qemu/error-report.h" #include "hw/empty_slot.h" #include "sysemu/kvm.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "hw/mips/cps.h" #define ENVP_ADDR 0x80002000lhw/semihosting/Makefile.objs new file +1
-0@@ -0,0 +1 @@ +common-obj-$(CONFIG_SOFTMMU) += config.ohw/semihosting/config.c new file +160
-0@@ -0,0 +1,160 @@ +/* +* Semihosting configuration +* +* Copyright (c) 2015 Imagination Technologies +* Copyright (c) 2019 Linaro Ltd +* +* This controls the configuration of semihosting for all guest +* targets that support it. Architecture specific handling is handled +* in target/HW/HW-semi.c +* +* Semihosting is sightly strange in that it is also supported by some +* linux-user targets. However in that use case no configuration of +* the outputs and command lines is supported. +* +* The config module is common to all softmmu targets however as vl.c +* needs to link against the helpers. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "hw/semihosting/semihost.h" + +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 , + }, { + .name ="arg" , + .type =QEMU_OPT_STRING , + }, + {/* end of list */ } + }, +}; + +typedef struct SemihostingConfig { +bool enabled; +SemihostingTarget target; +const char **argv; +int argc; +const char *cmdline;/* concatenated argv */ +}SemihostingConfig ; + +static SemihostingConfig semihosting; + +bool semihosting_enabled (void ) +{ +return semihosting.enabled; +} + +SemihostingTarget semihosting_get_target (void ) +{ +return semihosting.target; +} + +const char *semihosting_get_arg (int i) +{ +if (i >= semihosting.argc) { +return NULL ; + } +return semihosting.argv[i]; +} + +int semihosting_get_argc (void ) +{ +return semihosting.argc; +} + +const char *semihosting_get_cmdline (void ) +{ +if (semihosting.cmdline ==NULL && semihosting.argc >0 ) { + semihosting.cmdline =g_strjoinv (" " , (gchar **)semihosting.argv); + } +return semihosting.cmdline; +} + +static int add_semihosting_arg (void *opaque, +const char *name,const char *val, +Error **errp) +{ +SemihostingConfig *s = opaque; +if (strcmp (name,"arg" ) ==0 ) { + s->argc++; +/* one extra element as g_strjoinv() expects NULL-terminated array */ + s->argv =g_realloc (s->argv, (s->argc +1 ) *sizeof (void *)); + s->argv[s->argc -1 ] = val; + s->argv[s->argc] =NULL ; + } +return 0 ; +} + +/* Use strings passed via -kernel/-append to initialize semihosting.argv[] */ +void semihosting_arg_fallback (const char *file,const char *cmd) +{ +char *cmd_token; + +/* argv[0] */ +add_semihosting_arg (&semihosting,"arg" , file,NULL ); + +/* split -append and initialize argv[1..n] */ + cmd_token =strtok (g_strdup (cmd)," " ); +while (cmd_token) { +add_semihosting_arg (&semihosting,"arg" , cmd_token,NULL ); + cmd_token =strtok (NULL ," " ); + } +} + +void qemu_semihosting_enable (void ) +{ + semihosting.enabled = true; + semihosting.target =SEMIHOSTING_TARGET_AUTO ; +} + +int qemu_semihosting_config_options (const char *optarg) +{ +QemuOptsList *opt_list =qemu_find_opts ("semihosting-config" ); +QemuOpts *opts =qemu_opts_parse_noisily (opt_list, optarg, false); + + semihosting.enabled = true; + +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 { +error_report ("unsupported semihosting-config %s" , + optarg); +return 1 ; + } + }else { + semihosting.target =SEMIHOSTING_TARGET_AUTO ; + } +/* Set semihosting argument count and vector */ +qemu_opt_foreach (opts, add_semihosting_arg, + &semihosting,NULL ); + }else { +error_report ("unsupported semihosting-config %s" , optarg); +return 1 ; + } + +return 0 ; +} +include/hw/semihosting/semihost.h renamed from include/exec/semihost.h +7
-3@@ -51,12 +51,16 @@ static inline const char *semihosting_get_cmdline(void) {return NULL ; } -#else +#else /* !CONFIG_USER_ONLY */ bool semihosting_enabled (void );SemihostingTarget semihosting_get_target (void );const char *semihosting_get_arg (int i);int semihosting_get_argc (void );const char *semihosting_get_cmdline (void ); -#endif +void semihosting_arg_fallback (const char *file,const char *cmd); +/* for vl.c hooks */ +void qemu_semihosting_enable (void ); +int qemu_semihosting_config_options (const char *opt); +#endif /* CONFIG_USER_ONLY */ -#endif +#endif /* SEMIHOST_H */ include/sysemu/sysemu.h +1
-0@@ -193,5 +193,6 @@ extern QemuOptsList qemu_nic_opts;extern QemuOptsList qemu_net_opts;extern QemuOptsList qemu_global_opts;extern QemuOptsList qemu_mon_opts; +extern QemuOptsList qemu_semihosting_config_opts;#endif target/arm/arm-semi.c +1
-1@@ -21,7 +21,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" target/arm/helper.c +1
-1@@ -16,7 +16,7 @@#include "exec/cpu_ldst.h" #include "arm_ldst.h" #include <zlib.h> /* For crc32 */ -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" target/arm/translate-a64.c +1
-1@@ -29,7 +29,7 @@#include "qemu/host-utils.h" #include "qemu/qemu-print.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/gen-icount.h" #include "exec/helper-proto.h" target/arm/translate.c +1
-1@@ -30,7 +30,7 @@#include "qemu/bitops.h" #include "qemu/qemu-print.h" #include "arm_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/helper-proto.h" #include "exec/helper-gen.h" target/lm32/helper.c +1
-1@@ -22,7 +22,7 @@#include "exec/exec-all.h" #include "qemu/host-utils.h" #include "sysemu/sysemu.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/log.h" int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw,target/m68k/op_helper.c +1
-1@@ -21,7 +21,7 @@#include "exec/helper-proto.h" #include "exec/exec-all.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY )target/mips/mips-semi.c +1
-1@@ -22,7 +22,7 @@#include "qemu/log.h" #include "exec/helper-proto.h" #include "exec/softmmu-semi.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" typedef enum UHIOp { UHI_exit = 1,target/mips/translate.c +1
-1@@ -32,7 +32,7 @@#include "exec/helper-proto.h" #include "exec/helper-gen.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "target/mips/trace.h" #include "trace-tcg.h" target/nios2/helper.c +1
-1@@ -26,7 +26,7 @@#include "exec/cpu_ldst.h" #include "exec/log.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #if defined(CONFIG_USER_ONLY )target/xtensa/translate.c +1
-1@@ -38,7 +38,7 @@#include "qemu/qemu-print.h" #include "sysemu/sysemu.h" #include "exec/cpu_ldst.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "exec/translator.h" #include "exec/helper-proto.h" target/xtensa/xtensa-semi.c +1
-1@@ -29,7 +29,7 @@#include "cpu.h" #include "chardev/char-fe.h" #include "exec/helper-proto.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "qapi/error.h" #include "qemu/log.h" #include "sysemu/sysemu.h" vl.c +3
-123@@ -116,7 +116,7 @@ int main(int argc, char **argv)#include "qapi/opts-visitor.h" #include "qapi/clone-visitor.h" #include "qom/object_interfaces.h" -#include "exec/semihost.h" +#include "hw/semihosting/semihost.h" #include "crypto/init.h" #include "sysemu/replay.h" #include "qapi/qapi-events-run-state.h" @@ -500,25 +500,6 @@ 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 , - }, { - .name ="arg" , - .type =QEMU_OPT_STRING , - }, - {/* end of list */ } - }, -}; -static QemuOptsList qemu_fw_cfg_opts = { .name ="fw_cfg" , .implied_opt_name ="name" ,@@ -1350,80 +1331,6 @@ static void configure_msg(QemuOpts *opts) enable_timestamp_msg =qemu_opt_get_bool (opts,"timestamp" , true); } -/***********************************************************/ -/* Semihosting */ - -typedef struct SemihostingConfig { -bool enabled; -SemihostingTarget target; -const char **argv; -int argc; -const char *cmdline;/* concatenated argv */ -}SemihostingConfig ; - -static SemihostingConfig semihosting; - -bool semihosting_enabled (void ) -{ -return semihosting.enabled; -} - -SemihostingTarget semihosting_get_target (void ) -{ -return semihosting.target; -} - -const char *semihosting_get_arg (int i) -{ -if (i >= semihosting.argc) { -return NULL ; - } -return semihosting.argv[i]; -} - -int semihosting_get_argc (void ) -{ -return semihosting.argc; -} - -const char *semihosting_get_cmdline (void ) -{ -if (semihosting.cmdline ==NULL && semihosting.argc >0 ) { - semihosting.cmdline =g_strjoinv (" " , (gchar **)semihosting.argv); - } -return semihosting.cmdline; -} - -static int add_semihosting_arg (void *opaque, -const char *name,const char *val, -Error **errp) -{ -SemihostingConfig *s = opaque; -if (strcmp (name,"arg" ) ==0 ) { - s->argc++; -/* one extra element as g_strjoinv() expects NULL-terminated array */ - s->argv =g_realloc (s->argv, (s->argc +1 ) *sizeof (void *)); - s->argv[s->argc -1 ] = val; - s->argv[s->argc] =NULL ; - } -return 0 ; -} - -/* Use strings passed via -kernel/-append to initialize semihosting.argv[] */ -static inline void semihosting_arg_fallback (const char *file,const char *cmd) -{ -char *cmd_token; - -/* argv[0] */ -add_semihosting_arg (&semihosting,"arg" , file,NULL ); - -/* split -append and initialize argv[1..n] */ - cmd_token =strtok (g_strdup (cmd)," " ); -while (cmd_token) { -add_semihosting_arg (&semihosting,"arg" , cmd_token,NULL ); - cmd_token =strtok (NULL ," " ); - } -}/* Now we still need this for compatibility with XEN. */ bool has_igd_gfx_passthru;@@ -3733,37 +3640,10 @@ int main(int argc, char **argv, char **envp) nb_option_roms++;break ;case QEMU_OPTION_semihosting: - semihosting.enabled = true; - semihosting.target =SEMIHOSTING_TARGET_AUTO ; +qemu_semihosting_enable ();break ;case QEMU_OPTION_semihosting_config: - semihosting.enabled = true; - opts =qemu_opts_parse_noisily (qemu_find_opts ("semihosting-config" ), - optarg, false); -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 { -error_report ("unsupported semihosting-config %s" , - optarg); -exit (1 ); - } - }else { - semihosting.target =SEMIHOSTING_TARGET_AUTO ; - } -/* Set semihosting argument count and vector */ -qemu_opt_foreach (opts, add_semihosting_arg, - &semihosting,NULL ); - }else { -error_report ("unsupported semihosting-config %s" , optarg); +if (qemu_semihosting_config_options (optarg) !=0 ) {exit (1 ); }break ;
RFC PATCH 2/11 semihosting: introduce CONFIG_SEMIHOSTING
In reply to Alex BennéeThere isn't much point building semihosting for platforms that don't support it. Introduce a new symbol and enable it only for the softmmu targets that need it.
--- default-configs/arm-softmmu.mak | 1 + default-configs/lm32-softmmu.mak | 2 + default-configs/m68k-softmmu.mak | 2 + default-configs/mips-softmmu-common.mak | 1 + default-configs/nios2-softmmu.mak | 2 + default-configs/xtensa-softmmu.mak | 2 + hw/Kconfig | 1 + hw/semihosting/Kconfig | 3 ++ hw/semihosting/Makefile.objs | 2 +- stubs/Makefile.objs | 1 + stubs/semihost.c | 66 +++++++++++++++++++++++++ 11 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 hw/semihosting/Kconfig create mode 100644 stubs/semihost.c
default-configs/arm-softmmu.mak +1 -0
@@ -39,3 +39,4 @@ CONFIG_MICROBIT=y CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y +CONFIG_SEMIHOSTING=y
default-configs/lm32-softmmu.mak +2 -0
@@ -4,6 +4,8 @@ # #CONFIG_MILKYMIST_TMU2=n # disabling it actually causes compile-time failures +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_LM32=y
default-configs/m68k-softmmu.mak +2 -0
@@ -1,5 +1,7 @@ # Default configuration for m68k-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_AN5206=y
default-configs/mips-softmmu-common.mak +1 -0
@@ -35,6 +35,7 @@ CONFIG_MIPS_CPS=y CONFIG_MIPS_ITU=y CONFIG_R4K=y CONFIG_MALTA=y +CONFIG_SEMIHOSTING=y CONFIG_PCNET_PCI=y CONFIG_MIPSSIM=y CONFIG_ACPI_SMBUS=y
default-configs/nios2-softmmu.mak +2 -0
@@ -1,5 +1,7 @@ # Default configuration for nios2-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_NIOS2_10M50=y
default-configs/xtensa-softmmu.mak +2 -0
@@ -1,5 +1,7 @@ # Default configuration for Xtensa +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_XTENSA_SIM=y
hw/Kconfig +1 -0
@@ -29,6 +29,7 @@ source pci/Kconfig source rdma/Kconfig source scsi/Kconfig source sd/Kconfig +source semihosting/Kconfig source smbios/Kconfig source ssi/Kconfig source timer/Kconfig
hw/semihosting/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ + +config SEMIHOSTING + bool
hw/semihosting/Makefile.objs +1 -1
@@ -1 +1 @@ -common-obj-$(CONFIG_SOFTMMU) += config.o +obj-$(CONFIG_SEMIHOSTING) += config.o
stubs/Makefile.objs +1 -0
@@ -39,3 +39,4 @@ stub-obj-y += xen-hvm.o stub-obj-y += pci-host-piix.o stub-obj-y += ram-block.o stub-obj-y += ramfb.o +stub-obj-$(CONFIG_SOFTMMU) += semihost.o
stubs/semihost.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 02/11] semihosting: introduce CONFIG_SEMIHOSTING
Quoted 5 lines · Alex Bennée
There isn't much point building semihosting for platforms that don't support it. Introduce a new symbol and enable it only for the softmmu targets that need it.
Signed-off-by Alex Bennée <[email protected]>
Quoted 196 lines
--- default-configs/arm-softmmu.mak | 1 + default-configs/lm32-softmmu.mak | 2 + default-configs/m68k-softmmu.mak | 2 + default-configs/mips-softmmu-common.mak | 1 + default-configs/nios2-softmmu.mak | 2 + default-configs/xtensa-softmmu.mak | 2 + hw/Kconfig | 1 + hw/semihosting/Kconfig | 3 ++ hw/semihosting/Makefile.objs | 2 +- stubs/Makefile.objs | 1 + stubs/semihost.c | 66 +++++++++++++++++++++++++ 11 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 hw/semihosting/Kconfig create mode 100644 stubs/semihost.cdefault-configs/arm-softmmu.mak +1
-0@@ -39,3 +39,4 @@ CONFIG_MICROBIT=y CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y +CONFIG_SEMIHOSTING=ydefault-configs/lm32-softmmu.mak +2
-0@@ -4,6 +4,8 @@ # #CONFIG_MILKYMIST_TMU2=n # disabling it actually causes compile-time failures +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_LM32=ydefault-configs/m68k-softmmu.mak +2
-0@@ -1,5 +1,7 @@ # Default configuration for m68k-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_AN5206=ydefault-configs/mips-softmmu-common.mak +1
-0@@ -35,6 +35,7 @@ CONFIG_MIPS_CPS=y CONFIG_MIPS_ITU=y CONFIG_R4K=y CONFIG_MALTA=y +CONFIG_SEMIHOSTING=y CONFIG_PCNET_PCI=y CONFIG_MIPSSIM=y CONFIG_ACPI_SMBUS=ydefault-configs/nios2-softmmu.mak +2
-0@@ -1,5 +1,7 @@ # Default configuration for nios2-softmmu +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_NIOS2_10M50=ydefault-configs/xtensa-softmmu.mak +2
-0@@ -1,5 +1,7 @@ # Default configuration for Xtensa +CONFIG_SEMIHOSTING=y + # Boards: # CONFIG_XTENSA_SIM=yhw/Kconfig +1
-0@@ -29,6 +29,7 @@ source pci/Kconfig source rdma/Kconfig source scsi/Kconfig source sd/Kconfig +source semihosting/Kconfig source smbios/Kconfig source ssi/Kconfig source timer/Kconfighw/semihosting/Kconfig new file +3
-0@@ -0,0 +1,3 @@ + +config SEMIHOSTING + boolhw/semihosting/Makefile.objs +1
-1@@ -1 +1 @@ -common-obj-$(CONFIG_SOFTMMU) += config.o +obj-$(CONFIG_SEMIHOSTING) += config.ostubs/Makefile.objs +1
-0@@ -39,3 +39,4 @@ stub-obj-y += xen-hvm.o stub-obj-y += pci-host-piix.o stub-obj-y += ram-block.o stub-obj-y += ramfb.o +stub-obj-$(CONFIG_SOFTMMU) += semihost.ostubs/semihost.c new file +66
-0@@ -0,0 +1,66 @@ +/* +* Semihosting Stubs for SoftMMU +* +* Copyright (c) 2019 Linaro Ltd +* +* Stubs for SoftMMU targets that don't actually do semihosting. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/option.h" +#include "qemu/error-report.h" +#include "hw/semihosting/semihost.h" + +/* Empty config */ +QemuOptsList qemu_semihosting_config_opts = { + .name ="" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_semihosting_config_opts.head), + .desc = { + {/* end of list */ } + }, +}; + +/* Queries to config status default to off */ +bool semihosting_enabled (void ) +{ +return false; +} + +SemihostingTarget semihosting_get_target (void ) +{ +return SEMIHOSTING_TARGET_AUTO ; +} + +/* +* All the rest are empty subs. We could g_assert_not_reached() but +* that adds extra weight to the final binary. Waste not want not. +*/ +void qemu_semihosting_enable (void ) +{ +} + +int qemu_semihosting_config_options (const char *optarg) +{ +return 1 ; +} + +const char *semihosting_get_arg (int i) +{ +return NULL ; +} + +int semihosting_get_argc (void ) +{ +return 0 ; +} + +const char *semihosting_get_cmdline (void ) +{ +return NULL ; +} + +void semihosting_arg_fallback (const char *file,const char *cmd) +{ +}
RFC PATCH 3/11 semihosting: implement a semihosting console
In reply to Alex BennéeThis provides two functions for handling console output that handle the common backend behaviour for semihosting.
--- gdbstub.c | 5 +++ hw/semihosting/Makefile.objs | 1 + hw/semihosting/console.c | 70 ++++++++++++++++++++++++++++++++ include/exec/gdbstub.h | 11 +++++ include/hw/semihosting/console.h | 38 +++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 hw/semihosting/console.c create mode 100644 include/hw/semihosting/console.h
gdbstub.c +5 -0
@@ -1987,6 +1987,11 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)va_end (va); } +void gdb_do_console_out (target_ulong s,int len) +{ +gdb_do_syscall (NULL ,"write,2,%x,1" , s, len); +} +static void gdb_read_byte (GDBState *s,int ch) {uint8_t reply;
hw/semihosting/Makefile.objs +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_SEMIHOSTING) += config.o +obj-$(CONFIG_SEMIHOSTING) += console.o
hw/semihosting/console.c new file +70 -0
70 lines not on this page · raw message
include/exec/gdbstub.h +11 -0
@@ -44,6 +44,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);* argument list. */ void gdb_do_syscallv (gdb_syscall_complete_cb cb,const char *fmt,va_list va); +/** +* gdb_do_console_out: +* @gs: guest address of string to send +* @len: length of string +* +* Sends a string to gdb console. Unlike the system call interface +* there is no callback and we assume the system call always +* succeeds. +*/ +void gdb_do_console_out (target_ulong s,int len); +int use_gdb_syscalls (void );void gdb_set_stop_cpu (CPUState *cpu);void gdb_exit (CPUArchState *,int );
include/hw/semihosting/console.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Semihosting Console +* +* Copyright (c) 2019 Linaro Ltd +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef _SEMIHOST_CONSOLE_H_ +#define _SEMIHOST_CONSOLE_H_ + +/** +* qemu_semihosting_console_out: +* @env: CPUArchState +* @s: host address of guest string +* @len: length of string or 0 (string is null terminated) +* +* Send a guest string to the debug console. This may be the remote +* gdb session if a softmmu guest is currently being debugged. +* +* Returns: number of bytes written. +*/ +int qemu_semihosting_console_out (CPUArchState *env,target_ulong s,int len); + +/** +* qemu_semihosting_log_out: +* @s: pointer to string +* @len: length of string +* +* Send a string to the debug output. Unlike console_out these strings +* can't be sent to a remote gdb instance as they don't exist in guest +* memory. +* +* Returns: number of bytes written +*/ +int qemu_semihosting_log_out (const char *s,int len); + +#endif /* _SEMIHOST_CONSOLE_H_ */
Signature · 1 line
2.20.1
RFC PATCH 4/11 semihosting: enable chardev backed output for console
In reply to Alex BennéeIt will be useful for a number of use-cases to be able to re-direct output to a file like we do with serial output. This does the wiring to allow us to treat then semihosting console like just another character output device.
--- hw/semihosting/config.c | 26 ++++++++++++++++++++++++++ hw/semihosting/console.c | 9 ++++++++- include/hw/semihosting/semihost.h | 7 +++++++ qemu-options.hx | 6 ++++-- stubs/semihost.c | 4 ++++ vl.c | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-)
hw/semihosting/config.c +26 -0
@@ -23,6 +23,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "hw/semihosting/semihost.h" +#include "chardev/char.h" QemuOptsList qemu_semihosting_config_opts = { .name ="semihosting-config" ,
@@ -35,6 +36,9 @@ QemuOptsList qemu_semihosting_config_opts = { }, { .name = "target", .type = QEMU_OPT_STRING, + }, { + .name = "chardev", + .type = QEMU_OPT_STRING, }, { .name = "arg", .type = QEMU_OPT_STRING,
@@ -46,12 +50,14 @@ QemuOptsList qemu_semihosting_config_opts = {typedef struct SemihostingConfig {bool enabled;SemihostingTarget target; +Chardev *chardev;const char **argv;int argc;const char *cmdline;/* concatenated argv */ }SemihostingConfig ;static SemihostingConfig semihosting; +static const char *semihost_chardev;bool semihosting_enabled (void ) {
@@ -115,6 +121,11 @@ void semihosting_arg_fallback(const char *file, const char *cmd) } } +Chardev *semihosting_get_chardev (void ) +{ +return semihosting.chardev; +} +void qemu_semihosting_enable (void ) { semihosting.enabled = true;
@@ -132,6 +143,8 @@ int qemu_semihosting_config_options(const char *optarg) semihosting.enabled =qemu_opt_get_bool (opts,"enable" , true);const char *target =qemu_opt_get (opts,"target" ); +/* setup of chardev is deferred until they are initialised */ + semihost_chardev =qemu_opt_get (opts,"chardev" );if (target !=NULL ) {if (strcmp ("native" , target) ==0 ) { semihosting.target =SEMIHOSTING_TARGET_NATIVE ;
@@ -158,3 +171,16 @@ int qemu_semihosting_config_options(const char *optarg)return 0 ; } +void qemu_semihosting_connect_chardevs (void ) +{ +/* We had to defer this until chardevs were created */ +if (semihost_chardev) { +Chardev *chr =qemu_chr_find (semihost_chardev); +if (chr ==NULL ) { +error_report ("semihosting chardev '%s' not found" , + semihost_chardev); +exit (1 ); + } + semihosting.chardev = chr; + } +}
hw/semihosting/console.c +8 -1
@@ -17,13 +17,20 @@#include "qemu/osdep.h" #include "cpu.h" +#include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" #include "exec/gdbstub.h" #include "qemu/log.h" +#include "chardev/char.h" int qemu_semihosting_log_out (const char *s,int len) { -return write (STDERR_FILENO , s, len); +Chardev *chardev =semihosting_get_chardev (); +if (chardev) { +return qemu_chr_write_all (chardev, (uint8_t *) s, len); + }else { +return write (STDERR_FILENO , s, len); + } }/*
include/hw/semihosting/semihost.h +7 -0
@@ -51,6 +51,11 @@ static inline const char *semihosting_get_cmdline(void) {return NULL ; } + +static inline Chardev *semihosting_get_chardev (void ) +{ +return NULL ; +}#else /* !CONFIG_USER_ONLY */ bool semihosting_enabled (void );SemihostingTarget semihosting_get_target (void );
@@ -58,9 +63,11 @@ const char *semihosting_get_arg(int i);int semihosting_get_argc (void );const char *semihosting_get_cmdline (void );void semihosting_arg_fallback (const char *file,const char *cmd); +Chardev *semihosting_get_chardev (void );/* for vl.c hooks */ void qemu_semihosting_enable (void );int qemu_semihosting_config_options (const char *opt); +void qemu_semihosting_connect_chardevs (void );#endif /* CONFIG_USER_ONLY */ #endif /* SEMIHOST_H */
qemu-options.hx +4 -2
@@ -3975,12 +3975,12 @@ STEXI Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II only). ETEXI DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, - "-semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]]\n" \ + "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) STEXI -@item -semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]] +@item -semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]] @findex -semihosting-config Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II only). @table @option
@@ -3988,6 +3988,8 @@ Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II only). Defines 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. +@item chardev=@var{str1} +Send the output to a chardev backend output for native or auto output when not in gdb @item arg=@var{str1},arg=@var{str2},... Allows the user to pass input arguments, and can be used multiple times to build up a list. The old-style @code{-kernel}/@code{-append} method of passing a
stubs/semihost.c +4 -0
@@ -64,3 +64,7 @@ const char *semihosting_get_cmdline(void)void semihosting_arg_fallback (const char *file,const char *cmd) { } + +void qemu_semihosting_connect_chardevs (void ) +{ +}
vl.c +2 -0
@@ -4156,6 +4156,8 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL , &error_fatal); +/* now chardevs have been created we may have semihosting to connect */ +qemu_semihosting_connect_chardevs ();#ifdef CONFIG_VIRTFS qemu_opts_foreach(qemu_find_opts("fsdev"),
Signature · 1 line
2.20.1
RFC PATCH 5/11 target/arm: fixup some of the commentary for arm-semi
In reply to Alex BennéeThis cleans up a number of the block comments to fit the proper style. While we are at it we also reference the official specification and document what the return register value can be.
--- target/arm/arm-semi.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
target/arm/arm-semi.c +31 -9
@@ -2,6 +2,7 @@* Arm "Angel" semihosting syscalls * * Copyright (c) 2005, 2007 CodeSourcery. +* Copyright (c) 2019 Linaro * Written by Paul Brook. * * This program is free software; you can redistribute it and/or modify
@@ -16,6 +17,10 @@* * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. +* +* ARM Semihosting is documented in: +* Semihosting for AArch32 and AArch64 Release 2.0 +* https://static.docs.arm.com/100863/0200/semihosting.pdf */ #include "qemu/osdep.h"
@@ -240,6 +245,15 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, put_user_u64(val, args + (n) * 8) : \ put_user_u32(val, args + (n) * 4)) +/* +* Do a semihosting call. +* +* The specification always says that the "return register" either +* returns a specific value or is corrupted, so we don't need to +* report to our caller whether we are returning a value or trying to +* leave the register unchanged. We use 0xdeadbeef as the return value +* when there isn't a defined return value for the call. +*/ target_ulong do_arm_semihosting (CPUARMState *env) {ARMCPU *cpu =arm_env_get_cpu (env);
@@ -510,14 +524,16 @@ target_ulong do_arm_semihosting(CPUARMState *env) output_size = ts->info->arg_end - ts->info->arg_start;if (!output_size) { -/* We special-case the "empty command line" case (argc==0). -Just provide the terminating 0. */ +/* +* We special-case the "empty command line" case (argc==0). +* Just provide the terminating 0. +*/ output_size =1 ; }#endif if (output_size > input_size) { -/* Not enough space to store command-line arguments. */ +/* Not enough space to store command-line arguments. */ return -1 ; }
@@ -571,8 +587,10 @@ target_ulong do_arm_semihosting(CPUARMState *env)GET_ARG (0 );#ifdef CONFIG_USER_ONLY -/* Some C libraries assume the heap immediately follows .bss, so -allocate it using sbrk. */ +/* +* Some C libraries assume the heap immediately follows .bss, so +* allocate it using sbrk. +*/ if (!ts->heap_limit) {abi_ulong ret;
@@ -620,7 +638,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) }case TARGET_SYS_EXIT :if (is_a64 (env)) { -/* The A64 version of this call takes a parameter block, +/* +* The A64 version of this call takes a parameter block, * so the application-exit type can return a subcode which * is the exit status code from the application. */
@@ -633,14 +652,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) ret =1 ; } }else { -/* ARM specifies only Stopped_ApplicationExit as normal -* exit, everything else is considered an error */ +/* +* ARM specifies only Stopped_ApplicationExit as normal +* exit, everything else is considered an error +*/ ret = (args == ADP_Stopped_ApplicationExit) ?0 :1 ; }gdb_exit (env, ret);exit (ret);case TARGET_SYS_SYNCCACHE : -/* Clean the D-cache and invalidate the I-cache for the specified +/* +* Clean the D-cache and invalidate the I-cache for the specified * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 05/11] target/arm: fixup some of the commentary for arm-semi
Quoted 5 lines · Alex Bennée
This cleans up a number of the block comments to fit the proper style. While we are at it we also reference the official specification and document what the return register value can be.
Signed-off-by Alex Bennée <[email protected]>
Quoted 108 lines
--- target/arm/arm-semi.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)target/arm/arm-semi.c +31
-9@@ -2,6 +2,7 @@* Arm "Angel" semihosting syscalls * * Copyright (c) 2005, 2007 CodeSourcery. +* Copyright (c) 2019 Linaro * Written by Paul Brook. * * This program is free software; you can redistribute it and/or modify @@ -16,6 +17,10 @@* * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. +* +* ARM Semihosting is documented in: +* Semihosting for AArch32 and AArch64 Release 2.0 +* https://static.docs.arm.com/100863/0200/semihosting.pdf */ #include "qemu/osdep.h" @@ -240,6 +245,15 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, put_user_u64(val, args + (n) * 8) : \ put_user_u32(val, args + (n) * 4)) +/* +* Do a semihosting call. +* +* The specification always says that the "return register" either +* returns a specific value or is corrupted, so we don't need to +* report to our caller whether we are returning a value or trying to +* leave the register unchanged. We use 0xdeadbeef as the return value +* when there isn't a defined return value for the call. +*/ target_ulong do_arm_semihosting (CPUARMState *env) {ARMCPU *cpu =arm_env_get_cpu (env);@@ -510,14 +524,16 @@ target_ulong do_arm_semihosting(CPUARMState *env) output_size = ts->info->arg_end - ts->info->arg_start;if (!output_size) { -/* We special-case the "empty command line" case (argc==0). -Just provide the terminating 0. */ +/* +* We special-case the "empty command line" case (argc==0). +* Just provide the terminating 0. +*/ output_size =1 ; }#endif if (output_size > input_size) { -/* Not enough space to store command-line arguments. */ +/* Not enough space to store command-line arguments. */ return -1 ; }@@ -571,8 +587,10 @@ target_ulong do_arm_semihosting(CPUARMState *env)GET_ARG (0 );#ifdef CONFIG_USER_ONLY -/* Some C libraries assume the heap immediately follows .bss, so -allocate it using sbrk. */ +/* +* Some C libraries assume the heap immediately follows .bss, so +* allocate it using sbrk. +*/ if (!ts->heap_limit) {abi_ulong ret;@@ -620,7 +638,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) }case TARGET_SYS_EXIT :if (is_a64 (env)) { -/* The A64 version of this call takes a parameter block, +/* +* The A64 version of this call takes a parameter block, * so the application-exit type can return a subcode which * is the exit status code from the application. */ @@ -633,14 +652,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) ret =1 ; } }else { -/* ARM specifies only Stopped_ApplicationExit as normal -* exit, everything else is considered an error */ +/* +* ARM specifies only Stopped_ApplicationExit as normal +* exit, everything else is considered an error +*/ ret = (args == ADP_Stopped_ApplicationExit) ?0 :1 ; }gdb_exit (env, ret);exit (ret);case TARGET_SYS_SYNCCACHE : -/* Clean the D-cache and invalidate the I-cache for the specified +/* +* Clean the D-cache and invalidate the I-cache for the specified * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */
RFC PATCH 6/11 target/arm: use the common interface for WRITE0/WRITEC in arm-semi
In reply to Alex BennéeNow we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.c
linux-user/Makefile.objs +2 -0
@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.o
linux-user/arm/semihost.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out (CPUArchState *env,target_ulong addr,int len) +{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}
target/arm/arm-semi.c +6 -25
@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h"
@@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 );
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Quoted 109 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +24
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out (CPUArchState *env,target_ulong addr,int len) +{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 );Signature · 1 line
2.20.1
Hi Alex,
this patch breaks build for softmmu target when CONFIG_SEMIHOSTING is not enabled as qemu_semihosting_console_out is not defined in such case - neither linux-user/arm/semihost.c nor hw/semihosting/console.c compiled and function is not in stubs/semihost.c
Mirek
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Hi Miroslav,
Quoted 113 lines · Miroslav Rezanina
Quoted 109 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +24
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out (CPUArchState *env,target_ulong addr,int len) +{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 );Signature · 1 line
2.20.1Hi Alex,
Quoted 3 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_outis not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function is not instubs/semihost.c
Kinda funny, I noticed the same issue at the same time, and was chatting with Alex about it.
I prepared a patch expliciting we can not disable CONFIG_SEMIHOSTING on the MIPS arch. Would that work for you?
Regards,
Phil.
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Quoted 120 lines · Philippe Mathieu-Daudé
Hi Miroslav,
Quoted 116 lines · Miroslav Rezanina
Quoted 106 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +24
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out (CPUArchState *env,target_ulong addr,int len) +{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-26@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 ); --Quoted 3 lines
2.20.1
Hi Alex,
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_outis not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function is not instubs/semihost.c
linux-user/arm/semihost.c is not built on softmmu-only build.
Quoted 9 lines
Kinda funny, I noticed the same issue at the same time, and was chatting with Alex about it.
I prepared a patch expliciting we can not disable
CONFIG_SEMIHOSTINGon the MIPS arch. Would that work for you?Regards,
Phil.
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
In reply to Philippe Mathieu-Daudé----- Original Message -----
Quoted 134 lines
From: "Philippe Mathieu-Daudé" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>, "Alex Bennée" <[email protected]>
Cc: "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], [email protected], "Laurent Vivier" <[email protected]>, "Aleksandar Markovic" <[email protected]>
Sent: Friday, May 31, 2019 12:42:46 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiHi Miroslav,
Quoted 115 lines · Miroslav Rezanina
Quoted 107 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +18
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr,int len)
linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG(1);Quoted 4 lines
--
2.20.1Hi Alex,
Quoted 5 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.cKinda funny, I noticed the same issue at the same time, and was chatting with Alex about it.
Quoted 7 lines
I prepared a patch expliciting we can not disable
CONFIG_SEMIHOSTINGon the MIPS arch. Would that work for you?Regards,
Phil.
Hi Phil,
we've got problem with build for AArch64 where SEMIHOSTING cannot be disabled too:
target/arm/helper.c use do_arm_semihosting
Mirek
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team Maintainer
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
In reply to Miroslav RezaninaQuoted 113 lines · Miroslav Rezanina
Quoted 106 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +24
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out (CPUArchState *env,target_ulong addr,int len) +{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-26@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 ); --Quoted 3 lines
2.20.1
Hi Alex,
Quoted 3 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_outis not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function is not instubs/semihost.c
How do you do that? I tried ../../configure --without-default-devices and that still builds for me.
But I suspect what's needed is to change:
#ifndef CONFIG_USER_ONLY
to
#ifdef CONFIG_SEMIHOSTING
to the relevant headers and helper bits.
Quoted 2 lines
Mirek
--
Alex Bennée
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
----- Original Message -----
Quoted 125 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 1:08:06 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 115 lines · Miroslav Rezanina
Quoted 107 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +18
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr,int len)
linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG(1);Quoted 4 lines
--
2.20.1Hi Alex,
Quoted 8 lines
Quoted 5 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.cHow do you do that? I tried ../../configure --without-default-devices and that still builds for me.
It's usual RHEL way - use --without-default-devices and use specific list of enabled devices (this mean disable CONFIG_SEMIHOSTING in default_config/* file).
Quoted 10 lines
But I suspect what's needed is to change:
#ifndef
CONFIG_USER_ONLYto
#ifdef
CONFIG_SEMIHOSTINGto the relevant headers and helper bits.
Yeah, have to find out what are relevant pieces.
Mirek
Quoted 8 lines
Quoted 3 lines
Mirek
--
Alex Bennée
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team Maintainer
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Quoted 132 lines · Miroslav Rezanina
----- Original Message -----
Quoted 131 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 1:08:06 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 120 lines · Miroslav Rezanina
Quoted 107 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +18
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr,int len)
linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG(1);Quoted 4 lines
--
2.20.1Hi Alex,
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.c
Quoted 6 lines
Quoted 2 lines
How do you do that? I tried ../../configure --without-default-devices and that still builds for me.
It's usual RHEL way - use --without-default-devices and use specific list of enabled devices (this mean disable
CONFIG_SEMIHOSTINGin default_config/* file).
OK - so from the upstream source tree CONFIG_SEMIHOSTING is still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of the default_config file to include SEMIHOSTING?
Is this an out-of-tree RHEL addition?
Quoted 7 lines
Quoted 7 lines
But I suspect what's needed is to change:
#ifndef
CONFIG_USER_ONLYto
Quoted 16 lines
Quoted 3 lines
#ifdef
CONFIG_SEMIHOSTINGto the relevant headers and helper bits.
Yeah, have to find out what are relevant pieces.
Mirek
Quoted 8 lines
Quoted 3 lines
Mirek
--
Alex Bennée
--
Alex Bennée
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
----- Original Message -----
Quoted 149 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 3:16:38 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 139 lines · Miroslav Rezanina
----- Original Message -----
Quoted 137 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>,
[email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 1:08:06 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 116 lines · Miroslav Rezanina
Quoted 108 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +18
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr,int len)
linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG(0); GET_ARG(1);Quoted 4 lines
--
2.20.1Hi Alex,
Quoted 6 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not
enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.cHow do you do that? I tried ../../configure --without-default-devices and that still builds for me.
Quoted 8 lines
Quoted 3 lines
It's usual RHEL way - use --without-default-devices and use specific list of enabled devices (this mean disable
CONFIG_SEMIHOSTINGin default_config/* file).OK - so from the upstream source tree
CONFIG_SEMIHOSTINGis still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of thedefault_configfile to include SEMIHOSTING?
It's fix but it goes against our policy of handling CONFIG options so we would prefer to have this fixed - otherwise there's no meaning in having config option if you can't disable it.
Quoted 2 lines
Is this an out-of-tree RHEL addition?
No, it's RHEL device config handling.
Mirek
Quoted 28 lines
Quoted 7 lines
Quoted 7 lines
But I suspect what's needed is to change:
#ifndef
CONFIG_USER_ONLYto
Quoted 16 lines
Quoted 3 lines
#ifdef
CONFIG_SEMIHOSTINGto the relevant headers and helper bits.
Yeah, have to find out what are relevant pieces.
Mirek
Quoted 8 lines
Quoted 3 lines
Mirek
--
Alex Bennée--
Alex Bennée
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team Maintainer
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Quoted 154 lines · Miroslav Rezanina
----- Original Message -----
Quoted 153 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 3:16:38 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 142 lines · Miroslav Rezanina
----- Original Message -----
Quoted 135 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>,
[email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 1:08:06 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 116 lines · Miroslav Rezanina
Quoted 108 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +18
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support +* in linux-user. So for now we implement the common console API but +* just for arm linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulong addr,int len)
linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +6
-25@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState *env)return set_swi_errno (ts,close (arg0)); }case TARGET_SYS_WRITEC : - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,%x" , - args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG(0); GET_ARG(1);Quoted 4 lines
--
2.20.1Hi Alex,
Quoted 6 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not
enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.cQuoted 2 lines
How do you do that? I tried ../../configure --without-default-devices and that still builds for me.
It's usual RHEL way - use --without-default-devices and use specific list of enabled devices (this mean disable
CONFIG_SEMIHOSTINGin default_config/* file).
Quoted 8 lines
Quoted 4 lines
OK - so from the upstream source tree
CONFIG_SEMIHOSTINGis still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of thedefault_configfile to include SEMIHOSTING?It's fix but it goes against our policy of handling CONFIG options so we would prefer to have this fixed - otherwise there's no meaning in having config option if you can't disable it.
Is that what it means? For my part it means we don't build in CONFIG_SEMIHOSTING for the arches that don't need it (which we were before). Granted it only really simplified the vl.c parsing and dropped support for semihosting for the linux-user targets (except ARM).
Quoted 5 lines
Quoted 3 lines
Is this an out-of-tree RHEL addition?
No, it's RHEL device config handling.
I mean how do I replicate this failure on the upstream source tree?
Quoted 31 lines
Mirek
Quoted 28 lines
Quoted 7 lines
Quoted 7 lines
But I suspect what's needed is to change:
#ifndef
CONFIG_USER_ONLYto
Quoted 16 lines
Quoted 3 lines
#ifdef
CONFIG_SEMIHOSTINGto the relevant headers and helper bits.
Yeah, have to find out what are relevant pieces.
Mirek
Quoted 8 lines
Quoted 3 lines
Mirek
--
Alex Bennée--
Alex Bennée
--
Alex Bennée
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
Quoted 7 lines · Alex Bennée
Quoted 6 lines · Miroslav Rezanina
From: "Alex Bennée" <[email protected]>
Quoted 4 lines
OK - so from the upstream source tree
CONFIG_SEMIHOSTINGis still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of thedefault_configfile to include SEMIHOSTING?
Quoted 8 lines
Quoted 3 lines
It's fix but it goes against our policy of handling CONFIG options so we would prefer to have this fixed - otherwise there's no meaning in having config option if you can't disable it.
Is that what it means? For my part it means we don't build in
CONFIG_SEMIHOSTINGfor the arches that don't need it (which we were before). Granted it only really simplified thevl.cparsing and dropped support for semihosting for the linux-user targets (except ARM).
Yes, that would be my interpretation of it. If we had
a 'config FOO' stanza for CPUs, then Arm CPUs would "select SEMIHOSTING". If RedHat would like it to be possible to build Arm CPUs without CONFIG_SEMIHOSTING then they're free to submit patches for that, but that's a new feature upstream doesn't currently support, not a bug in upstream. (Also I'd be a bit dubious because it means that previously working guest setups that use semihosting will break.)
PS: if we had a 'config FOO' stanza for CPUs that would also allow us to say "building Arm CPUs requires the NVIC" and similarly for things which in QEMU are devices but which are architecturally tightly-coupled non-optional parts of the CPU.
thanks
-- PMM
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
----- Original Message -----
Quoted 24 lines
From: "Peter Maydell" <[email protected]>
To: "Alex Bennée" <[email protected]>
Cc: "Miroslav Rezanina" <[email protected]>, "QEMU Developers" <[email protected]>, "Riku Voipio" <[email protected]>, "qemu-arm" <[email protected]>, "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 4:38:04 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 7 lines · Alex Bennée
Quoted 6 lines · Miroslav Rezanina
From: "Alex Bennée" <[email protected]>
Quoted 4 lines
OK - so from the upstream source tree
CONFIG_SEMIHOSTINGis still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of thedefault_configfile to include SEMIHOSTING?Quoted 8 lines
Quoted 3 lines
It's fix but it goes against our policy of handling CONFIG options so we would prefer to have this fixed - otherwise there's no meaning in having config option if you can't disable it.
Is that what it means? For my part it means we don't build in
CONFIG_SEMIHOSTINGfor the arches that don't need it (which we were before). Granted it only really simplified thevl.cparsing and dropped support for semihosting for the linux-user targets (except ARM).
Quoted 8 lines
Yes, that would be my interpretation of it. If we had
a 'config FOO' stanza for CPUs, then Arm CPUs would "select SEMIHOSTING". If RedHat would like it to be possible to build Arm CPUs withoutCONFIG_SEMIHOSTINGthen they're free to submit patches for that, but that's a new feature upstream doesn't currently support, not a bug in upstream. (Also I'd be a bit dubious because it means that previously working guest setups that use semihosting will break.)
I partially agree here - I see difference between disabling config and omitting it. We are not not disabling CONFIG_SEMIHOSTING, we just ignore it. So we got error because it is not properly handled. Proper handling should be either auto-include it as dependency or successful build with option disabled.
As there's currently no way to auto-include it through dependency, it would be good to have comment in default_config file next to it stating that it's required option. This will allow us to see it and add to our default_config we used instead upstream one.
Mirek
Quoted 9 lines
PS: if we had a 'config FOO' stanza for CPUs that would also allow us to say "building Arm CPUs requires the NVIC" and similarly for things which in QEMU are devices but which are architecturally tightly-coupled non-optional parts of the CPU.
thanks
-- PMM
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team Maintainer
Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semi
In reply to Alex Bennée----- Original Message -----
Quoted 188 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>, [email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 4:28:02 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 163 lines · Miroslav Rezanina
----- Original Message -----
Quoted 162 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>,
[email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 3:16:38 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 149 lines · Miroslav Rezanina
----- Original Message -----
Quoted 142 lines
From: "Alex Bennée" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: [email protected], "Peter Maydell" <[email protected]>, "Riku Voipio" <[email protected]>,
[email protected], "Laurent Vivier" <[email protected]>
Sent: Friday, May 31, 2019 1:08:06 PM
Subject: Re: [Qemu-devel] [RFC PATCH 06/11] target/arm: use the common interface for WRITE0/WRITEC in arm-semiQuoted 123 lines · Miroslav Rezanina
Quoted 116 lines · Alex Bennée
Now we have a common semihosting console interface use that for our string output. However ARM is currently unique in also supporting semihosting for linux-user so we need to replicate the API in linux-user. If other architectures gain this support we can move the file later.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/Makefile.objs | 2 ++ linux-user/arm/semihost.c | 24 ++++++++++++++++++++++++ target/arm/arm-semi.c | 31 ++++++------------------------- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 linux-user/arm/semihost.clinux-user/Makefile.objs +2
-0@@ -6,4 +6,6 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o obj-$(TARGET_ARM) += arm/nwfpe/ +obj-$(TARGET_ARM) += arm/semihost.o +obj-$(TARGET_AARCH64) += arm/semihost.o obj-$(TARGET_M68K) += m68k-sim.olinux-user/arm/semihost.c new file +6
-0@@ -0,0 +1,24 @@ +/* +* ARM Semihosting Console Support +* +* Copyright (c) 2019 Linaro Ltd +* +* Currently ARM is unique in having support for semihosting support
+ * in linux-user. So for now we implement the common console API but
+ * just for arm linux-user.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */linux-user/arm/semihost.c new file +7
-0+ +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/semihosting/console.h" +#include "qemu.h" + +int qemu_semihosting_console_out(CPUArchState *env, target_ulongaddr,
int len)linux-user/arm/semihost.c new file +6
-0+{ +void *s =lock_user_string (addr); + len =write (STDERR_FILENO , s, len ? len :strlen (s)); +unlock_user (s, addr,0 ); +return len; +}target/arm/arm-semi.c +5
-15@@ -27,6 +27,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -314,32 +315,12 @@ target_ulong do_arm_semihosting(CPUARMState*env) return set_swi_errno(ts, close(arg0)); } case TARGET_SYS_WRITEC: - { -char c; - -if (get_user_u8 (c, args)) -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; -/* Write to debug console. stderr is near enough. */ -if (use_gdb_syscalls ()) { -return arm_gdb_syscall (cpu, arm_semi_cb,"write,2,%x,1" , args); - }else { -return write (STDERR_FILENO , &c,1 ); - } - } + { +qemu_semihosting_console_out (env, args,1 ); +return 0xdeadbeef ; + }case TARGET_SYS_WRITE0 : -if (!(s =lock_user_string (args))) -/* FIXME - should this error code be -TARGET_EFAULT ? */
target/arm/arm-semi.c +0
-4-return (uint32_t )-1 ; - len =strlen (s); -if (use_gdb_syscalls ()) { - return arm_gdb_syscall(cpu, arm_semi_cb,"write,2,%x,%x",
target/arm/arm-semi.c +1
-7- args, len); - }else { - ret =write (STDERR_FILENO , s, len); - } -unlock_user (s, args,0 ); -return ret; +return qemu_semihosting_console_out (env, args,0 );case TARGET_SYS_WRITE :GET_ARG (0 );GET_ARG (1 ); --Quoted 3 lines
2.20.1
Hi Alex,
Quoted 6 lines
this patch breaks build for softmmu target when
CONFIG_SEMIHOSTINGis not
enabled asqemu_semihosting_console_out
is not defined in such case - neitherlinux-user/arm/semihost.cnorhw/semihosting/console.ccompiled and function
is not instubs/semihost.cQuoted 2 lines
How do you do that? I tried ../../configure --without-default-devices and that still builds for me.
It's usual RHEL way - use --without-default-devices and use specific list of enabled devices (this mean disable
CONFIG_SEMIHOSTINGin default_config/* file).Quoted 8 lines
Quoted 4 lines
OK - so from the upstream source tree
CONFIG_SEMIHOSTINGis still =y (but I can see most of them are now =n). Isn't the simplest solution to fix-up your version of thedefault_configfile to include SEMIHOSTING?It's fix but it goes against our policy of handling CONFIG options so we would prefer to have this fixed - otherwise there's no meaning in having config option if you can't disable it.
Is that what it means? For my part it means we don't build in
CONFIG_SEMIHOSTINGfor the arches that don't need it (which we were before). Granted it only really simplified thevl.cparsing and dropped support for semihosting for the linux-user targets (except ARM).Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Is this an out-of-tree RHEL addition?
No, it's RHEL device config handling.
I mean how do I replicate this failure on the upstream source tree?
Easiest way should be probably commenting out the CONFIG_SEMIHOSTING=y line in default_config/arm-softmmu.mak. It is not auto-include so the build will be run without it and fail.
Mirek
Quoted 37 lines
Quoted 32 lines
Mirek
Quoted 28 lines
Quoted 7 lines
Quoted 7 lines
But I suspect what's needed is to change:
#ifndef
CONFIG_USER_ONLYto
Quoted 16 lines
Quoted 3 lines
#ifdef
CONFIG_SEMIHOSTINGto the relevant headers and helper bits.
Yeah, have to find out what are relevant pieces.
Mirek
Quoted 8 lines
Quoted 3 lines
Mirek
--
Alex Bennée--
Alex Bennée--
Alex Bennée
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team Maintainer
RFC PATCH 7/11 target/arm: add LOG_UNIMP messages to arm-semi
In reply to Alex BennéeClean-up our unimplemented bits with a proper message.
--- target/arm/arm-semi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/arm/arm-semi.c +3 -2
@@ -28,6 +28,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" +#include "qemu/log.h" #ifdef CONFIG_USER_ONLY #include "qemu.h"
@@ -366,7 +367,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)return len - ret; }case TARGET_SYS_READC : -/* XXX: Read from debug console. Not implemented. */ +qemu_log_mask (LOG_UNIMP ,"%s: SYS_READC not implemented" , __func__);return 0 ;case TARGET_SYS_ISTTY :GET_ARG (0 );
@@ -400,7 +401,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)return buf.st_size; }case TARGET_SYS_TMPNAM : -/* XXX: Not implemented. */ +qemu_log_mask (LOG_UNIMP ,"%s: SYS_TMPNAM not implemented" , __func__);return -1 ;case TARGET_SYS_REMOVE :GET_ARG (0 );
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 07/11] target/arm: add LOG_UNIMP messages to arm-semi
Quoted 3 lines · Alex Bennée
Clean-up our unimplemented bits with a proper message.
Signed-off-by Alex Bennée <[email protected]>
Quoted 35 lines
--- target/arm/arm-semi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/arm/arm-semi.c +3
-2@@ -28,6 +28,7 @@#include "cpu.h" #include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" +#include "qemu/log.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -366,7 +367,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)return len - ret; }case TARGET_SYS_READC : -/* XXX: Read from debug console. Not implemented. */ +qemu_log_mask (LOG_UNIMP ,"%s: SYS_READC not implemented" , __func__);return 0 ;case TARGET_SYS_ISTTY :GET_ARG (0 );@@ -400,7 +401,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)return buf.st_size; }case TARGET_SYS_TMPNAM : -/* XXX: Not implemented. */ +qemu_log_mask (LOG_UNIMP ,"%s: SYS_TMPNAM not implemented" , __func__);return -1 ;case TARGET_SYS_REMOVE :GET_ARG (0 );
RFC PATCH 8/11 target/arm: correct return values for WRITE/READ in arm-semi
In reply to Alex BennéeThe documentation says the write should return the number of bytes not written on an error (0 means everything was written). Read provides a buffer length and the return value should be the buffer length - bytes actually read. Remove the incorrect FIXME's and return the correct values.
--- target/arm/arm-semi.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
target/arm/arm-semi.c +12 -8
@@ -334,13 +334,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) }else { s =lock_user (VERIFY_READ , arg1, len,1 );if (!s) { -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; +/* Return bytes not written on error */ +return len; } ret =set_swi_errno (ts,write (arg0, s, len));unlock_user (s, arg1,0 ); -if (ret == (uint32_t )-1 ) -return -1 ; +if (ret == (uint32_t )-1 ) { + ret =0 ; + } +/* Return bytes not written */ return len - ret; }case TARGET_SYS_READ :
@@ -355,15 +357,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) }else { s =lock_user (VERIFY_WRITE , arg1, len,0 );if (!s) { -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; +/* return bytes not read */ +return len; }do { ret =set_swi_errno (ts,read (arg0, s, len)); }while (ret ==-1 && errno ==EINTR );unlock_user (s, arg1, len); -if (ret == (uint32_t )-1 ) -return -1 ; +if (ret == (uint32_t )-1 ) { + ret =0 ; + } +/* Return bytes not read */ return len - ret; }case TARGET_SYS_READC :
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 08/11] target/arm: correct return values for WRITE/READ in arm-semi
Quoted 7 lines · Alex Bennée
The documentation says the write should return the number of bytes not written on an error (0 means everything was written). Read provides a buffer length and the return value should be the buffer length - bytes actually read. Remove the incorrect FIXME's and return the correct values.
Signed-off-by Alex Bennée <[email protected]>
Quoted 51 lines
--- target/arm/arm-semi.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)target/arm/arm-semi.c +12
-8@@ -334,13 +334,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) }else { s =lock_user (VERIFY_READ , arg1, len,1 );if (!s) { -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; +/* Return bytes not written on error */ +return len; } ret =set_swi_errno (ts,write (arg0, s, len));unlock_user (s, arg1,0 ); -if (ret == (uint32_t )-1 ) -return -1 ; +if (ret == (uint32_t )-1 ) { + ret =0 ; + } +/* Return bytes not written */ return len - ret; }case TARGET_SYS_READ :@@ -355,15 +357,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) }else { s =lock_user (VERIFY_WRITE , arg1, len,0 );if (!s) { -/* FIXME - should this error code be -TARGET_EFAULT ? */ -return (uint32_t )-1 ; +/* return bytes not read */ +return len; }do { ret =set_swi_errno (ts,read (arg0, s, len)); }while (ret ==-1 && errno ==EINTR );unlock_user (s, arg1, len); -if (ret == (uint32_t )-1 ) -return -1 ; +if (ret == (uint32_t )-1 ) { + ret =0 ; + } +/* Return bytes not read */ return len - ret; }case TARGET_SYS_READC :
RFC PATCH 9/11 target/mips: only build mips-semi for softmmu
In reply to Alex BennéeThe is_uhi gates all semihosting calls and always returns false for CONFIG_USER_ONLY builds. There is no reason to build and link mips-semi for these builds so lets fix that.
--- target/mips/Makefile.objs | 3 ++- target/mips/helper.h | 2 ++ target/mips/translate.c | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
target/mips/Makefile.objs +2 -1
@@ -1,4 +1,5 @@ obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o -obj-y += gdbstub.o msa_helper.o mips-semi.o +obj-y += gdbstub.o msa_helper.o +obj-$(CONFIG_SOFTMMU) += mips-semi.o obj-$(CONFIG_SOFTMMU) += machine.o cp0_timer.o obj-$(CONFIG_KVM) += kvm.o
target/mips/helper.h +2 -0
@@ -2,7 +2,9 @@ DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(raise_exception_debug, noreturn, env) +#ifndef CONFIG_USER_ONLY DEF_HELPER_1(do_semihosting, void, env) +#endif #ifdef TARGET_MIPS64 DEF_HELPER_4 (sdl, void, env, tl, tl, int)
target/mips/translate.c +8 -0
@@ -13726,6 +13726,14 @@ static inline bool is_uhi(int sdbbp_code)#endif } +#ifdef CONFIG_USER_ONLY +/* The above should dead-code away any calls to this..*/ +static inline void gen_helper_do_semihosting (void *env) +{ +g_assert_not_reached (); +} +#endif +static int decode_mips16_opc (CPUMIPSState *env,DisasContext *ctx) {int rx, ry;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 09/11] target/mips: only build mips-semi for softmmu
Quoted 5 lines · Alex Bennée
The
is_uhigates all semihosting calls and always returns false forCONFIG_USER_ONLYbuilds. There is no reason to build and link mips-semi for these builds so lets fix that.Signed-off-by Alex Bennée <[email protected]>
Quoted 51 lines
--- target/mips/Makefile.objs | 3 ++- target/mips/helper.h | 2 ++ target/mips/translate.c | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)target/mips/Makefile.objs +2
-1@@ -1,4 +1,5 @@ obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o -obj-y += gdbstub.o msa_helper.o mips-semi.o +obj-y += gdbstub.o msa_helper.o +obj-$(CONFIG_SOFTMMU) += mips-semi.o obj-$(CONFIG_SOFTMMU) += machine.o cp0_timer.o obj-$(CONFIG_KVM) += kvm.otarget/mips/helper.h +2
-0@@ -2,7 +2,9 @@ DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(raise_exception_debug, noreturn, env) +#ifndef CONFIG_USER_ONLY DEF_HELPER_1(do_semihosting, void, env) +#endif #ifdef TARGET_MIPS64 DEF_HELPER_4 (sdl, void, env, tl, tl, int)target/mips/translate.c +8
-0@@ -13726,6 +13726,14 @@ static inline bool is_uhi(int sdbbp_code)#endif } +#ifdef CONFIG_USER_ONLY +/* The above should dead-code away any calls to this..*/ +static inline void gen_helper_do_semihosting (void *env) +{ +g_assert_not_reached (); +} +#endif +static int decode_mips16_opc (CPUMIPSState *env,DisasContext *ctx) {int rx, ry;
Re: [Qemu-devel] [RFC PATCH 09/11] target/mips: only build mips-semi for softmmu
In reply to Alex BennéeQuoted 7 lines · Alex Bennée
The
is_uhigates all semihosting calls and always returns false forCONFIG_USER_ONLYbuilds. There is no reason to build and link mips-semi for these builds so lets fix that.Signed-off-by Alex Bennée <[email protected]>---
Quoted 53 lines
target/mips/Makefile.objs | 3 ++- target/mips/helper.h | 2 ++ target/mips/translate.c | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-)target/mips/Makefile.objs +2
-1@@ -1,4 +1,5 @@ obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o -obj-y += gdbstub.o msa_helper.o mips-semi.o +obj-y += gdbstub.o msa_helper.o +obj-$(CONFIG_SOFTMMU) += mips-semi.o obj-$(CONFIG_SOFTMMU) += machine.o cp0_timer.o obj-$(CONFIG_KVM) += kvm.otarget/mips/helper.h +2
-0@@ -2,7 +2,9 @@ DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(raise_exception_debug, noreturn, env) +#ifndef CONFIG_USER_ONLY DEF_HELPER_1(do_semihosting, void, env) +#endif #ifdef TARGET_MIPS64 DEF_HELPER_4 (sdl, void, env, tl, tl, int)target/mips/translate.c +8
-1@@ -13726,6 +13726,14 @@ static inline bool is_uhi(int sdbbp_code)#endif } +#ifdef CONFIG_USER_ONLY +/* The above should dead-code away any calls to this..*/ +static inline void gen_helper_do_semihosting (void *env) +{ +g_assert_not_reached (); +} +#endif +static int decode_mips16_opc (CPUMIPSState *env,DisasContext *ctx) {int rx, ry; --2.20.1
RFC PATCH 10/11 target/mips: convert UHI_plog to use common semihosting code
In reply to Alex BennéeRather than printing directly to stdout lets use our common semihosting code. There is one minor difference in that the output currently defaults to stderr instead of stdout however this can be controlled by connecting semihosting to a chardev.
--- target/mips/mips-semi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target/mips/mips-semi.c +6 -6
@@ -23,6 +23,7 @@#include "exec/helper-proto.h" #include "exec/softmmu-semi.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" typedef enum UHIOp { UHI_exit = 1,
@@ -329,13 +330,12 @@ void helper_do_semihosting(CPUMIPSState *env) p2 =strstr (p,"%d" );if (p2) {int char_num = p2 - p; -char *buf =g_malloc (char_num +1 ); -strncpy (buf, p, char_num); - buf[char_num] ='\0' ; - gpr[2 ] =printf ("%s%d%s" , buf, (int )gpr[5 ], p2 +2 ); -g_free (buf); +GString *s =g_string_new_len (p, char_num); +g_string_append_printf (s,"%d%s" , (int )gpr[5 ], p2 +2 ); + gpr[2 ] =qemu_semihosting_log_out (s->str, s->len); +g_string_free (s, true); }else { - gpr[2 ] =printf ("%s" , p); + gpr[2 ] =qemu_semihosting_log_out (p,strlen (p)); }FREE_TARGET_STRING (p, gpr[4 ]);break ;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 10/11] target/mips: convert UHI_plog to use common semihosting code
Quoted 8 lines · Alex Bennée
Rather than printing directly to stdout lets use our common semihosting code. There is one minor difference in that the output currently defaults to stderr instead of stdout however this can be controlled by connecting semihosting to a chardev.
Signed-off-by Alex Bennée <[email protected]>---
Quoted 38 lines
target/mips/mips-semi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)target/mips/mips-semi.c +6
-7@@ -23,6 +23,7 @@#include "exec/helper-proto.h" #include "exec/softmmu-semi.h" #include "hw/semihosting/semihost.h" +#include "hw/semihosting/console.h" typedef enum UHIOp { UHI_exit = 1,@@ -329,13 +330,12 @@ void helper_do_semihosting(CPUMIPSState *env) p2 =strstr (p,"%d" );if (p2) {int char_num = p2 - p; -char *buf =g_malloc (char_num +1 ); -strncpy (buf, p, char_num); - buf[char_num] ='\0' ; - gpr[2 ] =printf ("%s%d%s" , buf, (int )gpr[5 ], p2 +2 ); -g_free (buf); +GString *s =g_string_new_len (p, char_num); +g_string_append_printf (s,"%d%s" , (int )gpr[5 ], p2 +2 ); + gpr[2 ] =qemu_semihosting_log_out (s->str, s->len); +g_string_free (s, true); }else { - gpr[2 ] =printf ("%s" , p); + gpr[2 ] =qemu_semihosting_log_out (p,strlen (p)); }FREE_TARGET_STRING (p, gpr[4 ]);break ; --2.20.1
RFC PATCH 11/11 MAINTAINERS: update for semihostings new home
In reply to Alex BennéeSeeing as I touched it I should at least keep an eye on it.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -2559,6 +2559,13 @@ F: docs/pvrdma.txt F: contrib/rdmacm-mux/* F: qapi/rdma.json +Semihosting +M: Alex Bennée <[email protected]> +L: [email protected] +S: Maintained +F: hw/semihosting/ +F: include/hw/semihosting/ + Build and test automation ------------------------- Build and test automation
Signature · 1 line
2.20.1
Re: [Qemu-devel] [RFC PATCH 11/11] MAINTAINERS: update for semihostings new home
Quoted 1 line · Alex Bennée
Seeing as I touched it I should at least keep an eye on it.
Thanks for that.
Quoted 2 lines
Signed-off-by Alex Bennée <[email protected]>
FWIW:
Quoted 23 lines
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)MAINTAINERS +7
-0@@ -2559,6 +2559,13 @@ F: docs/pvrdma.txt F: contrib/rdmacm-mux/* F: qapi/rdma.json +Semihosting +M: Alex Bennée <[email protected]> +L: [email protected] +S: Maintained +F: hw/semihosting/ +F: include/hw/semihosting/ + Build and test automation ------------------------- Build and test automation
Quoted 10 lines · Alex Bennée
Hi,
This collects together some fixes from last weeks RFC clean-up patch as well as a generalised version of the chardev console tweak I made last week for testing/next. As it happens it only really made sense for ARM and MIPs logging semihost calls but there is certainly scope for handling all the semihost syscalls in a more common way. I didn't make the changes to xtensa as that already has a bi-directional console-via-chardev setup and that would be quite a bit of extra work to support.
Ping?
Philippe has already done a bunch of review (no changes suggested so far) but could ARM/MIPS people look over the changes I made to their architectures?
Quoted 61 lines
I've added myself to the
MAINTAINERSsection for the common code but my focus at the moment is really just to improve the use of semihosting in our expanding system tests. Hopefully this is enough to ensure future enhancements (common open/read/write/close?) can be done and easily enabled for all semihost targets.Please review.
Alex Bennée (11):
semihosting: move semihosting configuration into its own directory
semihosting: introduceCONFIG_SEMIHOSTING
semihosting: implement a semihosting console
semihosting: enable chardev backed output for console target/arm: fixup some of the commentary for arm-semi target/arm: use the common interface for WRITE0/WRITEC in arm-semi target/arm: addLOG_UNIMPmessages to arm-semi target/arm: correct return values for WRITE/READ in arm-semi target/mips: only build mips-semi for softmmu target/mips: convertUHI_plogto use common semihosting code
MAINTAINERS: update for semihostings new homeMAINTAINERS | 7 + default-configs/arm-softmmu.mak | 1 + default-configs/lm32-softmmu.mak | 2 + default-configs/m68k-softmmu.mak | 2 + default-configs/mips-softmmu-common.mak | 1 + default-configs/nios2-softmmu.mak | 2 + default-configs/xtensa-softmmu.mak | 2 + gdbstub.c | 7 +- hw/Kconfig | 1 + hw/Makefile.objs | 1 + hw/mips/mips_malta.c | 2 +- hw/semihosting/Kconfig | 3 + hw/semihosting/Makefile.objs | 2 + hw/semihosting/config.c | 186 ++++++++++++++++++++ hw/semihosting/console.c | 77 ++++++++ include/exec/gdbstub.h | 11 ++ include/hw/semihosting/console.h | 38 ++++ include/{exec => hw/semihosting}/semihost.h | 17 +- include/sysemu/sysemu.h | 1 + linux-user/Makefile.objs | 2 + linux-user/arm/semihost.c | 24 +++ qemu-options.hx | 6 +- stubs/Makefile.objs | 1 + stubs/semihost.c | 70 ++++++++ target/arm/arm-semi.c | 98 ++++++----- target/arm/helper.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 2 +- target/lm32/helper.c | 2 +- target/m68k/op_helper.c | 2 +- target/mips/Makefile.objs | 3 +- target/mips/helper.h | 2 + target/mips/mips-semi.c | 14 +- target/mips/translate.c | 10 +- target/nios2/helper.c | 2 +- target/xtensa/translate.c | 2 +- target/xtensa/xtensa-semi.c | 2 +- vl.c | 128 +------------- 38 files changed, 545 insertions(+), 192 deletions(-)
Quoted 8 lines
create mode 100644 hw/semihosting/Kconfig
create mode 100644 hw/semihosting/Makefile.objs
create mode 100644 hw/semihosting/config.c
create mode 100644 hw/semihosting/console.c
create mode 100644 include/hw/semihosting/console.h
rename include/{exec => hw/semihosting}/semihost.h (78%)
create mode 100644 linux-user/arm/semihost.c
create mode 100644 stubs/semihost.c--
Alex Bennée