aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-07-17 12:15:16 +0100
committerMatt Fleming <matt.fleming@intel.com>2013-07-17 18:29:16 +0100
commit787d7e568fe08d7080d2cd03cd9ee27c327eca67 (patch)
tree7364accf7bce6fc99929d4cee40067de3d2f24b3 /com32/lib
parentba638fd9bf72b0c786c88909014136cfa641a147 (diff)
downloadsyslinux-787d7e568fe08d7080d2cd03cd9ee27c327eca67.tar.gz
syslinux-787d7e568fe08d7080d2cd03cd9ee27c327eca67.tar.xz
syslinux-787d7e568fe08d7080d2cd03cd9ee27c327eca67.zip
memscan: build a linked list of memory scanners
By registering memory scanners at runtime we can support multiple memory scanner functions, which helps us to isolate them and keep things modular, only registering them for specific platform/derivative combinations. This is preparation for adding a memory scanner that is specific to PXELINUX on bios and understands when the memory region occupied by the PXE stack can be reused. Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'com32/lib')
-rw-r--r--com32/lib/syslinux/memscan.c146
1 files changed, 27 insertions, 119 deletions
diff --git a/com32/lib/syslinux/memscan.c b/com32/lib/syslinux/memscan.c
index 2fa14a23..fdb72749 100644
--- a/com32/lib/syslinux/memscan.c
+++ b/com32/lib/syslinux/memscan.c
@@ -32,136 +32,44 @@
* Query the system for free memory
*/
-#include <assert.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <com32.h>
-
#include <syslinux/memscan.h>
-#include <syslinux/firmware.h>
-struct e820_entry {
- uint64_t start;
- uint64_t len;
- uint32_t type;
-};
+static LIST_HEAD(syslinux_memscan_head);
-int bios_scan_memory(scan_memory_callback_t callback, void *data)
+/*
+ * Add a memscan entry to the list.
+ */
+void syslinux_memscan_add(struct syslinux_memscan *entry)
{
- static com32sys_t ireg;
- com32sys_t oreg;
- struct e820_entry *e820buf;
- uint64_t start, len, maxlen;
- int memfound = 0;
- int rv;
- addr_t dosmem;
- const addr_t bios_data = 0x510; /* Amount to reserve for BIOS data */
+ list_add(&entry->next, &syslinux_memscan_head);
+}
- /* Use INT 12h to get DOS memory */
- __intcall(0x12, &__com32_zero_regs, &oreg);
- dosmem = oreg.eax.w[0] << 10;
- if (dosmem < 32 * 1024 || dosmem > 640 * 1024) {
- /* INT 12h reports nonsense... now what? */
- uint16_t ebda_seg = *(uint16_t *) 0x40e;
- if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
- dosmem = ebda_seg << 4;
- else
- dosmem = 640 * 1024; /* Hope for the best... */
- }
- rv = callback(data, bios_data, dosmem - bios_data, SMT_FREE);
- if (rv)
- return rv;
+/*
+ * Build a new memscan entry and add it to the list.
+ */
+int syslinux_memscan_new(int func(scan_memory_callback_t, void *data))
+{
+ struct syslinux_memscan *entry;
- /* First try INT 15h AX=E820h */
- e820buf = lzalloc(sizeof *e820buf);
- if (!e820buf)
+ entry = malloc(sizeof *entry);
+ if (!entry)
return -1;
- ireg.eax.l = 0xe820;
- ireg.edx.l = 0x534d4150;
- ireg.ebx.l = 0;
- ireg.ecx.l = sizeof(*e820buf);
- ireg.es = SEG(e820buf);
- ireg.edi.w[0] = OFFS(e820buf);
-
- do {
- __intcall(0x15, &ireg, &oreg);
-
- if ((oreg.eflags.l & EFLAGS_CF) ||
- (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
- break;
-
- start = e820buf->start;
- len = e820buf->len;
-
- if (start < 0x100000000ULL) {
- /* Don't rely on E820 being valid for low memory. Doing so
- could mean stuff like overwriting the PXE stack even when
- using "keeppxe", etc. */
- if (start < 0x100000ULL) {
- if (len > 0x100000ULL - start)
- len -= 0x100000ULL - start;
- else
- len = 0;
- start = 0x100000ULL;
- }
-
- maxlen = 0x100000000ULL - start;
- if (len > maxlen)
- len = maxlen;
-
- if (len) {
- enum syslinux_memmap_types type;
-
- type = e820buf->type == 1 ? SMT_FREE : SMT_RESERVED;
- rv = callback(data, (addr_t) start, (addr_t) len, type);
- if (rv)
- return rv;
- memfound = 1;
- }
- }
-
- ireg.ebx.l = oreg.ebx.l;
- } while (oreg.ebx.l);
-
- lfree(e820buf);
-
- if (memfound)
- return 0;
-
- /* Next try INT 15h AX=E801h */
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
-
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
- rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, SMT_FREE);
- if (rv)
- return rv;
-
- if (oreg.edx.w[0]) {
- rv = callback(data, (addr_t) 16 << 20,
- oreg.edx.w[0] << 16, SMT_FREE);
- if (rv)
- return rv;
- }
-
- return 0;
- }
-
- /* Finally try INT 15h AH=88h */
- ireg.eax.w[0] = 0x8800;
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
- rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, SMT_FREE);
- if (rv)
- return rv;
- }
-
+ entry->func = func;
+ syslinux_memscan_add(entry);
return 0;
}
int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
{
- return firmware->mem->scan_memory(callback, data);
+ struct syslinux_memscan *entry;
+ int rv = 0;
+
+ list_for_each_entry(entry, &syslinux_memscan_head, next) {
+ rv = entry->func(callback, data);
+ if (rv)
+ break;
+ }
+
+ return rv;
}