Skip to contentSkip to conversation

target/xtensa: semihosting cleanup

PATCH In review Richard Henderson 3 participants 11 messages Jun 28, 2022 – Jun 29, 2022

lore
Share & tools
lore
#0 lore raw

v5 cover target/xtensa: semihosting cleanup

Changes for v5:
* Rebase on master.

r~

Richard Henderson (2):
target/xtensa: Use an exception for semihosting
target/xtensa: Use semihosting/syscalls.h

 target/xtensa/cpu.h         |   3 +-
 target/xtensa/helper.h      |   3 -
 hw/xtensa/sim.c             |   3 -
 target/xtensa/exc_helper.c  |   4 +
 target/xtensa/translate.c   |   3 +-
 target/xtensa/xtensa-semi.c | 229 ++++++++----------------------------
 6 files changed, 59 insertions(+), 186 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/2 target/xtensa: Use an exception for semihosting

Within do_interrupt, we hold the iothread lock, which is required for Chardev access for the console, and for the round trip for use_gdb_syscalls().

---
 target/xtensa/cpu.h         | 2 ++
 target/xtensa/helper.h      | 3 ---
 target/xtensa/exc_helper.c  | 4 ++++
 target/xtensa/translate.c   | 3 ++-
 target/xtensa/xtensa-semi.c | 3 +--
 5 files changed, 9 insertions(+), 6 deletions(-)
target/xtensa/cpu.h +2 -0
index 579adcb769..ea66895e7f 100644
@@ -260,6 +260,7 @@ enum {
     EXC_USER,
     EXC_DOUBLE,
     EXC_DEBUG,
+    EXC_SEMIHOST,
     EXC_MAX
 };
 
@@ -576,6 +577,7 @@ void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
                                       unsigned size, MMUAccessType access_type,
                                       int mmu_idx, MemTxAttrs attrs,
                                       MemTxResult response, uintptr_t retaddr);
+void xtensa_semihosting(CPUXtensaState *env);
 #endif
 void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
 hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
target/xtensa/helper.h +0 -3
index ae938ceedb..531679cd86 100644
@@ -11,9 +11,6 @@ DEF_HELPER_2(retw, void, env, i32)
 DEF_HELPER_3(window_check, noreturn, env, i32, i32)
 DEF_HELPER_1(restore_owb, void, env)
 DEF_HELPER_2(movsp, void, env, i32)
-#ifndef CONFIG_USER_ONLY
-DEF_HELPER_1(simcall, void, env)
-#endif
 
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_3(waiti, void, env, i32, i32)
target/xtensa/exc_helper.c +4 -0
index d4823a65cd..d54a518875 100644
@@ -219,6 +219,10 @@ void xtensa_cpu_do_interrupt(CPUState *cs)
     }
 
     switch (cs->exception_index) {
+    case EXC_SEMIHOST:
+        xtensa_semihosting(env);
+        return;
+
     case EXC_WINDOW_OVERFLOW4:
     case EXC_WINDOW_UNDERFLOW4:
     case EXC_WINDOW_OVERFLOW8:
target/xtensa/translate.c +2 -1
index 70e11eeb45..b65c8b8428 100644
@@ -2377,7 +2377,8 @@ static void translate_simcall(DisasContext *dc, const OpcodeArg arg[],
 {
 #ifndef CONFIG_USER_ONLY
     if (semihosting_enabled()) {
-        gen_helper_simcall(cpu_env);
+        tcg_gen_movi_i32(cpu_pc, dc->base.pc_next);
+        gen_exception(dc, EXC_SEMIHOST);
     }
 #endif
 }
target/xtensa/xtensa-semi.c +1 -2
index fa21b7e11f..5375f106fc 100644
@@ -28,7 +28,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "chardev/char-fe.h"
-#include "exec/helper-proto.h"
 #include "semihosting/semihost.h"
 #include "qapi/error.h"
 #include "qemu/log.h"
@@ -188,7 +187,7 @@ void xtensa_sim_open_console(Chardev *chr)
     sim_console = &console;
 }
 
-void HELPER(simcall)(CPUXtensaState *env)
+void xtensa_semihosting(CPUXtensaState *env)
 {
     CPUState *cs = env_cpu(env);
     uint32_t *regs = env->regs;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/2 target/xtensa: Use semihosting/syscalls.h

In reply to Richard Henderson

This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Remove the xtensa custom console handing and rely on the generic -semihosting-config handling of chardevs.

---
 target/xtensa/cpu.h         |   1 -
 hw/xtensa/sim.c             |   3 -
 target/xtensa/xtensa-semi.c | 226 ++++++++----------------------------
 3 files changed, 50 insertions(+), 180 deletions(-)
target/xtensa/cpu.h +0 -1
index ea66895e7f..99ac3efd71 100644
@@ -612,7 +612,6 @@ void xtensa_translate_init(void);
 void **xtensa_get_regfile_by_name(const char *name, int entries, int bits);
 void xtensa_breakpoint_handler(CPUState *cs);
 void xtensa_register_core(XtensaConfigList *node);
-void xtensa_sim_open_console(Chardev *chr);
 void check_interrupts(CPUXtensaState *s);
 void xtensa_irq_init(CPUXtensaState *env);
 qemu_irq *xtensa_get_extints(CPUXtensaState *env);
hw/xtensa/sim.c +0 -3
index 946c71cb5b..5cca6a170e 100644
@@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
         xtensa_create_memory_regions(&sysram, "xtensa.sysram",
                                      get_system_memory());
     }
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }
     return cpu;
 }
 
