From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M8tnx-0000Mh-TV for qemu-devel@nongnu.org; Tue, 26 May 2009 06:22:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M8tnt-0000Lp-9A for qemu-devel@nongnu.org; Tue, 26 May 2009 06:22:45 -0400 Received: from [199.232.76.173] (port=38220 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8tnt-0000Ll-1v for qemu-devel@nongnu.org; Tue, 26 May 2009 06:22:41 -0400 Received: from an-out-0708.google.com ([209.85.132.246]:34009) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M8tns-0002DD-Je for qemu-devel@nongnu.org; Tue, 26 May 2009 06:22:40 -0400 Received: by an-out-0708.google.com with SMTP id d11so2019827and.37 for ; Tue, 26 May 2009 03:22:40 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 26 May 2009 18:22:39 +0800 Message-ID: <162800e10905260322r39594e35y4fd7f7afb52ef29@mail.gmail.com> Subject: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader From: joy zhao Content-Type: multipart/alternative; boundary=00032557691e3f16bc046ace1b2e List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --00032557691e3f16bc046ace1b2e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit hi, I made a patch to have qemu parse vga field in kernel command line and set the vid_mode field of real-mode kernel header. This patch is necessary because vga is one of the special command line options that should be parsed in bootloader, as in linux kernel Documentation/x86/i386/boot.txt. After bootloader write the passed vga value into the vid_mode field of linux real-mode kernel header, this vid_mode will be handled by linux/x86/boot/video.c in linux kernel to select vesa graphics mode, and only in this mode can vesafb be registered(in vesafb_probe()). So, if we decide to launch linux directly from qemu command line as "qemu -kernel ... -initrd... -append "..." ", (use qemu bootloader) and use vesafb as framebuffer driver, this patch to qemu is required, otherwise, the screen should just blank since the vesafb fails to register itself. Joy. diff --git a/qemu/hw/pc.c b/qemu-new/hw/pc.c index 66cc780..5615db8 100644 --- a/qemu/hw/pc.c +++ b/qemu-new/hw/pc.c @@ -593,6 +593,77 @@ static long get_file_size(FILE *f) return size; } +static uint16_t hato16i(char *hex) +{ + uint16_t integer = 0; + if(hex[1] == 'x') + hex += 2; + + while(*hex != '\0'){ + integer = (integer<<4); + + if(*hex >= 0x30 && *hex <= 0x39){ /*0~9*/ + integer += *hex - 0x30; + }else if(*hex >= 0x61 && *hex <= 0x66){ /*a~f*/ + integer += *hex - 0x61 + 0xa; + }else if(*hex >= 0x41 && *hex <= 0x46){ /*A~F*/ + integer += *hex - 0x41 + 0xa; + }else + break; + + hex++; + } + return integer; +} + +static uint16_t ato16i(char *dec) +{ + uint16_t integer = 0; + + while(*dec != '\0'){ + integer *= 10; + + if(*dec >= 0x30 && *dec <= 0x39){ /*0~9*/ + integer += *dec - 0x30; + }else + break; + + dec++; + } + return integer; +} + +static int get_vga_mode(const char* kernel_cmdline, uint16_t *vga_mode) +{ + char mode[6]; + int i = 0; + char *p = strstr(kernel_cmdline, "vga="); + if(p == NULL) + return 1; + + p += 4; + + while(*p != ' ' && *p != '\0' && i < 6) { + mode[i] = *p; + i++; + p++; + } + + 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 if(!strncmp(mode, "0x", 2)){//in hexdecimal + *vga_mode = hato16i(mode); + }else //in decimal + *vga_mode = ato16i(mode); + + return 0; +} + + static void load_linux(target_phys_addr_t option_rom, const char *kernel_filename, const char *initrd_filename, @@ -605,6 +676,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 +755,12 @@ 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)){ + header[0x1fa] = vid_mode&0xff; + header[0x1fb] = (vid_mode&0xff00)>>8; + } + /* heap */ if (protocol >= 0x201) { header[0x211] |= 0x80; /* CAN_USE_HEAP */ --00032557691e3f16bc046ace1b2e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
hi,
I made a patch to have qemu parse vga field in kernel command l= ine and set the vid_mode field of real-mode kernel header.
This patch is= necessary because vga is one of the special command line options that shou= ld be parsed in bootloader, as in linux kernel Documentation/x86/i386/boot.= txt. After bootloader write the passed vga value into the vid_mode field of= linux real-mode kernel header, this vid_mode will be handled by linux/x86/= boot/video.c in linux kernel to select vesa graphics mode, and only in this= mode can vesafb be registered(in vesafb_probe()).
So, if we decide to launch linux directly from qemu command line as "q= emu -kernel ... -initrd... -append "..." ", (use qemu bootlo= ader) and use vesafb as framebuffer driver, this patch to qemu is required,= otherwise, the screen should just blank since the vesafb fails to register= itself.
Joy.

=C2=A0
diff --git a/qemu/hw/pc.c b/qemu-new/hw/pc.c
index 66cc780..5615db8= 100644
--- a/qemu/hw/pc.c
+++ b/qemu-new/hw/pc.c
@@ -593,6 +593,7= 7 @@ static long get_file_size(FILE *f)
=C2=A0=C2=A0=C2=A0=C2=A0 return = size;
=C2=A0}
=C2=A0
+static uint16_t hato16i(char *hex)
+{
+=C2=A0uint16_t inte= ger =3D 0;
+=C2=A0if(hex[1] =3D=3D 'x')
+=C2=A0=C2=A0=C2=A0 h= ex +=3D 2;
+
+=C2=A0=C2=A0=C2=A0 while(*hex !=3D '\0'){
+= =C2=A0=C2=A0integer =3D (integer<<4);
+
+=C2=A0=C2=A0if(*hex &g= t;=3D 0x30 && *hex <=3D 0x39){ /*0~9*/
+=C2=A0=C2=A0=C2=A0integer +=3D *hex - 0x30;
+=C2=A0=C2=A0}else if(*hex = >=3D 0x61 && *hex <=3D 0x66){ /*a~f*/
+=C2=A0=C2=A0=C2=A0i= nteger +=3D *hex - 0x61 + 0xa;
+=C2=A0=C2=A0}else if(*hex >=3D 0x41 &= amp;& *hex <=3D 0x46){ /*A~F*/
+=C2=A0=C2=A0=C2=A0integer +=3D *h= ex - 0x41 + 0xa;
+=C2=A0=C2=A0}else
+=C2=A0=C2=A0=C2=A0break;
+
+=C2=A0=C2=A0hex++;=
+=C2=A0}=C2=A0
+=C2=A0return integer;
+}
+
+static uint16_t= ato16i(char *dec)
+{
+=C2=A0uint16_t integer =3D 0;
+
+=C2=A0= =C2=A0=C2=A0 while(*dec !=3D '\0'){
+=C2=A0=C2=A0integer *=3D 10= ;
+
+=C2=A0=C2=A0if(*dec >=3D 0x30 && *dec <=3D 0x39){ /*0~9*/+=C2=A0=C2=A0=C2=A0integer +=3D *dec - 0x30;
+=C2=A0=C2=A0}else
+=C2= =A0=C2=A0=C2=A0break;
+
+=C2=A0=C2=A0dec++;
+=C2=A0}=C2=A0
+=C2= =A0return integer;
+}
+
+static int get_vga_mode(const char* kerne= l_cmdline, uint16_t *vga_mode)
+{
+=C2=A0char mode[6];
+=C2=A0int i =3D 0;
+=C2=A0char *p=C2=A0= =3D strstr(kernel_cmdline, "vga=3D");
+=C2=A0if(p =3D=3D NULL)=
+=C2=A0=C2=A0return 1;
+
+=C2=A0p +=3D 4;
+
+=C2=A0while(*p= !=3D ' ' && *p !=3D '\0' && i < 6)=C2= =A0{
+=C2=A0=C2=A0mode[i] =3D *p;
+=C2=A0=C2=A0i++;
+=C2=A0=C2=A0p++;=C2= =A0=C2=A0
+=C2=A0}
+
+=C2=A0if(!strncmp(mode, "ask", 3)= ){
+=C2=A0=C2=A0*vga_mode =3D 0xfffd;
+=C2=A0}else if(!strncmp(mode, = "normal",6)){
+=C2=A0=C2=A0*vga_mode =3D 0xffff;
+=C2=A0}el= se if(!strncmp(mode, "ext", 3)){
+=C2=A0=C2=A0*vga_mode =3D 0xfffe;
+=C2=A0}else if(!strncmp(mode, "= 0x", 2)){//in hexdecimal
+=C2=A0=C2=A0*vga_mode =3D hato16i(mode);=
+=C2=A0}else=C2=A0//in decimal
+=C2=A0=C2=A0*vga_mode =3D ato16i(mo= de);
+
+=C2=A0return 0;
+}
+
+
=C2=A0static void load_li= nux(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 +676,7 @@ static void load_linux= (target_phys_addr_t option_rom,
=C2=A0=C2=A0=C2=A0=C2=A0 uint16_t real_s= eg;
=C2=A0=C2=A0=C2=A0=C2=A0 int setup_size, kernel_size, initrd_size, c= mdline_size;
=C2=A0=C2=A0=C2=A0=C2=A0 uint32_t initrd_max;
+=C2=A0uint16_t vid_mode;<= br>=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 +755,12 @@ static void = load_linux(target_phys_addr_t option_rom,
=C2=A0=C2=A0=C2=A0=C2=A0 if (protocol >=3D 0x200)
=C2=A0=C2=A0header[= 0x210] =3D 0xB0;
=C2=A0
+=C2=A0/*parse cmdline and set vga mode*/
= +=C2=A0if(!get_vga_mode(kernel_cmdline, &vid_mode)){
+=C2=A0=C2=A0he= ader[0x1fa] =3D vid_mode&0xff;
+=C2=A0=C2=A0header[0x1fb] =3D (vid_m= ode&0xff00)>>8;
+=C2=A0}
+
=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 */
--00032557691e3f16bc046ace1b2e--