]> xenbits.xensource.com Git - seabios.git/commitdiff
smm: unify SMM handlers
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 15 May 2014 11:22:29 +0000 (13:22 +0200)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 4 Jun 2014 15:06:58 +0000 (11:06 -0400)
The next patch will add shared code between the initial handler for
SMBASE relocation and the actual SMI handler.  Combine the code of
the two handlers for simplicity.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
src/fw/smm.c

index eccef881c40a83f7f643f5c2e7b403ef43c3af1a..f486c781c855746e51b3e69666e1e55e4bb19761 100644 (file)
 #include "util.h" // smm_setup
 #include "x86.h" // wbinvd
 
-extern u8 smm_relocation_start, smm_relocation_end;
+extern u8 smm_code_start, smm_code_end;
+
 ASM32FLAT(
-    ".global smm_relocation_start, smm_relocation_end\n"
+    ".global smm_code_start, smm_code_end\n"
     "  .code16gcc\n"
+    "smm_code_start:\n"
+    "  mov %cs, %ax\n"
+    "  cmp $0xa000, %ax\n"
+    "  je smm_exit\n"
 
     /* code to relocate SMBASE to 0xa0000 */
-    "smm_relocation_start:\n"
     "  movl $" __stringify(BUILD_SMM_INIT_ADDR) " + 0x7efc, %ebx\n"
     "  addr32 movb (%ebx), %al\n"  /* revision ID to see if x86_64 or x86 */
     "  cmpb $0x64, %al\n"
@@ -39,16 +43,7 @@ ASM32FLAT(
     "  movb $0x00, %al\n"
     "  movw $" __stringify(PORT_SMI_STATUS) ", %dx\n"
     "  outb %al, %dx\n"
-    "  rsm\n"
-    "smm_relocation_end:\n"
-    "  .code32\n"
-    );
-
-extern u8 smm_code_start, smm_code_end;
-ASM32FLAT(
-    ".global smm_code_start, smm_code_end\n"
-    "  .code16gcc\n"
-    "smm_code_start:\n"
+    "smm_exit:\n"
     "  rsm\n"
     "smm_code_end:\n"
     "  .code32\n"
@@ -60,9 +55,9 @@ smm_save_and_copy(void)
     /* save original memory content */
     memcpy((void *)BUILD_SMM_ADDR, (void *)BUILD_SMM_INIT_ADDR, BUILD_SMM_SIZE);
 
-    /* copy the SMM relocation code */
-    memcpy((void *)BUILD_SMM_INIT_ADDR, &smm_relocation_start,
-           &smm_relocation_end - &smm_relocation_start);
+    /* copy the SMM code, which will relocate itself on the first execution */
+    memcpy((void *)BUILD_SMM_INIT_ADDR, &smm_code_start,
+           &smm_code_end - &smm_code_start);
 }
 
 static void