Tim Deegan
2010-Jul-06 15:35 UTC
[Xen-devel] [PATCH] rombios: move the stack to 0x9e000 and protect it with an e820 entry
rombios: move the stack to 0x9e000 and protect it with an e820 entry so that we don''t corrupt E820_RAM memory with stack ops in S3 wakeup. It has to move up so the lowest contiguous RAM area is >= 512MiB. This relies on the previous fix to let DS != SS Signed-off-by: Paul Durrant <Paul.Durrant@citrix.com> Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com> diff -r 4160103f98e3 tools/firmware/hvmloader/hvmloader.c --- a/tools/firmware/hvmloader/hvmloader.c Tue Jul 06 16:27:22 2010 +0100 +++ b/tools/firmware/hvmloader/hvmloader.c Tue Jul 06 16:28:09 2010 +0100 @@ -576,16 +576,64 @@ printf("vm86 TSS at %08lx\n", virt_to_phys(tss)); } +static void dump_e820_table(void) +{ + struct e820entry *e820 = E820; + unsigned int nr = *E820_NR; + unsigned int last_end = 0; + int i; + + printf("E820 table:\n"); + + for (i = 0; i < nr; i++) { + unsigned int start = e820[i].addr; + unsigned int end = e820[i].addr + e820[i].size; + + if (start < last_end) + printf(" OVERLAP!!\n"); + else if (start > last_end) + printf(" HOLE: %08x - %08x\n", last_end, start); + + printf(" [%02d]: %08x - %08x: ", i, start, end); + switch (e820[i].type) { + case E820_RAM: + printf("RAM\n"); + break; + case E820_RESERVED: + printf("RESERVED\n"); + break; + case E820_ACPI: + printf("ACPI\n"); + break; + case E820_NVS: + printf("NVS\n"); + break; + default: + printf("UNKNOWN (%08x)\n", e820[i].type); + break; + } + + last_end = end; + } +} + /* Create an E820 table based on memory parameters provided in hvm_info. */ static void build_e820_table(void) { struct e820entry *e820 = E820; unsigned int nr = 0; - /* 0x0-0x9FC00: Ordinary RAM. */ - e820[nr].addr = 0x0; - e820[nr].size = 0x9FC00; + /* 0x0-0x9EC00: Ordinary RAM. */ + /* (Must be at least 512K to keep Windows happy) */ + e820[nr].addr = 0x00000; + e820[nr].size = 0x9E000; e820[nr].type = E820_RAM; + nr++; + + /* 0x9E000-0x9FC00: Reserved for internal use. */ + e820[nr].addr = 0x9E000; + e820[nr].size = 0x01C00; + e820[nr].type = E820_RESERVED; nr++; /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */ @@ -739,6 +787,7 @@ ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1); build_e820_table(); + dump_e820_table(); bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS; memset(bios_info, 0, sizeof(*bios_info)); diff -r 4160103f98e3 tools/firmware/rombios/rombios.c --- a/tools/firmware/rombios/rombios.c Tue Jul 06 16:27:22 2010 +0100 +++ b/tools/firmware/rombios/rombios.c Tue Jul 06 16:28:09 2010 +0100 @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////// // $Id: rombios.c,v 1.221 2008/12/07 17:32:29 sshwarts Exp $ -///////////////////////////////////////////////////////////////////////// +////////////////////////////#///////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. // @@ -8871,13 +8871,14 @@ int18_handler: ;; Boot Failure recovery: try the next device. ;; Reset SP and SS - mov ax, #0xfffe + mov ax, #0x0ffe mov sp, ax - xor ax, ax + mov ax, #0x9e00 mov ss, ax ;; The first time we do this it will have been set to -1 so ;; we will start from device 0. + xor ax, ax mov ds, ax mov bx, word ptr [0x40E] ;; EBDA segment mov ds, bx ;; Set segment @@ -8911,9 +8912,9 @@ ;; ;; Reset SP and SS - mov ax, #0xfffe + mov ax, #0x0ffe mov sp, ax - xor ax, ax + mov ax, #0x9e00 mov ss, ax call _machine_reset @@ -10848,10 +10849,9 @@ ; case 0: normal startup cli - mov ax, #0xfffe + mov ax, #0x0ffe mov sp, ax - xor ax, ax - mov ds, ax + mov ax, #0x9e00 mov ss, ax ;; Save shutdown status _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2010-Jul-06 15:44 UTC
[Xen-devel] Re: [PATCH] rombios: move the stack to 0x9e000 and protect it with an e820 entry
Ooops - please don''t apply this, it breaks CD-ROM boot. Cheers, Tim. At 16:35 +0100 on 06 Jul (1278434127), Tim Deegan wrote:> rombios: move the stack to 0x9e000 and protect it with an e820 entry > so that we don''t corrupt E820_RAM memory with stack ops in S3 wakeup. > It has to move up so the lowest contiguous RAM area is >= 512MiB. > > This relies on the previous fix to let DS != SS > > Signed-off-by: Paul Durrant <Paul.Durrant@citrix.com> > Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com> > > diff -r 4160103f98e3 tools/firmware/hvmloader/hvmloader.c > --- a/tools/firmware/hvmloader/hvmloader.c Tue Jul 06 16:27:22 2010 +0100 > +++ b/tools/firmware/hvmloader/hvmloader.c Tue Jul 06 16:28:09 2010 +0100 > @@ -576,16 +576,64 @@ > printf("vm86 TSS at %08lx\n", virt_to_phys(tss)); > } > > +static void dump_e820_table(void) > +{ > + struct e820entry *e820 = E820; > + unsigned int nr = *E820_NR; > + unsigned int last_end = 0; > + int i; > + > + printf("E820 table:\n"); > + > + for (i = 0; i < nr; i++) { > + unsigned int start = e820[i].addr; > + unsigned int end = e820[i].addr + e820[i].size; > + > + if (start < last_end) > + printf(" OVERLAP!!\n"); > + else if (start > last_end) > + printf(" HOLE: %08x - %08x\n", last_end, start); > + > + printf(" [%02d]: %08x - %08x: ", i, start, end); > + switch (e820[i].type) { > + case E820_RAM: > + printf("RAM\n"); > + break; > + case E820_RESERVED: > + printf("RESERVED\n"); > + break; > + case E820_ACPI: > + printf("ACPI\n"); > + break; > + case E820_NVS: > + printf("NVS\n"); > + break; > + default: > + printf("UNKNOWN (%08x)\n", e820[i].type); > + break; > + } > + > + last_end = end; > + } > +} > + > /* Create an E820 table based on memory parameters provided in hvm_info. */ > static void build_e820_table(void) > { > struct e820entry *e820 = E820; > unsigned int nr = 0; > > - /* 0x0-0x9FC00: Ordinary RAM. */ > - e820[nr].addr = 0x0; > - e820[nr].size = 0x9FC00; > + /* 0x0-0x9EC00: Ordinary RAM. */ > + /* (Must be at least 512K to keep Windows happy) */ > + e820[nr].addr = 0x00000; > + e820[nr].size = 0x9E000; > e820[nr].type = E820_RAM; > + nr++; > + > + /* 0x9E000-0x9FC00: Reserved for internal use. */ > + e820[nr].addr = 0x9E000; > + e820[nr].size = 0x01C00; > + e820[nr].type = E820_RESERVED; > nr++; > > /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */ > @@ -739,6 +787,7 @@ > ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1); > > build_e820_table(); > + dump_e820_table(); > > bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS; > memset(bios_info, 0, sizeof(*bios_info)); > diff -r 4160103f98e3 tools/firmware/rombios/rombios.c > --- a/tools/firmware/rombios/rombios.c Tue Jul 06 16:27:22 2010 +0100 > +++ b/tools/firmware/rombios/rombios.c Tue Jul 06 16:28:09 2010 +0100 > @@ -1,6 +1,6 @@ > ///////////////////////////////////////////////////////////////////////// > // $Id: rombios.c,v 1.221 2008/12/07 17:32:29 sshwarts Exp $ > -///////////////////////////////////////////////////////////////////////// > +////////////////////////////#///////////////////////////////////////////// > // > // Copyright (C) 2002 MandrakeSoft S.A. > // > @@ -8871,13 +8871,14 @@ > int18_handler: ;; Boot Failure recovery: try the next device. > > ;; Reset SP and SS > - mov ax, #0xfffe > + mov ax, #0x0ffe > mov sp, ax > - xor ax, ax > + mov ax, #0x9e00 > mov ss, ax > > ;; The first time we do this it will have been set to -1 so > ;; we will start from device 0. > + xor ax, ax > mov ds, ax > mov bx, word ptr [0x40E] ;; EBDA segment > mov ds, bx ;; Set segment > @@ -8911,9 +8912,9 @@ > ;; > ;; Reset SP and SS > > - mov ax, #0xfffe > + mov ax, #0x0ffe > mov sp, ax > - xor ax, ax > + mov ax, #0x9e00 > mov ss, ax > > call _machine_reset > @@ -10848,10 +10849,9 @@ > ; case 0: normal startup > > cli > - mov ax, #0xfffe > + mov ax, #0x0ffe > mov sp, ax > - xor ax, ax > - mov ds, ax > + mov ax, #0x9e00 > mov ss, ax > > ;; Save shutdown status-- Tim Deegan <Tim.Deegan@citrix.com> Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2010-Jul-07 10:35 UTC
[Xen-devel] Re: [PATCH] rombios: move the stack to 0x9e000 and protect it with an e820 entry
At 16:44 +0100 on 06 Jul (1278434642), Tim Deegan wrote:> Ooops - please don''t apply this, it breaks CD-ROM boot.Correction, please do apply it, and also this: rombios: use explicit SS prefix for calculated on-stack array accesses. The bcc compiler gets constant array offsets right but does all calculated array offsets via DS. Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com> diff -r e316ad18de3c tools/firmware/rombios/rombios.c --- a/tools/firmware/rombios/rombios.c Wed Jul 07 11:27:36 2010 +0100 +++ b/tools/firmware/rombios/rombios.c Wed Jul 07 11:30:14 2010 +0100 @@ -3735,10 +3735,10 @@ // Validity checks if(buffer[0]!=0)return 4; for(i=0;i<5;i++){ - if(buffer[1+i]!=read_byte(0xf000,&isotag[i]))return 5; + if(read_byte(get_SS(),&buffer[1+i])!=read_byte(0xf000,&isotag[i]))return 5; } for(i=0;i<23;i++) - if(buffer[7+i]!=read_byte(0xf000,&eltorito[i]))return 6; + if(read_byte(get_SS(),&buffer[7+i])!=read_byte(0xf000,&eltorito[i]))return 6; // ok, now we calculate the Boot catalog address lba=buffer[0x4A]*0x1000000+buffer[0x49]*0x10000+buffer[0x48]*0x100+buffer[0x47]; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel