Add e820 driver

This commit is contained in:
mintsuki 2020-03-27 01:59:11 +01:00
parent c0129c4d8c
commit f537f64b89
3 changed files with 75 additions and 0 deletions

55
src/lib/e820.c Normal file
View File

@ -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));
}
}

19
src/lib/e820.h Normal file
View File

@ -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

View File

@ -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;