ARM AArch64 Support for BSD
v2 cover ARM AArch64 Support for BSD
Patch 1: Previous patches 1 to 5, which were reviewed and acked, have been folded into this patch.Some changes that were suggested,
such as replacing "pstate &= ~PSTATE_C" with faster constructs like "env->CF = 0", have been addressed in patch 8.
Patch 2: In this patch, patches 6 to 11 have been folded. Changes such as using "ROUND_DOWN" for stack pointer calculation
and replacing "__uint128_t" with "Int128" in the following patch 8 have been addressed. Also, "CPUARMState" will be changed to "CPUArchState" in the upcoming version, and the issue with "-R" is being worked on separately.
Patch 3: Patches 12 to 16 were reviewed and folded. The function "get_second_rval" will be used upstream. Patch 4: Patches 17 to 19 were folded, and "__uint128_t" to "Int128" has been fixed in patch 8. Also, the suggestion to
use "const_le32()" has been deferred for now.
Patch 5: Previously patch 20, the FP suggestion is being deferred, but the patch is ready for review. Patch 6: Previously patch 21 has been reviewed.
Patch 7: Previously patch 22, same as patch 5.
Patch 8: Previously patch 23. For now, no changes, but issues of other patches have been addressed, such as updating
AArch64 code to use CF directly and changing FP data structures to use Int128 instead of __uint128_t.
Stacey Son (6):
bsd-user:Add CPU initialization and management functions bsd-user:Add AArch64 register handling and related functions bsd-user:Add ARM AArch64 signal handling support bsd-user:Add get_mcontext function for ARM AArch64 bsd-user:Add set_mcontext function for ARM AArch64 bsd-user:Add AArch64 improvements and signal handling functions
Warner Losh (2):
bsd-user:Add ARM AArch64 support and capabilities bsd-user:Add setup_sigframe_arch function for ARM AArch64
bsd-user/aarch64/signal.c | 137 +++++++++++++++++ bsd-user/aarch64/target_arch.h | 28 ++++ bsd-user/aarch64/target_arch_cpu.c | 31 ++++ bsd-user/aarch64/target_arch_cpu.h | 188 ++++++++++++++++++++++++ bsd-user/aarch64/target_arch_elf.h | 165 +++++++++++++++++++++ bsd-user/aarch64/target_arch_reg.h | 56 +++++++ bsd-user/aarch64/target_arch_signal.h | 80 ++++++++++ bsd-user/aarch64/target_arch_sigtramp.h | 48 ++++++ bsd-user/aarch64/target_arch_sysarch.h | 42 ++++++ bsd-user/aarch64/target_arch_thread.h | 61 ++++++++ bsd-user/aarch64/target_arch_vmparam.h | 74 ++++++++++ bsd-user/aarch64/target_syscall.h | 51 +++++++ bsd-user/qemu.h | 3 + 13 files changed, 964 insertions(+) create mode 100644 bsd-user/aarch64/signal.c create mode 100644 bsd-user/aarch64/target_arch.h create mode 100644 bsd-user/aarch64/target_arch_cpu.c create mode 100644 bsd-user/aarch64/target_arch_cpu.h create mode 100644 bsd-user/aarch64/target_arch_elf.h create mode 100644 bsd-user/aarch64/target_arch_reg.h create mode 100644 bsd-user/aarch64/target_arch_signal.h create mode 100644 bsd-user/aarch64/target_arch_sigtramp.h create mode 100644 bsd-user/aarch64/target_arch_sysarch.h create mode 100644 bsd-user/aarch64/target_arch_thread.h create mode 100644 bsd-user/aarch64/target_arch_vmparam.h create mode 100644 bsd-user/aarch64/target_syscall.h
Signature · 1 line
2.34.1
PATCH v2 1/8 bsd-user:Add CPU initialization and management functions
From: Stacey Son <[email protected]>
Added function to initialize ARM CPU and check if it supports 64-bit mode. Implemented CPU loop function to handle exceptions and emulate execution of instructions. Added function to clone CPU state to create a new thread.
Included AArch64 specific CPU functions for bsd-user to set and receive thread-local-storage value from the tpidr_el0 register.
Introduced structure for storing CPU register states for BSD-USER.
--- bsd-user/aarch64/target_arch_cpu.c | 31 +++++ bsd-user/aarch64/target_arch_cpu.h | 191 +++++++++++++++++++++++++++++ bsd-user/aarch64/target_syscall.h | 51 ++++++++ 3 files changed, 273 insertions(+) create mode 100644 bsd-user/aarch64/target_arch_cpu.c create mode 100644 bsd-user/aarch64/target_arch_cpu.h create mode 100644 bsd-user/aarch64/target_syscall.h
bsd-user/aarch64/target_arch_cpu.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* ARM AArch64 specific CPU for bsd-user +* +* Copyright (c) 2015 Stacey Son +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "target_arch.h" + +/* See cpu_set_user_tls() in arm64/arm64/vm_machdep.c */ +void target_cpu_set_tls (CPUARMState *env,target_ulong newtls) +{ + env->cp15.tpidr_el[0 ] = newtls; +} + +target_ulong target_cpu_get_tls (CPUARMState *env) +{ +return env->cp15.tpidr_el[0 ]; +}
bsd-user/aarch64/target_arch_cpu.h new file +191 -0
191 lines not on this page · raw message
bsd-user/aarch64/target_syscall.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/8 bsd-user:Add AArch64 register handling and related functions
In reply to Ajeet SinghFrom: Stacey Son <[email protected]>
Added header file for managing CPU register states in FreeBSD user mode.
Introduced prototypes for setting and getting thread-local storage (TLS).
Implemented AArch64 sysarch() system call emulation and a printing function.
Added function for setting up thread upcall to add thread support to BSD-USER. Initialized thread's register state during thread setup.
Updated ARM AArch64 VM parameter definitions for bsd-user, including address spaces for FreeBSD/arm64 and a function for getting the stack pointer from CPU and setting a return value.
--- bsd-user/aarch64/target_arch.h | 28 +++++++++++ bsd-user/aarch64/target_arch_reg.h | 56 +++++++++++++++++++++ bsd-user/aarch64/target_arch_sysarch.h | 42 ++++++++++++++++ bsd-user/aarch64/target_arch_thread.h | 61 +++++++++++++++++++++++ bsd-user/aarch64/target_arch_vmparam.h | 68 ++++++++++++++++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 bsd-user/aarch64/target_arch.h create mode 100644 bsd-user/aarch64/target_arch_reg.h create mode 100644 bsd-user/aarch64/target_arch_sysarch.h create mode 100644 bsd-user/aarch64/target_arch_thread.h create mode 100644 bsd-user/aarch64/target_arch_vmparam.h
bsd-user/aarch64/target_arch.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* ARM AArch64 specific prototypes for bsd-user +* +* Copyright (c) 2015 Stacey D. Son <sson at FreeBSD> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TARGET_ARCH_H +#define TARGET_ARCH_H + +#include "qemu.h" + +void target_cpu_set_tls (CPUARMState *env,target_ulong newtls); +target_ulong target_cpu_get_tls (CPUARMState *env); + +#endif /* TARGET_ARCH_H */
bsd-user/aarch64/target_arch_reg.h new file +56 -0
56 lines not on this page · raw message
bsd-user/aarch64/target_arch_sysarch.h new file +42 -0
42 lines not on this page · raw message
bsd-user/aarch64/target_arch_thread.h new file +61 -0
61 lines not on this page · raw message
bsd-user/aarch64/target_arch_vmparam.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 3/8 bsd-user:Add ARM AArch64 support and capabilities
In reply to Ajeet SinghFrom: Warner Losh <[email protected]>
Added function to access rval2 by accessing the x1 register.
Defined ARM AArch64 ELF parameters including mmap and dynamic load addresses.
Introduced extensive hardware capability definitions and macros for retrieving hardware capability (hwcap) flags. Implemented function to retrieve ARM AArch64 hardware capabilities using the GET_FEATURE_ID macro. Added function to retrieve extended ARM AArch64 hardware capability flags.
--- bsd-user/aarch64/target_arch_elf.h | 165 +++++++++++++++++++++++++ bsd-user/aarch64/target_arch_vmparam.h | 6 + 2 files changed, 171 insertions(+) create mode 100644 bsd-user/aarch64/target_arch_elf.h
bsd-user/aarch64/target_arch_elf.h new file +165 -0
@@ -0,0 +1,165 @@ +/* +* ARM AArch64 ELF definitions for bsd-user +* +* Copyright (c) 2015 Stacey D. Son +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef TARGET_ARCH_ELF_H +#define TARGET_ARCH_ELF_H + +#include "target/arm/cpu-features.h" + +#define ELF_START_MMAP 0x80000000 +#define ELF_ET_DYN_LOAD_ADDR 0x100000 + +#define elf_check_arch (x) ((x) == EM_AARCH64) + +#define ELF_CLASS ELFCLASS64 +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_AARCH64 + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +enum { +ARM_HWCAP_A64_FP =1 <<0 , +ARM_HWCAP_A64_ASIMD =1 <<1 , +ARM_HWCAP_A64_EVTSTRM =1 <<2 , +ARM_HWCAP_A64_AES =1 <<3 , +ARM_HWCAP_A64_PMULL =1 <<4 , +ARM_HWCAP_A64_SHA1 =1 <<5 , +ARM_HWCAP_A64_SHA2 =1 <<6 , +ARM_HWCAP_A64_CRC32 =1 <<7 , +ARM_HWCAP_A64_ATOMICS =1 <<8 , +ARM_HWCAP_A64_FPHP =1 <<9 , +ARM_HWCAP_A64_ASIMDHP =1 <<10 , +ARM_HWCAP_A64_CPUID =1 <<11 , +ARM_HWCAP_A64_ASIMDRDM =1 <<12 , +ARM_HWCAP_A64_JSCVT =1 <<13 , +ARM_HWCAP_A64_FCMA =1 <<14 , +ARM_HWCAP_A64_LRCPC =1 <<15 , +ARM_HWCAP_A64_DCPOP =1 <<16 , +ARM_HWCAP_A64_SHA3 =1 <<17 , +ARM_HWCAP_A64_SM3 =1 <<18 , +ARM_HWCAP_A64_SM4 =1 <<19 , +ARM_HWCAP_A64_ASIMDDP =1 <<20 , +ARM_HWCAP_A64_SHA512 =1 <<21 , +ARM_HWCAP_A64_SVE =1 <<22 , +ARM_HWCAP_A64_ASIMDFHM =1 <<23 , +ARM_HWCAP_A64_DIT =1 <<24 , +ARM_HWCAP_A64_USCAT =1 <<25 , +ARM_HWCAP_A64_ILRCPC =1 <<26 , +ARM_HWCAP_A64_FLAGM =1 <<27 , +ARM_HWCAP_A64_SSBS =1 <<28 , +ARM_HWCAP_A64_SB =1 <<29 , +ARM_HWCAP_A64_PACA =1 <<30 , +ARM_HWCAP_A64_PACG =1UL <<31 , + +ARM_HWCAP2_A64_DCPODP =1 <<0 , +ARM_HWCAP2_A64_SVE2 =1 <<1 , +ARM_HWCAP2_A64_SVEAES =1 <<2 , +ARM_HWCAP2_A64_SVEPMULL =1 <<3 , +ARM_HWCAP2_A64_SVEBITPERM =1 <<4 , +ARM_HWCAP2_A64_SVESHA3 =1 <<5 , +ARM_HWCAP2_A64_SVESM4 =1 <<6 , +ARM_HWCAP2_A64_FLAGM2 =1 <<7 , +ARM_HWCAP2_A64_FRINT =1 <<8 , +ARM_HWCAP2_A64_SVEI8MM =1 <<9 , +ARM_HWCAP2_A64_SVEF32MM =1 <<10 , +ARM_HWCAP2_A64_SVEF64MM =1 <<11 , +ARM_HWCAP2_A64_SVEBF16 =1 <<12 , +ARM_HWCAP2_A64_I8MM =1 <<13 , +ARM_HWCAP2_A64_BF16 =1 <<14 , +ARM_HWCAP2_A64_DGH =1 <<15 , +ARM_HWCAP2_A64_RNG =1 <<16 , +ARM_HWCAP2_A64_BTI =1 <<17 , +ARM_HWCAP2_A64_MTE =1 <<18 , +}; + +#define ELF_HWCAP get_elf_hwcap() +#define ELF_HWCAP2 get_elf_hwcap2() + +#define GET_FEATURE_ID (feat, hwcap) \ + do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) + +static uint32_t get_elf_hwcap (void ) +{ +ARMCPU *cpu =ARM_CPU (thread_cpu); +uint32_t hwcaps =0 ; + + hwcaps |=ARM_HWCAP_A64_FP ; + hwcaps |=ARM_HWCAP_A64_ASIMD ; + hwcaps |=ARM_HWCAP_A64_CPUID ; + +/* probe for the extra features */ + +GET_FEATURE_ID (aa64_aes,ARM_HWCAP_A64_AES ); +GET_FEATURE_ID (aa64_pmull,ARM_HWCAP_A64_PMULL ); +GET_FEATURE_ID (aa64_sha1,ARM_HWCAP_A64_SHA1 ); +GET_FEATURE_ID (aa64_sha256,ARM_HWCAP_A64_SHA2 ); +GET_FEATURE_ID (aa64_sha512,ARM_HWCAP_A64_SHA512 ); +GET_FEATURE_ID (aa64_crc32,ARM_HWCAP_A64_CRC32 ); +GET_FEATURE_ID (aa64_sha3,ARM_HWCAP_A64_SHA3 ); +GET_FEATURE_ID (aa64_sm3,ARM_HWCAP_A64_SM3 ); +GET_FEATURE_ID (aa64_sm4,ARM_HWCAP_A64_SM4 ); +GET_FEATURE_ID (aa64_fp16,ARM_HWCAP_A64_FPHP |ARM_HWCAP_A64_ASIMDHP ); +GET_FEATURE_ID (aa64_atomics,ARM_HWCAP_A64_ATOMICS ); +GET_FEATURE_ID (aa64_rdm,ARM_HWCAP_A64_ASIMDRDM ); +GET_FEATURE_ID (aa64_dp,ARM_HWCAP_A64_ASIMDDP ); +GET_FEATURE_ID (aa64_fcma,ARM_HWCAP_A64_FCMA ); +GET_FEATURE_ID (aa64_sve,ARM_HWCAP_A64_SVE ); +GET_FEATURE_ID (aa64_pauth,ARM_HWCAP_A64_PACA |ARM_HWCAP_A64_PACG ); +GET_FEATURE_ID (aa64_fhm,ARM_HWCAP_A64_ASIMDFHM ); +GET_FEATURE_ID (aa64_jscvt,ARM_HWCAP_A64_JSCVT ); +GET_FEATURE_ID (aa64_sb,ARM_HWCAP_A64_SB ); +GET_FEATURE_ID (aa64_condm_4,ARM_HWCAP_A64_FLAGM ); +GET_FEATURE_ID (aa64_dcpop,ARM_HWCAP_A64_DCPOP ); +GET_FEATURE_ID (aa64_rcpc_8_3,ARM_HWCAP_A64_LRCPC ); +GET_FEATURE_ID (aa64_rcpc_8_4,ARM_HWCAP_A64_ILRCPC ); + +return hwcaps; +} + +static uint32_t get_elf_hwcap2 (void ) +{ +ARMCPU *cpu =ARM_CPU (thread_cpu); +uint32_t hwcaps =0 ; + +GET_FEATURE_ID (aa64_dcpodp,ARM_HWCAP2_A64_DCPODP ); +GET_FEATURE_ID (aa64_sve2,ARM_HWCAP2_A64_SVE2 ); +GET_FEATURE_ID (aa64_sve2_aes,ARM_HWCAP2_A64_SVEAES ); +GET_FEATURE_ID (aa64_sve2_pmull128,ARM_HWCAP2_A64_SVEPMULL ); +GET_FEATURE_ID (aa64_sve2_bitperm,ARM_HWCAP2_A64_SVEBITPERM ); +GET_FEATURE_ID (aa64_sve2_sha3,ARM_HWCAP2_A64_SVESHA3 ); +GET_FEATURE_ID (aa64_sve2_sm4,ARM_HWCAP2_A64_SVESM4 ); +GET_FEATURE_ID (aa64_condm_5,ARM_HWCAP2_A64_FLAGM2 ); +GET_FEATURE_ID (aa64_frint,ARM_HWCAP2_A64_FRINT ); +GET_FEATURE_ID (aa64_sve_i8mm,ARM_HWCAP2_A64_SVEI8MM ); +GET_FEATURE_ID (aa64_sve_f32mm,ARM_HWCAP2_A64_SVEF32MM ); +GET_FEATURE_ID (aa64_sve_f64mm,ARM_HWCAP2_A64_SVEF64MM ); +GET_FEATURE_ID (aa64_sve_bf16,ARM_HWCAP2_A64_SVEBF16 ); +GET_FEATURE_ID (aa64_i8mm,ARM_HWCAP2_A64_I8MM ); +GET_FEATURE_ID (aa64_bf16,ARM_HWCAP2_A64_BF16 ); +GET_FEATURE_ID (aa64_rndr,ARM_HWCAP2_A64_RNG ); +GET_FEATURE_ID (aa64_bti,ARM_HWCAP2_A64_BTI ); +GET_FEATURE_ID (aa64_mte,ARM_HWCAP2_A64_MTE ); + +return hwcaps; +} + +#undef GET_FEATURE_ID + +#endif /* TARGET_ARCH_ELF_H */
bsd-user/aarch64/target_arch_vmparam.h +6 -0
@@ -65,4 +65,10 @@ static inline void set_second_rval(CPUARMState *state, abi_ulong retval2) { state->xregs[1 ] = retval2;/* XXX not really used on 64-bit arch */ } + +static inline abi_ulong get_second_rval (CPUARMState *state) +{ +return state->xregs[1 ]; +} +#endif /* TARGET_ARCH_VMPARAM_H */
Signature · 1 line
2.34.1
PATCH v2 4/8 bsd-user:Add ARM AArch64 signal handling support
In reply to Ajeet SinghFrom: Stacey Son <[email protected]>
Added sigcode setup function for signal trampoline which initializes a sequence of instructions to handle signal returns and exits, copying this code to the target offset.
Defined ARM AArch64 specific signal definitions including register indices and sizes,
and introduced structures to represent general purpose registers, floating point registers, and machine context. Added function to set up signal handler arguments, populating register values in CPUARMState based on the provided signal, signal frame, signal action, and frame address.
--- bsd-user/aarch64/signal.c | 53 ++++++++++++++++ bsd-user/aarch64/target_arch_signal.h | 80 +++++++++++++++++++++++++ bsd-user/aarch64/target_arch_sigtramp.h | 48 +++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 bsd-user/aarch64/signal.c create mode 100644 bsd-user/aarch64/target_arch_signal.h create mode 100644 bsd-user/aarch64/target_arch_sigtramp.h
bsd-user/aarch64/signal.c new file +53 -0
@@ -0,0 +1,53 @@ +/* +* ARM AArch64 specific signal definitions for bsd-user +* +* Copyright (c) 2015 Stacey D. Son <sson at FreeBSD> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" + +#include "qemu.h" + +/* +* Compare to sendsig() in sys/arm64/arm64/machdep.c +* Assumes that target stack frame memory is locked. +*/ +abi_long set_sigtramp_args (CPUARMState *regs,int sig, +struct target_sigframe *frame, +abi_ulong frame_addr, +struct target_sigaction *ka) +{ +/* +* Arguments to signal handler: +* x0 = signal number +* x1 = siginfo pointer +* x2 = ucontext pointer +* pc/elr = signal handler pointer +* sp = sigframe struct pointer +* lr = sigtramp at base of user stack +*/ + + regs->xregs[0 ] = sig; + regs->xregs[1 ] = frame_addr + + offsetof(struct target_sigframe , sf_si); + regs->xregs[2 ] = frame_addr + + offsetof(struct target_sigframe , sf_uc); + + regs->pc = ka->_sa_handler; + regs->xregs[TARGET_REG_SP ] = frame_addr; + regs->xregs[TARGET_REG_LR ] =TARGET_PS_STRINGS -TARGET_SZSIGCODE ; + +return 0 ; +}
bsd-user/aarch64/target_arch_signal.h new file +80 -0
80 lines not on this page · raw message
bsd-user/aarch64/target_arch_sigtramp.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 5/8 bsd-user:Add get_mcontext function for ARM AArch64
In reply to Ajeet SinghFrom: Stacey Son <[email protected]>
function to retrieve machine context,it populates the provided target_mcontext_t structure with information from the CPUARMState registers.
--- bsd-user/aarch64/signal.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
bsd-user/aarch64/signal.c +30 -0
@@ -51,3 +51,33 @@ abi_long set_sigtramp_args(CPUARMState *regs, int sig,return 0 ; } + +/* +* Compare to get_mcontext() in arm64/arm64/machdep.c +* Assumes that the memory is locked if mcp points to user memory. +*/ +abi_long get_mcontext (CPUARMState *regs,target_mcontext_t *mcp,int flags) +{ +int err =0 , i; +uint64_t *gr = mcp->mc_gpregs.gp_x; + + mcp->mc_gpregs.gp_spsr =pstate_read (regs); +if (flags &TARGET_MC_GET_CLEAR_RET ) { + gr[0 ] =0UL ; + mcp->mc_gpregs.gp_spsr &= ~CPSR_C ; + }else { + gr[0 ] =tswap64 (regs->xregs[0 ]); + } + +for (i =1 ; i <30 ; i++) { + gr[i] =tswap64 (regs->xregs[i]); + } + + mcp->mc_gpregs.gp_sp =tswap64 (regs->xregs[TARGET_REG_SP ]); + mcp->mc_gpregs.gp_lr =tswap64 (regs->xregs[TARGET_REG_LR ]); + mcp->mc_gpregs.gp_elr =tswap64 (regs->pc); + +/* XXX FP? */ + +return err; +}
Signature · 1 line
2.34.1
Re: [PATCH v2 5/8] bsd-user:Add get_mcontext function for ARM AArch64
Quoted 6 lines · Ajeet Singh
From: Stacey Son<[email protected]>
function to retrieve machine context,it populates the provided
target_mcontext_tstructure with information from the CPUARMState registers.
Quoted 6 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Ajeet Singh<[email protected]>Co-authored-by Kyle Evans<[email protected]>--- bsd-user/aarch64/signal.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
r~
PATCH v2 6/8 bsd-user:Add setup_sigframe_arch function for ARM AArch64
In reply to Ajeet SinghFrom: Warner Losh <[email protected]>
The function utilizes the get_mcontext function to retrieve the machine context for the current CPUARMState
--- bsd-user/aarch64/signal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
bsd-user/aarch64/signal.c +14 -0
@@ -81,3 +81,17 @@ abi_long get_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int flags)return err; } + +/* +* Compare to arm64/arm64/exec_machdep.c sendsig() +* Assumes that the memory is locked if frame points to user memory. +*/ +abi_long setup_sigframe_arch (CPUARMState *env,abi_ulong frame_addr, +struct target_sigframe *frame,int flags) +{ +target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + +get_mcontext (env, mcp, flags); +return 0 ; +} +
Signature · 1 line
2.34.1
PATCH v2 7/8 bsd-user:Add set_mcontext function for ARM AArch64
In reply to Ajeet SinghFrom: Stacey Son <[email protected]>
The function copies register values from the provided target_mcontext_t structure to the CPUARMState registers.
Note:FP is unfinished upstream but will be a separate commit coming soon.
--- bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
bsd-user/aarch64/signal.c +22 -0
@@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr,return 0 ; } +/* +* Compare to set_mcontext() in arm64/arm64/machdep.c +* Assumes that the memory is locked if frame points to user memory. +*/ +abi_long set_mcontext (CPUARMState *regs,target_mcontext_t *mcp,int srflag) +{ +int err =0 , i; +const uint64_t *gr = mcp->mc_gpregs.gp_x; + +for (i =0 ; i <30 ; i++) { + regs->xregs[i] =tswap64 (gr[i]); + } + + regs->xregs[TARGET_REG_SP ] =tswap64 (mcp->mc_gpregs.gp_sp); + regs->xregs[TARGET_REG_LR ] =tswap64 (mcp->mc_gpregs.gp_lr); + regs->pc = mcp->mc_gpregs.gp_elr; +pstate_write (regs, mcp->mc_gpregs.gp_spsr); + +/* XXX FP? */ + +return err; +}
Signature · 1 line
2.34.1
Re: [PATCH v2 7/8] bsd-user:Add set_mcontext function for ARM AArch64
Quoted 11 lines · Ajeet Singh
From: Stacey Son<[email protected]>
The function copies register values from the provided
target_mcontext_tstructure to the CPUARMState registers.
Note:FP is unfinished upstream but will be a separate commit coming soon.Signed-off-by Stacey Son<[email protected]>Signed-off-by Ajeet Singh<[email protected]>--- bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
r~
PATCH v2 8/8 bsd-user:Add AArch64 improvements and signal handling functions
In reply to Ajeet SinghFrom: Stacey Son <[email protected]>
Added get_ucontext_sigreturn function to check processor state ensuring current execution mode is EL0 and no flags indicating interrupts or exceptions are set.
Updated AArch64 code to use CF directly without reading/writing the entire processor state, improving efficiency. Changed FP data structures to use Int128 instead of __uint128_t, leveraging QEMU's generic mechanism for referencing this type.
--- bsd-user/aarch64/signal.c | 20 +++++++++++++++++++- bsd-user/aarch64/target_arch_cpu.h | 7 ++----- bsd-user/aarch64/target_arch_reg.h | 2 +- bsd-user/aarch64/target_arch_signal.h | 2 +- bsd-user/qemu.h | 3 +++ 5 files changed, 26 insertions(+), 8 deletions(-)
bsd-user/aarch64/signal.c +19 -1
@@ -21,7 +21,7 @@#include "qemu.h" /* -* Compare to sendsig() in sys/arm64/arm64/machdep.c +* Compare to sendsig() in sys/arm64/arm64/exec_machdep.c * Assumes that target stack frame memory is locked. */ abi_long set_sigtramp_args(CPUARMState *regs, int sig,
@@ -117,3 +117,21 @@ abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag)return err; } + +/* Compare to sys_sigreturn() in arm64/arm64/machdep.c */ +abi_long get_ucontext_sigreturn (CPUARMState *regs,abi_ulong target_sf, +abi_ulong *target_uc) +{ +uint32_t pstate =pstate_read (regs); + + *target_uc =0 ; + +if ((pstate &PSTATE_M ) != PSTATE_MODE_EL0t || + (pstate & (PSTATE_F |PSTATE_I |PSTATE_A |PSTATE_D )) !=0 ) { +return -TARGET_EINVAL ; + } + + *target_uc = target_sf; + +return 0 ; +}
bsd-user/aarch64/target_arch_cpu.h +2 -5
@@ -47,7 +47,6 @@ static inline void target_cpu_loop(CPUARMState *env)CPUState *cs =env_cpu (env);int trapnr, ec, fsc, si_code, si_signo;uint64_t code, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; -uint32_t pstate;abi_long ret;for (;;) {
@@ -87,18 +86,16 @@ static inline void target_cpu_loop(CPUARMState *env)* The carry bit is cleared for no error; set for error. * See arm64/arm64/vm_machdep.c cpu_set_syscall_retval() */ - pstate =pstate_read (env);if (ret >=0 ) { - pstate &= ~PSTATE_C ; + env->CF =0 ; env->xregs[0 ] = ret; }else if (ret == -TARGET_ERESTART ) { env->pc -=4 ;break ; }else if (ret != -TARGET_EJUSTRETURN ) { - pstate |=PSTATE_C ; + env->CF =1 ; env->xregs[0 ] = -ret; } -pstate_write (env, pstate);break ;case EXCP_INTERRUPT :
bsd-user/aarch64/target_arch_reg.h +1 -1
@@ -31,7 +31,7 @@ typedef struct target_reg { } target_reg_t;typedef struct target_fpreg { -__uint128_t fp_q[32 ]; +Int128 fp_q[32 ];uint32_t fp_sr;uint32_t fp_cr; }target_fpreg_t ;
bsd-user/aarch64/target_arch_signal.h +1 -1
@@ -49,7 +49,7 @@ struct target_gpregs { };struct target_fpregs { -__uint128_t fp_q[32 ]; +Int128 fp_q[32 ];uint32_t fp_sr;uint32_t fp_cr;uint32_t fp_flags;
bsd-user/qemu.h +3 -0
@@ -17,6 +17,9 @@#ifndef QEMU_H #define QEMU_H +#include <sys/param.h> + +#include "qemu/int128.h" #include "cpu.h" #include "qemu/units.h" #include "exec/cpu_ldst.h"
Signature · 1 line
2.34.1
Re: [PATCH v2 8/8] bsd-user:Add AArch64 improvements and signal handling functions
Quoted 10 lines · Ajeet Singh
From: Stacey Son<[email protected]>
Added
get_ucontext_sigreturnfunction to check processor state ensuring current execution mode is EL0 and no flags indicating interrupts or exceptions are set.
Updated AArch64 code to use CF directly without reading/writing the entire processor state, improving efficiency. Changed FP data structures to use Int128 instead of__uint128_t, leveraging QEMU's generic mechanism for referencing this type.Signed-off-by Stacey Son<[email protected]>Signed-off-by Ajeet Singh<[email protected]>Signed-off-by Warner Losh<[email protected]>
Quoted 7 lines
--- bsd-user/aarch64/signal.c | 20 +++++++++++++++++++- bsd-user/aarch64/target_arch_cpu.h | 7 ++----- bsd-user/aarch64/target_arch_reg.h | 2 +- bsd-user/aarch64/target_arch_signal.h | 2 +- bsd-user/qemu.h | 3 +++ 5 files changed, 26 insertions(+), 8 deletions(-)
r~
Queued for my 9.1 pull request...
Thanks! Sorry for the delay...
Warner
Quoted 67 lines · Ajeet Singh
Patch 1: Previous patches 1 to 5, which were reviewed and acked, have been folded into this patch.Some changes that were suggested,
such as replacing "pstate &= ~PSTATE_C" with faster constructs
like "env->CF= 0", have been addressed in patch 8.
Patch 2: In this patch, patches 6 to 11 have been folded. Changes such as using "ROUND_DOWN" for stack pointer calculation
and replacing "__uint128_t" with "Int128" in the following patch
8 have been addressed. Also, "CPUARMState" will be
changed to "CPUArchState" in the upcoming version, and the issue
with "-R" is being worked on separately.
Patch 3: Patches 12 to 16 were reviewed and folded. The function "get_second_rval" will be used upstream.
Patch 4: Patches 17 to 19 were folded, and "__uint128_t" to "Int128" has been fixed in patch 8. Also, the suggestion to
use "const_le32()" has been deferred for now.
Patch 5: Previously patch 20, the FP suggestion is being deferred, but the patch is ready for review.
Patch 6: Previously patch 21 has been reviewed.
Patch 7: Previously patch 22, same as patch 5.
Patch 8: Previously patch 23. For now, no changes, but issues of other patches have been addressed, such as updating
AArch64 code to use CF directly and changing FP data structures
to use Int128 instead of__uint128_t.Stacey Son (6):
bsd-user:Add CPU initialization and management functions bsd-user:Add AArch64 register handling and related functions bsd-user:Add ARM AArch64 signal handling support bsd-user:Addget_mcontextfunction for ARM AArch64 bsd-user:Addset_mcontextfunction for ARM AArch64 bsd-user:Add AArch64 improvements and signal handling functionsWarner Losh (2):
bsd-user:Add ARM AArch64 support and capabilities bsd-user:Addsetup_sigframe_archfunction for ARM AArch64bsd-user/aarch64/signal.c | 137 +++++++++++++++++ bsd-user/aarch64/target_arch.h | 28 ++++ bsd-user/aarch64/target_arch_cpu.c | 31 ++++ bsd-user/aarch64/target_arch_cpu.h | 188 ++++++++++++++++++++++++ bsd-user/aarch64/target_arch_elf.h | 165 +++++++++++++++++++++ bsd-user/aarch64/target_arch_reg.h | 56 +++++++ bsd-user/aarch64/target_arch_signal.h | 80 ++++++++++ bsd-user/aarch64/target_arch_sigtramp.h | 48 ++++++ bsd-user/aarch64/target_arch_sysarch.h | 42 ++++++ bsd-user/aarch64/target_arch_thread.h | 61 ++++++++ bsd-user/aarch64/target_arch_vmparam.h | 74 ++++++++++ bsd-user/aarch64/target_syscall.h | 51 +++++++ bsd-user/qemu.h | 3 + 13 files changed, 964 insertions(+) create mode 100644 bsd-user/aarch64/signal.c create mode 100644 bsd-user/aarch64/target_arch.h create mode 100644 bsd-user/aarch64/target_arch_cpu.c create mode 100644 bsd-user/aarch64/target_arch_cpu.h create mode 100644 bsd-user/aarch64/target_arch_elf.h create mode 100644 bsd-user/aarch64/target_arch_reg.h create mode 100644 bsd-user/aarch64/target_arch_signal.h create mode 100644 bsd-user/aarch64/target_arch_sigtramp.h create mode 100644 bsd-user/aarch64/target_arch_sysarch.h create mode 100644 bsd-user/aarch64/target_arch_thread.h create mode 100644 bsd-user/aarch64/target_arch_vmparam.h create mode 100644 bsd-user/aarch64/target_syscall.h--
2.34.1