pc: Factor common code out of pc_boot_set() and cmos_init()

Code duplicated in commit 0ecdffbb.  The two versions are similar, but
not identical:

* cmos_init() reports errors to stderr, pc_boot_set() via
  qemu_error().  The latter is fine for both, so pick that for the
  common code.

* cmos_init() obeys fd_bootchk, pc_boot_set() ignores it.  Make it a
  parameter of the common code.
This commit is contained in:
Markus Armbruster 2010-02-17 18:07:48 +01:00
parent 8ad00f8425
commit d9346e81de

28
hw/pc.c
View File

@ -230,12 +230,9 @@ static int boot_device2nibble(char boot_device)
return 0; return 0;
} }
/* copy/pasted from cmos_init, should be made a general function static int set_boot_dev(RTCState *s, const char *boot_device, int fd_bootchk)
and used there as well */
static int pc_boot_set(void *opaque, const char *boot_device)
{ {
#define PC_MAX_BOOT_DEVICES 3 #define PC_MAX_BOOT_DEVICES 3
RTCState *s = (RTCState *)opaque;
int nbds, bds[3] = { 0, }; int nbds, bds[3] = { 0, };
int i; int i;
@ -253,16 +250,20 @@ static int pc_boot_set(void *opaque, const char *boot_device)
} }
} }
rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]); rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
rtc_set_memory(s, 0x38, (bds[2] << 4)); rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1));
return(0); return(0);
} }
static int pc_boot_set(void *opaque, const char *boot_device)
{
return set_boot_dev(opaque, boot_device, 0);
}
/* hd_table must contain 4 block drivers */ /* hd_table must contain 4 block drivers */
static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
const char *boot_device, DriveInfo **hd_table) const char *boot_device, DriveInfo **hd_table)
{ {
RTCState *s = rtc_state; RTCState *s = rtc_state;
int nbds, bds[3] = { 0, };
int val; int val;
int fd0, fd1, nb; int fd0, fd1, nb;
int i; int i;
@ -301,22 +302,9 @@ static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
rtc_set_memory(s, 0x5f, smp_cpus - 1); rtc_set_memory(s, 0x5f, smp_cpus - 1);
/* set boot devices, and disable floppy signature check if requested */ /* set boot devices, and disable floppy signature check if requested */
#define PC_MAX_BOOT_DEVICES 3 if (set_boot_dev(s, boot_device, fd_bootchk)) {
nbds = strlen(boot_device);
if (nbds > PC_MAX_BOOT_DEVICES) {
fprintf(stderr, "Too many boot devices for PC\n");
exit(1); exit(1);
} }
for (i = 0; i < nbds; i++) {
bds[i] = boot_device2nibble(boot_device[i]);
if (bds[i] == 0) {
fprintf(stderr, "Invalid boot device for PC: '%c'\n",
boot_device[i]);
exit(1);
}
}
rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1));
/* floppy type */ /* floppy type */