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