From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9CCW-0003aR-66 for qemu-devel@nongnu.org; Wed, 27 May 2009 02:01:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9CCT-0003aE-LT for qemu-devel@nongnu.org; Wed, 27 May 2009 02:01:18 -0400 Received: from [199.232.76.173] (port=59983 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9CCT-0003aB-BN for qemu-devel@nongnu.org; Wed, 27 May 2009 02:01:17 -0400 Received: from yw-out-1718.google.com ([74.125.46.156]:23760) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9CCS-0002pj-F2 for qemu-devel@nongnu.org; Wed, 27 May 2009 02:01:16 -0400 Received: by yw-out-1718.google.com with SMTP id 5so2136867ywr.82 for ; Tue, 26 May 2009 23:01:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4A1BEEC5.8050406@codemonkey.ws> References: <162800e10905260322r39594e35y4fd7f7afb52ef29@mail.gmail.com> <4A1BEEC5.8050406@codemonkey.ws> Date: Wed, 27 May 2009 14:01:14 +0800 Message-ID: <162800e10905262301r35b0bdev77c4639ccd8967df@mail.gmail.com> Subject: Re: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader From: joy zhao Content-Type: multipart/alternative; boundary=00221504880f2de850046ade92e6 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org --00221504880f2de850046ade92e6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit hi Anthony, This is my updated version of patch. I've been using strtoul to translate string. I do not have get_vga_mode() return vga_mode directly because I do not want to leave the default value of vga_mode to be decided by qemu, but by kernel when no "vga=..." is specified. B.R. Joy Signed-off-by: Joy Zhao diff --git a/qemu/hw/pc.c b/qemu-new/hw/pc.c index 66cc780..dc1c20f 100644 --- a/qemu/hw/pc.c +++ b/qemu-new/hw/pc.c @@ -36,6 +36,7 @@ #include "hpet_emul.h" #include "watchdog.h" #include "smbios.h" +#include /* output Bochs bios info messages */ //#define DEBUG_BIOS @@ -593,6 +594,41 @@ static long get_file_size(FILE *f) return size; } +static int get_vga_mode(const char* kernel_cmdline, uint16_t *vga_mode) +{ + char mode[10]; + int i = 0; + char *p = strstr(kernel_cmdline, "vga="); + if(p == NULL) + return 1; + + p += 4; + + while(*p != ' ' && *p != '\0' && i < 9) { + mode[i] = *p; + i++; + p++; + } + mode[i] = '\0'; + + if(!strncmp(mode, "ask", 3)) + *vga_mode = 0xfffd; + else if(!strncmp(mode, "normal",6)) + *vga_mode = 0xffff; + else if(!strncmp(mode, "ext", 3)) + *vga_mode = 0xfffe; + else{ + errno = 0; + *vga_mode = strtoul(mode, NULL, 0); + if(errno){ + fprintf(stderr, "vga mode Overflow or unsupported base value\n"); + return 1; + } + } + + return 0; +} + static void load_linux(target_phys_addr_t option_rom, const char *kernel_filename, const char *initrd_filename, @@ -605,6 +641,7 @@ static void load_linux(target_phys_addr_t option_rom, uint16_t real_seg; int setup_size, kernel_size, initrd_size, cmdline_size; uint32_t initrd_max; + uint16_t vid_mode; uint8_t header[1024]; target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr; FILE *f, *fi; @@ -683,6 +720,10 @@ static void load_linux(target_phys_addr_t option_rom, if (protocol >= 0x200) header[0x210] = 0xB0; + /*parse cmdline and set vga mode*/ + if(!get_vga_mode(kernel_cmdline, &vid_mode)) + stw_p(header+0x1fa, vid_mode); + /* heap */ if (protocol >= 0x201) { header[0x211] |= 0x80; /* CAN_USE_HEAP */ --00221504880f2de850046ade92e6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
hi Anthony,
This is my=C2=A0 updated version of patch. I've been using strtoul= to translate string. I do not=C2=A0 have get_vga_mode() return vga_mode di= rectly because I do not want to=C2=A0leave the default value of vga_mode = =C2=A0to be decided=C2=A0by qemu, but=C2=A0by kernel=C2=A0when no "vga= =3D..." is specified.=C2=A0=C2=A0
=C2=A0
B.R.
Joy
=C2=A0
Signed-off-by: Joy Zhao <ya= nhwizhao@gmail.com>
=C2=A0
diff --git a/qemu/hw/pc.c b/qemu-new/hw/pc.c
index 66cc780..dc1c20f= 100644
--- a/qemu/hw/pc.c
+++ b/qemu-new/hw/pc.c
@@ -36,6 +36,7 @= @
=C2=A0#include "hpet_emul.h"
=C2=A0#include "watchdo= g.h"
=C2=A0#include "smbios.h"
+#include <stdlib.h>
=C2=A0=
=C2=A0/* output Bochs bios info messages */
=C2=A0//#define DEBUG_BI= OS
@@ -593,6 +594,41 @@ static long get_file_size(FILE *f)
=C2=A0=C2= =A0=C2=A0=C2=A0 return size;
=C2=A0}
=C2=A0
+static int get_vga_mode(const char* kernel_cmdline, uint16_t *vg= a_mode)
+{
+=C2=A0=C2=A0=C2=A0 char mode[10];
+=C2=A0=C2=A0=C2=A0= int i =3D 0;
+=C2=A0=C2=A0=C2=A0 char *p=C2=A0=3D strstr(kernel_cmdline= , "vga=3D");
+=C2=A0=C2=A0=C2=A0 if(p =3D=3D NULL)
+=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return 1;
+
+=C2=A0=C2=A0=C2=A0 p +=3D 4;
+
+=C2=A0=C2=A0=C2=A0 while(*p != =3D ' ' && *p !=3D '\0' && i < 9)=C2=A0{=
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mode[i] =3D *p;
+=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i++;
+=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 p++;=C2=A0=C2=A0
+=C2=A0=C2=A0=C2=A0 }
+=C2=A0=C2=A0= =C2=A0 mode[i] =3D '\0';
+
+=C2=A0=C2=A0=C2=A0 if(!strncmp(mode, "ask", 3))
+=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *vga_mode =3D 0xfffd;
+=C2=A0=C2=A0=C2=A0= else if(!strncmp(mode, "normal",6))
+=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 *vga_mode =3D 0xffff;
+=C2=A0=C2=A0=C2=A0 else if(!st= rncmp(mode, "ext", 3))
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 *vga_mode =3D 0xfffe;
+=C2=A0=C2=A0=C2=A0 else{
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 er= rno =3D 0;
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *vga_mode =3D str= toul(mode, NULL, 0);
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(errn= o){
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = fprintf(stderr, "vga mode Overflow or unsupported base value\n");=
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret= urn 1;
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
+=C2=A0=C2=A0=C2=A0 }
+=
+=C2=A0=C2=A0=C2=A0 return 0;
+}
+
=C2=A0static void load_lin= ux(target_phys_addr_t option_rom,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *kernel_filename,
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *initrd_filename,
@@ = -605,6 +641,7 @@ static void load_linux(target_phys_addr_t option_rom,
=C2=A0=C2=A0=C2=A0=C2=A0 uint16_t real_seg;
=C2=A0=C2=A0=C2=A0=C2=A0 int= setup_size, kernel_size, initrd_size, cmdline_size;
=C2=A0=C2=A0=C2=A0= =C2=A0 uint32_t initrd_max;
+=C2=A0=C2=A0=C2=A0 uint16_t vid_mode;
= =C2=A0=C2=A0=C2=A0=C2=A0 uint8_t header[1024];
=C2=A0=C2=A0=C2=A0=C2=A0 = target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr;
=C2=A0=C2=A0=C2=A0=C2=A0 FILE *f, *fi;
@@ -683,6 +720,10 @@ static void = load_linux(target_phys_addr_t option_rom,
=C2=A0=C2=A0=C2=A0=C2=A0 if (p= rotocol >=3D 0x200)
=C2=A0=C2=A0header[0x210] =3D 0xB0;
=C2=A0
= +=C2=A0=C2=A0=C2=A0 /*parse cmdline and set vga mode*/
+=C2=A0=C2=A0=C2= =A0 if(!get_vga_mode(kernel_cmdline, &vid_mode))
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 stw_p(header+0x1fa, vid_mode);<= br>+
=C2=A0=C2=A0=C2=A0=C2=A0 /* heap */
=C2=A0=C2=A0=C2=A0=C2=A0 if = (protocol >=3D 0x201) {
=C2=A0=C2=A0header[0x211] |=3D 0x80;=C2=A0/* = CAN_USE_HEAP */
--00221504880f2de850046ade92e6--