2018-04-11 21:56:33 +03: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"
|
2019-05-23 17:35:08 +03:00
|
|
|
#include "qemu-common.h"
|
2018-04-11 21:56:33 +03:00
|
|
|
#include "qemu.h"
|
2021-09-08 18:44:03 +03:00
|
|
|
#include "user-internals.h"
|
2018-04-11 21:56:33 +03:00
|
|
|
#include "cpu_loop-common.h"
|
2021-09-08 18:43:59 +03:00
|
|
|
#include "signal-common.h"
|
2018-04-11 21:56:33 +03:00
|
|
|
|
2018-04-11 21:56:41 +03:00
|
|
|
void cpu_loop(CPUOpenRISCState *env)
|
|
|
|
{
|
2019-03-23 04:48:56 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2018-04-11 21:56:41 +03:00
|
|
|
int trapnr;
|
|
|
|
abi_long ret;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
cpu_exec_start(cs);
|
|
|
|
trapnr = cpu_exec(cs);
|
|
|
|
cpu_exec_end(cs);
|
|
|
|
process_queued_cpu_work(cs);
|
|
|
|
|
|
|
|
switch (trapnr) {
|
|
|
|
case EXCP_SYSCALL:
|
|
|
|
env->pc += 4; /* 0xc00; */
|
|
|
|
ret = do_syscall(env,
|
|
|
|
cpu_get_gpr(env, 11), /* return value */
|
|
|
|
cpu_get_gpr(env, 3), /* r3 - r7 are params */
|
|
|
|
cpu_get_gpr(env, 4),
|
|
|
|
cpu_get_gpr(env, 5),
|
|
|
|
cpu_get_gpr(env, 6),
|
|
|
|
cpu_get_gpr(env, 7),
|
|
|
|
cpu_get_gpr(env, 8), 0, 0);
|
2021-11-22 21:47:33 +03:00
|
|
|
if (ret == -QEMU_ERESTARTSYS) {
|
2018-04-11 21:56:41 +03:00
|
|
|
env->pc -= 4;
|
2021-11-17 16:14:52 +03:00
|
|
|
} else if (ret != -QEMU_ESIGRETURN) {
|
2018-04-11 21:56:41 +03:00
|
|
|
cpu_set_gpr(env, 11, ret);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXCP_ALIGN:
|
2022-01-08 00:32:37 +03:00
|
|
|
force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, env->eear);
|
2018-04-11 21:56:41 +03:00
|
|
|
break;
|
|
|
|
case EXCP_ILLEGAL:
|
2022-01-08 00:32:37 +03:00
|
|
|
force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
|
2018-04-11 21:56:41 +03:00
|
|
|
break;
|
|
|
|
case EXCP_INTERRUPT:
|
|
|
|
/* We processed the pending cpu work above. */
|
|
|
|
break;
|
|
|
|
case EXCP_DEBUG:
|
2022-01-08 00:32:37 +03:00
|
|
|
force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
|
2018-04-11 21:56:41 +03:00
|
|
|
break;
|
|
|
|
case EXCP_ATOMIC:
|
|
|
|
cpu_exec_step_atomic(cs);
|
|
|
|
break;
|
2021-09-15 06:27:58 +03:00
|
|
|
case EXCP_RANGE:
|
|
|
|
/* Requires SR.OVE set, which linux-user won't do. */
|
|
|
|
cpu_abort(cs, "Unexpected RANGE exception");
|
|
|
|
case EXCP_FPE:
|
|
|
|
/*
|
|
|
|
* Requires FPSCR.FPEE set. Writes to FPSCR from usermode not
|
|
|
|
* yet enabled in kernel ABI, so linux-user does not either.
|
|
|
|
*/
|
|
|
|
cpu_abort(cs, "Unexpected FPE exception");
|
2018-04-11 21:56:41 +03:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
process_pending_signals(env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:56:33 +03:00
|
|
|
void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
|
|
|
|
{
|
2018-04-11 21:56:41 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
cpu_set_gpr(env, i, regs->gpr[i]);
|
|
|
|
}
|
|
|
|
env->pc = regs->pc;
|
|
|
|
cpu_set_sr(env, regs->sr);
|
2018-04-11 21:56:33 +03:00
|
|
|
}
|