target/xtensa/xtensa-semi.c +50 -176

271 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 30 lines · Richard Henderson

This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Remove the xtensa custom console handing and rely on the generic -semihosting-config handling of chardevs.

---
 target/xtensa/cpu.h         |   1 -
 hw/xtensa/sim.c             |   3 -
 target/xtensa/xtensa-semi.c | 226 ++++++++----------------------------
 3 files changed, 50 insertions(+), 180 deletions(-)
target/xtensa/cpu.h +0 -1
index ea66895e7f..99ac3efd71 100644
@@ -612,7 +612,6 @@ void xtensa_translate_init(void);
 void **xtensa_get_regfile_by_name(const char *name, int entries, int bits);
 void xtensa_breakpoint_handler(CPUState *cs);
 void xtensa_register_core(XtensaConfigList *node);
-void xtensa_sim_open_console(Chardev *chr);
 void check_interrupts(CPUXtensaState *s);
 void xtensa_irq_init(CPUXtensaState *env);
 qemu_irq *xtensa_get_extints(CPUXtensaState *env);
hw/xtensa/sim.c +0 -0
index 946c71cb5b..5cca6a170e 100644

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 6 lines
hw/xtensa/sim.c +0 -3
@@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
         xtensa_create_memory_regions(&sysram, "xtensa.sysram",
                                      get_system_memory());
     }
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still accepted in the command line, but now they do nothing. This quiet change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

Quoted 1 line
hw/xtensa/sim.c +0 -0
@@ -194,165 +169,64 @@ void xtensa_semihosting(CPUXtensaState *env)

...

