blob: 7f1499ed28b8384baf28e0c2ee84cf6507c27acb [file] [log] [blame]
Taylor Simpsond2a56bd2021-02-07 23:46:20 -06001/*
2 * qemu user cpu loop
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "qemu/osdep.h"
22#include "qemu.h"
Peter Maydell3b249d22021-09-08 16:44:03 +010023#include "user-internals.h"
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060024#include "cpu_loop-common.h"
Peter Maydell2113aed2021-09-08 16:43:59 +010025#include "signal-common.h"
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060026#include "internal.h"
27
28void cpu_loop(CPUHexagonState *env)
29{
Taylor Simpson7d9ab202021-04-08 20:07:32 -050030 CPUState *cs = env_cpu(env);
Richard Henderson70863882021-09-14 16:32:17 -070031 int trapnr;
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060032 target_ulong syscallnum;
33 target_ulong ret;
34
35 for (;;) {
36 cpu_exec_start(cs);
37 trapnr = cpu_exec(cs);
38 cpu_exec_end(cs);
39 process_queued_cpu_work(cs);
40
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060041 switch (trapnr) {
42 case EXCP_INTERRUPT:
43 /* just indicate that signals should be handled asap */
44 break;
45 case HEX_EXCP_TRAP0:
46 syscallnum = env->gpr[6];
47 env->gpr[HEX_REG_PC] += 4;
48 ret = do_syscall(env,
49 syscallnum,
50 env->gpr[0],
51 env->gpr[1],
52 env->gpr[2],
53 env->gpr[3],
54 env->gpr[4],
55 env->gpr[5],
56 0, 0);
Richard Hendersonaf254a22021-11-22 19:47:33 +010057 if (ret == -QEMU_ERESTARTSYS) {
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060058 env->gpr[HEX_REG_PC] -= 4;
Richard Henderson57a0c932021-11-17 05:14:52 -080059 } else if (ret != -QEMU_ESIGRETURN) {
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060060 env->gpr[0] = ret;
61 }
62 break;
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060063 case EXCP_ATOMIC:
64 cpu_exec_step_atomic(cs);
65 break;
Matheus Tavares Bernardino9073bfd2023-05-04 12:37:36 -030066 case EXCP_DEBUG:
67 force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0);
68 break;
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060069 default:
70 EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
71 trapnr);
72 exit(EXIT_FAILURE);
73 }
Taylor Simpsond2a56bd2021-02-07 23:46:20 -060074 process_pending_signals(env);
75 }
76}
77
78void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
79{
80 env->gpr[HEX_REG_PC] = regs->sepc;
81 env->gpr[HEX_REG_SP] = regs->sp;
82 env->gpr[HEX_REG_USR] = 0x56000;
83}