#include #include "assert.h" #include "util.h" #define VGA_WIDTH 80 #define VGA_HEIGHT 25 struct e820_entry { uint64_t base; uint64_t length; uint32_t type; uint32_t ext_attr; }; STATIC_ASSERT(sizeof(struct e820_entry) == 24, e820_entry); static uint64_t * memsetu64(uint64_t *const dst, const uint64_t c, const uint64_t n) { for (uint64_t i = 0; i < n; ++i) dst[i] = c; return dst; } static uint16_t * print_hex(uint16_t *dst, uint64_t num) { dst[0] = 0x0f00 | '0'; dst[1] = 0x0f00 | 'x'; dst += 2; for (int i = 0; i < 16; ++i) { uint16_t x = (num >> 60); *(dst++) = 0x0f00 | (x < 0xa ? x+'0' : x+'a'-0xa); num <<= 4; } return dst; } static uint16_t * puts(uint16_t *dst, const char *str) { for (; *str; ++str, ++dst) *dst = 0x0f00|(*str); return dst; } static uint16_t * print_e820_table(uint16_t *dst, const struct e820_entry *const entries, const uint16_t count) { for (uint16_t i = 0; i < count; ++i, dst += VGA_WIDTH) { uint16_t *cursor; cursor = print_hex(dst, entries[i].base); *(cursor++) = 0x0f00 | '-'; cursor = print_hex(cursor, entries[i].base + entries[i].length - 1); ++cursor; cursor = puts(cursor, entries[i].type == 1 ? "available" : "reserved"); } return dst; } void kmain(void) { vga_cursor_hide(); uint16_t *const vga_memory = (uint16_t *)0xb8000; memsetu64((uint64_t *)vga_memory, 0x0f200f200f200f20, (VGA_WIDTH*VGA_HEIGHT*sizeof(uint16_t))/sizeof(uint64_t)); puts(vga_memory, "ProvidenceOS v0.1"); puts(vga_memory+VGA_WIDTH*2, "e820 memory map:"); const uint16_t e820_size = *(uint16_t *)0xf000; const struct e820_entry *const e820_mmap = (struct e820_entry *)0xf008; print_e820_table(vga_memory+(VGA_WIDTH*3), e820_mmap, e820_size); halt(); }