Revision b41a2cd1 hw/pc.c
b/hw/pc.c | ||
---|---|---|
43 | 43 |
#include "cpu.h" |
44 | 44 |
#include "vl.h" |
45 | 45 |
|
46 |
/* output Bochs bios info messages */ |
|
47 |
//#define DEBUG_BIOS |
|
48 |
|
|
46 | 49 |
#define BIOS_FILENAME "bios.bin" |
47 | 50 |
#define VGABIOS_FILENAME "vgabios.bin" |
48 | 51 |
#define LINUX_BOOT_FILENAME "linux_boot.bin" |
... | ... | |
55 | 58 |
int speaker_data_on; |
56 | 59 |
int dummy_refresh_clock; |
57 | 60 |
|
58 |
static void ioport80_write(CPUState *env, uint32_t addr, uint32_t data)
|
|
61 |
static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
|
|
59 | 62 |
{ |
60 | 63 |
} |
61 | 64 |
|
... | ... | |
65 | 68 |
{ |
66 | 69 |
RTCState *s = &rtc_state; |
67 | 70 |
int val; |
71 |
int fd0, fd1, nb; |
|
68 | 72 |
|
69 | 73 |
/* various important CMOS locations needed by PC/Bochs bios */ |
70 | 74 |
|
... | ... | |
99 | 103 |
s->cmos_data[0x3d] = 0x03; /* CD-ROM boot */ |
100 | 104 |
break; |
101 | 105 |
} |
102 |
} |
|
103 | 106 |
|
104 |
void cmos_register_fd (uint8_t fd0, uint8_t fd1)
|
|
105 |
{ |
|
106 |
RTCState *s = &rtc_state;
|
|
107 |
int nb = 0;
|
|
107 |
/* floppy type */
|
|
108 |
|
|
109 |
fd0 = fdctrl_get_drive_type(0);
|
|
110 |
fd1 = fdctrl_get_drive_type(1);
|
|
108 | 111 |
|
109 | 112 |
s->cmos_data[0x10] = 0; |
110 | 113 |
switch (fd0) { |
... | ... | |
135 | 138 |
s->cmos_data[0x10] |= 0x02; |
136 | 139 |
break; |
137 | 140 |
} |
141 |
nb = 0; |
|
138 | 142 |
if (fd0 < 3) |
139 | 143 |
nb++; |
140 | 144 |
if (fd1 < 3) |
... | ... | |
151 | 155 |
} |
152 | 156 |
} |
153 | 157 |
|
154 |
void speaker_ioport_write(CPUState *env, uint32_t addr, uint32_t val)
|
|
158 |
static void speaker_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
|
155 | 159 |
{ |
156 | 160 |
speaker_data_on = (val >> 1) & 1; |
157 | 161 |
pit_set_gate(&pit_channels[2], val & 1); |
158 | 162 |
} |
159 | 163 |
|
160 |
uint32_t speaker_ioport_read(CPUState *env, uint32_t addr)
|
|
164 |
static uint32_t speaker_ioport_read(void *opaque, uint32_t addr)
|
|
161 | 165 |
{ |
162 | 166 |
int out; |
163 | 167 |
out = pit_get_out(&pit_channels[2]); |
... | ... | |
167 | 171 |
} |
168 | 172 |
|
169 | 173 |
/***********************************************************/ |
170 |
/* PC floppy disk controler emulation glue */ |
|
171 |
#define PC_FDC_DMA 0x2 |
|
172 |
#define PC_FDC_IRQ 0x6 |
|
173 |
#define PC_FDC_BASE 0x3F0 |
|
174 |
|
|
175 |
static void fdctrl_register (unsigned char **disknames, int ro, |
|
176 |
char boot_device) |
|
177 |
{ |
|
178 |
int i; |
|
179 |
|
|
180 |
fdctrl_init(PC_FDC_IRQ, PC_FDC_DMA, 0, PC_FDC_BASE, boot_device); |
|
181 |
for (i = 0; i < MAX_FD; i++) { |
|
182 |
if (disknames[i] != NULL) |
|
183 |
fdctrl_disk_change(i, disknames[i], ro); |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
/***********************************************************/ |
|
188 | 174 |
/* Bochs BIOS debug ports */ |
189 | 175 |
|
190 |
void bochs_bios_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
|
176 |
void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
|
|
191 | 177 |
{ |
192 | 178 |
switch(addr) { |
193 | 179 |
/* Bochs BIOS messages */ |
... | ... | |
218 | 204 |
|
219 | 205 |
void bochs_bios_init(void) |
220 | 206 |
{ |
221 |
register_ioport_write(0x400, 1, bochs_bios_write, 2);
|
|
222 |
register_ioport_write(0x401, 1, bochs_bios_write, 2);
|
|
223 |
register_ioport_write(0x402, 1, bochs_bios_write, 1);
|
|
224 |
register_ioport_write(0x403, 1, bochs_bios_write, 1);
|
|
225 |
|
|
226 |
register_ioport_write(0x501, 1, bochs_bios_write, 2);
|
|
227 |
register_ioport_write(0x502, 1, bochs_bios_write, 2);
|
|
228 |
register_ioport_write(0x500, 1, bochs_bios_write, 1);
|
|
229 |
register_ioport_write(0x503, 1, bochs_bios_write, 1);
|
|
207 |
register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL);
|
|
208 |
register_ioport_write(0x401, 1, 2, bochs_bios_write, NULL);
|
|
209 |
register_ioport_write(0x402, 1, 1, bochs_bios_write, NULL);
|
|
210 |
register_ioport_write(0x403, 1, 1, bochs_bios_write, NULL);
|
|
211 |
|
|
212 |
register_ioport_write(0x501, 1, 2, bochs_bios_write, NULL);
|
|
213 |
register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL);
|
|
214 |
register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
|
|
215 |
register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
|
|
230 | 216 |
} |
231 | 217 |
|
232 | 218 |
|
... | ... | |
261 | 247 |
return -1; |
262 | 248 |
} |
263 | 249 |
|
250 |
static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
|
251 |
static const int ide_iobase2[2] = { 0x3f6, 0x376 }; |
|
252 |
static const int ide_irq[2] = { 14, 15 }; |
|
253 |
|
|
254 |
#define NE2000_NB_MAX 6 |
|
255 |
|
|
256 |
static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 }; |
|
257 |
static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 }; |
|
258 |
|
|
264 | 259 |
/* PC hardware initialisation */ |
265 | 260 |
void pc_init(int ram_size, int vga_ram_size, int boot_device, |
266 | 261 |
DisplayState *ds, const char **fd_filename, int snapshot, |
... | ... | |
268 | 263 |
const char *initrd_filename) |
269 | 264 |
{ |
270 | 265 |
char buf[1024]; |
271 |
int ret, linux_boot, initrd_size; |
|
266 |
int ret, linux_boot, initrd_size, i, nb_nics1, fd;
|
|
272 | 267 |
|
273 | 268 |
linux_boot = (kernel_filename != NULL); |
274 | 269 |
|
... | ... | |
344 | 339 |
} |
345 | 340 |
|
346 | 341 |
/* init basic PC hardware */ |
347 |
register_ioport_write(0x80, 1, ioport80_write, 1);
|
|
342 |
register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
|
|
348 | 343 |
|
349 | 344 |
vga_initialize(ds, phys_ram_base + ram_size, ram_size, |
350 | 345 |
vga_ram_size); |
351 | 346 |
|
352 | 347 |
rtc_init(0x70, 8); |
353 |
cmos_init(ram_size, boot_device); |
|
354 |
register_ioport_read(0x61, 1, speaker_ioport_read, 1); |
|
355 |
register_ioport_write(0x61, 1, speaker_ioport_write, 1); |
|
348 |
register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL); |
|
349 |
register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL); |
|
356 | 350 |
|
357 | 351 |
pic_init(); |
358 |
pit_init(); |
|
359 |
serial_init(0x3f8, 4); |
|
360 |
ne2000_init(0x300, 9); |
|
361 |
ide_init(); |
|
352 |
pit_init(0x40); |
|
353 |
|
|
354 |
fd = serial_open_device(); |
|
355 |
serial_init(0x3f8, 4, fd); |
|
356 |
|
|
357 |
nb_nics1 = nb_nics; |
|
358 |
if (nb_nics1 > NE2000_NB_MAX) |
|
359 |
nb_nics1 = NE2000_NB_MAX; |
|
360 |
for(i = 0; i < nb_nics1; i++) { |
|
361 |
ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]); |
|
362 |
} |
|
363 |
|
|
364 |
for(i = 0; i < 2; i++) { |
|
365 |
ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], |
|
366 |
bs_table[2 * i], bs_table[2 * i + 1]); |
|
367 |
} |
|
362 | 368 |
kbd_init(); |
363 | 369 |
AUD_init(); |
364 | 370 |
DMA_init(); |
365 | 371 |
SB16_init(); |
366 | 372 |
|
367 |
fdctrl_register((unsigned char **)fd_filename, snapshot, boot_device); |
|
373 |
fdctrl_init(6, 2, 0, 0x3f0, fd_table); |
|
374 |
|
|
375 |
cmos_init(ram_size, boot_device); |
|
368 | 376 |
} |
Also available in: Unified diff