root / linux-user / main.c @ ea785922
History | View | Annotate | Download (57.1 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 93ac68bc | bellard | * qemu user main
|
3 | 31e31b8a | bellard | *
|
4 | 31e31b8a | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 31e31b8a | bellard | * along with this program; if not, write to the Free Software
|
18 | 31e31b8a | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 31e31b8a | bellard | */
|
20 | 31e31b8a | bellard | #include <stdlib.h> |
21 | 31e31b8a | bellard | #include <stdio.h> |
22 | 31e31b8a | bellard | #include <stdarg.h> |
23 | 04369ff2 | bellard | #include <string.h> |
24 | 31e31b8a | bellard | #include <errno.h> |
25 | 0ecfa993 | bellard | #include <unistd.h> |
26 | 31e31b8a | bellard | |
27 | 3ef693a0 | bellard | #include "qemu.h" |
28 | 31e31b8a | bellard | |
29 | 3ef693a0 | bellard | #define DEBUG_LOGFILE "/tmp/qemu.log" |
30 | 586314f2 | bellard | |
31 | 83fb7adf | bellard | #ifdef __APPLE__
|
32 | 83fb7adf | bellard | #include <crt_externs.h> |
33 | 83fb7adf | bellard | # define environ (*_NSGetEnviron())
|
34 | 83fb7adf | bellard | #endif
|
35 | 83fb7adf | bellard | |
36 | 74cd30b8 | bellard | static const char *interp_prefix = CONFIG_QEMU_PREFIX; |
37 | c5937220 | pbrook | const char *qemu_uname_release = CONFIG_UNAME_RELEASE; |
38 | 586314f2 | bellard | |
39 | 3a4739d6 | bellard | #if defined(__i386__) && !defined(CONFIG_STATIC)
|
40 | f801f97e | bellard | /* Force usage of an ELF interpreter even if it is an ELF shared
|
41 | f801f97e | bellard | object ! */
|
42 | f801f97e | bellard | const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2"; |
43 | 4304763b | bellard | #endif
|
44 | 74cd30b8 | bellard | |
45 | 93ac68bc | bellard | /* for recent libc, we add these dummy symbols which are not declared
|
46 | 74cd30b8 | bellard | when generating a linked object (bug in ld ?) */
|
47 | fbf59244 | bellard | #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined(CONFIG_STATIC) |
48 | c6981055 | bellard | long __preinit_array_start[0]; |
49 | c6981055 | bellard | long __preinit_array_end[0]; |
50 | 74cd30b8 | bellard | long __init_array_start[0]; |
51 | 74cd30b8 | bellard | long __init_array_end[0]; |
52 | 74cd30b8 | bellard | long __fini_array_start[0]; |
53 | 74cd30b8 | bellard | long __fini_array_end[0]; |
54 | 74cd30b8 | bellard | #endif
|
55 | 74cd30b8 | bellard | |
56 | 9de5e440 | bellard | /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
|
57 | 9de5e440 | bellard | we allocate a bigger stack. Need a better solution, for example
|
58 | 9de5e440 | bellard | by remapping the process stack directly at the right place */
|
59 | 9de5e440 | bellard | unsigned long x86_stack_size = 512 * 1024; |
60 | 31e31b8a | bellard | |
61 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) |
62 | 31e31b8a | bellard | { |
63 | 31e31b8a | bellard | va_list ap; |
64 | 31e31b8a | bellard | |
65 | 31e31b8a | bellard | va_start(ap, fmt); |
66 | 31e31b8a | bellard | vfprintf(stderr, fmt, ap); |
67 | 31e31b8a | bellard | va_end(ap); |
68 | 31e31b8a | bellard | } |
69 | 31e31b8a | bellard | |
70 | 61190b14 | bellard | void cpu_outb(CPUState *env, int addr, int val) |
71 | 367e86e8 | bellard | { |
72 | 367e86e8 | bellard | fprintf(stderr, "outb: port=0x%04x, data=%02x\n", addr, val);
|
73 | 367e86e8 | bellard | } |
74 | 367e86e8 | bellard | |
75 | 61190b14 | bellard | void cpu_outw(CPUState *env, int addr, int val) |
76 | 367e86e8 | bellard | { |
77 | 367e86e8 | bellard | fprintf(stderr, "outw: port=0x%04x, data=%04x\n", addr, val);
|
78 | 367e86e8 | bellard | } |
79 | 367e86e8 | bellard | |
80 | 61190b14 | bellard | void cpu_outl(CPUState *env, int addr, int val) |
81 | 367e86e8 | bellard | { |
82 | 367e86e8 | bellard | fprintf(stderr, "outl: port=0x%04x, data=%08x\n", addr, val);
|
83 | 367e86e8 | bellard | } |
84 | 367e86e8 | bellard | |
85 | 61190b14 | bellard | int cpu_inb(CPUState *env, int addr) |
86 | 367e86e8 | bellard | { |
87 | 367e86e8 | bellard | fprintf(stderr, "inb: port=0x%04x\n", addr);
|
88 | 367e86e8 | bellard | return 0; |
89 | 367e86e8 | bellard | } |
90 | 367e86e8 | bellard | |
91 | 61190b14 | bellard | int cpu_inw(CPUState *env, int addr) |
92 | 367e86e8 | bellard | { |
93 | 367e86e8 | bellard | fprintf(stderr, "inw: port=0x%04x\n", addr);
|
94 | 367e86e8 | bellard | return 0; |
95 | 367e86e8 | bellard | } |
96 | 367e86e8 | bellard | |
97 | 61190b14 | bellard | int cpu_inl(CPUState *env, int addr) |
98 | 367e86e8 | bellard | { |
99 | 367e86e8 | bellard | fprintf(stderr, "inl: port=0x%04x\n", addr);
|
100 | 367e86e8 | bellard | return 0; |
101 | 367e86e8 | bellard | } |
102 | 367e86e8 | bellard | |
103 | a541f297 | bellard | int cpu_get_pic_interrupt(CPUState *env)
|
104 | 92ccca6a | bellard | { |
105 | 92ccca6a | bellard | return -1; |
106 | 92ccca6a | bellard | } |
107 | 92ccca6a | bellard | |
108 | 28ab0e2e | bellard | /* timers for rdtsc */
|
109 | 28ab0e2e | bellard | |
110 | 1dce7c3c | bellard | #if 0
|
111 | 28ab0e2e | bellard | |
112 | 28ab0e2e | bellard | static uint64_t emu_time;
|
113 | 28ab0e2e | bellard | |
114 | 28ab0e2e | bellard | int64_t cpu_get_real_ticks(void)
|
115 | 28ab0e2e | bellard | {
|
116 | 28ab0e2e | bellard | return emu_time++;
|
117 | 28ab0e2e | bellard | }
|
118 | 28ab0e2e | bellard | |
119 | 28ab0e2e | bellard | #endif
|
120 | 28ab0e2e | bellard | |
121 | a541f297 | bellard | #ifdef TARGET_I386
|
122 | a541f297 | bellard | /***********************************************************/
|
123 | a541f297 | bellard | /* CPUX86 core interface */
|
124 | a541f297 | bellard | |
125 | 02a1602e | bellard | void cpu_smm_update(CPUState *env)
|
126 | 02a1602e | bellard | { |
127 | 02a1602e | bellard | } |
128 | 02a1602e | bellard | |
129 | 28ab0e2e | bellard | uint64_t cpu_get_tsc(CPUX86State *env) |
130 | 28ab0e2e | bellard | { |
131 | 28ab0e2e | bellard | return cpu_get_real_ticks();
|
132 | 28ab0e2e | bellard | } |
133 | 28ab0e2e | bellard | |
134 | f4beb510 | bellard | static void write_dt(void *ptr, unsigned long addr, unsigned long limit, |
135 | f4beb510 | bellard | int flags)
|
136 | 6dbad63e | bellard | { |
137 | f4beb510 | bellard | unsigned int e1, e2; |
138 | 53a5960a | pbrook | uint32_t *p; |
139 | 6dbad63e | bellard | e1 = (addr << 16) | (limit & 0xffff); |
140 | 6dbad63e | bellard | e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); |
141 | f4beb510 | bellard | e2 |= flags; |
142 | 53a5960a | pbrook | p = ptr; |
143 | 53a5960a | pbrook | p[0] = tswapl(e1);
|
144 | 53a5960a | pbrook | p[1] = tswapl(e2);
|
145 | f4beb510 | bellard | } |
146 | f4beb510 | bellard | |
147 | f4beb510 | bellard | static void set_gate(void *ptr, unsigned int type, unsigned int dpl, |
148 | f4beb510 | bellard | unsigned long addr, unsigned int sel) |
149 | f4beb510 | bellard | { |
150 | f4beb510 | bellard | unsigned int e1, e2; |
151 | 53a5960a | pbrook | uint32_t *p; |
152 | f4beb510 | bellard | e1 = (addr & 0xffff) | (sel << 16); |
153 | f4beb510 | bellard | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); |
154 | 53a5960a | pbrook | p = ptr; |
155 | 53a5960a | pbrook | p[0] = tswapl(e1);
|
156 | 53a5960a | pbrook | p[1] = tswapl(e2);
|
157 | 6dbad63e | bellard | } |
158 | 6dbad63e | bellard | |
159 | 6dbad63e | bellard | uint64_t gdt_table[6];
|
160 | f4beb510 | bellard | uint64_t idt_table[256];
|
161 | f4beb510 | bellard | |
162 | f4beb510 | bellard | /* only dpl matters as we do only user space emulation */
|
163 | f4beb510 | bellard | static void set_idt(int n, unsigned int dpl) |
164 | f4beb510 | bellard | { |
165 | f4beb510 | bellard | set_gate(idt_table + n, 0, dpl, 0, 0); |
166 | f4beb510 | bellard | } |
167 | 31e31b8a | bellard | |
168 | 89e957e7 | bellard | void cpu_loop(CPUX86State *env)
|
169 | 1b6b029e | bellard | { |
170 | bc8a22cc | bellard | int trapnr;
|
171 | 80a9d035 | bellard | target_ulong pc; |
172 | 9de5e440 | bellard | target_siginfo_t info; |
173 | 851e67a1 | bellard | |
174 | 1b6b029e | bellard | for(;;) {
|
175 | bc8a22cc | bellard | trapnr = cpu_x86_exec(env); |
176 | bc8a22cc | bellard | switch(trapnr) {
|
177 | f4beb510 | bellard | case 0x80: |
178 | f4beb510 | bellard | /* linux syscall */
|
179 | f4beb510 | bellard | env->regs[R_EAX] = do_syscall(env, |
180 | f4beb510 | bellard | env->regs[R_EAX], |
181 | f4beb510 | bellard | env->regs[R_EBX], |
182 | f4beb510 | bellard | env->regs[R_ECX], |
183 | f4beb510 | bellard | env->regs[R_EDX], |
184 | f4beb510 | bellard | env->regs[R_ESI], |
185 | f4beb510 | bellard | env->regs[R_EDI], |
186 | f4beb510 | bellard | env->regs[R_EBP]); |
187 | f4beb510 | bellard | break;
|
188 | f4beb510 | bellard | case EXCP0B_NOSEG:
|
189 | f4beb510 | bellard | case EXCP0C_STACK:
|
190 | f4beb510 | bellard | info.si_signo = SIGBUS; |
191 | f4beb510 | bellard | info.si_errno = 0;
|
192 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
193 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
194 | f4beb510 | bellard | queue_signal(info.si_signo, &info); |
195 | f4beb510 | bellard | break;
|
196 | 1b6b029e | bellard | case EXCP0D_GPF:
|
197 | 851e67a1 | bellard | if (env->eflags & VM_MASK) {
|
198 | 89e957e7 | bellard | handle_vm86_fault(env); |
199 | 1b6b029e | bellard | } else {
|
200 | f4beb510 | bellard | info.si_signo = SIGSEGV; |
201 | f4beb510 | bellard | info.si_errno = 0;
|
202 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
203 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
204 | f4beb510 | bellard | queue_signal(info.si_signo, &info); |
205 | 1b6b029e | bellard | } |
206 | 1b6b029e | bellard | break;
|
207 | b689bc57 | bellard | case EXCP0E_PAGE:
|
208 | b689bc57 | bellard | info.si_signo = SIGSEGV; |
209 | b689bc57 | bellard | info.si_errno = 0;
|
210 | b689bc57 | bellard | if (!(env->error_code & 1)) |
211 | b689bc57 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
212 | b689bc57 | bellard | else
|
213 | b689bc57 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
214 | 970a87a6 | bellard | info._sifields._sigfault._addr = env->cr[2];
|
215 | b689bc57 | bellard | queue_signal(info.si_signo, &info); |
216 | b689bc57 | bellard | break;
|
217 | 9de5e440 | bellard | case EXCP00_DIVZ:
|
218 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
219 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
220 | bc8a22cc | bellard | } else {
|
221 | bc8a22cc | bellard | /* division by zero */
|
222 | bc8a22cc | bellard | info.si_signo = SIGFPE; |
223 | bc8a22cc | bellard | info.si_errno = 0;
|
224 | bc8a22cc | bellard | info.si_code = TARGET_FPE_INTDIV; |
225 | bc8a22cc | bellard | info._sifields._sigfault._addr = env->eip; |
226 | bc8a22cc | bellard | queue_signal(info.si_signo, &info); |
227 | bc8a22cc | bellard | } |
228 | 9de5e440 | bellard | break;
|
229 | 447db213 | bellard | case EXCP01_SSTP:
|
230 | 447db213 | bellard | case EXCP03_INT3:
|
231 | 447db213 | bellard | if (env->eflags & VM_MASK) {
|
232 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
233 | 447db213 | bellard | } else {
|
234 | 447db213 | bellard | info.si_signo = SIGTRAP; |
235 | 447db213 | bellard | info.si_errno = 0;
|
236 | 447db213 | bellard | if (trapnr == EXCP01_SSTP) {
|
237 | 447db213 | bellard | info.si_code = TARGET_TRAP_BRKPT; |
238 | 447db213 | bellard | info._sifields._sigfault._addr = env->eip; |
239 | 447db213 | bellard | } else {
|
240 | 447db213 | bellard | info.si_code = TARGET_SI_KERNEL; |
241 | 447db213 | bellard | info._sifields._sigfault._addr = 0;
|
242 | 447db213 | bellard | } |
243 | 447db213 | bellard | queue_signal(info.si_signo, &info); |
244 | 447db213 | bellard | } |
245 | 447db213 | bellard | break;
|
246 | 9de5e440 | bellard | case EXCP04_INTO:
|
247 | 9de5e440 | bellard | case EXCP05_BOUND:
|
248 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
249 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
250 | bc8a22cc | bellard | } else {
|
251 | bc8a22cc | bellard | info.si_signo = SIGSEGV; |
252 | bc8a22cc | bellard | info.si_errno = 0;
|
253 | b689bc57 | bellard | info.si_code = TARGET_SI_KERNEL; |
254 | bc8a22cc | bellard | info._sifields._sigfault._addr = 0;
|
255 | bc8a22cc | bellard | queue_signal(info.si_signo, &info); |
256 | bc8a22cc | bellard | } |
257 | 9de5e440 | bellard | break;
|
258 | 9de5e440 | bellard | case EXCP06_ILLOP:
|
259 | 9de5e440 | bellard | info.si_signo = SIGILL; |
260 | 9de5e440 | bellard | info.si_errno = 0;
|
261 | 9de5e440 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
262 | 9de5e440 | bellard | info._sifields._sigfault._addr = env->eip; |
263 | 9de5e440 | bellard | queue_signal(info.si_signo, &info); |
264 | 9de5e440 | bellard | break;
|
265 | 9de5e440 | bellard | case EXCP_INTERRUPT:
|
266 | 9de5e440 | bellard | /* just indicate that signals should be handled asap */
|
267 | 9de5e440 | bellard | break;
|
268 | 1fddef4b | bellard | case EXCP_DEBUG:
|
269 | 1fddef4b | bellard | { |
270 | 1fddef4b | bellard | int sig;
|
271 | 1fddef4b | bellard | |
272 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
273 | 1fddef4b | bellard | if (sig)
|
274 | 1fddef4b | bellard | { |
275 | 1fddef4b | bellard | info.si_signo = sig; |
276 | 1fddef4b | bellard | info.si_errno = 0;
|
277 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
278 | 1fddef4b | bellard | queue_signal(info.si_signo, &info); |
279 | 1fddef4b | bellard | } |
280 | 1fddef4b | bellard | } |
281 | 1fddef4b | bellard | break;
|
282 | 1b6b029e | bellard | default:
|
283 | 970a87a6 | bellard | pc = env->segs[R_CS].base + env->eip; |
284 | bc8a22cc | bellard | fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
|
285 | bc8a22cc | bellard | (long)pc, trapnr);
|
286 | 1b6b029e | bellard | abort(); |
287 | 1b6b029e | bellard | } |
288 | 66fb9763 | bellard | process_pending_signals(env); |
289 | 1b6b029e | bellard | } |
290 | 1b6b029e | bellard | } |
291 | b346ff46 | bellard | #endif
|
292 | b346ff46 | bellard | |
293 | b346ff46 | bellard | #ifdef TARGET_ARM
|
294 | b346ff46 | bellard | |
295 | 6f1f31c0 | bellard | /* XXX: find a better solution */
|
296 | 6f1f31c0 | bellard | extern void tb_invalidate_page_range(target_ulong start, target_ulong end); |
297 | 6f1f31c0 | bellard | |
298 | 6f1f31c0 | bellard | static void arm_cache_flush(target_ulong start, target_ulong last) |
299 | 6f1f31c0 | bellard | { |
300 | 6f1f31c0 | bellard | target_ulong addr, last1; |
301 | 6f1f31c0 | bellard | |
302 | 6f1f31c0 | bellard | if (last < start)
|
303 | 6f1f31c0 | bellard | return;
|
304 | 6f1f31c0 | bellard | addr = start; |
305 | 6f1f31c0 | bellard | for(;;) {
|
306 | 6f1f31c0 | bellard | last1 = ((addr + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK) - 1;
|
307 | 6f1f31c0 | bellard | if (last1 > last)
|
308 | 6f1f31c0 | bellard | last1 = last; |
309 | 6f1f31c0 | bellard | tb_invalidate_page_range(addr, last1 + 1);
|
310 | 6f1f31c0 | bellard | if (last1 == last)
|
311 | 6f1f31c0 | bellard | break;
|
312 | 6f1f31c0 | bellard | addr = last1 + 1;
|
313 | 6f1f31c0 | bellard | } |
314 | 6f1f31c0 | bellard | } |
315 | 6f1f31c0 | bellard | |
316 | b346ff46 | bellard | void cpu_loop(CPUARMState *env)
|
317 | b346ff46 | bellard | { |
318 | b346ff46 | bellard | int trapnr;
|
319 | b346ff46 | bellard | unsigned int n, insn; |
320 | b346ff46 | bellard | target_siginfo_t info; |
321 | b5ff1b31 | bellard | uint32_t addr; |
322 | b346ff46 | bellard | |
323 | b346ff46 | bellard | for(;;) {
|
324 | b346ff46 | bellard | trapnr = cpu_arm_exec(env); |
325 | b346ff46 | bellard | switch(trapnr) {
|
326 | b346ff46 | bellard | case EXCP_UDEF:
|
327 | c6981055 | bellard | { |
328 | c6981055 | bellard | TaskState *ts = env->opaque; |
329 | c6981055 | bellard | uint32_t opcode; |
330 | c6981055 | bellard | |
331 | c6981055 | bellard | /* we handle the FPU emulation here, as Linux */
|
332 | c6981055 | bellard | /* we get the opcode */
|
333 | 53a5960a | pbrook | opcode = tget32(env->regs[15]);
|
334 | c6981055 | bellard | |
335 | 19b045de | pbrook | if (EmulateAll(opcode, &ts->fpa, env) == 0) { |
336 | c6981055 | bellard | info.si_signo = SIGILL; |
337 | c6981055 | bellard | info.si_errno = 0;
|
338 | c6981055 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
339 | c6981055 | bellard | info._sifields._sigfault._addr = env->regs[15];
|
340 | c6981055 | bellard | queue_signal(info.si_signo, &info); |
341 | c6981055 | bellard | } else {
|
342 | c6981055 | bellard | /* increment PC */
|
343 | c6981055 | bellard | env->regs[15] += 4; |
344 | c6981055 | bellard | } |
345 | c6981055 | bellard | } |
346 | b346ff46 | bellard | break;
|
347 | b346ff46 | bellard | case EXCP_SWI:
|
348 | 06c949e6 | pbrook | case EXCP_BKPT:
|
349 | b346ff46 | bellard | { |
350 | ce4defa0 | pbrook | env->eabi = 1;
|
351 | b346ff46 | bellard | /* system call */
|
352 | 06c949e6 | pbrook | if (trapnr == EXCP_BKPT) {
|
353 | 06c949e6 | pbrook | if (env->thumb) {
|
354 | 53a5960a | pbrook | insn = tget16(env->regs[15]);
|
355 | 06c949e6 | pbrook | n = insn & 0xff;
|
356 | 06c949e6 | pbrook | env->regs[15] += 2; |
357 | 06c949e6 | pbrook | } else {
|
358 | 53a5960a | pbrook | insn = tget32(env->regs[15]);
|
359 | 06c949e6 | pbrook | n = (insn & 0xf) | ((insn >> 4) & 0xff0); |
360 | 06c949e6 | pbrook | env->regs[15] += 4; |
361 | 06c949e6 | pbrook | } |
362 | 192c7bd9 | bellard | } else {
|
363 | 06c949e6 | pbrook | if (env->thumb) {
|
364 | 53a5960a | pbrook | insn = tget16(env->regs[15] - 2); |
365 | 06c949e6 | pbrook | n = insn & 0xff;
|
366 | 06c949e6 | pbrook | } else {
|
367 | 53a5960a | pbrook | insn = tget32(env->regs[15] - 4); |
368 | 06c949e6 | pbrook | n = insn & 0xffffff;
|
369 | 06c949e6 | pbrook | } |
370 | 192c7bd9 | bellard | } |
371 | 192c7bd9 | bellard | |
372 | 6f1f31c0 | bellard | if (n == ARM_NR_cacheflush) {
|
373 | 6f1f31c0 | bellard | arm_cache_flush(env->regs[0], env->regs[1]); |
374 | a4f81979 | bellard | } else if (n == ARM_NR_semihosting |
375 | a4f81979 | bellard | || n == ARM_NR_thumb_semihosting) { |
376 | a4f81979 | bellard | env->regs[0] = do_arm_semihosting (env);
|
377 | ce4defa0 | pbrook | } else if (n == 0 || n >= ARM_SYSCALL_BASE |
378 | 192c7bd9 | bellard | || (env->thumb && n == ARM_THUMB_SYSCALL)) { |
379 | b346ff46 | bellard | /* linux syscall */
|
380 | ce4defa0 | pbrook | if (env->thumb || n == 0) { |
381 | 192c7bd9 | bellard | n = env->regs[7];
|
382 | 192c7bd9 | bellard | } else {
|
383 | 192c7bd9 | bellard | n -= ARM_SYSCALL_BASE; |
384 | ce4defa0 | pbrook | env->eabi = 0;
|
385 | 192c7bd9 | bellard | } |
386 | b346ff46 | bellard | env->regs[0] = do_syscall(env,
|
387 | b346ff46 | bellard | n, |
388 | b346ff46 | bellard | env->regs[0],
|
389 | b346ff46 | bellard | env->regs[1],
|
390 | b346ff46 | bellard | env->regs[2],
|
391 | b346ff46 | bellard | env->regs[3],
|
392 | b346ff46 | bellard | env->regs[4],
|
393 | e1a2849c | bellard | env->regs[5]);
|
394 | b346ff46 | bellard | } else {
|
395 | b346ff46 | bellard | goto error;
|
396 | b346ff46 | bellard | } |
397 | b346ff46 | bellard | } |
398 | b346ff46 | bellard | break;
|
399 | 43fff238 | bellard | case EXCP_INTERRUPT:
|
400 | 43fff238 | bellard | /* just indicate that signals should be handled asap */
|
401 | 43fff238 | bellard | break;
|
402 | 68016c62 | bellard | case EXCP_PREFETCH_ABORT:
|
403 | b5ff1b31 | bellard | addr = env->cp15.c6_data; |
404 | b5ff1b31 | bellard | goto do_segv;
|
405 | 68016c62 | bellard | case EXCP_DATA_ABORT:
|
406 | b5ff1b31 | bellard | addr = env->cp15.c6_insn; |
407 | b5ff1b31 | bellard | goto do_segv;
|
408 | b5ff1b31 | bellard | do_segv:
|
409 | 68016c62 | bellard | { |
410 | 68016c62 | bellard | info.si_signo = SIGSEGV; |
411 | 68016c62 | bellard | info.si_errno = 0;
|
412 | 68016c62 | bellard | /* XXX: check env->error_code */
|
413 | 68016c62 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
414 | b5ff1b31 | bellard | info._sifields._sigfault._addr = addr; |
415 | 68016c62 | bellard | queue_signal(info.si_signo, &info); |
416 | 68016c62 | bellard | } |
417 | 68016c62 | bellard | break;
|
418 | 1fddef4b | bellard | case EXCP_DEBUG:
|
419 | 1fddef4b | bellard | { |
420 | 1fddef4b | bellard | int sig;
|
421 | 1fddef4b | bellard | |
422 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
423 | 1fddef4b | bellard | if (sig)
|
424 | 1fddef4b | bellard | { |
425 | 1fddef4b | bellard | info.si_signo = sig; |
426 | 1fddef4b | bellard | info.si_errno = 0;
|
427 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
428 | 1fddef4b | bellard | queue_signal(info.si_signo, &info); |
429 | 1fddef4b | bellard | } |
430 | 1fddef4b | bellard | } |
431 | 1fddef4b | bellard | break;
|
432 | b346ff46 | bellard | default:
|
433 | b346ff46 | bellard | error:
|
434 | b346ff46 | bellard | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
435 | b346ff46 | bellard | trapnr); |
436 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
437 | b346ff46 | bellard | abort(); |
438 | b346ff46 | bellard | } |
439 | b346ff46 | bellard | process_pending_signals(env); |
440 | b346ff46 | bellard | } |
441 | b346ff46 | bellard | } |
442 | b346ff46 | bellard | |
443 | b346ff46 | bellard | #endif
|
444 | 1b6b029e | bellard | |
445 | 93ac68bc | bellard | #ifdef TARGET_SPARC
|
446 | 93ac68bc | bellard | |
447 | 060366c5 | bellard | //#define DEBUG_WIN
|
448 | 060366c5 | bellard | |
449 | 2623cbaf | bellard | /* WARNING: dealing with register windows _is_ complicated. More info
|
450 | 2623cbaf | bellard | can be found at http://www.sics.se/~psm/sparcstack.html */
|
451 | 060366c5 | bellard | static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) |
452 | 060366c5 | bellard | { |
453 | 060366c5 | bellard | index = (index + cwp * 16) & (16 * NWINDOWS - 1); |
454 | 060366c5 | bellard | /* wrap handling : if cwp is on the last window, then we use the
|
455 | 060366c5 | bellard | registers 'after' the end */
|
456 | 060366c5 | bellard | if (index < 8 && env->cwp == (NWINDOWS - 1)) |
457 | 060366c5 | bellard | index += (16 * NWINDOWS);
|
458 | 060366c5 | bellard | return index;
|
459 | 060366c5 | bellard | } |
460 | 060366c5 | bellard | |
461 | 2623cbaf | bellard | /* save the register window 'cwp1' */
|
462 | 2623cbaf | bellard | static inline void save_window_offset(CPUSPARCState *env, int cwp1) |
463 | 060366c5 | bellard | { |
464 | 2623cbaf | bellard | unsigned int i; |
465 | 53a5960a | pbrook | target_ulong sp_ptr; |
466 | 060366c5 | bellard | |
467 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
468 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
469 | 060366c5 | bellard | printf("win_overflow: sp_ptr=0x%x save_cwp=%d\n",
|
470 | 060366c5 | bellard | (int)sp_ptr, cwp1);
|
471 | 060366c5 | bellard | #endif
|
472 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
473 | 53a5960a | pbrook | tputl(sp_ptr, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
|
474 | 53a5960a | pbrook | sp_ptr += sizeof(target_ulong);
|
475 | 2623cbaf | bellard | } |
476 | 060366c5 | bellard | } |
477 | 060366c5 | bellard | |
478 | 060366c5 | bellard | static void save_window(CPUSPARCState *env) |
479 | 060366c5 | bellard | { |
480 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
481 | 2623cbaf | bellard | unsigned int new_wim; |
482 | 2623cbaf | bellard | new_wim = ((env->wim >> 1) | (env->wim << (NWINDOWS - 1))) & |
483 | 2623cbaf | bellard | ((1LL << NWINDOWS) - 1); |
484 | 2623cbaf | bellard | save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1)); |
485 | 2623cbaf | bellard | env->wim = new_wim; |
486 | 5ef54116 | bellard | #else
|
487 | 5ef54116 | bellard | save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1)); |
488 | 5ef54116 | bellard | env->cansave++; |
489 | 5ef54116 | bellard | env->canrestore--; |
490 | 5ef54116 | bellard | #endif
|
491 | 060366c5 | bellard | } |
492 | 060366c5 | bellard | |
493 | 060366c5 | bellard | static void restore_window(CPUSPARCState *env) |
494 | 060366c5 | bellard | { |
495 | 060366c5 | bellard | unsigned int new_wim, i, cwp1; |
496 | 53a5960a | pbrook | target_ulong sp_ptr; |
497 | 060366c5 | bellard | |
498 | 060366c5 | bellard | new_wim = ((env->wim << 1) | (env->wim >> (NWINDOWS - 1))) & |
499 | 060366c5 | bellard | ((1LL << NWINDOWS) - 1); |
500 | 060366c5 | bellard | |
501 | 060366c5 | bellard | /* restore the invalid window */
|
502 | 060366c5 | bellard | cwp1 = (env->cwp + 1) & (NWINDOWS - 1); |
503 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
504 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
505 | 060366c5 | bellard | printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
|
506 | 060366c5 | bellard | (int)sp_ptr, cwp1);
|
507 | 060366c5 | bellard | #endif
|
508 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
509 | 53a5960a | pbrook | env->regbase[get_reg_index(env, cwp1, 8 + i)] = tgetl(sp_ptr);
|
510 | 53a5960a | pbrook | sp_ptr += sizeof(target_ulong);
|
511 | 2623cbaf | bellard | } |
512 | 060366c5 | bellard | env->wim = new_wim; |
513 | 5ef54116 | bellard | #ifdef TARGET_SPARC64
|
514 | 5ef54116 | bellard | env->canrestore++; |
515 | 5ef54116 | bellard | if (env->cleanwin < NWINDOWS - 1) |
516 | 5ef54116 | bellard | env->cleanwin++; |
517 | 5ef54116 | bellard | env->cansave--; |
518 | 5ef54116 | bellard | #endif
|
519 | 060366c5 | bellard | } |
520 | 060366c5 | bellard | |
521 | 060366c5 | bellard | static void flush_windows(CPUSPARCState *env) |
522 | 060366c5 | bellard | { |
523 | 060366c5 | bellard | int offset, cwp1;
|
524 | 2623cbaf | bellard | |
525 | 2623cbaf | bellard | offset = 1;
|
526 | 060366c5 | bellard | for(;;) {
|
527 | 060366c5 | bellard | /* if restore would invoke restore_window(), then we can stop */
|
528 | 2623cbaf | bellard | cwp1 = (env->cwp + offset) & (NWINDOWS - 1);
|
529 | 060366c5 | bellard | if (env->wim & (1 << cwp1)) |
530 | 060366c5 | bellard | break;
|
531 | 2623cbaf | bellard | save_window_offset(env, cwp1); |
532 | 060366c5 | bellard | offset++; |
533 | 060366c5 | bellard | } |
534 | 2623cbaf | bellard | /* set wim so that restore will reload the registers */
|
535 | 2623cbaf | bellard | cwp1 = (env->cwp + 1) & (NWINDOWS - 1); |
536 | 2623cbaf | bellard | env->wim = 1 << cwp1;
|
537 | 2623cbaf | bellard | #if defined(DEBUG_WIN)
|
538 | 2623cbaf | bellard | printf("flush_windows: nb=%d\n", offset - 1); |
539 | 80a9d035 | bellard | #endif
|
540 | 2623cbaf | bellard | } |
541 | 060366c5 | bellard | |
542 | 93ac68bc | bellard | void cpu_loop (CPUSPARCState *env)
|
543 | 93ac68bc | bellard | { |
544 | 060366c5 | bellard | int trapnr, ret;
|
545 | 61ff6f58 | bellard | target_siginfo_t info; |
546 | 060366c5 | bellard | |
547 | 060366c5 | bellard | while (1) { |
548 | 060366c5 | bellard | trapnr = cpu_sparc_exec (env); |
549 | 060366c5 | bellard | |
550 | 060366c5 | bellard | switch (trapnr) {
|
551 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
552 | 060366c5 | bellard | case 0x88: |
553 | 060366c5 | bellard | case 0x90: |
554 | 5ef54116 | bellard | #else
|
555 | 5ef54116 | bellard | case 0x16d: |
556 | 5ef54116 | bellard | #endif
|
557 | 060366c5 | bellard | ret = do_syscall (env, env->gregs[1],
|
558 | 060366c5 | bellard | env->regwptr[0], env->regwptr[1], |
559 | 060366c5 | bellard | env->regwptr[2], env->regwptr[3], |
560 | 060366c5 | bellard | env->regwptr[4], env->regwptr[5]); |
561 | 060366c5 | bellard | if ((unsigned int)ret >= (unsigned int)(-515)) { |
562 | 27908725 | bellard | #ifdef TARGET_SPARC64
|
563 | 27908725 | bellard | env->xcc |= PSR_CARRY; |
564 | 27908725 | bellard | #else
|
565 | 060366c5 | bellard | env->psr |= PSR_CARRY; |
566 | 27908725 | bellard | #endif
|
567 | 060366c5 | bellard | ret = -ret; |
568 | 060366c5 | bellard | } else {
|
569 | 27908725 | bellard | #ifdef TARGET_SPARC64
|
570 | 27908725 | bellard | env->xcc &= ~PSR_CARRY; |
571 | 27908725 | bellard | #else
|
572 | 060366c5 | bellard | env->psr &= ~PSR_CARRY; |
573 | 27908725 | bellard | #endif
|
574 | 060366c5 | bellard | } |
575 | 060366c5 | bellard | env->regwptr[0] = ret;
|
576 | 060366c5 | bellard | /* next instruction */
|
577 | 060366c5 | bellard | env->pc = env->npc; |
578 | 060366c5 | bellard | env->npc = env->npc + 4;
|
579 | 060366c5 | bellard | break;
|
580 | 060366c5 | bellard | case 0x83: /* flush windows */ |
581 | 2623cbaf | bellard | flush_windows(env); |
582 | 060366c5 | bellard | /* next instruction */
|
583 | 060366c5 | bellard | env->pc = env->npc; |
584 | 060366c5 | bellard | env->npc = env->npc + 4;
|
585 | 060366c5 | bellard | break;
|
586 | 3475187d | bellard | #ifndef TARGET_SPARC64
|
587 | 060366c5 | bellard | case TT_WIN_OVF: /* window overflow */ |
588 | 060366c5 | bellard | save_window(env); |
589 | 060366c5 | bellard | break;
|
590 | 060366c5 | bellard | case TT_WIN_UNF: /* window underflow */ |
591 | 060366c5 | bellard | restore_window(env); |
592 | 060366c5 | bellard | break;
|
593 | 61ff6f58 | bellard | case TT_TFAULT:
|
594 | 61ff6f58 | bellard | case TT_DFAULT:
|
595 | 61ff6f58 | bellard | { |
596 | 61ff6f58 | bellard | info.si_signo = SIGSEGV; |
597 | 61ff6f58 | bellard | info.si_errno = 0;
|
598 | 61ff6f58 | bellard | /* XXX: check env->error_code */
|
599 | 61ff6f58 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
600 | 61ff6f58 | bellard | info._sifields._sigfault._addr = env->mmuregs[4];
|
601 | 61ff6f58 | bellard | queue_signal(info.si_signo, &info); |
602 | 61ff6f58 | bellard | } |
603 | 61ff6f58 | bellard | break;
|
604 | 3475187d | bellard | #else
|
605 | 5ef54116 | bellard | case TT_SPILL: /* window overflow */ |
606 | 5ef54116 | bellard | save_window(env); |
607 | 5ef54116 | bellard | break;
|
608 | 5ef54116 | bellard | case TT_FILL: /* window underflow */ |
609 | 5ef54116 | bellard | restore_window(env); |
610 | 5ef54116 | bellard | break;
|
611 | 3475187d | bellard | // XXX
|
612 | 3475187d | bellard | #endif
|
613 | 48dc41eb | bellard | case EXCP_INTERRUPT:
|
614 | 48dc41eb | bellard | /* just indicate that signals should be handled asap */
|
615 | 48dc41eb | bellard | break;
|
616 | 1fddef4b | bellard | case EXCP_DEBUG:
|
617 | 1fddef4b | bellard | { |
618 | 1fddef4b | bellard | int sig;
|
619 | 1fddef4b | bellard | |
620 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
621 | 1fddef4b | bellard | if (sig)
|
622 | 1fddef4b | bellard | { |
623 | 1fddef4b | bellard | info.si_signo = sig; |
624 | 1fddef4b | bellard | info.si_errno = 0;
|
625 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
626 | 1fddef4b | bellard | queue_signal(info.si_signo, &info); |
627 | 1fddef4b | bellard | } |
628 | 1fddef4b | bellard | } |
629 | 1fddef4b | bellard | break;
|
630 | 060366c5 | bellard | default:
|
631 | 060366c5 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
632 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
633 | 060366c5 | bellard | exit (1);
|
634 | 060366c5 | bellard | } |
635 | 060366c5 | bellard | process_pending_signals (env); |
636 | 060366c5 | bellard | } |
637 | 93ac68bc | bellard | } |
638 | 93ac68bc | bellard | |
639 | 93ac68bc | bellard | #endif
|
640 | 93ac68bc | bellard | |
641 | 67867308 | bellard | #ifdef TARGET_PPC
|
642 | 9fddaa0c | bellard | |
643 | 9fddaa0c | bellard | static inline uint64_t cpu_ppc_get_tb (CPUState *env) |
644 | 9fddaa0c | bellard | { |
645 | 9fddaa0c | bellard | /* TO FIX */
|
646 | 9fddaa0c | bellard | return 0; |
647 | 9fddaa0c | bellard | } |
648 | 9fddaa0c | bellard | |
649 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbl (CPUState *env) |
650 | 9fddaa0c | bellard | { |
651 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) & 0xFFFFFFFF; |
652 | 9fddaa0c | bellard | } |
653 | 9fddaa0c | bellard | |
654 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbu (CPUState *env) |
655 | 9fddaa0c | bellard | { |
656 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) >> 32; |
657 | 9fddaa0c | bellard | } |
658 | 9fddaa0c | bellard | |
659 | 9fddaa0c | bellard | static void cpu_ppc_store_tb (CPUState *env, uint64_t value) |
660 | 9fddaa0c | bellard | { |
661 | 9fddaa0c | bellard | /* TO FIX */
|
662 | 9fddaa0c | bellard | } |
663 | 9fddaa0c | bellard | |
664 | 9fddaa0c | bellard | void cpu_ppc_store_tbu (CPUState *env, uint32_t value)
|
665 | 9fddaa0c | bellard | { |
666 | 9fddaa0c | bellard | cpu_ppc_store_tb(env, ((uint64_t)value << 32) | cpu_ppc_load_tbl(env));
|
667 | 9fddaa0c | bellard | } |
668 | 9fddaa0c | bellard | |
669 | 9fddaa0c | bellard | void cpu_ppc_store_tbl (CPUState *env, uint32_t value)
|
670 | 9fddaa0c | bellard | { |
671 | 9fddaa0c | bellard | cpu_ppc_store_tb(env, ((uint64_t)cpu_ppc_load_tbl(env) << 32) | value);
|
672 | 9fddaa0c | bellard | } |
673 | 9fddaa0c | bellard | |
674 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_decr (CPUState *env) |
675 | 9fddaa0c | bellard | { |
676 | 9fddaa0c | bellard | /* TO FIX */
|
677 | 9fddaa0c | bellard | return -1; |
678 | 9fddaa0c | bellard | } |
679 | 9fddaa0c | bellard | |
680 | 9fddaa0c | bellard | void cpu_ppc_store_decr (CPUState *env, uint32_t value)
|
681 | 9fddaa0c | bellard | { |
682 | 9fddaa0c | bellard | /* TO FIX */
|
683 | 9fddaa0c | bellard | } |
684 | 9fddaa0c | bellard | |
685 | 67867308 | bellard | void cpu_loop(CPUPPCState *env)
|
686 | 67867308 | bellard | { |
687 | 67867308 | bellard | target_siginfo_t info; |
688 | 61190b14 | bellard | int trapnr;
|
689 | 61190b14 | bellard | uint32_t ret; |
690 | 67867308 | bellard | |
691 | 67867308 | bellard | for(;;) {
|
692 | 67867308 | bellard | trapnr = cpu_ppc_exec(env); |
693 | 61190b14 | bellard | if (trapnr != EXCP_SYSCALL_USER && trapnr != EXCP_BRANCH &&
|
694 | 61190b14 | bellard | trapnr != EXCP_TRACE) { |
695 | 61190b14 | bellard | if (loglevel > 0) { |
696 | 7fe48483 | bellard | cpu_dump_state(env, logfile, fprintf, 0);
|
697 | 61190b14 | bellard | } |
698 | 61190b14 | bellard | } |
699 | 67867308 | bellard | switch(trapnr) {
|
700 | 67867308 | bellard | case EXCP_NONE:
|
701 | 67867308 | bellard | break;
|
702 | 61190b14 | bellard | case EXCP_SYSCALL_USER:
|
703 | 61190b14 | bellard | /* system call */
|
704 | 61190b14 | bellard | /* WARNING:
|
705 | 61190b14 | bellard | * PPC ABI uses overflow flag in cr0 to signal an error
|
706 | 61190b14 | bellard | * in syscalls.
|
707 | 61190b14 | bellard | */
|
708 | 67867308 | bellard | #if 0
|
709 | 61190b14 | bellard | printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env->gpr[0],
|
710 | 61190b14 | bellard | env->gpr[3], env->gpr[4], env->gpr[5], env->gpr[6]);
|
711 | 67867308 | bellard | #endif
|
712 | 61190b14 | bellard | env->crf[0] &= ~0x1; |
713 | 61190b14 | bellard | ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4], |
714 | 61190b14 | bellard | env->gpr[5], env->gpr[6], env->gpr[7], |
715 | 61190b14 | bellard | env->gpr[8]);
|
716 | 61190b14 | bellard | if (ret > (uint32_t)(-515)) { |
717 | 61190b14 | bellard | env->crf[0] |= 0x1; |
718 | 61190b14 | bellard | ret = -ret; |
719 | 61190b14 | bellard | } |
720 | 61190b14 | bellard | env->gpr[3] = ret;
|
721 | 61190b14 | bellard | #if 0
|
722 | 61190b14 | bellard | printf("syscall returned 0x%08x (%d)\n", ret, ret);
|
723 | 61190b14 | bellard | #endif
|
724 | 61190b14 | bellard | break;
|
725 | 61190b14 | bellard | case EXCP_RESET:
|
726 | 61190b14 | bellard | /* Should not happen ! */
|
727 | 61190b14 | bellard | fprintf(stderr, "RESET asked... Stop emulation\n");
|
728 | 61190b14 | bellard | if (loglevel)
|
729 | 61190b14 | bellard | fprintf(logfile, "RESET asked... Stop emulation\n");
|
730 | 67867308 | bellard | abort(); |
731 | 61190b14 | bellard | case EXCP_MACHINE_CHECK:
|
732 | 61190b14 | bellard | fprintf(stderr, "Machine check exeption... Stop emulation\n");
|
733 | 61190b14 | bellard | if (loglevel)
|
734 | 61190b14 | bellard | fprintf(logfile, "RESET asked... Stop emulation\n");
|
735 | 61190b14 | bellard | info.si_signo = TARGET_SIGBUS; |
736 | 67867308 | bellard | info.si_errno = 0;
|
737 | 61190b14 | bellard | info.si_code = TARGET_BUS_OBJERR; |
738 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
739 | 61190b14 | bellard | queue_signal(info.si_signo, &info); |
740 | 61190b14 | bellard | case EXCP_DSI:
|
741 | 3fc6c082 | bellard | fprintf(stderr, "Invalid data memory access: 0x%08x\n",
|
742 | 3fc6c082 | bellard | env->spr[SPR_DAR]); |
743 | 61190b14 | bellard | if (loglevel) {
|
744 | 61190b14 | bellard | fprintf(logfile, "Invalid data memory access: 0x%08x\n",
|
745 | 3fc6c082 | bellard | env->spr[SPR_DAR]); |
746 | 61190b14 | bellard | } |
747 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
748 | 2be0071f | bellard | case 0x40000000: |
749 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
750 | 61190b14 | bellard | info.si_errno = 0;
|
751 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
752 | 61190b14 | bellard | break;
|
753 | 2be0071f | bellard | case 0x04000000: |
754 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
755 | 61190b14 | bellard | info.si_errno = 0;
|
756 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
757 | 61190b14 | bellard | break;
|
758 | 2be0071f | bellard | case 0x08000000: |
759 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
760 | 61190b14 | bellard | info.si_errno = 0;
|
761 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
762 | 61190b14 | bellard | break;
|
763 | 61190b14 | bellard | default:
|
764 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
765 | 61190b14 | bellard | fprintf(stderr, "Invalid segfault errno (%02x)\n",
|
766 | 61190b14 | bellard | env->error_code); |
767 | 61190b14 | bellard | if (loglevel) {
|
768 | 61190b14 | bellard | fprintf(logfile, "Invalid segfault errno (%02x)\n",
|
769 | 61190b14 | bellard | env->error_code); |
770 | 61190b14 | bellard | } |
771 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
772 | 61190b14 | bellard | info.si_errno = 0;
|
773 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
774 | 61190b14 | bellard | break;
|
775 | 61190b14 | bellard | } |
776 | 67867308 | bellard | info._sifields._sigfault._addr = env->nip; |
777 | 67867308 | bellard | queue_signal(info.si_signo, &info); |
778 | 67867308 | bellard | break;
|
779 | 61190b14 | bellard | case EXCP_ISI:
|
780 | 67867308 | bellard | fprintf(stderr, "Invalid instruction fetch\n");
|
781 | 61190b14 | bellard | if (loglevel)
|
782 | 61190b14 | bellard | fprintf(logfile, "Invalid instruction fetch\n");
|
783 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
784 | 2be0071f | bellard | case 0x40000000: |
785 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
786 | 67867308 | bellard | info.si_errno = 0;
|
787 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
788 | 61190b14 | bellard | break;
|
789 | 2be0071f | bellard | case 0x10000000: |
790 | 2be0071f | bellard | case 0x08000000: |
791 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
792 | 61190b14 | bellard | info.si_errno = 0;
|
793 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
794 | 61190b14 | bellard | break;
|
795 | 61190b14 | bellard | default:
|
796 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
797 | 61190b14 | bellard | fprintf(stderr, "Invalid segfault errno (%02x)\n",
|
798 | 61190b14 | bellard | env->error_code); |
799 | 61190b14 | bellard | if (loglevel) {
|
800 | 61190b14 | bellard | fprintf(logfile, "Invalid segfault errno (%02x)\n",
|
801 | 61190b14 | bellard | env->error_code); |
802 | 61190b14 | bellard | } |
803 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
804 | 61190b14 | bellard | info.si_errno = 0;
|
805 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
806 | 61190b14 | bellard | break;
|
807 | 61190b14 | bellard | } |
808 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
809 | 67867308 | bellard | queue_signal(info.si_signo, &info); |
810 | 67867308 | bellard | break;
|
811 | 61190b14 | bellard | case EXCP_EXTERNAL:
|
812 | 61190b14 | bellard | /* Should not happen ! */
|
813 | 61190b14 | bellard | fprintf(stderr, "External interruption... Stop emulation\n");
|
814 | 61190b14 | bellard | if (loglevel)
|
815 | 61190b14 | bellard | fprintf(logfile, "External interruption... Stop emulation\n");
|
816 | 67867308 | bellard | abort(); |
817 | 61190b14 | bellard | case EXCP_ALIGN:
|
818 | 61190b14 | bellard | fprintf(stderr, "Invalid unaligned memory access\n");
|
819 | 61190b14 | bellard | if (loglevel)
|
820 | 61190b14 | bellard | fprintf(logfile, "Invalid unaligned memory access\n");
|
821 | 61190b14 | bellard | info.si_signo = TARGET_SIGBUS; |
822 | 67867308 | bellard | info.si_errno = 0;
|
823 | 61190b14 | bellard | info.si_code = TARGET_BUS_ADRALN; |
824 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
825 | 67867308 | bellard | queue_signal(info.si_signo, &info); |
826 | 67867308 | bellard | break;
|
827 | 61190b14 | bellard | case EXCP_PROGRAM:
|
828 | 61190b14 | bellard | switch (env->error_code & ~0xF) { |
829 | 61190b14 | bellard | case EXCP_FP:
|
830 | 61190b14 | bellard | fprintf(stderr, "Program exception\n");
|
831 | 61190b14 | bellard | if (loglevel)
|
832 | 61190b14 | bellard | fprintf(logfile, "Program exception\n");
|
833 | 61190b14 | bellard | /* Set FX */
|
834 | 61190b14 | bellard | env->fpscr[7] |= 0x8; |
835 | 61190b14 | bellard | /* Finally, update FEX */
|
836 | 61190b14 | bellard | if ((((env->fpscr[7] & 0x3) << 3) | (env->fpscr[6] >> 1)) & |
837 | 61190b14 | bellard | ((env->fpscr[1] << 1) | (env->fpscr[0] >> 3))) |
838 | 61190b14 | bellard | env->fpscr[7] |= 0x4; |
839 | 61190b14 | bellard | info.si_signo = TARGET_SIGFPE; |
840 | 61190b14 | bellard | info.si_errno = 0;
|
841 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
842 | 61190b14 | bellard | case EXCP_FP_OX:
|
843 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTOVF; |
844 | 61190b14 | bellard | break;
|
845 | 61190b14 | bellard | case EXCP_FP_UX:
|
846 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTUND; |
847 | 61190b14 | bellard | break;
|
848 | 61190b14 | bellard | case EXCP_FP_ZX:
|
849 | 61190b14 | bellard | case EXCP_FP_VXZDZ:
|
850 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTDIV; |
851 | 61190b14 | bellard | break;
|
852 | 61190b14 | bellard | case EXCP_FP_XX:
|
853 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTRES; |
854 | 61190b14 | bellard | break;
|
855 | 61190b14 | bellard | case EXCP_FP_VXSOFT:
|
856 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTINV; |
857 | 61190b14 | bellard | break;
|
858 | 61190b14 | bellard | case EXCP_FP_VXNAN:
|
859 | 61190b14 | bellard | case EXCP_FP_VXISI:
|
860 | 61190b14 | bellard | case EXCP_FP_VXIDI:
|
861 | 61190b14 | bellard | case EXCP_FP_VXIMZ:
|
862 | 61190b14 | bellard | case EXCP_FP_VXVC:
|
863 | 61190b14 | bellard | case EXCP_FP_VXSQRT:
|
864 | 61190b14 | bellard | case EXCP_FP_VXCVI:
|
865 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTSUB; |
866 | 61190b14 | bellard | break;
|
867 | 61190b14 | bellard | default:
|
868 | 61190b14 | bellard | fprintf(stderr, "Unknown floating point exception "
|
869 | 61190b14 | bellard | "(%02x)\n", env->error_code);
|
870 | 61190b14 | bellard | if (loglevel) {
|
871 | 61190b14 | bellard | fprintf(logfile, "Unknown floating point exception "
|
872 | 61190b14 | bellard | "(%02x)\n", env->error_code & 0xF); |
873 | 61190b14 | bellard | } |
874 | 61190b14 | bellard | } |
875 | 61190b14 | bellard | break;
|
876 | 67867308 | bellard | case EXCP_INVAL:
|
877 | 61190b14 | bellard | fprintf(stderr, "Invalid instruction\n");
|
878 | 61190b14 | bellard | if (loglevel)
|
879 | 61190b14 | bellard | fprintf(logfile, "Invalid instruction\n");
|
880 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
881 | 61190b14 | bellard | info.si_errno = 0;
|
882 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
883 | 61190b14 | bellard | case EXCP_INVAL_INVAL:
|
884 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLOPC; |
885 | 61190b14 | bellard | break;
|
886 | 61190b14 | bellard | case EXCP_INVAL_LSWX:
|
887 | 67867308 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
888 | 61190b14 | bellard | break;
|
889 | 61190b14 | bellard | case EXCP_INVAL_SPR:
|
890 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
891 | 61190b14 | bellard | break;
|
892 | 61190b14 | bellard | case EXCP_INVAL_FP:
|
893 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
894 | 61190b14 | bellard | break;
|
895 | 61190b14 | bellard | default:
|
896 | 61190b14 | bellard | fprintf(stderr, "Unknown invalid operation (%02x)\n",
|
897 | 61190b14 | bellard | env->error_code & 0xF);
|
898 | 61190b14 | bellard | if (loglevel) {
|
899 | 61190b14 | bellard | fprintf(logfile, "Unknown invalid operation (%02x)\n",
|
900 | 61190b14 | bellard | env->error_code & 0xF);
|
901 | 61190b14 | bellard | } |
902 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
903 | 61190b14 | bellard | break;
|
904 | 61190b14 | bellard | } |
905 | 61190b14 | bellard | break;
|
906 | 61190b14 | bellard | case EXCP_PRIV:
|
907 | 61190b14 | bellard | fprintf(stderr, "Privilege violation\n");
|
908 | 61190b14 | bellard | if (loglevel)
|
909 | 61190b14 | bellard | fprintf(logfile, "Privilege violation\n");
|
910 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
911 | 61190b14 | bellard | info.si_errno = 0;
|
912 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
913 | 61190b14 | bellard | case EXCP_PRIV_OPC:
|
914 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
915 | 61190b14 | bellard | break;
|
916 | 61190b14 | bellard | case EXCP_PRIV_REG:
|
917 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
918 | 61190b14 | bellard | break;
|
919 | 61190b14 | bellard | default:
|
920 | 61190b14 | bellard | fprintf(stderr, "Unknown privilege violation (%02x)\n",
|
921 | 61190b14 | bellard | env->error_code & 0xF);
|
922 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
923 | 61190b14 | bellard | break;
|
924 | 61190b14 | bellard | } |
925 | 61190b14 | bellard | break;
|
926 | 61190b14 | bellard | case EXCP_TRAP:
|
927 | 61190b14 | bellard | fprintf(stderr, "Tried to call a TRAP\n");
|
928 | 61190b14 | bellard | if (loglevel)
|
929 | 61190b14 | bellard | fprintf(logfile, "Tried to call a TRAP\n");
|
930 | 61190b14 | bellard | abort(); |
931 | 61190b14 | bellard | default:
|
932 | 61190b14 | bellard | /* Should not happen ! */
|
933 | 61190b14 | bellard | fprintf(stderr, "Unknown program exception (%02x)\n",
|
934 | 61190b14 | bellard | env->error_code); |
935 | 61190b14 | bellard | if (loglevel) {
|
936 | 61190b14 | bellard | fprintf(logfile, "Unknwon program exception (%02x)\n",
|
937 | 61190b14 | bellard | env->error_code); |
938 | 61190b14 | bellard | } |
939 | 61190b14 | bellard | abort(); |
940 | 61190b14 | bellard | } |
941 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
942 | 67867308 | bellard | queue_signal(info.si_signo, &info); |
943 | 67867308 | bellard | break;
|
944 | 61190b14 | bellard | case EXCP_NO_FP:
|
945 | 61190b14 | bellard | fprintf(stderr, "No floating point allowed\n");
|
946 | 61190b14 | bellard | if (loglevel)
|
947 | 61190b14 | bellard | fprintf(logfile, "No floating point allowed\n");
|
948 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
949 | 67867308 | bellard | info.si_errno = 0;
|
950 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
951 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
952 | 67867308 | bellard | queue_signal(info.si_signo, &info); |
953 | 67867308 | bellard | break;
|
954 | 61190b14 | bellard | case EXCP_DECR:
|
955 | 61190b14 | bellard | /* Should not happen ! */
|
956 | 61190b14 | bellard | fprintf(stderr, "Decrementer exception\n");
|
957 | 61190b14 | bellard | if (loglevel)
|
958 | 61190b14 | bellard | fprintf(logfile, "Decrementer exception\n");
|
959 | 61190b14 | bellard | abort(); |
960 | 61190b14 | bellard | case EXCP_TRACE:
|
961 | 61190b14 | bellard | /* Do nothing: we use this to trace execution */
|
962 | 67867308 | bellard | break;
|
963 | 61190b14 | bellard | case EXCP_FP_ASSIST:
|
964 | 61190b14 | bellard | /* Should not happen ! */
|
965 | 61190b14 | bellard | fprintf(stderr, "Floating point assist exception\n");
|
966 | 61190b14 | bellard | if (loglevel)
|
967 | 61190b14 | bellard | fprintf(logfile, "Floating point assist exception\n");
|
968 | 61190b14 | bellard | abort(); |
969 | 61190b14 | bellard | case EXCP_MTMSR:
|
970 | 61190b14 | bellard | /* We reloaded the msr, just go on */
|
971 | 9fddaa0c | bellard | if (msr_pr == 0) { |
972 | 61190b14 | bellard | fprintf(stderr, "Tried to go into supervisor mode !\n");
|
973 | 61190b14 | bellard | if (loglevel)
|
974 | 61190b14 | bellard | fprintf(logfile, "Tried to go into supervisor mode !\n");
|
975 | 61190b14 | bellard | abort(); |
976 | 67867308 | bellard | } |
977 | 61190b14 | bellard | break;
|
978 | 61190b14 | bellard | case EXCP_BRANCH:
|
979 | 61190b14 | bellard | /* We stopped because of a jump... */
|
980 | 61190b14 | bellard | break;
|
981 | 61190b14 | bellard | case EXCP_INTERRUPT:
|
982 | 61190b14 | bellard | /* Don't know why this should ever happen... */
|
983 | 61190b14 | bellard | break;
|
984 | 1fddef4b | bellard | case EXCP_DEBUG:
|
985 | 1fddef4b | bellard | { |
986 | 1fddef4b | bellard | int sig;
|
987 | 1fddef4b | bellard | |
988 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
989 | 1fddef4b | bellard | if (sig)
|
990 | 1fddef4b | bellard | { |
991 | 1fddef4b | bellard | info.si_signo = sig; |
992 | 1fddef4b | bellard | info.si_errno = 0;
|
993 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
994 | 1fddef4b | bellard | queue_signal(info.si_signo, &info); |
995 | 1fddef4b | bellard | } |
996 | 1fddef4b | bellard | } |
997 | 1fddef4b | bellard | break;
|
998 | 67867308 | bellard | default:
|
999 | 67867308 | bellard | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
1000 | 67867308 | bellard | trapnr); |
1001 | 61190b14 | bellard | if (loglevel) {
|
1002 | 61190b14 | bellard | fprintf(logfile, "qemu: unhandled CPU exception 0x%02x - "
|
1003 | 61190b14 | bellard | "0x%02x - aborting\n", trapnr, env->error_code);
|
1004 | 61190b14 | bellard | } |
1005 | 67867308 | bellard | abort(); |
1006 | 67867308 | bellard | } |
1007 | 67867308 | bellard | process_pending_signals(env); |
1008 | 67867308 | bellard | } |
1009 | 67867308 | bellard | } |
1010 | 67867308 | bellard | #endif
|
1011 | 67867308 | bellard | |
1012 | 048f6b4d | bellard | #ifdef TARGET_MIPS
|
1013 | 048f6b4d | bellard | |
1014 | 048f6b4d | bellard | #define MIPS_SYS(name, args) args,
|
1015 | 048f6b4d | bellard | |
1016 | 048f6b4d | bellard | static const uint8_t mips_syscall_args[] = { |
1017 | 048f6b4d | bellard | MIPS_SYS(sys_syscall , 0) /* 4000 */ |
1018 | 048f6b4d | bellard | MIPS_SYS(sys_exit , 1)
|
1019 | 048f6b4d | bellard | MIPS_SYS(sys_fork , 0)
|
1020 | 048f6b4d | bellard | MIPS_SYS(sys_read , 3)
|
1021 | 048f6b4d | bellard | MIPS_SYS(sys_write , 3)
|
1022 | 048f6b4d | bellard | MIPS_SYS(sys_open , 3) /* 4005 */ |
1023 | 048f6b4d | bellard | MIPS_SYS(sys_close , 1)
|
1024 | 048f6b4d | bellard | MIPS_SYS(sys_waitpid , 3)
|
1025 | 048f6b4d | bellard | MIPS_SYS(sys_creat , 2)
|
1026 | 048f6b4d | bellard | MIPS_SYS(sys_link , 2)
|
1027 | 048f6b4d | bellard | MIPS_SYS(sys_unlink , 1) /* 4010 */ |
1028 | 048f6b4d | bellard | MIPS_SYS(sys_execve , 0)
|
1029 | 048f6b4d | bellard | MIPS_SYS(sys_chdir , 1)
|
1030 | 048f6b4d | bellard | MIPS_SYS(sys_time , 1)
|
1031 | 048f6b4d | bellard | MIPS_SYS(sys_mknod , 3)
|
1032 | 048f6b4d | bellard | MIPS_SYS(sys_chmod , 2) /* 4015 */ |
1033 | 048f6b4d | bellard | MIPS_SYS(sys_lchown , 3)
|
1034 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1035 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_stat */ |
1036 | 048f6b4d | bellard | MIPS_SYS(sys_lseek , 3)
|
1037 | 048f6b4d | bellard | MIPS_SYS(sys_getpid , 0) /* 4020 */ |
1038 | 048f6b4d | bellard | MIPS_SYS(sys_mount , 5)
|
1039 | 048f6b4d | bellard | MIPS_SYS(sys_oldumount , 1)
|
1040 | 048f6b4d | bellard | MIPS_SYS(sys_setuid , 1)
|
1041 | 048f6b4d | bellard | MIPS_SYS(sys_getuid , 0)
|
1042 | 048f6b4d | bellard | MIPS_SYS(sys_stime , 1) /* 4025 */ |
1043 | 048f6b4d | bellard | MIPS_SYS(sys_ptrace , 4)
|
1044 | 048f6b4d | bellard | MIPS_SYS(sys_alarm , 1)
|
1045 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_fstat */ |
1046 | 048f6b4d | bellard | MIPS_SYS(sys_pause , 0)
|
1047 | 048f6b4d | bellard | MIPS_SYS(sys_utime , 2) /* 4030 */ |
1048 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1049 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1050 | 048f6b4d | bellard | MIPS_SYS(sys_access , 2)
|
1051 | 048f6b4d | bellard | MIPS_SYS(sys_nice , 1)
|
1052 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4035 */ |
1053 | 048f6b4d | bellard | MIPS_SYS(sys_sync , 0)
|
1054 | 048f6b4d | bellard | MIPS_SYS(sys_kill , 2)
|
1055 | 048f6b4d | bellard | MIPS_SYS(sys_rename , 2)
|
1056 | 048f6b4d | bellard | MIPS_SYS(sys_mkdir , 2)
|
1057 | 048f6b4d | bellard | MIPS_SYS(sys_rmdir , 1) /* 4040 */ |
1058 | 048f6b4d | bellard | MIPS_SYS(sys_dup , 1)
|
1059 | 048f6b4d | bellard | MIPS_SYS(sys_pipe , 0)
|
1060 | 048f6b4d | bellard | MIPS_SYS(sys_times , 1)
|
1061 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1062 | 048f6b4d | bellard | MIPS_SYS(sys_brk , 1) /* 4045 */ |
1063 | 048f6b4d | bellard | MIPS_SYS(sys_setgid , 1)
|
1064 | 048f6b4d | bellard | MIPS_SYS(sys_getgid , 0)
|
1065 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was signal(2) */ |
1066 | 048f6b4d | bellard | MIPS_SYS(sys_geteuid , 0)
|
1067 | 048f6b4d | bellard | MIPS_SYS(sys_getegid , 0) /* 4050 */ |
1068 | 048f6b4d | bellard | MIPS_SYS(sys_acct , 0)
|
1069 | 048f6b4d | bellard | MIPS_SYS(sys_umount , 2)
|
1070 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1071 | 048f6b4d | bellard | MIPS_SYS(sys_ioctl , 3)
|
1072 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl , 3) /* 4055 */ |
1073 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 2)
|
1074 | 048f6b4d | bellard | MIPS_SYS(sys_setpgid , 2)
|
1075 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1076 | 048f6b4d | bellard | MIPS_SYS(sys_olduname , 1)
|
1077 | 048f6b4d | bellard | MIPS_SYS(sys_umask , 1) /* 4060 */ |
1078 | 048f6b4d | bellard | MIPS_SYS(sys_chroot , 1)
|
1079 | 048f6b4d | bellard | MIPS_SYS(sys_ustat , 2)
|
1080 | 048f6b4d | bellard | MIPS_SYS(sys_dup2 , 2)
|
1081 | 048f6b4d | bellard | MIPS_SYS(sys_getppid , 0)
|
1082 | 048f6b4d | bellard | MIPS_SYS(sys_getpgrp , 0) /* 4065 */ |
1083 | 048f6b4d | bellard | MIPS_SYS(sys_setsid , 0)
|
1084 | 048f6b4d | bellard | MIPS_SYS(sys_sigaction , 3)
|
1085 | 048f6b4d | bellard | MIPS_SYS(sys_sgetmask , 0)
|
1086 | 048f6b4d | bellard | MIPS_SYS(sys_ssetmask , 1)
|
1087 | 048f6b4d | bellard | MIPS_SYS(sys_setreuid , 2) /* 4070 */ |
1088 | 048f6b4d | bellard | MIPS_SYS(sys_setregid , 2)
|
1089 | 048f6b4d | bellard | MIPS_SYS(sys_sigsuspend , 0)
|
1090 | 048f6b4d | bellard | MIPS_SYS(sys_sigpending , 1)
|
1091 | 048f6b4d | bellard | MIPS_SYS(sys_sethostname , 2)
|
1092 | 048f6b4d | bellard | MIPS_SYS(sys_setrlimit , 2) /* 4075 */ |
1093 | 048f6b4d | bellard | MIPS_SYS(sys_getrlimit , 2)
|
1094 | 048f6b4d | bellard | MIPS_SYS(sys_getrusage , 2)
|
1095 | 048f6b4d | bellard | MIPS_SYS(sys_gettimeofday, 2)
|
1096 | 048f6b4d | bellard | MIPS_SYS(sys_settimeofday, 2)
|
1097 | 048f6b4d | bellard | MIPS_SYS(sys_getgroups , 2) /* 4080 */ |
1098 | 048f6b4d | bellard | MIPS_SYS(sys_setgroups , 2)
|
1099 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* old_select */ |
1100 | 048f6b4d | bellard | MIPS_SYS(sys_symlink , 2)
|
1101 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_lstat */ |
1102 | 048f6b4d | bellard | MIPS_SYS(sys_readlink , 3) /* 4085 */ |
1103 | 048f6b4d | bellard | MIPS_SYS(sys_uselib , 1)
|
1104 | 048f6b4d | bellard | MIPS_SYS(sys_swapon , 2)
|
1105 | 048f6b4d | bellard | MIPS_SYS(sys_reboot , 3)
|
1106 | 048f6b4d | bellard | MIPS_SYS(old_readdir , 3)
|
1107 | 048f6b4d | bellard | MIPS_SYS(old_mmap , 6) /* 4090 */ |
1108 | 048f6b4d | bellard | MIPS_SYS(sys_munmap , 2)
|
1109 | 048f6b4d | bellard | MIPS_SYS(sys_truncate , 2)
|
1110 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate , 2)
|
1111 | 048f6b4d | bellard | MIPS_SYS(sys_fchmod , 2)
|
1112 | 048f6b4d | bellard | MIPS_SYS(sys_fchown , 3) /* 4095 */ |
1113 | 048f6b4d | bellard | MIPS_SYS(sys_getpriority , 2)
|
1114 | 048f6b4d | bellard | MIPS_SYS(sys_setpriority , 3)
|
1115 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1116 | 048f6b4d | bellard | MIPS_SYS(sys_statfs , 2)
|
1117 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs , 2) /* 4100 */ |
1118 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was ioperm(2) */ |
1119 | 048f6b4d | bellard | MIPS_SYS(sys_socketcall , 2)
|
1120 | 048f6b4d | bellard | MIPS_SYS(sys_syslog , 3)
|
1121 | 048f6b4d | bellard | MIPS_SYS(sys_setitimer , 3)
|
1122 | 048f6b4d | bellard | MIPS_SYS(sys_getitimer , 2) /* 4105 */ |
1123 | 048f6b4d | bellard | MIPS_SYS(sys_newstat , 2)
|
1124 | 048f6b4d | bellard | MIPS_SYS(sys_newlstat , 2)
|
1125 | 048f6b4d | bellard | MIPS_SYS(sys_newfstat , 2)
|
1126 | 048f6b4d | bellard | MIPS_SYS(sys_uname , 1)
|
1127 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4110 was iopl(2) */ |
1128 | 048f6b4d | bellard | MIPS_SYS(sys_vhangup , 0)
|
1129 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_idle() */ |
1130 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_vm86 */ |
1131 | 048f6b4d | bellard | MIPS_SYS(sys_wait4 , 4)
|
1132 | 048f6b4d | bellard | MIPS_SYS(sys_swapoff , 1) /* 4115 */ |
1133 | 048f6b4d | bellard | MIPS_SYS(sys_sysinfo , 1)
|
1134 | 048f6b4d | bellard | MIPS_SYS(sys_ipc , 6)
|
1135 | 048f6b4d | bellard | MIPS_SYS(sys_fsync , 1)
|
1136 | 048f6b4d | bellard | MIPS_SYS(sys_sigreturn , 0)
|
1137 | 048f6b4d | bellard | MIPS_SYS(sys_clone , 0) /* 4120 */ |
1138 | 048f6b4d | bellard | MIPS_SYS(sys_setdomainname, 2)
|
1139 | 048f6b4d | bellard | MIPS_SYS(sys_newuname , 1)
|
1140 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_modify_ldt */ |
1141 | 048f6b4d | bellard | MIPS_SYS(sys_adjtimex , 1)
|
1142 | 048f6b4d | bellard | MIPS_SYS(sys_mprotect , 3) /* 4125 */ |
1143 | 048f6b4d | bellard | MIPS_SYS(sys_sigprocmask , 3)
|
1144 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was create_module */ |
1145 | 048f6b4d | bellard | MIPS_SYS(sys_init_module , 5)
|
1146 | 048f6b4d | bellard | MIPS_SYS(sys_delete_module, 1)
|
1147 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4130 was get_kernel_syms */ |
1148 | 048f6b4d | bellard | MIPS_SYS(sys_quotactl , 0)
|
1149 | 048f6b4d | bellard | MIPS_SYS(sys_getpgid , 1)
|
1150 | 048f6b4d | bellard | MIPS_SYS(sys_fchdir , 1)
|
1151 | 048f6b4d | bellard | MIPS_SYS(sys_bdflush , 2)
|
1152 | 048f6b4d | bellard | MIPS_SYS(sys_sysfs , 3) /* 4135 */ |
1153 | 048f6b4d | bellard | MIPS_SYS(sys_personality , 1)
|
1154 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* for afs_syscall */ |
1155 | 048f6b4d | bellard | MIPS_SYS(sys_setfsuid , 1)
|
1156 | 048f6b4d | bellard | MIPS_SYS(sys_setfsgid , 1)
|
1157 | 048f6b4d | bellard | MIPS_SYS(sys_llseek , 5) /* 4140 */ |
1158 | 048f6b4d | bellard | MIPS_SYS(sys_getdents , 3)
|
1159 | 048f6b4d | bellard | MIPS_SYS(sys_select , 5)
|
1160 | 048f6b4d | bellard | MIPS_SYS(sys_flock , 2)
|
1161 | 048f6b4d | bellard | MIPS_SYS(sys_msync , 3)
|
1162 | 048f6b4d | bellard | MIPS_SYS(sys_readv , 3) /* 4145 */ |
1163 | 048f6b4d | bellard | MIPS_SYS(sys_writev , 3)
|
1164 | 048f6b4d | bellard | MIPS_SYS(sys_cacheflush , 3)
|
1165 | 048f6b4d | bellard | MIPS_SYS(sys_cachectl , 3)
|
1166 | 048f6b4d | bellard | MIPS_SYS(sys_sysmips , 4)
|
1167 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4150 */ |
1168 | 048f6b4d | bellard | MIPS_SYS(sys_getsid , 1)
|
1169 | 048f6b4d | bellard | MIPS_SYS(sys_fdatasync , 0)
|
1170 | 048f6b4d | bellard | MIPS_SYS(sys_sysctl , 1)
|
1171 | 048f6b4d | bellard | MIPS_SYS(sys_mlock , 2)
|
1172 | 048f6b4d | bellard | MIPS_SYS(sys_munlock , 2) /* 4155 */ |
1173 | 048f6b4d | bellard | MIPS_SYS(sys_mlockall , 1)
|
1174 | 048f6b4d | bellard | MIPS_SYS(sys_munlockall , 0)
|
1175 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setparam, 2)
|
1176 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getparam, 2)
|
1177 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setscheduler, 3) /* 4160 */ |
1178 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getscheduler, 1)
|
1179 | 048f6b4d | bellard | MIPS_SYS(sys_sched_yield , 0)
|
1180 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_max, 1)
|
1181 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_min, 1)
|
1182 | 048f6b4d | bellard | MIPS_SYS(sys_sched_rr_get_interval, 2) /* 4165 */ |
1183 | 048f6b4d | bellard | MIPS_SYS(sys_nanosleep, 2)
|
1184 | 048f6b4d | bellard | MIPS_SYS(sys_mremap , 4)
|
1185 | 048f6b4d | bellard | MIPS_SYS(sys_accept , 3)
|
1186 | 048f6b4d | bellard | MIPS_SYS(sys_bind , 3)
|
1187 | 048f6b4d | bellard | MIPS_SYS(sys_connect , 3) /* 4170 */ |
1188 | 048f6b4d | bellard | MIPS_SYS(sys_getpeername , 3)
|
1189 | 048f6b4d | bellard | MIPS_SYS(sys_getsockname , 3)
|
1190 | 048f6b4d | bellard | MIPS_SYS(sys_getsockopt , 5)
|
1191 | 048f6b4d | bellard | MIPS_SYS(sys_listen , 2)
|
1192 | 048f6b4d | bellard | MIPS_SYS(sys_recv , 4) /* 4175 */ |
1193 | 048f6b4d | bellard | MIPS_SYS(sys_recvfrom , 6)
|
1194 | 048f6b4d | bellard | MIPS_SYS(sys_recvmsg , 3)
|
1195 | 048f6b4d | bellard | MIPS_SYS(sys_send , 4)
|
1196 | 048f6b4d | bellard | MIPS_SYS(sys_sendmsg , 3)
|
1197 | 048f6b4d | bellard | MIPS_SYS(sys_sendto , 6) /* 4180 */ |
1198 | 048f6b4d | bellard | MIPS_SYS(sys_setsockopt , 5)
|
1199 | 048f6b4d | bellard | MIPS_SYS(sys_shutdown , 2)
|
1200 | 048f6b4d | bellard | MIPS_SYS(sys_socket , 3)
|
1201 | 048f6b4d | bellard | MIPS_SYS(sys_socketpair , 4)
|
1202 | 048f6b4d | bellard | MIPS_SYS(sys_setresuid , 3) /* 4185 */ |
1203 | 048f6b4d | bellard | MIPS_SYS(sys_getresuid , 3)
|
1204 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_query_module */ |
1205 | 048f6b4d | bellard | MIPS_SYS(sys_poll , 3)
|
1206 | 048f6b4d | bellard | MIPS_SYS(sys_nfsservctl , 3)
|
1207 | 048f6b4d | bellard | MIPS_SYS(sys_setresgid , 3) /* 4190 */ |
1208 | 048f6b4d | bellard | MIPS_SYS(sys_getresgid , 3)
|
1209 | 048f6b4d | bellard | MIPS_SYS(sys_prctl , 5)
|
1210 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigreturn, 0)
|
1211 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigaction, 4)
|
1212 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigprocmask, 4) /* 4195 */ |
1213 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigpending, 2)
|
1214 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigtimedwait, 4)
|
1215 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigqueueinfo, 3)
|
1216 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigsuspend, 0)
|
1217 | 048f6b4d | bellard | MIPS_SYS(sys_pread64 , 6) /* 4200 */ |
1218 | 048f6b4d | bellard | MIPS_SYS(sys_pwrite64 , 6)
|
1219 | 048f6b4d | bellard | MIPS_SYS(sys_chown , 3)
|
1220 | 048f6b4d | bellard | MIPS_SYS(sys_getcwd , 2)
|
1221 | 048f6b4d | bellard | MIPS_SYS(sys_capget , 2)
|
1222 | 048f6b4d | bellard | MIPS_SYS(sys_capset , 2) /* 4205 */ |
1223 | 048f6b4d | bellard | MIPS_SYS(sys_sigaltstack , 0)
|
1224 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile , 4)
|
1225 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1226 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1227 | 048f6b4d | bellard | MIPS_SYS(sys_mmap2 , 6) /* 4210 */ |
1228 | 048f6b4d | bellard | MIPS_SYS(sys_truncate64 , 4)
|
1229 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate64 , 4)
|
1230 | 048f6b4d | bellard | MIPS_SYS(sys_stat64 , 2)
|
1231 | 048f6b4d | bellard | MIPS_SYS(sys_lstat64 , 2)
|
1232 | 048f6b4d | bellard | MIPS_SYS(sys_fstat64 , 2) /* 4215 */ |
1233 | 048f6b4d | bellard | MIPS_SYS(sys_pivot_root , 2)
|
1234 | 048f6b4d | bellard | MIPS_SYS(sys_mincore , 3)
|
1235 | 048f6b4d | bellard | MIPS_SYS(sys_madvise , 3)
|
1236 | 048f6b4d | bellard | MIPS_SYS(sys_getdents64 , 3)
|
1237 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl64 , 3) /* 4220 */ |
1238 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1239 | 048f6b4d | bellard | MIPS_SYS(sys_gettid , 0)
|
1240 | 048f6b4d | bellard | MIPS_SYS(sys_readahead , 5)
|
1241 | 048f6b4d | bellard | MIPS_SYS(sys_setxattr , 5)
|
1242 | 048f6b4d | bellard | MIPS_SYS(sys_lsetxattr , 5) /* 4225 */ |
1243 | 048f6b4d | bellard | MIPS_SYS(sys_fsetxattr , 5)
|
1244 | 048f6b4d | bellard | MIPS_SYS(sys_getxattr , 4)
|
1245 | 048f6b4d | bellard | MIPS_SYS(sys_lgetxattr , 4)
|
1246 | 048f6b4d | bellard | MIPS_SYS(sys_fgetxattr , 4)
|
1247 | 048f6b4d | bellard | MIPS_SYS(sys_listxattr , 3) /* 4230 */ |
1248 | 048f6b4d | bellard | MIPS_SYS(sys_llistxattr , 3)
|
1249 | 048f6b4d | bellard | MIPS_SYS(sys_flistxattr , 3)
|
1250 | 048f6b4d | bellard | MIPS_SYS(sys_removexattr , 2)
|
1251 | 048f6b4d | bellard | MIPS_SYS(sys_lremovexattr, 2)
|
1252 | 048f6b4d | bellard | MIPS_SYS(sys_fremovexattr, 2) /* 4235 */ |
1253 | 048f6b4d | bellard | MIPS_SYS(sys_tkill , 2)
|
1254 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile64 , 5)
|
1255 | 048f6b4d | bellard | MIPS_SYS(sys_futex , 2)
|
1256 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setaffinity, 3)
|
1257 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getaffinity, 3) /* 4240 */ |
1258 | 048f6b4d | bellard | MIPS_SYS(sys_io_setup , 2)
|
1259 | 048f6b4d | bellard | MIPS_SYS(sys_io_destroy , 1)
|
1260 | 048f6b4d | bellard | MIPS_SYS(sys_io_getevents, 5)
|
1261 | 048f6b4d | bellard | MIPS_SYS(sys_io_submit , 3)
|
1262 | 048f6b4d | bellard | MIPS_SYS(sys_io_cancel , 3) /* 4245 */ |
1263 | 048f6b4d | bellard | MIPS_SYS(sys_exit_group , 1)
|
1264 | 048f6b4d | bellard | MIPS_SYS(sys_lookup_dcookie, 3)
|
1265 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_create, 1)
|
1266 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_ctl , 4)
|
1267 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_wait , 3) /* 4250 */ |
1268 | 048f6b4d | bellard | MIPS_SYS(sys_remap_file_pages, 5)
|
1269 | 048f6b4d | bellard | MIPS_SYS(sys_set_tid_address, 1)
|
1270 | 048f6b4d | bellard | MIPS_SYS(sys_restart_syscall, 0)
|
1271 | 048f6b4d | bellard | MIPS_SYS(sys_fadvise64_64, 7)
|
1272 | 048f6b4d | bellard | MIPS_SYS(sys_statfs64 , 3) /* 4255 */ |
1273 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs64 , 2)
|
1274 | 048f6b4d | bellard | MIPS_SYS(sys_timer_create, 3)
|
1275 | 048f6b4d | bellard | MIPS_SYS(sys_timer_settime, 4)
|
1276 | 048f6b4d | bellard | MIPS_SYS(sys_timer_gettime, 2)
|
1277 | 048f6b4d | bellard | MIPS_SYS(sys_timer_getoverrun, 1) /* 4260 */ |
1278 | 048f6b4d | bellard | MIPS_SYS(sys_timer_delete, 1)
|
1279 | 048f6b4d | bellard | MIPS_SYS(sys_clock_settime, 2)
|
1280 | 048f6b4d | bellard | MIPS_SYS(sys_clock_gettime, 2)
|
1281 | 048f6b4d | bellard | MIPS_SYS(sys_clock_getres, 2)
|
1282 | 048f6b4d | bellard | MIPS_SYS(sys_clock_nanosleep, 4) /* 4265 */ |
1283 | 048f6b4d | bellard | MIPS_SYS(sys_tgkill , 3)
|
1284 | 048f6b4d | bellard | MIPS_SYS(sys_utimes , 2)
|
1285 | 048f6b4d | bellard | MIPS_SYS(sys_mbind , 4)
|
1286 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_get_mempolicy */ |
1287 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4270 sys_set_mempolicy */ |
1288 | 048f6b4d | bellard | MIPS_SYS(sys_mq_open , 4)
|
1289 | 048f6b4d | bellard | MIPS_SYS(sys_mq_unlink , 1)
|
1290 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedsend, 5)
|
1291 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedreceive, 5)
|
1292 | 048f6b4d | bellard | MIPS_SYS(sys_mq_notify , 2) /* 4275 */ |
1293 | 048f6b4d | bellard | MIPS_SYS(sys_mq_getsetattr, 3)
|
1294 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_vserver */ |
1295 | 048f6b4d | bellard | MIPS_SYS(sys_waitid , 4)
|
1296 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* available, was setaltroot */ |
1297 | 048f6b4d | bellard | MIPS_SYS(sys_add_key , 5)
|
1298 | 048f6b4d | bellard | MIPS_SYS(sys_request_key , 4)
|
1299 | 048f6b4d | bellard | MIPS_SYS(sys_keyctl , 5)
|
1300 | 048f6b4d | bellard | }; |
1301 | 048f6b4d | bellard | |
1302 | 048f6b4d | bellard | #undef MIPS_SYS
|
1303 | 048f6b4d | bellard | |
1304 | 048f6b4d | bellard | void cpu_loop(CPUMIPSState *env)
|
1305 | 048f6b4d | bellard | { |
1306 | 048f6b4d | bellard | target_siginfo_t info; |
1307 | 048f6b4d | bellard | int trapnr, ret, nb_args;
|
1308 | 048f6b4d | bellard | unsigned int syscall_num; |
1309 | 048f6b4d | bellard | target_ulong arg5, arg6, sp_reg; |
1310 | 048f6b4d | bellard | |
1311 | 048f6b4d | bellard | for(;;) {
|
1312 | 048f6b4d | bellard | trapnr = cpu_mips_exec(env); |
1313 | 048f6b4d | bellard | switch(trapnr) {
|
1314 | 048f6b4d | bellard | case EXCP_SYSCALL:
|
1315 | 048f6b4d | bellard | { |
1316 | 048f6b4d | bellard | syscall_num = env->gpr[2] - 4000; |
1317 | 106ec879 | bellard | env->PC += 4;
|
1318 | 048f6b4d | bellard | if (syscall_num >= sizeof(mips_syscall_args)) { |
1319 | 048f6b4d | bellard | ret = -ENOSYS; |
1320 | 048f6b4d | bellard | } else {
|
1321 | 048f6b4d | bellard | nb_args = mips_syscall_args[syscall_num]; |
1322 | 048f6b4d | bellard | if (nb_args >= 5) { |
1323 | 048f6b4d | bellard | sp_reg = env->gpr[29];
|
1324 | 048f6b4d | bellard | /* these arguments are taken from the stack */
|
1325 | 53a5960a | pbrook | arg5 = tgetl(sp_reg + 16);
|
1326 | 048f6b4d | bellard | if (nb_args >= 6) { |
1327 | 53a5960a | pbrook | arg6 = tgetl(sp_reg + 20);
|
1328 | 048f6b4d | bellard | } else {
|
1329 | 048f6b4d | bellard | arg6 = 0;
|
1330 | 048f6b4d | bellard | } |
1331 | 048f6b4d | bellard | } else {
|
1332 | 048f6b4d | bellard | arg5 = 0;
|
1333 | 048f6b4d | bellard | arg6 = 0;
|
1334 | 048f6b4d | bellard | } |
1335 | 048f6b4d | bellard | ret = do_syscall(env, |
1336 | 048f6b4d | bellard | env->gpr[2],
|
1337 | 048f6b4d | bellard | env->gpr[4],
|
1338 | 048f6b4d | bellard | env->gpr[5],
|
1339 | 048f6b4d | bellard | env->gpr[6],
|
1340 | 048f6b4d | bellard | env->gpr[7],
|
1341 | 048f6b4d | bellard | arg5, |
1342 | 048f6b4d | bellard | arg6); |
1343 | 048f6b4d | bellard | } |
1344 | 048f6b4d | bellard | if ((unsigned int)ret >= (unsigned int)(-1133)) { |
1345 | 048f6b4d | bellard | env->gpr[7] = 1; /* error flag */ |
1346 | 048f6b4d | bellard | ret = -ret; |
1347 | 048f6b4d | bellard | env->gpr[0] = ret;
|
1348 | 048f6b4d | bellard | env->gpr[2] = ret;
|
1349 | 048f6b4d | bellard | } else {
|
1350 | 048f6b4d | bellard | env->gpr[7] = 0; /* error flag */ |
1351 | 048f6b4d | bellard | env->gpr[2] = ret;
|
1352 | 048f6b4d | bellard | } |
1353 | 048f6b4d | bellard | } |
1354 | 048f6b4d | bellard | break;
|
1355 | ca7c2b1b | ths | case EXCP_TLBL:
|
1356 | ca7c2b1b | ths | case EXCP_TLBS:
|
1357 | 6900e84b | bellard | case EXCP_CpU:
|
1358 | 048f6b4d | bellard | case EXCP_RI:
|
1359 | bc1ad2de | bellard | info.si_signo = TARGET_SIGILL; |
1360 | bc1ad2de | bellard | info.si_errno = 0;
|
1361 | bc1ad2de | bellard | info.si_code = 0;
|
1362 | bc1ad2de | bellard | queue_signal(info.si_signo, &info); |
1363 | 048f6b4d | bellard | break;
|
1364 | 106ec879 | bellard | case EXCP_INTERRUPT:
|
1365 | 106ec879 | bellard | /* just indicate that signals should be handled asap */
|
1366 | 106ec879 | bellard | break;
|
1367 | d08b2a28 | pbrook | case EXCP_DEBUG:
|
1368 | d08b2a28 | pbrook | { |
1369 | d08b2a28 | pbrook | int sig;
|
1370 | d08b2a28 | pbrook | |
1371 | d08b2a28 | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
1372 | d08b2a28 | pbrook | if (sig)
|
1373 | d08b2a28 | pbrook | { |
1374 | d08b2a28 | pbrook | info.si_signo = sig; |
1375 | d08b2a28 | pbrook | info.si_errno = 0;
|
1376 | d08b2a28 | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
1377 | d08b2a28 | pbrook | queue_signal(info.si_signo, &info); |
1378 | d08b2a28 | pbrook | } |
1379 | d08b2a28 | pbrook | } |
1380 | d08b2a28 | pbrook | break;
|
1381 | 048f6b4d | bellard | default:
|
1382 | 048f6b4d | bellard | // error:
|
1383 | 048f6b4d | bellard | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
1384 | 048f6b4d | bellard | trapnr); |
1385 | 048f6b4d | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
1386 | 048f6b4d | bellard | abort(); |
1387 | 048f6b4d | bellard | } |
1388 | 048f6b4d | bellard | process_pending_signals(env); |
1389 | 048f6b4d | bellard | } |
1390 | 048f6b4d | bellard | } |
1391 | 048f6b4d | bellard | #endif
|
1392 | 048f6b4d | bellard | |
1393 | fdf9b3e8 | bellard | #ifdef TARGET_SH4
|
1394 | fdf9b3e8 | bellard | void cpu_loop (CPUState *env)
|
1395 | fdf9b3e8 | bellard | { |
1396 | fdf9b3e8 | bellard | int trapnr, ret;
|
1397 | 355fb23d | pbrook | target_siginfo_t info; |
1398 | fdf9b3e8 | bellard | |
1399 | fdf9b3e8 | bellard | while (1) { |
1400 | fdf9b3e8 | bellard | trapnr = cpu_sh4_exec (env); |
1401 | fdf9b3e8 | bellard | |
1402 | fdf9b3e8 | bellard | switch (trapnr) {
|
1403 | fdf9b3e8 | bellard | case 0x160: |
1404 | fdf9b3e8 | bellard | ret = do_syscall(env, |
1405 | 9c2a9ea1 | pbrook | env->gregs[3],
|
1406 | 9c2a9ea1 | pbrook | env->gregs[4],
|
1407 | 9c2a9ea1 | pbrook | env->gregs[5],
|
1408 | 9c2a9ea1 | pbrook | env->gregs[6],
|
1409 | 9c2a9ea1 | pbrook | env->gregs[7],
|
1410 | 9c2a9ea1 | pbrook | env->gregs[0],
|
1411 | fdf9b3e8 | bellard | 0);
|
1412 | 9c2a9ea1 | pbrook | env->gregs[0] = ret;
|
1413 | fdf9b3e8 | bellard | env->pc += 2;
|
1414 | fdf9b3e8 | bellard | break;
|
1415 | 355fb23d | pbrook | case EXCP_DEBUG:
|
1416 | 355fb23d | pbrook | { |
1417 | 355fb23d | pbrook | int sig;
|
1418 | 355fb23d | pbrook | |
1419 | 355fb23d | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
1420 | 355fb23d | pbrook | if (sig)
|
1421 | 355fb23d | pbrook | { |
1422 | 355fb23d | pbrook | info.si_signo = sig; |
1423 | 355fb23d | pbrook | info.si_errno = 0;
|
1424 | 355fb23d | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
1425 | 355fb23d | pbrook | queue_signal(info.si_signo, &info); |
1426 | 355fb23d | pbrook | } |
1427 | 355fb23d | pbrook | } |
1428 | 355fb23d | pbrook | break;
|
1429 | fdf9b3e8 | bellard | default:
|
1430 | fdf9b3e8 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
1431 | fdf9b3e8 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
1432 | fdf9b3e8 | bellard | exit (1);
|
1433 | fdf9b3e8 | bellard | } |
1434 | fdf9b3e8 | bellard | process_pending_signals (env); |
1435 | fdf9b3e8 | bellard | } |
1436 | fdf9b3e8 | bellard | } |
1437 | fdf9b3e8 | bellard | #endif
|
1438 | fdf9b3e8 | bellard | |
1439 | e6e5906b | pbrook | #ifdef TARGET_M68K
|
1440 | e6e5906b | pbrook | |
1441 | e6e5906b | pbrook | void cpu_loop(CPUM68KState *env)
|
1442 | e6e5906b | pbrook | { |
1443 | e6e5906b | pbrook | int trapnr;
|
1444 | e6e5906b | pbrook | unsigned int n; |
1445 | e6e5906b | pbrook | target_siginfo_t info; |
1446 | e6e5906b | pbrook | TaskState *ts = env->opaque; |
1447 | e6e5906b | pbrook | |
1448 | e6e5906b | pbrook | for(;;) {
|
1449 | e6e5906b | pbrook | trapnr = cpu_m68k_exec(env); |
1450 | e6e5906b | pbrook | switch(trapnr) {
|
1451 | e6e5906b | pbrook | case EXCP_ILLEGAL:
|
1452 | e6e5906b | pbrook | { |
1453 | e6e5906b | pbrook | if (ts->sim_syscalls) {
|
1454 | e6e5906b | pbrook | uint16_t nr; |
1455 | e6e5906b | pbrook | nr = lduw(env->pc + 2);
|
1456 | e6e5906b | pbrook | env->pc += 4;
|
1457 | e6e5906b | pbrook | do_m68k_simcall(env, nr); |
1458 | e6e5906b | pbrook | } else {
|
1459 | e6e5906b | pbrook | goto do_sigill;
|
1460 | e6e5906b | pbrook | } |
1461 | e6e5906b | pbrook | } |
1462 | e6e5906b | pbrook | break;
|
1463 | e6e5906b | pbrook | case EXCP_HALTED:
|
1464 | e6e5906b | pbrook | /* Semihosing syscall. */
|
1465 | e6e5906b | pbrook | env->pc += 2;
|
1466 | e6e5906b | pbrook | do_m68k_semihosting(env, env->dregs[0]);
|
1467 | e6e5906b | pbrook | break;
|
1468 | e6e5906b | pbrook | case EXCP_LINEA:
|
1469 | e6e5906b | pbrook | case EXCP_LINEF:
|
1470 | e6e5906b | pbrook | case EXCP_UNSUPPORTED:
|
1471 | e6e5906b | pbrook | do_sigill:
|
1472 | e6e5906b | pbrook | info.si_signo = SIGILL; |
1473 | e6e5906b | pbrook | info.si_errno = 0;
|
1474 | e6e5906b | pbrook | info.si_code = TARGET_ILL_ILLOPN; |
1475 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->pc; |
1476 | e6e5906b | pbrook | queue_signal(info.si_signo, &info); |
1477 | e6e5906b | pbrook | break;
|
1478 | e6e5906b | pbrook | case EXCP_TRAP0:
|
1479 | e6e5906b | pbrook | { |
1480 | e6e5906b | pbrook | ts->sim_syscalls = 0;
|
1481 | e6e5906b | pbrook | n = env->dregs[0];
|
1482 | e6e5906b | pbrook | env->pc += 2;
|
1483 | e6e5906b | pbrook | env->dregs[0] = do_syscall(env,
|
1484 | e6e5906b | pbrook | n, |
1485 | e6e5906b | pbrook | env->dregs[1],
|
1486 | e6e5906b | pbrook | env->dregs[2],
|
1487 | e6e5906b | pbrook | env->dregs[3],
|
1488 | e6e5906b | pbrook | env->dregs[4],
|
1489 | e6e5906b | pbrook | env->dregs[5],
|
1490 | e6e5906b | pbrook | env->dregs[6]);
|
1491 | e6e5906b | pbrook | } |
1492 | e6e5906b | pbrook | break;
|
1493 | e6e5906b | pbrook | case EXCP_INTERRUPT:
|
1494 | e6e5906b | pbrook | /* just indicate that signals should be handled asap */
|
1495 | e6e5906b | pbrook | break;
|
1496 | e6e5906b | pbrook | case EXCP_ACCESS:
|
1497 | e6e5906b | pbrook | { |
1498 | e6e5906b | pbrook | info.si_signo = SIGSEGV; |
1499 | e6e5906b | pbrook | info.si_errno = 0;
|
1500 | e6e5906b | pbrook | /* XXX: check env->error_code */
|
1501 | e6e5906b | pbrook | info.si_code = TARGET_SEGV_MAPERR; |
1502 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->mmu.ar; |
1503 | e6e5906b | pbrook | queue_signal(info.si_signo, &info); |
1504 | e6e5906b | pbrook | } |
1505 | e6e5906b | pbrook | break;
|
1506 | e6e5906b | pbrook | case EXCP_DEBUG:
|
1507 | e6e5906b | pbrook | { |
1508 | e6e5906b | pbrook | int sig;
|
1509 | e6e5906b | pbrook | |
1510 | e6e5906b | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
1511 | e6e5906b | pbrook | if (sig)
|
1512 | e6e5906b | pbrook | { |
1513 | e6e5906b | pbrook | info.si_signo = sig; |
1514 | e6e5906b | pbrook | info.si_errno = 0;
|
1515 | e6e5906b | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
1516 | e6e5906b | pbrook | queue_signal(info.si_signo, &info); |
1517 | e6e5906b | pbrook | } |
1518 | e6e5906b | pbrook | } |
1519 | e6e5906b | pbrook | break;
|
1520 | e6e5906b | pbrook | default:
|
1521 | e6e5906b | pbrook | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
1522 | e6e5906b | pbrook | trapnr); |
1523 | e6e5906b | pbrook | cpu_dump_state(env, stderr, fprintf, 0);
|
1524 | e6e5906b | pbrook | abort(); |
1525 | e6e5906b | pbrook | } |
1526 | e6e5906b | pbrook | process_pending_signals(env); |
1527 | e6e5906b | pbrook | } |
1528 | e6e5906b | pbrook | } |
1529 | e6e5906b | pbrook | #endif /* TARGET_M68K */ |
1530 | e6e5906b | pbrook | |
1531 | 31e31b8a | bellard | void usage(void) |
1532 | 31e31b8a | bellard | { |
1533 | 84f2e8ef | bellard | printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2007 Fabrice Bellard\n" |
1534 | 1fddef4b | bellard | "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] program [arguments...]\n" |
1535 | b346ff46 | bellard | "Linux CPU emulator (compiled for %s emulation)\n"
|
1536 | d691f669 | bellard | "\n"
|
1537 | 54936004 | bellard | "-h print this help\n"
|
1538 | 74c33bed | bellard | "-g port wait gdb connection to port\n"
|
1539 | b346ff46 | bellard | "-L path set the elf interpreter prefix (default=%s)\n"
|
1540 | b346ff46 | bellard | "-s size set the stack size in bytes (default=%ld)\n"
|
1541 | 54936004 | bellard | "\n"
|
1542 | 54936004 | bellard | "debug options:\n"
|
1543 | c6981055 | bellard | #ifdef USE_CODE_COPY
|
1544 | c6981055 | bellard | "-no-code-copy disable code copy acceleration\n"
|
1545 | c6981055 | bellard | #endif
|
1546 | 6f1f31c0 | bellard | "-d options activate log (logfile=%s)\n"
|
1547 | 54936004 | bellard | "-p pagesize set the host page size to 'pagesize'\n",
|
1548 | b346ff46 | bellard | TARGET_ARCH, |
1549 | d691f669 | bellard | interp_prefix, |
1550 | 54936004 | bellard | x86_stack_size, |
1551 | 54936004 | bellard | DEBUG_LOGFILE); |
1552 | 74cd30b8 | bellard | _exit(1);
|
1553 | 31e31b8a | bellard | } |
1554 | 31e31b8a | bellard | |
1555 | 9de5e440 | bellard | /* XXX: currently only used for async signals (see signal.c) */
|
1556 | b346ff46 | bellard | CPUState *global_env; |
1557 | 59faf6d6 | bellard | |
1558 | 851e67a1 | bellard | /* used to free thread contexts */
|
1559 | 851e67a1 | bellard | TaskState *first_task_state; |
1560 | 9de5e440 | bellard | |
1561 | 31e31b8a | bellard | int main(int argc, char **argv) |
1562 | 31e31b8a | bellard | { |
1563 | 31e31b8a | bellard | const char *filename; |
1564 | 01ffc75b | bellard | struct target_pt_regs regs1, *regs = ®s1;
|
1565 | 31e31b8a | bellard | struct image_info info1, *info = &info1;
|
1566 | 851e67a1 | bellard | TaskState ts1, *ts = &ts1; |
1567 | b346ff46 | bellard | CPUState *env; |
1568 | 586314f2 | bellard | int optind;
|
1569 | d691f669 | bellard | const char *r; |
1570 | 74c33bed | bellard | int gdbstub_port = 0; |
1571 | d691f669 | bellard | |
1572 | 31e31b8a | bellard | if (argc <= 1) |
1573 | 31e31b8a | bellard | usage(); |
1574 | f801f97e | bellard | |
1575 | cc38b844 | bellard | /* init debug */
|
1576 | cc38b844 | bellard | cpu_set_log_filename(DEBUG_LOGFILE); |
1577 | cc38b844 | bellard | |
1578 | 586314f2 | bellard | optind = 1;
|
1579 | d691f669 | bellard | for(;;) {
|
1580 | d691f669 | bellard | if (optind >= argc)
|
1581 | d691f669 | bellard | break;
|
1582 | d691f669 | bellard | r = argv[optind]; |
1583 | d691f669 | bellard | if (r[0] != '-') |
1584 | d691f669 | bellard | break;
|
1585 | 586314f2 | bellard | optind++; |
1586 | d691f669 | bellard | r++; |
1587 | d691f669 | bellard | if (!strcmp(r, "-")) { |
1588 | d691f669 | bellard | break;
|
1589 | d691f669 | bellard | } else if (!strcmp(r, "d")) { |
1590 | e19e89a5 | bellard | int mask;
|
1591 | e19e89a5 | bellard | CPULogItem *item; |
1592 | 6f1f31c0 | bellard | |
1593 | 6f1f31c0 | bellard | if (optind >= argc)
|
1594 | 6f1f31c0 | bellard | break;
|
1595 | e19e89a5 | bellard | |
1596 | 6f1f31c0 | bellard | r = argv[optind++]; |
1597 | 6f1f31c0 | bellard | mask = cpu_str_to_log_mask(r); |
1598 | e19e89a5 | bellard | if (!mask) {
|
1599 | e19e89a5 | bellard | printf("Log items (comma separated):\n");
|
1600 | e19e89a5 | bellard | for(item = cpu_log_items; item->mask != 0; item++) { |
1601 | e19e89a5 | bellard | printf("%-10s %s\n", item->name, item->help);
|
1602 | e19e89a5 | bellard | } |
1603 | e19e89a5 | bellard | exit(1);
|
1604 | e19e89a5 | bellard | } |
1605 | e19e89a5 | bellard | cpu_set_log(mask); |
1606 | d691f669 | bellard | } else if (!strcmp(r, "s")) { |
1607 | d691f669 | bellard | r = argv[optind++]; |
1608 | d691f669 | bellard | x86_stack_size = strtol(r, (char **)&r, 0); |
1609 | d691f669 | bellard | if (x86_stack_size <= 0) |
1610 | d691f669 | bellard | usage(); |
1611 | d691f669 | bellard | if (*r == 'M') |
1612 | d691f669 | bellard | x86_stack_size *= 1024 * 1024; |
1613 | d691f669 | bellard | else if (*r == 'k' || *r == 'K') |
1614 | d691f669 | bellard | x86_stack_size *= 1024;
|
1615 | d691f669 | bellard | } else if (!strcmp(r, "L")) { |
1616 | d691f669 | bellard | interp_prefix = argv[optind++]; |
1617 | 54936004 | bellard | } else if (!strcmp(r, "p")) { |
1618 | 83fb7adf | bellard | qemu_host_page_size = atoi(argv[optind++]); |
1619 | 83fb7adf | bellard | if (qemu_host_page_size == 0 || |
1620 | 83fb7adf | bellard | (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { |
1621 | 54936004 | bellard | fprintf(stderr, "page size must be a power of two\n");
|
1622 | 54936004 | bellard | exit(1);
|
1623 | 54936004 | bellard | } |
1624 | 1fddef4b | bellard | } else if (!strcmp(r, "g")) { |
1625 | 74c33bed | bellard | gdbstub_port = atoi(argv[optind++]); |
1626 | c5937220 | pbrook | } else if (!strcmp(r, "r")) { |
1627 | c5937220 | pbrook | qemu_uname_release = argv[optind++]; |
1628 | c6981055 | bellard | } else
|
1629 | c6981055 | bellard | #ifdef USE_CODE_COPY
|
1630 | c6981055 | bellard | if (!strcmp(r, "no-code-copy")) { |
1631 | c6981055 | bellard | code_copy_enabled = 0;
|
1632 | c6981055 | bellard | } else
|
1633 | c6981055 | bellard | #endif
|
1634 | c6981055 | bellard | { |
1635 | d691f669 | bellard | usage(); |
1636 | d691f669 | bellard | } |
1637 | 586314f2 | bellard | } |
1638 | d691f669 | bellard | if (optind >= argc)
|
1639 | d691f669 | bellard | usage(); |
1640 | 586314f2 | bellard | filename = argv[optind]; |
1641 | 586314f2 | bellard | |
1642 | 31e31b8a | bellard | /* Zero out regs */
|
1643 | 01ffc75b | bellard | memset(regs, 0, sizeof(struct target_pt_regs)); |
1644 | 31e31b8a | bellard | |
1645 | 31e31b8a | bellard | /* Zero out image_info */
|
1646 | 31e31b8a | bellard | memset(info, 0, sizeof(struct image_info)); |
1647 | 31e31b8a | bellard | |
1648 | 74cd30b8 | bellard | /* Scan interp_prefix dir for replacement files. */
|
1649 | 74cd30b8 | bellard | init_paths(interp_prefix); |
1650 | 74cd30b8 | bellard | |
1651 | 83fb7adf | bellard | /* NOTE: we need to init the CPU at this stage to get
|
1652 | 83fb7adf | bellard | qemu_host_page_size */
|
1653 | b346ff46 | bellard | env = cpu_init(); |
1654 | 15338fd7 | bellard | global_env = env; |
1655 | 92ccca6a | bellard | |
1656 | e5fe0c52 | pbrook | if (loader_exec(filename, argv+optind, environ, regs, info) != 0) { |
1657 | 31e31b8a | bellard | printf("Error loading %s\n", filename);
|
1658 | 74cd30b8 | bellard | _exit(1);
|
1659 | 31e31b8a | bellard | } |
1660 | 31e31b8a | bellard | |
1661 | 4b74fe1f | bellard | if (loglevel) {
|
1662 | 54936004 | bellard | page_dump(logfile); |
1663 | 54936004 | bellard | |
1664 | 4b74fe1f | bellard | fprintf(logfile, "start_brk 0x%08lx\n" , info->start_brk);
|
1665 | 4b74fe1f | bellard | fprintf(logfile, "end_code 0x%08lx\n" , info->end_code);
|
1666 | 4b74fe1f | bellard | fprintf(logfile, "start_code 0x%08lx\n" , info->start_code);
|
1667 | e5fe0c52 | pbrook | fprintf(logfile, "start_data 0x%08lx\n" , info->start_data);
|
1668 | 4b74fe1f | bellard | fprintf(logfile, "end_data 0x%08lx\n" , info->end_data);
|
1669 | 4b74fe1f | bellard | fprintf(logfile, "start_stack 0x%08lx\n" , info->start_stack);
|
1670 | 4b74fe1f | bellard | fprintf(logfile, "brk 0x%08lx\n" , info->brk);
|
1671 | b346ff46 | bellard | fprintf(logfile, "entry 0x%08lx\n" , info->entry);
|
1672 | 4b74fe1f | bellard | } |
1673 | 31e31b8a | bellard | |
1674 | 53a5960a | pbrook | target_set_brk(info->brk); |
1675 | 31e31b8a | bellard | syscall_init(); |
1676 | 66fb9763 | bellard | signal_init(); |
1677 | 31e31b8a | bellard | |
1678 | 851e67a1 | bellard | /* build Task State */
|
1679 | 851e67a1 | bellard | memset(ts, 0, sizeof(TaskState)); |
1680 | 851e67a1 | bellard | env->opaque = ts; |
1681 | 851e67a1 | bellard | ts->used = 1;
|
1682 | 978efd6a | pbrook | ts->info = info; |
1683 | 59faf6d6 | bellard | env->user_mode_only = 1;
|
1684 | 851e67a1 | bellard | |
1685 | b346ff46 | bellard | #if defined(TARGET_I386)
|
1686 | 2e255c6b | bellard | cpu_x86_set_cpl(env, 3);
|
1687 | 2e255c6b | bellard | |
1688 | 3802ce26 | bellard | env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
|
1689 | 1bde465e | bellard | env->hflags |= HF_PE_MASK; |
1690 | 1bde465e | bellard | if (env->cpuid_features & CPUID_SSE) {
|
1691 | 1bde465e | bellard | env->cr[4] |= CR4_OSFXSR_MASK;
|
1692 | 1bde465e | bellard | env->hflags |= HF_OSFXSR_MASK; |
1693 | 1bde465e | bellard | } |
1694 | 1bde465e | bellard | |
1695 | 415e561f | bellard | /* flags setup : we activate the IRQs by default as in user mode */
|
1696 | 415e561f | bellard | env->eflags |= IF_MASK; |
1697 | 415e561f | bellard | |
1698 | 6dbad63e | bellard | /* linux register setup */
|
1699 | 0ecfa993 | bellard | env->regs[R_EAX] = regs->eax; |
1700 | 0ecfa993 | bellard | env->regs[R_EBX] = regs->ebx; |
1701 | 0ecfa993 | bellard | env->regs[R_ECX] = regs->ecx; |
1702 | 0ecfa993 | bellard | env->regs[R_EDX] = regs->edx; |
1703 | 0ecfa993 | bellard | env->regs[R_ESI] = regs->esi; |
1704 | 0ecfa993 | bellard | env->regs[R_EDI] = regs->edi; |
1705 | 0ecfa993 | bellard | env->regs[R_EBP] = regs->ebp; |
1706 | 0ecfa993 | bellard | env->regs[R_ESP] = regs->esp; |
1707 | dab2ed99 | bellard | env->eip = regs->eip; |
1708 | 31e31b8a | bellard | |
1709 | f4beb510 | bellard | /* linux interrupt setup */
|
1710 | 53a5960a | pbrook | env->idt.base = h2g(idt_table); |
1711 | f4beb510 | bellard | env->idt.limit = sizeof(idt_table) - 1; |
1712 | f4beb510 | bellard | set_idt(0, 0); |
1713 | f4beb510 | bellard | set_idt(1, 0); |
1714 | f4beb510 | bellard | set_idt(2, 0); |
1715 | f4beb510 | bellard | set_idt(3, 3); |
1716 | f4beb510 | bellard | set_idt(4, 3); |
1717 | f4beb510 | bellard | set_idt(5, 3); |
1718 | f4beb510 | bellard | set_idt(6, 0); |
1719 | f4beb510 | bellard | set_idt(7, 0); |
1720 | f4beb510 | bellard | set_idt(8, 0); |
1721 | f4beb510 | bellard | set_idt(9, 0); |
1722 | f4beb510 | bellard | set_idt(10, 0); |
1723 | f4beb510 | bellard | set_idt(11, 0); |
1724 | f4beb510 | bellard | set_idt(12, 0); |
1725 | f4beb510 | bellard | set_idt(13, 0); |
1726 | f4beb510 | bellard | set_idt(14, 0); |
1727 | f4beb510 | bellard | set_idt(15, 0); |
1728 | f4beb510 | bellard | set_idt(16, 0); |
1729 | f4beb510 | bellard | set_idt(17, 0); |
1730 | f4beb510 | bellard | set_idt(18, 0); |
1731 | f4beb510 | bellard | set_idt(19, 0); |
1732 | f4beb510 | bellard | set_idt(0x80, 3); |
1733 | f4beb510 | bellard | |
1734 | 6dbad63e | bellard | /* linux segment setup */
|
1735 | 53a5960a | pbrook | env->gdt.base = h2g(gdt_table); |
1736 | 6dbad63e | bellard | env->gdt.limit = sizeof(gdt_table) - 1; |
1737 | f4beb510 | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, |
1738 | f4beb510 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
1739 | f4beb510 | bellard | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); |
1740 | f4beb510 | bellard | write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, |
1741 | f4beb510 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
1742 | f4beb510 | bellard | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); |
1743 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
1744 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
1745 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
1746 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
1747 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_FS, __USER_DS); |
1748 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_GS, __USER_DS); |
1749 | 92ccca6a | bellard | |
1750 | b346ff46 | bellard | #elif defined(TARGET_ARM)
|
1751 | b346ff46 | bellard | { |
1752 | b346ff46 | bellard | int i;
|
1753 | 40f137e1 | pbrook | cpu_arm_set_model(env, ARM_CPUID_ARM1026); |
1754 | b5ff1b31 | bellard | cpsr_write(env, regs->uregs[16], 0xffffffff); |
1755 | b346ff46 | bellard | for(i = 0; i < 16; i++) { |
1756 | b346ff46 | bellard | env->regs[i] = regs->uregs[i]; |
1757 | b346ff46 | bellard | } |
1758 | a4f81979 | bellard | ts->stack_base = info->start_stack; |
1759 | a4f81979 | bellard | ts->heap_base = info->brk; |
1760 | a4f81979 | bellard | /* This will be filled in on the first SYS_HEAPINFO call. */
|
1761 | a4f81979 | bellard | ts->heap_limit = 0;
|
1762 | b346ff46 | bellard | } |
1763 | 93ac68bc | bellard | #elif defined(TARGET_SPARC)
|
1764 | 060366c5 | bellard | { |
1765 | 060366c5 | bellard | int i;
|
1766 | 060366c5 | bellard | env->pc = regs->pc; |
1767 | 060366c5 | bellard | env->npc = regs->npc; |
1768 | 060366c5 | bellard | env->y = regs->y; |
1769 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
1770 | 060366c5 | bellard | env->gregs[i] = regs->u_regs[i]; |
1771 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
1772 | 060366c5 | bellard | env->regwptr[i] = regs->u_regs[i + 8];
|
1773 | 060366c5 | bellard | } |
1774 | 67867308 | bellard | #elif defined(TARGET_PPC)
|
1775 | 67867308 | bellard | { |
1776 | 3fc6c082 | bellard | ppc_def_t *def; |
1777 | 67867308 | bellard | int i;
|
1778 | 3fc6c082 | bellard | |
1779 | 3fc6c082 | bellard | /* Choose and initialise CPU */
|
1780 | 3fc6c082 | bellard | /* XXX: CPU model (or PVR) should be provided on command line */
|
1781 | 3fc6c082 | bellard | // ppc_find_by_name("750gx", &def);
|
1782 | 3fc6c082 | bellard | // ppc_find_by_name("750fx", &def);
|
1783 | 3fc6c082 | bellard | // ppc_find_by_name("750p", &def);
|
1784 | 3fc6c082 | bellard | ppc_find_by_name("750", &def);
|
1785 | 3fc6c082 | bellard | // ppc_find_by_name("G3", &def);
|
1786 | 3fc6c082 | bellard | // ppc_find_by_name("604r", &def);
|
1787 | 3fc6c082 | bellard | // ppc_find_by_name("604e", &def);
|
1788 | 3fc6c082 | bellard | // ppc_find_by_name("604", &def);
|
1789 | 3fc6c082 | bellard | if (def == NULL) { |
1790 | c68ea704 | bellard | cpu_abort(env, |
1791 | 3fc6c082 | bellard | "Unable to find PowerPC CPU definition\n");
|
1792 | 3fc6c082 | bellard | } |
1793 | c68ea704 | bellard | cpu_ppc_register(env, def); |
1794 | 3fc6c082 | bellard | |
1795 | 61190b14 | bellard | for (i = 0; i < 32; i++) { |
1796 | 4c2e770f | bellard | if (i != 12 && i != 6 && i != 13) |
1797 | 61190b14 | bellard | env->msr[i] = (regs->msr >> i) & 1;
|
1798 | 61190b14 | bellard | } |
1799 | 67867308 | bellard | env->nip = regs->nip; |
1800 | 67867308 | bellard | for(i = 0; i < 32; i++) { |
1801 | 67867308 | bellard | env->gpr[i] = regs->gpr[i]; |
1802 | 67867308 | bellard | } |
1803 | 67867308 | bellard | } |
1804 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
1805 | e6e5906b | pbrook | { |
1806 | e6e5906b | pbrook | m68k_def_t *def; |
1807 | e6e5906b | pbrook | def = m68k_find_by_name("cfv4e");
|
1808 | e6e5906b | pbrook | if (def == NULL) { |
1809 | e6e5906b | pbrook | cpu_abort(cpu_single_env, |
1810 | e6e5906b | pbrook | "Unable to find m68k CPU definition\n");
|
1811 | e6e5906b | pbrook | } |
1812 | e6e5906b | pbrook | cpu_m68k_register(cpu_single_env, def); |
1813 | e6e5906b | pbrook | env->pc = regs->pc; |
1814 | e6e5906b | pbrook | env->dregs[0] = regs->d0;
|
1815 | e6e5906b | pbrook | env->dregs[1] = regs->d1;
|
1816 | e6e5906b | pbrook | env->dregs[2] = regs->d2;
|
1817 | e6e5906b | pbrook | env->dregs[3] = regs->d3;
|
1818 | e6e5906b | pbrook | env->dregs[4] = regs->d4;
|
1819 | e6e5906b | pbrook | env->dregs[5] = regs->d5;
|
1820 | e6e5906b | pbrook | env->dregs[6] = regs->d6;
|
1821 | e6e5906b | pbrook | env->dregs[7] = regs->d7;
|
1822 | e6e5906b | pbrook | env->aregs[0] = regs->a0;
|
1823 | e6e5906b | pbrook | env->aregs[1] = regs->a1;
|
1824 | e6e5906b | pbrook | env->aregs[2] = regs->a2;
|
1825 | e6e5906b | pbrook | env->aregs[3] = regs->a3;
|
1826 | e6e5906b | pbrook | env->aregs[4] = regs->a4;
|
1827 | e6e5906b | pbrook | env->aregs[5] = regs->a5;
|
1828 | e6e5906b | pbrook | env->aregs[6] = regs->a6;
|
1829 | e6e5906b | pbrook | env->aregs[7] = regs->usp;
|
1830 | e6e5906b | pbrook | env->sr = regs->sr; |
1831 | e6e5906b | pbrook | ts->sim_syscalls = 1;
|
1832 | e6e5906b | pbrook | } |
1833 | 048f6b4d | bellard | #elif defined(TARGET_MIPS)
|
1834 | 048f6b4d | bellard | { |
1835 | 048f6b4d | bellard | int i;
|
1836 | 048f6b4d | bellard | |
1837 | 048f6b4d | bellard | for(i = 0; i < 32; i++) { |
1838 | 048f6b4d | bellard | env->gpr[i] = regs->regs[i]; |
1839 | 048f6b4d | bellard | } |
1840 | 048f6b4d | bellard | env->PC = regs->cp0_epc; |
1841 | bc1ad2de | bellard | #ifdef MIPS_USES_FPU
|
1842 | bc1ad2de | bellard | env->CP0_Status |= (1 << CP0St_CU1);
|
1843 | bc1ad2de | bellard | #endif
|
1844 | 048f6b4d | bellard | } |
1845 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
1846 | fdf9b3e8 | bellard | { |
1847 | fdf9b3e8 | bellard | int i;
|
1848 | fdf9b3e8 | bellard | |
1849 | fdf9b3e8 | bellard | for(i = 0; i < 16; i++) { |
1850 | fdf9b3e8 | bellard | env->gregs[i] = regs->regs[i]; |
1851 | fdf9b3e8 | bellard | } |
1852 | fdf9b3e8 | bellard | env->pc = regs->pc; |
1853 | fdf9b3e8 | bellard | } |
1854 | b346ff46 | bellard | #else
|
1855 | b346ff46 | bellard | #error unsupported target CPU
|
1856 | b346ff46 | bellard | #endif
|
1857 | 31e31b8a | bellard | |
1858 | 74c33bed | bellard | if (gdbstub_port) {
|
1859 | 74c33bed | bellard | gdbserver_start (gdbstub_port); |
1860 | 1fddef4b | bellard | gdb_handlesig(env, 0);
|
1861 | 1fddef4b | bellard | } |
1862 | 1b6b029e | bellard | cpu_loop(env); |
1863 | 1b6b029e | bellard | /* never exits */
|
1864 | 31e31b8a | bellard | return 0; |
1865 | 31e31b8a | bellard | } |