From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JeVQc-0001W3-OE for qemu-devel@nongnu.org; Wed, 26 Mar 2008 09:12:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JeVQa-0001V7-1e for qemu-devel@nongnu.org; Wed, 26 Mar 2008 09:12:29 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JeVQZ-0001Uy-Pw for qemu-devel@nongnu.org; Wed, 26 Mar 2008 09:12:27 -0400 Received: from yw-out-1718.google.com ([74.125.46.152]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from <3ntr0p13@gmail.com>) id 1JeVQZ-0000UF-Tw for qemu-devel@nongnu.org; Wed, 26 Mar 2008 09:12:28 -0400 Received: by yw-out-1718.google.com with SMTP id 4so26619ywq.82 for ; Wed, 26 Mar 2008 06:12:26 -0700 (PDT) Message-ID: <9a8ae26c0803260612l92c88d5r638b57972c9d55e1@mail.gmail.com> Date: Wed, 26 Mar 2008 14:12:25 +0100 From: Gildas <3ntr0p13@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: [Qemu-devel] [PATCH] allow bootdevice change from the monitor Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This patch allows changing the boot device from within the monitor. Signed-off-by: Gildas Le Nadan <3ntr0p13@gmail.com> diff -Nur a/hw/pc.c b/hw/pc.c --- a/hw/pc.c 2008-03-18 07:53:05.000000000 +0100 +++ b/hw/pc.c 2008-03-26 13:18:16.000000000 +0100 @@ -180,6 +180,33 @@ return 0; } +/* copy/pasted from cmos_init, should be made a general function + and used there as well */ +int pc_set_bootdevice(const char *boot_device) +{ +#define PC_MAX_BOOT_DEVICES 3 + RTCState *s = rtc_state; + int nbds, bds[3] = { 0, }; + int i; + + nbds = strlen(boot_device); + if (nbds > PC_MAX_BOOT_DEVICES) { + fprintf(stderr, "Too many boot devices for PC\n"); + return(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]); + return(1); + } + } + rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]); + rtc_set_memory(s, 0x38, (bds[2] << 4)); + return(0); +} + /* hd_table must contain 4 block drivers */ static void cmos_init(int ram_size, const char *boot_device, BlockDriverState **hd_table) { @@ -717,6 +744,8 @@ BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; BlockDriverState *fd[MAX_FD]; + set_bootdevice_fct = pc_set_bootdevice; + linux_boot = (kernel_filename != NULL); /* init CPUs */ diff -Nur a/monitor.c b/monitor.c --- a/monitor.c 2008-02-10 17:33:13.000000000 +0100 +++ b/monitor.c 2008-03-26 13:17:56.000000000 +0100 @@ -993,6 +993,21 @@ suffix, addr, size * 2, val); } +static void do_bootdevice_set(const char *bootdevice) +{ + int res; + + if (set_bootdevice_fct != NULL) { + res = set_bootdevice_fct(bootdevice); + if (res == 0) + term_printf("boot device list now set to %s\n", bootdevice); + else + term_printf("setting boot device list failed with error %i\n", res); + } else { + term_printf("no function defined to set boot device list for this architecture\n"); + } +} + static void do_system_reset(void) { qemu_system_reset_request(); @@ -1328,6 +1343,8 @@ "capture index", "stop capture" }, { "memsave", "lis", do_memory_save, "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", }, + { "boot_set", "s", do_bootdevice_set, + "bootdevice", "define new values for the boot device list" }, { NULL, NULL, }, }; diff -Nur a/sysemu.h b/sysemu.h --- a/sysemu.h 2008-03-18 07:53:05.000000000 +0100 +++ b/sysemu.h 2008-03-26 13:12:20.000000000 +0100 @@ -9,6 +9,11 @@ extern int vm_running; extern const char *qemu_name; +/* handler to set the boot_device for a specific type of QEMUMachine */ +/* return 0 if success */ +typedef int QEMUMachineSetBootFunc(const char *boot_device); +QEMUMachineSetBootFunc *set_bootdevice_fct; + typedef struct vm_change_state_entry VMChangeStateEntry; typedef void VMChangeStateHandler(void *opaque, int running); typedef void VMStopHandler(void *opaque, int reason);