#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); struct vga_term { uint16_t *buf; uint16_t column; uint16_t line; }; static void vga_term_scroll(const struct vga_term *const term) { for (int i = 0; i < VGA_HEIGHT-1; ++i) for (int j = 0; j < VGA_WIDTH; ++j) term->buf[i*VGA_WIDTH+j] = term->buf[(i+1)*VGA_WIDTH+j]; for (int i = 0; i < VGA_WIDTH; ++i) term->buf[(VGA_HEIGHT-1)*VGA_WIDTH+i] = 0x0f20; } static void vga_term_newline(struct vga_term *const term) { if (term->line < VGA_HEIGHT-1) ++term->line; else vga_term_scroll(term); term->column = 0; return; } static void vga_term_putc(struct vga_term *const term, const char c, const uint8_t color) { if (c == '\n') { vga_term_newline(term); return; } if (term->column >= VGA_WIDTH) vga_term_newline(term); term->buf[term->line*VGA_WIDTH+(term->column++)] = (color<<8)|(c); } static void vga_term_puts(struct vga_term *const term, const char *const str, const uint8_t color) { for (int i = 0; str[i]; ++i) vga_term_putc(term, str[i], color); } static void vga_term_print_hex(struct vga_term *const term, uint64_t num, const uint8_t color) { vga_term_putc(term, '0', color); vga_term_putc(term, 'x', color); for (int i = 0; i < 16; ++i) { char c; c = (num >> 60); c = (c < 0xa) ? (c + '0') : (c + 'a' - 0xa); vga_term_putc(term, c, color); num <<= 4; } } void kmain(void) { vga_cursor_hide(); struct vga_term term = {(uint16_t *)0xb8000, 0, 0}; for (int i = 0; i < VGA_WIDTH*VGA_HEIGHT; ++i) term.buf[i] = 0x0f20; vga_term_puts(&term, "ProvidenceOS v0.1\n\ne820 memory map:\n", 0x0f); const uint16_t e820_size = *(uint16_t *)0xf000; const struct e820_entry *const e820_mmap = (struct e820_entry *)0xf008; for (uint16_t i = 0; i < e820_size; ++i) { vga_term_print_hex(&term, e820_mmap[i].base, 0x0f); vga_term_putc(&term, '-', 0x0f); vga_term_print_hex(&term, e820_mmap[i].base + e820_mmap[i].length - 1, 0x0f); vga_term_putc(&term, ' ', 0x0f); vga_term_puts(&term, e820_mmap[i].type == 1 ? "available\n" : "reserved\n", 0x0f); } halt(); }