summaryrefslogtreecommitdiff
path: root/hw/pc.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2010-02-17 18:07:48 +0100
committerMarkus Armbruster <armbru@redhat.com>2010-03-16 16:55:05 +0100
commitd9346e81de83a99ac20d94d6598ae927895cb9ef (patch)
treeeadd1088a094b82ef3d901a83efb1e407ca164d5 /hw/pc.c
parent8ad00f84251c7aefca26461faccfbb557e1dba47 (diff)
downloadqemu-d9346e81de83a99ac20d94d6598ae927895cb9ef.tar.gz
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.
Diffstat (limited to 'hw/pc.c')
-rw-r--r--hw/pc.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/hw/pc.c b/hw/pc.c
index 0c190439be..a150f8d9dc 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -230,12 +230,9 @@ static int boot_device2nibble(char boot_device)
return 0;
}
-/* copy/pasted from cmos_init, should be made a general function
- and used there as well */
-static int pc_boot_set(void *opaque, const char *boot_device)
+static int set_boot_dev(RTCState *s, const char *boot_device, int fd_bootchk)
{
#define PC_MAX_BOOT_DEVICES 3
- RTCState *s = (RTCState *)opaque;
int nbds, bds[3] = { 0, };
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, 0x38, (bds[2] << 4));
+ rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1));
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 */
static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
const char *boot_device, DriveInfo **hd_table)
{
RTCState *s = rtc_state;
- int nbds, bds[3] = { 0, };
int val;
int fd0, fd1, nb;
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);
/* set boot devices, and disable floppy signature check if requested */
-#define PC_MAX_BOOT_DEVICES 3
- nbds = strlen(boot_device);
- if (nbds > PC_MAX_BOOT_DEVICES) {
- fprintf(stderr, "Too many boot devices for PC\n");
+ if (set_boot_dev(s, boot_device, fd_bootchk)) {
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 */