Quoted 18 lines
     case TARGET_SYS_select_one:
         {
hw/xtensa/sim.c +4 -10
-            uint32_t fd = regs[3];
-            uint32_t rq = regs[4];
-            uint32_t target_tv = regs[5];
-            uint32_t target_tvv[2];
+            int timeout, events;
 
-            struct timeval tv = {0};
+            if (regs[5]) {
+                uint32_t tv_sec, tv_usec;
+                uint64_t msec;
 
-            if (target_tv) {
-                cpu_memory_rw_debug(cs, target_tv,
-                        (uint8_t *)target_tvv, sizeof(target_tvv), 0);
-                tv.tv_sec = (int32_t)tswap32(target_tvv[0]);
-                tv.tv_usec = (int32_t)tswap32(target_tvv[1]);

hw/xtensa/sim.c

Quoted 10 lines
hw/xtensa/sim.c +2 -8
-            }
-            if (fd < 3 && sim_console) {
-                if ((fd == 1 || fd == 2) && rq == SELECT_ONE_WRITE) {
-                    regs[2] = 1;
-                } else if (fd == 0 && rq == SELECT_ONE_READ) {
-                    regs[2] = sim_console->input.offset > 0;
-                } else {
-                    regs[2] = 0;
+                if (get_user_u32(tv_sec, regs[5]) ||
+                    get_user_u32(tv_usec, regs[5])) {

get_user_u32(tv_usec, regs[5] + 4)?

Quoted 24 lines
hw/xtensa/sim.c +10 -11
+                    xtensa_cb(cs, -1, EFAULT);
+                    return;
                 }
-                regs[3] = 0;
-            } else {
-                fd_set fdset;
 
-                FD_ZERO(&fdset);
-                FD_SET(fd, &fdset);
-                regs[2] = select(fd + 1,
-                                 rq == SELECT_ONE_READ   ? &fdset : NULL,
-                                 rq == SELECT_ONE_WRITE  ? &fdset : NULL,
-                                 rq == SELECT_ONE_EXCEPT ? &fdset : NULL,
-                                 target_tv ? &tv : NULL);
-                regs[3] = errno_h2g(errno);
+                /* Poll timeout is in milliseconds; overflow to infinity. */
+                msec = tv_sec * 1000ull + DIV_ROUND_UP(tv_usec, 1000ull);
+                timeout = msec <= INT32_MAX ? msec : -1;
+            } else {
+                timeout = -1;
             }
+
+            switch (regs[4]) {
+            case SELECT_ONE_READ:

hw/xtensa/sim.c

Quoted 10 lines
hw/xtensa/sim.c +10 -0
+                events = G_IO_IN;
+                break;
+            case SELECT_ONE_WRITE:
+                events = G_IO_OUT;
+                break;
+            case SELECT_ONE_EXCEPT:
+                events = G_IO_PRI;
+                break;
+            default:
+                xtensa_cb(cs, -1, EINVAL);

This doesn't match what there used to be: it was possible to call select_one with rq other than SELECT_ONE_* and that would've passed NULL for all fd sets in the select invocation turning it into a sleep. It would return 0 after the timeout.

Signature · 2 lines
Thanks.
-- Max
#4 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 33 lines · Max Filippov
Quoted 31 lines · Richard Henderson

This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Remove the xtensa custom console handing and rely on the generic -semihosting-config handling of chardevs.

---
  target/xtensa/cpu.h         |   1 -
  hw/xtensa/sim.c             |   3 -
  target/xtensa/xtensa-semi.c | 226 ++++++++----------------------------
  3 files changed, 50 insertions(+), 180 deletions(-)
target/xtensa/cpu.h +0 -1
index ea66895e7f..99ac3efd71 100644
@@ -612,7 +612,6 @@ void xtensa_translate_init(void);
  void **xtensa_get_regfile_by_name(const char *name, int entries, int bits);
  void xtensa_breakpoint_handler(CPUState *cs);
  void xtensa_register_core(XtensaConfigList *node);
-void xtensa_sim_open_console(Chardev *chr);
  void check_interrupts(CPUXtensaState *s);
  void xtensa_irq_init(CPUXtensaState *env);
  qemu_irq *xtensa_get_extints(CPUXtensaState *env);
hw/xtensa/sim.c +0 -0
index 946c71cb5b..5cca6a170e 100644
@@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
          xtensa_create_memory_regions(&sysram, "xtensa.sysram",
Quoted 8 lines

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 5 lines
hw/xtensa/sim.c +0 -3
                                       get_system_memory());
      }
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still accepted in the command line, but now they do nothing.

Pardon? They certainly will do something, via writes to the serial hardware.

Quoted 4 lines

This quiet
change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

I dunno. I'm wary of having xtensa be unique here. Alex, thoughts?

Quoted 4 lines

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 91

Quoted 2 lines
hw/xtensa/sim.c +2 -0
+                if (get_user_u32(tv_sec, regs[5]) ||
+                    get_user_u32(tv_usec, regs[5])) {

get_user_u32(tv_usec, regs[5] + 4)?

Oops, yes.

Quoted 26 lines
Quoted 15 lines
hw/xtensa/sim.c +8 -6
-                regs[2] = select(fd + 1,
-                                 rq == SELECT_ONE_READ   ? &fdset : NULL,
-                                 rq == SELECT_ONE_WRITE  ? &fdset : NULL,
-                                 rq == SELECT_ONE_EXCEPT ? &fdset : NULL,
-                                 target_tv ? &tv : NULL);
-                regs[3] = errno_h2g(errno);
+                /* Poll timeout is in milliseconds; overflow to infinity. */
+                msec = tv_sec * 1000ull + DIV_ROUND_UP(tv_usec, 1000ull);
+                timeout = msec <= INT32_MAX ? msec : -1;
+            } else {
+                timeout = -1;
              }
+
+            switch (regs[4]) {
+            case SELECT_ONE_READ:

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine)

Quoted 10 lines
hw/xtensa/sim.c +10 -0
+                events = G_IO_IN;
+                break;
+            case SELECT_ONE_WRITE:
+                events = G_IO_OUT;
+                break;
+            case SELECT_ONE_EXCEPT:
+                events = G_IO_PRI;
+                break;
+            default:
+                xtensa_cb(cs, -1, EINVAL);
Quoted 4 lines

This doesn't match what there used to be: it was possible to call select_one with rq other than SELECT_ONE_* and that would've passed NULL for all fd sets in the select invocation turning it into a sleep. It would return 0 after the timeout.

Hmm. Is there any documentation of what it was *supposed* to do? Passing rq == 0xdeadbeef and expecting a specific behaviour seems odd.

r~

#5 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 46 lines · Richard Henderson
Quoted 33 lines · Max Filippov
Quoted 31 lines · Richard Henderson

This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Remove the xtensa custom console handing and rely on the generic -semihosting-config handling of chardevs.

---
  target/xtensa/cpu.h         |   1 -
  hw/xtensa/sim.c             |   3 -
  target/xtensa/xtensa-semi.c | 226 ++++++++----------------------------
  3 files changed, 50 insertions(+), 180 deletions(-)
target/xtensa/cpu.h +0 -1
index ea66895e7f..99ac3efd71 100644
@@ -612,7 +612,6 @@ void xtensa_translate_init(void);
  void **xtensa_get_regfile_by_name(const char *name, int entries, int bits);
  void xtensa_breakpoint_handler(CPUState *cs);
  void xtensa_register_core(XtensaConfigList *node);
-void xtensa_sim_open_console(Chardev *chr);
  void check_interrupts(CPUXtensaState *s);
  void xtensa_irq_init(CPUXtensaState *env);
  qemu_irq *xtensa_get_extints(CPUXtensaState *env);
hw/xtensa/sim.c +0 -0
index 946c71cb5b..5cca6a170e 100644
@@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
          xtensa_create_memory_regions(&sysram, "xtensa.sysram",
Quoted 8 lines

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 5 lines
hw/xtensa/sim.c +0 -3
                                       get_system_memory());
      }
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still
accepted in the command line, but now they do nothing.

Pardon? They certainly will do something, via writes to the serial hardware.

Quoted 6 lines
Quoted 4 lines

This quiet
change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

I dunno. I'm wary of having xtensa be unique here. Alex, thoughts?

Is semihosting *the* serial hardware for xtensa-sim or is it overriding another serial interface? I'm wary of adding more magical behaviour for -serial as it can be confusing enough already what actually gets routed to it if not doing everything explicitly.

Quoted 42 lines
Quoted 4 lines

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 91

Quoted 3 lines
hw/xtensa/sim.c +2 -0
+                if (get_user_u32(tv_sec, regs[5]) ||
+                    get_user_u32(tv_usec, regs[5])) {

get_user_u32(tv_usec, regs[5] + 4)?

Oops, yes.

Quoted 25 lines
Quoted 15 lines
hw/xtensa/sim.c +8 -6
-                regs[2] = select(fd + 1,
-                                 rq == SELECT_ONE_READ   ? &fdset : NULL,
-                                 rq == SELECT_ONE_WRITE  ? &fdset : NULL,
-                                 rq == SELECT_ONE_EXCEPT ? &fdset : NULL,
-                                 target_tv ? &tv : NULL);
-                regs[3] = errno_h2g(errno);
+                /* Poll timeout is in milliseconds; overflow to infinity. */
+                msec = tv_sec * 1000ull + DIV_ROUND_UP(tv_usec, 1000ull);
+                timeout = msec <= INT32_MAX ? msec : -1;
+            } else {
+                timeout = -1;
              }
+
+            switch (regs[4]) {
+            case SELECT_ONE_READ:

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine)

Quoted 10 lines
hw/xtensa/sim.c +10 -0
+                events = G_IO_IN;
+                break;
+            case SELECT_ONE_WRITE:
+                events = G_IO_OUT;
+                break;
+            case SELECT_ONE_EXCEPT:
+                events = G_IO_PRI;
+                break;
+            default:
+                xtensa_cb(cs, -1, EINVAL);
Quoted 4 lines

This doesn't match what there used to be: it was possible to call select_one with rq other than SELECT_ONE_* and that would've passed NULL for all fd sets in the select invocation turning it into a sleep. It would return 0 after the timeout.

Hmm. Is there any documentation of what it was *supposed* to do? Passing rq == 0xdeadbeef and expecting a specific behaviour seems odd.

r~

Signature · 1 line
Alex Bennée
#6 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 21 lines · Alex Bennée
Quoted 20 lines · Richard Henderson
Quoted 10 lines · Max Filippov

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 4 lines · Richard Henderson
      }
hw/xtensa/sim.c +0 -3
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still
accepted in the command line, but now they do nothing.

Pardon? They certainly will do something, via writes to the serial hardware.

Quoted 4 lines

This quiet
change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

Quoted 6 lines
Quoted 1 line

I dunno. I'm wary of having xtensa be unique here. Alex, thoughts?

Is semihosting *the* serial hardware for xtensa-sim or is it overriding another serial interface? I'm wary of adding more magical behaviour for -serial as it can be confusing enough already what actually gets routed to it if not doing everything explicitly.

There's no notion of 'serial hardware' for the xtensa-sim, all it has is the three standard stdio file descriptors. But it was convenient thinking of them as a serial port. I agree that no magic is needed here, but the change shouldn't be quiet eiter, so xtensa-sim should warn (or maybe even quit with an error code) when it sees the -serial option.

Signature · 2 lines
Thanks.
-- Max
#7 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 24 lines · Max Filippov
Quoted 23 lines · Alex Bennée
Quoted 21 lines · Richard Henderson
Quoted 10 lines · Max Filippov

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 4 lines · Richard Henderson
      }
