Add PMM stubs.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 26 Jul 2009 23:33:13 +0000 (19:33 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 26 Jul 2009 23:33:13 +0000 (19:33 -0400)
Add initial code for Post Memory Manager - it's just the stubs for now.
Also, fix PnP entry point not clearing irqs and direction flags.

Makefile
src/config.h
src/pmm.c [new file with mode: 0644]
src/post.c
src/romlayout.S
src/util.h

index 41e6514d175aa1f12b02eeaf85d95f6e57038b38..2e2ba1dbf46cb7a12eeaafbc394f3f279c10abf4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ OUT=out/
 # Source files
 SRCBOTH=output.c util.c floppy.c ata.c misc.c mouse.c kbd.c pci.c \
         serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
-        pnpbios.c pirtable.c vgahooks.c
+        pnpbios.c pirtable.c vgahooks.c pmm.c
 SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c font.c
 SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
       acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
index 6f1910701311db260b2acd547d3f23f12e0b2a8d..36f2a728dab674fb241580e76ec966e761bfb6f8 100644 (file)
@@ -39,6 +39,8 @@
 #define CONFIG_APMBIOS 1
 // Support PnP BIOS entry point.
 #define CONFIG_PNPBIOS 1
+// Support Post Memory Manager (PMM) entry point.
+#define CONFIG_PMM 0
 // Support int 19/18 system bootup support
 #define CONFIG_BOOT 1
 // Support an interactive boot menu at end of post.
 #define DEBUG_ISR_hwpic1 5
 #define DEBUG_ISR_hwpic2 5
 #define DEBUG_HDL_pnp 1
+#define DEBUG_HDL_pmm 1
 
 #endif // config.h
diff --git a/src/pmm.c b/src/pmm.c
new file mode 100644 (file)
index 0000000..bf53e3b
--- /dev/null
+++ b/src/pmm.c
@@ -0,0 +1,117 @@
+// Post memory manager (PMM) calls
+//
+// Copyright (C) 2009  Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+
+#include "util.h" // checksum
+#include "config.h" // BUILD_BIOS_ADDR
+
+struct pmmheader {
+    u32 signature;
+    u8 version;
+    u8 length;
+    u8 checksum;
+    u16 entry_offset;
+    u16 entry_seg;
+    u8 reserved[5];
+} PACKED;
+
+extern struct pmmheader PMMHEADER;
+
+#define PMM_SIGNATURE 0x4d4d5024 // $PMM
+
+#if CONFIG_PMM
+struct pmmheader PMMHEADER __aligned(16) VAR16EXPORT = {
+    .version = 0x01,
+    .length = sizeof(PMMHEADER),
+    .entry_seg = SEG_BIOS,
+};
+#endif
+
+#define FUNCTION_NOT_SUPPORTED 0xffffffff
+
+// PMM - allocate
+static u32
+handle_pmm00(u16 *args)
+{
+    u32 length = *(u32*)&args[1], handle = *(u32*)&args[3];
+    u16 flags = args[5];
+    dprintf(1, "pmm00: length=%x handle=%x flags=%x\n"
+            , length, handle, flags);
+    // XXX
+    return 0;
+}
+
+// PMM - find
+static u32
+handle_pmm01(u16 *args)
+{
+    u32 handle = *(u32*)&args[1];
+    dprintf(1, "pmm01: handle=%x\n", handle);
+    // XXX
+    return 0;
+}
+
+// PMM - deallocate
+static u32
+handle_pmm02(u16 *args)
+{
+    u32 buffer = *(u32*)&args[1];
+    dprintf(1, "pmm02: buffer=%x\n", buffer);
+    // XXX
+    return 0;
+}
+
+static u32
+handle_pmmXX(u16 *args)
+{
+    return FUNCTION_NOT_SUPPORTED;
+}
+
+u32 VISIBLE16
+handle_pmm(u16 *args)
+{
+    if (! CONFIG_PMM)
+        return FUNCTION_NOT_SUPPORTED;
+
+    u16 arg1 = args[0];
+    dprintf(DEBUG_HDL_pmm, "pmm call arg1=%x\n", arg1);
+
+    switch (arg1) {
+    case 0x00: return handle_pmm00(args);
+    case 0x01: return handle_pmm01(args);
+    case 0x02: return handle_pmm02(args);
+    default:   return handle_pmmXX(args);
+    }
+}
+
+// romlayout.S
+extern void entry_pmm();
+
+void
+pmm_setup()
+{
+    if (! CONFIG_PMM)
+        return;
+
+    dprintf(3, "init PMM\n");
+
+    PMMHEADER.signature = PMM_SIGNATURE;
+    PMMHEADER.entry_offset = (u32)entry_pmm - BUILD_BIOS_ADDR;
+    PMMHEADER.checksum -= checksum(&PMMHEADER, sizeof(PMMHEADER));
+}
+
+void
+pmm_finalize()
+{
+    if (! CONFIG_PMM)
+        return;
+
+    dprintf(3, "finalize PMM\n");
+
+    PMMHEADER.signature = 0;
+    PMMHEADER.entry_offset = 0;
+
+    // XXX - zero low-memory allocations.
+}
index 052edb576e776732cc60adefacdea5811b1f9810..9568ca488680cb83e4989ed7cd9c862086822f48 100644 (file)
@@ -167,6 +167,7 @@ post()
     mtrr_setup();
     smp_probe();
     malloc_setup();
+    pmm_setup();
 
     pnp_setup();
     vga_setup();
@@ -180,8 +181,6 @@ post()
     smm_init();
 
     init_bios_tables();
-    malloc_finalize();
-    memmap_finalize();
 
     boot_setup();
 
@@ -189,6 +188,10 @@ post()
     hard_drive_setup();
 
     optionrom_setup();
+
+    pmm_finalize();
+    malloc_finalize();
+    memmap_finalize();
 }
 
 // 32-bit entry point.
