]> git.proxmox.com Git - mirror_qemu.git/blame - linux-user/microblaze/cpu_loop.c
linux-user: Split safe-syscall macro into its own header
[mirror_qemu.git] / linux-user / microblaze / cpu_loop.c
CommitLineData
cd71c089
LV
1/*
2 * qemu user cpu loop
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "qemu/osdep.h"
a8d25326 21#include "qemu-common.h"
cd71c089
LV
22#include "qemu.h"
23#include "cpu_loop-common.h"
2113aed6 24#include "signal-common.h"
cd71c089 25
82e8e645
LV
26void cpu_loop(CPUMBState *env)
27{
f5c7e93a 28 CPUState *cs = env_cpu(env);
82e8e645
LV
29 int trapnr, ret;
30 target_siginfo_t info;
31
32 while (1) {
33 cpu_exec_start(cs);
34 trapnr = cpu_exec(cs);
35 cpu_exec_end(cs);
36 process_queued_cpu_work(cs);
37
38 switch (trapnr) {
39 case 0xaa:
40 {
41 info.si_signo = TARGET_SIGSEGV;
42 info.si_errno = 0;
43 /* XXX: check env->error_code */
44 info.si_code = TARGET_SEGV_MAPERR;
45 info._sifields._sigfault._addr = 0;
46 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
47 }
48 break;
49 case EXCP_INTERRUPT:
50 /* just indicate that signals should be handled asap */
51 break;
f5235314 52 case EXCP_SYSCALL:
82e8e645
LV
53 /* Return address is 4 bytes after the call. */
54 env->regs[14] += 4;
76e8187d 55 env->pc = env->regs[14];
82e8e645
LV
56 ret = do_syscall(env,
57 env->regs[12],
58 env->regs[5],
59 env->regs[6],
60 env->regs[7],
61 env->regs[8],
62 env->regs[9],
63 env->regs[10],
64 0, 0);
65 if (ret == -TARGET_ERESTARTSYS) {
66 /* Wind back to before the syscall. */
76e8187d 67 env->pc -= 4;
82e8e645
LV
68 } else if (ret != -TARGET_QEMU_ESIGRETURN) {
69 env->regs[3] = ret;
70 }
71 /* All syscall exits result in guest r14 being equal to the
72 * PC we return to, because the kernel syscall exit "rtbd" does
73 * this. (This is true even for sigreturn(); note that r14 is
74 * not a userspace-usable register, as the kernel may clobber it
75 * at any point.)
76 */
76e8187d 77 env->regs[14] = env->pc;
82e8e645
LV
78 break;
79 case EXCP_HW_EXCP:
76e8187d 80 env->regs[17] = env->pc + 4;
82e8e645 81 if (env->iflags & D_FLAG) {
78e9caf2 82 env->esr |= 1 << 12;
76e8187d 83 env->pc -= 4;
82e8e645
LV
84 /* FIXME: if branch was immed, replay the imm as well. */
85 }
86
87 env->iflags &= ~(IMM_FLAG | D_FLAG);
88
78e9caf2 89 switch (env->esr & 31) {
82e8e645
LV
90 case ESR_EC_DIVZERO:
91 info.si_signo = TARGET_SIGFPE;
92 info.si_errno = 0;
93 info.si_code = TARGET_FPE_FLTDIV;
94 info._sifields._sigfault._addr = 0;
95 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
96 break;
97 case ESR_EC_FPU:
98 info.si_signo = TARGET_SIGFPE;
99 info.si_errno = 0;
5a8e0136 100 if (env->fsr & FSR_IO) {
82e8e645
LV
101 info.si_code = TARGET_FPE_FLTINV;
102 }
5a8e0136 103 if (env->fsr & FSR_DZ) {
82e8e645
LV
104 info.si_code = TARGET_FPE_FLTDIV;
105 }
106 info._sifields._sigfault._addr = 0;
107 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
108 break;
109 default:
6efd5599 110 fprintf(stderr, "Unhandled hw-exception: 0x%x\n",
78e9caf2 111 env->esr & ESR_EC_MASK);
90c84c56 112 cpu_dump_state(cs, stderr, 0);
82e8e645
LV
113 exit(EXIT_FAILURE);
114 break;
115 }
116 break;
117 case EXCP_DEBUG:
b10089a1
PM
118 info.si_signo = TARGET_SIGTRAP;
119 info.si_errno = 0;
120 info.si_code = TARGET_TRAP_BRKPT;
121 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
82e8e645
LV
122 break;
123 case EXCP_ATOMIC:
124 cpu_exec_step_atomic(cs);
125 break;
126 default:
84ca4fa9 127 fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
90c84c56 128 cpu_dump_state(cs, stderr, 0);
82e8e645
LV
129 exit(EXIT_FAILURE);
130 }
131 process_pending_signals (env);
132 }
133}
134
cd71c089
LV
135void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
136{
82e8e645
LV
137 env->regs[0] = regs->r0;
138 env->regs[1] = regs->r1;
139 env->regs[2] = regs->r2;
140 env->regs[3] = regs->r3;
141 env->regs[4] = regs->r4;
142 env->regs[5] = regs->r5;
143 env->regs[6] = regs->r6;
144 env->regs[7] = regs->r7;
145 env->regs[8] = regs->r8;
146 env->regs[9] = regs->r9;
147 env->regs[10] = regs->r10;
148 env->regs[11] = regs->r11;
149 env->regs[12] = regs->r12;
150 env->regs[13] = regs->r13;
151 env->regs[14] = regs->r14;
152 env->regs[15] = regs->r15;
153 env->regs[16] = regs->r16;
154 env->regs[17] = regs->r17;
155 env->regs[18] = regs->r18;
156 env->regs[19] = regs->r19;
157 env->regs[20] = regs->r20;
158 env->regs[21] = regs->r21;
159 env->regs[22] = regs->r22;
160 env->regs[23] = regs->r23;
161 env->regs[24] = regs->r24;
162 env->regs[25] = regs->r25;
163 env->regs[26] = regs->r26;
164 env->regs[27] = regs->r27;
165 env->regs[28] = regs->r28;
166 env->regs[29] = regs->r29;
167 env->regs[30] = regs->r30;
168 env->regs[31] = regs->r31;
76e8187d 169 env->pc = regs->pc;
cd71c089 170}