hw/xtensa/sim.c +0 -3
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still
accepted in the command line, but now they do nothing.

Pardon? They certainly will do something, via writes to the serial hardware.

Quoted 4 lines

This quiet
change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

I dunno. I'm wary of having xtensa be unique here. Alex, thoughts?

Quoted 7 lines
Quoted 4 lines

Is semihosting *the* serial hardware for xtensa-sim or is it overriding another serial interface? I'm wary of adding more magical behaviour for -serial as it can be confusing enough already what actually gets routed to it if not doing everything explicitly.

There's no notion of 'serial hardware' for the xtensa-sim, all it has is the three standard stdio file descriptors.

Which are accessed via semihosting calls? Are they implicitly mapped to 3 chardev devices for stdin, stdout and stderr?

Quoted 4 lines

But it was convenient thinking
of them as a serial port. I agree that no magic is needed here, but the change shouldn't be quiet eiter, so xtensa-sim should warn (or maybe even quit with an error code) when it sees the -serial option.

If the default chardevs already map to the 3 FDs then perhaps -serial should be invalid because it is more explicit to use -chardev to redirect the stream you want somewhere else. However I don't see them at the moment:

➜ ./qemu-system-xtensa -M sim -semihosting -S -display none -monitor stdio QEMU 7.0.50 monitor - type 'help' for more information
(qemu) info chardev
compat_monitor0: filename=stdio
parallel0: filename=vc

