Many TCG targets copy the same two-line raise: set cs->exception_index and call
cpu_loop_exit_restore. They also copy DEF_HELPER_2(raise_exception, ...).
helper_raise_exception is a global C symbol, so a unified binary cannot keep
that name on more than one target.

This series adds a shared C exit and two shared TCG helpers, then converts one
target per commit. Joiners call gen_helper_raise_excp or
gen_helper_raise_excp_restore and drop the copied DEF. Leftover TCG helpers that
still do extra work take an arch prefix. C wrappers keep the short name as
static inline where that is enough. The shared helpers only touch CPUState.
Translate may store arch state (error_code, PC) first. Guest trap numbers stay
below 0x10000. TCG loop codes such as EXCP_INTERRUPT start at 0x10000.

- Move helper_exit_atomic into cpu-exec-common.c with its DEF_HELPER, so the new
  helpers can sit beside it.
- Add cpu_loop_exit_excp next to cpu_loop_exit_restore. Set
  cpu->exception_index, then restore and exit the same way as
  cpu_loop_exit_restore.
- Add TCG raise_excp and raise_excp_restore next to cpu_loop_exit_excp.
  raise_excp exits with host_pc 0. raise_excp_restore exits with GETPC(). Each
  helper does one thing.
- Name RX and SH4 guest traps RX_EXCP_* and SH4_EXCP_* in their own commits,
  then convert the raises. Join privilege and illegal on RX through
  raise_excp_restore, and BRK and INT through raise_excp. Join illegal and
  FPU-disable on SH4. Keep SH4 sleep, trapa, and exclusive.
- Convert the remaining joiners one arch per commit: m68k, or1k, microblaze,
  sparc, loongarch, hppa, alpha, s390x, xtensa, avr, arm exception_internal,
  mips, and ppc. Store error_code or PC in translate where needed, then call the
  shared helper. loongarch and the mips 2-arg path use raise_excp_restore.
- Add gen_yield before the xtensa conversion. Fold gen_exception_nip into
  gen_exception_err_nip before the ppc conversion.
- Prefix leftover TCG helpers that still do extra work: riscv_raise_exception
  and hexagon_raise_exception. Tricore raise_exception_sync does not join.

v1: https://patchew.org/QEMU/[email protected]/

Changes v1 -> v2:

- Move helper_exit_atomic into cpu-exec-common.c. Split the restore flag into
  raise_excp and raise_excp_restore, and define both there.
- Drop the helper-gen nested-extern change.
- Shorten the cpu_loop_exit_excp comment. Drop the generic EXCP_INTERRUPT note
  on the RX and SH4 trap enums, and put those enums in their own commits.
- Split xtensa gen_yield and the ppc gen_exception_nip fold out of the
  conversion commits.
- Omit the i386 conversion, the rx, mips, and hexagon helper_wait renames, and
  the arm raise_exception rename.

