* [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader
@ 2009-05-26 10:22 joy zhao
2009-05-26 13:29 ` Anthony Liguori
2009-05-26 14:26 ` Mark McLoughlin
0 siblings, 2 replies; 4+ messages in thread
From: joy zhao @ 2009-05-26 10:22 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 3218 bytes --]
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 */
[-- Attachment #2: Type: text/html, Size: 4026 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader
2009-05-26 10:22 [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader joy zhao
@ 2009-05-26 13:29 ` Anthony Liguori
2009-05-27 6:01 ` joy zhao
2009-05-26 14:26 ` Mark McLoughlin
1 sibling, 1 reply; 4+ messages in thread
From: Anthony Liguori @ 2009-05-26 13:29 UTC (permalink / raw)
To: joy zhao; +Cc: qemu-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader
2009-05-26 10:22 [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader joy zhao
2009-05-26 13:29 ` Anthony Liguori
@ 2009-05-26 14:26 ` Mark McLoughlin
1 sibling, 0 replies; 4+ messages in thread
From: Mark McLoughlin @ 2009-05-26 14:26 UTC (permalink / raw)
To: joy zhao; +Cc: qemu-devel
On Tue, 2009-05-26 at 18:22 +0800, 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.
FWIW, I agree we do need this - see also:
https://bugzilla.redhat.com/501935
qemu-kvm -kernel should parse "vga=" cmdline option
Cheers,
Mark.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader
2009-05-26 13:29 ` Anthony Liguori
@ 2009-05-27 6:01 ` joy zhao
0 siblings, 0 replies; 4+ messages in thread
From: joy zhao @ 2009-05-27 6:01 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 2310 bytes --]
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 <yanhwizhao@gmail.com>
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 <stdlib.h>
/* 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 */
[-- Attachment #2: Type: text/html, Size: 3133 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-27 6:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-26 10:22 [Qemu-devel] [PATCH] set vidmode in linux kernel header when boot x86 using qemu bootloader joy zhao
2009-05-26 13:29 ` Anthony Liguori
2009-05-27 6:01 ` joy zhao
2009-05-26 14:26 ` Mark McLoughlin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).