Add e820 driver
diff --git a/src/lib/e820.c b/src/lib/e820.c
new file mode 100644
index 00000000..3bc230c7
--- /dev/null
+++ b/src/lib/e820.c
@@ -0,0 +1,55 @@
+#include <lib/e820.h>
+#include <lib/real.h>
+#include <lib/blib.h>
+
+struct e820_entry_t e820_map[E820_MAX_ENTRIES];
+
+static const char *e820_type(uint32_t type) {
+ switch (type) {
+ case 1:
+ return "Usable RAM";
+ case 2:
+ return "Reserved";
+ case 3:
+ return "ACPI reclaimable";
+ case 4:
+ return "ACPI NVS";
+ case 5:
+ return "Bad memory";
+ default:
+ return "???";
+ }
+}
+
+void init_e820(void) {
+ struct rm_regs r = {0};
+
+ for (size_t i = 0; i < E820_MAX_ENTRIES; i++) {
+ r.eax = 0xe820;
+ r.ecx = 24;
+ r.edx = 0x534d4150;
+ r.edi = (uint32_t)&e820_map[i];
+ rm_int(0x15, &r, &r);
+
+ if (r.eflags & EFLAGS_CF) {
+ e820_map[i].type = 0;
+ goto done;
+ }
+
+ if (!r.ebx) {
+ e820_map[i+1].type = 0;
+ goto done;
+ }
+ }
+
+ print("e820: Too many entries!\n");
+
+done:
+ for (size_t i = 0; e820_map[i].type; i++) {
+ print("e820: [%X -> %X] : %X <%s>\n",
+ e820_map[i].base,
+ e820_map[i].base + e820_map[i].length,
+ e820_map[i].length,
+ e820_type(e820_map[i].type));
+ }
+}
diff --git a/src/lib/e820.h b/src/lib/e820.h
new file mode 100644
index 00000000..b6fa599f
--- /dev/null
+++ b/src/lib/e820.h
@@ -0,0 +1,19 @@
+#ifndef __LIB__E820_H__
+#define __LIB__E820_H__
+
+#include <stdint.h>
+
+#define E820_MAX_ENTRIES 256
+
+struct e820_entry_t {
+ uint64_t base;
+ uint64_t length;
+ uint32_t type;
+ uint32_t unused;
+} __attribute__((packed));
+
+extern struct e820_entry_t e820_map[E820_MAX_ENTRIES];
+
+void init_e820(void);
+
+#endif
diff --git a/src/lib/real.h b/src/lib/real.h
index d577b3c8..4d9573b0 100644
--- a/src/lib/real.h
+++ b/src/lib/real.h
@@ -9,6 +9,7 @@
#define rm_desegment(seg, off) (((uint32_t)(seg) << 4) + (uint32_t)(off))
#define EFLAGS_CF (1 << 0)
+#define EFLAGS_ZF (1 << 6)
struct rm_regs {
uint32_t eflags;
