From f283fa3ab12843a4e0e373cd9d7b93b429c23baa Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 31 Mar 2010 13:24:27 -0300 Subject: [PATCH 12/66] pc: Factor common code out of pc_boot_set() and cmos_init() RH-Author: Markus Armbruster Message-id: <1270041921-28969-13-git-send-email-armbru@redhat.com> Patchwork-id: 8259 O-Subject: [PATCH 12/66] pc: Factor common code out of pc_boot_set() and cmos_init() Bugzilla: 579470 RH-Acked-by: Juan Quintela RH-Acked-by: Kevin Wolf RH-Acked-by: Luiz Capitulino 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. (cherry picked from commit d9346e81de83a99ac20d94d6598ae927895cb9ef) --- hw/pc.c | 28 ++++++++-------------------- 1 files changed, 8 insertions(+), 20 deletions(-) Signed-off-by: Eduardo Habkost --- hw/pc.c | 28 ++++++++-------------------- 1 files changed, 8 insertions(+), 20 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 1b396a9..7feaf32 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -224,12 +224,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; @@ -247,16 +244,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; @@ -295,22 +296,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 */ -- 1.7.0.3