Yonggang Luo (24):
  accel/tcg: move helper_exit_atomic next to cpu_loop_exit_atomic
  accel/tcg: add cpu_loop_exit_excp
  accel/tcg: add raise_excp and raise_excp_restore helpers
  target/rx: name guest trap numbers RX_EXCP_*
  target/rx: convert raises to raise_excp
  target/sh4: name guest trap numbers SH4_EXCP_*
  target/sh4: convert raises to raise_excp
  target/m68k: convert raises to raise_excp
  target/or1k: convert exception to raise_excp
  target/microblaze: convert raise_exception to raise_excp
  target/sparc: convert raise_exception to raise_excp
  target/loongarch: convert raise_exception to raise_excp
  target/hexagon: convert raise_exception to hexagon_raise_exception
  target/hppa: convert excp to raise_excp
  target/alpha: convert excp to raise_excp
  target/s390x: convert exception to raise_excp
  target/xtensa: add gen_yield for EXCP_YIELD
  target/xtensa: convert exception to raise_excp
  target/avr: convert debug/break/sleep to raise_excp
  target/arm: convert exception_internal to raise_excp
  target/riscv: convert raise_exception to riscv_raise_exception
  target/mips: convert raise_exception to raise_excp
  target/ppc: fold gen_exception_nip into gen_exception_err_nip
  target/ppc: convert raise_exception to raise_excp

 MAINTAINERS                                   |  1 +
 accel/tcg/cpu-exec-common.c                   | 28 +++++++
 accel/tcg/cpu-exec-common.h                   |  4 +
 accel/tcg/tcg-runtime.c                       |  8 --
 accel/tcg/tcg-runtime.h                       |  2 -
 include/accel/tcg/cpu-loop.h                  | 12 +++
 include/exec/helper-gen-common.h              |  4 +
 include/exec/helper-proto-common.h            |  4 +
 target/alpha/helper.c                         | 11 ---
 target/alpha/helper.h                         |  1 -
 target/alpha/translate.c                      |  8 +-
 target/arm/tcg/helper-defs.h                  |  1 -
 target/arm/tcg/m_helper.c                     |  3 +-
 target/arm/tcg/op_helper.c                    | 33 ++------
 target/arm/tcg/translate.c                    |  2 +-
 target/avr/helper.c                           | 24 ------
 target/avr/helper.h                           |  3 -
 target/avr/translate.c                        |  4 +-
 target/hexagon/cpu.c                          | 13 +--
 target/hexagon/cpu.h                          |  2 +-
 target/hexagon/helper.h                       |  3 +-
 target/hexagon/internal.h                     |  5 --
 target/hexagon/macros.h                       |  2 +-
 target/hexagon/op_helper.c                    | 29 +++----
 target/hexagon/translate.c                    | 11 +--
 target/hppa/helper.h                          |  2 -
 target/hppa/op_helper.c                       | 15 +---
 target/hppa/sys_helper.c                      |  4 +-
 target/hppa/translate.c                       |  2 +-
 target/loongarch/tcg/helper.h                 |  2 -
 target/loongarch/tcg/op_helper.c              |  6 --
 target/loongarch/tcg/tcg_cpu.c                |  4 +-
 target/loongarch/tcg/translate.c              |  2 +-
 target/m68k/helper.c                          | 12 +--
 target/m68k/helper.h                          |  1 -
 target/m68k/op_helper.c                       | 19 -----
 target/m68k/translate.c                       |  2 +-
 target/microblaze/helper.c                    |  3 +-
 target/microblaze/helper.h                    |  2 -
 target/microblaze/op_helper.c                 | 22 +----
 target/microblaze/translate.c                 |  2 +-
 target/mips/helper.h                          |  4 -
 target/mips/tcg/exception.c                   | 20 +----
 target/mips/tcg/fpu_helper.c                  |  6 +-
 target/mips/tcg/translate.c                   |  9 +-
 target/or1k/exception.c                       | 31 -------
 target/or1k/exception.h                       |  7 +-
 target/or1k/exception_helper.c                | 13 +--
 target/or1k/helper.h                          |  1 -
 target/or1k/meson.build                       |  1 -
 target/or1k/translate.c                       |  2 +-
 target/ppc/cpu.h                              |  3 -
 target/ppc/helper.h                           |  2 -
 target/ppc/internal.h                         |  9 ++
 target/ppc/misc_helper.c                      |  1 +
 target/ppc/tcg-excp_helper.c                  | 21 -----
 target/ppc/timebase_helper.c                  |  1 +
 target/ppc/translate.c                        | 20 ++---
 target/riscv/helper.h                         |  2 +-
 target/riscv/tcg/insn_trans/trans_rvi.c.inc   |  6 +-
 .../tcg/insn_trans/trans_rvzicfiss.c.inc      |  3 +-
 target/riscv/tcg/op_helper.c                  |  5 +-
 target/riscv/tcg/translate.c                  | 10 ++-
 target/rx/cpu.h                               | 10 +++
 target/rx/helper.c                            | 16 ++--
 target/rx/helper.h                            |  5 --
 target/rx/op_helper.c                         | 44 +---------
 target/rx/translate.c                         | 13 ++-
 target/s390x/helper.h                         |  1 -
 target/s390x/tcg/mem_helper.c                 |  2 +-
 target/s390x/tcg/misc_helper.c                | 10 ---
 target/s390x/tcg/translate.c                  |  2 +-
 target/sh4/cpu.h                              | 21 +++++
 target/sh4/helper.c                           | 82 ++++++++++---------
 target/sh4/helper.h                           |  4 -
 target/sh4/op_helper.c                        | 43 ++--------
 target/sh4/translate.c                        | 12 ++-
 target/sparc/helper.c                         | 21 +----
 target/sparc/helper.h                         |  2 -
 target/sparc/translate.c                      |  6 +-
 target/xtensa/cpu.h                           |  1 +
 target/xtensa/exc_helper.c                    | 13 ++-
 target/xtensa/helper.h                        |  1 -
 target/xtensa/translate.c                     |  8 +-
 target/xtensa/win_helper.c                    | 12 +--
 85 files changed, 287 insertions(+), 537 deletions(-)
 create mode 100644 accel/tcg/cpu-exec-common.h
 delete mode 100644 target/or1k/exception.c

-- 
2.52.0.windows.1


Reply via email to