root / linux-user / main.c @ 9ea37780
History | View | Annotate | Download (96.3 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 93ac68bc | bellard | * qemu user main
|
3 | 5fafdf24 | ths | *
|
4 | 68d0f70e | bellard | * Copyright (c) 2003-2008 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 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 31e31b8a | bellard | */
|
19 | 31e31b8a | bellard | #include <stdlib.h> |
20 | 31e31b8a | bellard | #include <stdio.h> |
21 | 31e31b8a | bellard | #include <stdarg.h> |
22 | 04369ff2 | bellard | #include <string.h> |
23 | 31e31b8a | bellard | #include <errno.h> |
24 | 0ecfa993 | bellard | #include <unistd.h> |
25 | e441570f | balrog | #include <sys/mman.h> |
26 | edf8e2af | Mika Westerberg | #include <sys/syscall.h> |
27 | 31e31b8a | bellard | |
28 | 3ef693a0 | bellard | #include "qemu.h" |
29 | ca10f867 | aurel32 | #include "qemu-common.h" |
30 | 902b3d5c | malc | #include "cache-utils.h" |
31 | d5975363 | pbrook | /* For tb_lock */
|
32 | d5975363 | pbrook | #include "exec-all.h" |
33 | 31e31b8a | bellard | |
34 | 04a6dfeb | aurel32 | |
35 | 04a6dfeb | aurel32 | #include "envlist.h" |
36 | 04a6dfeb | aurel32 | |
37 | 3ef693a0 | bellard | #define DEBUG_LOGFILE "/tmp/qemu.log" |
38 | 586314f2 | bellard | |
39 | d088d664 | aurel32 | char *exec_path;
|
40 | d088d664 | aurel32 | |
41 | 1b530a6d | aurel32 | int singlestep;
|
42 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
43 | 379f6698 | Paul Brook | unsigned long mmap_min_addr; |
44 | 379f6698 | Paul Brook | unsigned long guest_base; |
45 | 379f6698 | Paul Brook | int have_guest_base;
|
46 | 379f6698 | Paul Brook | #endif
|
47 | 1b530a6d | aurel32 | |
48 | 74cd30b8 | bellard | static const char *interp_prefix = CONFIG_QEMU_PREFIX; |
49 | c5937220 | pbrook | const char *qemu_uname_release = CONFIG_UNAME_RELEASE; |
50 | 586314f2 | bellard | |
51 | 9de5e440 | bellard | /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
|
52 | 9de5e440 | bellard | we allocate a bigger stack. Need a better solution, for example
|
53 | 9de5e440 | bellard | by remapping the process stack directly at the right place */
|
54 | 9de5e440 | bellard | unsigned long x86_stack_size = 512 * 1024; |
55 | 31e31b8a | bellard | |
56 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) |
57 | 31e31b8a | bellard | { |
58 | 31e31b8a | bellard | va_list ap; |
59 | 31e31b8a | bellard | |
60 | 31e31b8a | bellard | va_start(ap, fmt); |
61 | 31e31b8a | bellard | vfprintf(stderr, fmt, ap); |
62 | 31e31b8a | bellard | va_end(ap); |
63 | 31e31b8a | bellard | } |
64 | 31e31b8a | bellard | |
65 | 8fcd3692 | blueswir1 | #if defined(TARGET_I386)
|
66 | a541f297 | bellard | int cpu_get_pic_interrupt(CPUState *env)
|
67 | 92ccca6a | bellard | { |
68 | 92ccca6a | bellard | return -1; |
69 | 92ccca6a | bellard | } |
70 | 8fcd3692 | blueswir1 | #endif
|
71 | 92ccca6a | bellard | |
72 | 28ab0e2e | bellard | /* timers for rdtsc */
|
73 | 28ab0e2e | bellard | |
74 | 1dce7c3c | bellard | #if 0
|
75 | 28ab0e2e | bellard | |
76 | 28ab0e2e | bellard | static uint64_t emu_time;
|
77 | 28ab0e2e | bellard | |
78 | 28ab0e2e | bellard | int64_t cpu_get_real_ticks(void)
|
79 | 28ab0e2e | bellard | {
|
80 | 28ab0e2e | bellard | return emu_time++;
|
81 | 28ab0e2e | bellard | }
|
82 | 28ab0e2e | bellard | |
83 | 28ab0e2e | bellard | #endif
|
84 | 28ab0e2e | bellard | |
85 | 2f7bb878 | Juan Quintela | #if defined(CONFIG_USE_NPTL)
|
86 | d5975363 | pbrook | /***********************************************************/
|
87 | d5975363 | pbrook | /* Helper routines for implementing atomic operations. */
|
88 | d5975363 | pbrook | |
89 | d5975363 | pbrook | /* To implement exclusive operations we force all cpus to syncronise.
|
90 | d5975363 | pbrook | We don't require a full sync, only that no cpus are executing guest code.
|
91 | d5975363 | pbrook | The alternative is to map target atomic ops onto host equivalents,
|
92 | d5975363 | pbrook | which requires quite a lot of per host/target work. */
|
93 | c2764719 | pbrook | static pthread_mutex_t cpu_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
94 | d5975363 | pbrook | static pthread_mutex_t exclusive_lock = PTHREAD_MUTEX_INITIALIZER;
|
95 | d5975363 | pbrook | static pthread_cond_t exclusive_cond = PTHREAD_COND_INITIALIZER;
|
96 | d5975363 | pbrook | static pthread_cond_t exclusive_resume = PTHREAD_COND_INITIALIZER;
|
97 | d5975363 | pbrook | static int pending_cpus; |
98 | d5975363 | pbrook | |
99 | d5975363 | pbrook | /* Make sure everything is in a consistent state for calling fork(). */
|
100 | d5975363 | pbrook | void fork_start(void) |
101 | d5975363 | pbrook | { |
102 | d5975363 | pbrook | mmap_fork_start(); |
103 | d5975363 | pbrook | pthread_mutex_lock(&tb_lock); |
104 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
105 | d5975363 | pbrook | } |
106 | d5975363 | pbrook | |
107 | d5975363 | pbrook | void fork_end(int child) |
108 | d5975363 | pbrook | { |
109 | d5975363 | pbrook | if (child) {
|
110 | d5975363 | pbrook | /* Child processes created by fork() only have a single thread.
|
111 | d5975363 | pbrook | Discard information about the parent threads. */
|
112 | d5975363 | pbrook | first_cpu = thread_env; |
113 | d5975363 | pbrook | thread_env->next_cpu = NULL;
|
114 | d5975363 | pbrook | pending_cpus = 0;
|
115 | d5975363 | pbrook | pthread_mutex_init(&exclusive_lock, NULL);
|
116 | c2764719 | pbrook | pthread_mutex_init(&cpu_list_mutex, NULL);
|
117 | d5975363 | pbrook | pthread_cond_init(&exclusive_cond, NULL);
|
118 | d5975363 | pbrook | pthread_cond_init(&exclusive_resume, NULL);
|
119 | d5975363 | pbrook | pthread_mutex_init(&tb_lock, NULL);
|
120 | 2b1319c8 | aurel32 | gdbserver_fork(thread_env); |
121 | d5975363 | pbrook | } else {
|
122 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
123 | d5975363 | pbrook | pthread_mutex_unlock(&tb_lock); |
124 | d5975363 | pbrook | } |
125 | d5975363 | pbrook | mmap_fork_end(child); |
126 | d5975363 | pbrook | } |
127 | d5975363 | pbrook | |
128 | d5975363 | pbrook | /* Wait for pending exclusive operations to complete. The exclusive lock
|
129 | d5975363 | pbrook | must be held. */
|
130 | d5975363 | pbrook | static inline void exclusive_idle(void) |
131 | d5975363 | pbrook | { |
132 | d5975363 | pbrook | while (pending_cpus) {
|
133 | d5975363 | pbrook | pthread_cond_wait(&exclusive_resume, &exclusive_lock); |
134 | d5975363 | pbrook | } |
135 | d5975363 | pbrook | } |
136 | d5975363 | pbrook | |
137 | d5975363 | pbrook | /* Start an exclusive operation.
|
138 | d5975363 | pbrook | Must only be called from outside cpu_arm_exec. */
|
139 | d5975363 | pbrook | static inline void start_exclusive(void) |
140 | d5975363 | pbrook | { |
141 | d5975363 | pbrook | CPUState *other; |
142 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
143 | d5975363 | pbrook | exclusive_idle(); |
144 | d5975363 | pbrook | |
145 | d5975363 | pbrook | pending_cpus = 1;
|
146 | d5975363 | pbrook | /* Make all other cpus stop executing. */
|
147 | d5975363 | pbrook | for (other = first_cpu; other; other = other->next_cpu) {
|
148 | d5975363 | pbrook | if (other->running) {
|
149 | d5975363 | pbrook | pending_cpus++; |
150 | 3098dba0 | aurel32 | cpu_exit(other); |
151 | d5975363 | pbrook | } |
152 | d5975363 | pbrook | } |
153 | d5975363 | pbrook | if (pending_cpus > 1) { |
154 | d5975363 | pbrook | pthread_cond_wait(&exclusive_cond, &exclusive_lock); |
155 | d5975363 | pbrook | } |
156 | d5975363 | pbrook | } |
157 | d5975363 | pbrook | |
158 | d5975363 | pbrook | /* Finish an exclusive operation. */
|
159 | d5975363 | pbrook | static inline void end_exclusive(void) |
160 | d5975363 | pbrook | { |
161 | d5975363 | pbrook | pending_cpus = 0;
|
162 | d5975363 | pbrook | pthread_cond_broadcast(&exclusive_resume); |
163 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
164 | d5975363 | pbrook | } |
165 | d5975363 | pbrook | |
166 | d5975363 | pbrook | /* Wait for exclusive ops to finish, and begin cpu execution. */
|
167 | d5975363 | pbrook | static inline void cpu_exec_start(CPUState *env) |
168 | d5975363 | pbrook | { |
169 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
170 | d5975363 | pbrook | exclusive_idle(); |
171 | d5975363 | pbrook | env->running = 1;
|
172 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
173 | d5975363 | pbrook | } |
174 | d5975363 | pbrook | |
175 | d5975363 | pbrook | /* Mark cpu as not executing, and release pending exclusive ops. */
|
176 | d5975363 | pbrook | static inline void cpu_exec_end(CPUState *env) |
177 | d5975363 | pbrook | { |
178 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
179 | d5975363 | pbrook | env->running = 0;
|
180 | d5975363 | pbrook | if (pending_cpus > 1) { |
181 | d5975363 | pbrook | pending_cpus--; |
182 | d5975363 | pbrook | if (pending_cpus == 1) { |
183 | d5975363 | pbrook | pthread_cond_signal(&exclusive_cond); |
184 | d5975363 | pbrook | } |
185 | d5975363 | pbrook | } |
186 | d5975363 | pbrook | exclusive_idle(); |
187 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
188 | d5975363 | pbrook | } |
189 | c2764719 | pbrook | |
190 | c2764719 | pbrook | void cpu_list_lock(void) |
191 | c2764719 | pbrook | { |
192 | c2764719 | pbrook | pthread_mutex_lock(&cpu_list_mutex); |
193 | c2764719 | pbrook | } |
194 | c2764719 | pbrook | |
195 | c2764719 | pbrook | void cpu_list_unlock(void) |
196 | c2764719 | pbrook | { |
197 | c2764719 | pbrook | pthread_mutex_unlock(&cpu_list_mutex); |
198 | c2764719 | pbrook | } |
199 | 2f7bb878 | Juan Quintela | #else /* if !CONFIG_USE_NPTL */ |
200 | d5975363 | pbrook | /* These are no-ops because we are not threadsafe. */
|
201 | d5975363 | pbrook | static inline void cpu_exec_start(CPUState *env) |
202 | d5975363 | pbrook | { |
203 | d5975363 | pbrook | } |
204 | d5975363 | pbrook | |
205 | d5975363 | pbrook | static inline void cpu_exec_end(CPUState *env) |
206 | d5975363 | pbrook | { |
207 | d5975363 | pbrook | } |
208 | d5975363 | pbrook | |
209 | d5975363 | pbrook | static inline void start_exclusive(void) |
210 | d5975363 | pbrook | { |
211 | d5975363 | pbrook | } |
212 | d5975363 | pbrook | |
213 | d5975363 | pbrook | static inline void end_exclusive(void) |
214 | d5975363 | pbrook | { |
215 | d5975363 | pbrook | } |
216 | d5975363 | pbrook | |
217 | d5975363 | pbrook | void fork_start(void) |
218 | d5975363 | pbrook | { |
219 | d5975363 | pbrook | } |
220 | d5975363 | pbrook | |
221 | d5975363 | pbrook | void fork_end(int child) |
222 | d5975363 | pbrook | { |
223 | 2b1319c8 | aurel32 | if (child) {
|
224 | 2b1319c8 | aurel32 | gdbserver_fork(thread_env); |
225 | 2b1319c8 | aurel32 | } |
226 | d5975363 | pbrook | } |
227 | c2764719 | pbrook | |
228 | c2764719 | pbrook | void cpu_list_lock(void) |
229 | c2764719 | pbrook | { |
230 | c2764719 | pbrook | } |
231 | c2764719 | pbrook | |
232 | c2764719 | pbrook | void cpu_list_unlock(void) |
233 | c2764719 | pbrook | { |
234 | c2764719 | pbrook | } |
235 | d5975363 | pbrook | #endif
|
236 | d5975363 | pbrook | |
237 | d5975363 | pbrook | |
238 | a541f297 | bellard | #ifdef TARGET_I386
|
239 | a541f297 | bellard | /***********************************************************/
|
240 | a541f297 | bellard | /* CPUX86 core interface */
|
241 | a541f297 | bellard | |
242 | 02a1602e | bellard | void cpu_smm_update(CPUState *env)
|
243 | 02a1602e | bellard | { |
244 | 02a1602e | bellard | } |
245 | 02a1602e | bellard | |
246 | 28ab0e2e | bellard | uint64_t cpu_get_tsc(CPUX86State *env) |
247 | 28ab0e2e | bellard | { |
248 | 28ab0e2e | bellard | return cpu_get_real_ticks();
|
249 | 28ab0e2e | bellard | } |
250 | 28ab0e2e | bellard | |
251 | 5fafdf24 | ths | static void write_dt(void *ptr, unsigned long addr, unsigned long limit, |
252 | f4beb510 | bellard | int flags)
|
253 | 6dbad63e | bellard | { |
254 | f4beb510 | bellard | unsigned int e1, e2; |
255 | 53a5960a | pbrook | uint32_t *p; |
256 | 6dbad63e | bellard | e1 = (addr << 16) | (limit & 0xffff); |
257 | 6dbad63e | bellard | e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); |
258 | f4beb510 | bellard | e2 |= flags; |
259 | 53a5960a | pbrook | p = ptr; |
260 | d538e8f5 | malc | p[0] = tswap32(e1);
|
261 | d538e8f5 | malc | p[1] = tswap32(e2);
|
262 | f4beb510 | bellard | } |
263 | f4beb510 | bellard | |
264 | e441570f | balrog | static uint64_t *idt_table;
|
265 | eb38c52c | blueswir1 | #ifdef TARGET_X86_64
|
266 | d2fd1af7 | bellard | static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, |
267 | d2fd1af7 | bellard | uint64_t addr, unsigned int sel) |
268 | f4beb510 | bellard | { |
269 | 4dbc422b | bellard | uint32_t *p, e1, e2; |
270 | f4beb510 | bellard | e1 = (addr & 0xffff) | (sel << 16); |
271 | f4beb510 | bellard | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); |
272 | 53a5960a | pbrook | p = ptr; |
273 | 4dbc422b | bellard | p[0] = tswap32(e1);
|
274 | 4dbc422b | bellard | p[1] = tswap32(e2);
|
275 | 4dbc422b | bellard | p[2] = tswap32(addr >> 32); |
276 | 4dbc422b | bellard | p[3] = 0; |
277 | 6dbad63e | bellard | } |
278 | d2fd1af7 | bellard | /* only dpl matters as we do only user space emulation */
|
279 | d2fd1af7 | bellard | static void set_idt(int n, unsigned int dpl) |
280 | d2fd1af7 | bellard | { |
281 | d2fd1af7 | bellard | set_gate64(idt_table + n * 2, 0, dpl, 0, 0); |
282 | d2fd1af7 | bellard | } |
283 | d2fd1af7 | bellard | #else
|
284 | d2fd1af7 | bellard | static void set_gate(void *ptr, unsigned int type, unsigned int dpl, |
285 | d2fd1af7 | bellard | uint32_t addr, unsigned int sel) |
286 | d2fd1af7 | bellard | { |
287 | 4dbc422b | bellard | uint32_t *p, e1, e2; |
288 | d2fd1af7 | bellard | e1 = (addr & 0xffff) | (sel << 16); |
289 | d2fd1af7 | bellard | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); |
290 | d2fd1af7 | bellard | p = ptr; |
291 | 4dbc422b | bellard | p[0] = tswap32(e1);
|
292 | 4dbc422b | bellard | p[1] = tswap32(e2);
|
293 | d2fd1af7 | bellard | } |
294 | d2fd1af7 | bellard | |
295 | f4beb510 | bellard | /* only dpl matters as we do only user space emulation */
|
296 | f4beb510 | bellard | static void set_idt(int n, unsigned int dpl) |
297 | f4beb510 | bellard | { |
298 | f4beb510 | bellard | set_gate(idt_table + n, 0, dpl, 0, 0); |
299 | f4beb510 | bellard | } |
300 | d2fd1af7 | bellard | #endif
|
301 | 31e31b8a | bellard | |
302 | 89e957e7 | bellard | void cpu_loop(CPUX86State *env)
|
303 | 1b6b029e | bellard | { |
304 | bc8a22cc | bellard | int trapnr;
|
305 | 992f48a0 | blueswir1 | abi_ulong pc; |
306 | c227f099 | Anthony Liguori | target_siginfo_t info; |
307 | 851e67a1 | bellard | |
308 | 1b6b029e | bellard | for(;;) {
|
309 | bc8a22cc | bellard | trapnr = cpu_x86_exec(env); |
310 | bc8a22cc | bellard | switch(trapnr) {
|
311 | f4beb510 | bellard | case 0x80: |
312 | d2fd1af7 | bellard | /* linux syscall from int $0x80 */
|
313 | 5fafdf24 | ths | env->regs[R_EAX] = do_syscall(env, |
314 | 5fafdf24 | ths | env->regs[R_EAX], |
315 | f4beb510 | bellard | env->regs[R_EBX], |
316 | f4beb510 | bellard | env->regs[R_ECX], |
317 | f4beb510 | bellard | env->regs[R_EDX], |
318 | f4beb510 | bellard | env->regs[R_ESI], |
319 | f4beb510 | bellard | env->regs[R_EDI], |
320 | f4beb510 | bellard | env->regs[R_EBP]); |
321 | f4beb510 | bellard | break;
|
322 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
323 | d2fd1af7 | bellard | case EXCP_SYSCALL:
|
324 | d2fd1af7 | bellard | /* linux syscall from syscall intruction */
|
325 | d2fd1af7 | bellard | env->regs[R_EAX] = do_syscall(env, |
326 | d2fd1af7 | bellard | env->regs[R_EAX], |
327 | d2fd1af7 | bellard | env->regs[R_EDI], |
328 | d2fd1af7 | bellard | env->regs[R_ESI], |
329 | d2fd1af7 | bellard | env->regs[R_EDX], |
330 | d2fd1af7 | bellard | env->regs[10],
|
331 | d2fd1af7 | bellard | env->regs[8],
|
332 | d2fd1af7 | bellard | env->regs[9]);
|
333 | d2fd1af7 | bellard | env->eip = env->exception_next_eip; |
334 | d2fd1af7 | bellard | break;
|
335 | d2fd1af7 | bellard | #endif
|
336 | f4beb510 | bellard | case EXCP0B_NOSEG:
|
337 | f4beb510 | bellard | case EXCP0C_STACK:
|
338 | f4beb510 | bellard | info.si_signo = SIGBUS; |
339 | f4beb510 | bellard | info.si_errno = 0;
|
340 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
341 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
342 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
343 | f4beb510 | bellard | break;
|
344 | 1b6b029e | bellard | case EXCP0D_GPF:
|
345 | d2fd1af7 | bellard | /* XXX: potential problem if ABI32 */
|
346 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
347 | 851e67a1 | bellard | if (env->eflags & VM_MASK) {
|
348 | 89e957e7 | bellard | handle_vm86_fault(env); |
349 | 84409ddb | j_mayer | } else
|
350 | 84409ddb | j_mayer | #endif
|
351 | 84409ddb | j_mayer | { |
352 | f4beb510 | bellard | info.si_signo = SIGSEGV; |
353 | f4beb510 | bellard | info.si_errno = 0;
|
354 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
355 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
356 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
357 | 1b6b029e | bellard | } |
358 | 1b6b029e | bellard | break;
|
359 | b689bc57 | bellard | case EXCP0E_PAGE:
|
360 | b689bc57 | bellard | info.si_signo = SIGSEGV; |
361 | b689bc57 | bellard | info.si_errno = 0;
|
362 | b689bc57 | bellard | if (!(env->error_code & 1)) |
363 | b689bc57 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
364 | b689bc57 | bellard | else
|
365 | b689bc57 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
366 | 970a87a6 | bellard | info._sifields._sigfault._addr = env->cr[2];
|
367 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
368 | b689bc57 | bellard | break;
|
369 | 9de5e440 | bellard | case EXCP00_DIVZ:
|
370 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
371 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
372 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
373 | 84409ddb | j_mayer | } else
|
374 | 84409ddb | j_mayer | #endif
|
375 | 84409ddb | j_mayer | { |
376 | bc8a22cc | bellard | /* division by zero */
|
377 | bc8a22cc | bellard | info.si_signo = SIGFPE; |
378 | bc8a22cc | bellard | info.si_errno = 0;
|
379 | bc8a22cc | bellard | info.si_code = TARGET_FPE_INTDIV; |
380 | bc8a22cc | bellard | info._sifields._sigfault._addr = env->eip; |
381 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
382 | bc8a22cc | bellard | } |
383 | 9de5e440 | bellard | break;
|
384 | 01df040b | aliguori | case EXCP01_DB:
|
385 | 447db213 | bellard | case EXCP03_INT3:
|
386 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
387 | 447db213 | bellard | if (env->eflags & VM_MASK) {
|
388 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
389 | 84409ddb | j_mayer | } else
|
390 | 84409ddb | j_mayer | #endif
|
391 | 84409ddb | j_mayer | { |
392 | 447db213 | bellard | info.si_signo = SIGTRAP; |
393 | 447db213 | bellard | info.si_errno = 0;
|
394 | 01df040b | aliguori | if (trapnr == EXCP01_DB) {
|
395 | 447db213 | bellard | info.si_code = TARGET_TRAP_BRKPT; |
396 | 447db213 | bellard | info._sifields._sigfault._addr = env->eip; |
397 | 447db213 | bellard | } else {
|
398 | 447db213 | bellard | info.si_code = TARGET_SI_KERNEL; |
399 | 447db213 | bellard | info._sifields._sigfault._addr = 0;
|
400 | 447db213 | bellard | } |
401 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
402 | 447db213 | bellard | } |
403 | 447db213 | bellard | break;
|
404 | 9de5e440 | bellard | case EXCP04_INTO:
|
405 | 9de5e440 | bellard | case EXCP05_BOUND:
|
406 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
407 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
408 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
409 | 84409ddb | j_mayer | } else
|
410 | 84409ddb | j_mayer | #endif
|
411 | 84409ddb | j_mayer | { |
412 | bc8a22cc | bellard | info.si_signo = SIGSEGV; |
413 | bc8a22cc | bellard | info.si_errno = 0;
|
414 | b689bc57 | bellard | info.si_code = TARGET_SI_KERNEL; |
415 | bc8a22cc | bellard | info._sifields._sigfault._addr = 0;
|
416 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
417 | bc8a22cc | bellard | } |
418 | 9de5e440 | bellard | break;
|
419 | 9de5e440 | bellard | case EXCP06_ILLOP:
|
420 | 9de5e440 | bellard | info.si_signo = SIGILL; |
421 | 9de5e440 | bellard | info.si_errno = 0;
|
422 | 9de5e440 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
423 | 9de5e440 | bellard | info._sifields._sigfault._addr = env->eip; |
424 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
425 | 9de5e440 | bellard | break;
|
426 | 9de5e440 | bellard | case EXCP_INTERRUPT:
|
427 | 9de5e440 | bellard | /* just indicate that signals should be handled asap */
|
428 | 9de5e440 | bellard | break;
|
429 | 1fddef4b | bellard | case EXCP_DEBUG:
|
430 | 1fddef4b | bellard | { |
431 | 1fddef4b | bellard | int sig;
|
432 | 1fddef4b | bellard | |
433 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
434 | 1fddef4b | bellard | if (sig)
|
435 | 1fddef4b | bellard | { |
436 | 1fddef4b | bellard | info.si_signo = sig; |
437 | 1fddef4b | bellard | info.si_errno = 0;
|
438 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
439 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
440 | 1fddef4b | bellard | } |
441 | 1fddef4b | bellard | } |
442 | 1fddef4b | bellard | break;
|
443 | 1b6b029e | bellard | default:
|
444 | 970a87a6 | bellard | pc = env->segs[R_CS].base + env->eip; |
445 | 5fafdf24 | ths | fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
|
446 | bc8a22cc | bellard | (long)pc, trapnr);
|
447 | 1b6b029e | bellard | abort(); |
448 | 1b6b029e | bellard | } |
449 | 66fb9763 | bellard | process_pending_signals(env); |
450 | 1b6b029e | bellard | } |
451 | 1b6b029e | bellard | } |
452 | b346ff46 | bellard | #endif
|
453 | b346ff46 | bellard | |
454 | b346ff46 | bellard | #ifdef TARGET_ARM
|
455 | b346ff46 | bellard | |
456 | 992f48a0 | blueswir1 | static void arm_cache_flush(abi_ulong start, abi_ulong last) |
457 | 6f1f31c0 | bellard | { |
458 | 992f48a0 | blueswir1 | abi_ulong addr, last1; |
459 | 6f1f31c0 | bellard | |
460 | 6f1f31c0 | bellard | if (last < start)
|
461 | 6f1f31c0 | bellard | return;
|
462 | 6f1f31c0 | bellard | addr = start; |
463 | 6f1f31c0 | bellard | for(;;) {
|
464 | 6f1f31c0 | bellard | last1 = ((addr + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK) - 1;
|
465 | 6f1f31c0 | bellard | if (last1 > last)
|
466 | 6f1f31c0 | bellard | last1 = last; |
467 | 6f1f31c0 | bellard | tb_invalidate_page_range(addr, last1 + 1);
|
468 | 6f1f31c0 | bellard | if (last1 == last)
|
469 | 6f1f31c0 | bellard | break;
|
470 | 6f1f31c0 | bellard | addr = last1 + 1;
|
471 | 6f1f31c0 | bellard | } |
472 | 6f1f31c0 | bellard | } |
473 | 6f1f31c0 | bellard | |
474 | fbb4a2e3 | pbrook | /* Handle a jump to the kernel code page. */
|
475 | fbb4a2e3 | pbrook | static int |
476 | fbb4a2e3 | pbrook | do_kernel_trap(CPUARMState *env) |
477 | fbb4a2e3 | pbrook | { |
478 | fbb4a2e3 | pbrook | uint32_t addr; |
479 | fbb4a2e3 | pbrook | uint32_t cpsr; |
480 | fbb4a2e3 | pbrook | uint32_t val; |
481 | fbb4a2e3 | pbrook | |
482 | fbb4a2e3 | pbrook | switch (env->regs[15]) { |
483 | fbb4a2e3 | pbrook | case 0xffff0fa0: /* __kernel_memory_barrier */ |
484 | fbb4a2e3 | pbrook | /* ??? No-op. Will need to do better for SMP. */
|
485 | fbb4a2e3 | pbrook | break;
|
486 | fbb4a2e3 | pbrook | case 0xffff0fc0: /* __kernel_cmpxchg */ |
487 | d5975363 | pbrook | /* XXX: This only works between threads, not between processes.
|
488 | d5975363 | pbrook | It's probably possible to implement this with native host
|
489 | d5975363 | pbrook | operations. However things like ldrex/strex are much harder so
|
490 | d5975363 | pbrook | there's not much point trying. */
|
491 | d5975363 | pbrook | start_exclusive(); |
492 | fbb4a2e3 | pbrook | cpsr = cpsr_read(env); |
493 | fbb4a2e3 | pbrook | addr = env->regs[2];
|
494 | fbb4a2e3 | pbrook | /* FIXME: This should SEGV if the access fails. */
|
495 | fbb4a2e3 | pbrook | if (get_user_u32(val, addr))
|
496 | fbb4a2e3 | pbrook | val = ~env->regs[0];
|
497 | fbb4a2e3 | pbrook | if (val == env->regs[0]) { |
498 | fbb4a2e3 | pbrook | val = env->regs[1];
|
499 | fbb4a2e3 | pbrook | /* FIXME: Check for segfaults. */
|
500 | fbb4a2e3 | pbrook | put_user_u32(val, addr); |
501 | fbb4a2e3 | pbrook | env->regs[0] = 0; |
502 | fbb4a2e3 | pbrook | cpsr |= CPSR_C; |
503 | fbb4a2e3 | pbrook | } else {
|
504 | fbb4a2e3 | pbrook | env->regs[0] = -1; |
505 | fbb4a2e3 | pbrook | cpsr &= ~CPSR_C; |
506 | fbb4a2e3 | pbrook | } |
507 | fbb4a2e3 | pbrook | cpsr_write(env, cpsr, CPSR_C); |
508 | d5975363 | pbrook | end_exclusive(); |
509 | fbb4a2e3 | pbrook | break;
|
510 | fbb4a2e3 | pbrook | case 0xffff0fe0: /* __kernel_get_tls */ |
511 | fbb4a2e3 | pbrook | env->regs[0] = env->cp15.c13_tls2;
|
512 | fbb4a2e3 | pbrook | break;
|
513 | fbb4a2e3 | pbrook | default:
|
514 | fbb4a2e3 | pbrook | return 1; |
515 | fbb4a2e3 | pbrook | } |
516 | fbb4a2e3 | pbrook | /* Jump back to the caller. */
|
517 | fbb4a2e3 | pbrook | addr = env->regs[14];
|
518 | fbb4a2e3 | pbrook | if (addr & 1) { |
519 | fbb4a2e3 | pbrook | env->thumb = 1;
|
520 | fbb4a2e3 | pbrook | addr &= ~1;
|
521 | fbb4a2e3 | pbrook | } |
522 | fbb4a2e3 | pbrook | env->regs[15] = addr;
|
523 | fbb4a2e3 | pbrook | |
524 | fbb4a2e3 | pbrook | return 0; |
525 | fbb4a2e3 | pbrook | } |
526 | fbb4a2e3 | pbrook | |
527 | 426f5abc | Paul Brook | static int do_strex(CPUARMState *env) |
528 | 426f5abc | Paul Brook | { |
529 | 426f5abc | Paul Brook | uint32_t val; |
530 | 426f5abc | Paul Brook | int size;
|
531 | 426f5abc | Paul Brook | int rc = 1; |
532 | 426f5abc | Paul Brook | int segv = 0; |
533 | 426f5abc | Paul Brook | uint32_t addr; |
534 | 426f5abc | Paul Brook | start_exclusive(); |
535 | 426f5abc | Paul Brook | addr = env->exclusive_addr; |
536 | 426f5abc | Paul Brook | if (addr != env->exclusive_test) {
|
537 | 426f5abc | Paul Brook | goto fail;
|
538 | 426f5abc | Paul Brook | } |
539 | 426f5abc | Paul Brook | size = env->exclusive_info & 0xf;
|
540 | 426f5abc | Paul Brook | switch (size) {
|
541 | 426f5abc | Paul Brook | case 0: |
542 | 426f5abc | Paul Brook | segv = get_user_u8(val, addr); |
543 | 426f5abc | Paul Brook | break;
|
544 | 426f5abc | Paul Brook | case 1: |
545 | 426f5abc | Paul Brook | segv = get_user_u16(val, addr); |
546 | 426f5abc | Paul Brook | break;
|
547 | 426f5abc | Paul Brook | case 2: |
548 | 426f5abc | Paul Brook | case 3: |
549 | 426f5abc | Paul Brook | segv = get_user_u32(val, addr); |
550 | 426f5abc | Paul Brook | break;
|
551 | 426f5abc | Paul Brook | } |
552 | 426f5abc | Paul Brook | if (segv) {
|
553 | 426f5abc | Paul Brook | env->cp15.c6_data = addr; |
554 | 426f5abc | Paul Brook | goto done;
|
555 | 426f5abc | Paul Brook | } |
556 | 426f5abc | Paul Brook | if (val != env->exclusive_val) {
|
557 | 426f5abc | Paul Brook | goto fail;
|
558 | 426f5abc | Paul Brook | } |
559 | 426f5abc | Paul Brook | if (size == 3) { |
560 | 426f5abc | Paul Brook | segv = get_user_u32(val, addr + 4);
|
561 | 426f5abc | Paul Brook | if (segv) {
|
562 | 426f5abc | Paul Brook | env->cp15.c6_data = addr + 4;
|
563 | 426f5abc | Paul Brook | goto done;
|
564 | 426f5abc | Paul Brook | } |
565 | 426f5abc | Paul Brook | if (val != env->exclusive_high) {
|
566 | 426f5abc | Paul Brook | goto fail;
|
567 | 426f5abc | Paul Brook | } |
568 | 426f5abc | Paul Brook | } |
569 | 426f5abc | Paul Brook | val = env->regs[(env->exclusive_info >> 8) & 0xf]; |
570 | 426f5abc | Paul Brook | switch (size) {
|
571 | 426f5abc | Paul Brook | case 0: |
572 | 426f5abc | Paul Brook | segv = put_user_u8(val, addr); |
573 | 426f5abc | Paul Brook | break;
|
574 | 426f5abc | Paul Brook | case 1: |
575 | 426f5abc | Paul Brook | segv = put_user_u16(val, addr); |
576 | 426f5abc | Paul Brook | break;
|
577 | 426f5abc | Paul Brook | case 2: |
578 | 426f5abc | Paul Brook | case 3: |
579 | 426f5abc | Paul Brook | segv = put_user_u32(val, addr); |
580 | 426f5abc | Paul Brook | break;
|
581 | 426f5abc | Paul Brook | } |
582 | 426f5abc | Paul Brook | if (segv) {
|
583 | 426f5abc | Paul Brook | env->cp15.c6_data = addr; |
584 | 426f5abc | Paul Brook | goto done;
|
585 | 426f5abc | Paul Brook | } |
586 | 426f5abc | Paul Brook | if (size == 3) { |
587 | 426f5abc | Paul Brook | val = env->regs[(env->exclusive_info >> 12) & 0xf]; |
588 | 426f5abc | Paul Brook | segv = put_user_u32(val, addr); |
589 | 426f5abc | Paul Brook | if (segv) {
|
590 | 426f5abc | Paul Brook | env->cp15.c6_data = addr + 4;
|
591 | 426f5abc | Paul Brook | goto done;
|
592 | 426f5abc | Paul Brook | } |
593 | 426f5abc | Paul Brook | } |
594 | 426f5abc | Paul Brook | rc = 0;
|
595 | 426f5abc | Paul Brook | fail:
|
596 | 426f5abc | Paul Brook | env->regs[(env->exclusive_info >> 4) & 0xf] = rc; |
597 | 426f5abc | Paul Brook | done:
|
598 | 426f5abc | Paul Brook | end_exclusive(); |
599 | 426f5abc | Paul Brook | return segv;
|
600 | 426f5abc | Paul Brook | } |
601 | 426f5abc | Paul Brook | |
602 | b346ff46 | bellard | void cpu_loop(CPUARMState *env)
|
603 | b346ff46 | bellard | { |
604 | b346ff46 | bellard | int trapnr;
|
605 | b346ff46 | bellard | unsigned int n, insn; |
606 | c227f099 | Anthony Liguori | target_siginfo_t info; |
607 | b5ff1b31 | bellard | uint32_t addr; |
608 | 3b46e624 | ths | |
609 | b346ff46 | bellard | for(;;) {
|
610 | d5975363 | pbrook | cpu_exec_start(env); |
611 | b346ff46 | bellard | trapnr = cpu_arm_exec(env); |
612 | d5975363 | pbrook | cpu_exec_end(env); |
613 | b346ff46 | bellard | switch(trapnr) {
|
614 | b346ff46 | bellard | case EXCP_UDEF:
|
615 | c6981055 | bellard | { |
616 | c6981055 | bellard | TaskState *ts = env->opaque; |
617 | c6981055 | bellard | uint32_t opcode; |
618 | 6d9a42be | aurel32 | int rc;
|
619 | c6981055 | bellard | |
620 | c6981055 | bellard | /* we handle the FPU emulation here, as Linux */
|
621 | c6981055 | bellard | /* we get the opcode */
|
622 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
623 | 2f619698 | bellard | get_user_u32(opcode, env->regs[15]);
|
624 | 3b46e624 | ths | |
625 | 6d9a42be | aurel32 | rc = EmulateAll(opcode, &ts->fpa, env); |
626 | 6d9a42be | aurel32 | if (rc == 0) { /* illegal instruction */ |
627 | c6981055 | bellard | info.si_signo = SIGILL; |
628 | c6981055 | bellard | info.si_errno = 0;
|
629 | c6981055 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
630 | c6981055 | bellard | info._sifields._sigfault._addr = env->regs[15];
|
631 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
632 | 6d9a42be | aurel32 | } else if (rc < 0) { /* FP exception */ |
633 | 6d9a42be | aurel32 | int arm_fpe=0; |
634 | 6d9a42be | aurel32 | |
635 | 6d9a42be | aurel32 | /* translate softfloat flags to FPSR flags */
|
636 | 6d9a42be | aurel32 | if (-rc & float_flag_invalid)
|
637 | 6d9a42be | aurel32 | arm_fpe |= BIT_IOC; |
638 | 6d9a42be | aurel32 | if (-rc & float_flag_divbyzero)
|
639 | 6d9a42be | aurel32 | arm_fpe |= BIT_DZC; |
640 | 6d9a42be | aurel32 | if (-rc & float_flag_overflow)
|
641 | 6d9a42be | aurel32 | arm_fpe |= BIT_OFC; |
642 | 6d9a42be | aurel32 | if (-rc & float_flag_underflow)
|
643 | 6d9a42be | aurel32 | arm_fpe |= BIT_UFC; |
644 | 6d9a42be | aurel32 | if (-rc & float_flag_inexact)
|
645 | 6d9a42be | aurel32 | arm_fpe |= BIT_IXC; |
646 | 6d9a42be | aurel32 | |
647 | 6d9a42be | aurel32 | FPSR fpsr = ts->fpa.fpsr; |
648 | 6d9a42be | aurel32 | //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe);
|
649 | 6d9a42be | aurel32 | |
650 | 6d9a42be | aurel32 | if (fpsr & (arm_fpe << 16)) { /* exception enabled? */ |
651 | 6d9a42be | aurel32 | info.si_signo = SIGFPE; |
652 | 6d9a42be | aurel32 | info.si_errno = 0;
|
653 | 6d9a42be | aurel32 | |
654 | 6d9a42be | aurel32 | /* ordered by priority, least first */
|
655 | 6d9a42be | aurel32 | if (arm_fpe & BIT_IXC) info.si_code = TARGET_FPE_FLTRES;
|
656 | 6d9a42be | aurel32 | if (arm_fpe & BIT_UFC) info.si_code = TARGET_FPE_FLTUND;
|
657 | 6d9a42be | aurel32 | if (arm_fpe & BIT_OFC) info.si_code = TARGET_FPE_FLTOVF;
|
658 | 6d9a42be | aurel32 | if (arm_fpe & BIT_DZC) info.si_code = TARGET_FPE_FLTDIV;
|
659 | 6d9a42be | aurel32 | if (arm_fpe & BIT_IOC) info.si_code = TARGET_FPE_FLTINV;
|
660 | 6d9a42be | aurel32 | |
661 | 6d9a42be | aurel32 | info._sifields._sigfault._addr = env->regs[15];
|
662 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
663 | 6d9a42be | aurel32 | } else {
|
664 | 6d9a42be | aurel32 | env->regs[15] += 4; |
665 | 6d9a42be | aurel32 | } |
666 | 6d9a42be | aurel32 | |
667 | 6d9a42be | aurel32 | /* accumulate unenabled exceptions */
|
668 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_IXE)) && (arm_fpe & BIT_IXC))
|
669 | 6d9a42be | aurel32 | fpsr |= BIT_IXC; |
670 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_UFE)) && (arm_fpe & BIT_UFC))
|
671 | 6d9a42be | aurel32 | fpsr |= BIT_UFC; |
672 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_OFE)) && (arm_fpe & BIT_OFC))
|
673 | 6d9a42be | aurel32 | fpsr |= BIT_OFC; |
674 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_DZE)) && (arm_fpe & BIT_DZC))
|
675 | 6d9a42be | aurel32 | fpsr |= BIT_DZC; |
676 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_IOE)) && (arm_fpe & BIT_IOC))
|
677 | 6d9a42be | aurel32 | fpsr |= BIT_IOC; |
678 | 6d9a42be | aurel32 | ts->fpa.fpsr=fpsr; |
679 | 6d9a42be | aurel32 | } else { /* everything OK */ |
680 | c6981055 | bellard | /* increment PC */
|
681 | c6981055 | bellard | env->regs[15] += 4; |
682 | c6981055 | bellard | } |
683 | c6981055 | bellard | } |
684 | b346ff46 | bellard | break;
|
685 | b346ff46 | bellard | case EXCP_SWI:
|
686 | 06c949e6 | pbrook | case EXCP_BKPT:
|
687 | b346ff46 | bellard | { |
688 | ce4defa0 | pbrook | env->eabi = 1;
|
689 | b346ff46 | bellard | /* system call */
|
690 | 06c949e6 | pbrook | if (trapnr == EXCP_BKPT) {
|
691 | 06c949e6 | pbrook | if (env->thumb) {
|
692 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
693 | 2f619698 | bellard | get_user_u16(insn, env->regs[15]);
|
694 | 06c949e6 | pbrook | n = insn & 0xff;
|
695 | 06c949e6 | pbrook | env->regs[15] += 2; |
696 | 06c949e6 | pbrook | } else {
|
697 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
698 | 2f619698 | bellard | get_user_u32(insn, env->regs[15]);
|
699 | 06c949e6 | pbrook | n = (insn & 0xf) | ((insn >> 4) & 0xff0); |
700 | 06c949e6 | pbrook | env->regs[15] += 4; |
701 | 06c949e6 | pbrook | } |
702 | 192c7bd9 | bellard | } else {
|
703 | 06c949e6 | pbrook | if (env->thumb) {
|
704 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
705 | 2f619698 | bellard | get_user_u16(insn, env->regs[15] - 2); |
706 | 06c949e6 | pbrook | n = insn & 0xff;
|
707 | 06c949e6 | pbrook | } else {
|
708 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
709 | 2f619698 | bellard | get_user_u32(insn, env->regs[15] - 4); |
710 | 06c949e6 | pbrook | n = insn & 0xffffff;
|
711 | 06c949e6 | pbrook | } |
712 | 192c7bd9 | bellard | } |
713 | 192c7bd9 | bellard | |
714 | 6f1f31c0 | bellard | if (n == ARM_NR_cacheflush) {
|
715 | 6f1f31c0 | bellard | arm_cache_flush(env->regs[0], env->regs[1]); |
716 | a4f81979 | bellard | } else if (n == ARM_NR_semihosting |
717 | a4f81979 | bellard | || n == ARM_NR_thumb_semihosting) { |
718 | a4f81979 | bellard | env->regs[0] = do_arm_semihosting (env);
|
719 | ce4defa0 | pbrook | } else if (n == 0 || n >= ARM_SYSCALL_BASE |
720 | 192c7bd9 | bellard | || (env->thumb && n == ARM_THUMB_SYSCALL)) { |
721 | b346ff46 | bellard | /* linux syscall */
|
722 | ce4defa0 | pbrook | if (env->thumb || n == 0) { |
723 | 192c7bd9 | bellard | n = env->regs[7];
|
724 | 192c7bd9 | bellard | } else {
|
725 | 192c7bd9 | bellard | n -= ARM_SYSCALL_BASE; |
726 | ce4defa0 | pbrook | env->eabi = 0;
|
727 | 192c7bd9 | bellard | } |
728 | fbb4a2e3 | pbrook | if ( n > ARM_NR_BASE) {
|
729 | fbb4a2e3 | pbrook | switch (n) {
|
730 | fbb4a2e3 | pbrook | case ARM_NR_cacheflush:
|
731 | fbb4a2e3 | pbrook | arm_cache_flush(env->regs[0], env->regs[1]); |
732 | fbb4a2e3 | pbrook | break;
|
733 | fbb4a2e3 | pbrook | case ARM_NR_set_tls:
|
734 | fbb4a2e3 | pbrook | cpu_set_tls(env, env->regs[0]);
|
735 | fbb4a2e3 | pbrook | env->regs[0] = 0; |
736 | fbb4a2e3 | pbrook | break;
|
737 | fbb4a2e3 | pbrook | default:
|
738 | fbb4a2e3 | pbrook | gemu_log("qemu: Unsupported ARM syscall: 0x%x\n",
|
739 | fbb4a2e3 | pbrook | n); |
740 | fbb4a2e3 | pbrook | env->regs[0] = -TARGET_ENOSYS;
|
741 | fbb4a2e3 | pbrook | break;
|
742 | fbb4a2e3 | pbrook | } |
743 | fbb4a2e3 | pbrook | } else {
|
744 | fbb4a2e3 | pbrook | env->regs[0] = do_syscall(env,
|
745 | fbb4a2e3 | pbrook | n, |
746 | fbb4a2e3 | pbrook | env->regs[0],
|
747 | fbb4a2e3 | pbrook | env->regs[1],
|
748 | fbb4a2e3 | pbrook | env->regs[2],
|
749 | fbb4a2e3 | pbrook | env->regs[3],
|
750 | fbb4a2e3 | pbrook | env->regs[4],
|
751 | fbb4a2e3 | pbrook | env->regs[5]);
|
752 | fbb4a2e3 | pbrook | } |
753 | b346ff46 | bellard | } else {
|
754 | b346ff46 | bellard | goto error;
|
755 | b346ff46 | bellard | } |
756 | b346ff46 | bellard | } |
757 | b346ff46 | bellard | break;
|
758 | 43fff238 | bellard | case EXCP_INTERRUPT:
|
759 | 43fff238 | bellard | /* just indicate that signals should be handled asap */
|
760 | 43fff238 | bellard | break;
|
761 | 68016c62 | bellard | case EXCP_PREFETCH_ABORT:
|
762 | eae473c1 | balrog | addr = env->cp15.c6_insn; |
763 | b5ff1b31 | bellard | goto do_segv;
|
764 | 68016c62 | bellard | case EXCP_DATA_ABORT:
|
765 | eae473c1 | balrog | addr = env->cp15.c6_data; |
766 | b5ff1b31 | bellard | goto do_segv;
|
767 | b5ff1b31 | bellard | do_segv:
|
768 | 68016c62 | bellard | { |
769 | 68016c62 | bellard | info.si_signo = SIGSEGV; |
770 | 68016c62 | bellard | info.si_errno = 0;
|
771 | 68016c62 | bellard | /* XXX: check env->error_code */
|
772 | 68016c62 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
773 | b5ff1b31 | bellard | info._sifields._sigfault._addr = addr; |
774 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
775 | 68016c62 | bellard | } |
776 | 68016c62 | bellard | break;
|
777 | 1fddef4b | bellard | case EXCP_DEBUG:
|
778 | 1fddef4b | bellard | { |
779 | 1fddef4b | bellard | int sig;
|
780 | 1fddef4b | bellard | |
781 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
782 | 1fddef4b | bellard | if (sig)
|
783 | 1fddef4b | bellard | { |
784 | 1fddef4b | bellard | info.si_signo = sig; |
785 | 1fddef4b | bellard | info.si_errno = 0;
|
786 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
787 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
788 | 1fddef4b | bellard | } |
789 | 1fddef4b | bellard | } |
790 | 1fddef4b | bellard | break;
|
791 | fbb4a2e3 | pbrook | case EXCP_KERNEL_TRAP:
|
792 | fbb4a2e3 | pbrook | if (do_kernel_trap(env))
|
793 | fbb4a2e3 | pbrook | goto error;
|
794 | fbb4a2e3 | pbrook | break;
|
795 | 426f5abc | Paul Brook | case EXCP_STREX:
|
796 | 426f5abc | Paul Brook | if (do_strex(env)) {
|
797 | 426f5abc | Paul Brook | addr = env->cp15.c6_data; |
798 | 426f5abc | Paul Brook | goto do_segv;
|
799 | 426f5abc | Paul Brook | } |
800 | e9273455 | Paul Brook | break;
|
801 | b346ff46 | bellard | default:
|
802 | b346ff46 | bellard | error:
|
803 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
804 | b346ff46 | bellard | trapnr); |
805 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
806 | b346ff46 | bellard | abort(); |
807 | b346ff46 | bellard | } |
808 | b346ff46 | bellard | process_pending_signals(env); |
809 | b346ff46 | bellard | } |
810 | b346ff46 | bellard | } |
811 | b346ff46 | bellard | |
812 | b346ff46 | bellard | #endif
|
813 | 1b6b029e | bellard | |
814 | 93ac68bc | bellard | #ifdef TARGET_SPARC
|
815 | ed23fbd9 | blueswir1 | #define SPARC64_STACK_BIAS 2047 |
816 | 93ac68bc | bellard | |
817 | 060366c5 | bellard | //#define DEBUG_WIN
|
818 | 060366c5 | bellard | |
819 | 2623cbaf | bellard | /* WARNING: dealing with register windows _is_ complicated. More info
|
820 | 2623cbaf | bellard | can be found at http://www.sics.se/~psm/sparcstack.html */
|
821 | 060366c5 | bellard | static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) |
822 | 060366c5 | bellard | { |
823 | 1a14026e | blueswir1 | index = (index + cwp * 16) % (16 * env->nwindows); |
824 | 060366c5 | bellard | /* wrap handling : if cwp is on the last window, then we use the
|
825 | 060366c5 | bellard | registers 'after' the end */
|
826 | 1a14026e | blueswir1 | if (index < 8 && env->cwp == env->nwindows - 1) |
827 | 1a14026e | blueswir1 | index += 16 * env->nwindows;
|
828 | 060366c5 | bellard | return index;
|
829 | 060366c5 | bellard | } |
830 | 060366c5 | bellard | |
831 | 2623cbaf | bellard | /* save the register window 'cwp1' */
|
832 | 2623cbaf | bellard | static inline void save_window_offset(CPUSPARCState *env, int cwp1) |
833 | 060366c5 | bellard | { |
834 | 2623cbaf | bellard | unsigned int i; |
835 | 992f48a0 | blueswir1 | abi_ulong sp_ptr; |
836 | 3b46e624 | ths | |
837 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
838 | ed23fbd9 | blueswir1 | #ifdef TARGET_SPARC64
|
839 | ed23fbd9 | blueswir1 | if (sp_ptr & 3) |
840 | ed23fbd9 | blueswir1 | sp_ptr += SPARC64_STACK_BIAS; |
841 | ed23fbd9 | blueswir1 | #endif
|
842 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
843 | 2daf0284 | blueswir1 | printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n", |
844 | 2daf0284 | blueswir1 | sp_ptr, cwp1); |
845 | 060366c5 | bellard | #endif
|
846 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
847 | 2f619698 | bellard | /* FIXME - what to do if put_user() fails? */
|
848 | 2f619698 | bellard | put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
|
849 | 992f48a0 | blueswir1 | sp_ptr += sizeof(abi_ulong);
|
850 | 2623cbaf | bellard | } |
851 | 060366c5 | bellard | } |
852 | 060366c5 | bellard | |
853 | 060366c5 | bellard | static void save_window(CPUSPARCState *env) |
854 | 060366c5 | bellard | { |
855 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
856 | 2623cbaf | bellard | unsigned int new_wim; |
857 | 1a14026e | blueswir1 | new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & |
858 | 1a14026e | blueswir1 | ((1LL << env->nwindows) - 1); |
859 | 1a14026e | blueswir1 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
|
860 | 2623cbaf | bellard | env->wim = new_wim; |
861 | 5ef54116 | bellard | #else
|
862 | 1a14026e | blueswir1 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
|
863 | 5ef54116 | bellard | env->cansave++; |
864 | 5ef54116 | bellard | env->canrestore--; |
865 | 5ef54116 | bellard | #endif
|
866 | 060366c5 | bellard | } |
867 | 060366c5 | bellard | |
868 | 060366c5 | bellard | static void restore_window(CPUSPARCState *env) |
869 | 060366c5 | bellard | { |
870 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
871 | eda52953 | blueswir1 | unsigned int new_wim; |
872 | eda52953 | blueswir1 | #endif
|
873 | eda52953 | blueswir1 | unsigned int i, cwp1; |
874 | 992f48a0 | blueswir1 | abi_ulong sp_ptr; |
875 | 3b46e624 | ths | |
876 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
877 | 1a14026e | blueswir1 | new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & |
878 | 1a14026e | blueswir1 | ((1LL << env->nwindows) - 1); |
879 | eda52953 | blueswir1 | #endif
|
880 | 3b46e624 | ths | |
881 | 060366c5 | bellard | /* restore the invalid window */
|
882 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + 1);
|
883 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
884 | ed23fbd9 | blueswir1 | #ifdef TARGET_SPARC64
|
885 | ed23fbd9 | blueswir1 | if (sp_ptr & 3) |
886 | ed23fbd9 | blueswir1 | sp_ptr += SPARC64_STACK_BIAS; |
887 | ed23fbd9 | blueswir1 | #endif
|
888 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
889 | 2daf0284 | blueswir1 | printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n", |
890 | 2daf0284 | blueswir1 | sp_ptr, cwp1); |
891 | 060366c5 | bellard | #endif
|
892 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
893 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
894 | 2f619698 | bellard | get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
|
895 | 992f48a0 | blueswir1 | sp_ptr += sizeof(abi_ulong);
|
896 | 2623cbaf | bellard | } |
897 | 5ef54116 | bellard | #ifdef TARGET_SPARC64
|
898 | 5ef54116 | bellard | env->canrestore++; |
899 | 1a14026e | blueswir1 | if (env->cleanwin < env->nwindows - 1) |
900 | 1a14026e | blueswir1 | env->cleanwin++; |
901 | 5ef54116 | bellard | env->cansave--; |
902 | eda52953 | blueswir1 | #else
|
903 | eda52953 | blueswir1 | env->wim = new_wim; |
904 | 5ef54116 | bellard | #endif
|
905 | 060366c5 | bellard | } |
906 | 060366c5 | bellard | |
907 | 060366c5 | bellard | static void flush_windows(CPUSPARCState *env) |
908 | 060366c5 | bellard | { |
909 | 060366c5 | bellard | int offset, cwp1;
|
910 | 2623cbaf | bellard | |
911 | 2623cbaf | bellard | offset = 1;
|
912 | 060366c5 | bellard | for(;;) {
|
913 | 060366c5 | bellard | /* if restore would invoke restore_window(), then we can stop */
|
914 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + offset); |
915 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
916 | 060366c5 | bellard | if (env->wim & (1 << cwp1)) |
917 | 060366c5 | bellard | break;
|
918 | eda52953 | blueswir1 | #else
|
919 | eda52953 | blueswir1 | if (env->canrestore == 0) |
920 | eda52953 | blueswir1 | break;
|
921 | eda52953 | blueswir1 | env->cansave++; |
922 | eda52953 | blueswir1 | env->canrestore--; |
923 | eda52953 | blueswir1 | #endif
|
924 | 2623cbaf | bellard | save_window_offset(env, cwp1); |
925 | 060366c5 | bellard | offset++; |
926 | 060366c5 | bellard | } |
927 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + 1);
|
928 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
929 | eda52953 | blueswir1 | /* set wim so that restore will reload the registers */
|
930 | 2623cbaf | bellard | env->wim = 1 << cwp1;
|
931 | eda52953 | blueswir1 | #endif
|
932 | 2623cbaf | bellard | #if defined(DEBUG_WIN)
|
933 | 2623cbaf | bellard | printf("flush_windows: nb=%d\n", offset - 1); |
934 | 80a9d035 | bellard | #endif
|
935 | 2623cbaf | bellard | } |
936 | 060366c5 | bellard | |
937 | 93ac68bc | bellard | void cpu_loop (CPUSPARCState *env)
|
938 | 93ac68bc | bellard | { |
939 | 060366c5 | bellard | int trapnr, ret;
|
940 | c227f099 | Anthony Liguori | target_siginfo_t info; |
941 | 3b46e624 | ths | |
942 | 060366c5 | bellard | while (1) { |
943 | 060366c5 | bellard | trapnr = cpu_sparc_exec (env); |
944 | 3b46e624 | ths | |
945 | 060366c5 | bellard | switch (trapnr) {
|
946 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
947 | 5fafdf24 | ths | case 0x88: |
948 | 060366c5 | bellard | case 0x90: |
949 | 5ef54116 | bellard | #else
|
950 | cb33da57 | blueswir1 | case 0x110: |
951 | 5ef54116 | bellard | case 0x16d: |
952 | 5ef54116 | bellard | #endif
|
953 | 060366c5 | bellard | ret = do_syscall (env, env->gregs[1],
|
954 | 5fafdf24 | ths | env->regwptr[0], env->regwptr[1], |
955 | 5fafdf24 | ths | env->regwptr[2], env->regwptr[3], |
956 | 060366c5 | bellard | env->regwptr[4], env->regwptr[5]); |
957 | 060366c5 | bellard | if ((unsigned int)ret >= (unsigned int)(-515)) { |
958 | 992f48a0 | blueswir1 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
959 | 27908725 | bellard | env->xcc |= PSR_CARRY; |
960 | 27908725 | bellard | #else
|
961 | 060366c5 | bellard | env->psr |= PSR_CARRY; |
962 | 27908725 | bellard | #endif
|
963 | 060366c5 | bellard | ret = -ret; |
964 | 060366c5 | bellard | } else {
|
965 | 992f48a0 | blueswir1 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
966 | 27908725 | bellard | env->xcc &= ~PSR_CARRY; |
967 | 27908725 | bellard | #else
|
968 | 060366c5 | bellard | env->psr &= ~PSR_CARRY; |
969 | 27908725 | bellard | #endif
|
970 | 060366c5 | bellard | } |
971 | 060366c5 | bellard | env->regwptr[0] = ret;
|
972 | 060366c5 | bellard | /* next instruction */
|
973 | 060366c5 | bellard | env->pc = env->npc; |
974 | 060366c5 | bellard | env->npc = env->npc + 4;
|
975 | 060366c5 | bellard | break;
|
976 | 060366c5 | bellard | case 0x83: /* flush windows */ |
977 | 992f48a0 | blueswir1 | #ifdef TARGET_ABI32
|
978 | 992f48a0 | blueswir1 | case 0x103: |
979 | 992f48a0 | blueswir1 | #endif
|
980 | 2623cbaf | bellard | flush_windows(env); |
981 | 060366c5 | bellard | /* next instruction */
|
982 | 060366c5 | bellard | env->pc = env->npc; |
983 | 060366c5 | bellard | env->npc = env->npc + 4;
|
984 | 060366c5 | bellard | break;
|
985 | 3475187d | bellard | #ifndef TARGET_SPARC64
|
986 | 060366c5 | bellard | case TT_WIN_OVF: /* window overflow */ |
987 | 060366c5 | bellard | save_window(env); |
988 | 060366c5 | bellard | break;
|
989 | 060366c5 | bellard | case TT_WIN_UNF: /* window underflow */ |
990 | 060366c5 | bellard | restore_window(env); |
991 | 060366c5 | bellard | break;
|
992 | 61ff6f58 | bellard | case TT_TFAULT:
|
993 | 61ff6f58 | bellard | case TT_DFAULT:
|
994 | 61ff6f58 | bellard | { |
995 | 61ff6f58 | bellard | info.si_signo = SIGSEGV; |
996 | 61ff6f58 | bellard | info.si_errno = 0;
|
997 | 61ff6f58 | bellard | /* XXX: check env->error_code */
|
998 | 61ff6f58 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
999 | 61ff6f58 | bellard | info._sifields._sigfault._addr = env->mmuregs[4];
|
1000 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1001 | 61ff6f58 | bellard | } |
1002 | 61ff6f58 | bellard | break;
|
1003 | 3475187d | bellard | #else
|
1004 | 5ef54116 | bellard | case TT_SPILL: /* window overflow */ |
1005 | 5ef54116 | bellard | save_window(env); |
1006 | 5ef54116 | bellard | break;
|
1007 | 5ef54116 | bellard | case TT_FILL: /* window underflow */ |
1008 | 5ef54116 | bellard | restore_window(env); |
1009 | 5ef54116 | bellard | break;
|
1010 | 7f84a729 | blueswir1 | case TT_TFAULT:
|
1011 | 7f84a729 | blueswir1 | case TT_DFAULT:
|
1012 | 7f84a729 | blueswir1 | { |
1013 | 7f84a729 | blueswir1 | info.si_signo = SIGSEGV; |
1014 | 7f84a729 | blueswir1 | info.si_errno = 0;
|
1015 | 7f84a729 | blueswir1 | /* XXX: check env->error_code */
|
1016 | 7f84a729 | blueswir1 | info.si_code = TARGET_SEGV_MAPERR; |
1017 | 7f84a729 | blueswir1 | if (trapnr == TT_DFAULT)
|
1018 | 7f84a729 | blueswir1 | info._sifields._sigfault._addr = env->dmmuregs[4];
|
1019 | 7f84a729 | blueswir1 | else
|
1020 | 8194f35a | Igor Kovalenko | info._sifields._sigfault._addr = cpu_tsptr(env)->tpc; |
1021 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1022 | 7f84a729 | blueswir1 | } |
1023 | 7f84a729 | blueswir1 | break;
|
1024 | 27524dc3 | bellard | #ifndef TARGET_ABI32
|
1025 | 5bfb56b2 | blueswir1 | case 0x16e: |
1026 | 5bfb56b2 | blueswir1 | flush_windows(env); |
1027 | 5bfb56b2 | blueswir1 | sparc64_get_context(env); |
1028 | 5bfb56b2 | blueswir1 | break;
|
1029 | 5bfb56b2 | blueswir1 | case 0x16f: |
1030 | 5bfb56b2 | blueswir1 | flush_windows(env); |
1031 | 5bfb56b2 | blueswir1 | sparc64_set_context(env); |
1032 | 5bfb56b2 | blueswir1 | break;
|
1033 | 3475187d | bellard | #endif
|
1034 | 27524dc3 | bellard | #endif
|
1035 | 48dc41eb | bellard | case EXCP_INTERRUPT:
|
1036 | 48dc41eb | bellard | /* just indicate that signals should be handled asap */
|
1037 | 48dc41eb | bellard | break;
|
1038 | 1fddef4b | bellard | case EXCP_DEBUG:
|
1039 | 1fddef4b | bellard | { |
1040 | 1fddef4b | bellard | int sig;
|
1041 | 1fddef4b | bellard | |
1042 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
1043 | 1fddef4b | bellard | if (sig)
|
1044 | 1fddef4b | bellard | { |
1045 | 1fddef4b | bellard | info.si_signo = sig; |
1046 | 1fddef4b | bellard | info.si_errno = 0;
|
1047 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
1048 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1049 | 1fddef4b | bellard | } |
1050 | 1fddef4b | bellard | } |
1051 | 1fddef4b | bellard | break;
|
1052 | 060366c5 | bellard | default:
|
1053 | 060366c5 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
1054 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
1055 | 060366c5 | bellard | exit (1);
|
1056 | 060366c5 | bellard | } |
1057 | 060366c5 | bellard | process_pending_signals (env); |
1058 | 060366c5 | bellard | } |
1059 | 93ac68bc | bellard | } |
1060 | 93ac68bc | bellard | |
1061 | 93ac68bc | bellard | #endif
|
1062 | 93ac68bc | bellard | |
1063 | 67867308 | bellard | #ifdef TARGET_PPC
|
1064 | 9fddaa0c | bellard | static inline uint64_t cpu_ppc_get_tb (CPUState *env) |
1065 | 9fddaa0c | bellard | { |
1066 | 9fddaa0c | bellard | /* TO FIX */
|
1067 | 9fddaa0c | bellard | return 0; |
1068 | 9fddaa0c | bellard | } |
1069 | 3b46e624 | ths | |
1070 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbl (CPUState *env) |
1071 | 9fddaa0c | bellard | { |
1072 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) & 0xFFFFFFFF; |
1073 | 9fddaa0c | bellard | } |
1074 | 3b46e624 | ths | |
1075 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbu (CPUState *env) |
1076 | 9fddaa0c | bellard | { |
1077 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) >> 32; |
1078 | 9fddaa0c | bellard | } |
1079 | 3b46e624 | ths | |
1080 | a062e36c | j_mayer | uint32_t cpu_ppc_load_atbl (CPUState *env) |
1081 | 9fddaa0c | bellard | { |
1082 | a062e36c | j_mayer | return cpu_ppc_get_tb(env) & 0xFFFFFFFF; |
1083 | 9fddaa0c | bellard | } |
1084 | 5fafdf24 | ths | |
1085 | a062e36c | j_mayer | uint32_t cpu_ppc_load_atbu (CPUState *env) |
1086 | 9fddaa0c | bellard | { |
1087 | a062e36c | j_mayer | return cpu_ppc_get_tb(env) >> 32; |
1088 | 9fddaa0c | bellard | } |
1089 | 76a66253 | j_mayer | |
1090 | 76a66253 | j_mayer | uint32_t cpu_ppc601_load_rtcu (CPUState *env) |
1091 | 76a66253 | j_mayer | __attribute__ (( alias ("cpu_ppc_load_tbu") ));
|
1092 | 76a66253 | j_mayer | |
1093 | 76a66253 | j_mayer | uint32_t cpu_ppc601_load_rtcl (CPUState *env) |
1094 | 9fddaa0c | bellard | { |
1095 | 76a66253 | j_mayer | return cpu_ppc_load_tbl(env) & 0x3FFFFF80; |
1096 | 9fddaa0c | bellard | } |
1097 | 76a66253 | j_mayer | |
1098 | a750fc0b | j_mayer | /* XXX: to be fixed */
|
1099 | c227f099 | Anthony Liguori | int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, target_ulong *valp) |
1100 | a750fc0b | j_mayer | { |
1101 | a750fc0b | j_mayer | return -1; |
1102 | a750fc0b | j_mayer | } |
1103 | a750fc0b | j_mayer | |
1104 | c227f099 | Anthony Liguori | int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, target_ulong val) |
1105 | a750fc0b | j_mayer | { |
1106 | a750fc0b | j_mayer | return -1; |
1107 | a750fc0b | j_mayer | } |
1108 | a750fc0b | j_mayer | |
1109 | 001faf32 | Blue Swirl | #define EXCP_DUMP(env, fmt, ...) \
|
1110 | 001faf32 | Blue Swirl | do { \
|
1111 | 001faf32 | Blue Swirl | fprintf(stderr, fmt , ## __VA_ARGS__); \ |
1112 | 001faf32 | Blue Swirl | cpu_dump_state(env, stderr, fprintf, 0); \
|
1113 | 001faf32 | Blue Swirl | qemu_log(fmt, ## __VA_ARGS__); \ |
1114 | 430c7ec7 | malc | if (logfile) \
|
1115 | 430c7ec7 | malc | log_cpu_state(env, 0); \
|
1116 | e1833e1f | j_mayer | } while (0) |
1117 | e1833e1f | j_mayer | |
1118 | 56f066bb | Nathan Froyd | static int do_store_exclusive(CPUPPCState *env) |
1119 | 56f066bb | Nathan Froyd | { |
1120 | 56f066bb | Nathan Froyd | target_ulong addr; |
1121 | 56f066bb | Nathan Froyd | target_ulong page_addr; |
1122 | 56f066bb | Nathan Froyd | target_ulong val; |
1123 | 56f066bb | Nathan Froyd | int flags;
|
1124 | 56f066bb | Nathan Froyd | int segv = 0; |
1125 | 56f066bb | Nathan Froyd | |
1126 | 56f066bb | Nathan Froyd | addr = env->reserve_ea; |
1127 | 56f066bb | Nathan Froyd | page_addr = addr & TARGET_PAGE_MASK; |
1128 | 56f066bb | Nathan Froyd | start_exclusive(); |
1129 | 56f066bb | Nathan Froyd | mmap_lock(); |
1130 | 56f066bb | Nathan Froyd | flags = page_get_flags(page_addr); |
1131 | 56f066bb | Nathan Froyd | if ((flags & PAGE_READ) == 0) { |
1132 | 56f066bb | Nathan Froyd | segv = 1;
|
1133 | 56f066bb | Nathan Froyd | } else {
|
1134 | 56f066bb | Nathan Froyd | int reg = env->reserve_info & 0x1f; |
1135 | 56f066bb | Nathan Froyd | int size = (env->reserve_info >> 5) & 0xf; |
1136 | 56f066bb | Nathan Froyd | int stored = 0; |
1137 | 56f066bb | Nathan Froyd | |
1138 | 56f066bb | Nathan Froyd | if (addr == env->reserve_addr) {
|
1139 | 56f066bb | Nathan Froyd | switch (size) {
|
1140 | 56f066bb | Nathan Froyd | case 1: segv = get_user_u8(val, addr); break; |
1141 | 56f066bb | Nathan Froyd | case 2: segv = get_user_u16(val, addr); break; |
1142 | 56f066bb | Nathan Froyd | case 4: segv = get_user_u32(val, addr); break; |
1143 | 56f066bb | Nathan Froyd | #if defined(TARGET_PPC64)
|
1144 | 56f066bb | Nathan Froyd | case 8: segv = get_user_u64(val, addr); break; |
1145 | 56f066bb | Nathan Froyd | #endif
|
1146 | 56f066bb | Nathan Froyd | default: abort();
|
1147 | 56f066bb | Nathan Froyd | } |
1148 | 56f066bb | Nathan Froyd | if (!segv && val == env->reserve_val) {
|
1149 | 56f066bb | Nathan Froyd | val = env->gpr[reg]; |
1150 | 56f066bb | Nathan Froyd | switch (size) {
|
1151 | 56f066bb | Nathan Froyd | case 1: segv = put_user_u8(val, addr); break; |
1152 | 56f066bb | Nathan Froyd | case 2: segv = put_user_u16(val, addr); break; |
1153 | 56f066bb | Nathan Froyd | case 4: segv = put_user_u32(val, addr); break; |
1154 | 56f066bb | Nathan Froyd | #if defined(TARGET_PPC64)
|
1155 | 56f066bb | Nathan Froyd | case 8: segv = put_user_u64(val, addr); break; |
1156 | 56f066bb | Nathan Froyd | #endif
|
1157 | 56f066bb | Nathan Froyd | default: abort();
|
1158 | 56f066bb | Nathan Froyd | } |
1159 | 56f066bb | Nathan Froyd | if (!segv) {
|
1160 | 56f066bb | Nathan Froyd | stored = 1;
|
1161 | 56f066bb | Nathan Froyd | } |
1162 | 56f066bb | Nathan Froyd | } |
1163 | 56f066bb | Nathan Froyd | } |
1164 | 56f066bb | Nathan Froyd | env->crf[0] = (stored << 1) | xer_so; |
1165 | 56f066bb | Nathan Froyd | env->reserve_addr = (target_ulong)-1;
|
1166 | 56f066bb | Nathan Froyd | } |
1167 | 56f066bb | Nathan Froyd | if (!segv) {
|
1168 | 56f066bb | Nathan Froyd | env->nip += 4;
|
1169 | 56f066bb | Nathan Froyd | } |
1170 | 56f066bb | Nathan Froyd | mmap_unlock(); |
1171 | 56f066bb | Nathan Froyd | end_exclusive(); |
1172 | 56f066bb | Nathan Froyd | return segv;
|
1173 | 56f066bb | Nathan Froyd | } |
1174 | 56f066bb | Nathan Froyd | |
1175 | 67867308 | bellard | void cpu_loop(CPUPPCState *env)
|
1176 | 67867308 | bellard | { |
1177 | c227f099 | Anthony Liguori | target_siginfo_t info; |
1178 | 61190b14 | bellard | int trapnr;
|
1179 | 61190b14 | bellard | uint32_t ret; |
1180 | 3b46e624 | ths | |
1181 | 67867308 | bellard | for(;;) {
|
1182 | 56f066bb | Nathan Froyd | cpu_exec_start(env); |
1183 | 67867308 | bellard | trapnr = cpu_ppc_exec(env); |
1184 | 56f066bb | Nathan Froyd | cpu_exec_end(env); |
1185 | 67867308 | bellard | switch(trapnr) {
|
1186 | e1833e1f | j_mayer | case POWERPC_EXCP_NONE:
|
1187 | e1833e1f | j_mayer | /* Just go on */
|
1188 | 67867308 | bellard | break;
|
1189 | e1833e1f | j_mayer | case POWERPC_EXCP_CRITICAL: /* Critical input */ |
1190 | e1833e1f | j_mayer | cpu_abort(env, "Critical interrupt while in user mode. "
|
1191 | e1833e1f | j_mayer | "Aborting\n");
|
1192 | 61190b14 | bellard | break;
|
1193 | e1833e1f | j_mayer | case POWERPC_EXCP_MCHECK: /* Machine check exception */ |
1194 | e1833e1f | j_mayer | cpu_abort(env, "Machine check exception while in user mode. "
|
1195 | e1833e1f | j_mayer | "Aborting\n");
|
1196 | e1833e1f | j_mayer | break;
|
1197 | e1833e1f | j_mayer | case POWERPC_EXCP_DSI: /* Data storage exception */ |
1198 | 90e189ec | Blue Swirl | EXCP_DUMP(env, "Invalid data memory access: 0x" TARGET_FMT_lx "\n", |
1199 | e1833e1f | j_mayer | env->spr[SPR_DAR]); |
1200 | e1833e1f | j_mayer | /* XXX: check this. Seems bugged */
|
1201 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
1202 | 2be0071f | bellard | case 0x40000000: |
1203 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1204 | 61190b14 | bellard | info.si_errno = 0;
|
1205 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1206 | 61190b14 | bellard | break;
|
1207 | 2be0071f | bellard | case 0x04000000: |
1208 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1209 | 61190b14 | bellard | info.si_errno = 0;
|
1210 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
1211 | 61190b14 | bellard | break;
|
1212 | 2be0071f | bellard | case 0x08000000: |
1213 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1214 | 61190b14 | bellard | info.si_errno = 0;
|
1215 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
1216 | 61190b14 | bellard | break;
|
1217 | 61190b14 | bellard | default:
|
1218 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
1219 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
|
1220 | e1833e1f | j_mayer | env->error_code); |
1221 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1222 | 61190b14 | bellard | info.si_errno = 0;
|
1223 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1224 | 61190b14 | bellard | break;
|
1225 | 61190b14 | bellard | } |
1226 | 67867308 | bellard | info._sifields._sigfault._addr = env->nip; |
1227 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1228 | 67867308 | bellard | break;
|
1229 | e1833e1f | j_mayer | case POWERPC_EXCP_ISI: /* Instruction storage exception */ |
1230 | 90e189ec | Blue Swirl | EXCP_DUMP(env, "Invalid instruction fetch: 0x\n" TARGET_FMT_lx
|
1231 | 90e189ec | Blue Swirl | "\n", env->spr[SPR_SRR0]);
|
1232 | e1833e1f | j_mayer | /* XXX: check this */
|
1233 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
1234 | 2be0071f | bellard | case 0x40000000: |
1235 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1236 | 67867308 | bellard | info.si_errno = 0;
|
1237 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1238 | 61190b14 | bellard | break;
|
1239 | 2be0071f | bellard | case 0x10000000: |
1240 | 2be0071f | bellard | case 0x08000000: |
1241 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1242 | 61190b14 | bellard | info.si_errno = 0;
|
1243 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
1244 | 61190b14 | bellard | break;
|
1245 | 61190b14 | bellard | default:
|
1246 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
1247 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
|
1248 | e1833e1f | j_mayer | env->error_code); |
1249 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1250 | 61190b14 | bellard | info.si_errno = 0;
|
1251 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1252 | 61190b14 | bellard | break;
|
1253 | 61190b14 | bellard | } |
1254 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1255 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1256 | 67867308 | bellard | break;
|
1257 | e1833e1f | j_mayer | case POWERPC_EXCP_EXTERNAL: /* External input */ |
1258 | e1833e1f | j_mayer | cpu_abort(env, "External interrupt while in user mode. "
|
1259 | e1833e1f | j_mayer | "Aborting\n");
|
1260 | e1833e1f | j_mayer | break;
|
1261 | e1833e1f | j_mayer | case POWERPC_EXCP_ALIGN: /* Alignment exception */ |
1262 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unaligned memory access\n");
|
1263 | e1833e1f | j_mayer | /* XXX: check this */
|
1264 | 61190b14 | bellard | info.si_signo = TARGET_SIGBUS; |
1265 | 67867308 | bellard | info.si_errno = 0;
|
1266 | 61190b14 | bellard | info.si_code = TARGET_BUS_ADRALN; |
1267 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1268 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1269 | 67867308 | bellard | break;
|
1270 | e1833e1f | j_mayer | case POWERPC_EXCP_PROGRAM: /* Program exception */ |
1271 | e1833e1f | j_mayer | /* XXX: check this */
|
1272 | 61190b14 | bellard | switch (env->error_code & ~0xF) { |
1273 | e1833e1f | j_mayer | case POWERPC_EXCP_FP:
|
1274 | e1833e1f | j_mayer | EXCP_DUMP(env, "Floating point program exception\n");
|
1275 | 61190b14 | bellard | info.si_signo = TARGET_SIGFPE; |
1276 | 61190b14 | bellard | info.si_errno = 0;
|
1277 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1278 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_OX:
|
1279 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTOVF; |
1280 | 61190b14 | bellard | break;
|
1281 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_UX:
|
1282 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTUND; |
1283 | 61190b14 | bellard | break;
|
1284 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_ZX:
|
1285 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXZDZ:
|
1286 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTDIV; |
1287 | 61190b14 | bellard | break;
|
1288 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_XX:
|
1289 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTRES; |
1290 | 61190b14 | bellard | break;
|
1291 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXSOFT:
|
1292 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTINV; |
1293 | 61190b14 | bellard | break;
|
1294 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXSNAN:
|
1295 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXISI:
|
1296 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXIDI:
|
1297 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXIMZ:
|
1298 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXVC:
|
1299 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXSQRT:
|
1300 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXCVI:
|
1301 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTSUB; |
1302 | 61190b14 | bellard | break;
|
1303 | 61190b14 | bellard | default:
|
1304 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown floating point exception (%02x)\n",
|
1305 | e1833e1f | j_mayer | env->error_code); |
1306 | e1833e1f | j_mayer | break;
|
1307 | 61190b14 | bellard | } |
1308 | e1833e1f | j_mayer | break;
|
1309 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL:
|
1310 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid instruction\n");
|
1311 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1312 | 61190b14 | bellard | info.si_errno = 0;
|
1313 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1314 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_INVAL:
|
1315 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLOPC; |
1316 | 61190b14 | bellard | break;
|
1317 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_LSWX:
|
1318 | a750fc0b | j_mayer | info.si_code = TARGET_ILL_ILLOPN; |
1319 | 61190b14 | bellard | break;
|
1320 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_SPR:
|
1321 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
1322 | 61190b14 | bellard | break;
|
1323 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_FP:
|
1324 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
1325 | 61190b14 | bellard | break;
|
1326 | 61190b14 | bellard | default:
|
1327 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown invalid operation (%02x)\n",
|
1328 | e1833e1f | j_mayer | env->error_code & 0xF);
|
1329 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
1330 | 61190b14 | bellard | break;
|
1331 | 61190b14 | bellard | } |
1332 | 61190b14 | bellard | break;
|
1333 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV:
|
1334 | e1833e1f | j_mayer | EXCP_DUMP(env, "Privilege violation\n");
|
1335 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1336 | 61190b14 | bellard | info.si_errno = 0;
|
1337 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1338 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV_OPC:
|
1339 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
1340 | 61190b14 | bellard | break;
|
1341 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV_REG:
|
1342 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
1343 | e1833e1f | j_mayer | break;
|
1344 | 61190b14 | bellard | default:
|
1345 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown privilege violation (%02x)\n",
|
1346 | e1833e1f | j_mayer | env->error_code & 0xF);
|
1347 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
1348 | 61190b14 | bellard | break;
|
1349 | 61190b14 | bellard | } |
1350 | 61190b14 | bellard | break;
|
1351 | e1833e1f | j_mayer | case POWERPC_EXCP_TRAP:
|
1352 | e1833e1f | j_mayer | cpu_abort(env, "Tried to call a TRAP\n");
|
1353 | e1833e1f | j_mayer | break;
|
1354 | 61190b14 | bellard | default:
|
1355 | 61190b14 | bellard | /* Should not happen ! */
|
1356 | e1833e1f | j_mayer | cpu_abort(env, "Unknown program exception (%02x)\n",
|
1357 | e1833e1f | j_mayer | env->error_code); |
1358 | e1833e1f | j_mayer | break;
|
1359 | 61190b14 | bellard | } |
1360 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1361 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1362 | 67867308 | bellard | break;
|
1363 | e1833e1f | j_mayer | case POWERPC_EXCP_FPU: /* Floating-point unavailable exception */ |
1364 | e1833e1f | j_mayer | EXCP_DUMP(env, "No floating point allowed\n");
|
1365 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1366 | 67867308 | bellard | info.si_errno = 0;
|
1367 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
1368 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1369 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1370 | 67867308 | bellard | break;
|
1371 | e1833e1f | j_mayer | case POWERPC_EXCP_SYSCALL: /* System call exception */ |
1372 | e1833e1f | j_mayer | cpu_abort(env, "Syscall exception while in user mode. "
|
1373 | e1833e1f | j_mayer | "Aborting\n");
|
1374 | 61190b14 | bellard | break;
|
1375 | e1833e1f | j_mayer | case POWERPC_EXCP_APU: /* Auxiliary processor unavailable */ |
1376 | e1833e1f | j_mayer | EXCP_DUMP(env, "No APU instruction allowed\n");
|
1377 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1378 | e1833e1f | j_mayer | info.si_errno = 0;
|
1379 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1380 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1381 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1382 | 61190b14 | bellard | break;
|
1383 | e1833e1f | j_mayer | case POWERPC_EXCP_DECR: /* Decrementer exception */ |
1384 | e1833e1f | j_mayer | cpu_abort(env, "Decrementer interrupt while in user mode. "
|
1385 | e1833e1f | j_mayer | "Aborting\n");
|
1386 | 61190b14 | bellard | break;
|
1387 | e1833e1f | j_mayer | case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt */ |
1388 | e1833e1f | j_mayer | cpu_abort(env, "Fix interval timer interrupt while in user mode. "
|
1389 | e1833e1f | j_mayer | "Aborting\n");
|
1390 | e1833e1f | j_mayer | break;
|
1391 | e1833e1f | j_mayer | case POWERPC_EXCP_WDT: /* Watchdog timer interrupt */ |
1392 | e1833e1f | j_mayer | cpu_abort(env, "Watchdog timer interrupt while in user mode. "
|
1393 | e1833e1f | j_mayer | "Aborting\n");
|
1394 | e1833e1f | j_mayer | break;
|
1395 | e1833e1f | j_mayer | case POWERPC_EXCP_DTLB: /* Data TLB error */ |
1396 | e1833e1f | j_mayer | cpu_abort(env, "Data TLB exception while in user mode. "
|
1397 | e1833e1f | j_mayer | "Aborting\n");
|
1398 | e1833e1f | j_mayer | break;
|
1399 | e1833e1f | j_mayer | case POWERPC_EXCP_ITLB: /* Instruction TLB error */ |
1400 | e1833e1f | j_mayer | cpu_abort(env, "Instruction TLB exception while in user mode. "
|
1401 | e1833e1f | j_mayer | "Aborting\n");
|
1402 | e1833e1f | j_mayer | break;
|
1403 | e1833e1f | j_mayer | case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavail. */ |
1404 | e1833e1f | j_mayer | EXCP_DUMP(env, "No SPE/floating-point instruction allowed\n");
|
1405 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1406 | e1833e1f | j_mayer | info.si_errno = 0;
|
1407 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1408 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1409 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1410 | e1833e1f | j_mayer | break;
|
1411 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPDI: /* Embedded floating-point data IRQ */ |
1412 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating-point data IRQ not handled\n");
|
1413 | e1833e1f | j_mayer | break;
|
1414 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPRI: /* Embedded floating-point round IRQ */ |
1415 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating-point round IRQ not handled\n");
|
1416 | e1833e1f | j_mayer | break;
|
1417 | e1833e1f | j_mayer | case POWERPC_EXCP_EPERFM: /* Embedded performance monitor IRQ */ |
1418 | e1833e1f | j_mayer | cpu_abort(env, "Performance monitor exception not handled\n");
|
1419 | e1833e1f | j_mayer | break;
|
1420 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt */ |
1421 | e1833e1f | j_mayer | cpu_abort(env, "Doorbell interrupt while in user mode. "
|
1422 | e1833e1f | j_mayer | "Aborting\n");
|
1423 | e1833e1f | j_mayer | break;
|
1424 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrupt */ |
1425 | e1833e1f | j_mayer | cpu_abort(env, "Doorbell critical interrupt while in user mode. "
|
1426 | e1833e1f | j_mayer | "Aborting\n");
|
1427 | e1833e1f | j_mayer | break;
|
1428 | e1833e1f | j_mayer | case POWERPC_EXCP_RESET: /* System reset exception */ |
1429 | e1833e1f | j_mayer | cpu_abort(env, "Reset interrupt while in user mode. "
|
1430 | e1833e1f | j_mayer | "Aborting\n");
|
1431 | e1833e1f | j_mayer | break;
|
1432 | e1833e1f | j_mayer | case POWERPC_EXCP_DSEG: /* Data segment exception */ |
1433 | e1833e1f | j_mayer | cpu_abort(env, "Data segment exception while in user mode. "
|
1434 | e1833e1f | j_mayer | "Aborting\n");
|
1435 | e1833e1f | j_mayer | break;
|
1436 | e1833e1f | j_mayer | case POWERPC_EXCP_ISEG: /* Instruction segment exception */ |
1437 | e1833e1f | j_mayer | cpu_abort(env, "Instruction segment exception "
|
1438 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1439 | e1833e1f | j_mayer | break;
|
1440 | e85e7c6e | j_mayer | /* PowerPC 64 with hypervisor mode support */
|
1441 | e1833e1f | j_mayer | case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception */ |
1442 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor decrementer interrupt "
|
1443 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1444 | e1833e1f | j_mayer | break;
|
1445 | e1833e1f | j_mayer | case POWERPC_EXCP_TRACE: /* Trace exception */ |
1446 | e1833e1f | j_mayer | /* Nothing to do:
|
1447 | e1833e1f | j_mayer | * we use this exception to emulate step-by-step execution mode.
|
1448 | e1833e1f | j_mayer | */
|
1449 | e1833e1f | j_mayer | break;
|
1450 | e85e7c6e | j_mayer | /* PowerPC 64 with hypervisor mode support */
|
1451 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception */ |
1452 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor data storage exception "
|
1453 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1454 | e1833e1f | j_mayer | break;
|
1455 | e1833e1f | j_mayer | case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excp */ |
1456 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor instruction storage exception "
|
1457 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1458 | e1833e1f | j_mayer | break;
|
1459 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception */ |
1460 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor data segment exception "
|
1461 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1462 | e1833e1f | j_mayer | break;
|
1463 | e1833e1f | j_mayer | case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excp */ |
1464 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor instruction segment exception "
|
1465 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1466 | e1833e1f | j_mayer | break;
|
1467 | e1833e1f | j_mayer | case POWERPC_EXCP_VPU: /* Vector unavailable exception */ |
1468 | e1833e1f | j_mayer | EXCP_DUMP(env, "No Altivec instructions allowed\n");
|
1469 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1470 | e1833e1f | j_mayer | info.si_errno = 0;
|
1471 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1472 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1473 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1474 | e1833e1f | j_mayer | break;
|
1475 | e1833e1f | j_mayer | case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ */ |
1476 | e1833e1f | j_mayer | cpu_abort(env, "Programable interval timer interrupt "
|
1477 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1478 | e1833e1f | j_mayer | break;
|
1479 | e1833e1f | j_mayer | case POWERPC_EXCP_IO: /* IO error exception */ |
1480 | e1833e1f | j_mayer | cpu_abort(env, "IO error exception while in user mode. "
|
1481 | e1833e1f | j_mayer | "Aborting\n");
|
1482 | e1833e1f | j_mayer | break;
|
1483 | e1833e1f | j_mayer | case POWERPC_EXCP_RUNM: /* Run mode exception */ |
1484 | e1833e1f | j_mayer | cpu_abort(env, "Run mode exception while in user mode. "
|
1485 | e1833e1f | j_mayer | "Aborting\n");
|
1486 | e1833e1f | j_mayer | break;
|
1487 | e1833e1f | j_mayer | case POWERPC_EXCP_EMUL: /* Emulation trap exception */ |
1488 | e1833e1f | j_mayer | cpu_abort(env, "Emulation trap exception not handled\n");
|
1489 | e1833e1f | j_mayer | break;
|
1490 | e1833e1f | j_mayer | case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error */ |
1491 | e1833e1f | j_mayer | cpu_abort(env, "Instruction fetch TLB exception "
|
1492 | e1833e1f | j_mayer | "while in user-mode. Aborting");
|
1493 | e1833e1f | j_mayer | break;
|
1494 | e1833e1f | j_mayer | case POWERPC_EXCP_DLTLB: /* Data load TLB miss */ |
1495 | e1833e1f | j_mayer | cpu_abort(env, "Data load TLB exception while in user-mode. "
|
1496 | e1833e1f | j_mayer | "Aborting");
|
1497 | e1833e1f | j_mayer | break;
|
1498 | e1833e1f | j_mayer | case POWERPC_EXCP_DSTLB: /* Data store TLB miss */ |
1499 | e1833e1f | j_mayer | cpu_abort(env, "Data store TLB exception while in user-mode. "
|
1500 | e1833e1f | j_mayer | "Aborting");
|
1501 | e1833e1f | j_mayer | break;
|
1502 | e1833e1f | j_mayer | case POWERPC_EXCP_FPA: /* Floating-point assist exception */ |
1503 | e1833e1f | j_mayer | cpu_abort(env, "Floating-point assist exception not handled\n");
|
1504 | e1833e1f | j_mayer | break;
|
1505 | e1833e1f | j_mayer | case POWERPC_EXCP_IABR: /* Instruction address breakpoint */ |
1506 | e1833e1f | j_mayer | cpu_abort(env, "Instruction address breakpoint exception "
|
1507 | e1833e1f | j_mayer | "not handled\n");
|
1508 | e1833e1f | j_mayer | break;
|
1509 | e1833e1f | j_mayer | case POWERPC_EXCP_SMI: /* System management interrupt */ |
1510 | e1833e1f | j_mayer | cpu_abort(env, "System management interrupt while in user mode. "
|
1511 | e1833e1f | j_mayer | "Aborting\n");
|
1512 | e1833e1f | j_mayer | break;
|
1513 | e1833e1f | j_mayer | case POWERPC_EXCP_THERM: /* Thermal interrupt */ |
1514 | e1833e1f | j_mayer | cpu_abort(env, "Thermal interrupt interrupt while in user mode. "
|
1515 | e1833e1f | j_mayer | "Aborting\n");
|
1516 | e1833e1f | j_mayer | break;
|
1517 | e1833e1f | j_mayer | case POWERPC_EXCP_PERFM: /* Embedded performance monitor IRQ */ |
1518 | e1833e1f | j_mayer | cpu_abort(env, "Performance monitor exception not handled\n");
|
1519 | e1833e1f | j_mayer | break;
|
1520 | e1833e1f | j_mayer | case POWERPC_EXCP_VPUA: /* Vector assist exception */ |
1521 | e1833e1f | j_mayer | cpu_abort(env, "Vector assist exception not handled\n");
|
1522 | e1833e1f | j_mayer | break;
|
1523 | e1833e1f | j_mayer | case POWERPC_EXCP_SOFTP: /* Soft patch exception */ |
1524 | e1833e1f | j_mayer | cpu_abort(env, "Soft patch exception not handled\n");
|
1525 | e1833e1f | j_mayer | break;
|
1526 | e1833e1f | j_mayer | case POWERPC_EXCP_MAINT: /* Maintenance exception */ |
1527 | e1833e1f | j_mayer | cpu_abort(env, "Maintenance exception while in user mode. "
|
1528 | e1833e1f | j_mayer | "Aborting\n");
|
1529 | e1833e1f | j_mayer | break;
|
1530 | e1833e1f | j_mayer | case POWERPC_EXCP_STOP: /* stop translation */ |
1531 | e1833e1f | j_mayer | /* We did invalidate the instruction cache. Go on */
|
1532 | e1833e1f | j_mayer | break;
|
1533 | e1833e1f | j_mayer | case POWERPC_EXCP_BRANCH: /* branch instruction: */ |
1534 | e1833e1f | j_mayer | /* We just stopped because of a branch. Go on */
|
1535 | e1833e1f | j_mayer | break;
|
1536 | e1833e1f | j_mayer | case POWERPC_EXCP_SYSCALL_USER:
|
1537 | e1833e1f | j_mayer | /* system call in user-mode emulation */
|
1538 | e1833e1f | j_mayer | /* WARNING:
|
1539 | e1833e1f | j_mayer | * PPC ABI uses overflow flag in cr0 to signal an error
|
1540 | e1833e1f | j_mayer | * in syscalls.
|
1541 | e1833e1f | j_mayer | */
|
1542 | e1833e1f | j_mayer | #if 0
|
1543 | e1833e1f | j_mayer | printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env->gpr[0],
|
1544 | e1833e1f | j_mayer | env->gpr[3], env->gpr[4], env->gpr[5], env->gpr[6]);
|
1545 | e1833e1f | j_mayer | #endif
|
1546 | e1833e1f | j_mayer | env->crf[0] &= ~0x1; |
1547 | e1833e1f | j_mayer | ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4], |
1548 | e1833e1f | j_mayer | env->gpr[5], env->gpr[6], env->gpr[7], |
1549 | e1833e1f | j_mayer | env->gpr[8]);
|
1550 | bcd4933a | Nathan Froyd | if (ret == (uint32_t)(-TARGET_QEMU_ESIGRETURN)) {
|
1551 | bcd4933a | Nathan Froyd | /* Returning from a successful sigreturn syscall.
|
1552 | bcd4933a | Nathan Froyd | Avoid corrupting register state. */
|
1553 | bcd4933a | Nathan Froyd | break;
|
1554 | bcd4933a | Nathan Froyd | } |
1555 | e1833e1f | j_mayer | if (ret > (uint32_t)(-515)) { |
1556 | e1833e1f | j_mayer | env->crf[0] |= 0x1; |
1557 | e1833e1f | j_mayer | ret = -ret; |
1558 | 61190b14 | bellard | } |
1559 | e1833e1f | j_mayer | env->gpr[3] = ret;
|
1560 | e1833e1f | j_mayer | #if 0
|
1561 | e1833e1f | j_mayer | printf("syscall returned 0x%08x (%d)\n", ret, ret);
|
1562 | e1833e1f | j_mayer | #endif
|
1563 | e1833e1f | j_mayer | break;
|
1564 | 56f066bb | Nathan Froyd | case POWERPC_EXCP_STCX:
|
1565 | 56f066bb | Nathan Froyd | if (do_store_exclusive(env)) {
|
1566 | 56f066bb | Nathan Froyd | info.si_signo = TARGET_SIGSEGV; |
1567 | 56f066bb | Nathan Froyd | info.si_errno = 0;
|
1568 | 56f066bb | Nathan Froyd | info.si_code = TARGET_SEGV_MAPERR; |
1569 | 56f066bb | Nathan Froyd | info._sifields._sigfault._addr = env->nip; |
1570 | 56f066bb | Nathan Froyd | queue_signal(env, info.si_signo, &info); |
1571 | 56f066bb | Nathan Froyd | } |
1572 | 56f066bb | Nathan Froyd | break;
|
1573 | 71f75756 | aurel32 | case EXCP_DEBUG:
|
1574 | 71f75756 | aurel32 | { |
1575 | 71f75756 | aurel32 | int sig;
|
1576 | 71f75756 | aurel32 | |
1577 | 71f75756 | aurel32 | sig = gdb_handlesig(env, TARGET_SIGTRAP); |
1578 | 71f75756 | aurel32 | if (sig) {
|
1579 | 71f75756 | aurel32 | info.si_signo = sig; |
1580 | 71f75756 | aurel32 | info.si_errno = 0;
|
1581 | 71f75756 | aurel32 | info.si_code = TARGET_TRAP_BRKPT; |
1582 | 71f75756 | aurel32 | queue_signal(env, info.si_signo, &info); |
1583 | 71f75756 | aurel32 | } |
1584 | 71f75756 | aurel32 | } |
1585 | 71f75756 | aurel32 | break;
|
1586 | 56ba31ff | j_mayer | case EXCP_INTERRUPT:
|
1587 | 56ba31ff | j_mayer | /* just indicate that signals should be handled asap */
|
1588 | 56ba31ff | j_mayer | break;
|
1589 | e1833e1f | j_mayer | default:
|
1590 | e1833e1f | j_mayer | cpu_abort(env, "Unknown exception 0x%d. Aborting\n", trapnr);
|
1591 | e1833e1f | j_mayer | break;
|
1592 | 67867308 | bellard | } |
1593 | 67867308 | bellard | process_pending_signals(env); |
1594 | 67867308 | bellard | } |
1595 | 67867308 | bellard | } |
1596 | 67867308 | bellard | #endif
|
1597 | 67867308 | bellard | |
1598 | 048f6b4d | bellard | #ifdef TARGET_MIPS
|
1599 | 048f6b4d | bellard | |
1600 | 048f6b4d | bellard | #define MIPS_SYS(name, args) args,
|
1601 | 048f6b4d | bellard | |
1602 | 048f6b4d | bellard | static const uint8_t mips_syscall_args[] = { |
1603 | 048f6b4d | bellard | MIPS_SYS(sys_syscall , 0) /* 4000 */ |
1604 | 048f6b4d | bellard | MIPS_SYS(sys_exit , 1)
|
1605 | 048f6b4d | bellard | MIPS_SYS(sys_fork , 0)
|
1606 | 048f6b4d | bellard | MIPS_SYS(sys_read , 3)
|
1607 | 048f6b4d | bellard | MIPS_SYS(sys_write , 3)
|
1608 | 048f6b4d | bellard | MIPS_SYS(sys_open , 3) /* 4005 */ |
1609 | 048f6b4d | bellard | MIPS_SYS(sys_close , 1)
|
1610 | 048f6b4d | bellard | MIPS_SYS(sys_waitpid , 3)
|
1611 | 048f6b4d | bellard | MIPS_SYS(sys_creat , 2)
|
1612 | 048f6b4d | bellard | MIPS_SYS(sys_link , 2)
|
1613 | 048f6b4d | bellard | MIPS_SYS(sys_unlink , 1) /* 4010 */ |
1614 | 048f6b4d | bellard | MIPS_SYS(sys_execve , 0)
|
1615 | 048f6b4d | bellard | MIPS_SYS(sys_chdir , 1)
|
1616 | 048f6b4d | bellard | MIPS_SYS(sys_time , 1)
|
1617 | 048f6b4d | bellard | MIPS_SYS(sys_mknod , 3)
|
1618 | 048f6b4d | bellard | MIPS_SYS(sys_chmod , 2) /* 4015 */ |
1619 | 048f6b4d | bellard | MIPS_SYS(sys_lchown , 3)
|
1620 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1621 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_stat */ |
1622 | 048f6b4d | bellard | MIPS_SYS(sys_lseek , 3)
|
1623 | 048f6b4d | bellard | MIPS_SYS(sys_getpid , 0) /* 4020 */ |
1624 | 048f6b4d | bellard | MIPS_SYS(sys_mount , 5)
|
1625 | 048f6b4d | bellard | MIPS_SYS(sys_oldumount , 1)
|
1626 | 048f6b4d | bellard | MIPS_SYS(sys_setuid , 1)
|
1627 | 048f6b4d | bellard | MIPS_SYS(sys_getuid , 0)
|
1628 | 048f6b4d | bellard | MIPS_SYS(sys_stime , 1) /* 4025 */ |
1629 | 048f6b4d | bellard | MIPS_SYS(sys_ptrace , 4)
|
1630 | 048f6b4d | bellard | MIPS_SYS(sys_alarm , 1)
|
1631 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_fstat */ |
1632 | 048f6b4d | bellard | MIPS_SYS(sys_pause , 0)
|
1633 | 048f6b4d | bellard | MIPS_SYS(sys_utime , 2) /* 4030 */ |
1634 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1635 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1636 | 048f6b4d | bellard | MIPS_SYS(sys_access , 2)
|
1637 | 048f6b4d | bellard | MIPS_SYS(sys_nice , 1)
|
1638 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4035 */ |
1639 | 048f6b4d | bellard | MIPS_SYS(sys_sync , 0)
|
1640 | 048f6b4d | bellard | MIPS_SYS(sys_kill , 2)
|
1641 | 048f6b4d | bellard | MIPS_SYS(sys_rename , 2)
|
1642 | 048f6b4d | bellard | MIPS_SYS(sys_mkdir , 2)
|
1643 | 048f6b4d | bellard | MIPS_SYS(sys_rmdir , 1) /* 4040 */ |
1644 | 048f6b4d | bellard | MIPS_SYS(sys_dup , 1)
|
1645 | 048f6b4d | bellard | MIPS_SYS(sys_pipe , 0)
|
1646 | 048f6b4d | bellard | MIPS_SYS(sys_times , 1)
|
1647 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1648 | 048f6b4d | bellard | MIPS_SYS(sys_brk , 1) /* 4045 */ |
1649 | 048f6b4d | bellard | MIPS_SYS(sys_setgid , 1)
|
1650 | 048f6b4d | bellard | MIPS_SYS(sys_getgid , 0)
|
1651 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was signal(2) */ |
1652 | 048f6b4d | bellard | MIPS_SYS(sys_geteuid , 0)
|
1653 | 048f6b4d | bellard | MIPS_SYS(sys_getegid , 0) /* 4050 */ |
1654 | 048f6b4d | bellard | MIPS_SYS(sys_acct , 0)
|
1655 | 048f6b4d | bellard | MIPS_SYS(sys_umount , 2)
|
1656 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1657 | 048f6b4d | bellard | MIPS_SYS(sys_ioctl , 3)
|
1658 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl , 3) /* 4055 */ |
1659 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 2)
|
1660 | 048f6b4d | bellard | MIPS_SYS(sys_setpgid , 2)
|
1661 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1662 | 048f6b4d | bellard | MIPS_SYS(sys_olduname , 1)
|
1663 | 048f6b4d | bellard | MIPS_SYS(sys_umask , 1) /* 4060 */ |
1664 | 048f6b4d | bellard | MIPS_SYS(sys_chroot , 1)
|
1665 | 048f6b4d | bellard | MIPS_SYS(sys_ustat , 2)
|
1666 | 048f6b4d | bellard | MIPS_SYS(sys_dup2 , 2)
|
1667 | 048f6b4d | bellard | MIPS_SYS(sys_getppid , 0)
|
1668 | 048f6b4d | bellard | MIPS_SYS(sys_getpgrp , 0) /* 4065 */ |
1669 | 048f6b4d | bellard | MIPS_SYS(sys_setsid , 0)
|
1670 | 048f6b4d | bellard | MIPS_SYS(sys_sigaction , 3)
|
1671 | 048f6b4d | bellard | MIPS_SYS(sys_sgetmask , 0)
|
1672 | 048f6b4d | bellard | MIPS_SYS(sys_ssetmask , 1)
|
1673 | 048f6b4d | bellard | MIPS_SYS(sys_setreuid , 2) /* 4070 */ |
1674 | 048f6b4d | bellard | MIPS_SYS(sys_setregid , 2)
|
1675 | 048f6b4d | bellard | MIPS_SYS(sys_sigsuspend , 0)
|
1676 | 048f6b4d | bellard | MIPS_SYS(sys_sigpending , 1)
|
1677 | 048f6b4d | bellard | MIPS_SYS(sys_sethostname , 2)
|
1678 | 048f6b4d | bellard | MIPS_SYS(sys_setrlimit , 2) /* 4075 */ |
1679 | 048f6b4d | bellard | MIPS_SYS(sys_getrlimit , 2)
|
1680 | 048f6b4d | bellard | MIPS_SYS(sys_getrusage , 2)
|
1681 | 048f6b4d | bellard | MIPS_SYS(sys_gettimeofday, 2)
|
1682 | 048f6b4d | bellard | MIPS_SYS(sys_settimeofday, 2)
|
1683 | 048f6b4d | bellard | MIPS_SYS(sys_getgroups , 2) /* 4080 */ |
1684 | 048f6b4d | bellard | MIPS_SYS(sys_setgroups , 2)
|
1685 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* old_select */ |
1686 | 048f6b4d | bellard | MIPS_SYS(sys_symlink , 2)
|
1687 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_lstat */ |
1688 | 048f6b4d | bellard | MIPS_SYS(sys_readlink , 3) /* 4085 */ |
1689 | 048f6b4d | bellard | MIPS_SYS(sys_uselib , 1)
|
1690 | 048f6b4d | bellard | MIPS_SYS(sys_swapon , 2)
|
1691 | 048f6b4d | bellard | MIPS_SYS(sys_reboot , 3)
|
1692 | 048f6b4d | bellard | MIPS_SYS(old_readdir , 3)
|
1693 | 048f6b4d | bellard | MIPS_SYS(old_mmap , 6) /* 4090 */ |
1694 | 048f6b4d | bellard | MIPS_SYS(sys_munmap , 2)
|
1695 | 048f6b4d | bellard | MIPS_SYS(sys_truncate , 2)
|
1696 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate , 2)
|
1697 | 048f6b4d | bellard | MIPS_SYS(sys_fchmod , 2)
|
1698 | 048f6b4d | bellard | MIPS_SYS(sys_fchown , 3) /* 4095 */ |
1699 | 048f6b4d | bellard | MIPS_SYS(sys_getpriority , 2)
|
1700 | 048f6b4d | bellard | MIPS_SYS(sys_setpriority , 3)
|
1701 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1702 | 048f6b4d | bellard | MIPS_SYS(sys_statfs , 2)
|
1703 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs , 2) /* 4100 */ |
1704 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was ioperm(2) */ |
1705 | 048f6b4d | bellard | MIPS_SYS(sys_socketcall , 2)
|
1706 | 048f6b4d | bellard | MIPS_SYS(sys_syslog , 3)
|
1707 | 048f6b4d | bellard | MIPS_SYS(sys_setitimer , 3)
|
1708 | 048f6b4d | bellard | MIPS_SYS(sys_getitimer , 2) /* 4105 */ |
1709 | 048f6b4d | bellard | MIPS_SYS(sys_newstat , 2)
|
1710 | 048f6b4d | bellard | MIPS_SYS(sys_newlstat , 2)
|
1711 | 048f6b4d | bellard | MIPS_SYS(sys_newfstat , 2)
|
1712 | 048f6b4d | bellard | MIPS_SYS(sys_uname , 1)
|
1713 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4110 was iopl(2) */ |
1714 | 048f6b4d | bellard | MIPS_SYS(sys_vhangup , 0)
|
1715 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_idle() */ |
1716 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_vm86 */ |
1717 | 048f6b4d | bellard | MIPS_SYS(sys_wait4 , 4)
|
1718 | 048f6b4d | bellard | MIPS_SYS(sys_swapoff , 1) /* 4115 */ |
1719 | 048f6b4d | bellard | MIPS_SYS(sys_sysinfo , 1)
|
1720 | 048f6b4d | bellard | MIPS_SYS(sys_ipc , 6)
|
1721 | 048f6b4d | bellard | MIPS_SYS(sys_fsync , 1)
|
1722 | 048f6b4d | bellard | MIPS_SYS(sys_sigreturn , 0)
|
1723 | 18113962 | Paul Brook | MIPS_SYS(sys_clone , 6) /* 4120 */ |
1724 | 048f6b4d | bellard | MIPS_SYS(sys_setdomainname, 2)
|
1725 | 048f6b4d | bellard | MIPS_SYS(sys_newuname , 1)
|
1726 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_modify_ldt */ |
1727 | 048f6b4d | bellard | MIPS_SYS(sys_adjtimex , 1)
|
1728 | 048f6b4d | bellard | MIPS_SYS(sys_mprotect , 3) /* 4125 */ |
1729 | 048f6b4d | bellard | MIPS_SYS(sys_sigprocmask , 3)
|
1730 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was create_module */ |
1731 | 048f6b4d | bellard | MIPS_SYS(sys_init_module , 5)
|
1732 | 048f6b4d | bellard | MIPS_SYS(sys_delete_module, 1)
|
1733 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4130 was get_kernel_syms */ |
1734 | 048f6b4d | bellard | MIPS_SYS(sys_quotactl , 0)
|
1735 | 048f6b4d | bellard | MIPS_SYS(sys_getpgid , 1)
|
1736 | 048f6b4d | bellard | MIPS_SYS(sys_fchdir , 1)
|
1737 | 048f6b4d | bellard | MIPS_SYS(sys_bdflush , 2)
|
1738 | 048f6b4d | bellard | MIPS_SYS(sys_sysfs , 3) /* 4135 */ |
1739 | 048f6b4d | bellard | MIPS_SYS(sys_personality , 1)
|
1740 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* for afs_syscall */ |
1741 | 048f6b4d | bellard | MIPS_SYS(sys_setfsuid , 1)
|
1742 | 048f6b4d | bellard | MIPS_SYS(sys_setfsgid , 1)
|
1743 | 048f6b4d | bellard | MIPS_SYS(sys_llseek , 5) /* 4140 */ |
1744 | 048f6b4d | bellard | MIPS_SYS(sys_getdents , 3)
|
1745 | 048f6b4d | bellard | MIPS_SYS(sys_select , 5)
|
1746 | 048f6b4d | bellard | MIPS_SYS(sys_flock , 2)
|
1747 | 048f6b4d | bellard | MIPS_SYS(sys_msync , 3)
|
1748 | 048f6b4d | bellard | MIPS_SYS(sys_readv , 3) /* 4145 */ |
1749 | 048f6b4d | bellard | MIPS_SYS(sys_writev , 3)
|
1750 | 048f6b4d | bellard | MIPS_SYS(sys_cacheflush , 3)
|
1751 | 048f6b4d | bellard | MIPS_SYS(sys_cachectl , 3)
|
1752 | 048f6b4d | bellard | MIPS_SYS(sys_sysmips , 4)
|
1753 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4150 */ |
1754 | 048f6b4d | bellard | MIPS_SYS(sys_getsid , 1)
|
1755 | 048f6b4d | bellard | MIPS_SYS(sys_fdatasync , 0)
|
1756 | 048f6b4d | bellard | MIPS_SYS(sys_sysctl , 1)
|
1757 | 048f6b4d | bellard | MIPS_SYS(sys_mlock , 2)
|
1758 | 048f6b4d | bellard | MIPS_SYS(sys_munlock , 2) /* 4155 */ |
1759 | 048f6b4d | bellard | MIPS_SYS(sys_mlockall , 1)
|
1760 | 048f6b4d | bellard | MIPS_SYS(sys_munlockall , 0)
|
1761 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setparam, 2)
|
1762 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getparam, 2)
|
1763 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setscheduler, 3) /* 4160 */ |
1764 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getscheduler, 1)
|
1765 | 048f6b4d | bellard | MIPS_SYS(sys_sched_yield , 0)
|
1766 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_max, 1)
|
1767 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_min, 1)
|
1768 | 048f6b4d | bellard | MIPS_SYS(sys_sched_rr_get_interval, 2) /* 4165 */ |
1769 | 048f6b4d | bellard | MIPS_SYS(sys_nanosleep, 2)
|
1770 | 048f6b4d | bellard | MIPS_SYS(sys_mremap , 4)
|
1771 | 048f6b4d | bellard | MIPS_SYS(sys_accept , 3)
|
1772 | 048f6b4d | bellard | MIPS_SYS(sys_bind , 3)
|
1773 | 048f6b4d | bellard | MIPS_SYS(sys_connect , 3) /* 4170 */ |
1774 | 048f6b4d | bellard | MIPS_SYS(sys_getpeername , 3)
|
1775 | 048f6b4d | bellard | MIPS_SYS(sys_getsockname , 3)
|
1776 | 048f6b4d | bellard | MIPS_SYS(sys_getsockopt , 5)
|
1777 | 048f6b4d | bellard | MIPS_SYS(sys_listen , 2)
|
1778 | 048f6b4d | bellard | MIPS_SYS(sys_recv , 4) /* 4175 */ |
1779 | 048f6b4d | bellard | MIPS_SYS(sys_recvfrom , 6)
|
1780 | 048f6b4d | bellard | MIPS_SYS(sys_recvmsg , 3)
|
1781 | 048f6b4d | bellard | MIPS_SYS(sys_send , 4)
|
1782 | 048f6b4d | bellard | MIPS_SYS(sys_sendmsg , 3)
|
1783 | 048f6b4d | bellard | MIPS_SYS(sys_sendto , 6) /* 4180 */ |
1784 | 048f6b4d | bellard | MIPS_SYS(sys_setsockopt , 5)
|
1785 | 048f6b4d | bellard | MIPS_SYS(sys_shutdown , 2)
|
1786 | 048f6b4d | bellard | MIPS_SYS(sys_socket , 3)
|
1787 | 048f6b4d | bellard | MIPS_SYS(sys_socketpair , 4)
|
1788 | 048f6b4d | bellard | MIPS_SYS(sys_setresuid , 3) /* 4185 */ |
1789 | 048f6b4d | bellard | MIPS_SYS(sys_getresuid , 3)
|
1790 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_query_module */ |
1791 | 048f6b4d | bellard | MIPS_SYS(sys_poll , 3)
|
1792 | 048f6b4d | bellard | MIPS_SYS(sys_nfsservctl , 3)
|
1793 | 048f6b4d | bellard | MIPS_SYS(sys_setresgid , 3) /* 4190 */ |
1794 | 048f6b4d | bellard | MIPS_SYS(sys_getresgid , 3)
|
1795 | 048f6b4d | bellard | MIPS_SYS(sys_prctl , 5)
|
1796 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigreturn, 0)
|
1797 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigaction, 4)
|
1798 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigprocmask, 4) /* 4195 */ |
1799 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigpending, 2)
|
1800 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigtimedwait, 4)
|
1801 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigqueueinfo, 3)
|
1802 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigsuspend, 0)
|
1803 | 048f6b4d | bellard | MIPS_SYS(sys_pread64 , 6) /* 4200 */ |
1804 | 048f6b4d | bellard | MIPS_SYS(sys_pwrite64 , 6)
|
1805 | 048f6b4d | bellard | MIPS_SYS(sys_chown , 3)
|
1806 | 048f6b4d | bellard | MIPS_SYS(sys_getcwd , 2)
|
1807 | 048f6b4d | bellard | MIPS_SYS(sys_capget , 2)
|
1808 | 048f6b4d | bellard | MIPS_SYS(sys_capset , 2) /* 4205 */ |
1809 | 048f6b4d | bellard | MIPS_SYS(sys_sigaltstack , 0)
|
1810 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile , 4)
|
1811 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1812 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1813 | 048f6b4d | bellard | MIPS_SYS(sys_mmap2 , 6) /* 4210 */ |
1814 | 048f6b4d | bellard | MIPS_SYS(sys_truncate64 , 4)
|
1815 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate64 , 4)
|
1816 | 048f6b4d | bellard | MIPS_SYS(sys_stat64 , 2)
|
1817 | 048f6b4d | bellard | MIPS_SYS(sys_lstat64 , 2)
|
1818 | 048f6b4d | bellard | MIPS_SYS(sys_fstat64 , 2) /* 4215 */ |
1819 | 048f6b4d | bellard | MIPS_SYS(sys_pivot_root , 2)
|
1820 | 048f6b4d | bellard | MIPS_SYS(sys_mincore , 3)
|
1821 | 048f6b4d | bellard | MIPS_SYS(sys_madvise , 3)
|
1822 | 048f6b4d | bellard | MIPS_SYS(sys_getdents64 , 3)
|
1823 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl64 , 3) /* 4220 */ |
1824 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1825 | 048f6b4d | bellard | MIPS_SYS(sys_gettid , 0)
|
1826 | 048f6b4d | bellard | MIPS_SYS(sys_readahead , 5)
|
1827 | 048f6b4d | bellard | MIPS_SYS(sys_setxattr , 5)
|
1828 | 048f6b4d | bellard | MIPS_SYS(sys_lsetxattr , 5) /* 4225 */ |
1829 | 048f6b4d | bellard | MIPS_SYS(sys_fsetxattr , 5)
|
1830 | 048f6b4d | bellard | MIPS_SYS(sys_getxattr , 4)
|
1831 | 048f6b4d | bellard | MIPS_SYS(sys_lgetxattr , 4)
|
1832 | 048f6b4d | bellard | MIPS_SYS(sys_fgetxattr , 4)
|
1833 | 048f6b4d | bellard | MIPS_SYS(sys_listxattr , 3) /* 4230 */ |
1834 | 048f6b4d | bellard | MIPS_SYS(sys_llistxattr , 3)
|
1835 | 048f6b4d | bellard | MIPS_SYS(sys_flistxattr , 3)
|
1836 | 048f6b4d | bellard | MIPS_SYS(sys_removexattr , 2)
|
1837 | 048f6b4d | bellard | MIPS_SYS(sys_lremovexattr, 2)
|
1838 | 048f6b4d | bellard | MIPS_SYS(sys_fremovexattr, 2) /* 4235 */ |
1839 | 048f6b4d | bellard | MIPS_SYS(sys_tkill , 2)
|
1840 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile64 , 5)
|
1841 | 048f6b4d | bellard | MIPS_SYS(sys_futex , 2)
|
1842 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setaffinity, 3)
|
1843 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getaffinity, 3) /* 4240 */ |
1844 | 048f6b4d | bellard | MIPS_SYS(sys_io_setup , 2)
|
1845 | 048f6b4d | bellard | MIPS_SYS(sys_io_destroy , 1)
|
1846 | 048f6b4d | bellard | MIPS_SYS(sys_io_getevents, 5)
|
1847 | 048f6b4d | bellard | MIPS_SYS(sys_io_submit , 3)
|
1848 | 048f6b4d | bellard | MIPS_SYS(sys_io_cancel , 3) /* 4245 */ |
1849 | 048f6b4d | bellard | MIPS_SYS(sys_exit_group , 1)
|
1850 | 048f6b4d | bellard | MIPS_SYS(sys_lookup_dcookie, 3)
|
1851 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_create, 1)
|
1852 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_ctl , 4)
|
1853 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_wait , 3) /* 4250 */ |
1854 | 048f6b4d | bellard | MIPS_SYS(sys_remap_file_pages, 5)
|
1855 | 048f6b4d | bellard | MIPS_SYS(sys_set_tid_address, 1)
|
1856 | 048f6b4d | bellard | MIPS_SYS(sys_restart_syscall, 0)
|
1857 | 048f6b4d | bellard | MIPS_SYS(sys_fadvise64_64, 7)
|
1858 | 048f6b4d | bellard | MIPS_SYS(sys_statfs64 , 3) /* 4255 */ |
1859 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs64 , 2)
|
1860 | 048f6b4d | bellard | MIPS_SYS(sys_timer_create, 3)
|
1861 | 048f6b4d | bellard | MIPS_SYS(sys_timer_settime, 4)
|
1862 | 048f6b4d | bellard | MIPS_SYS(sys_timer_gettime, 2)
|
1863 | 048f6b4d | bellard | MIPS_SYS(sys_timer_getoverrun, 1) /* 4260 */ |
1864 | 048f6b4d | bellard | MIPS_SYS(sys_timer_delete, 1)
|
1865 | 048f6b4d | bellard | MIPS_SYS(sys_clock_settime, 2)
|
1866 | 048f6b4d | bellard | MIPS_SYS(sys_clock_gettime, 2)
|
1867 | 048f6b4d | bellard | MIPS_SYS(sys_clock_getres, 2)
|
1868 | 048f6b4d | bellard | MIPS_SYS(sys_clock_nanosleep, 4) /* 4265 */ |
1869 | 048f6b4d | bellard | MIPS_SYS(sys_tgkill , 3)
|
1870 | 048f6b4d | bellard | MIPS_SYS(sys_utimes , 2)
|
1871 | 048f6b4d | bellard | MIPS_SYS(sys_mbind , 4)
|
1872 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_get_mempolicy */ |
1873 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4270 sys_set_mempolicy */ |
1874 | 048f6b4d | bellard | MIPS_SYS(sys_mq_open , 4)
|
1875 | 048f6b4d | bellard | MIPS_SYS(sys_mq_unlink , 1)
|
1876 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedsend, 5)
|
1877 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedreceive, 5)
|
1878 | 048f6b4d | bellard | MIPS_SYS(sys_mq_notify , 2) /* 4275 */ |
1879 | 048f6b4d | bellard | MIPS_SYS(sys_mq_getsetattr, 3)
|
1880 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_vserver */ |
1881 | 048f6b4d | bellard | MIPS_SYS(sys_waitid , 4)
|
1882 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* available, was setaltroot */ |
1883 | 048f6b4d | bellard | MIPS_SYS(sys_add_key , 5)
|
1884 | 388bb21a | ths | MIPS_SYS(sys_request_key, 4)
|
1885 | 048f6b4d | bellard | MIPS_SYS(sys_keyctl , 5)
|
1886 | 6f5b89a0 | ths | MIPS_SYS(sys_set_thread_area, 1)
|
1887 | 388bb21a | ths | MIPS_SYS(sys_inotify_init, 0)
|
1888 | 388bb21a | ths | MIPS_SYS(sys_inotify_add_watch, 3) /* 4285 */ |
1889 | 388bb21a | ths | MIPS_SYS(sys_inotify_rm_watch, 2)
|
1890 | 388bb21a | ths | MIPS_SYS(sys_migrate_pages, 4)
|
1891 | 388bb21a | ths | MIPS_SYS(sys_openat, 4)
|
1892 | 388bb21a | ths | MIPS_SYS(sys_mkdirat, 3)
|
1893 | 388bb21a | ths | MIPS_SYS(sys_mknodat, 4) /* 4290 */ |
1894 | 388bb21a | ths | MIPS_SYS(sys_fchownat, 5)
|
1895 | 388bb21a | ths | MIPS_SYS(sys_futimesat, 3)
|
1896 | 388bb21a | ths | MIPS_SYS(sys_fstatat64, 4)
|
1897 | 388bb21a | ths | MIPS_SYS(sys_unlinkat, 3)
|
1898 | 388bb21a | ths | MIPS_SYS(sys_renameat, 4) /* 4295 */ |
1899 | 388bb21a | ths | MIPS_SYS(sys_linkat, 5)
|
1900 | 388bb21a | ths | MIPS_SYS(sys_symlinkat, 3)
|
1901 | 388bb21a | ths | MIPS_SYS(sys_readlinkat, 4)
|
1902 | 388bb21a | ths | MIPS_SYS(sys_fchmodat, 3)
|
1903 | 388bb21a | ths | MIPS_SYS(sys_faccessat, 3) /* 4300 */ |
1904 | 388bb21a | ths | MIPS_SYS(sys_pselect6, 6)
|
1905 | 388bb21a | ths | MIPS_SYS(sys_ppoll, 5)
|
1906 | 388bb21a | ths | MIPS_SYS(sys_unshare, 1)
|
1907 | 388bb21a | ths | MIPS_SYS(sys_splice, 4)
|
1908 | 388bb21a | ths | MIPS_SYS(sys_sync_file_range, 7) /* 4305 */ |
1909 | 388bb21a | ths | MIPS_SYS(sys_tee, 4)
|
1910 | 388bb21a | ths | MIPS_SYS(sys_vmsplice, 4)
|
1911 | 388bb21a | ths | MIPS_SYS(sys_move_pages, 6)
|
1912 | 388bb21a | ths | MIPS_SYS(sys_set_robust_list, 2)
|
1913 | 388bb21a | ths | MIPS_SYS(sys_get_robust_list, 3) /* 4310 */ |
1914 | 388bb21a | ths | MIPS_SYS(sys_kexec_load, 4)
|
1915 | 388bb21a | ths | MIPS_SYS(sys_getcpu, 3)
|
1916 | 388bb21a | ths | MIPS_SYS(sys_epoll_pwait, 6)
|
1917 | 388bb21a | ths | MIPS_SYS(sys_ioprio_set, 3)
|
1918 | 388bb21a | ths | MIPS_SYS(sys_ioprio_get, 2)
|
1919 | 048f6b4d | bellard | }; |
1920 | 048f6b4d | bellard | |
1921 | 048f6b4d | bellard | #undef MIPS_SYS
|
1922 | 048f6b4d | bellard | |
1923 | 590bc601 | Paul Brook | static int do_store_exclusive(CPUMIPSState *env) |
1924 | 590bc601 | Paul Brook | { |
1925 | 590bc601 | Paul Brook | target_ulong addr; |
1926 | 590bc601 | Paul Brook | target_ulong page_addr; |
1927 | 590bc601 | Paul Brook | target_ulong val; |
1928 | 590bc601 | Paul Brook | int flags;
|
1929 | 590bc601 | Paul Brook | int segv = 0; |
1930 | 590bc601 | Paul Brook | int reg;
|
1931 | 590bc601 | Paul Brook | int d;
|
1932 | 590bc601 | Paul Brook | |
1933 | 5499b6ff | Aurelien Jarno | addr = env->lladdr; |
1934 | 590bc601 | Paul Brook | page_addr = addr & TARGET_PAGE_MASK; |
1935 | 590bc601 | Paul Brook | start_exclusive(); |
1936 | 590bc601 | Paul Brook | mmap_lock(); |
1937 | 590bc601 | Paul Brook | flags = page_get_flags(page_addr); |
1938 | 590bc601 | Paul Brook | if ((flags & PAGE_READ) == 0) { |
1939 | 590bc601 | Paul Brook | segv = 1;
|
1940 | 590bc601 | Paul Brook | } else {
|
1941 | 590bc601 | Paul Brook | reg = env->llreg & 0x1f;
|
1942 | 590bc601 | Paul Brook | d = (env->llreg & 0x20) != 0; |
1943 | 590bc601 | Paul Brook | if (d) {
|
1944 | 590bc601 | Paul Brook | segv = get_user_s64(val, addr); |
1945 | 590bc601 | Paul Brook | } else {
|
1946 | 590bc601 | Paul Brook | segv = get_user_s32(val, addr); |
1947 | 590bc601 | Paul Brook | } |
1948 | 590bc601 | Paul Brook | if (!segv) {
|
1949 | 590bc601 | Paul Brook | if (val != env->llval) {
|
1950 | 590bc601 | Paul Brook | env->active_tc.gpr[reg] = 0;
|
1951 | 590bc601 | Paul Brook | } else {
|
1952 | 590bc601 | Paul Brook | if (d) {
|
1953 | 590bc601 | Paul Brook | segv = put_user_u64(env->llnewval, addr); |
1954 | 590bc601 | Paul Brook | } else {
|
1955 | 590bc601 | Paul Brook | segv = put_user_u32(env->llnewval, addr); |
1956 | 590bc601 | Paul Brook | } |
1957 | 590bc601 | Paul Brook | if (!segv) {
|
1958 | 590bc601 | Paul Brook | env->active_tc.gpr[reg] = 1;
|
1959 | 590bc601 | Paul Brook | } |
1960 | 590bc601 | Paul Brook | } |
1961 | 590bc601 | Paul Brook | } |
1962 | 590bc601 | Paul Brook | } |
1963 | 5499b6ff | Aurelien Jarno | env->lladdr = -1;
|
1964 | 590bc601 | Paul Brook | if (!segv) {
|
1965 | 590bc601 | Paul Brook | env->active_tc.PC += 4;
|
1966 | 590bc601 | Paul Brook | } |
1967 | 590bc601 | Paul Brook | mmap_unlock(); |
1968 | 590bc601 | Paul Brook | end_exclusive(); |
1969 | 590bc601 | Paul Brook | return segv;
|
1970 | 590bc601 | Paul Brook | } |
1971 | 590bc601 | Paul Brook | |
1972 | 048f6b4d | bellard | void cpu_loop(CPUMIPSState *env)
|
1973 | 048f6b4d | bellard | { |
1974 | c227f099 | Anthony Liguori | target_siginfo_t info; |
1975 | 388bb21a | ths | int trapnr, ret;
|
1976 | 048f6b4d | bellard | unsigned int syscall_num; |
1977 | 048f6b4d | bellard | |
1978 | 048f6b4d | bellard | for(;;) {
|
1979 | 590bc601 | Paul Brook | cpu_exec_start(env); |
1980 | 048f6b4d | bellard | trapnr = cpu_mips_exec(env); |
1981 | 590bc601 | Paul Brook | cpu_exec_end(env); |
1982 | 048f6b4d | bellard | switch(trapnr) {
|
1983 | 048f6b4d | bellard | case EXCP_SYSCALL:
|
1984 | b5dc7732 | ths | syscall_num = env->active_tc.gpr[2] - 4000; |
1985 | b5dc7732 | ths | env->active_tc.PC += 4;
|
1986 | 388bb21a | ths | if (syscall_num >= sizeof(mips_syscall_args)) { |
1987 | 388bb21a | ths | ret = -ENOSYS; |
1988 | 388bb21a | ths | } else {
|
1989 | 388bb21a | ths | int nb_args;
|
1990 | 992f48a0 | blueswir1 | abi_ulong sp_reg; |
1991 | 992f48a0 | blueswir1 | abi_ulong arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0; |
1992 | 388bb21a | ths | |
1993 | 388bb21a | ths | nb_args = mips_syscall_args[syscall_num]; |
1994 | b5dc7732 | ths | sp_reg = env->active_tc.gpr[29];
|
1995 | 388bb21a | ths | switch (nb_args) {
|
1996 | 388bb21a | ths | /* these arguments are taken from the stack */
|
1997 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
1998 | 2f619698 | bellard | case 8: get_user_ual(arg8, sp_reg + 28); |
1999 | 2f619698 | bellard | case 7: get_user_ual(arg7, sp_reg + 24); |
2000 | 2f619698 | bellard | case 6: get_user_ual(arg6, sp_reg + 20); |
2001 | 2f619698 | bellard | case 5: get_user_ual(arg5, sp_reg + 16); |
2002 | 388bb21a | ths | default:
|
2003 | 388bb21a | ths | break;
|
2004 | 048f6b4d | bellard | } |
2005 | b5dc7732 | ths | ret = do_syscall(env, env->active_tc.gpr[2],
|
2006 | b5dc7732 | ths | env->active_tc.gpr[4],
|
2007 | b5dc7732 | ths | env->active_tc.gpr[5],
|
2008 | b5dc7732 | ths | env->active_tc.gpr[6],
|
2009 | b5dc7732 | ths | env->active_tc.gpr[7],
|
2010 | 388bb21a | ths | arg5, arg6/*, arg7, arg8*/);
|
2011 | 388bb21a | ths | } |
2012 | 0b1bcb00 | pbrook | if (ret == -TARGET_QEMU_ESIGRETURN) {
|
2013 | 0b1bcb00 | pbrook | /* Returning from a successful sigreturn syscall.
|
2014 | 0b1bcb00 | pbrook | Avoid clobbering register state. */
|
2015 | 0b1bcb00 | pbrook | break;
|
2016 | 0b1bcb00 | pbrook | } |
2017 | 388bb21a | ths | if ((unsigned int)ret >= (unsigned int)(-1133)) { |
2018 | b5dc7732 | ths | env->active_tc.gpr[7] = 1; /* error flag */ |
2019 | 388bb21a | ths | ret = -ret; |
2020 | 388bb21a | ths | } else {
|
2021 | b5dc7732 | ths | env->active_tc.gpr[7] = 0; /* error flag */ |
2022 | 048f6b4d | bellard | } |
2023 | b5dc7732 | ths | env->active_tc.gpr[2] = ret;
|
2024 | 048f6b4d | bellard | break;
|
2025 | ca7c2b1b | ths | case EXCP_TLBL:
|
2026 | ca7c2b1b | ths | case EXCP_TLBS:
|
2027 | e4474235 | pbrook | info.si_signo = TARGET_SIGSEGV; |
2028 | e4474235 | pbrook | info.si_errno = 0;
|
2029 | e4474235 | pbrook | /* XXX: check env->error_code */
|
2030 | e4474235 | pbrook | info.si_code = TARGET_SEGV_MAPERR; |
2031 | e4474235 | pbrook | info._sifields._sigfault._addr = env->CP0_BadVAddr; |
2032 | e4474235 | pbrook | queue_signal(env, info.si_signo, &info); |
2033 | e4474235 | pbrook | break;
|
2034 | 6900e84b | bellard | case EXCP_CpU:
|
2035 | 048f6b4d | bellard | case EXCP_RI:
|
2036 | bc1ad2de | bellard | info.si_signo = TARGET_SIGILL; |
2037 | bc1ad2de | bellard | info.si_errno = 0;
|
2038 | bc1ad2de | bellard | info.si_code = 0;
|
2039 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2040 | 048f6b4d | bellard | break;
|
2041 | 106ec879 | bellard | case EXCP_INTERRUPT:
|
2042 | 106ec879 | bellard | /* just indicate that signals should be handled asap */
|
2043 | 106ec879 | bellard | break;
|
2044 | d08b2a28 | pbrook | case EXCP_DEBUG:
|
2045 | d08b2a28 | pbrook | { |
2046 | d08b2a28 | pbrook | int sig;
|
2047 | d08b2a28 | pbrook | |
2048 | d08b2a28 | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2049 | d08b2a28 | pbrook | if (sig)
|
2050 | d08b2a28 | pbrook | { |
2051 | d08b2a28 | pbrook | info.si_signo = sig; |
2052 | d08b2a28 | pbrook | info.si_errno = 0;
|
2053 | d08b2a28 | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
2054 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2055 | d08b2a28 | pbrook | } |
2056 | d08b2a28 | pbrook | } |
2057 | d08b2a28 | pbrook | break;
|
2058 | 590bc601 | Paul Brook | case EXCP_SC:
|
2059 | 590bc601 | Paul Brook | if (do_store_exclusive(env)) {
|
2060 | 590bc601 | Paul Brook | info.si_signo = TARGET_SIGSEGV; |
2061 | 590bc601 | Paul Brook | info.si_errno = 0;
|
2062 | 590bc601 | Paul Brook | info.si_code = TARGET_SEGV_MAPERR; |
2063 | 590bc601 | Paul Brook | info._sifields._sigfault._addr = env->active_tc.PC; |
2064 | 590bc601 | Paul Brook | queue_signal(env, info.si_signo, &info); |
2065 | 590bc601 | Paul Brook | } |
2066 | 590bc601 | Paul Brook | break;
|
2067 | 048f6b4d | bellard | default:
|
2068 | 048f6b4d | bellard | // error:
|
2069 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
2070 | 048f6b4d | bellard | trapnr); |
2071 | 048f6b4d | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
2072 | 048f6b4d | bellard | abort(); |
2073 | 048f6b4d | bellard | } |
2074 | 048f6b4d | bellard | process_pending_signals(env); |
2075 | 048f6b4d | bellard | } |
2076 | 048f6b4d | bellard | } |
2077 | 048f6b4d | bellard | #endif
|
2078 | 048f6b4d | bellard | |
2079 | fdf9b3e8 | bellard | #ifdef TARGET_SH4
|
2080 | fdf9b3e8 | bellard | void cpu_loop (CPUState *env)
|
2081 | fdf9b3e8 | bellard | { |
2082 | fdf9b3e8 | bellard | int trapnr, ret;
|
2083 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2084 | 3b46e624 | ths | |
2085 | fdf9b3e8 | bellard | while (1) { |
2086 | fdf9b3e8 | bellard | trapnr = cpu_sh4_exec (env); |
2087 | 3b46e624 | ths | |
2088 | fdf9b3e8 | bellard | switch (trapnr) {
|
2089 | fdf9b3e8 | bellard | case 0x160: |
2090 | 0b6d3ae0 | aurel32 | env->pc += 2;
|
2091 | 5fafdf24 | ths | ret = do_syscall(env, |
2092 | 5fafdf24 | ths | env->gregs[3],
|
2093 | 5fafdf24 | ths | env->gregs[4],
|
2094 | 5fafdf24 | ths | env->gregs[5],
|
2095 | 5fafdf24 | ths | env->gregs[6],
|
2096 | 5fafdf24 | ths | env->gregs[7],
|
2097 | 5fafdf24 | ths | env->gregs[0],
|
2098 | fca743f3 | ths | env->gregs[1]);
|
2099 | 9c2a9ea1 | pbrook | env->gregs[0] = ret;
|
2100 | fdf9b3e8 | bellard | break;
|
2101 | c3b5bc8a | ths | case EXCP_INTERRUPT:
|
2102 | c3b5bc8a | ths | /* just indicate that signals should be handled asap */
|
2103 | c3b5bc8a | ths | break;
|
2104 | 355fb23d | pbrook | case EXCP_DEBUG:
|
2105 | 355fb23d | pbrook | { |
2106 | 355fb23d | pbrook | int sig;
|
2107 | 355fb23d | pbrook | |
2108 | 355fb23d | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2109 | 355fb23d | pbrook | if (sig)
|
2110 | 355fb23d | pbrook | { |
2111 | 355fb23d | pbrook | info.si_signo = sig; |
2112 | 355fb23d | pbrook | info.si_errno = 0;
|
2113 | 355fb23d | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
2114 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2115 | 355fb23d | pbrook | } |
2116 | 355fb23d | pbrook | } |
2117 | 355fb23d | pbrook | break;
|
2118 | c3b5bc8a | ths | case 0xa0: |
2119 | c3b5bc8a | ths | case 0xc0: |
2120 | c3b5bc8a | ths | info.si_signo = SIGSEGV; |
2121 | c3b5bc8a | ths | info.si_errno = 0;
|
2122 | c3b5bc8a | ths | info.si_code = TARGET_SEGV_MAPERR; |
2123 | c3b5bc8a | ths | info._sifields._sigfault._addr = env->tea; |
2124 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2125 | c3b5bc8a | ths | break;
|
2126 | c3b5bc8a | ths | |
2127 | fdf9b3e8 | bellard | default:
|
2128 | fdf9b3e8 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2129 | fdf9b3e8 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
2130 | fdf9b3e8 | bellard | exit (1);
|
2131 | fdf9b3e8 | bellard | } |
2132 | fdf9b3e8 | bellard | process_pending_signals (env); |
2133 | fdf9b3e8 | bellard | } |
2134 | fdf9b3e8 | bellard | } |
2135 | fdf9b3e8 | bellard | #endif
|
2136 | fdf9b3e8 | bellard | |
2137 | 48733d19 | ths | #ifdef TARGET_CRIS
|
2138 | 48733d19 | ths | void cpu_loop (CPUState *env)
|
2139 | 48733d19 | ths | { |
2140 | 48733d19 | ths | int trapnr, ret;
|
2141 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2142 | 48733d19 | ths | |
2143 | 48733d19 | ths | while (1) { |
2144 | 48733d19 | ths | trapnr = cpu_cris_exec (env); |
2145 | 48733d19 | ths | switch (trapnr) {
|
2146 | 48733d19 | ths | case 0xaa: |
2147 | 48733d19 | ths | { |
2148 | 48733d19 | ths | info.si_signo = SIGSEGV; |
2149 | 48733d19 | ths | info.si_errno = 0;
|
2150 | 48733d19 | ths | /* XXX: check env->error_code */
|
2151 | 48733d19 | ths | info.si_code = TARGET_SEGV_MAPERR; |
2152 | e00c1e71 | edgar_igl | info._sifields._sigfault._addr = env->pregs[PR_EDA]; |
2153 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2154 | 48733d19 | ths | } |
2155 | 48733d19 | ths | break;
|
2156 | b6d3abda | edgar_igl | case EXCP_INTERRUPT:
|
2157 | b6d3abda | edgar_igl | /* just indicate that signals should be handled asap */
|
2158 | b6d3abda | edgar_igl | break;
|
2159 | 48733d19 | ths | case EXCP_BREAK:
|
2160 | 48733d19 | ths | ret = do_syscall(env, |
2161 | 48733d19 | ths | env->regs[9],
|
2162 | 48733d19 | ths | env->regs[10],
|
2163 | 48733d19 | ths | env->regs[11],
|
2164 | 48733d19 | ths | env->regs[12],
|
2165 | 48733d19 | ths | env->regs[13],
|
2166 | 48733d19 | ths | env->pregs[7],
|
2167 | 48733d19 | ths | env->pregs[11]);
|
2168 | 48733d19 | ths | env->regs[10] = ret;
|
2169 | 48733d19 | ths | break;
|
2170 | 48733d19 | ths | case EXCP_DEBUG:
|
2171 | 48733d19 | ths | { |
2172 | 48733d19 | ths | int sig;
|
2173 | 48733d19 | ths | |
2174 | 48733d19 | ths | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2175 | 48733d19 | ths | if (sig)
|
2176 | 48733d19 | ths | { |
2177 | 48733d19 | ths | info.si_signo = sig; |
2178 | 48733d19 | ths | info.si_errno = 0;
|
2179 | 48733d19 | ths | info.si_code = TARGET_TRAP_BRKPT; |
2180 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2181 | 48733d19 | ths | } |
2182 | 48733d19 | ths | } |
2183 | 48733d19 | ths | break;
|
2184 | 48733d19 | ths | default:
|
2185 | 48733d19 | ths | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2186 | 48733d19 | ths | cpu_dump_state(env, stderr, fprintf, 0);
|
2187 | 48733d19 | ths | exit (1);
|
2188 | 48733d19 | ths | } |
2189 | 48733d19 | ths | process_pending_signals (env); |
2190 | 48733d19 | ths | } |
2191 | 48733d19 | ths | } |
2192 | 48733d19 | ths | #endif
|
2193 | 48733d19 | ths | |
2194 | b779e29e | Edgar E. Iglesias | #ifdef TARGET_MICROBLAZE
|
2195 | b779e29e | Edgar E. Iglesias | void cpu_loop (CPUState *env)
|
2196 | b779e29e | Edgar E. Iglesias | { |
2197 | b779e29e | Edgar E. Iglesias | int trapnr, ret;
|
2198 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2199 | b779e29e | Edgar E. Iglesias | |
2200 | b779e29e | Edgar E. Iglesias | while (1) { |
2201 | b779e29e | Edgar E. Iglesias | trapnr = cpu_mb_exec (env); |
2202 | b779e29e | Edgar E. Iglesias | switch (trapnr) {
|
2203 | b779e29e | Edgar E. Iglesias | case 0xaa: |
2204 | b779e29e | Edgar E. Iglesias | { |
2205 | b779e29e | Edgar E. Iglesias | info.si_signo = SIGSEGV; |
2206 | b779e29e | Edgar E. Iglesias | info.si_errno = 0;
|
2207 | b779e29e | Edgar E. Iglesias | /* XXX: check env->error_code */
|
2208 | b779e29e | Edgar E. Iglesias | info.si_code = TARGET_SEGV_MAPERR; |
2209 | b779e29e | Edgar E. Iglesias | info._sifields._sigfault._addr = 0;
|
2210 | b779e29e | Edgar E. Iglesias | queue_signal(env, info.si_signo, &info); |
2211 | b779e29e | Edgar E. Iglesias | } |
2212 | b779e29e | Edgar E. Iglesias | break;
|
2213 | b779e29e | Edgar E. Iglesias | case EXCP_INTERRUPT:
|
2214 | b779e29e | Edgar E. Iglesias | /* just indicate that signals should be handled asap */
|
2215 | b779e29e | Edgar E. Iglesias | break;
|
2216 | b779e29e | Edgar E. Iglesias | case EXCP_BREAK:
|
2217 | b779e29e | Edgar E. Iglesias | /* Return address is 4 bytes after the call. */
|
2218 | b779e29e | Edgar E. Iglesias | env->regs[14] += 4; |
2219 | b779e29e | Edgar E. Iglesias | ret = do_syscall(env, |
2220 | b779e29e | Edgar E. Iglesias | env->regs[12],
|
2221 | b779e29e | Edgar E. Iglesias | env->regs[5],
|
2222 | b779e29e | Edgar E. Iglesias | env->regs[6],
|
2223 | b779e29e | Edgar E. Iglesias | env->regs[7],
|
2224 | b779e29e | Edgar E. Iglesias | env->regs[8],
|
2225 | b779e29e | Edgar E. Iglesias | env->regs[9],
|
2226 | b779e29e | Edgar E. Iglesias | env->regs[10]);
|
2227 | b779e29e | Edgar E. Iglesias | env->regs[3] = ret;
|
2228 | b779e29e | Edgar E. Iglesias | env->sregs[SR_PC] = env->regs[14];
|
2229 | b779e29e | Edgar E. Iglesias | break;
|
2230 | b779e29e | Edgar E. Iglesias | case EXCP_DEBUG:
|
2231 | b779e29e | Edgar E. Iglesias | { |
2232 | b779e29e | Edgar E. Iglesias | int sig;
|
2233 | b779e29e | Edgar E. Iglesias | |
2234 | b779e29e | Edgar E. Iglesias | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2235 | b779e29e | Edgar E. Iglesias | if (sig)
|
2236 | b779e29e | Edgar E. Iglesias | { |
2237 | b779e29e | Edgar E. Iglesias | info.si_signo = sig; |
2238 | b779e29e | Edgar E. Iglesias | info.si_errno = 0;
|
2239 | b779e29e | Edgar E. Iglesias | info.si_code = TARGET_TRAP_BRKPT; |
2240 | b779e29e | Edgar E. Iglesias | queue_signal(env, info.si_signo, &info); |
2241 | b779e29e | Edgar E. Iglesias | } |
2242 | b779e29e | Edgar E. Iglesias | } |
2243 | b779e29e | Edgar E. Iglesias | break;
|
2244 | b779e29e | Edgar E. Iglesias | default:
|
2245 | b779e29e | Edgar E. Iglesias | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2246 | b779e29e | Edgar E. Iglesias | cpu_dump_state(env, stderr, fprintf, 0);
|
2247 | b779e29e | Edgar E. Iglesias | exit (1);
|
2248 | b779e29e | Edgar E. Iglesias | } |
2249 | b779e29e | Edgar E. Iglesias | process_pending_signals (env); |
2250 | b779e29e | Edgar E. Iglesias | } |
2251 | b779e29e | Edgar E. Iglesias | } |
2252 | b779e29e | Edgar E. Iglesias | #endif
|
2253 | b779e29e | Edgar E. Iglesias | |
2254 | e6e5906b | pbrook | #ifdef TARGET_M68K
|
2255 | e6e5906b | pbrook | |
2256 | e6e5906b | pbrook | void cpu_loop(CPUM68KState *env)
|
2257 | e6e5906b | pbrook | { |
2258 | e6e5906b | pbrook | int trapnr;
|
2259 | e6e5906b | pbrook | unsigned int n; |
2260 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2261 | e6e5906b | pbrook | TaskState *ts = env->opaque; |
2262 | 3b46e624 | ths | |
2263 | e6e5906b | pbrook | for(;;) {
|
2264 | e6e5906b | pbrook | trapnr = cpu_m68k_exec(env); |
2265 | e6e5906b | pbrook | switch(trapnr) {
|
2266 | e6e5906b | pbrook | case EXCP_ILLEGAL:
|
2267 | e6e5906b | pbrook | { |
2268 | e6e5906b | pbrook | if (ts->sim_syscalls) {
|
2269 | e6e5906b | pbrook | uint16_t nr; |
2270 | e6e5906b | pbrook | nr = lduw(env->pc + 2);
|
2271 | e6e5906b | pbrook | env->pc += 4;
|
2272 | e6e5906b | pbrook | do_m68k_simcall(env, nr); |
2273 | e6e5906b | pbrook | } else {
|
2274 | e6e5906b | pbrook | goto do_sigill;
|
2275 | e6e5906b | pbrook | } |
2276 | e6e5906b | pbrook | } |
2277 | e6e5906b | pbrook | break;
|
2278 | a87295e8 | pbrook | case EXCP_HALT_INSN:
|
2279 | e6e5906b | pbrook | /* Semihosing syscall. */
|
2280 | a87295e8 | pbrook | env->pc += 4;
|
2281 | e6e5906b | pbrook | do_m68k_semihosting(env, env->dregs[0]);
|
2282 | e6e5906b | pbrook | break;
|
2283 | e6e5906b | pbrook | case EXCP_LINEA:
|
2284 | e6e5906b | pbrook | case EXCP_LINEF:
|
2285 | e6e5906b | pbrook | case EXCP_UNSUPPORTED:
|
2286 | e6e5906b | pbrook | do_sigill:
|
2287 | e6e5906b | pbrook | info.si_signo = SIGILL; |
2288 | e6e5906b | pbrook | info.si_errno = 0;
|
2289 | e6e5906b | pbrook | info.si_code = TARGET_ILL_ILLOPN; |
2290 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->pc; |
2291 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2292 | e6e5906b | pbrook | break;
|
2293 | e6e5906b | pbrook | case EXCP_TRAP0:
|
2294 | e6e5906b | pbrook | { |
2295 | e6e5906b | pbrook | ts->sim_syscalls = 0;
|
2296 | e6e5906b | pbrook | n = env->dregs[0];
|
2297 | e6e5906b | pbrook | env->pc += 2;
|
2298 | 5fafdf24 | ths | env->dregs[0] = do_syscall(env,
|
2299 | 5fafdf24 | ths | n, |
2300 | e6e5906b | pbrook | env->dregs[1],
|
2301 | e6e5906b | pbrook | env->dregs[2],
|
2302 | e6e5906b | pbrook | env->dregs[3],
|
2303 | e6e5906b | pbrook | env->dregs[4],
|
2304 | e6e5906b | pbrook | env->dregs[5],
|
2305 | bb7ec043 | pbrook | env->aregs[0]);
|
2306 | e6e5906b | pbrook | } |
2307 | e6e5906b | pbrook | break;
|
2308 | e6e5906b | pbrook | case EXCP_INTERRUPT:
|
2309 | e6e5906b | pbrook | /* just indicate that signals should be handled asap */
|
2310 | e6e5906b | pbrook | break;
|
2311 | e6e5906b | pbrook | case EXCP_ACCESS:
|
2312 | e6e5906b | pbrook | { |
2313 | e6e5906b | pbrook | info.si_signo = SIGSEGV; |
2314 | e6e5906b | pbrook | info.si_errno = 0;
|
2315 | e6e5906b | pbrook | /* XXX: check env->error_code */
|
2316 | e6e5906b | pbrook | info.si_code = TARGET_SEGV_MAPERR; |
2317 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->mmu.ar; |
2318 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2319 | e6e5906b | pbrook | } |
2320 | e6e5906b | pbrook | break;
|
2321 | e6e5906b | pbrook | case EXCP_DEBUG:
|
2322 | e6e5906b | pbrook | { |
2323 | e6e5906b | pbrook | int sig;
|
2324 | e6e5906b | pbrook | |
2325 | e6e5906b | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2326 | e6e5906b | pbrook | if (sig)
|
2327 | e6e5906b | pbrook | { |
2328 | e6e5906b | pbrook | info.si_signo = sig; |
2329 | e6e5906b | pbrook | info.si_errno = 0;
|
2330 | e6e5906b | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
2331 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2332 | e6e5906b | pbrook | } |
2333 | e6e5906b | pbrook | } |
2334 | e6e5906b | pbrook | break;
|
2335 | e6e5906b | pbrook | default:
|
2336 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
2337 | e6e5906b | pbrook | trapnr); |
2338 | e6e5906b | pbrook | cpu_dump_state(env, stderr, fprintf, 0);
|
2339 | e6e5906b | pbrook | abort(); |
2340 | e6e5906b | pbrook | } |
2341 | e6e5906b | pbrook | process_pending_signals(env); |
2342 | e6e5906b | pbrook | } |
2343 | e6e5906b | pbrook | } |
2344 | e6e5906b | pbrook | #endif /* TARGET_M68K */ |
2345 | e6e5906b | pbrook | |
2346 | 7a3148a9 | j_mayer | #ifdef TARGET_ALPHA
|
2347 | 7a3148a9 | j_mayer | void cpu_loop (CPUState *env)
|
2348 | 7a3148a9 | j_mayer | { |
2349 | e96efcfc | j_mayer | int trapnr;
|
2350 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2351 | 3b46e624 | ths | |
2352 | 7a3148a9 | j_mayer | while (1) { |
2353 | 7a3148a9 | j_mayer | trapnr = cpu_alpha_exec (env); |
2354 | 3b46e624 | ths | |
2355 | 7a3148a9 | j_mayer | switch (trapnr) {
|
2356 | 7a3148a9 | j_mayer | case EXCP_RESET:
|
2357 | 7a3148a9 | j_mayer | fprintf(stderr, "Reset requested. Exit\n");
|
2358 | 7a3148a9 | j_mayer | exit(1);
|
2359 | 7a3148a9 | j_mayer | break;
|
2360 | 7a3148a9 | j_mayer | case EXCP_MCHK:
|
2361 | 7a3148a9 | j_mayer | fprintf(stderr, "Machine check exception. Exit\n");
|
2362 | 7a3148a9 | j_mayer | exit(1);
|
2363 | 7a3148a9 | j_mayer | break;
|
2364 | 7a3148a9 | j_mayer | case EXCP_ARITH:
|
2365 | 7a3148a9 | j_mayer | fprintf(stderr, "Arithmetic trap.\n");
|
2366 | 7a3148a9 | j_mayer | exit(1);
|
2367 | 7a3148a9 | j_mayer | break;
|
2368 | 7a3148a9 | j_mayer | case EXCP_HW_INTERRUPT:
|
2369 | 5fafdf24 | ths | fprintf(stderr, "External interrupt. Exit\n");
|
2370 | 7a3148a9 | j_mayer | exit(1);
|
2371 | 7a3148a9 | j_mayer | break;
|
2372 | 7a3148a9 | j_mayer | case EXCP_DFAULT:
|
2373 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data fault\n");
|
2374 | 7a3148a9 | j_mayer | exit(1);
|
2375 | 7a3148a9 | j_mayer | break;
|
2376 | 7a3148a9 | j_mayer | case EXCP_DTB_MISS_PAL:
|
2377 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data TLB miss in PALcode\n");
|
2378 | 7a3148a9 | j_mayer | exit(1);
|
2379 | 7a3148a9 | j_mayer | break;
|
2380 | 7a3148a9 | j_mayer | case EXCP_ITB_MISS:
|
2381 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU instruction TLB miss\n");
|
2382 | 7a3148a9 | j_mayer | exit(1);
|
2383 | 7a3148a9 | j_mayer | break;
|
2384 | 7a3148a9 | j_mayer | case EXCP_ITB_ACV:
|
2385 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU instruction access violation\n");
|
2386 | 7a3148a9 | j_mayer | exit(1);
|
2387 | 7a3148a9 | j_mayer | break;
|
2388 | 7a3148a9 | j_mayer | case EXCP_DTB_MISS_NATIVE:
|
2389 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data TLB miss\n");
|
2390 | 7a3148a9 | j_mayer | exit(1);
|
2391 | 7a3148a9 | j_mayer | break;
|
2392 | 7a3148a9 | j_mayer | case EXCP_UNALIGN:
|
2393 | 7a3148a9 | j_mayer | fprintf(stderr, "Unaligned access\n");
|
2394 | 7a3148a9 | j_mayer | exit(1);
|
2395 | 7a3148a9 | j_mayer | break;
|
2396 | 7a3148a9 | j_mayer | case EXCP_OPCDEC:
|
2397 | 7a3148a9 | j_mayer | fprintf(stderr, "Invalid instruction\n");
|
2398 | 7a3148a9 | j_mayer | exit(1);
|
2399 | 7a3148a9 | j_mayer | break;
|
2400 | 7a3148a9 | j_mayer | case EXCP_FEN:
|
2401 | 7a3148a9 | j_mayer | fprintf(stderr, "Floating-point not allowed\n");
|
2402 | 7a3148a9 | j_mayer | exit(1);
|
2403 | 7a3148a9 | j_mayer | break;
|
2404 | 7a3148a9 | j_mayer | case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1): |
2405 | 7a3148a9 | j_mayer | call_pal(env, (trapnr >> 6) | 0x80); |
2406 | 7a3148a9 | j_mayer | break;
|
2407 | 7a3148a9 | j_mayer | case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1): |
2408 | 7f75ffd3 | blueswir1 | fprintf(stderr, "Privileged call to PALcode\n");
|
2409 | 7a3148a9 | j_mayer | exit(1);
|
2410 | 7a3148a9 | j_mayer | break;
|
2411 | 7a3148a9 | j_mayer | case EXCP_DEBUG:
|
2412 | 7a3148a9 | j_mayer | { |
2413 | 7a3148a9 | j_mayer | int sig;
|
2414 | 7a3148a9 | j_mayer | |
2415 | 7a3148a9 | j_mayer | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2416 | 7a3148a9 | j_mayer | if (sig)
|
2417 | 7a3148a9 | j_mayer | { |
2418 | 7a3148a9 | j_mayer | info.si_signo = sig; |
2419 | 7a3148a9 | j_mayer | info.si_errno = 0;
|
2420 | 7a3148a9 | j_mayer | info.si_code = TARGET_TRAP_BRKPT; |
2421 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2422 | 7a3148a9 | j_mayer | } |
2423 | 7a3148a9 | j_mayer | } |
2424 | 7a3148a9 | j_mayer | break;
|
2425 | 7a3148a9 | j_mayer | default:
|
2426 | 7a3148a9 | j_mayer | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2427 | 7a3148a9 | j_mayer | cpu_dump_state(env, stderr, fprintf, 0);
|
2428 | 7a3148a9 | j_mayer | exit (1);
|
2429 | 7a3148a9 | j_mayer | } |
2430 | 7a3148a9 | j_mayer | process_pending_signals (env); |
2431 | 7a3148a9 | j_mayer | } |
2432 | 7a3148a9 | j_mayer | } |
2433 | 7a3148a9 | j_mayer | #endif /* TARGET_ALPHA */ |
2434 | 7a3148a9 | j_mayer | |
2435 | 8fcd3692 | blueswir1 | static void usage(void) |
2436 | 31e31b8a | bellard | { |
2437 | 4a19f1ec | pbrook | printf("qemu-" TARGET_ARCH " version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" |
2438 | 68d0f70e | bellard | "usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n" |
2439 | b346ff46 | bellard | "Linux CPU emulator (compiled for %s emulation)\n"
|
2440 | d691f669 | bellard | "\n"
|
2441 | 68d0f70e | bellard | "Standard options:\n"
|
2442 | b12b6a18 | ths | "-h print this help\n"
|
2443 | b12b6a18 | ths | "-g port wait gdb connection to port\n"
|
2444 | b12b6a18 | ths | "-L path set the elf interpreter prefix (default=%s)\n"
|
2445 | b12b6a18 | ths | "-s size set the stack size in bytes (default=%ld)\n"
|
2446 | b12b6a18 | ths | "-cpu model select CPU (-cpu ? for list)\n"
|
2447 | b12b6a18 | ths | "-drop-ld-preload drop LD_PRELOAD for target process\n"
|
2448 | 04a6dfeb | aurel32 | "-E var=value sets/modifies targets environment variable(s)\n"
|
2449 | 04a6dfeb | aurel32 | "-U var unsets targets environment variable(s)\n"
|
2450 | 7d8cec95 | aurel32 | "-0 argv0 forces target process argv[0] to be argv0\n"
|
2451 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2452 | 379f6698 | Paul Brook | "-B address set guest_base address to address\n"
|
2453 | 379f6698 | Paul Brook | #endif
|
2454 | 54936004 | bellard | "\n"
|
2455 | 68d0f70e | bellard | "Debug options:\n"
|
2456 | 6f1f31c0 | bellard | "-d options activate log (logfile=%s)\n"
|
2457 | b6741956 | bellard | "-p pagesize set the host page size to 'pagesize'\n"
|
2458 | 1b530a6d | aurel32 | "-singlestep always run in singlestep mode\n"
|
2459 | b01bcae6 | balrog | "-strace log system calls\n"
|
2460 | b01bcae6 | balrog | "\n"
|
2461 | 68d0f70e | bellard | "Environment variables:\n"
|
2462 | b01bcae6 | balrog | "QEMU_STRACE Print system calls and arguments similar to the\n"
|
2463 | b01bcae6 | balrog | " 'strace' program. Enable by setting to any value.\n"
|
2464 | 04a6dfeb | aurel32 | "You can use -E and -U options to set/unset environment variables\n"
|
2465 | 04a6dfeb | aurel32 | "for target process. It is possible to provide several variables\n"
|
2466 | 04a6dfeb | aurel32 | "by repeating the option. For example:\n"
|
2467 | 04a6dfeb | aurel32 | " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n"
|
2468 | 04a6dfeb | aurel32 | "Note that if you provide several changes to single variable\n"
|
2469 | 04a6dfeb | aurel32 | "last change will stay in effect.\n"
|
2470 | b01bcae6 | balrog | , |
2471 | b346ff46 | bellard | TARGET_ARCH, |
2472 | 5fafdf24 | ths | interp_prefix, |
2473 | 54936004 | bellard | x86_stack_size, |
2474 | 54936004 | bellard | DEBUG_LOGFILE); |
2475 | 2d18e637 | blueswir1 | exit(1);
|
2476 | 31e31b8a | bellard | } |
2477 | 31e31b8a | bellard | |
2478 | d5975363 | pbrook | THREAD CPUState *thread_env; |
2479 | 59faf6d6 | bellard | |
2480 | edf8e2af | Mika Westerberg | void task_settid(TaskState *ts)
|
2481 | edf8e2af | Mika Westerberg | { |
2482 | edf8e2af | Mika Westerberg | if (ts->ts_tid == 0) { |
2483 | 2f7bb878 | Juan Quintela | #ifdef CONFIG_USE_NPTL
|
2484 | edf8e2af | Mika Westerberg | ts->ts_tid = (pid_t)syscall(SYS_gettid); |
2485 | edf8e2af | Mika Westerberg | #else
|
2486 | edf8e2af | Mika Westerberg | /* when no threads are used, tid becomes pid */
|
2487 | edf8e2af | Mika Westerberg | ts->ts_tid = getpid(); |
2488 | edf8e2af | Mika Westerberg | #endif
|
2489 | edf8e2af | Mika Westerberg | } |
2490 | edf8e2af | Mika Westerberg | } |
2491 | edf8e2af | Mika Westerberg | |
2492 | edf8e2af | Mika Westerberg | void stop_all_tasks(void) |
2493 | edf8e2af | Mika Westerberg | { |
2494 | edf8e2af | Mika Westerberg | /*
|
2495 | edf8e2af | Mika Westerberg | * We trust that when using NPTL, start_exclusive()
|
2496 | edf8e2af | Mika Westerberg | * handles thread stopping correctly.
|
2497 | edf8e2af | Mika Westerberg | */
|
2498 | edf8e2af | Mika Westerberg | start_exclusive(); |
2499 | edf8e2af | Mika Westerberg | } |
2500 | edf8e2af | Mika Westerberg | |
2501 | c3a92833 | pbrook | /* Assumes contents are already zeroed. */
|
2502 | 624f7979 | pbrook | void init_task_state(TaskState *ts)
|
2503 | 624f7979 | pbrook | { |
2504 | 624f7979 | pbrook | int i;
|
2505 | 624f7979 | pbrook | |
2506 | 624f7979 | pbrook | ts->used = 1;
|
2507 | 624f7979 | pbrook | ts->first_free = ts->sigqueue_table; |
2508 | 624f7979 | pbrook | for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) { |
2509 | 624f7979 | pbrook | ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1];
|
2510 | 624f7979 | pbrook | } |
2511 | 624f7979 | pbrook | ts->sigqueue_table[i].next = NULL;
|
2512 | 624f7979 | pbrook | } |
2513 | 624f7979 | pbrook | |
2514 | 902b3d5c | malc | int main(int argc, char **argv, char **envp) |
2515 | 31e31b8a | bellard | { |
2516 | 31e31b8a | bellard | const char *filename; |
2517 | b1f9be31 | j_mayer | const char *cpu_model; |
2518 | 01ffc75b | bellard | struct target_pt_regs regs1, *regs = ®s1;
|
2519 | 31e31b8a | bellard | struct image_info info1, *info = &info1;
|
2520 | edf8e2af | Mika Westerberg | struct linux_binprm bprm;
|
2521 | 851e67a1 | bellard | TaskState ts1, *ts = &ts1; |
2522 | b346ff46 | bellard | CPUState *env; |
2523 | 586314f2 | bellard | int optind;
|
2524 | d691f669 | bellard | const char *r; |
2525 | 74c33bed | bellard | int gdbstub_port = 0; |
2526 | 04a6dfeb | aurel32 | char **target_environ, **wrk;
|
2527 | 7d8cec95 | aurel32 | char **target_argv;
|
2528 | 7d8cec95 | aurel32 | int target_argc;
|
2529 | 04a6dfeb | aurel32 | envlist_t *envlist = NULL;
|
2530 | 7d8cec95 | aurel32 | const char *argv0 = NULL; |
2531 | 7d8cec95 | aurel32 | int i;
|
2532 | fd4d81dd | Arnaud Patard | int ret;
|
2533 | b12b6a18 | ths | |
2534 | 31e31b8a | bellard | if (argc <= 1) |
2535 | 44de1b33 | pbrook | usage(); |
2536 | f801f97e | bellard | |
2537 | 902b3d5c | malc | qemu_cache_utils_init(envp); |
2538 | 902b3d5c | malc | |
2539 | cc38b844 | bellard | /* init debug */
|
2540 | cc38b844 | bellard | cpu_set_log_filename(DEBUG_LOGFILE); |
2541 | cc38b844 | bellard | |
2542 | 04a6dfeb | aurel32 | if ((envlist = envlist_create()) == NULL) { |
2543 | 04a6dfeb | aurel32 | (void) fprintf(stderr, "Unable to allocate envlist\n"); |
2544 | 04a6dfeb | aurel32 | exit(1);
|
2545 | 04a6dfeb | aurel32 | } |
2546 | 04a6dfeb | aurel32 | |
2547 | 04a6dfeb | aurel32 | /* add current environment into the list */
|
2548 | 04a6dfeb | aurel32 | for (wrk = environ; *wrk != NULL; wrk++) { |
2549 | 04a6dfeb | aurel32 | (void) envlist_setenv(envlist, *wrk);
|
2550 | 04a6dfeb | aurel32 | } |
2551 | 04a6dfeb | aurel32 | |
2552 | b1f9be31 | j_mayer | cpu_model = NULL;
|
2553 | 586314f2 | bellard | optind = 1;
|
2554 | d691f669 | bellard | for(;;) {
|
2555 | d691f669 | bellard | if (optind >= argc)
|
2556 | d691f669 | bellard | break;
|
2557 | d691f669 | bellard | r = argv[optind]; |
2558 | d691f669 | bellard | if (r[0] != '-') |
2559 | d691f669 | bellard | break;
|
2560 | 586314f2 | bellard | optind++; |
2561 | d691f669 | bellard | r++; |
2562 | d691f669 | bellard | if (!strcmp(r, "-")) { |
2563 | d691f669 | bellard | break;
|
2564 | d691f669 | bellard | } else if (!strcmp(r, "d")) { |
2565 | e19e89a5 | bellard | int mask;
|
2566 | c7cd6a37 | blueswir1 | const CPULogItem *item;
|
2567 | 6f1f31c0 | bellard | |
2568 | 6f1f31c0 | bellard | if (optind >= argc)
|
2569 | 6f1f31c0 | bellard | break;
|
2570 | 3b46e624 | ths | |
2571 | 6f1f31c0 | bellard | r = argv[optind++]; |
2572 | 6f1f31c0 | bellard | mask = cpu_str_to_log_mask(r); |
2573 | e19e89a5 | bellard | if (!mask) {
|
2574 | e19e89a5 | bellard | printf("Log items (comma separated):\n");
|
2575 | e19e89a5 | bellard | for(item = cpu_log_items; item->mask != 0; item++) { |
2576 | e19e89a5 | bellard | printf("%-10s %s\n", item->name, item->help);
|
2577 | e19e89a5 | bellard | } |
2578 | e19e89a5 | bellard | exit(1);
|
2579 | e19e89a5 | bellard | } |
2580 | e19e89a5 | bellard | cpu_set_log(mask); |
2581 | 04a6dfeb | aurel32 | } else if (!strcmp(r, "E")) { |
2582 | 04a6dfeb | aurel32 | r = argv[optind++]; |
2583 | 04a6dfeb | aurel32 | if (envlist_setenv(envlist, r) != 0) |
2584 | 04a6dfeb | aurel32 | usage(); |
2585 | 04a6dfeb | aurel32 | } else if (!strcmp(r, "U")) { |
2586 | 04a6dfeb | aurel32 | r = argv[optind++]; |
2587 | 04a6dfeb | aurel32 | if (envlist_unsetenv(envlist, r) != 0) |
2588 | 04a6dfeb | aurel32 | usage(); |
2589 | 7d8cec95 | aurel32 | } else if (!strcmp(r, "0")) { |
2590 | 7d8cec95 | aurel32 | r = argv[optind++]; |
2591 | 7d8cec95 | aurel32 | argv0 = r; |
2592 | d691f669 | bellard | } else if (!strcmp(r, "s")) { |
2593 | 491150db | aurel32 | if (optind >= argc)
|
2594 | 491150db | aurel32 | break;
|
2595 | d691f669 | bellard | r = argv[optind++]; |
2596 | d691f669 | bellard | x86_stack_size = strtol(r, (char **)&r, 0); |
2597 | d691f669 | bellard | if (x86_stack_size <= 0) |
2598 | 44de1b33 | pbrook | usage(); |
2599 | d691f669 | bellard | if (*r == 'M') |
2600 | d691f669 | bellard | x86_stack_size *= 1024 * 1024; |
2601 | d691f669 | bellard | else if (*r == 'k' || *r == 'K') |
2602 | d691f669 | bellard | x86_stack_size *= 1024;
|
2603 | d691f669 | bellard | } else if (!strcmp(r, "L")) { |
2604 | d691f669 | bellard | interp_prefix = argv[optind++]; |
2605 | 54936004 | bellard | } else if (!strcmp(r, "p")) { |
2606 | 491150db | aurel32 | if (optind >= argc)
|
2607 | 491150db | aurel32 | break;
|
2608 | 83fb7adf | bellard | qemu_host_page_size = atoi(argv[optind++]); |
2609 | 83fb7adf | bellard | if (qemu_host_page_size == 0 || |
2610 | 83fb7adf | bellard | (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { |
2611 | 54936004 | bellard | fprintf(stderr, "page size must be a power of two\n");
|
2612 | 54936004 | bellard | exit(1);
|
2613 | 54936004 | bellard | } |
2614 | 1fddef4b | bellard | } else if (!strcmp(r, "g")) { |
2615 | 491150db | aurel32 | if (optind >= argc)
|
2616 | 491150db | aurel32 | break;
|
2617 | 74c33bed | bellard | gdbstub_port = atoi(argv[optind++]); |
2618 | c5937220 | pbrook | } else if (!strcmp(r, "r")) { |
2619 | c5937220 | pbrook | qemu_uname_release = argv[optind++]; |
2620 | b1f9be31 | j_mayer | } else if (!strcmp(r, "cpu")) { |
2621 | b1f9be31 | j_mayer | cpu_model = argv[optind++]; |
2622 | 491150db | aurel32 | if (cpu_model == NULL || strcmp(cpu_model, "?") == 0) { |
2623 | c732abe2 | j_mayer | /* XXX: implement xxx_cpu_list for targets that still miss it */
|
2624 | c732abe2 | j_mayer | #if defined(cpu_list)
|
2625 | c732abe2 | j_mayer | cpu_list(stdout, &fprintf); |
2626 | b1f9be31 | j_mayer | #endif
|
2627 | 2d18e637 | blueswir1 | exit(1);
|
2628 | b1f9be31 | j_mayer | } |
2629 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2630 | 379f6698 | Paul Brook | } else if (!strcmp(r, "B")) { |
2631 | 379f6698 | Paul Brook | guest_base = strtol(argv[optind++], NULL, 0); |
2632 | 379f6698 | Paul Brook | have_guest_base = 1;
|
2633 | 379f6698 | Paul Brook | #endif
|
2634 | b12b6a18 | ths | } else if (!strcmp(r, "drop-ld-preload")) { |
2635 | 04a6dfeb | aurel32 | (void) envlist_unsetenv(envlist, "LD_PRELOAD"); |
2636 | 1b530a6d | aurel32 | } else if (!strcmp(r, "singlestep")) { |
2637 | 1b530a6d | aurel32 | singlestep = 1;
|
2638 | b6741956 | bellard | } else if (!strcmp(r, "strace")) { |
2639 | b6741956 | bellard | do_strace = 1;
|
2640 | 5fafdf24 | ths | } else
|
2641 | c6981055 | bellard | { |
2642 | d691f669 | bellard | usage(); |
2643 | d691f669 | bellard | } |
2644 | 586314f2 | bellard | } |
2645 | d691f669 | bellard | if (optind >= argc)
|
2646 | d691f669 | bellard | usage(); |
2647 | 586314f2 | bellard | filename = argv[optind]; |
2648 | d088d664 | aurel32 | exec_path = argv[optind]; |
2649 | 586314f2 | bellard | |
2650 | 31e31b8a | bellard | /* Zero out regs */
|
2651 | 01ffc75b | bellard | memset(regs, 0, sizeof(struct target_pt_regs)); |
2652 | 31e31b8a | bellard | |
2653 | 31e31b8a | bellard | /* Zero out image_info */
|
2654 | 31e31b8a | bellard | memset(info, 0, sizeof(struct image_info)); |
2655 | 31e31b8a | bellard | |
2656 | edf8e2af | Mika Westerberg | memset(&bprm, 0, sizeof (bprm)); |
2657 | edf8e2af | Mika Westerberg | |
2658 | 74cd30b8 | bellard | /* Scan interp_prefix dir for replacement files. */
|
2659 | 74cd30b8 | bellard | init_paths(interp_prefix); |
2660 | 74cd30b8 | bellard | |
2661 | 46027c07 | bellard | if (cpu_model == NULL) { |
2662 | aaed909a | bellard | #if defined(TARGET_I386)
|
2663 | 46027c07 | bellard | #ifdef TARGET_X86_64
|
2664 | 46027c07 | bellard | cpu_model = "qemu64";
|
2665 | 46027c07 | bellard | #else
|
2666 | 46027c07 | bellard | cpu_model = "qemu32";
|
2667 | 46027c07 | bellard | #endif
|
2668 | aaed909a | bellard | #elif defined(TARGET_ARM)
|
2669 | 088ab16c | pbrook | cpu_model = "any";
|
2670 | aaed909a | bellard | #elif defined(TARGET_M68K)
|
2671 | aaed909a | bellard | cpu_model = "any";
|
2672 | aaed909a | bellard | #elif defined(TARGET_SPARC)
|
2673 | aaed909a | bellard | #ifdef TARGET_SPARC64
|
2674 | aaed909a | bellard | cpu_model = "TI UltraSparc II";
|
2675 | aaed909a | bellard | #else
|
2676 | aaed909a | bellard | cpu_model = "Fujitsu MB86904";
|
2677 | 46027c07 | bellard | #endif
|
2678 | aaed909a | bellard | #elif defined(TARGET_MIPS)
|
2679 | aaed909a | bellard | #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
|
2680 | aaed909a | bellard | cpu_model = "20Kc";
|
2681 | aaed909a | bellard | #else
|
2682 | aaed909a | bellard | cpu_model = "24Kf";
|
2683 | aaed909a | bellard | #endif
|
2684 | aaed909a | bellard | #elif defined(TARGET_PPC)
|
2685 | 7ded4f52 | bellard | #ifdef TARGET_PPC64
|
2686 | 7ded4f52 | bellard | cpu_model = "970";
|
2687 | 7ded4f52 | bellard | #else
|
2688 | aaed909a | bellard | cpu_model = "750";
|
2689 | 7ded4f52 | bellard | #endif
|
2690 | aaed909a | bellard | #else
|
2691 | aaed909a | bellard | cpu_model = "any";
|
2692 | aaed909a | bellard | #endif
|
2693 | aaed909a | bellard | } |
2694 | 26a5f13b | bellard | cpu_exec_init_all(0);
|
2695 | 83fb7adf | bellard | /* NOTE: we need to init the CPU at this stage to get
|
2696 | 83fb7adf | bellard | qemu_host_page_size */
|
2697 | aaed909a | bellard | env = cpu_init(cpu_model); |
2698 | aaed909a | bellard | if (!env) {
|
2699 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2700 | aaed909a | bellard | exit(1);
|
2701 | aaed909a | bellard | } |
2702 | b55a37c9 | Blue Swirl | #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
|
2703 | b55a37c9 | Blue Swirl | cpu_reset(env); |
2704 | b55a37c9 | Blue Swirl | #endif
|
2705 | b55a37c9 | Blue Swirl | |
2706 | d5975363 | pbrook | thread_env = env; |
2707 | 3b46e624 | ths | |
2708 | b6741956 | bellard | if (getenv("QEMU_STRACE")) { |
2709 | b6741956 | bellard | do_strace = 1;
|
2710 | b92c47c1 | ths | } |
2711 | b92c47c1 | ths | |
2712 | 04a6dfeb | aurel32 | target_environ = envlist_to_environ(envlist, NULL);
|
2713 | 04a6dfeb | aurel32 | envlist_free(envlist); |
2714 | b12b6a18 | ths | |
2715 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2716 | 379f6698 | Paul Brook | /*
|
2717 | 379f6698 | Paul Brook | * Now that page sizes are configured in cpu_init() we can do
|
2718 | 379f6698 | Paul Brook | * proper page alignment for guest_base.
|
2719 | 379f6698 | Paul Brook | */
|
2720 | 379f6698 | Paul Brook | guest_base = HOST_PAGE_ALIGN(guest_base); |
2721 | 379f6698 | Paul Brook | |
2722 | 379f6698 | Paul Brook | /*
|
2723 | 379f6698 | Paul Brook | * Read in mmap_min_addr kernel parameter. This value is used
|
2724 | 379f6698 | Paul Brook | * When loading the ELF image to determine whether guest_base
|
2725 | 379f6698 | Paul Brook | * is needed.
|
2726 | 379f6698 | Paul Brook | *
|
2727 | 379f6698 | Paul Brook | * When user has explicitly set the quest base, we skip this
|
2728 | 379f6698 | Paul Brook | * test.
|
2729 | 379f6698 | Paul Brook | */
|
2730 | 379f6698 | Paul Brook | if (!have_guest_base) {
|
2731 | 379f6698 | Paul Brook | FILE *fp; |
2732 | 379f6698 | Paul Brook | |
2733 | 379f6698 | Paul Brook | if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) { |
2734 | 379f6698 | Paul Brook | unsigned long tmp; |
2735 | 379f6698 | Paul Brook | if (fscanf(fp, "%lu", &tmp) == 1) { |
2736 | 379f6698 | Paul Brook | mmap_min_addr = tmp; |
2737 | 379f6698 | Paul Brook | qemu_log("host mmap_min_addr=0x%lx\n", mmap_min_addr);
|
2738 | 379f6698 | Paul Brook | } |
2739 | 379f6698 | Paul Brook | fclose(fp); |
2740 | 379f6698 | Paul Brook | } |
2741 | 379f6698 | Paul Brook | } |
2742 | 379f6698 | Paul Brook | #endif /* CONFIG_USE_GUEST_BASE */ |
2743 | 379f6698 | Paul Brook | |
2744 | 7d8cec95 | aurel32 | /*
|
2745 | 7d8cec95 | aurel32 | * Prepare copy of argv vector for target.
|
2746 | 7d8cec95 | aurel32 | */
|
2747 | 7d8cec95 | aurel32 | target_argc = argc - optind; |
2748 | 7d8cec95 | aurel32 | target_argv = calloc(target_argc + 1, sizeof (char *)); |
2749 | 7d8cec95 | aurel32 | if (target_argv == NULL) { |
2750 | 7d8cec95 | aurel32 | (void) fprintf(stderr, "Unable to allocate memory for target_argv\n"); |
2751 | 7d8cec95 | aurel32 | exit(1);
|
2752 | 7d8cec95 | aurel32 | } |
2753 | 7d8cec95 | aurel32 | |
2754 | 7d8cec95 | aurel32 | /*
|
2755 | 7d8cec95 | aurel32 | * If argv0 is specified (using '-0' switch) we replace
|
2756 | 7d8cec95 | aurel32 | * argv[0] pointer with the given one.
|
2757 | 7d8cec95 | aurel32 | */
|
2758 | 7d8cec95 | aurel32 | i = 0;
|
2759 | 7d8cec95 | aurel32 | if (argv0 != NULL) { |
2760 | 7d8cec95 | aurel32 | target_argv[i++] = strdup(argv0); |
2761 | 7d8cec95 | aurel32 | } |
2762 | 7d8cec95 | aurel32 | for (; i < target_argc; i++) {
|
2763 | 7d8cec95 | aurel32 | target_argv[i] = strdup(argv[optind + i]); |
2764 | 7d8cec95 | aurel32 | } |
2765 | 7d8cec95 | aurel32 | target_argv[target_argc] = NULL;
|
2766 | 7d8cec95 | aurel32 | |
2767 | edf8e2af | Mika Westerberg | memset(ts, 0, sizeof(TaskState)); |
2768 | edf8e2af | Mika Westerberg | init_task_state(ts); |
2769 | edf8e2af | Mika Westerberg | /* build Task State */
|
2770 | edf8e2af | Mika Westerberg | ts->info = info; |
2771 | edf8e2af | Mika Westerberg | ts->bprm = &bprm; |
2772 | edf8e2af | Mika Westerberg | env->opaque = ts; |
2773 | edf8e2af | Mika Westerberg | task_settid(ts); |
2774 | edf8e2af | Mika Westerberg | |
2775 | fd4d81dd | Arnaud Patard | ret = loader_exec(filename, target_argv, target_environ, regs, |
2776 | fd4d81dd | Arnaud Patard | info, &bprm); |
2777 | fd4d81dd | Arnaud Patard | if (ret != 0) { |
2778 | fd4d81dd | Arnaud Patard | printf("Error %d while loading %s\n", ret, filename);
|
2779 | b12b6a18 | ths | _exit(1);
|
2780 | b12b6a18 | ths | } |
2781 | b12b6a18 | ths | |
2782 | 7d8cec95 | aurel32 | for (i = 0; i < target_argc; i++) { |
2783 | 7d8cec95 | aurel32 | free(target_argv[i]); |
2784 | 7d8cec95 | aurel32 | } |
2785 | 7d8cec95 | aurel32 | free(target_argv); |
2786 | 7d8cec95 | aurel32 | |
2787 | b12b6a18 | ths | for (wrk = target_environ; *wrk; wrk++) {
|
2788 | b12b6a18 | ths | free(*wrk); |
2789 | 31e31b8a | bellard | } |
2790 | 3b46e624 | ths | |
2791 | b12b6a18 | ths | free(target_environ); |
2792 | b12b6a18 | ths | |
2793 | 2e77eac6 | blueswir1 | if (qemu_log_enabled()) {
|
2794 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2795 | 379f6698 | Paul Brook | qemu_log("guest_base 0x%lx\n", guest_base);
|
2796 | 379f6698 | Paul Brook | #endif
|
2797 | 2e77eac6 | blueswir1 | log_page_dump(); |
2798 | 2e77eac6 | blueswir1 | |
2799 | 2e77eac6 | blueswir1 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); |
2800 | 2e77eac6 | blueswir1 | qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); |
2801 | 2e77eac6 | blueswir1 | qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n", |
2802 | 2e77eac6 | blueswir1 | info->start_code); |
2803 | 2e77eac6 | blueswir1 | qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n", |
2804 | 2e77eac6 | blueswir1 | info->start_data); |
2805 | 2e77eac6 | blueswir1 | qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data); |
2806 | 2e77eac6 | blueswir1 | qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n", |
2807 | 2e77eac6 | blueswir1 | info->start_stack); |
2808 | 2e77eac6 | blueswir1 | qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk); |
2809 | 2e77eac6 | blueswir1 | qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); |
2810 | 2e77eac6 | blueswir1 | } |
2811 | 31e31b8a | bellard | |
2812 | 53a5960a | pbrook | target_set_brk(info->brk); |
2813 | 31e31b8a | bellard | syscall_init(); |
2814 | 66fb9763 | bellard | signal_init(); |
2815 | 31e31b8a | bellard | |
2816 | b346ff46 | bellard | #if defined(TARGET_I386)
|
2817 | 2e255c6b | bellard | cpu_x86_set_cpl(env, 3);
|
2818 | 2e255c6b | bellard | |
2819 | 3802ce26 | bellard | env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
|
2820 | 1bde465e | bellard | env->hflags |= HF_PE_MASK; |
2821 | 1bde465e | bellard | if (env->cpuid_features & CPUID_SSE) {
|
2822 | 1bde465e | bellard | env->cr[4] |= CR4_OSFXSR_MASK;
|
2823 | 1bde465e | bellard | env->hflags |= HF_OSFXSR_MASK; |
2824 | 1bde465e | bellard | } |
2825 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
2826 | 4dbc422b | bellard | /* enable 64 bit mode if possible */
|
2827 | 4dbc422b | bellard | if (!(env->cpuid_ext2_features & CPUID_EXT2_LM)) {
|
2828 | 4dbc422b | bellard | fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n");
|
2829 | 4dbc422b | bellard | exit(1);
|
2830 | 4dbc422b | bellard | } |
2831 | d2fd1af7 | bellard | env->cr[4] |= CR4_PAE_MASK;
|
2832 | 4dbc422b | bellard | env->efer |= MSR_EFER_LMA | MSR_EFER_LME; |
2833 | d2fd1af7 | bellard | env->hflags |= HF_LMA_MASK; |
2834 | d2fd1af7 | bellard | #endif
|
2835 | 1bde465e | bellard | |
2836 | 415e561f | bellard | /* flags setup : we activate the IRQs by default as in user mode */
|
2837 | 415e561f | bellard | env->eflags |= IF_MASK; |
2838 | 3b46e624 | ths | |
2839 | 6dbad63e | bellard | /* linux register setup */
|
2840 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
2841 | 84409ddb | j_mayer | env->regs[R_EAX] = regs->rax; |
2842 | 84409ddb | j_mayer | env->regs[R_EBX] = regs->rbx; |
2843 | 84409ddb | j_mayer | env->regs[R_ECX] = regs->rcx; |
2844 | 84409ddb | j_mayer | env->regs[R_EDX] = regs->rdx; |
2845 | 84409ddb | j_mayer | env->regs[R_ESI] = regs->rsi; |
2846 | 84409ddb | j_mayer | env->regs[R_EDI] = regs->rdi; |
2847 | 84409ddb | j_mayer | env->regs[R_EBP] = regs->rbp; |
2848 | 84409ddb | j_mayer | env->regs[R_ESP] = regs->rsp; |
2849 | 84409ddb | j_mayer | env->eip = regs->rip; |
2850 | 84409ddb | j_mayer | #else
|
2851 | 0ecfa993 | bellard | env->regs[R_EAX] = regs->eax; |
2852 | 0ecfa993 | bellard | env->regs[R_EBX] = regs->ebx; |
2853 | 0ecfa993 | bellard | env->regs[R_ECX] = regs->ecx; |
2854 | 0ecfa993 | bellard | env->regs[R_EDX] = regs->edx; |
2855 | 0ecfa993 | bellard | env->regs[R_ESI] = regs->esi; |
2856 | 0ecfa993 | bellard | env->regs[R_EDI] = regs->edi; |
2857 | 0ecfa993 | bellard | env->regs[R_EBP] = regs->ebp; |
2858 | 0ecfa993 | bellard | env->regs[R_ESP] = regs->esp; |
2859 | dab2ed99 | bellard | env->eip = regs->eip; |
2860 | 84409ddb | j_mayer | #endif
|
2861 | 31e31b8a | bellard | |
2862 | f4beb510 | bellard | /* linux interrupt setup */
|
2863 | e441570f | balrog | #ifndef TARGET_ABI32
|
2864 | e441570f | balrog | env->idt.limit = 511;
|
2865 | e441570f | balrog | #else
|
2866 | e441570f | balrog | env->idt.limit = 255;
|
2867 | e441570f | balrog | #endif
|
2868 | e441570f | balrog | env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), |
2869 | e441570f | balrog | PROT_READ|PROT_WRITE, |
2870 | e441570f | balrog | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
2871 | e441570f | balrog | idt_table = g2h(env->idt.base); |
2872 | f4beb510 | bellard | set_idt(0, 0); |
2873 | f4beb510 | bellard | set_idt(1, 0); |
2874 | f4beb510 | bellard | set_idt(2, 0); |
2875 | f4beb510 | bellard | set_idt(3, 3); |
2876 | f4beb510 | bellard | set_idt(4, 3); |
2877 | ec95da6c | bellard | set_idt(5, 0); |
2878 | f4beb510 | bellard | set_idt(6, 0); |
2879 | f4beb510 | bellard | set_idt(7, 0); |
2880 | f4beb510 | bellard | set_idt(8, 0); |
2881 | f4beb510 | bellard | set_idt(9, 0); |
2882 | f4beb510 | bellard | set_idt(10, 0); |
2883 | f4beb510 | bellard | set_idt(11, 0); |
2884 | f4beb510 | bellard | set_idt(12, 0); |
2885 | f4beb510 | bellard | set_idt(13, 0); |
2886 | f4beb510 | bellard | set_idt(14, 0); |
2887 | f4beb510 | bellard | set_idt(15, 0); |
2888 | f4beb510 | bellard | set_idt(16, 0); |
2889 | f4beb510 | bellard | set_idt(17, 0); |
2890 | f4beb510 | bellard | set_idt(18, 0); |
2891 | f4beb510 | bellard | set_idt(19, 0); |
2892 | f4beb510 | bellard | set_idt(0x80, 3); |
2893 | f4beb510 | bellard | |
2894 | 6dbad63e | bellard | /* linux segment setup */
|
2895 | 8d18e893 | bellard | { |
2896 | 8d18e893 | bellard | uint64_t *gdt_table; |
2897 | e441570f | balrog | env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, |
2898 | e441570f | balrog | PROT_READ|PROT_WRITE, |
2899 | e441570f | balrog | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
2900 | 8d18e893 | bellard | env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; |
2901 | e441570f | balrog | gdt_table = g2h(env->gdt.base); |
2902 | d2fd1af7 | bellard | #ifdef TARGET_ABI32
|
2903 | 8d18e893 | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, |
2904 | 8d18e893 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2905 | 8d18e893 | bellard | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); |
2906 | d2fd1af7 | bellard | #else
|
2907 | d2fd1af7 | bellard | /* 64 bit code segment */
|
2908 | d2fd1af7 | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, |
2909 | d2fd1af7 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2910 | d2fd1af7 | bellard | DESC_L_MASK | |
2911 | d2fd1af7 | bellard | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); |
2912 | d2fd1af7 | bellard | #endif
|
2913 | 8d18e893 | bellard | write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, |
2914 | 8d18e893 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2915 | 8d18e893 | bellard | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); |
2916 | 8d18e893 | bellard | } |
2917 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
2918 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
2919 | d2fd1af7 | bellard | #ifdef TARGET_ABI32
|
2920 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
2921 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
2922 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_FS, __USER_DS); |
2923 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_GS, __USER_DS); |
2924 | d6eb40f6 | ths | /* This hack makes Wine work... */
|
2925 | d6eb40f6 | ths | env->segs[R_FS].selector = 0;
|
2926 | d2fd1af7 | bellard | #else
|
2927 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_DS, 0);
|
2928 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_ES, 0);
|
2929 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_FS, 0);
|
2930 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_GS, 0);
|
2931 | d2fd1af7 | bellard | #endif
|
2932 | b346ff46 | bellard | #elif defined(TARGET_ARM)
|
2933 | b346ff46 | bellard | { |
2934 | b346ff46 | bellard | int i;
|
2935 | b5ff1b31 | bellard | cpsr_write(env, regs->uregs[16], 0xffffffff); |
2936 | b346ff46 | bellard | for(i = 0; i < 16; i++) { |
2937 | b346ff46 | bellard | env->regs[i] = regs->uregs[i]; |
2938 | b346ff46 | bellard | } |
2939 | b346ff46 | bellard | } |
2940 | 93ac68bc | bellard | #elif defined(TARGET_SPARC)
|
2941 | 060366c5 | bellard | { |
2942 | 060366c5 | bellard | int i;
|
2943 | 060366c5 | bellard | env->pc = regs->pc; |
2944 | 060366c5 | bellard | env->npc = regs->npc; |
2945 | 060366c5 | bellard | env->y = regs->y; |
2946 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
2947 | 060366c5 | bellard | env->gregs[i] = regs->u_regs[i]; |
2948 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
2949 | 060366c5 | bellard | env->regwptr[i] = regs->u_regs[i + 8];
|
2950 | 060366c5 | bellard | } |
2951 | 67867308 | bellard | #elif defined(TARGET_PPC)
|
2952 | 67867308 | bellard | { |
2953 | 67867308 | bellard | int i;
|
2954 | 3fc6c082 | bellard | |
2955 | 0411a972 | j_mayer | #if defined(TARGET_PPC64)
|
2956 | 0411a972 | j_mayer | #if defined(TARGET_ABI32)
|
2957 | 0411a972 | j_mayer | env->msr &= ~((target_ulong)1 << MSR_SF);
|
2958 | e85e7c6e | j_mayer | #else
|
2959 | 0411a972 | j_mayer | env->msr |= (target_ulong)1 << MSR_SF;
|
2960 | 0411a972 | j_mayer | #endif
|
2961 | 84409ddb | j_mayer | #endif
|
2962 | 67867308 | bellard | env->nip = regs->nip; |
2963 | 67867308 | bellard | for(i = 0; i < 32; i++) { |
2964 | 67867308 | bellard | env->gpr[i] = regs->gpr[i]; |
2965 | 67867308 | bellard | } |
2966 | 67867308 | bellard | } |
2967 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
2968 | e6e5906b | pbrook | { |
2969 | e6e5906b | pbrook | env->pc = regs->pc; |
2970 | e6e5906b | pbrook | env->dregs[0] = regs->d0;
|
2971 | e6e5906b | pbrook | env->dregs[1] = regs->d1;
|
2972 | e6e5906b | pbrook | env->dregs[2] = regs->d2;
|
2973 | e6e5906b | pbrook | env->dregs[3] = regs->d3;
|
2974 | e6e5906b | pbrook | env->dregs[4] = regs->d4;
|
2975 | e6e5906b | pbrook | env->dregs[5] = regs->d5;
|
2976 | e6e5906b | pbrook | env->dregs[6] = regs->d6;
|
2977 | e6e5906b | pbrook | env->dregs[7] = regs->d7;
|
2978 | e6e5906b | pbrook | env->aregs[0] = regs->a0;
|
2979 | e6e5906b | pbrook | env->aregs[1] = regs->a1;
|
2980 | e6e5906b | pbrook | env->aregs[2] = regs->a2;
|
2981 | e6e5906b | pbrook | env->aregs[3] = regs->a3;
|
2982 | e6e5906b | pbrook | env->aregs[4] = regs->a4;
|
2983 | e6e5906b | pbrook | env->aregs[5] = regs->a5;
|
2984 | e6e5906b | pbrook | env->aregs[6] = regs->a6;
|
2985 | e6e5906b | pbrook | env->aregs[7] = regs->usp;
|
2986 | e6e5906b | pbrook | env->sr = regs->sr; |
2987 | e6e5906b | pbrook | ts->sim_syscalls = 1;
|
2988 | e6e5906b | pbrook | } |
2989 | b779e29e | Edgar E. Iglesias | #elif defined(TARGET_MICROBLAZE)
|
2990 | b779e29e | Edgar E. Iglesias | { |
2991 | b779e29e | Edgar E. Iglesias | env->regs[0] = regs->r0;
|
2992 | b779e29e | Edgar E. Iglesias | env->regs[1] = regs->r1;
|
2993 | b779e29e | Edgar E. Iglesias | env->regs[2] = regs->r2;
|
2994 | b779e29e | Edgar E. Iglesias | env->regs[3] = regs->r3;
|
2995 | b779e29e | Edgar E. Iglesias | env->regs[4] = regs->r4;
|
2996 | b779e29e | Edgar E. Iglesias | env->regs[5] = regs->r5;
|
2997 | b779e29e | Edgar E. Iglesias | env->regs[6] = regs->r6;
|
2998 | b779e29e | Edgar E. Iglesias | env->regs[7] = regs->r7;
|
2999 | b779e29e | Edgar E. Iglesias | env->regs[8] = regs->r8;
|
3000 | b779e29e | Edgar E. Iglesias | env->regs[9] = regs->r9;
|
3001 | b779e29e | Edgar E. Iglesias | env->regs[10] = regs->r10;
|
3002 | b779e29e | Edgar E. Iglesias | env->regs[11] = regs->r11;
|
3003 | b779e29e | Edgar E. Iglesias | env->regs[12] = regs->r12;
|
3004 | b779e29e | Edgar E. Iglesias | env->regs[13] = regs->r13;
|
3005 | b779e29e | Edgar E. Iglesias | env->regs[14] = regs->r14;
|
3006 | b779e29e | Edgar E. Iglesias | env->regs[15] = regs->r15;
|
3007 | b779e29e | Edgar E. Iglesias | env->regs[16] = regs->r16;
|
3008 | b779e29e | Edgar E. Iglesias | env->regs[17] = regs->r17;
|
3009 | b779e29e | Edgar E. Iglesias | env->regs[18] = regs->r18;
|
3010 | b779e29e | Edgar E. Iglesias | env->regs[19] = regs->r19;
|
3011 | b779e29e | Edgar E. Iglesias | env->regs[20] = regs->r20;
|
3012 | b779e29e | Edgar E. Iglesias | env->regs[21] = regs->r21;
|
3013 | b779e29e | Edgar E. Iglesias | env->regs[22] = regs->r22;
|
3014 | b779e29e | Edgar E. Iglesias | env->regs[23] = regs->r23;
|
3015 | b779e29e | Edgar E. Iglesias | env->regs[24] = regs->r24;
|
3016 | b779e29e | Edgar E. Iglesias | env->regs[25] = regs->r25;
|
3017 | b779e29e | Edgar E. Iglesias | env->regs[26] = regs->r26;
|
3018 | b779e29e | Edgar E. Iglesias | env->regs[27] = regs->r27;
|
3019 | b779e29e | Edgar E. Iglesias | env->regs[28] = regs->r28;
|
3020 | b779e29e | Edgar E. Iglesias | env->regs[29] = regs->r29;
|
3021 | b779e29e | Edgar E. Iglesias | env->regs[30] = regs->r30;
|
3022 | b779e29e | Edgar E. Iglesias | env->regs[31] = regs->r31;
|
3023 | b779e29e | Edgar E. Iglesias | env->sregs[SR_PC] = regs->pc; |
3024 | b779e29e | Edgar E. Iglesias | } |
3025 | 048f6b4d | bellard | #elif defined(TARGET_MIPS)
|
3026 | 048f6b4d | bellard | { |
3027 | 048f6b4d | bellard | int i;
|
3028 | 048f6b4d | bellard | |
3029 | 048f6b4d | bellard | for(i = 0; i < 32; i++) { |
3030 | b5dc7732 | ths | env->active_tc.gpr[i] = regs->regs[i]; |
3031 | 048f6b4d | bellard | } |
3032 | b5dc7732 | ths | env->active_tc.PC = regs->cp0_epc; |
3033 | 048f6b4d | bellard | } |
3034 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
3035 | fdf9b3e8 | bellard | { |
3036 | fdf9b3e8 | bellard | int i;
|
3037 | fdf9b3e8 | bellard | |
3038 | fdf9b3e8 | bellard | for(i = 0; i < 16; i++) { |
3039 | fdf9b3e8 | bellard | env->gregs[i] = regs->regs[i]; |
3040 | fdf9b3e8 | bellard | } |
3041 | fdf9b3e8 | bellard | env->pc = regs->pc; |
3042 | fdf9b3e8 | bellard | } |
3043 | 7a3148a9 | j_mayer | #elif defined(TARGET_ALPHA)
|
3044 | 7a3148a9 | j_mayer | { |
3045 | 7a3148a9 | j_mayer | int i;
|
3046 | 7a3148a9 | j_mayer | |
3047 | 7a3148a9 | j_mayer | for(i = 0; i < 28; i++) { |
3048 | 992f48a0 | blueswir1 | env->ir[i] = ((abi_ulong *)regs)[i]; |
3049 | 7a3148a9 | j_mayer | } |
3050 | 7a3148a9 | j_mayer | env->ipr[IPR_USP] = regs->usp; |
3051 | 7a3148a9 | j_mayer | env->ir[30] = regs->usp;
|
3052 | 7a3148a9 | j_mayer | env->pc = regs->pc; |
3053 | 7a3148a9 | j_mayer | env->unique = regs->unique; |
3054 | 7a3148a9 | j_mayer | } |
3055 | 48733d19 | ths | #elif defined(TARGET_CRIS)
|
3056 | 48733d19 | ths | { |
3057 | 48733d19 | ths | env->regs[0] = regs->r0;
|
3058 | 48733d19 | ths | env->regs[1] = regs->r1;
|
3059 | 48733d19 | ths | env->regs[2] = regs->r2;
|
3060 | 48733d19 | ths | env->regs[3] = regs->r3;
|
3061 | 48733d19 | ths | env->regs[4] = regs->r4;
|
3062 | 48733d19 | ths | env->regs[5] = regs->r5;
|
3063 | 48733d19 | ths | env->regs[6] = regs->r6;
|
3064 | 48733d19 | ths | env->regs[7] = regs->r7;
|
3065 | 48733d19 | ths | env->regs[8] = regs->r8;
|
3066 | 48733d19 | ths | env->regs[9] = regs->r9;
|
3067 | 48733d19 | ths | env->regs[10] = regs->r10;
|
3068 | 48733d19 | ths | env->regs[11] = regs->r11;
|
3069 | 48733d19 | ths | env->regs[12] = regs->r12;
|
3070 | 48733d19 | ths | env->regs[13] = regs->r13;
|
3071 | 48733d19 | ths | env->regs[14] = info->start_stack;
|
3072 | 48733d19 | ths | env->regs[15] = regs->acr;
|
3073 | 48733d19 | ths | env->pc = regs->erp; |
3074 | 48733d19 | ths | } |
3075 | b346ff46 | bellard | #else
|
3076 | b346ff46 | bellard | #error unsupported target CPU
|
3077 | b346ff46 | bellard | #endif
|
3078 | 31e31b8a | bellard | |
3079 | a87295e8 | pbrook | #if defined(TARGET_ARM) || defined(TARGET_M68K)
|
3080 | a87295e8 | pbrook | ts->stack_base = info->start_stack; |
3081 | a87295e8 | pbrook | ts->heap_base = info->brk; |
3082 | a87295e8 | pbrook | /* This will be filled in on the first SYS_HEAPINFO call. */
|
3083 | a87295e8 | pbrook | ts->heap_limit = 0;
|
3084 | a87295e8 | pbrook | #endif
|
3085 | a87295e8 | pbrook | |
3086 | 74c33bed | bellard | if (gdbstub_port) {
|
3087 | 74c33bed | bellard | gdbserver_start (gdbstub_port); |
3088 | 1fddef4b | bellard | gdb_handlesig(env, 0);
|
3089 | 1fddef4b | bellard | } |
3090 | 1b6b029e | bellard | cpu_loop(env); |
3091 | 1b6b029e | bellard | /* never exits */
|
3092 | 31e31b8a | bellard | return 0; |
3093 | 31e31b8a | bellard | } |