index cbd9483681749555a102ee617742a81246eda408..d430d2878472f4ff679e62fe92343d36c3b9a062 100644 (file)
@@ -270,6 +270,35 @@ entry_post:
  * Misc. entry points.
  ****************************************************************/
 
+// PMM entry point
+        DECLFUNC entry_pmm
+entry_pmm:
+        pushl %esp              // Backup %esp, then clear high bits
+        movzwl %sp, %esp
+        pushfl                  // Save registers clobbered by C code
+        cli
+        cld
+        pushl %eax
+        pushl %ecx
+        pushl %edx
+        pushw %es
+        pushw %ds
+        movw %ss, %cx           // Move %ss to %ds
+        movw %cx, %ds
+        lea 28(%esp), %eax      // %eax points to start of args
+        calll handle_pmm
+        movw %ax, 12(%esp)      // Modify %ax:%dx to return %eax
+        shrl $16, %eax
+        movw %ax, 4(%esp)
+        popw %ds                // Restore saved registers
+        popw %es
+        popl %edx
+        popl %ecx
+        popl %eax
+        popfl
+        popl %esp
+        lretw
+
 // PnP entry points
         DECLFUNC entry_pnp_real
         .global entry_pnp_prot
@@ -281,6 +310,8 @@ entry_pnp_real:
         movzwl %sp, %esp
 1:
         pushfl                  // Save registers clobbered by C code
+        cli
+        cld
         pushl %eax
         pushl %ecx
         pushl %edx
index 8ae54f4d70d38d7dfdd88f6926570500094edc9c..8a43914c88304f0ab2f6d8132b7bb44e6ded2759 100644 (file)
@@ -230,6 +230,10 @@ void init_dma();
 u16 get_pnp_offset();
 void pnp_setup();
 
+// pmm.c
+void pmm_setup();
+void pmm_finalize();
+
 // mtrr.c
 void mtrr_setup(void);