Signature · 1 line
Alex Bennée
#8 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

Quoted 6 lines · Alex Bennée
Quoted 2 lines · Max Filippov

There's no notion of 'serial hardware' for the xtensa-sim, all it has is the three standard stdio file descriptors.

Which are accessed via semihosting calls?

Yes.

Quoted 2 lines

Are they implicitly mapped to
3 chardev devices for stdin, stdout and stderr?

In the absence of -serial option they are not mapped.
In the presence of that option they are mapped to the single chardev that was passed as the parameter of that option.

Quoted 10 lines
Quoted 4 lines

But it was convenient thinking
of them as a serial port. I agree that no magic is needed here, but the change shouldn't be quiet eiter, so xtensa-sim should warn (or maybe even quit with an error code) when it sees the -serial option.

If the default chardevs already map to the 3 FDs then perhaps -serial should be invalid because it is more explicit to use -chardev to redirect the stream you want somewhere else. However I don't see them at the moment:

Quoted 5 lines

➜ ./qemu-system-xtensa -M sim -semihosting -S -display none -monitor stdio QEMU 7.0.50 monitor - type 'help' for more information
(qemu) info chardev
compat_monitor0: filename=stdio
parallel0: filename=vc

Well, that mapping was done by me, manually (grep for sim_console in the target/xtensa/xtensa-semi.c), so no wonder that parts like this don't work.

