rulimine/stage23/sys/e820.s2.c

50 lines
916 B
C
Raw Normal View History

2021-03-02 12:23:43 +03:00
#if defined (bios)
2020-05-03 00:38:57 +03:00
#include <stdint.h>
#include <stddef.h>
2020-09-18 21:02:10 +03:00
#include <sys/e820.h>
2020-03-27 03:59:11 +03:00
#include <lib/real.h>
#include <lib/blib.h>
2020-05-10 01:38:27 +03:00
#include <lib/print.h>
2020-09-20 13:03:44 +03:00
#include <mm/pmm.h>
2020-03-27 03:59:11 +03:00
struct e820_entry_t *e820_map = NULL;
2020-05-03 00:38:57 +03:00
size_t e820_entries;
2020-03-27 03:59:11 +03:00
2020-05-03 00:38:57 +03:00
void init_e820(void) {
2020-03-27 03:59:11 +03:00
struct rm_regs r = {0};
load_up:
// Figure out the number of entries
2020-05-03 00:38:57 +03:00
for (size_t i = 0; ; i++) {
2020-05-01 00:59:14 +03:00
struct e820_entry_t entry;
2020-03-27 03:59:11 +03:00
r.eax = 0xe820;
r.ecx = 24;
r.edx = 0x534d4150;
2020-05-01 00:59:14 +03:00
r.edi = (uint32_t)&entry;
2020-03-27 03:59:11 +03:00
rm_int(0x15, &r, &r);
if (r.eflags & EFLAGS_CF) {
2020-05-03 00:38:57 +03:00
e820_entries = i;
2020-05-01 00:59:14 +03:00
break;
2020-03-27 03:59:11 +03:00
}
if (e820_map)
e820_map[i] = entry;
2020-03-27 03:59:11 +03:00
if (!r.ebx) {
2020-05-03 00:38:57 +03:00
e820_entries = ++i;
2020-05-01 00:59:14 +03:00
break;
2020-03-27 03:59:11 +03:00
}
2020-05-01 00:59:14 +03:00
}
if (e820_map)
return;
e820_map = conv_mem_alloc(sizeof(struct e820_entry_t) * e820_entries);
goto load_up;
2020-03-27 03:59:11 +03:00
}
2021-03-02 12:23:43 +03:00
#endif