2022-09-02 03:29:12 +03:00
|
|
|
#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
|
|
|
|
2021-09-03 04:10:23 +03:00
|
|
|
#define MAX_E820_ENTRIES 256
|
2021-04-15 03:21:38 +03:00
|
|
|
|
2022-08-13 20:54:49 +03:00
|
|
|
struct memmap_entry e820_map[MAX_E820_ENTRIES];
|
2021-04-15 03:21:38 +03:00
|
|
|
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};
|
|
|
|
|
2021-04-15 03:21:38 +03:00
|
|
|
for (size_t i = 0; i < MAX_E820_ENTRIES; i++) {
|
2022-08-13 20:54:49 +03:00
|
|
|
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;
|
2021-04-15 03:21:38 +03:00
|
|
|
return;
|
2020-03-27 03:59:11 +03:00
|
|
|
}
|
|
|
|
|
2021-04-15 03:21:38 +03:00
|
|
|
e820_map[i] = entry;
|
2020-10-20 09:51:56 +03:00
|
|
|
|
2020-03-27 03:59:11 +03:00
|
|
|
if (!r.ebx) {
|
2020-05-03 00:38:57 +03:00
|
|
|
e820_entries = ++i;
|
2021-04-15 03:21:38 +03:00
|
|
|
return;
|
2020-03-27 03:59:11 +03:00
|
|
|
}
|
2020-05-01 00:59:14 +03:00
|
|
|
}
|
2020-10-20 09:51:56 +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
|