10 #define die(x) { perror(x); exit(1); }
11 #define warn(x) { perror(x); }
13 #include <x86emu/x86emu.h>
14 #include "helper_exec.h"
16 #include "pci-userspace.h"
18 void x86emu_dump_xregs(void);
19 int int15_handler(void);
20 int int16_handler(void);
21 int int1A_handler(void);
23 int int42_handler(void);
25 int intE6_handler(void);
29 unsigned short get_device(char *arg_val);
31 extern int teststart, testend;
35 unsigned char biosmem[1024 * 1024];
40 /* Interrupt multiplexer */
46 printf("int%x vector at %x\n", num, getIntVect(num));
48 /* This is a pInt leftover */
57 if (getIntVect(num) == 0xFF065) {
58 ret = int42_handler();
63 ret = int15_handler();
66 ret = int16_handler();
69 ret = int1A_handler();
72 ret = intE6_handler();
79 ret = run_bios_int(num);
82 printf("\nint%x: not implemented\n", num);
83 //x86emu_dump_xregs();
87 unsigned char *mapitin(char *file, off_t where, size_t size)
91 int fd = open(file, O_RDWR, 0);
95 z = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, where);
106 void x_outb(u16 port, u8 val);
107 void x_outw(u16 port, u16 val);
109 void x_outl(u16 port, u32 val);
112 X86EMU_pioFuncs myfuncs = {
114 x_outb, x_outw, x_outl
118 void usage(char *name)
121 ("Usage: %s [-c codesegment] [-s size] [-b base] [-i ip] [-t] <filename> ... \n",
125 int main(int argc, char **argv)
134 int have_size = 0, have_base = 0, have_ip = 0, have_cs = 0;
138 unsigned char *fsegptr;
139 unsigned short initialip = 0, initialcs = 0, devfn = 0;
140 X86EMU_intrFuncs intFuncs[256];
141 void X86EMU_setMemBase(void *base, size_t size);
142 void x86emu_dump_xregs(void);
143 int X86EMU_set_debug(int debug);
146 const char *optstring = "vh?b:i:c:s:tpd:";
148 int option_index = 0;
149 static struct option long_options[] = {
150 {"verbose", 0, 0, 'v'},
152 {"trace", 0, 0, 't'},
155 {"instructionpointer", 1, 0, 'i'},
156 {"codesegment", 1, 0, 'c'},
157 {"absegment", 1, 0, 'a'},
159 {"parserom", 0, 0, 'p'},
160 {"device", 1, 0, 'd'},
161 {"debug", 1, 0, 'D'},
164 c = getopt_long(argc, argv, optstring, long_options, &option_index);
179 base = strtol(optarg, 0, 0);
183 initialip = strtol(optarg, 0, 0);
187 initialcs = strtol(optarg, 0, 0);
191 size = strtol(optarg, 0, 0);
195 printf("Parsing rom images not implemented.\n");
205 devfn = get_device(optarg);
209 debugflag = strtol(optarg, 0, 0);
212 printf("Unknown option \n");
218 if (optind >= argc) {
219 printf("Filename missing.\n");
224 while (optind < argc) {
225 printf("running file %s\n", argv[optind]);
226 filename = argv[optind];
228 /* normally we would do continue, but for
229 * now only one filename is supported.
236 printf("No size specified. defaulting to 32k\n");
240 printf("No base specified. defaulting to 0xc0000\n");
244 printf("No initial code segment specified. defaulting to 0xc000\n");
249 ("No initial instruction pointer specified. defaulting to 0x0003\n");
253 //printf("Point 1 int%x vector at %x\n", 0x42, getIntVect(0x42));
255 if (initialip == 0x0003) {
256 if ((devfn == 0) || (have_devfn == 0)) {
257 printf("WARNING! It appears you are trying to run an option ROM.\n");
258 printf(" (initial ip = 0x0003)\n");
260 printf(" However, the device you have specified is 0x00\n");
261 printf(" It is very unlikely that your device is at this address\n");
262 printf(" Please check your -d option\n");
265 printf(" Please specify a device with -d\n");
266 printf(" The default is not likely to work\n");
272 abseg = mapitin(absegname, (off_t) 0xa0000, 0x20000);
278 X86EMU_setMemBase(biosmem, sizeof(biosmem));
279 M.abseg = (unsigned long)abseg;
280 X86EMU_setupPioFuncs(&myfuncs);
284 warn("iopl failed, continuing anyway");
287 /* Emergency sync ;-) */
291 /* Setting up interrupt environment.
292 * basically this means initializing PCI and
297 for (i = 0; i < 256; i++)
298 intFuncs[i] = do_int;
299 X86EMU_setupIntrFuncs(intFuncs);
300 cp = mapitin(filename, (off_t) 0, size);
303 printf("Loading ax with BusDevFn = %x\n",devfn);
306 current->ax = devfn ? devfn : 0xff;
309 for (i = 0; i < size; i++)
310 wrb(base + i, cp[i]);
313 fsegptr = mapitin(fsegname, (off_t) 0, 0x10000);
314 for (i = 0; i < 0x10000; i++)
315 wrb(0xf0000 + i, fsegptr[i]);
317 char *date = "01/01/99";
318 for (i = i; date[i]; i++)
319 wrb(0xffff5 + i, date[i]);
324 X86_AX = devfn ? devfn : 0xff;
329 /* Initialize stack and data segment */
333 /* We need a sane way to return from bios
334 * execution. A hlt instruction and a pointer
335 * to it, both kept on the stack, will do.
337 pushw(0xf4f4); /* hlt; hlt */
344 printf("Switching to single step mode.\n");
348 //X86EMU_set_debug(debugflag);
357 unsigned short get_device(char *arg_val)
359 unsigned short devfn=0;
360 long bus=0,dev=0,fn=0,need_pack=0;
363 tok = strsep(&arg_val,":");
364 if (arg_val != NULL) {
365 bus = strtol(tok,0,16);
372 tok = strsep(&arg_val,".");
373 if (arg_val != NULL) {
374 dev = strtol(tok,0,16);
375 fn = strtol(arg_val,0,16);
379 if (need_pack ==1 && (strlen(tok))) {
380 dev = strtol(tok,0,16);
384 if ( need_pack == 1) {
385 devfn = bus<<8 | (dev<<3) | fn;
388 devfn = strtol(tok, 0, 0);