root / linux-user / main.c @ d418c81e
History | View | Annotate | Download (11.6 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 3ef693a0 | bellard | * qemu main
|
3 | 31e31b8a | bellard | *
|
4 | 31e31b8a | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 31e31b8a | bellard | * along with this program; if not, write to the Free Software
|
18 | 31e31b8a | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 31e31b8a | bellard | */
|
20 | 31e31b8a | bellard | #include <stdlib.h> |
21 | 31e31b8a | bellard | #include <stdio.h> |
22 | 31e31b8a | bellard | #include <stdarg.h> |
23 | 04369ff2 | bellard | #include <string.h> |
24 | 31e31b8a | bellard | #include <errno.h> |
25 | 0ecfa993 | bellard | #include <unistd.h> |
26 | 31e31b8a | bellard | |
27 | 3ef693a0 | bellard | #include "qemu.h" |
28 | 31e31b8a | bellard | |
29 | 0ecfa993 | bellard | #include "cpu-i386.h" |
30 | 31e31b8a | bellard | |
31 | 3ef693a0 | bellard | #define DEBUG_LOGFILE "/tmp/qemu.log" |
32 | 586314f2 | bellard | |
33 | 586314f2 | bellard | FILE *logfile = NULL;
|
34 | 586314f2 | bellard | int loglevel;
|
35 | 74cd30b8 | bellard | static const char *interp_prefix = CONFIG_QEMU_PREFIX; |
36 | 586314f2 | bellard | |
37 | f801f97e | bellard | #ifdef __i386__
|
38 | f801f97e | bellard | /* Force usage of an ELF interpreter even if it is an ELF shared
|
39 | f801f97e | bellard | object ! */
|
40 | f801f97e | bellard | const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2"; |
41 | 74cd30b8 | bellard | |
42 | 74cd30b8 | bellard | /* for recent libc, we add these dummies symbol which are not declared
|
43 | 74cd30b8 | bellard | when generating a linked object (bug in ld ?) */
|
44 | 74cd30b8 | bellard | #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) |
45 | 74cd30b8 | bellard | long __init_array_start[0]; |
46 | 74cd30b8 | bellard | long __init_array_end[0]; |
47 | 74cd30b8 | bellard | long __fini_array_start[0]; |
48 | 74cd30b8 | bellard | long __fini_array_end[0]; |
49 | 74cd30b8 | bellard | #endif
|
50 | 74cd30b8 | bellard | |
51 | f801f97e | bellard | #endif
|
52 | f801f97e | bellard | |
53 | 9de5e440 | bellard | /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
|
54 | 9de5e440 | bellard | we allocate a bigger stack. Need a better solution, for example
|
55 | 9de5e440 | bellard | by remapping the process stack directly at the right place */
|
56 | 9de5e440 | bellard | unsigned long x86_stack_size = 512 * 1024; |
57 | 31e31b8a | bellard | |
58 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) |
59 | 31e31b8a | bellard | { |
60 | 31e31b8a | bellard | va_list ap; |
61 | 31e31b8a | bellard | |
62 | 31e31b8a | bellard | va_start(ap, fmt); |
63 | 31e31b8a | bellard | vfprintf(stderr, fmt, ap); |
64 | 31e31b8a | bellard | va_end(ap); |
65 | 31e31b8a | bellard | } |
66 | 31e31b8a | bellard | |
67 | 31e31b8a | bellard | /***********************************************************/
|
68 | 0ecfa993 | bellard | /* CPUX86 core interface */
|
69 | 367e86e8 | bellard | |
70 | b689bc57 | bellard | void cpu_x86_outb(CPUX86State *env, int addr, int val) |
71 | 367e86e8 | bellard | { |
72 | 367e86e8 | bellard | fprintf(stderr, "outb: port=0x%04x, data=%02x\n", addr, val);
|
73 | 367e86e8 | bellard | } |
74 | 367e86e8 | bellard | |
75 | b689bc57 | bellard | void cpu_x86_outw(CPUX86State *env, int addr, int val) |
76 | 367e86e8 | bellard | { |
77 | 367e86e8 | bellard | fprintf(stderr, "outw: port=0x%04x, data=%04x\n", addr, val);
|
78 | 367e86e8 | bellard | } |
79 | 367e86e8 | bellard | |
80 | b689bc57 | bellard | void cpu_x86_outl(CPUX86State *env, int addr, int val) |
81 | 367e86e8 | bellard | { |
82 | 367e86e8 | bellard | fprintf(stderr, "outl: port=0x%04x, data=%08x\n", addr, val);
|
83 | 367e86e8 | bellard | } |
84 | 367e86e8 | bellard | |
85 | b689bc57 | bellard | int cpu_x86_inb(CPUX86State *env, int addr) |
86 | 367e86e8 | bellard | { |
87 | 367e86e8 | bellard | fprintf(stderr, "inb: port=0x%04x\n", addr);
|
88 | 367e86e8 | bellard | return 0; |
89 | 367e86e8 | bellard | } |
90 | 367e86e8 | bellard | |
91 | b689bc57 | bellard | int cpu_x86_inw(CPUX86State *env, int addr) |
92 | 367e86e8 | bellard | { |
93 | 367e86e8 | bellard | fprintf(stderr, "inw: port=0x%04x\n", addr);
|
94 | 367e86e8 | bellard | return 0; |
95 | 367e86e8 | bellard | } |
96 | 367e86e8 | bellard | |
97 | b689bc57 | bellard | int cpu_x86_inl(CPUX86State *env, int addr) |
98 | 367e86e8 | bellard | { |
99 | 367e86e8 | bellard | fprintf(stderr, "inl: port=0x%04x\n", addr);
|
100 | 367e86e8 | bellard | return 0; |
101 | 367e86e8 | bellard | } |
102 | 367e86e8 | bellard | |
103 | 6dbad63e | bellard | void write_dt(void *ptr, unsigned long addr, unsigned long limit, |
104 | 6dbad63e | bellard | int seg32_bit)
|
105 | 6dbad63e | bellard | { |
106 | 6dbad63e | bellard | unsigned int e1, e2, limit_in_pages; |
107 | 6dbad63e | bellard | limit_in_pages = 0;
|
108 | 6dbad63e | bellard | if (limit > 0xffff) { |
109 | 6dbad63e | bellard | limit = limit >> 12;
|
110 | 6dbad63e | bellard | limit_in_pages = 1;
|
111 | 6dbad63e | bellard | } |
112 | 6dbad63e | bellard | e1 = (addr << 16) | (limit & 0xffff); |
113 | 6dbad63e | bellard | e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); |
114 | 6dbad63e | bellard | e2 |= limit_in_pages << 23; /* byte granularity */ |
115 | 6dbad63e | bellard | e2 |= seg32_bit << 22; /* 32 bit segment */ |
116 | 6dbad63e | bellard | stl((uint8_t *)ptr, e1); |
117 | 6dbad63e | bellard | stl((uint8_t *)ptr + 4, e2);
|
118 | 6dbad63e | bellard | } |
119 | 6dbad63e | bellard | |
120 | 6dbad63e | bellard | uint64_t gdt_table[6];
|
121 | 31e31b8a | bellard | |
122 | 89e957e7 | bellard | void cpu_loop(CPUX86State *env)
|
123 | 1b6b029e | bellard | { |
124 | bc8a22cc | bellard | int trapnr;
|
125 | 9de5e440 | bellard | uint8_t *pc; |
126 | 9de5e440 | bellard | target_siginfo_t info; |
127 | 851e67a1 | bellard | |
128 | 1b6b029e | bellard | for(;;) {
|
129 | bc8a22cc | bellard | trapnr = cpu_x86_exec(env); |
130 | bc8a22cc | bellard | switch(trapnr) {
|
131 | 1b6b029e | bellard | case EXCP0D_GPF:
|
132 | 851e67a1 | bellard | if (env->eflags & VM_MASK) {
|
133 | 89e957e7 | bellard | handle_vm86_fault(env); |
134 | 1b6b029e | bellard | } else {
|
135 | 89e957e7 | bellard | pc = env->seg_cache[R_CS].base + env->eip; |
136 | 851e67a1 | bellard | if (pc[0] == 0xcd && pc[1] == 0x80) { |
137 | 851e67a1 | bellard | /* syscall */
|
138 | 851e67a1 | bellard | env->eip += 2;
|
139 | 851e67a1 | bellard | env->regs[R_EAX] = do_syscall(env, |
140 | 851e67a1 | bellard | env->regs[R_EAX], |
141 | 851e67a1 | bellard | env->regs[R_EBX], |
142 | 851e67a1 | bellard | env->regs[R_ECX], |
143 | 851e67a1 | bellard | env->regs[R_EDX], |
144 | 851e67a1 | bellard | env->regs[R_ESI], |
145 | 851e67a1 | bellard | env->regs[R_EDI], |
146 | 851e67a1 | bellard | env->regs[R_EBP]); |
147 | 851e67a1 | bellard | } else {
|
148 | 851e67a1 | bellard | /* XXX: more precise info */
|
149 | 851e67a1 | bellard | info.si_signo = SIGSEGV; |
150 | 851e67a1 | bellard | info.si_errno = 0;
|
151 | b689bc57 | bellard | info.si_code = TARGET_SI_KERNEL; |
152 | 851e67a1 | bellard | info._sifields._sigfault._addr = 0;
|
153 | 851e67a1 | bellard | queue_signal(info.si_signo, &info); |
154 | 851e67a1 | bellard | } |
155 | 1b6b029e | bellard | } |
156 | 1b6b029e | bellard | break;
|
157 | b689bc57 | bellard | case EXCP0E_PAGE:
|
158 | b689bc57 | bellard | info.si_signo = SIGSEGV; |
159 | b689bc57 | bellard | info.si_errno = 0;
|
160 | b689bc57 | bellard | if (!(env->error_code & 1)) |
161 | b689bc57 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
162 | b689bc57 | bellard | else
|
163 | b689bc57 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
164 | b689bc57 | bellard | info._sifields._sigfault._addr = env->cr2; |
165 | b689bc57 | bellard | queue_signal(info.si_signo, &info); |
166 | b689bc57 | bellard | break;
|
167 | 9de5e440 | bellard | case EXCP00_DIVZ:
|
168 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
169 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
170 | bc8a22cc | bellard | } else {
|
171 | bc8a22cc | bellard | /* division by zero */
|
172 | bc8a22cc | bellard | info.si_signo = SIGFPE; |
173 | bc8a22cc | bellard | info.si_errno = 0;
|
174 | bc8a22cc | bellard | info.si_code = TARGET_FPE_INTDIV; |
175 | bc8a22cc | bellard | info._sifields._sigfault._addr = env->eip; |
176 | bc8a22cc | bellard | queue_signal(info.si_signo, &info); |
177 | bc8a22cc | bellard | } |
178 | 9de5e440 | bellard | break;
|
179 | 447db213 | bellard | case EXCP01_SSTP:
|
180 | 447db213 | bellard | case EXCP03_INT3:
|
181 | 447db213 | bellard | if (env->eflags & VM_MASK) {
|
182 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
183 | 447db213 | bellard | } else {
|
184 | 447db213 | bellard | info.si_signo = SIGTRAP; |
185 | 447db213 | bellard | info.si_errno = 0;
|
186 | 447db213 | bellard | if (trapnr == EXCP01_SSTP) {
|
187 | 447db213 | bellard | info.si_code = TARGET_TRAP_BRKPT; |
188 | 447db213 | bellard | info._sifields._sigfault._addr = env->eip; |
189 | 447db213 | bellard | } else {
|
190 | 447db213 | bellard | info.si_code = TARGET_SI_KERNEL; |
191 | 447db213 | bellard | info._sifields._sigfault._addr = 0;
|
192 | 447db213 | bellard | } |
193 | 447db213 | bellard | queue_signal(info.si_signo, &info); |
194 | 447db213 | bellard | } |
195 | 447db213 | bellard | break;
|
196 | 9de5e440 | bellard | case EXCP04_INTO:
|
197 | 9de5e440 | bellard | case EXCP05_BOUND:
|
198 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
199 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
200 | bc8a22cc | bellard | } else {
|
201 | bc8a22cc | bellard | info.si_signo = SIGSEGV; |
202 | bc8a22cc | bellard | info.si_errno = 0;
|
203 | b689bc57 | bellard | info.si_code = TARGET_SI_KERNEL; |
204 | bc8a22cc | bellard | info._sifields._sigfault._addr = 0;
|
205 | bc8a22cc | bellard | queue_signal(info.si_signo, &info); |
206 | bc8a22cc | bellard | } |
207 | 9de5e440 | bellard | break;
|
208 | 9de5e440 | bellard | case EXCP06_ILLOP:
|
209 | 9de5e440 | bellard | info.si_signo = SIGILL; |
210 | 9de5e440 | bellard | info.si_errno = 0;
|
211 | 9de5e440 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
212 | 9de5e440 | bellard | info._sifields._sigfault._addr = env->eip; |
213 | 9de5e440 | bellard | queue_signal(info.si_signo, &info); |
214 | 9de5e440 | bellard | break;
|
215 | 9de5e440 | bellard | case EXCP_INTERRUPT:
|
216 | 9de5e440 | bellard | /* just indicate that signals should be handled asap */
|
217 | 9de5e440 | bellard | break;
|
218 | 1b6b029e | bellard | default:
|
219 | 89e957e7 | bellard | pc = env->seg_cache[R_CS].base + env->eip; |
220 | bc8a22cc | bellard | fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
|
221 | bc8a22cc | bellard | (long)pc, trapnr);
|
222 | 1b6b029e | bellard | abort(); |
223 | 1b6b029e | bellard | } |
224 | 66fb9763 | bellard | process_pending_signals(env); |
225 | 1b6b029e | bellard | } |
226 | 1b6b029e | bellard | } |
227 | 1b6b029e | bellard | |
228 | 31e31b8a | bellard | void usage(void) |
229 | 31e31b8a | bellard | { |
230 | 3ef693a0 | bellard | printf("qemu version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n" |
231 | d691f669 | bellard | "usage: qemu [-h] [-d] [-L path] [-s size] program [arguments...]\n"
|
232 | 31e31b8a | bellard | "Linux x86 emulator\n"
|
233 | d691f669 | bellard | "\n"
|
234 | 54936004 | bellard | "-h print this help\n"
|
235 | 54936004 | bellard | "-L path set the x86 elf interpreter prefix (default=%s)\n"
|
236 | 54936004 | bellard | "-s size set the x86 stack size in bytes (default=%ld)\n"
|
237 | 54936004 | bellard | "\n"
|
238 | 54936004 | bellard | "debug options:\n"
|
239 | 54936004 | bellard | "-d activate log (logfile=%s)\n"
|
240 | 54936004 | bellard | "-p pagesize set the host page size to 'pagesize'\n",
|
241 | d691f669 | bellard | interp_prefix, |
242 | 54936004 | bellard | x86_stack_size, |
243 | 54936004 | bellard | DEBUG_LOGFILE); |
244 | 74cd30b8 | bellard | _exit(1);
|
245 | 31e31b8a | bellard | } |
246 | 31e31b8a | bellard | |
247 | 9de5e440 | bellard | /* XXX: currently only used for async signals (see signal.c) */
|
248 | 9de5e440 | bellard | CPUX86State *global_env; |
249 | 851e67a1 | bellard | /* used to free thread contexts */
|
250 | 851e67a1 | bellard | TaskState *first_task_state; |
251 | 9de5e440 | bellard | |
252 | 31e31b8a | bellard | int main(int argc, char **argv) |
253 | 31e31b8a | bellard | { |
254 | 31e31b8a | bellard | const char *filename; |
255 | 01ffc75b | bellard | struct target_pt_regs regs1, *regs = ®s1;
|
256 | 31e31b8a | bellard | struct image_info info1, *info = &info1;
|
257 | 851e67a1 | bellard | TaskState ts1, *ts = &ts1; |
258 | 0ecfa993 | bellard | CPUX86State *env; |
259 | 586314f2 | bellard | int optind;
|
260 | d691f669 | bellard | const char *r; |
261 | d691f669 | bellard | |
262 | 31e31b8a | bellard | if (argc <= 1) |
263 | 31e31b8a | bellard | usage(); |
264 | f801f97e | bellard | |
265 | 586314f2 | bellard | loglevel = 0;
|
266 | 586314f2 | bellard | optind = 1;
|
267 | d691f669 | bellard | for(;;) {
|
268 | d691f669 | bellard | if (optind >= argc)
|
269 | d691f669 | bellard | break;
|
270 | d691f669 | bellard | r = argv[optind]; |
271 | d691f669 | bellard | if (r[0] != '-') |
272 | d691f669 | bellard | break;
|
273 | 586314f2 | bellard | optind++; |
274 | d691f669 | bellard | r++; |
275 | d691f669 | bellard | if (!strcmp(r, "-")) { |
276 | d691f669 | bellard | break;
|
277 | d691f669 | bellard | } else if (!strcmp(r, "d")) { |
278 | d691f669 | bellard | loglevel = 1;
|
279 | d691f669 | bellard | } else if (!strcmp(r, "s")) { |
280 | d691f669 | bellard | r = argv[optind++]; |
281 | d691f669 | bellard | x86_stack_size = strtol(r, (char **)&r, 0); |
282 | d691f669 | bellard | if (x86_stack_size <= 0) |
283 | d691f669 | bellard | usage(); |
284 | d691f669 | bellard | if (*r == 'M') |
285 | d691f669 | bellard | x86_stack_size *= 1024 * 1024; |
286 | d691f669 | bellard | else if (*r == 'k' || *r == 'K') |
287 | d691f669 | bellard | x86_stack_size *= 1024;
|
288 | d691f669 | bellard | } else if (!strcmp(r, "L")) { |
289 | d691f669 | bellard | interp_prefix = argv[optind++]; |
290 | 54936004 | bellard | } else if (!strcmp(r, "p")) { |
291 | 54936004 | bellard | host_page_size = atoi(argv[optind++]); |
292 | 54936004 | bellard | if (host_page_size == 0 || |
293 | 54936004 | bellard | (host_page_size & (host_page_size - 1)) != 0) { |
294 | 54936004 | bellard | fprintf(stderr, "page size must be a power of two\n");
|
295 | 54936004 | bellard | exit(1);
|
296 | 54936004 | bellard | } |
297 | d691f669 | bellard | } else {
|
298 | d691f669 | bellard | usage(); |
299 | d691f669 | bellard | } |
300 | 586314f2 | bellard | } |
301 | d691f669 | bellard | if (optind >= argc)
|
302 | d691f669 | bellard | usage(); |
303 | 586314f2 | bellard | filename = argv[optind]; |
304 | 586314f2 | bellard | |
305 | 586314f2 | bellard | /* init debug */
|
306 | 586314f2 | bellard | if (loglevel) {
|
307 | 586314f2 | bellard | logfile = fopen(DEBUG_LOGFILE, "w");
|
308 | 586314f2 | bellard | if (!logfile) {
|
309 | 586314f2 | bellard | perror(DEBUG_LOGFILE); |
310 | 74cd30b8 | bellard | _exit(1);
|
311 | 586314f2 | bellard | } |
312 | 586314f2 | bellard | setvbuf(logfile, NULL, _IOLBF, 0); |
313 | 586314f2 | bellard | } |
314 | 31e31b8a | bellard | |
315 | 31e31b8a | bellard | /* Zero out regs */
|
316 | 01ffc75b | bellard | memset(regs, 0, sizeof(struct target_pt_regs)); |
317 | 31e31b8a | bellard | |
318 | 31e31b8a | bellard | /* Zero out image_info */
|
319 | 31e31b8a | bellard | memset(info, 0, sizeof(struct image_info)); |
320 | 31e31b8a | bellard | |
321 | 74cd30b8 | bellard | /* Scan interp_prefix dir for replacement files. */
|
322 | 74cd30b8 | bellard | init_paths(interp_prefix); |
323 | 74cd30b8 | bellard | |
324 | 54936004 | bellard | /* NOTE: we need to init the CPU at this stage to get the
|
325 | 54936004 | bellard | host_page_size */
|
326 | 54936004 | bellard | env = cpu_x86_init(); |
327 | 54936004 | bellard | |
328 | 74cd30b8 | bellard | if (elf_exec(filename, argv+optind, environ, regs, info) != 0) { |
329 | 31e31b8a | bellard | printf("Error loading %s\n", filename);
|
330 | 74cd30b8 | bellard | _exit(1);
|
331 | 31e31b8a | bellard | } |
332 | 31e31b8a | bellard | |
333 | 4b74fe1f | bellard | if (loglevel) {
|
334 | 54936004 | bellard | page_dump(logfile); |
335 | 54936004 | bellard | |
336 | 4b74fe1f | bellard | fprintf(logfile, "start_brk 0x%08lx\n" , info->start_brk);
|
337 | 4b74fe1f | bellard | fprintf(logfile, "end_code 0x%08lx\n" , info->end_code);
|
338 | 4b74fe1f | bellard | fprintf(logfile, "start_code 0x%08lx\n" , info->start_code);
|
339 | 4b74fe1f | bellard | fprintf(logfile, "end_data 0x%08lx\n" , info->end_data);
|
340 | 4b74fe1f | bellard | fprintf(logfile, "start_stack 0x%08lx\n" , info->start_stack);
|
341 | 4b74fe1f | bellard | fprintf(logfile, "brk 0x%08lx\n" , info->brk);
|
342 | 4b74fe1f | bellard | fprintf(logfile, "esp 0x%08lx\n" , regs->esp);
|
343 | 4b74fe1f | bellard | fprintf(logfile, "eip 0x%08lx\n" , regs->eip);
|
344 | 4b74fe1f | bellard | } |
345 | 31e31b8a | bellard | |
346 | 31e31b8a | bellard | target_set_brk((char *)info->brk);
|
347 | 31e31b8a | bellard | syscall_init(); |
348 | 66fb9763 | bellard | signal_init(); |
349 | 31e31b8a | bellard | |
350 | 9de5e440 | bellard | global_env = env; |
351 | 0ecfa993 | bellard | |
352 | 851e67a1 | bellard | /* build Task State */
|
353 | 851e67a1 | bellard | memset(ts, 0, sizeof(TaskState)); |
354 | 851e67a1 | bellard | env->opaque = ts; |
355 | 851e67a1 | bellard | ts->used = 1;
|
356 | 851e67a1 | bellard | |
357 | 6dbad63e | bellard | /* linux register setup */
|
358 | 0ecfa993 | bellard | env->regs[R_EAX] = regs->eax; |
359 | 0ecfa993 | bellard | env->regs[R_EBX] = regs->ebx; |
360 | 0ecfa993 | bellard | env->regs[R_ECX] = regs->ecx; |
361 | 0ecfa993 | bellard | env->regs[R_EDX] = regs->edx; |
362 | 0ecfa993 | bellard | env->regs[R_ESI] = regs->esi; |
363 | 0ecfa993 | bellard | env->regs[R_EDI] = regs->edi; |
364 | 0ecfa993 | bellard | env->regs[R_EBP] = regs->ebp; |
365 | 0ecfa993 | bellard | env->regs[R_ESP] = regs->esp; |
366 | dab2ed99 | bellard | env->eip = regs->eip; |
367 | 31e31b8a | bellard | |
368 | 6dbad63e | bellard | /* linux segment setup */
|
369 | 6dbad63e | bellard | env->gdt.base = (void *)gdt_table;
|
370 | 6dbad63e | bellard | env->gdt.limit = sizeof(gdt_table) - 1; |
371 | 6dbad63e | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xffffffff, 1); |
372 | 6dbad63e | bellard | write_dt(&gdt_table[__USER_DS >> 3], 0, 0xffffffff, 1); |
373 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
374 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
375 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
376 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
377 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_FS, __USER_DS); |
378 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_GS, __USER_DS); |
379 | 31e31b8a | bellard | |
380 | 1b6b029e | bellard | cpu_loop(env); |
381 | 1b6b029e | bellard | /* never exits */
|
382 | 31e31b8a | bellard | return 0; |
383 | 31e31b8a | bellard | } |