1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "qemu.h"
23#include "cpu_loop-common.h"
24#include "internal.h"
25
26void cpu_loop(CPUHexagonState *env)
27{
28 CPUState *cs = env_cpu(env);
29 int trapnr, signum, sigcode;
30 target_ulong sigaddr;
31 target_ulong syscallnum;
32 target_ulong ret;
33
34 for (;;) {
35 cpu_exec_start(cs);
36 trapnr = cpu_exec(cs);
37 cpu_exec_end(cs);
38 process_queued_cpu_work(cs);
39
40 signum = 0;
41 sigcode = 0;
42 sigaddr = 0;
43
44 switch (trapnr) {
45 case EXCP_INTERRUPT:
46
47 break;
48 case HEX_EXCP_TRAP0:
49 syscallnum = env->gpr[6];
50 env->gpr[HEX_REG_PC] += 4;
51 ret = do_syscall(env,
52 syscallnum,
53 env->gpr[0],
54 env->gpr[1],
55 env->gpr[2],
56 env->gpr[3],
57 env->gpr[4],
58 env->gpr[5],
59 0, 0);
60 if (ret == -TARGET_ERESTARTSYS) {
61 env->gpr[HEX_REG_PC] -= 4;
62 } else if (ret != -TARGET_QEMU_ESIGRETURN) {
63 env->gpr[0] = ret;
64 }
65 break;
66 case HEX_EXCP_FETCH_NO_UPAGE:
67 case HEX_EXCP_PRIV_NO_UREAD:
68 case HEX_EXCP_PRIV_NO_UWRITE:
69 signum = TARGET_SIGSEGV;
70 sigcode = TARGET_SEGV_MAPERR;
71 break;
72 case EXCP_ATOMIC:
73 cpu_exec_step_atomic(cs);
74 break;
75 default:
76 EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
77 trapnr);
78 exit(EXIT_FAILURE);
79 }
80
81 if (signum) {
82 target_siginfo_t info = {
83 .si_signo = signum,
84 .si_errno = 0,
85 .si_code = sigcode,
86 ._sifields._sigfault._addr = sigaddr
87 };
88 queue_signal(env, info.si_signo, QEMU_SI_KILL, &info);
89 }
90
91 process_pending_signals(env);
92 }
93}
94
95void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
96{
97 env->gpr[HEX_REG_PC] = regs->sepc;
98 env->gpr[HEX_REG_SP] = regs->sp;
99 env->gpr[HEX_REG_USR] = 0x56000;
100}
101