From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnDQf-0000WY-Ki for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:37 -0500 Received: from [199.232.76.173] (port=35953 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnDQd-0000TW-HM for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:35 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnDQQ-0000Io-7S for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:34 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:39622) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnDQO-0000H8-Fb for qemu-devel@nongnu.org; Thu, 04 Mar 2010 10:57:21 -0500 Received: from blackfin.pond.sub.org (pD9E38041.dip.t-dialin.net [217.227.128.65]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 2612C276DAC for ; Thu, 4 Mar 2010 16:57:13 +0100 (CET) From: Markus Armbruster Date: Thu, 4 Mar 2010 16:56:25 +0100 Message-Id: <1267718231-13303-5-git-send-email-armbru@redhat.com> In-Reply-To: <1267718231-13303-1-git-send-email-armbru@redhat.com> References: <1267718231-13303-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 04/50] pc: Factor common code out of pc_boot_set() and cmos_init() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: 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. Signed-off-by: Markus Armbruster --- hw/pc.c | 28 ++++++++-------------------- 1 files changed, 8 insertions(+), 20 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index d94980b..1595283 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 */ -- 1.6.6.1