From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M8wj2-0002Zz-LG for qemu-devel@nongnu.org; Tue, 26 May 2009 09:29:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M8wiy-0002YK-2B for qemu-devel@nongnu.org; Tue, 26 May 2009 09:29:52 -0400 Received: from [199.232.76.173] (port=48038 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8wix-0002YC-Tc for qemu-devel@nongnu.org; Tue, 26 May 2009 09:29:47 -0400 Received: from mail-qy0-f123.google.com ([209.85.221.123]:40800) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M8wix-000260-Fc for qemu-devel@nongnu.org; Tue, 26 May 2009 09:29:47 -0400 Received: by qyk29 with SMTP id 29so3684393qyk.4 for ; Tue, 26 May 2009 06:29:47 -0700 (PDT) Message-ID: <4A1BEEC5.8050406@codemonkey.ws> Date: Tue, 26 May 2009 08:29:41 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader References: <162800e10905260322r39594e35y4fd7f7afb52ef29@mail.gmail.com> In-Reply-To: <162800e10905260322r39594e35y4fd7f7afb52ef29@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: joy zhao Cc: qemu-devel@nongnu.org Hi Joy, joy zhao wrote: > 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. > > Need a Signed-off-by: to apply this. > 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; > +} Make sure you format according to CodingStyle. Also, this function isn't needed as strtoul(hex, NULL, 16) provides the same functionality. > +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); strtoul(mode, NULL, 0) will cover both hex and decimal. You can check the value afterword to enforce u16 if you really want to. Regards, Anthony Liguori