rombios: move the stack to 0x9e000 and protect it with an e820 entry
PATCH 1/1 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
tools/firmware/hvmloader/hvmloader.c +52 -3
@@ -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));
tools/firmware/rombios/rombios.c +8 -8
@@ -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, #0x9e00mov 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, #0x9e00mov 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, #0x9e00mov ss, ax ;; Save shutdown status
Ooops - please don't apply this, it breaks CD-ROM boot.
Cheers,
Tim.
Quoted 141 lines · Tim Deegan
rombios: move the stack to
0x9e000and protect it with an e820 entry so that we don't corruptE820_RAMmemory 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 <[email protected]>Signed-off-by Tim Deegan <[email protected]>diff -r
4160103f98e3tools/firmware/hvmloader/hvmloader.ctools/firmware/hvmloader/hvmloader.c +52
-3@@ -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
4160103f98e3tools/firmware/rombios/rombios.ctools/firmware/rombios/rombios.c +8
-8@@ -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, #0x9e00mov 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, #0x9e00mov 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, #0x9e00mov ss, ax ;; Save shutdown status
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 1 line · Tim Deegan
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.
tools/firmware/rombios/rombios.c +2 -2
@@ -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 ];