ia64/xen-unstable

view tools/ioemu/main.c @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 8e5fc5fe636c
children
line source
1 /*
2 * qemu user main
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <unistd.h>
27 #include "qemu.h"
29 #define DEBUG_LOGFILE "/tmp/qemu.log"
31 #ifdef __APPLE__
32 #include <crt_externs.h>
33 # define environ (*_NSGetEnviron())
34 #endif
36 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
38 #if defined(__i386__) && !defined(CONFIG_STATIC)
39 /* Force usage of an ELF interpreter even if it is an ELF shared
40 object ! */
41 const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
42 #endif
44 /* for recent libc, we add these dummy symbols which are not declared
45 when generating a linked object (bug in ld ?) */
46 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined(CONFIG_STATIC)
47 long __preinit_array_start[0];
48 long __preinit_array_end[0];
49 long __init_array_start[0];
50 long __init_array_end[0];
51 long __fini_array_start[0];
52 long __fini_array_end[0];
53 #endif
55 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
56 we allocate a bigger stack. Need a better solution, for example
57 by remapping the process stack directly at the right place */
58 unsigned long x86_stack_size = 512 * 1024;
60 void gemu_log(const char *fmt, ...)
61 {
62 va_list ap;
64 va_start(ap, fmt);
65 vfprintf(stderr, fmt, ap);
66 va_end(ap);
67 }
68 /* timers for rdtsc */
70 #if defined(__i386__)
72 int64_t cpu_get_real_ticks(void)
73 {
74 int64_t val;
75 asm volatile ("rdtsc" : "=A" (val));
76 return val;
77 }
79 #elif defined(__x86_64__)
81 int64_t cpu_get_real_ticks(void)
82 {
83 uint32_t low,high;
84 int64_t val;
85 asm volatile("rdtsc" : "=a" (low), "=d" (high));
86 val = high;
87 val <<= 32;
88 val |= low;
89 return val;
90 }
92 #else
94 static uint64_t emu_time;
96 int64_t cpu_get_real_ticks(void)
97 {
98 return emu_time++;
99 }
101 #endif
103 #ifdef TARGET_I386
104 /***********************************************************/
105 /* CPUX86 core interface */
107 uint64_t cpu_get_tsc(CPUX86State *env)
108 {
109 return cpu_get_real_ticks();
110 }
112 void cpu_loop()
113 {
114 }
115 #endif
117 void usage(void)
118 {
119 printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2004 Fabrice Bellard\n"
120 "usage: qemu-" TARGET_ARCH " [-h] [-d opts] [-L path] [-s size] program [arguments...]\n"
121 "Linux CPU emulator (compiled for %s emulation)\n"
122 "\n"
123 "-h print this help\n"
124 "-L path set the elf interpreter prefix (default=%s)\n"
125 "-s size set the stack size in bytes (default=%ld)\n"
126 "\n"
127 "debug options:\n"
128 #ifdef USE_CODE_COPY
129 "-no-code-copy disable code copy acceleration\n"
130 #endif
131 "-l options activate log (logfile=%s)\n"
132 "-p xen port number\n",
133 "-d xen domain id\n",
134 TARGET_ARCH,
135 interp_prefix,
136 x86_stack_size,
137 DEBUG_LOGFILE);
138 _exit(1);
139 }
141 /* XXX: currently only used for async signals (see signal.c) */
142 CPUState *global_env;
143 /* used only if single thread */
144 CPUState *cpu_single_env = NULL;
146 /* used to free thread contexts */
147 TaskState *first_task_state;
149 int main(int argc, char **argv)
150 {
151 const char *filename;
152 struct target_pt_regs regs1, *regs = &regs1;
153 struct image_info info1, *info = &info1;
154 TaskState ts1, *ts = &ts1;
155 CPUState *env;
156 int optind;
157 const char *r;
159 if (argc <= 1)
160 usage();
162 /* init debug */
163 cpu_set_log_filename(DEBUG_LOGFILE);
164 cpu_set_log(0);
166 optind = 1;
167 for(;;) {
168 if (optind >= argc)
169 break;
170 r = argv[optind];
171 if (r[0] != '-')
172 break;
173 optind++;
174 r++;
175 if (!strcmp(r, "-")) {
176 break;
177 } else if (!strcmp(r, "l")) {
178 int mask;
179 CPULogItem *item;
181 if (optind >= argc)
182 break;
184 r = argv[optind++];
185 mask = cpu_str_to_log_mask(r);
186 if (!mask) {
187 printf("Log items (comma separated):\n");
188 for(item = cpu_log_items; item->mask != 0; item++) {
189 printf("%-10s %s\n", item->name, item->help);
190 }
191 exit(1);
192 }
193 cpu_set_log(mask);
194 } else if (!strcmp(r, "s")) {
195 r = argv[optind++];
196 x86_stack_size = strtol(r, (char **)&r, 0);
197 if (x86_stack_size <= 0)
198 usage();
199 if (*r == 'M')
200 x86_stack_size *= 1024 * 1024;
201 else if (*r == 'k' || *r == 'K')
202 x86_stack_size *= 1024;
203 } else if (!strcmp(r, "L")) {
204 interp_prefix = argv[optind++];
205 } else if (!strcmp(r, "p")) {
206 qemu_host_page_size = atoi(argv[optind++]);
207 if (qemu_host_page_size == 0 ||
208 (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
209 fprintf(stderr, "page size must be a power of two\n");
210 exit(1);
211 }
212 } else
213 #ifdef USE_CODE_COPY
214 if (!strcmp(r, "no-code-copy")) {
215 code_copy_enabled = 0;
216 } else
217 #endif
218 {
219 usage();
220 }
221 }
222 if (optind >= argc)
223 usage();
224 filename = argv[optind];
226 /* Zero out regs */
227 memset(regs, 0, sizeof(struct target_pt_regs));
229 /* Zero out image_info */
230 memset(info, 0, sizeof(struct image_info));
232 /* Scan interp_prefix dir for replacement files. */
233 init_paths(interp_prefix);
235 /* NOTE: we need to init the CPU at this stage to get
236 qemu_host_page_size */
237 env = cpu_init();
239 global_env = env;
241 /* build Task State */
242 memset(ts, 0, sizeof(TaskState));
243 env->opaque = ts;
244 ts->used = 1;
245 env->user_mode_only = 1;
247 cpu_loop(env);
248 /* never exits */
249 return 0;
250 }