Don't overwrite memory on smm init.

Save/restore memory changed during smm init - this is based on a patch
    committed to bochs bios.
Also, clean up ioport and base memory address definitions for smm.
diff --git a/src/smm.c b/src/smm.c
index dda8d5d..5a79269 100644
--- a/src/smm.c
+++ b/src/smm.c
@@ -21,33 +21,33 @@
 
     /* code to relocate SMBASE to 0xa0000 */
     "smm_relocation_start:\n"
-    "  mov $0x38000 + 0x7efc, %ebx\n"
+    "  mov $" __stringify(BUILD_SMM_INIT_ADDR) " + 0x7efc, %ebx\n"
     "  addr32 mov (%ebx), %al\n"  /* revision ID to see if x86_64 or x86 */
     "  cmp $0x64, %al\n"
     "  je 1f\n"
-    "  mov $0x38000 + 0x7ef8, %ebx\n"
+    "  mov $" __stringify(BUILD_SMM_INIT_ADDR) " + 0x7ef8, %ebx\n"
     "  jmp 2f\n"
     "1:\n"
-    "  mov $0x38000 + 0x7f00, %ebx\n"
+    "  mov $" __stringify(BUILD_SMM_INIT_ADDR) " + 0x7f00, %ebx\n"
     "2:\n"
-    "  movl $0xa0000, %eax\n"
+    "  movl $" __stringify(BUILD_SMM_ADDR) " - 0x8000, %eax\n"
     "  addr32 movl %eax, (%ebx)\n"
     /* indicate to the BIOS that the SMM code was executed */
     "  mov $0x00, %al\n"
-    "  movw $0xb3, %dx\n"
+    "  movw $" __stringify(PORT_SMI_STATUS) ", %dx\n"
     "  outb %al, %dx\n"
     "  rsm\n"
     "smm_relocation_end:\n"
 
     /* minimal SMM code to enable or disable ACPI */
     "smm_code_start:\n"
-    "  movw $0xb2, %dx\n"
+    "  movw $" __stringify(PORT_SMI_CMD) ", %dx\n"
     "  inb %dx, %al\n"
     "  cmp $0xf0, %al\n"
     "  jne 1f\n"
 
     /* ACPI disable */
-    "  mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
+    "  mov $" __stringify(PORT_ACPI_PM_BASE) " + 0x04, %dx\n" /* PMCNTRL */
     "  inw %dx, %ax\n"
     "  andw $~1, %ax\n"
     "  outw %ax, %dx\n"
@@ -59,7 +59,7 @@
     "  jne 2f\n"
 
     /* ACPI enable */
-    "  mov $" __stringify(BUILD_PM_IO_BASE) " + 0x04, %dx\n" /* PMCNTRL */
+    "  mov $" __stringify(PORT_ACPI_PM_BASE) " + 0x04, %dx\n" /* PMCNTRL */
     "  inw %dx, %ax\n"
     "  orw $1, %ax\n"
     "  outw %ax, %dx\n"
@@ -98,28 +98,35 @@
     if (value & (1 << 25))
         return;
 
+    /* enable the SMM memory window */
+    pci_config_writeb(i440_bdf, 0x72, 0x02 | 0x48);
+
+    /* save original memory content */
+    memcpy((void *)BUILD_SMM_ADDR, (void *)BUILD_SMM_INIT_ADDR, BUILD_SMM_SIZE);
+
     /* copy the SMM relocation code */
-    memcpy((void *)0x38000, &smm_relocation_start,
+    memcpy((void *)BUILD_SMM_INIT_ADDR, &smm_relocation_start,
            &smm_relocation_end - &smm_relocation_start);
 
     /* enable SMI generation when writing to the APMC register */
     pci_config_writel(bdf, 0x58, value | (1 << 25));
 
     /* init APM status port */
-    outb(0x01, 0xb3);
+    outb(0x01, PORT_SMI_STATUS);
 
     /* raise an SMI interrupt */
-    outb(0x00, 0xb2);
+    outb(0x00, PORT_SMI_CMD);
 
     /* wait until SMM code executed */
-    while (inb(0xb3) != 0x00)
+    while (inb(PORT_SMI_STATUS) != 0x00)
         ;
 
-    /* enable the SMM memory window */
-    pci_config_writeb(i440_bdf, 0x72, 0x02 | 0x48);
+    /* restore original memory content */
+    memcpy((void *)BUILD_SMM_INIT_ADDR, (void *)BUILD_SMM_ADDR, BUILD_SMM_SIZE);
 
     /* copy the SMM code */
-    memcpy((void *)0xa8000, &smm_code_start, &smm_code_end - &smm_code_start);
+    memcpy((void *)BUILD_SMM_ADDR, &smm_code_start
+           , &smm_code_end - &smm_code_start);
     wbinvd();
 
     /* close the SMM memory window and enable normal SMM */