rulimine/common/sys/e820.s2.c

45 lines
823 B
C
Raw Permalink Normal View History

#if defined (BIOS)
2021-03-02 10:23:43 +01:00
2020-05-02 23:38:57 +02:00
#include <stdint.h>
#include <stddef.h>
2020-09-18 20:02:10 +02:00
#include <sys/e820.h>
2020-03-27 01:59:11 +01:00
#include <lib/real.h>
2022-08-26 23:44:47 +02:00
#include <lib/misc.h>
2020-05-10 00:38:27 +02:00
#include <lib/print.h>
2020-09-20 12:03:44 +02:00
#include <mm/pmm.h>
2020-03-27 01:59:11 +01:00
#define MAX_E820_ENTRIES 256
struct memmap_entry e820_map[MAX_E820_ENTRIES];
size_t e820_entries = 0;
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};
for (size_t i = 0; i < MAX_E820_ENTRIES; i++) {
struct memmap_entry entry;
2020-04-30 23:59:14 +02:00
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);
if (r.eflags & EFLAGS_CF) {
2020-05-02 23:38:57 +02:00
e820_entries = i;
return;
2020-03-27 01:59:11 +01:00
}
e820_map[i] = entry;
2020-03-27 01:59:11 +01:00
if (!r.ebx) {
2020-05-02 23:38:57 +02:00
e820_entries = ++i;
return;
2020-03-27 01:59:11 +01:00
}
2020-04-30 23:59:14 +02:00
}
2021-12-11 19:58:00 +01:00
panic(false, "Too many E820 entries!");
2020-03-27 01:59:11 +01:00
}
2021-03-02 10:23:43 +01:00
#endif