Skip to contentSkip to conversation

Support for S3 ACPI state (suspend to memory) in BIOS

PATCH In review Gleb Natapov 5 participants 24 messages Nov 27, 2008 – Dec 14, 2008

lore
Share & tools
lore
#0 lore raw

v5 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.

v3:
- Stack pointer for rombios32 code depends on EBDA settings
- Fix .data and .rodata* section overlap
- Various small fixes

v4:
- If resume vector is NULL return to normal POST

v5:
- Call smm_init() at S3 resume boot
- Shadow BIOS before looking for resume vector

---

Gleb Natapov (5):
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.

 bios/Makefile.in      |    1 
 bios/acpi-dsdt.dsl    |   45 +++++-
 bios/acpi-dsdt.hex    |  376 +++++++++++++++++++++++++------------------------
 bios/rombios.c        |   77 ++++++++--
 bios/rombios.h        |    1 
 bios/rombios32.c      |  132 ++++++++++++++---
 bios/rombios32.ld     |   10 +
 bios/rombios32start.S |   11 +
 8 files changed, 414 insertions(+), 239 deletions(-)
Signature · 1 line
        Gleb.
#1 lore raw

PATCH v5 1/5 Add S3 state to DSDT. Handle resume event in the BIOS.

---

 bios/acpi-dsdt.dsl |   30 +++++++++++---
 bios/acpi-dsdt.hex |   17 +++++---
 bios/rombios.c     |   51 ++++++++++++++++++++++++
 bios/rombios32.c   |  111 ++++++++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 184 insertions(+), 25 deletions(-)
bios/acpi-dsdt.dsl +24 -6
index 19ac2f9..280a05e 100644
@@ -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-disk) 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
index 6bc6268..6088b18 100644
@@ -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 +51 -0

81 lines not on this page · raw message

bios/rombios32.c +99 -12

171 lines not on this page · raw message

#2 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Hi Gleb,

On Thu, Nov 27, 2008 at 01:02:25PM +0200, Gleb Natapov wrote:
[...]

bios/rombios.c normal_post: · line 10428

Quoted 10 lines
bios/rombios.c +6 -0
@@ -10375,6 +10420,12 @@ normal_post:
   mov  ds, ax
   mov  ss, ax
 
+  ;; Save shutdown status
+  mov 0x04b0, bl
+
+  cmp bl, #0xfe
+  jz s3_post
+

What sets 40:b0 to 0xfe on a resume?

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

-Kevin

#3 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Quoted 8 lines · Kevin O'Connor

Hi Gleb,

On Thu, Nov 27, 2008 at 01:02:25PM +0200, Gleb Natapov wrote:
[...]

Quoted 4 lines
bios/rombios.c +0 -0
@@ -10375,6 +10420,12 @@ normal_post:
   mov  ds, ax
   mov  ss, ax
 
Quoted 9 lines

bios/rombios.c normal_post: · line 10428

Quoted 6 lines
bios/rombios.c +6 -0
+  ;; Save shutdown status
+  mov 0x04b0, bl
+
+  cmp bl, #0xfe
+  jz s3_post
+

What sets 40:b0 to 0xfe on a resume?

Qemu/Bochs.

