Add e820 driver
This commit is contained in:
parent
c0129c4d8c
commit
f537f64b89
55
src/lib/e820.c
Normal file
55
src/lib/e820.c
Normal 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
19
src/lib/e820.h
Normal 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
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user