Support for S3 ACPI state (suspend to memory) in BIOS
v2 cover Support for S3 ACPI state (suspend to memory) in BIOS
Hello,
This patch series adds S3 (suspend to RAM) ACPI state to BIOS. Most changes concern themselves with preventing BIOS from using memory locations available to a guest OS.
Changelog:
v2:
- Don't disable SMM.
- Jump to resume vector ASAP. Don't execute entire POST.
- Use smp_cpus directly for smp initialization instead of special memory location.
---
Gleb Natapov (6):
Don't power down vga card on entering S3 state.
Don't use unreserved memory in BIOS.
Execute rombios32 code from rom address 0xe0000. Preserve memory content during SMM init.
Add S3 state to DSDT. Handle resume event in the BIOS. Move PIC initialization out of line to save space in post code area.
bios/Makefile.in | 1 bios/acpi-dsdt.dsl | 45 +++++- bios/acpi-dsdt.hex | 376 +++++++++++++++++++++++++------------------------ bios/rombios.c | 112 +++++++++------ bios/rombios.h | 1 bios/rombios32.c | 95 +++++++++++- bios/rombios32.ld | 8 - bios/rombios32start.S | 11 + 8 files changed, 398 insertions(+), 251 deletions(-)
Signature · 1 line
Gleb.
PATCH v2 1/6 Move PIC initialization out of line to save space in post code area.
There are only a couple of bytes left in post area.
---
bios/rombios.c | 48 ++++++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 22 deletions(-)
bios/rombios.c +26 -22
@@ -10256,6 +10256,31 @@ rom_scan_increment: mov ds, ax ret +post_init_pic: + mov al, #0x11 ; send initialisation commands + out 0x20, al + out 0xa0, al + mov al, #0x08 + out 0x21, al + mov al, #0x70 + out 0xa1, al + mov al, #0x04 + out 0x21, al + mov al, #0x02 + out 0xa1, al + mov al, #0x01 + out 0x21, al + out 0xa1, al + mov al, #0xb8 + out 0x21, AL ;master pic: unmask IRQ 0, 1, 2, 6 +#if BX_USE_PS2_MOUSE + mov al, #0x8f +#else + mov al, #0x9f +#endif + out 0xa1, AL ;slave pic: unmask IRQ 12, 13, 14 + ret + ;; the following area can be used to write dynamically generated tables .align 16 bios_table_area_start:
@@ -10516,28 +10541,7 @@ post_default_ints: SET_INT_VECTOR(0x10, #0xF000, #int10_handler) ;;PIC - mov al, #0x11 ; send initialisation commands - out 0x20, al - out 0xa0, al - mov al, #0x08 - out 0x21, al - mov al, #0x70 - out 0xa1, al - mov al, #0x04 - out 0x21, al - mov al, #0x02 - out 0xa1, al - mov al, #0x01 - out 0x21, al - out 0xa1, al - mov al, #0xb8 - out 0x21, AL ;master pic: unmask IRQ 0, 1, 2, 6 -#if BX_USE_PS2_MOUSE - mov al, #0x8f -#else - mov al, #0x9f -#endif - out 0xa1, AL ;slave pic: unmask IRQ 12, 13, 14 + call post_init_pic mov cx, #0xc000 ;; init vga bios mov ax, #0xc780
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 1/6] Move PIC initialization out ofline to save space in post code area.
Quoted 64 lines · Gleb Natapov
There are only a couple of bytes left in post area.
Signed-off-by Gleb Natapov <[email protected]>---
bios/rombios.c| 48 ++++++++++++++++++++++++++----------------------1 files changed, 26 insertions(+), 22 deletions(-)bios/rombios.c +25
-0@@ -10256,6 +10256,31 @@ rom_scan_increment: mov ds, ax ret +post_init_pic: + mov al, #0x11 ; send initialisation commands + out 0x20, al + out 0xa0, al + mov al, #0x08 + out 0x21, al + mov al, #0x70 + out 0xa1, al + mov al, #0x04 + out 0x21, al + mov al, #0x02 + out 0xa1, al + mov al, #0x01 + out 0x21, al + out 0xa1, al + mov al, #0xb8 + out 0x21, AL ;master pic: unmask IRQ 0, 1, 2, 6 +#if BX_USE_PS2_MOUSE + mov al, #0x8f +#else + mov al, #0x9f +#endif + out 0xa1, AL ;slave pic: unmask IRQ 12, 13, 14 + ret +;; the following area can be used to write dynamically generated tables
.align 16bios_table_area_start:bios/rombios.c +0
-16@@ -10516,28 +10541,7 @@ post_default_ints: SET_INT_VECTOR(0x10, #0xF000, #int10_handler) ;;PIC - mov al, #0x11 ; send initialisation commands - out 0x20, al - out 0xa0, al - mov al, #0x08 - out 0x21, al - mov al, #0x70 - out 0xa1, al - mov al, #0x04 - out 0x21, al - mov al, #0x02 - out 0xa1, al - mov al, #0x01 - out 0x21, al - out 0xa1, al - mov al, #0xb8 - out 0x21, AL ;master pic: unmask IRQ 0, 1, 2, 6
bios/rombios.c post_default_ints: · line 10547
Quoted 10 lines
bios/rombios.c +1
-6-#if BX_USE_PS2_MOUSE - mov al, #0x8f -#else - mov al, #0x9f -#endif - out 0xa1, AL ;slave pic: unmask IRQ 12, 13, 14 + call post_init_pic mov cx, #0xc000 ;; init vga bios mov ax, #0xc780
Looks good. Similar patch is already in the VirtualBox tree [1].
[1] http://www.virtualbox.org/changeset/12494
- Sebastian
PATCH v2 2/6 Add S3 state to DSDT. Handle resume event in the BIOS.
In reply to Gleb Natapov---
bios/acpi-dsdt.dsl | 30 +++++++++++++++++---- bios/acpi-dsdt.hex | 17 +++++++----- bios/rombios.c | 41 +++++++++++++++++++++++++++++ bios/rombios32.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 146 insertions(+), 16 deletions(-)
bios/acpi-dsdt.dsl +24 -6
@@ -531,11 +531,29 @@ DefinitionBlock ( } } - /* S5 = power off state */ - Name (_S5, Package (4) { - 0x00, // PM1a_CNT.SLP_TYP - 0x00, // PM2a_CNT.SLP_TYP - 0x00, // reserved - 0x00, // reserved + /* + * S3 (suspend-to-ram), S4 (suspend-to-disc) and S5 (power-off) type codes: + * must match piix4 emulation. + */ + Name (\_S3, Package (0x04) + { + 0x01, /* PM1a_CNT.SLP_TYP */ + 0x01, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ + }) + Name (\_S4, Package (0x04) + { + Zero, /* PM1a_CNT.SLP_TYP */ + Zero, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ + }) + Name (\_S5, Package (0x04) + { + Zero, /* PM1a_CNT.SLP_TYP */ + Zero, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ }) }
bios/acpi-dsdt.hex +10 -7
@@ -1,22 +1,22 @@ /* * * Intel ACPI Component Architecture - * ASL Optimizing Compiler version 20060912 [Nov 25 2006] + * ASL Optimizing Compiler version 20061109 [May 15 2007] * Copyright (C) 2000 - 2006 Intel Corporation * Supports ACPI Specification Revision 3.0a * - * Compilation of "acpi-dsdt.dsl" - Sun Sep 14 10:27:40 2008 + * Compilation of "acpi-dsdt.dsl" - Mon Oct 27 10:37:05 2008 * * C source code output * */ -unsigned char AmlCode[] = +const unsigned char AmlCode[] = { - 0x44,0x53,0x44,0x54,0xC9,0x07,0x00,0x00, /* 00000000 "DSDT...." */ - 0x01,0x0E,0x42,0x58,0x50,0x43,0x00,0x00, /* 00000008 "..BXPC.." */ + 0x44,0x53,0x44,0x54,0xE1,0x07,0x00,0x00, /* 00000000 "DSDT...." */ + 0x01,0x24,0x42,0x58,0x50,0x43,0x00,0x00, /* 00000008 ".$BXPC.." */ 0x42,0x58,0x44,0x53,0x44,0x54,0x00,0x00, /* 00000010 "BXDSDT.." */ 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ - 0x12,0x09,0x06,0x20,0x10,0x1C,0x5C,0x00, /* 00000020 "... ..\." */ + 0x09,0x11,0x06,0x20,0x10,0x1C,0x5C,0x00, /* 00000020 "... ..\." */ 0x5B,0x80,0x44,0x42,0x47,0x5F,0x01,0x0B, /* 00000028 "[.DBG_.." */ 0x44,0xB0,0x0A,0x04,0x5B,0x81,0x0B,0x44, /* 00000030 "D...[..D" */ 0x42,0x47,0x5F,0x03,0x44,0x42,0x47,0x4C, /* 00000038 "BG_.DBGL" */
@@ -260,6 +260,9 @@ unsigned char AmlCode[] = 0x8B,0x68,0x01,0x54,0x4D,0x50,0x5F,0x82, /* 000007A8 ".h.TMP_." */ 0x54,0x4D,0x50,0x5F,0x60,0x76,0x60,0x70, /* 000007B0 "TMP_`v`p" */ 0x60,0x50,0x52,0x51,0x33,0x08,0x5F,0x53, /* 000007B8 "`PRQ3._S" */ - 0x35,0x5F,0x12,0x06,0x04,0x00,0x00,0x00, /* 000007C0 "5_......" */ + 0x33,0x5F,0x12,0x06,0x04,0x01,0x01,0x00, /* 000007C0 "3_......" */ + 0x00,0x08,0x5F,0x53,0x34,0x5F,0x12,0x06, /* 000007C8 ".._S4_.." */ + 0x04,0x00,0x00,0x00,0x00,0x08,0x5F,0x53, /* 000007D0 "......_S" */ + 0x35,0x5F,0x12,0x06,0x04,0x00,0x00,0x00, /* 000007D8 "5_......" */ 0x00, };
bios/rombios.c +41 -0
65 lines not on this page · raw message
bios/rombios32.c +71 -3
106 lines not on this page · raw message
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 2/6] Add S3 state to DSDT. Handleresume event in the BIOS.
Quoted 17 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>---
bios/acpi-dsdt.dsl | 30 +++++++++++++++++---- bios/acpi-dsdt.hex | 17 +++++++----- bios/rombios.c | 41 +++++++++++++++++++++++++++++ bios/rombios32.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 146 insertions(+), 16 deletions(-)bios/acpi-dsdt.dsl +0
-0@@ -531,11 +531,29 @@ DefinitionBlock ( } }
bios/acpi-dsdt.dsl DefinitionBlock ( · line 537
Quoted 10 lines
bios/acpi-dsdt.dsl +4
-6- /* S5 = power off state */ - Name (_S5, Package (4) { - 0x00, // PM1a_CNT.SLP_TYP - 0x00, // PM2a_CNT.SLP_TYP - 0x00, // reserved - 0x00, // reserved + /* + * S3 (suspend-to-ram), S4 (suspend-to-disc) and S5 (power-off) type codes: + * must match piix4 emulation. + */
Is it suspend-to-disc or suspend-to-disk?
Quoted 4 lines
bios/acpi-dsdt.dsl +4
-0+ Name (\_S3, Package (0x04) + { + 0x01, /* PM1a_CNT.SLP_TYP */ + 0x01, /* PM1b_CNT.SLP_TYP */
bios/acpi-dsdt.dsl DefinitionBlock ( · line 551
Quoted 10 lines
bios/acpi-dsdt.dsl +10
-0+ Zero, /* reserved */ + Zero /* reserved */ + }) + Name (\_S4, Package (0x04) + { + Zero, /* PM1a_CNT.SLP_TYP */ + Zero, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ + })
Do we need \_S4 for S3 support?
Quoted 70 lines
bios/acpi-dsdt.dsl +6
-0+ Name (\_S5, Package (0x04) + { + Zero, /* PM1a_CNT.SLP_TYP */ + Zero, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ }) }bios/acpi-dsdt.hex +10
-7@@ -1,22 +1,22 @@ /* * * Intel ACPI Component Architecture - * ASL Optimizing Compiler version 20060912 [Nov 25 2006] + * ASL Optimizing Compiler version 20061109 [May 15 2007] * Copyright (C) 2000 - 2006 Intel Corporation * Supports ACPI Specification Revision 3.0a * - * Compilation of "acpi-dsdt.dsl" - Sun Sep 14 10:27:40 2008 + * Compilation of "acpi-dsdt.dsl" - Mon Oct 27 10:37:05 2008 * * C source code output * */ -unsigned char AmlCode[] = +const unsigned char AmlCode[] = { - 0x44,0x53,0x44,0x54,0xC9,0x07,0x00,0x00, /* 00000000 "DSDT...." */ - 0x01,0x0E,0x42,0x58,0x50,0x43,0x00,0x00, /* 00000008 "..BXPC.." */ + 0x44,0x53,0x44,0x54,0xE1,0x07,0x00,0x00, /* 00000000 "DSDT...." */ + 0x01,0x24,0x42,0x58,0x50,0x43,0x00,0x00, /* 00000008 ".$BXPC.." */ 0x42,0x58,0x44,0x53,0x44,0x54,0x00,0x00, /* 00000010 "BXDSDT.." */ 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ - 0x12,0x09,0x06,0x20,0x10,0x1C,0x5C,0x00, /* 00000020 "... ..\." */ + 0x09,0x11,0x06,0x20,0x10,0x1C,0x5C,0x00, /* 00000020 "... ..\." */ 0x5B,0x80,0x44,0x42,0x47,0x5F,0x01,0x0B, /* 00000028 "[.DBG_.." */ 0x44,0xB0,0x0A,0x04,0x5B,0x81,0x0B,0x44, /* 00000030 "D...[..D" */ 0x42,0x47,0x5F,0x03,0x44,0x42,0x47,0x4C, /* 00000038 "BG_.DBGL" */@@ -260,6 +260,9 @@ unsigned char AmlCode[] = 0x8B,0x68,0x01,0x54,0x4D,0x50,0x5F,0x82, /* 000007A8 ".h.TMP_." */ 0x54,0x4D,0x50,0x5F,0x60,0x76,0x60,0x70, /* 000007B0 "TMP_`v`p" */ 0x60,0x50,0x52,0x51,0x33,0x08,0x5F,0x53, /* 000007B8 "`PRQ3._S" */ - 0x35,0x5F,0x12,0x06,0x04,0x00,0x00,0x00, /* 000007C0 "5_......" */ + 0x33,0x5F,0x12,0x06,0x04,0x01,0x01,0x00, /* 000007C0 "3_......" */ + 0x00,0x08,0x5F,0x53,0x34,0x5F,0x12,0x06, /* 000007C8 ".._S4_.." */ + 0x04,0x00,0x00,0x00,0x00,0x08,0x5F,0x53, /* 000007D0 "......_S" */ + 0x35,0x5F,0x12,0x06,0x04,0x00,0x00,0x00, /* 000007D8 "5_......" */ 0x00, };bios/rombios.c +10
-0@@ -2198,6 +2198,31 @@ debugger_off()outb (0xfedc ,0x00 ); } +void +s3_resume () +{ +Bit32u s3_wakeup_vector; +Bit8u s3_resume_flag; + + s3_resume_flag =read_byte (0x40 ,0xb0 ); + s3_wakeup_vector =read_dword (0x40 ,0xb2 ); + +BX_INFO ("S3 resume called %x 0x%lx\n" , s3_resume_flag, s3_wakeup_vector);
bios/rombios.c debugger_off() · line 2220
Quoted 10 lines
bios/rombios.c +10
-0+if (s3_resume_flag !=0xFE || !s3_wakeup_vector) +return ; + +write_byte (0x40 ,0xb0 ,0 ); + +/* setup wakeup vector */ +write_word (0x40 ,0xb6 , (s3_wakeup_vector &0xF ));/* IP */ +write_word (0x40 ,0xb8 , (s3_wakeup_vector >>4 ));/* CS */ + +BX_INFO ("S3 resume jump to %x:%x\n" , *(Bit16u *)0x04b8 , *(Bit16u *)0x04b6 );
Is DS always 0x0 here?
Maybe use s3_wakeup_vector & 0xF and s3_wakeup_vector >> 4?
Quoted 9 lines
bios/rombios.c +5
-0+ASM_START + jmpf [0x04b6] +ASM_END +} +#if BX_USE_ATADRV // ---------------------------------------------------------------------------
bios/rombios.c retf_post_0x467: · line 9114
Quoted 9 lines
bios/rombios.c +6
-0@@ -9081,6 +9106,12 @@ retf_post_0x467: mov ss, [0x469] retf +s3_post: +#if BX_ROMBIOS32 + call rombios32_init +#endif + call _s3_resume + hlt
Why HLT here? Is IF always 0?
I think we can use BX_PANIC instead:BX_PANIC("Returned from s3_resume.\n");
Quoted 61 lines
;--------------------
eoi_both_pics:bios/rombios.c +10
-0@@ -10005,6 +10036,10 @@ rombios32_05: ;; init the stack pointer mov esp, #0x00080000 + ;; pass pointer to s3_resume_flag and s3_resume_vector to rombios32 + push #0x04b0 + push #0x04b2 + ;; call rombios32 code mov eax, #0x00040000call eax@@ -10375,6 +10410,12 @@ normal_post:mov ds, ax mov ss, ax + ;; Save shutdown status + mov 0x04b0, bl + + cmp bl, #0xfe + jz s3_post + ;; zero out BIOS data area (40:00..40:ff)mov es, ax mov cx, #0x0080 ;; 128 wordsbios/rombios32.c +15
-1@@ -180,6 +180,20 @@ void *memmove(void *d1, const void *s1, size_t len)return d1; } +int memcmp (const void *s1,const void *s2,size_t len) +{ +const int8_t *p1 = s1; +const int8_t *p2 = s2; + +while (len--) { +int r = *p1++ - *p2++; +if (r) +return r; + } + +return 0 ; +} +size_t strlen (const char *s) {const char *s1;@@ -644,7 +658,7 @@ static void bios_shadow_init(PCIDevice *d) {int v; -if (find_bios_table_area () <0 ) +if (bios_table_cur_addr ==0 )return ;/* remap the BIOS to shadow RAM an keep it read/write while we
bios/rombios32.c void acpi_bios_init(void) · line 1478
Quoted 5 lines
bios/rombios32.c +1
-1@@ -1461,7 +1475,7 @@ void acpi_bios_init(void)memset (facs,0 ,sizeof (*facs));memcpy (facs->signature,"FACS" ,4 ); facs->length =cpu_to_le32 (sizeof (*facs)); - +BX_INFO ("Firmware waking vector %p\n" , &facs->firmware_waking_vector);
Please keep the empty line before /* DSDT */
Quoted 5 lines
bios/rombios32.c +0
-0/* DSDT */ memcpy (dsdt, AmlCode,sizeof (AmlCode));@@ -2011,9 +2025,48 @@ void smbios_init(void)BX_INFO ("SMBIOS table addr=0x%08lx\n" , (unsigned long )start);
bios/rombios32.c void smbios_init(void) · line 2034
Quoted 10 lines
bios/rombios32.c +7
-1} -void rombios32_init (void ) +static uint32_t find_resume_vector (void ) +{ +unsigned long addr, start, end; + +#ifdef BX_USE_EBDA_TABLES + start =align (ebda_cur_addr,16 ); + end =0xa0000 <<4 ;
0xA00000? 10MB?
Quoted 39 lines
bios/rombios32.c +33
-0+#else +if (bios_table_cur_addr ==0 ) +return 0 ; + start =align (bios_table_cur_addr,16 ); + end = bios_table_end_addr; +#endif + +for (addr = start; addr < end; addr +=16 ) { +if (!memcmp ((void *)addr,"RSD PTR " ,8 )) { +struct rsdp_descriptor *rsdp = (void *)addr; +struct rsdt_descriptor_rev1 *rsdt = (void *)rsdp->rsdt_physical_address; +struct fadt_descriptor_rev1 *fadt = (void *)rsdt->table_offset_entry[0 ]; +struct facs_descriptor_rev1 *facs = (void *)fadt->firmware_ctrl; +return facs->firmware_waking_vector; + } + } + +return 0 ; +} + +static void find_440fx (PCIDevice *d) +{ +uint16_t vendor_id, device_id; + + vendor_id =pci_config_readw (d,PCI_VENDOR_ID ); + device_id =pci_config_readw (d,PCI_DEVICE_ID ); + +if (vendor_id ==PCI_VENDOR_ID_INTEL && device_id ==PCI_DEVICE_ID_INTEL_82441 ) + i440_pcidev = *d; +} + +void rombios32_init (uint32_t *s3_resume_vector,uint8_t *shutdown_flag) {BX_INFO ("Starting rombios32\n" ); +BX_INFO ("Shutdown flag %x\n" , *shutdown_flag);#ifdef BX_QEMU qemu_cfg_port =qemu_cfg_port_probe ();
bios/rombios32.c void rombios32_init(void) · line 2081
Quoted 4 lines
bios/rombios32.c +1
-0@@ -2025,6 +2078,21 @@ void rombios32_init(void)smp_probe (); +find_bios_table_area ();
The return value is no longer used, remove it?
Quoted 8 lines
bios/rombios32.c +7
-0+ +if (*shutdown_flag ==0xfe ) { + *s3_resume_vector =find_resume_vector (); +if (!*s3_resume_vector) { +BX_INFO ("This is S3 resume but wakeup vector is NULL\n" ); + }else { +BX_INFO ("S3 resume vector %p\n" , *s3_resume_vector);
bios/rombios32.c void rombios32_init(void) · line 2098
Quoted 10 lines
bios/rombios32.c +7
-0+/* redirect bios read access to RAM */ +pci_for_each_device (find_440fx); +bios_lock_shadow_ram ();/* bios is already copied */ +return ; + } + } +pci_bios_init ();if (bios_table_cur_addr !=0 ) {
- Sebastian
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 2/6] Add S3 state to DSDT. Handleresume event in the BIOS.
Quoted 15 lines · Sebastian Herbszt
Quoted 4 lines
bios/acpi-dsdt.dsl +4
-0+ Name (\_S3, Package (0x04) + { + 0x01, /* PM1a_CNT.SLP_TYP */ + 0x01, /* PM1b_CNT.SLP_TYP */bios/acpi-dsdt.dsl DefinitionBlock ( · line 551
Quoted 10 lines
bios/acpi-dsdt.dsl +10
-0+ Zero, /* reserved */ + Zero /* reserved */ + }) + Name (\_S4, Package (0x04) + { + Zero, /* PM1a_CNT.SLP_TYP */ + Zero, /* PM1b_CNT.SLP_TYP */ + Zero, /* reserved */ + Zero /* reserved */ + })
Quoted 2 lines
Do we need \_S4 for S3 support?
Strictly saying no we don't, but S4 is supported by the chipset we emulate (it is the same as power-off), so why don't advertise it explicitly?
Other comments are addressed in v3 of the patch series.
--
Gleb.
PATCH v2 3/6 Preserve memory content during SMM init.
In reply to Gleb Natapov---
bios/rombios32.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
bios/rombios32.c +8 -2
@@ -731,6 +731,12 @@ static void smm_init(PCIDevice *d) value =pci_config_readl (d,0x58 );if ((value & (1 <<25 )) ==0 ) { +/* enable the SMM memory window */ +pci_config_writeb (&i440_pcidev,0x72 ,0x02 |0x48 ); + +/* save original memory content */ +memcpy ((void *)0xa8000 , (void *)0x38000 ,0x8000 ); +/* copy the SMM relocation code */ memcpy ((void *)0x38000 , &smm_relocation_start, &smm_relocation_end - &smm_relocation_start);
@@ -747,8 +753,8 @@ static void smm_init(PCIDevice *d)/* wait until SMM code executed */ while (inb (0xb3 ) !=0x00 ); -/* enable the SMM memory window */ -pci_config_writeb (&i440_pcidev,0x72 ,0x02 |0x48 ); +/* restore original memory content */ +memcpy ((void *)0x38000 , (void *)0xa8000 ,0x8000 );/* copy the SMM code */ memcpy((void *)0xa8000, &smm_code_start,
PATCH v2 4/6 Execute rombios32 code from rom address 0xe0000.
In reply to Gleb Natapov---
bios/Makefile.in | 1 + bios/rombios.c | 17 +---------------- bios/rombios32.ld | 8 +++----- bios/rombios32start.S | 9 ++++++++- 4 files changed, 13 insertions(+), 22 deletions(-)
bios/Makefile.in +1 -0
@@ -106,6 +106,7 @@ rombios32.o: rombios32.c acpi-dsdt.hex ifeq ("1", "0") acpi-dsdt.hex: acpi-dsdt.dsl iasl -tc -p $@ $< + sed -i -e's/^unsigned/const unsigned/' $@ endif rombios32start.o: rombios32start.S
bios/rombios.c +1 -16
@@ -10026,13 +10026,6 @@ rombios32_05: mov gs, ax cld - ;; copy rombios32 code to ram (ram offset = 1MB) - mov esi, #0xfffe0000 - mov edi, #0x00040000 - mov ecx, #0x10000 / 4 -rep - movsd - ;; init the stack pointer mov esp, #0x00080000
@@ -10041,17 +10034,9 @@ rombios32_05: push #0x04b2 ;; call rombios32 code - mov eax, #0x00040000 + mov eax, #0x000e0000call eax - ;; reset the memory (some boot loaders such as syslinux suppose - ;; that the memory is set to zero) - mov edi, #0x00040000 - mov ecx, #0x40000 / 4 - xor eax, eax - rep - stosd - ;; return to 16 bit protected mode first db 0xea dd rombios32_10
bios/rombios32.ld +3 -5
@@ -3,14 +3,12 @@ OUTPUT_ARCH(i386) ENTRY(_start); SECTIONS { - . = 0x00040000; + . = 0x000e0000; .text : { *(.text) } .rodata : { *(.rodata) } - . = ALIGN(4096); - .data : { *(.data) } - __bss_start = . ; - .bss : { *(.bss) *(COMMON) } _end = . ; + .data 0x700 : AT (_end) { __data_start = .; *(.data); __data_end = .;} + .bss : { __bss_start = .; *(.bss) *(COMMON); __bss_end = .;} /DISCARD/ : { *(.stab) *(.stabstr) *(.comment)
bios/rombios32start.S +8 -1
@@ -32,10 +32,17 @@ _start: /* clear bss section */ xor %eax, %eax mov $__bss_start, %edi - mov $_end, %ecx + mov $__bss_end, %ecx sub %edi, %ecx rep stosb + /* copy data section */ + mov $_end, %esi + mov $__data_start, %edi + mov $__data_end, %ecx + sub %edi, %ecx + rep movsb + jmp rombios32_init .code16
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 4/6] Execute rombios32 code from romaddress 0xe0000.
Quoted 70 lines · Gleb Natapov
Signed-off-by Gleb Natapov <[email protected]>---
bios/Makefile.in | 1 + bios/rombios.c | 17 +---------------- bios/rombios32.ld | 8 +++----- bios/rombios32start.S | 9 ++++++++- 4 files changed, 13 insertions(+), 22 deletions(-)bios/Makefile.in +0
-0@@ -106,6 +106,7 @@ rombios32.o: rombios32.c acpi-dsdt.hex ifeq ("1", "0")acpi-dsdt.hex: acpi-dsdt.dsl
iasl -tc -p $@ $<
+ sed -i -e's/^unsigned/const unsigned/' $@
endifrombios32start.o:
rombios32start.Sbios/rombios.c +1
-16@@ -10026,13 +10026,6 @@ rombios32_05: mov gs, ax cld - ;; copy rombios32 code to ram (ram offset = 1MB) - mov esi, #0xfffe0000 - mov edi, #0x00040000 - mov ecx, #0x10000 / 4 -rep - movsd - ;; init the stack pointer mov esp, #0x00080000@@ -10041,17 +10034,9 @@ rombios32_05: push #0x04b2 ;; call rombios32 code - mov eax, #0x00040000 + mov eax, #0x000e0000call eax - ;; reset the memory (some boot loaders such as syslinux suppose - ;; that the memory is set to zero) - mov edi, #0x00040000 - mov ecx, #0x40000 / 4 - xor eax, eax - rep - stosd - ;; return to 16 bit protected mode first db 0xea dd rombios32_10bios/rombios32.ld +0
-0@@ -3,14 +3,12 @@ OUTPUT_ARCH(i386) ENTRY(_start);SECTIONS
{bios/rombios32.ld +1
-1- . = 0x00040000; + . = 0x000e0000; .text : { *(.text) } .rodata : { *(.rodata) }
bios/rombios32.ld OUTPUT_ARCH(i386) · line 14
Quoted 10 lines
bios/rombios32.ld +2
-4- . = ALIGN(4096); - .data : { *(.data) } - __bss_start = . ; - .bss : { *(.bss) *(COMMON) } _end = . ; + .data 0x700 : AT (_end) { __data_start = .; *(.data); __data_end = .;} + .bss : { __bss_start = .; *(.bss) *(COMMON); __bss_end = .;} /DISCARD/ : { *(.stab) *(.stabstr) *(.comment)
The .data section is currently empty because all data is read-only and put into .rodata, .rodata.str1.1 and .rodata.str1.4. As soon as we put something into .data we get a link error because .data now overlaps .rodata.str1.1. The error is gone if we put all .rodata input sections into .rodata output
section with ".rodata : { *(.rodata*)".
bios/rombios32start.S _start: · line 37
Quoted 12 lines
bios/rombios32start.S +1
-1@@ -32,10 +32,17 @@ _start: /* clear bss section */ xor %eax, %eax mov $__bss_start, %edi - mov $_end, %ecx + mov $__bss_end, %ecx sub %edi, %ecx rep stosb
We do overwrite data at 0x700 here. Is this acceptable for S3 resume?
bios/rombios32start.S _start: · line 45
Quoted 7 lines
bios/rombios32start.S +7
-0+ /* copy data section */ + mov $_end, %esi + mov $__data_start, %edi + mov $__data_end, %ecx + sub %edi, %ecx + rep movsb +
As described above this is currently a no-op, because __data_start = __data_end = 0x700.
bios/rombios32start.S _start:
Quoted 4 lines
bios/rombios32start.S +0
-0jmp rombios32_init .code16
- Sebastian
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 4/6] Execute rombios32 code from romaddress 0xe0000.
Quoted 19 lines · Sebastian Herbszt
Quoted 19 lines
index c7f6066..113a2c0 100644
bios/rombios32.ld +0
-0@@ -3,14 +3,12 @@ OUTPUT_ARCH(i386) ENTRY(_start);SECTIONS
{bios/rombios32.ld +3
-5- . = 0x00040000; + . = 0x000e0000; .text : { *(.text) } .rodata : { *(.rodata) } - . = ALIGN(4096); - .data : { *(.data) } - __bss_start = . ; - .bss : { *(.bss) *(COMMON) } _end = . ; + .data 0x700 : AT (_end) { __data_start = .; *(.data); __data_end = .;} + .bss : { __bss_start = .; *(.bss) *(COMMON); __bss_end = .;} /DISCARD/ : { *(.stab)
Quoted 9 lines
Quoted 2 lines
*(.stabstr) *(.comment)The .data section is currently empty because all data is read-only and put into .rodata, .rodata.str1.1 and .rodata.str1.4. As soon as we put something into .data we get a link error because .data now overlaps .rodata.str1.1. The error is gone if we put all .rodata input sections into .rodata output
section with ".rodata : { *(.rodata*)".
Oops. I'll fix that. Worked for me in KVM bios even though its .data is not empty, but now I see that it worked accidentally because there is ALIGN after .rodata there.
Quoted 6 lines
Quoted 6 lines
bios/rombios32start.S +0
-0@@ -32,10 +32,17 @@ _start: /* clear bss section */
Quoted 9 lines
bios/rombios32start.S _start: · line 37
Quoted 6 lines
bios/rombios32start.S +1
-1xor %eax, %eax mov $__bss_start, %edi - mov $_end, %ecx + mov $__bss_end, %ecx sub %edi, %ecx rep stosbWe do overwrite data at
0x700here. Is this acceptable for S3 resume?
First page is reserved for BIOS use.
Quoted 11 lines
bios/rombios32start.S _start: · line 45
Quoted 7 lines
bios/rombios32start.S +7
-0+ /* copy data section */ + mov $_end, %esi + mov $__data_start, %edi + mov $__data_end, %ecx + sub %edi, %ecx + rep movsb +As described above this is currently a no-op, because
__data_start=__data_end=0x700.
I know, but do we want to remember to add this after changing C code? There is no harm to add it here and let it do nothing, and don't worry about adding .data variable later.
--
Gleb.
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 4/6] Execute rombios32 code fromromaddress 0xe0000.
Quoted 16 lines · Gleb Natapov
Quoted 6 lines · Sebastian Herbszt
Quoted 6 lines
bios/rombios32start.S +0
-0@@ -32,10 +32,17 @@ _start: /* clear bss section */Quoted 9 lines
bios/rombios32start.S _start: · line 37
Quoted 6 lines
bios/rombios32start.S +1
-1xor %eax, %eax mov $__bss_start, %edi - mov $_end, %ecx + mov $__bss_end, %ecx sub %edi, %ecx rep stosbWe do overwrite data at
0x700here. Is this acceptable for S3 resume?
Quoted 1 line
First page is reserved for BIOS use.
I might have missed something, but Ralf Brown's MEMORY MAP Release 61 says "MEM 0070h:0000h - DOS 2+ IO.SYS LOAD ADDRESS".
Which specification do you refer to?
- Sebastian
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 4/6] Execute rombios32 code fromromaddress 0xe0000.
Quoted 17 lines · Sebastian Herbszt
Quoted 16 lines · Gleb Natapov
Quoted 15 lines · Sebastian Herbszt
bios/rombios32start.S _start: · line 37
Quoted 12 lines
bios/rombios32start.S +1
-1@@ -32,10 +32,17 @@ _start: /* clear bss section */ xor %eax, %eax mov $__bss_start, %edi - mov $_end, %ecx + mov $__bss_end, %ecx sub %edi, %ecx rep stosbWe do overwrite data at
0x700here. Is this acceptable for S3 resume?
Quoted 7 lines
Quoted 1 line
First page is reserved for BIOS use.
I might have missed something, but Ralf Brown's MEMORY MAP Release 61 says "MEM 0070h:0000h - DOS 2+ IO.SYS LOAD ADDRESS".
Which specification do you refer to?
DOS does not support S3 :). Linux reserve first page for BIOS use (as can be seed in the code). As far as I know Windows doesn't touch even more of low memory.
--
Gleb.
PATCH v2 5/6 Don't use unreserved memory in BIOS.
In reply to Gleb NatapovUse only first page and last page of low memory. OSes assumes that first page is used by bios and last page is reserved in e820 map.
---
bios/rombios.c | 6 +++--- bios/rombios.h | 1 - bios/rombios32.c | 11 ++++------- bios/rombios32start.S | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-)
bios/rombios.c +3 -3
@@ -4541,7 +4541,7 @@ ASM_END {case 0 :set_e820_range (ES , regs.u.r16.di, -0x0000000L ,0x0009fc00L ,1 ); +0x0000000L ,0x0009f000L ,1 ); regs.u.r32.ebx =1 ; regs.u.r32.eax =0x534D4150 ; regs.u.r32.ecx =0x14 ;
@@ -4550,7 +4550,7 @@ ASM_ENDbreak ;case 1 :set_e820_range (ES , regs.u.r16.di, -0x0009fc00L ,0x000a0000L ,2 ); +0x0009f000L ,0x000a0000L ,2 ); regs.u.r32.ebx =2 ; regs.u.r32.eax =0x534D4150 ; regs.u.r32.ecx =0x14 ;
@@ -10027,7 +10027,7 @@ rombios32_05: cld ;; init the stack pointer - mov esp, #0x00080000 + mov esp, #0x9fbf0 ;; pass pointer to s3_resume_flag and s3_resume_vector to rombios32 push #0x04b0
bios/rombios.h +0 -1
@@ -56,7 +56,6 @@#define ACPI_DATA_SIZE 0x00010000L#define PM_IO_BASE 0xb000#define SMB_IO_BASE 0xb100 -#define CPU_COUNT_ADDR 0xf000// Define the application NAME #if defined(BX_QEMU )
bios/rombios32.c +4 -7
@@ -57,7 +57,7 @@ typedef unsigned long long uint64_t;#define APIC_ENABLED 0x0100 -#define AP_BOOT_ADDR 0x10000 +#define AP_BOOT_ADDR 0x9f000#define MPTABLE_MAX_SIZE 0x00002000#define SMI_CMD_IO_ADDR 0xb2
@@ -392,7 +392,7 @@ void delay_ms(int n) } } -int smp_cpus; +uint16_t smp_cpus;uint32_t cpuid_signature;uint32_t cpuid_features;uint32_t cpuid_ext_features;
@@ -495,7 +495,7 @@ void smp_probe(void) {uint32_t val, sipi_vector; - smp_cpus =1 ; +writew (&smp_cpus,1 );if (cpuid_features &CPUID_APIC ) {/* enable local APIC */
@@ -503,7 +503,6 @@ void smp_probe(void) val |=APIC_ENABLED ;writel (APIC_BASE +APIC_SVR , val); -writew ((void *)CPU_COUNT_ADDR ,1 );/* copy AP boot code */ memcpy ((void *)AP_BOOT_ADDR , &smp_ap_boot_code_start, &smp_ap_boot_code_end - &smp_ap_boot_code_start);
@@ -514,10 +513,8 @@ void smp_probe(void)writel (APIC_BASE +APIC_ICR_LOW ,0x000C4600 | sipi_vector);delay_ms (10 ); - - smp_cpus =readw ((void *)CPU_COUNT_ADDR ); } -BX_INFO ("Found %d cpu(s)\n" , smp_cpus); +BX_INFO ("Found %d cpu(s)\n" ,readw (&smp_cpus)); }/****************************************************/
bios/rombios32start.S +1 -1
@@ -49,7 +49,7 @@ _start: smp_ap_boot_code_start: xor %ax, %ax mov %ax, %ds - lock incw CPU_COUNT_ADDR + lock incw smp_cpus 1: hlt jmp 1b
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 5/6] Don't use unreserved memory in BIOS.
Quoted 2 lines · Gleb Natapov
Use only first page and last page of low memory. OSes assumes that first page is used by bios and last page is reserved in e820 map.
[...]
bios/rombios.c rombios32_05: · line 10030
Quoted 3 lines
;; init the stack pointer
bios/rombios.c +1
-1- mov esp, #0x00080000 + mov esp, #0x9fbf0
Random note - I'm told that some option roms can relocate the EBDA. Setting the stack in the EBDA area will prevent that from working.
I'm not sure if this is really a problem though - a relocated EBDA would likely break bochs bios today. Something to be aware of though.
-Kevin
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 5/6] Don't use unreserved memory in BIOS.
Quoted 1 line · On Friday 07 November 2008 00:25:52 Kevin O'Connor wrote:
Random note - I'm told that some option roms can relocate the EBDA.
Correct; there's even a defined protocol somewhere for doing this. Etherboot/gPXE ROMs won't touch the EBDA, FWIW.
Michael
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 5/6] Don't use unreservedmemory in BIOS.
In reply to Kevin O'ConnorQuoted 10 lines · Kevin O'Connor
Quoted 2 lines · Gleb Natapov
Use only first page and last page of low memory. OSes assumes that first page is used by bios and last page is reserved in e820 map.
[...]
bios/rombios.c rombios32_05: · line 10030
Quoted 3 lines
;; init the stack pointer
bios/rombios.c +1
-1- mov esp, #0x00080000 + mov esp, #0x9fbf0Random note - I'm told that some option roms can relocate the EBDA. Setting the stack in the EBDA area will prevent that from working.
The option rom for the LSI SCSI controller (8xx_64.rom) relocates the EBDA. It moves it from 0x9fc0 to 0x9f00.
Quoted 2 lines
I'm not sure if this is really a problem though - a relocated EBDA would likely break bochs bios today. Something to be aware of though.
EBDA relocation breaks BIOS from cvs. It used to work with my patch "rombios.c - EBDA move fix" available at sf as #1909786.
Since the option rom updates the value at 0040h:000Eh it's possible to use it to set the correct value of esp.
- Sebastian
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 5/6] Don't use unreservedmemory in BIOS.
Quoted 6 lines · Sebastian Herbszt
Quoted 2 lines · Kevin O'Connor
Random note - I'm told that some option roms can relocate the EBDA. Setting the stack in the EBDA area will prevent that from working.
The option rom for the LSI SCSI controller (8xx_64.rom) relocates the EBDA. It moves it from
0x9fc0to0x9f00.
Thanks Sebastian.
Do you know of any document or specification that details how the bios is supposed to handle this case and/or how an option rom should accomplish this?
One of the questions I have, is how the bios should handle the e820 map when this happens. Currently, bochs bios always reserves 1K at 0x9fc0. If the ebda is moved to 0x9f00, should bochs reserve 1K at 0x9f00 or 4K at 0x9f00?
-Kevin
[Qemu-devel] Re: [Bochs-developers] [PATCH v2 5/6] Don't use unreservedmemory inBIOS.
Quoted 5 lines · Kevin O'Connor
Quoted 4 lines · Sebastian Herbszt
Quoted 2 lines · Kevin O'Connor
Random note - I'm told that some option roms can relocate the EBDA. Setting the stack in the EBDA area will prevent that from working.
Quoted 8 lines
Quoted 2 lines
The option rom for the LSI SCSI controller (8xx_64.rom) relocates the EBDA. It moves it from
0x9fc0to0x9f00.Thanks Sebastian.
Do you know of any document or specification that details how the bios is supposed to handle this case and/or how an option rom should accomplish this?
Unfortunatelly not. I discovered this behaviour while playing with the mentioned option rom.
Quoted 4 lines
One of the questions I have, is how the bios should handle the e820 map when this happens. Currently, bochs bios always reserves 1K at
0x9fc0. If the ebda is moved to0x9f00, should bochs reserve 1K at0x9f00or 4K at0x9f00?
Same problem with the simpler INT 12h interface. Currently it returns the value in 0040h:0013h. This is the static value BASE_MEM_IN_K which is 640 - EBDA_SIZE. EBDA_SIZE is the BIOS EBDA size.
Guess the value at 0040h:0013h has to be recalculated after option rom scan based on the EBDA length field. The BIOS set's this to EBDA_SIZE and if an option rom does relocate and resize it it should update that field.
So far the map reported by e820 does match INT 12h (both report 0x9fc0). With this patch e820 reports 0x9f00 and INT 12h sticks to 0x9fc0. I am not sure about the implications tho.
- Sebastian
PATCH v2 6/6 Don't power down vga card on entering S3 state.
In reply to Gleb NatapovThis is needed to fool windows to enter S3. The trick works for XP and Windows2003, but Vista still refuse to allow S3.
---
bios/acpi-dsdt.dsl | 15 ++ bios/acpi-dsdt.hex | 373 ++++++++++++++++++++++++++-------------------------- 2 files changed, 204 insertions(+), 184 deletions(-)
bios/acpi-dsdt.dsl +15 -0
@@ -133,6 +133,21 @@ DefinitionBlock ( } Scope(\_SB.PCI0) { + Device (VGA) { + Name (_ADR, 0x00020000) + Method (_S1D, 0, NotSerialized) + { + Return (0x00) + } + Method (_S2D, 0, NotSerialized) + { + Return (0x00) + } + Method (_S3D, 0, NotSerialized) + { + Return (0x00) + } + } /* PIIX3 ISA bridge */ Device (ISA) {
bios/acpi-dsdt.hex +189 -184
390 lines not on this page · raw message