| 1 | #if defined (BIOS) |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stddef.h> |
| 5 | #include <sys/e820.h> |
| 6 | #include <lib/real.h> |
| 7 | #include <lib/misc.h> |
| 8 | #include <lib/print.h> |
| 9 | #include <mm/pmm.h> |
| 10 | |
| 11 | #define MAX_E820_ENTRIES 256 |
| 12 | |
| 13 | struct memmap_entry e820_map[MAX_E820_ENTRIES]; |
| 14 | size_t e820_entries = 0; |
| 15 | |
| 16 | void init_e820(void) { |
| 17 | struct rm_regs r = {0}; |
| 18 | |
| 19 | for (size_t i = 0; i < MAX_E820_ENTRIES; i++) { |
| 20 | struct memmap_entry entry; |
| 21 | |
| 22 | r.eax = 0xe820; |
| 23 | r.ecx = 24; |
| 24 | r.edx = 0x534d4150; |
| 25 | r.edi = (uint32_t)&entry; |
| 26 | rm_int(0x15, &r, &r); |
| 27 | |
| 28 | if (r.eflags & EFLAGS_CF) { |
| 29 | e820_entries = i; |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | e820_map[i] = entry; |
| 34 | |
| 35 | if (!r.ebx) { |
| 36 | e820_entries = ++i; |
| 37 | return; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | panic(false, "Too many E820 entries!"); |
| 42 | } |
| 43 | |
| 44 | #endif |