master
c 122 lines 4.09 KB
Raw
1 /*
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"
23 #include "user-internals.h"
24 #include "user/cpu_loop.h"
25 #include "target/hexagon/internal.h"
26 #include "signal-common.h"
27 #include "internal.h"
28
29 void cpu_loop(CPUHexagonState *env)
30 {
31 CPUState *cs = env_cpu(env);
32 int trapnr;
33 target_ulong syscallnum;
34 target_ulong ret;
35
36 for (;;) {
37 cpu_exec_start(cs);
38 trapnr = cpu_exec(cs);
39 cpu_exec_end(cs);
40 qemu_process_cpu_events(cs);
41
42 switch (trapnr) {
43 case EXCP_INTERRUPT:
44 /* just indicate that signals should be handled asap */
45 break;
46 case HEX_EVENT_TRAP0:
47 syscallnum = env->gpr[6];
48 env->gpr[HEX_REG_PC] += 4;
49 ret = do_syscall(env,
50 syscallnum,
51 env->gpr[0],
52 env->gpr[1],
53 env->gpr[2],
54 env->gpr[3],
55 env->gpr[4],
56 env->gpr[5],
57 0, 0);
58 if (ret == -QEMU_ERESTARTSYS) {
59 env->gpr[HEX_REG_PC] -= 4;
60 } else if (ret != -QEMU_ESIGRETURN && ret != -QEMU_ESETPC) {
61 env->gpr[0] = ret;
62 }
63 break;
64 case HEX_EVENT_PRECISE:
65 switch (env->cause_code) {
66 case HEX_CAUSE_FETCH_NO_UPAGE:
67 case HEX_CAUSE_PRIV_NO_UREAD:
68 case HEX_CAUSE_PRIV_NO_UWRITE:
69 force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR,
70 env->gpr[HEX_REG_PC]);
71
72 break;
73 case HEX_CAUSE_PRIV_USER_NO_GINSN:
74 case HEX_CAUSE_PRIV_USER_NO_SINSN:
75 case HEX_CAUSE_INVALID_PACKET:
76 force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
77 env->gpr[HEX_REG_PC]);
78 break;
79 case HEX_CAUSE_MISALIGNED_LOAD:
80 case HEX_CAUSE_MISALIGNED_STORE:
81 force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
82 env->gpr[HEX_REG_PC]);
83 break;
84 default:
85 EXCP_DUMP(env, "\nqemu: unhandled CPU precise exception "
86 "cause code 0x%x - aborting\n",
87 env->cause_code);
88 exit(EXIT_FAILURE);
89 }
90 break;
91 case HEX_CAUSE_PC_NOT_ALIGNED:
92 force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
93 env->gpr[HEX_REG_R31]);
94 break;
95 case HEX_CAUSE_INVALID_PACKET:
96 case HEX_CAUSE_REG_WRITE_CONFLICT:
97 force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
98 env->gpr[HEX_REG_PC]);
99 break;
100 case EXCP_ATOMIC:
101 cpu_exec_step_atomic(cs);
102 break;
103 case EXCP_DEBUG:
104 force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0);
105 break;
106 default:
107 EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
108 trapnr);
109 exit(EXIT_FAILURE);
110 }
111 process_pending_signals(env);
112 }
113 }
114
115 void init_main_thread(CPUState *cs, struct image_info *info)
116 {
117 CPUArchState *env = cpu_env(cs);
118
119 env->gpr[HEX_REG_PC] = info->entry;
120 env->gpr[HEX_REG_SP] = info->start_stack;
121 env->gpr[HEX_REG_USR] = 0x56000;
122 }