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