43 lines
855 B
C
Raw Normal View History

2020-05-02 23:38:57 +02:00
#include <stdint.h>
#include <stddef.h>
2020-03-27 01:59:11 +01:00
#include <lib/e820.h>
#include <lib/real.h>
#include <lib/blib.h>
2020-05-10 00:38:27 +02:00
#include <lib/print.h>
2020-06-05 20:57:09 +02:00
#include <lib/memmap.h>
2020-03-27 01:59:11 +01:00
2020-04-30 23:59:14 +02:00
struct e820_entry_t *e820_map;
2020-05-02 23:38:57 +02:00
size_t e820_entries;
2020-03-27 01:59:11 +01:00
2020-05-02 23:38:57 +02:00
void init_e820(void) {
2020-03-27 01:59:11 +01:00
struct rm_regs r = {0};
2020-04-30 23:59:14 +02:00
e820_map = balloc(sizeof(struct e820_entry_t));
2020-05-02 23:38:57 +02:00
for (size_t i = 0; ; i++) {
2020-04-30 23:59:14 +02:00
struct e820_entry_t entry;
2020-03-27 01:59:11 +01:00
r.eax = 0xe820;
r.ecx = 24;
r.edx = 0x534d4150;
2020-04-30 23:59:14 +02:00
r.edi = (uint32_t)&entry;
2020-03-27 01:59:11 +01:00
rm_int(0x15, &r, &r);
2020-04-30 23:59:14 +02:00
e820_map[i] = entry;
2020-03-27 01:59:11 +01:00
if (r.eflags & EFLAGS_CF) {
2020-05-02 23:38:57 +02:00
e820_entries = i;
2020-04-30 23:59:14 +02:00
break;
2020-03-27 01:59:11 +01:00
}
if (!r.ebx) {
2020-05-02 23:38:57 +02:00
e820_entries = ++i;
2020-04-30 23:59:14 +02:00
break;
2020-03-27 01:59:11 +01:00
}
2020-04-30 23:59:14 +02:00
balloc(sizeof(struct e820_entry_t));
}
2020-03-27 01:59:11 +01:00
2020-06-05 20:57:09 +02:00
print("E820 memory map:\n");
print_memmap(e820_map, e820_entries);
2020-03-27 01:59:11 +01:00
}