2018-04-11 20:56:33 +02:00
|
|
|
/*
|
|
|
|
* qemu user cpu loop
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu.h"
|
2021-09-08 17:44:03 +02:00
|
|
|
#include "user-internals.h"
|
2018-04-11 20:56:33 +02:00
|
|
|
#include "cpu_loop-common.h"
|
2021-09-08 17:43:59 +02:00
|
|
|
#include "signal-common.h"
|
2018-04-11 20:56:33 +02:00
|
|
|
|
2018-04-11 20:56:46 +02:00
|
|
|
void cpu_loop(CPUAlphaState *env)
|
|
|
|
{
|
2019-03-23 01:26:58 +01:00
|
|
|
CPUState *cs = env_cpu(env);
|
2022-01-07 22:32:22 +01:00
|
|
|
int trapnr, si_code;
|
2018-04-11 20:56:46 +02:00
|
|
|
abi_long sysret;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
bool arch_interrupt = true;
|
|
|
|
|
|
|
|
cpu_exec_start(cs);
|
|
|
|
trapnr = cpu_exec(cs);
|
|
|
|
cpu_exec_end(cs);
|
|
|
|
process_queued_cpu_work(cs);
|
|
|
|
|
|
|
|
switch (trapnr) {
|
|
|
|
case EXCP_RESET:
|
|
|
|
fprintf(stderr, "Reset requested. Exit\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
case EXCP_MCHK:
|
|
|
|
fprintf(stderr, "Machine check exception. Exit\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
case EXCP_SMP_INTERRUPT:
|
|
|
|
case EXCP_CLK_INTERRUPT:
|
|
|
|
case EXCP_DEV_INTERRUPT:
|
|
|
|
fprintf(stderr, "External interrupt. Exit\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
case EXCP_OPCDEC:
|
|
|
|
do_sigill:
|
2022-01-07 22:32:22 +01:00
|
|
|
force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case EXCP_ARITH:
|
2022-01-07 22:32:22 +01:00
|
|
|
force_sig_fault(TARGET_SIGFPE, TARGET_FPE_FLTINV, env->pc);
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case EXCP_FEN:
|
|
|
|
/* No-op. Linux simply re-enables the FPU. */
|
|
|
|
break;
|
|
|
|
case EXCP_CALL_PAL:
|
|
|
|
switch (env->error_code) {
|
|
|
|
case 0x80:
|
|
|
|
/* BPT */
|
2022-01-07 22:32:22 +01:00
|
|
|
goto do_sigtrap_brkpt;
|
2018-04-11 20:56:46 +02:00
|
|
|
case 0x81:
|
|
|
|
/* BUGCHK */
|
2022-01-07 22:32:22 +01:00
|
|
|
goto do_sigtrap_unk;
|
2018-04-11 20:56:46 +02:00
|
|
|
case 0x83:
|
|
|
|
/* CALLSYS */
|
|
|
|
trapnr = env->ir[IR_V0];
|
|
|
|
sysret = do_syscall(env, trapnr,
|
|
|
|
env->ir[IR_A0], env->ir[IR_A1],
|
|
|
|
env->ir[IR_A2], env->ir[IR_A3],
|
|
|
|
env->ir[IR_A4], env->ir[IR_A5],
|
|
|
|
0, 0);
|
2021-11-22 19:47:33 +01:00
|
|
|
if (sysret == -QEMU_ERESTARTSYS) {
|
2018-04-11 20:56:46 +02:00
|
|
|
env->pc -= 4;
|
|
|
|
break;
|
|
|
|
}
|
2021-11-17 14:14:52 +01:00
|
|
|
if (sysret == -QEMU_ESIGRETURN) {
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Syscall writes 0 to V0 to bypass error check, similar
|
|
|
|
to how this is handled internal to Linux kernel.
|
|
|
|
(Ab)use trapnr temporarily as boolean indicating error. */
|
|
|
|
trapnr = (env->ir[IR_V0] != 0 && sysret < 0);
|
|
|
|
env->ir[IR_V0] = (trapnr ? -sysret : sysret);
|
|
|
|
env->ir[IR_A3] = trapnr;
|
|
|
|
break;
|
|
|
|
case 0x86:
|
|
|
|
/* IMB */
|
|
|
|
/* ??? We can probably elide the code using page_unprotect
|
|
|
|
that is checking for self-modifying code. Instead we
|
|
|
|
could simply call tb_flush here. Until we work out the
|
|
|
|
changes required to turn off the extra write protection,
|
|
|
|
this can be a no-op. */
|
|
|
|
break;
|
|
|
|
case 0x9E:
|
|
|
|
/* RDUNIQUE */
|
|
|
|
/* Handled in the translator for usermode. */
|
|
|
|
abort();
|
|
|
|
case 0x9F:
|
|
|
|
/* WRUNIQUE */
|
|
|
|
/* Handled in the translator for usermode. */
|
|
|
|
abort();
|
|
|
|
case 0xAA:
|
|
|
|
/* GENTRAP */
|
|
|
|
switch (env->ir[IR_A0]) {
|
|
|
|
case TARGET_GEN_INTOVF:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_INTOVF;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_INTDIV:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_INTDIV;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_FLTOVF:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_FLTOVF;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_FLTUND:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_FLTUND;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_FLTINV:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_FLTINV;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_FLTINE:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_FLTRES;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case TARGET_GEN_ROPRAND:
|
2022-01-07 22:32:22 +01:00
|
|
|
si_code = TARGET_FPE_FLTUNK;
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-07 22:32:22 +01:00
|
|
|
goto do_sigtrap_unk;
|
2018-04-11 20:56:46 +02:00
|
|
|
}
|
2022-01-07 22:32:22 +01:00
|
|
|
force_sig_fault(TARGET_SIGFPE, si_code, env->pc);
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto do_sigill;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXCP_DEBUG:
|
2022-01-07 22:32:22 +01:00
|
|
|
do_sigtrap_brkpt:
|
|
|
|
force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
|
|
|
|
break;
|
|
|
|
do_sigtrap_unk:
|
|
|
|
force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_UNK, env->pc);
|
2018-04-11 20:56:46 +02:00
|
|
|
break;
|
|
|
|
case EXCP_INTERRUPT:
|
|
|
|
/* Just indicate that signals should be handled asap. */
|
|
|
|
break;
|
|
|
|
case EXCP_ATOMIC:
|
|
|
|
cpu_exec_step_atomic(cs);
|
|
|
|
arch_interrupt = false;
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-06 17:51:27 +02:00
|
|
|
fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
|
2019-04-17 21:18:02 +02:00
|
|
|
cpu_dump_state(cs, stderr, 0);
|
2018-04-11 20:56:46 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
process_pending_signals (env);
|
|
|
|
|
|
|
|
/* Most of the traps imply a transition through PALcode, which
|
|
|
|
implies an REI instruction has been executed. Which means
|
|
|
|
that RX and LOCK_ADDR should be cleared. But there are a
|
|
|
|
few exceptions for traps internal to QEMU. */
|
|
|
|
if (arch_interrupt) {
|
|
|
|
env->flags &= ~ENV_FLAG_RX_FLAG;
|
|
|
|
env->lock_addr = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 20:56:33 +02:00
|
|
|
void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
|
|
|
|
{
|
2018-04-11 20:56:46 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < 28; i++) {
|
|
|
|
env->ir[i] = ((abi_ulong *)regs)[i];
|
|
|
|
}
|
|
|
|
env->ir[IR_SP] = regs->usp;
|
|
|
|
env->pc = regs->pc;
|
2018-04-11 20:56:33 +02:00
|
|
|
}
|