bsd-user/arm/target_arch_cpu.h: Implement data faults

Update for the richer set of data faults that are now possible. Copied
largely from linux-user/arm/cpu_loop.c, with minor typo fixes.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Warner Losh 2022-01-08 16:26:55 -07:00
parent 5e02ded157
commit 67ccbe798f

View File

@ -39,8 +39,7 @@ static inline void target_cpu_init(CPUARMState *env,
static inline void target_cpu_loop(CPUARMState *env) static inline void target_cpu_loop(CPUARMState *env)
{ {
int trapnr; int trapnr, si_signo, si_code;
target_siginfo_t info;
unsigned int n; unsigned int n;
CPUState *cs = env_cpu(env); CPUState *cs = env_cpu(env);
@ -150,15 +149,41 @@ static inline void target_cpu_loop(CPUARMState *env)
/* just indicate that signals should be handled asap */ /* just indicate that signals should be handled asap */
break; break;
case EXCP_PREFETCH_ABORT: case EXCP_PREFETCH_ABORT:
/* See arm/arm/trap.c prefetch_abort_handler() */
case EXCP_DATA_ABORT: case EXCP_DATA_ABORT:
/* See arm/arm/trap.c data_abort_handler() */ /*
info.si_signo = TARGET_SIGSEGV; * See arm/arm/trap-v6.c prefetch_abort_handler() and
info.si_errno = 0; * data_abort_handler()
/* XXX: check env->error_code */ *
info.si_code = 0; * However, FreeBSD maps these to a generic value and then uses that
info.si_addr = env->exception.vaddress; * to maybe fault in pages in vm/vm_fault.c:vm_fault_trap(). I
queue_signal(env, info.si_signo, &info); * believe that the indirection maps the same as Linux, but haven't
* chased down every single possible indirection.
*/
/* For user-only we don't set TTBCR_EAE, so look at the FSR. */
switch (env->exception.fsr & 0x1f) {
case 0x1: /* Alignment */
si_signo = TARGET_SIGBUS;
si_code = TARGET_BUS_ADRALN;
break;
case 0x3: /* Access flag fault, level 1 */
case 0x6: /* Access flag fault, level 2 */
case 0x9: /* Domain fault, level 1 */
case 0xb: /* Domain fault, level 2 */
case 0xd: /* Permission fault, level 1 */
case 0xf: /* Permission fault, level 2 */
si_signo = TARGET_SIGSEGV;
si_code = TARGET_SEGV_ACCERR;
break;
case 0x5: /* Translation fault, level 1 */
case 0x7: /* Translation fault, level 2 */
si_signo = TARGET_SIGSEGV;
si_code = TARGET_SEGV_MAPERR;
break;
default:
g_assert_not_reached();
}
force_sig_fault(si_signo, si_code, env->exception.vaddress);
break; break;
case EXCP_DEBUG: case EXCP_DEBUG:
case EXCP_BKPT: case EXCP_BKPT: