rulimine/common/sys/e820.s2.c

45 lines
823 B
C
Raw Normal View History

#if defined (BIOS)
2021-03-02 12:23:43 +03:00
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>
2022-08-27 00:44:47 +03:00
#include <lib/misc.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
#define MAX_E820_ENTRIES 256
struct memmap_entry e820_map[MAX_E820_ENTRIES];
size_t e820_entries = 0;
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};
for (size_t i = 0; i < MAX_E820_ENTRIES; i++) {
struct memmap_entry entry;
2020-05-01 00:59:14 +03:00
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;
return;
2020-03-27 03:59:11 +03:00
}
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;
return;
2020-03-27 03:59:11 +03:00
}
2020-05-01 00:59:14 +03:00
}
2021-12-11 21:58:00 +03:00
panic(false, "Too many E820 entries!");
2020-03-27 03:59:11 +03:00
}
2021-03-02 12:23:43 +03:00
#endif