Signature · 2 lines
Thanks.
-- Max
#9 lore raw

Re: [PATCH v5 2/2] target/xtensa: Use semihosting/syscalls.h

In reply to Richard Henderson
Quoted 3 lines · Richard Henderson
Quoted 2 lines · Max Filippov

On Tue, Jun 28, 2022 at 4:43 AM Richard Henderson
<[email protected]> wrote:

...

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
hw/xtensa/sim.c +0 -0
index 946c71cb5b..5cca6a170e 100644
@@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
          xtensa_create_memory_regions(&sysram, "xtensa.sysram",
Quoted 8 lines

hw/xtensa/sim.c XtensaCPU *xtensa_sim_common_init(MachineState *machine) · line 92

Quoted 5 lines
hw/xtensa/sim.c +0 -3
                                       get_system_memory());
      }
-    if (serial_hd(0)) {
-        xtensa_sim_open_console(serial_hd(0));
-    }

I've noticed that with this change '-serial stdio' and its variants are still accepted in the command line, but now they do nothing.

Quoted 1 line

Pardon? They certainly will do something, via writes to the serial hardware.

What I meant was that with '-serial' option prior to this change it was possible to redirect the standard streams of the sim machine, to stdio, or socket or wherever, but after this change the option will be accepted, but the machine will always have its first three file descriptors connected to the QEMU's first three file descriptors.

I'd print a warning here, saying that the behavior has changed and the '-semihosting-config chardev' must be used now.

Quoted 6 lines
Quoted 4 lines

This quiet
change of behavior is unfortunate. I wonder if it would be acceptable to map the '-serial stdio' option in the presence of '-semihosting' to something like '-chardev stdio,id=id1 -semihosting-config chardev=id1'?

I dunno. I'm wary of having xtensa be unique here. Alex, thoughts?

Yeah, I thought about it some more and now it doesn't look like a good idea to me either.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
hw/xtensa/sim.c +12 -0
+            switch (regs[4]) {
+            case SELECT_ONE_READ:
+                events = G_IO_IN;
+                break;
+            case SELECT_ONE_WRITE:
+                events = G_IO_OUT;
+                break;
+            case SELECT_ONE_EXCEPT:
+                events = G_IO_PRI;
+                break;
+            default:
+                xtensa_cb(cs, -1, EINVAL);
Quoted 7 lines
Quoted 4 lines

This doesn't match what there used to be: it was possible to call select_one with rq other than SELECT_ONE_* and that would've passed NULL for all fd sets in the select invocation turning it into a sleep. It would return 0 after the timeout.

Hmm. Is there any documentation of what it was *supposed* to do? Passing rq == 0xdeadbeef and expecting a specific behaviour seems odd.

I haven't found any documentation for that simcall.
All I can say is that the logic in the code that used to be here is matching exactly the logic in the code of the xtensa ISS from Cadence/Tensilica.

Signature · 2 lines
Thanks.
-- Max
Tested-by on the v5 series
#10 lore raw
In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

Changes for v5:
* Rebase on master.

r~

Richard Henderson (2):
target/xtensa: Use an exception for semihosting
target/xtensa: Use semihosting/syscalls.h

Quoted 7 lines
 target/xtensa/cpu.h         |   3 +-
 target/xtensa/helper.h      |   3 -
 hw/xtensa/sim.c             |   3 -
 target/xtensa/exc_helper.c  |   4 +
 target/xtensa/translate.c   |   3 +-
 target/xtensa/xtensa-semi.c | 229 ++++++++----------------------------
 6 files changed, 59 insertions(+), 186 deletions(-)
Signature · 2 lines
Thanks.
-- Max