target/arm: Remove bswap_code
v2 cover target/arm: Remove bswap_code
Based-on: [email protected] ("[PATCH v11 00/21] target/arm: single-binary")
Version 2 here should probably be RFC. This time around, all instruction loading, and more decode, is done by translate. A new CPUARMState field is added for passing data to EXCP_SWI and EXCP_NWFPE.
r~
Richard Henderson (7):
linux-user/arm: Restrict regpairs_aligned target/arm: Only define aarch64_untagged_addr for aarch64 target/arm: Segregate target-specific user-only fields target/arm: Store SVC immediate for user-only target/arm: Recognize linux faux BPKT target/arm: Introduce EXCP_NWFPE
target/arm: Remove bswap_code
linux-user/user-internals.h | 2 +- target/arm/cpu.h | 27 ++++--------- linux-user/arm/cpu_loop.c | 75 +++++-------------------------------- target/arm/cpu.c | 28 +++++++------- target/arm/tcg/translate.c | 63 ++++++++++++++++++++++++++++++- target/arm/tcg/a32.decode | 5 ++- target/arm/tcg/t16.decode | 1 + target/arm/tcg/t32.decode | 5 ++- 8 files changed, 103 insertions(+), 103 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/7 linux-user/arm: Restrict regpairs_aligned
The function regpairs_aligned is for extracting a 64-bit quantity from a pair of 32-bit registers and does not apply to AArch64.
--- linux-user/user-internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/user-internals.h +1 -1
@@ -136,7 +136,7 @@ void print_termios2(void *arg);#endif /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ -#ifdef TARGET_ARM +#if defined(TARGET_ARM ) && !defined(TARGET_AARCH64 )static inline int regpairs_aligned (CPUArchState *cpu_env,int num) {return cpu_env->eabi;
Signature · 1 line
2.43.0
Re: [PATCH v2 1/7] linux-user/arm: Restrict regpairs_aligned
Quoted 8 lines · Richard Henderson
The function
regpairs_alignedis for extracting a 64-bit quantity from a pair of 32-bit registers and does not apply to AArch64.Signed-off-by Richard Henderson <[email protected]>--- linux-user/user-internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 2/7 target/arm: Only define aarch64_untagged_addr for aarch64
In reply to Richard Henderson--- target/arm/cpu.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
target/arm/cpu.c +15 -13
@@ -2262,7 +2262,19 @@ static const char *arm_gdb_get_core_xml_file(CPUState *cs)return "arm-core.xml" ; } -#ifdef CONFIG_USER_ONLY +#ifndef CONFIG_USER_ONLY +#include "hw/core/sysemu-cpu-ops.h" + +static const struct SysemuCPUOps arm_sysemu_ops = { + .has_work = arm_cpu_has_work, + .get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug, + .asidx_from_attrs = arm_asidx_from_attrs, + .write_elf32_note = arm_cpu_write_elf32_note, + .write_elf64_note = arm_cpu_write_elf64_note, + .internal_is_big_endian = arm_cpu_internal_is_big_endian, + .legacy_vmsd = &vmstate_arm_cpu, +}; +#elif defined(TARGET_AARCH64 )/** * aarch64_untagged_addr: *
@@ -2286,18 +2298,6 @@ static vaddr aarch64_untagged_addr(CPUState *cs, vaddr x) }return x; } -#else -#include "hw/core/sysemu-cpu-ops.h" - -static const struct SysemuCPUOps arm_sysemu_ops = { - .has_work = arm_cpu_has_work, - .get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug, - .asidx_from_attrs = arm_asidx_from_attrs, - .write_elf32_note = arm_cpu_write_elf32_note, - .write_elf64_note = arm_cpu_write_elf64_note, - .internal_is_big_endian = arm_cpu_internal_is_big_endian, - .legacy_vmsd = &vmstate_arm_cpu, -};#endif #ifdef CONFIG_TCG
@@ -2340,7 +2340,9 @@ static const TCGCPUOps arm_tcg_ops = {#ifdef CONFIG_USER_ONLY .record_sigsegv = arm_cpu_record_sigsegv, .record_sigbus = arm_cpu_record_sigbus, +# ifdef TARGET_AARCH64 .untagged_addr = aarch64_untagged_addr, +# endif #else .tlb_fill_align = arm_cpu_tlb_fill_align, .pointer_wrap = aprofile_pointer_wrap,
Signature · 1 line
2.43.0
Re: [PATCH v2 2/7] target/arm: Only define aarch64_untagged_addr for aarch64
Quoted 4 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
PATCH v2 3/7 target/arm: Segregate target-specific user-only fields
In reply to Richard HendersonIn CPUARMState, we have one field that is only used for AArch32 and one that is only used for AArch64. Use one more ifdef to avoid adding both at the same time.
--- target/arm/cpu.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/arm/cpu.h +5 -4
@@ -812,12 +812,13 @@ typedef struct CPUArchState {const struct arm_boot_info *boot_info;/* Store GICv3CPUState to access from this struct */ void *gicv3state; -#else /* CONFIG_USER_ONLY */ -/* For usermode syscall translation. */ -bool eabi; +#elif defined(TARGET_AARCH64 )/* Linux syscall tagged address support */ bool tagged_addr_enable; -#endif /* CONFIG_USER_ONLY */ +#else +/* For usermode syscall translation. */ +bool eabi; +#endif /* !CONFIG_USER_ONLY */ } CPUARMState;static inline void set_feature (CPUARMState *env,int feature)
Signature · 1 line
2.43.0
Re: [PATCH v2 3/7] target/arm: Segregate target-specific user-only fields
Quoted 8 lines · Richard Henderson
In CPUARMState, we have one field that is only used for AArch32 and one that is only used for AArch64. Use one more ifdef to avoid adding both at the same time.
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
PATCH v2 4/7 target/arm: Store SVC immediate for user-only
In reply to Richard HendersonRather than re-reading the insn during syscall processing to find the immediate, store it in CPUARMState during translate.
--- target/arm/cpu.h | 1 + linux-user/arm/cpu_loop.c | 13 ++++--------- target/arm/tcg/translate.c | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 11 deletions(-)
target/arm/cpu.h +1 -0
@@ -817,6 +817,7 @@ typedef struct CPUArchState {bool tagged_addr_enable;#else /* For usermode syscall translation. */ +uint32_t syscall_info;bool eabi;#endif /* !CONFIG_USER_ONLY */ } CPUARMState;
linux-user/arm/cpu_loop.c +4 -9
@@ -271,7 +271,6 @@ void cpu_loop(CPUARMState *env) {CPUState *cs =env_cpu (env);int trapnr, si_signo, si_code; -unsigned int n, insn;abi_ulong ret;for (;;) {
@@ -312,20 +311,16 @@ void cpu_loop(CPUARMState *env)break ;case EXCP_SWI : { +unsigned int n; + env->eabi = true;/* system call */ if (env->thumb) {/* Thumb is always EABI style with syscall number in r7 */ n = env->regs[7 ]; }else { -/* -* Equivalent of kernel CONFIG_OABI_COMPAT: read the -* Arm SVC insn to extract the immediate, which is the -* syscall number in OABI. -*/ -/* FIXME - what to do if get_user() fails? */ -get_user_code_u32 (insn, env->regs[15 ] -4 , env); - n = insn &0xffffff ; +/* The 24-bit SVC immediate is stored during translate. */ + n = env->syscall_info;if (n ==0 ) {/* zero immediate: EABI, syscall number in r7 */ n = env->regs[7 ];
target/arm/tcg/translate.c +17 -2
@@ -1158,6 +1158,21 @@ void unallocated_encoding(DisasContext *s)gen_exception_insn (s,0 ,EXCP_UDEF ,syn_uncategorized ()); } +static void gen_exception_swi (DisasContext *s) +{ +#ifdef CONFIG_USER_ONLY +# ifndef TARGET_AARCH64 +/* +* Only 16-bits of the immediate are recorded in the syndrome, +* so store the entire 24-bit immediate for cpu_loop(). +*/ +tcg_gen_st_i32 (tcg_constant_i32 (s->svc_imm), tcg_env, + offsetof(CPUARMState , syscall_info)); +# endif +#endif +gen_exception (EXCP_SWI ,syn_aa32_svc (s->svc_imm, s->thumb)); +} +/* Force a TB lookup after an instruction that changes the CPU state. */ void gen_lookup_tb (DisasContext *s) {
@@ -6781,7 +6796,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)switch (dc->base.is_jmp) {case DISAS_SWI :gen_ss_advance (dc); -gen_exception (EXCP_SWI ,syn_aa32_svc (dc->svc_imm, dc->thumb)); +gen_exception_swi (dc);break ;case DISAS_HVC :gen_ss_advance (dc);
@@ -6854,7 +6869,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)gen_helper_yield (tcg_env);break ;case DISAS_SWI : -gen_exception (EXCP_SWI ,syn_aa32_svc (dc->svc_imm, dc->thumb)); +gen_exception_swi (dc);break ;case DISAS_HVC :gen_exception_el (EXCP_HVC ,syn_aa32_hvc (dc->svc_imm),2 );
Signature · 1 line
2.43.0
PATCH v2 5/7 target/arm: Recognize linux faux BPKT
In reply to Richard HendersonIt is easier to recognize the insn from decodetree than it is from cpu_loop. In particular, there is a BE32 bug in how we rebuild thumb2 insns in get_user_code_u32.
--- linux-user/arm/cpu_loop.c | 28 ---------------------------- target/arm/tcg/translate.c | 17 +++++++++++++++++ target/arm/tcg/a32.decode | 5 ++++- target/arm/tcg/t16.decode | 1 + target/arm/tcg/t32.decode | 5 ++++- 5 files changed, 26 insertions(+), 30 deletions(-)
linux-user/arm/cpu_loop.c +0 -28
@@ -194,24 +194,6 @@ do_kernel_trap(CPUARMState *env)return 0 ; } -static bool insn_is_linux_bkpt (uint32_t opcode,bool is_thumb) -{ -/* -* Return true if this insn is one of the three magic UDF insns -* which the kernel treats as breakpoint insns. -*/ -if (!is_thumb) { -return (opcode &0x0fffffff ) ==0x07f001f0 ; - }else { -/* -* Note that we get the two halves of the 32-bit T32 insn -* in the opposite order to the value the kernel uses in -* its undef_hook struct. -*/ -return ((opcode &0xffff ) ==0xde01 ) || (opcode ==0xa000f7f0 ); - } -} -static bool emulate_arm_fpa11 (CPUARMState *env,uint32_t opcode) {TaskState *ts =get_task_state (env_cpu (env));
@@ -291,16 +273,6 @@ void cpu_loop(CPUARMState *env)/* FIXME - what to do if get_user() fails? */ get_user_code_u32 (opcode, env->regs[15 ], env); -/* -* The Linux kernel treats some UDF patterns specially -* to use as breakpoints (instead of the architectural -* bkpt insn). These should trigger a SIGTRAP rather -* than SIGILL. -*/ -if (insn_is_linux_bkpt (opcode, env->thumb)) { - goto excp_debug; - } -if (!env->thumb &&emulate_arm_fpa11 (env, opcode)) {break ; }
target/arm/tcg/translate.c +17 -0
@@ -4508,6 +4508,23 @@ static bool trans_BFCI(DisasContext *s, arg_BFCI *a)return true; } +static bool trans_LINUX_BKPT (DisasContext *s,arg_LINUX_BKPT *a) +{ +#ifdef CONFIG_USER_ONLY +# ifdef CONFIG_LINUX +/* +* The Linux kernel recognizes 3 UDF patterns as breakpoints. +* Recognizing these during translate is much less error prone +* than deferring to cpu_loop. +*/ +gen_exception_bkpt_insn (s,0 ); +return true; +# endif +#endif +/* Fall through to UDF. */ +return false; +} +static bool trans_UDF (DisasContext *s,arg_UDF *a) {unallocated_encoding (s);
target/arm/tcg/a32.decode +4 -1
@@ -425,7 +425,10 @@ BFCI ---- 0111 110 msb:5 rd:4 lsb:5 001 rn:4 &bfi # While we could get UDEF by not including this, add the pattern for # documentation and to conflict with any other typos in this file. -UDF 1110 0111 1111 ---- ---- ---- 1111 ---- +{ + LINUX_BKPT 1110 0111 1111 0000 0000 0001 1111 0000 + UDF 1110 0111 1111 ---- ---- ---- 1111 ---- +} # Parallel addition and subtraction
target/arm/tcg/t16.decode +1 -0
@@ -263,6 +263,7 @@ LDM_t16 1011 110 ......... \ %imm8_0x2 0:s8 !function=times_2 { + LINUX_BKPT 1101 1110 0000 0001 UDF 1101 1110 ---- ---- SVC 1101 1111 imm:8 &i B_cond_thumb 1101 cond:4 ........ &ci imm=%imm8_0x2
target/arm/tcg/t32.decode +4 -1
@@ -418,7 +418,10 @@ CLZ 1111 1010 1011 ---- 1111 .... 1000 .... @rdm SMC 1111 0111 1111 imm:4 1000 0000 0000 0000 &i HVC 1111 0111 1110 .... 1000 .... .... .... \ &i imm=%imm16_16_0 - UDF 1111 0111 1111 ---- 1010 ---- ---- ---- + { + LINUX_BKPT 1111 0111 1111 0000 1010 0000 0000 0000 + UDF 1111 0111 1111 ---- 1010 ---- ---- ---- + } ] B_cond_thumb 1111 0. cond:4 ...... 10.0 ............ &ci imm=%imm21 }
Signature · 1 line
2.43.0
PATCH v2 6/7 target/arm: Introduce EXCP_NWFPE
In reply to Richard HendersonWe don't normally emulate any coprocessor {1,2} insns, but linux-user would like to emulate these fpa11 insns.
Filter these, raise a special exception, and store the instruction in CPUARMState.syscall_info rather than reload the instruction in the linux-user cpu_loop.
--- target/arm/cpu.h | 1 + linux-user/arm/cpu_loop.c | 34 ++++++---------------------------- target/arm/tcg/translate.c | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 28 deletions(-)
target/arm/cpu.h +1 -0
@@ -64,6 +64,7 @@#define EXCP_VINMI 27#define EXCP_VFNMI 28#define EXCP_MON_TRAP 29/* AArch32 trap to Monitor mode */ +#define EXCP_NWFPE 30/* linux-user fpa11 emulation */ /* NB: add new EXCP_ defines to the array in arm_log_exception() too */ #define ARMV7M_EXCP_RESET 1
linux-user/arm/cpu_loop.c +6 -28
@@ -29,19 +29,6 @@#include "user/page-protection.h" #include "target/arm/syndrome.h" -#define get_user_code_u32 (x, gaddr, env) \ - ({ abi_long __r = get_user_u32((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ - (x) = bswap32(x); \ - } \ - __r; \ - }) - -/* -* Note that if we need to do data accesses here, they should do a -* bswap if arm_cpu_bswap_data() returns true. -*/ -/* * Similar to code in accel/tcg/user-exec.c, but outside the execution loop. * Must be called with mmap_lock.
@@ -262,24 +249,15 @@ void cpu_loop(CPUARMState *env)qemu_process_cpu_events (cs);switch (trapnr) { +case EXCP_NWFPE : +if (emulate_arm_fpa11 (env, env->syscall_info)) { +break ; + } +/* fall through */ case EXCP_UDEF :case EXCP_NOCP :case EXCP_INVSTATE : - { -uint32_t opcode; - -/* we handle the FPU emulation here, as Linux */ -/* we get the opcode */ -/* FIXME - what to do if get_user() fails? */ -get_user_code_u32 (opcode, env->regs[15 ], env); - -if (!env->thumb &&emulate_arm_fpa11 (env, opcode)) { -break ; - } - -force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , - env->regs[15 ]); - } +force_sig_fault (TARGET_SIGILL ,TARGET_ILL_ILLOPN , env->regs[15 ]);break ;case EXCP_SWI : {
target/arm/tcg/translate.c +27 -0
@@ -2358,8 +2358,26 @@ static bool valid_cp(DisasContext *s, int cp)return cp <8 || cp >=14 ; } +static bool maybe_nwfpe (DisasContext *s,int cp) +{ +#ifdef CONFIG_USER_ONLY +# if defined(CONFIG_LINUX ) && !defined(TARGET_AARCH64 ) +if (!s->thumb && (cp ==1 || cp ==2 )) { +tcg_gen_st_i32 (tcg_constant_i32 (s->insn), tcg_env, + offsetof(CPUARMState , syscall_info)); +gen_exception_insn (s,0 ,EXCP_NWFPE ,syn_uncategorized ()); +return true; + } +# endif +#endif +return false; +} +static bool trans_MCR (DisasContext *s,arg_MCR *a) { +if (maybe_nwfpe (s, a->cp)) { +return true; + }if (!valid_cp (s, a->cp)) {return false; }
@@ -2370,6 +2388,9 @@ static bool trans_MCR(DisasContext *s, arg_MCR *a)static bool trans_MRC (DisasContext *s,arg_MRC *a) { +if (maybe_nwfpe (s, a->cp)) { +return true; + }if (!valid_cp (s, a->cp)) {return false; }
@@ -2380,6 +2401,9 @@ static bool trans_MRC(DisasContext *s, arg_MRC *a)static bool trans_MCRR (DisasContext *s,arg_MCRR *a) { +if (maybe_nwfpe (s, a->cp)) { +return true; + }if (!valid_cp (s, a->cp)) {return false; }
@@ -2390,6 +2414,9 @@ static bool trans_MCRR(DisasContext *s, arg_MCRR *a)static bool trans_MRRC (DisasContext *s,arg_MRRC *a) { +if (maybe_nwfpe (s, a->cp)) { +return true; + }if (!valid_cp (s, a->cp)) {return false; }
Signature · 1 line
2.43.0
PATCH v2 7/7 target/arm: Remove bswap_code
In reply to Richard HendersonThis function is no longer used.
--- target/arm/cpu.h | 16 ---------------- 1 file changed, 16 deletions(-)
target/arm/cpu.h +0 -16
@@ -2571,22 +2571,6 @@ static inline int sme_vq(CPUARMState *env)return EX_TBFLAG_A64 (env->hflags,SVL ) +1 ; } -static inline bool bswap_code (bool sctlr_b) -{ -#ifdef CONFIG_USER_ONLY -/* BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian. -* The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0 -* would also end up as a mixed-endian mode with BE code, LE data. -*/ -return TARGET_BIG_ENDIAN ^ sctlr_b; -#else -/* All code access in ARM is little endian, and there are no loaders -* doing swaps that need to be reversed -*/ -return 0 ; -#endif -} -enum {QEMU_PSCI_CONDUIT_DISABLED =0 ,QEMU_PSCI_CONDUIT_SMC =1 ,
Signature · 1 line
2.43.0
Quoted 13 lines · Richard Henderson
Based-on: [email protected] ("[PATCH v11 00/21] target/arm: single-binary")
Version 2 here should probably be RFC. This time around, all instruction loading, and more decode, is done by translate. A new CPUARMState field is added for passing data to
EXCP_SWIandEXCP_NWFPE.r~
Quoted 8 lines
Richard Henderson (7):
linux-user/arm: Restrictregpairs_alignedtarget/arm: Only defineaarch64_untagged_addrfor aarch64 target/arm: Segregate target-specific user-only fields target/arm: Store SVC immediate for user-only target/arm: Recognize linux faux BPKT target/arm: IntroduceEXCP_NWFPE
target/arm: Removebswap_code
I'm not sure about the SVC part, but I'm definitely not very enthusiastic about the BKPT and NWFPE pieces moving into target/arm. I prefer the existing split where (as far as reasonably feasible) target/arm is architectural stuff, and things that are matching behaviour of the Linux kernel for user-mode (nwfpe, odd bpkt insn, user-page helpers, etc) stay in linux-user.
thanks
-- PMM
Peter Maydell
AppliedQuoted 10 lines · Richard Henderson
Based-on: [email protected] ("[PATCH v11 00/21] target/arm: single-binary")
Version 2 here should probably be RFC. This time around, all instruction loading, and more decode, is done by translate. A new CPUARMState field is added for passing data to
EXCP_SWIandEXCP_NWFPE.
Quoted 7 lines
r~
Richard Henderson (7):
linux-user/arm: Restrictregpairs_alignedtarget/arm: Only defineaarch64_untagged_addrfor aarch64 target/arm: Segregate target-specific user-only fields
I've applied these first 3 patches to target-arm.next, as they're good cleanups independent of the bswap_code parts.
thanks
-- PMM
Quoted 16 lines · Peter Maydell
Quoted 13 lines · Richard Henderson
Based-on: [email protected] ("[PATCH v11 00/21] target/arm: single-binary")
Version 2 here should probably be RFC. This time around, all instruction loading, and more decode, is done by translate. A new CPUARMState field is added for passing data to
EXCP_SWIandEXCP_NWFPE.r~
Quoted 7 lines
Quoted 4 lines
Richard Henderson (7):
linux-user/arm: Restrictregpairs_alignedtarget/arm: Only defineaarch64_untagged_addrfor aarch64 target/arm: Segregate target-specific user-only fieldsI've applied these first 3 patches to target-arm.next, as they're good cleanups independent of the
bswap_codeparts.
...the target/arm patches don't build; I guess they clash with some of the single-binary work that's landed since:
../../target/arm/cpu.c:2422:15: error: attempt to use a poisoned identifier
2422 | #elif defined(TARGET_AARCH64)
../../target/arm/cpu.h:815:15: error: attempt to use a poisoned identifier
815 | #elif defined(TARGET_AARCH64)
| ^
So I've dropped those, and just kept the regpairs_aligned one.
thanks
-- PMM