Quoted 3 lines

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Oh. I thought it was set to be at the top of the first page, but it has one extra 'f' :( We should change it to be 0xffe instead.

--
Gleb.

#4 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Quoted 9 lines · Gleb Natapov
Quoted 7 lines · Kevin O'Connor

bios/rombios.c normal_post: · line 10427

Quoted 5 lines · Gleb Natapov
bios/rombios.c +5 -0
+  ;; Save shutdown status
+  mov 0x04b0, bl
+
+  cmp bl, #0xfe
+  jz s3_post

What sets 40:b0 to 0xfe on a resume?

Qemu/Bochs.

Thanks.

If we're going to set a flag to indicate a resume, I think we should use more than one byte to ensure we don't invoke that path on random memory. (Maybe something like 0x5333524d -- 'S3RM'?)

Also, can the ACPI dsdt code set the flag instead of the emulators?

-Kevin

#5 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Quoted 11 lines · Kevin O'Connor
Quoted 9 lines · Gleb Natapov
Quoted 7 lines · Kevin O'Connor

bios/rombios.c normal_post: · line 10427

Quoted 5 lines · Gleb Natapov
bios/rombios.c +5 -0
+  ;; Save shutdown status
+  mov 0x04b0, bl
+
+  cmp bl, #0xfe
+  jz s3_post

What sets 40:b0 to 0xfe on a resume?

Qemu/Bochs.

Quoted 8 lines

Thanks.

If we're going to set a flag to indicate a resume, I think we should use more than one byte to ensure we don't invoke that path on random memory. (Maybe something like 0x5333524d -- 'S3RM'?)

Also, can the ACPI dsdt code set the flag instead of the emulators?

Sorry I gave you a wrong answer. Qemu/BOCHS write 0xfe to CMOS offset 0xf (reboot reason) and BIOS saves it into 40:b0. We cannot write into CMOS from AML since windows doesn't like it.

--

Gleb.

#6 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT.Handle resume event in the BIOS.

In reply to Gleb Natapov
Quoted 18 lines · Gleb Natapov
Quoted 8 lines · Kevin O'Connor

Hi Gleb,

On Thu, Nov 27, 2008 at 01:02:25PM +0200, Gleb Natapov wrote:
[...]

Quoted 4 lines
bios/rombios.c +0 -0
@@ -10375,6 +10420,12 @@ normal_post:
   mov  ds, ax
   mov  ss, ax
 
Quoted 9 lines

bios/rombios.c normal_post: · line 10428

Quoted 6 lines
bios/rombios.c +6 -0
+  ;; Save shutdown status
+  mov 0x04b0, bl
+
+  cmp bl, #0xfe
+  jz s3_post
+

What sets 40:b0 to 0xfe on a resume?

Quoted 4 lines

Qemu/Bochs.

Quoted 2 lines

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

insns = instructions?

Quoted 2 lines

Oh. I thought it was set to be at the top of the first page, but it has one extra 'f' :( We should change it to be 0xffe instead.

Can you please explain this memory corruption? Why would "this" (?) corrupt memory used by the stack?

We set the stack to 0xfffe and then call rombios32_init. rombios32_init saves the current ss:sp and then uses own stack, which is now located below the EBDA. 0xfffe is "user memory", same applys to 0xffe so in both cases we use "user memory".

Do you suggest 0xffe because it's in the first page (i assume 4KB pages) reserved for BIOS use?

- Sebastian

#7 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT.Handle resume event in the BIOS.

Quoted 9 lines · Sebastian Herbszt
Quoted 5 lines · Gleb Natapov
Quoted 2 lines · Kevin O'Connor

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Oh. I thought it was set to be at the top of the first page, but it has one extra 'f' :( We should change it to be 0xffe instead.

Can you please explain this memory corruption? Why would "this" (?) corrupt memory used by the stack?

On an s3 resume, memory the OS may be using must not be changed by the bios. When bochs bios detects an s3 resume, it jumps to s3_post with the stack pointer set to 0xfffe. In s3_post, there are "call" instruction which will alter memory at 0xfffe (to store the return address). This could break the resume, because the OS could be using that memory for something else.

Gleb is suggesting that we change that to 0xffe, because the OS can't be using memory at that address and expect s3 resume to work. (The first 4KiB is reserved for BIOS use.)

-Kevin

#8 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT.Handle resume event in the BIOS.

Quoted 18 lines · Kevin O'Connor
Quoted 9 lines · Sebastian Herbszt
Quoted 5 lines · Gleb Natapov
Quoted 2 lines · Kevin O'Connor

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Oh. I thought it was set to be at the top of the first page, but it has one extra 'f' :( We should change it to be 0xffe instead.

Can you please explain this memory corruption? Why would "this" (?) corrupt memory used by the stack?

On an s3 resume, memory the OS may be using must not be changed by the bios. When bochs bios detects an s3 resume, it jumps to s3_post with the stack pointer set to 0xfffe. In s3_post, there are "call" instruction which will alter memory at 0xfffe (to store the return address). This could break the resume, because the OS could be using that memory for something else.

Quoted 4 lines

Gleb is suggesting that we change that to 0xffe, because the OS can't be using memory at that address and expect s3 resume to work. (The first 4KiB is reserved for BIOS use.)

And the patch I've sent set sp to 0xffe only on S3 resume path where stack usage is minimal.

--
Gleb.

#9 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

In reply to Kevin O'Connor
Quoted 2 lines · Kevin O'Connor

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Here is the patch to set stack pointer to a different value on S3 resume:

bios/rombios.c +1 -0
index 7a9c1fd..8e1d3ec 100644
@@ -9114,6 +9114,7 @@ retf_post_0x467:
   retf
 
 s3_post:
+  mov sp, #0xffe
 #if BX_ROMBIOS32
   call rombios32_init
 #endif

--
Gleb.

#10 lore raw

[Qemu-devel] RE: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Sebastian, Kevin, Let me know if any of the patches here should be integrated to Bochs ...

Stanislav

-----Original Message-----
From: Gleb Natapov [mailto:[email protected]]
Sent: Tuesday, December 09, 2008 3:39 PM
To: [email protected]
Cc: Kevin O'Connor; [email protected]
Subject: Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT. Handle resume event in the BIOS.

Quoted 2 lines · Kevin O'Connor

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Here is the patch to set stack pointer to a different value on S3 resume:

bios/rombios.c +1 -0
index 7a9c1fd..8e1d3ec 100644
@@ -9114,6 +9114,7 @@ retf_post_0x467:
   retf
 
 s3_post:
+  mov sp, #0xffe
 #if BX_ROMBIOS32
   call rombios32_init
 #endif

--
Gleb.

----------------------------------------------------------------------------
--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
bochs-developers mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bochs-developers

#11 lore raw

[Qemu-devel] Re: [Bochs-developers] [PATCH v5 1/5] Add S3 state to DSDT.Handle resume event in the BIOS.

In reply to Gleb Natapov
Quoted 14 lines · Gleb Natapov
Quoted 2 lines · Kevin O'Connor

Also, wouldn't this corrupt memory used by the stack (the stack gets set to 0xfffe, and s3_post has call insns in it)?

Here is the patch to set stack pointer to a different value on S3 resume:

bios/rombios.c +0 -0
index 7a9c1fd..8e1d3ec 100644
@@ -9114,6 +9114,7 @@ retf_post_0x467:
  retf
 
Quoted 5 lines

s3_post:
+ mov sp, #0xffe
#if BX_ROMBIOS32
call rombios32_init
#endif

Stanislav, please apply.

- Sebastian

#12 lore raw

PATCH v5 2/5 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
index d9b59d5..4093d88 100644
@@ -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,
#13 lore raw

PATCH v5 3/5 Execute rombios32 code from rom address 0xe0000.

In reply to Gleb Natapov

---

 bios/Makefile.in      |    1 +
 bios/rombios.c        |   17 +----------------
 bios/rombios32.ld     |   10 ++++------
 bios/rombios32start.S |    9 ++++++++-
 4 files changed, 14 insertions(+), 23 deletions(-)
bios/Makefile.in +1 -0
index b055910..af674b4 100644
@@ -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
index a34c6b2..4e555a9 100644
@@ -10036,13 +10036,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
 
@@ -10051,17 +10044,9 @@ rombios32_05:
   push #0x04b2
 
   ;; call rombios32 code
-  mov eax, #0x00040000
+  mov eax, #0x000e0000
   call 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 +4 -6
index c7f6066..ff765c8 100644
@@ -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) }
+        .rodata    : { *(.rodata*) }
         _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
index 601e2b0..1900261 100644
@@ -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
#14 lore raw

PATCH v5 4/5 Don't use unreserved memory in BIOS.

In reply to 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        |   11 +++++++----
 bios/rombios.h        |    1 -
 bios/rombios32.c      |   11 ++++-------
 bios/rombios32start.S |    2 +-
 4 files changed, 12 insertions(+), 13 deletions(-)
bios/rombios.c +7 -4
index 4e555a9..5a56716 100644
@@ -4548,7 +4548,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;
@@ -4557,7 +4557,7 @@ ASM_END
                         break;
                     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;
@@ -10036,8 +10036,11 @@ rombios32_05:
   mov gs, ax
   cld
 
-  ;; init the stack pointer
-  mov esp, #0x00080000
+  ;; init the stack pointer to point below EBDA
+  mov ax, [0x040e]
+  shl eax, #4
+  mov esp, #-0x10
+  add esp, eax
 
   ;; pass pointer to s3_resume_flag and s3_resume_vector to rombios32
   push #0x04b0
bios/rombios.h +0 -1
index f0ed88e..b3df88b 100644
@@ -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
index 4093d88..1d8e0a3 100644
@@ -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
index 1900261..836652c 100644
@@ -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
#15 lore raw

PATCH v5 5/5 Don't power down vga card on entering S3 state.

In reply to Gleb Natapov

This 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
index 280a05e..5fc3636 100644
@@ -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

#16 lore raw
In reply to Gleb Natapov

Hi,

Quoted 4 lines · Gleb Natapov

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.

I see the problem you're facing with the overwrite and it looks there might be a cleaner solution: If you can lock the CPU cache so that writes don't get passed through to RAM, you're free to use any area (with a few contraints) for stack without having to worry about clobbering memory contents there.

That method is called Cache-as-RAM and I'm currently trying to implement it in Qemu. I haven't looked into Bochs yet, but it should be doable there as well.

coreboot (a free x86 firmware/BIOS replacement) is using Cache-as-RAM and I believe quite a few commercial BIOSes use that technique as well.

Regards,
Carl-Daniel

#17 lore raw
Quoted 14 lines · Carl-Daniel Hailfinger

Hi,

Quoted 4 lines · Gleb Natapov

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.

I see the problem you're facing with the overwrite and it looks there might be a cleaner solution: If you can lock the CPU cache so that writes don't get passed through to RAM, you're free to use any area (with a few contraints) for stack without having to worry about clobbering memory contents there.

Quoted 4 lines

That method is called Cache-as-RAM and I'm currently trying to implement it in Qemu. I haven't looked into Bochs yet, but it should be doable there as well.

It would be nice to not worry about stack location. We may try to use it when you changes will work in Qemu and BOCHS.

--
Gleb.

#18 lore raw

In Bochs CPU doesn't have a cache memory emulated to use it as RAM but it is still possible to emulate cache-as-ram mode.
The problem that cache-as-ram mode is very very very processor specific and implementation of it might be different between Intel and AMD for example. Which one to pick up ?
Or might be better to invent some other mode especially for emulation reasons ?

Stanislav

-----Original Message-----
From: Gleb Natapov [mailto:[email protected]]
Sent: Thursday, November 27, 2008 2:36 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [Bochs-developers] [Qemu-devel] [PATCH v5 0/5] Support for S3 ACPI state (suspend to memory) in BIOS

Quoted 14 lines · Carl-Daniel Hailfinger

Hi,

Quoted 4 lines · Gleb Natapov

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.

I see the problem you're facing with the overwrite and it looks there might be a cleaner solution: If you can lock the CPU cache so that writes don't get passed through to RAM, you're free to use any area (with a few contraints) for stack without having to worry about clobbering memory contents there.

Quoted 4 lines

That method is called Cache-as-RAM and I'm currently trying to implement it in Qemu. I haven't looked into Bochs yet, but it should be doable there as well.

It would be nice to not worry about stack location. We may try to use it when you changes will work in Qemu and BOCHS.

--
Gleb.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
bochs-developers mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bochs-developers

#19 lore raw
Quoted 6 lines · Stanislav

In Bochs CPU doesn't have a cache memory emulated to use it as RAM but it is still possible to emulate cache-as-ram mode.
The problem that cache-as-ram mode is very very very processor specific and implementation of it might be different between Intel and AMD for example. Which one to pick up ?

I have worked on Intel, AMD and VIA implementations for Cache-as-RAM. Avi Kivity suggested a simple algorithm which is a catchall for Intel 586, Intel Core 2 Duo, AMD K8, AMD K10 and VIA C7.

Quoted 3 lines

Or might be better to invent some other mode especially for emulation reasons ?

With the catchall emulation, inventing a special mode should be unneeded.

Regards,
Carl-Daniel

Signature · 1 line
http://www.hailfinger.org/
#20 lore raw

What is the catchall emulation ? Could you explain/point me some docs ?

Thanks,
Stanislav

-----Original Message-----
From: Carl-Daniel Hailfinger [mailto:[email protected]]
Sent: Thursday, November 27, 2008 9:08 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [Bochs-developers] [Qemu-devel] [PATCH v5 0/5] Support for S3 ACPI state (suspend to memory) in BIOS

Quoted 1 line · Stanislav

In Bochs CPU doesn't have a cache memory emulated to use it as RAM but it

is

Quoted 2 lines

still possible to emulate cache-as-ram mode.
The problem that cache-as-ram mode is very very very processor specific

and

Quoted 3 lines

implementation of it might be different between Intel and AMD for example. Which one to pick up ?

I have worked on Intel, AMD and VIA implementations for Cache-as-RAM. Avi Kivity suggested a simple algorithm which is a catchall for Intel 586, Intel Core 2 Duo, AMD K8, AMD K10 and VIA C7.

Quoted 3 lines

Or might be better to invent some other mode especially for emulation reasons ?

With the catchall emulation, inventing a special mode should be unneeded.

Regards,
Carl-Daniel

Signature · 13 lines
http://www.hailfinger.org/


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
bochs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bochs-developers
#21 lore raw
Quoted 2 lines · Stanislav

What is the catchall emulation ? Could you explain/point me some docs ?

Sorry, it was only a brief sentence. Basically, if the total size of all cached areas is not bigger than CPU cache size, no cache line will be evicted and the cache behaves like Cache-as-RAM (CAR). That should be doable in Bochs, KVM and Qemu.

Or were you looking for BIOS code to enable CAR? That is indeed processor specific, but any of the existing CAR implementations will work if the catchall emulation is used.

Regards,
Carl-Daniel

Signature · 1 line
http://www.hailfinger.org/
#22 lore raw

Again, I mean Bochs doesn't emulate caches. So what do you mean by catchall emulation ?
To allocate kind of dummy 32K block and use it when CRAM mode and delete immediately after ?
About the way you enable CRAM mode - it would be nice if we agree to use a protocol which real hardware needs.
I still hope to be able to execute real hardware BIOSes on Bochs for example
...

Stanislav

-----Original Message-----
From: Carl-Daniel Hailfinger [mailto:[email protected]]
Sent: Thursday, November 27, 2008 11:05 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [Bochs-developers] [Qemu-devel] [PATCH v5 0/5] Support for S3 ACPI state (suspend to memory) in BIOS

Quoted 2 lines · Stanislav

What is the catchall emulation ? Could you explain/point me some docs ?

Sorry, it was only a brief sentence. Basically, if the total size of all cached areas is not bigger than CPU cache size, no cache line will be evicted and the cache behaves like Cache-as-RAM (CAR). That should be doable in Bochs, KVM and Qemu.

Or were you looking for BIOS code to enable CAR? That is indeed processor specific, but any of the existing CAR implementations will work if the catchall emulation is used.

Regards,
Carl-Daniel

Signature · 13 lines
http://www.hailfinger.org/


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
bochs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bochs-developers
#23 lore raw
Quoted 5 lines · Stanislav

Again, I mean Bochs doesn't emulate caches. So what do you mean by catchall emulation ?
To allocate kind of dummy 32K block and use it when CRAM mode and delete immediately after ?

Yes, exactly. However, the size of the dummy block depends on your cache size. And I have seen Intel CPUs (with 2 MB cache) which used up to 1056 kB of cache during CAR mode.

Quoted 3 lines

About the way you enable CRAM mode - it would be nice if we agree to use a protocol which real hardware needs.

Yes. That is my goal. The problem is that CPU documentation is often a bit ambiguous about how CAR mode is enabled. AFAIK the common denominator is the CARsize <= Cachesize setting. That is really unusual for any point in time (during OS execution) except for the short time where CAR is enabled in the firmware/BIOS.

Quoted 2 lines

I still hope to be able to execute real hardware BIOSes on Bochs for example

That would be cool. The RAM controller emulation may need some tweaking, though.

Regards,
Carl-Daniel

Quoted 29 lines

Stanislav

-----Original Message-----
From: Carl-Daniel Hailfinger [mailto:[email protected]]
Sent: Thursday, November 27, 2008 11:05 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [Bochs-developers] [Qemu-devel] [PATCH v5 0/5] Support for S3 ACPI state (suspend to memory) in BIOS

Quoted 3 lines · Stanislav

What is the catchall emulation ? Could you explain/point me some docs ?

Sorry, it was only a brief sentence. Basically, if the total size of all cached areas is not bigger than CPU cache size, no cache line will be evicted and the cache behaves like Cache-as-RAM (CAR). That should be doable in Bochs, KVM and Qemu.

Or were you looking for BIOS code to enable CAR? That is indeed processor specific, but any of the existing CAR implementations will work if the catchall emulation is used.

Regards,
Carl-Daniel

Signature · 1 line
http://www.hailfinger.org/