63 |
#define INITRD_LOAD_ADDR 0x00400000 |
#define INITRD_LOAD_ADDR 0x00400000 |
64 |
#define KERNEL_PARAMS_ADDR 0x00090000 |
#define KERNEL_PARAMS_ADDR 0x00090000 |
65 |
|
|
66 |
|
#define MAX_DISKS 2 |
67 |
|
|
68 |
/* from plex86 (BSD license) */ |
/* from plex86 (BSD license) */ |
69 |
struct __attribute__ ((packed)) linux_params { |
struct __attribute__ ((packed)) linux_params { |
70 |
// For 0x00..0x3f, see 'struct screen_info' in linux/include/linux/tty.h. |
// For 0x00..0x3f, see 'struct screen_info' in linux/include/linux/tty.h. |
192 |
int loglevel; |
int loglevel; |
193 |
IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; |
IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; |
194 |
IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; |
IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; |
195 |
|
BlockDriverState *bs_table[MAX_DISKS]; |
196 |
|
|
197 |
/***********************************************************/ |
/***********************************************************/ |
198 |
/* x86 io ports */ |
/* x86 io ports */ |
1268 |
printf("\n" |
printf("\n" |
1269 |
"C-a h print this help\n" |
"C-a h print this help\n" |
1270 |
"C-a x exit emulatior\n" |
"C-a x exit emulatior\n" |
1271 |
|
"C-a s save disk data back to file (if -snapshot)\n" |
1272 |
"C-a b send break (magic sysrq)\n" |
"C-a b send break (magic sysrq)\n" |
1273 |
"C-a C-a send C-a\n" |
"C-a C-a send C-a\n" |
1274 |
); |
); |
1286 |
case 'x': |
case 'x': |
1287 |
exit(0); |
exit(0); |
1288 |
break; |
break; |
1289 |
|
case 's': |
1290 |
|
{ |
1291 |
|
int i; |
1292 |
|
for (i = 0; i < MAX_DISKS; i++) { |
1293 |
|
if (bs_table[i]) |
1294 |
|
bdrv_commit(bs_table[i]); |
1295 |
|
} |
1296 |
|
} |
1297 |
|
break; |
1298 |
case 'b': |
case 'b': |
1299 |
/* send break */ |
/* send break */ |
1300 |
s->rbr = 0; |
s->rbr = 0; |
1989 |
/* set to 1 set disable mult support */ |
/* set to 1 set disable mult support */ |
1990 |
#define MAX_MULT_SECTORS 8 |
#define MAX_MULT_SECTORS 8 |
1991 |
|
|
|
#define MAX_DISKS 2 |
|
|
|
|
1992 |
struct IDEState; |
struct IDEState; |
1993 |
|
|
1994 |
typedef void EndTransferFunc(struct IDEState *); |
typedef void EndTransferFunc(struct IDEState *); |
2020 |
uint8_t io_buffer[MAX_MULT_SECTORS*512 + 4]; |
uint8_t io_buffer[MAX_MULT_SECTORS*512 + 4]; |
2021 |
} IDEState; |
} IDEState; |
2022 |
|
|
|
BlockDriverState *bs_table[MAX_DISKS]; |
|
2023 |
IDEState ide_state[MAX_DISKS]; |
IDEState ide_state[MAX_DISKS]; |
2024 |
|
|
2025 |
static void padstr(char *str, const char *src, int len) |
static void padstr(char *str, const char *src, int len) |
2523 |
} |
} |
2524 |
} |
} |
2525 |
|
|
2526 |
|
unsigned long mmap_addr = PHYS_RAM_BASE; |
2527 |
|
|
2528 |
|
void *get_mmap_addr(unsigned long size) |
2529 |
|
{ |
2530 |
|
unsigned long addr; |
2531 |
|
addr = mmap_addr; |
2532 |
|
mmap_addr += ((size + 4095) & ~4095) + 4096; |
2533 |
|
return (void *)addr; |
2534 |
|
} |
2535 |
|
|
2536 |
/* main execution loop */ |
/* main execution loop */ |
2537 |
|
|
2538 |
CPUState *cpu_gdbstub_get_env(void *opaque) |
CPUState *cpu_gdbstub_get_env(void *opaque) |
2632 |
"-initrd file use 'file' as initial ram disk\n" |
"-initrd file use 'file' as initial ram disk\n" |
2633 |
"-hda file use 'file' as hard disk 0 image\n" |
"-hda file use 'file' as hard disk 0 image\n" |
2634 |
"-hdb file use 'file' as hard disk 1 image\n" |
"-hdb file use 'file' as hard disk 1 image\n" |
2635 |
|
"-snapshot write to temporary files instead of disk image files\n" |
2636 |
"-m megs set virtual RAM size to megs MB\n" |
"-m megs set virtual RAM size to megs MB\n" |
2637 |
"-n script set network init script [default=%s]\n" |
"-n script set network init script [default=%s]\n" |
2638 |
"\n" |
"\n" |
2651 |
{ "initrd", 1, NULL, 0, }, |
{ "initrd", 1, NULL, 0, }, |
2652 |
{ "hda", 1, NULL, 0, }, |
{ "hda", 1, NULL, 0, }, |
2653 |
{ "hdb", 1, NULL, 0, }, |
{ "hdb", 1, NULL, 0, }, |
2654 |
|
{ "snapshot", 0, NULL, 0, }, |
2655 |
{ NULL, 0, NULL, 0 }, |
{ NULL, 0, NULL, 0 }, |
2656 |
}; |
}; |
2657 |
|
|
2658 |
int main(int argc, char **argv) |
int main(int argc, char **argv) |
2659 |
{ |
{ |
2660 |
int c, ret, initrd_size, i, use_gdbstub, gdbstub_port, long_index; |
int c, ret, initrd_size, i, use_gdbstub, gdbstub_port, long_index; |
2661 |
|
int snapshot; |
2662 |
struct linux_params *params; |
struct linux_params *params; |
2663 |
struct sigaction act; |
struct sigaction act; |
2664 |
struct itimerval itv; |
struct itimerval itv; |
2675 |
pstrcpy(network_script, sizeof(network_script), DEFAULT_NETWORK_SCRIPT); |
pstrcpy(network_script, sizeof(network_script), DEFAULT_NETWORK_SCRIPT); |
2676 |
use_gdbstub = 0; |
use_gdbstub = 0; |
2677 |
gdbstub_port = DEFAULT_GDBSTUB_PORT; |
gdbstub_port = DEFAULT_GDBSTUB_PORT; |
2678 |
|
snapshot = 0; |
2679 |
for(;;) { |
for(;;) { |
2680 |
c = getopt_long_only(argc, argv, "hm:dn:sp:", long_options, &long_index); |
c = getopt_long_only(argc, argv, "hm:dn:sp:", long_options, &long_index); |
2681 |
if (c == -1) |
if (c == -1) |
2692 |
case 2: |
case 2: |
2693 |
hd_filename[1] = optarg; |
hd_filename[1] = optarg; |
2694 |
break; |
break; |
2695 |
|
case 3: |
2696 |
|
snapshot = 1; |
2697 |
|
break; |
2698 |
} |
} |
2699 |
break; |
break; |
2700 |
case 'h': |
case 'h': |
2738 |
setvbuf(logfile, NULL, _IOLBF, 0); |
setvbuf(logfile, NULL, _IOLBF, 0); |
2739 |
} |
} |
2740 |
|
|
|
/* open the virtual block devices */ |
|
|
for(i = 0; i < MAX_DISKS; i++) { |
|
|
if (hd_filename[i]) { |
|
|
bs_table[i] = bdrv_open(hd_filename[i]); |
|
|
if (!bs_table[i]) { |
|
|
fprintf(stderr, "vl: could not open hard disk image '%s\n", |
|
|
hd_filename[i]); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
2741 |
/* init network tun interface */ |
/* init network tun interface */ |
2742 |
net_init(); |
net_init(); |
2743 |
|
|
2759 |
} |
} |
2760 |
ftruncate(phys_ram_fd, phys_ram_size); |
ftruncate(phys_ram_fd, phys_ram_size); |
2761 |
unlink(phys_ram_file); |
unlink(phys_ram_file); |
2762 |
phys_ram_base = mmap((void *)PHYS_RAM_BASE, phys_ram_size, |
phys_ram_base = mmap(get_mmap_addr(phys_ram_size), phys_ram_size, |
2763 |
PROT_WRITE | PROT_READ, MAP_SHARED | MAP_FIXED, |
PROT_WRITE | PROT_READ, MAP_SHARED | MAP_FIXED, |
2764 |
phys_ram_fd, 0); |
phys_ram_fd, 0); |
2765 |
if (phys_ram_base == MAP_FAILED) { |
if (phys_ram_base == MAP_FAILED) { |
2767 |
exit(1); |
exit(1); |
2768 |
} |
} |
2769 |
|
|
2770 |
|
/* open the virtual block devices */ |
2771 |
|
for(i = 0; i < MAX_DISKS; i++) { |
2772 |
|
if (hd_filename[i]) { |
2773 |
|
bs_table[i] = bdrv_open(hd_filename[i], snapshot); |
2774 |
|
if (!bs_table[i]) { |
2775 |
|
fprintf(stderr, "vl: could not open hard disk image '%s\n", |
2776 |
|
hd_filename[i]); |
2777 |
|
exit(1); |
2778 |
|
} |
2779 |
|
} |
2780 |
|
} |
2781 |
|
|
2782 |
/* now we can load the kernel */ |
/* now we can load the kernel */ |
2783 |
ret = load_kernel(argv[optind], phys_ram_base + KERNEL_LOAD_ADDR); |
ret = load_kernel(argv[optind], phys_ram_base + KERNEL_LOAD_ADDR); |
2784 |
if (ret < 0) { |
if (ret < 0) { |