Give kernel image a header.

Kernel image now has a header with version, magic number, and a
pointer to its actual entrypoint. Entry point is now _start in
boot.s, and we now generate versions.s in the build tree for the
version macros.
This commit is contained in:
Justin C. Miller
2018-03-24 18:34:44 -07:00
parent d438392ed5
commit e19c7cee50
11 changed files with 246 additions and 28 deletions

54
src/modules/main/vga.c Normal file
View File

@@ -0,0 +1,54 @@
#include "vga.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
static size_t terminal_row;
static size_t terminal_column;
static uint8_t terminal_color;
/* Note the use of the volatile keyword to prevent the compiler from eliminating dead stores. */
static volatile uint16_t* terminal_buffer;
uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg);
uint16_t vga_entry(unsigned char uc, uint8_t color);
static size_t strlen(const char* str) {
size_t len = 0;
while (str[len++]);
return len;
}
void terminal_initialize(size_t startrow) {
terminal_row = startrow;
terminal_column = 0;
terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
terminal_buffer = (uint16_t*) 0xB8000;
}
void terminal_setcolor(uint8_t color) {
terminal_color = color;
}
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = vga_entry(c, color);
}
void terminal_putchar(char c) {
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
if (++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT)
terminal_row = 0;
}
}
void terminal_write(const char* data, size_t size) {
for (size_t i = 0; i < size; i++)
terminal_putchar(data[i]);
}
void terminal_writestring(const char* data) {
terminal_write(data, strlen(data));
}