fix: memory layout and startup

This commit is contained in:
Katharina 2026-06-27 09:48:09 +02:00
parent 92d8a91be4
commit 8dc53f662e
7 changed files with 48 additions and 32 deletions

View file

@ -45,7 +45,8 @@ static void loadMultiboot() {
}
[[maybe_unused]] [[noreturn]] __attribute__((used)) void init() {
initFromLow();
print("Reached init\n", {});
//step("multiboot", loadMultiboot);
step("multiboot", loadMultiboot);
halt();
}

View file

@ -11,17 +11,14 @@ static constexpr int HEX_TOP_SHIFT = (sizeof(uint64_t) * 8) - HEX_BITS;
static const char hex_chars[] = "0123456789ABCDEF";
static volatile uint32_t* cursor() {
auto cursor_addr = read_symbol("__cursor");
return paddr_t{cursor_addr}.access<volatile uint32_t>();
}
static uint32_t cursor;
static volatile uint16_t* vga_cell(uint32_t offset) {
return paddr_t{VGA_PHYS_BASE + offset}.access<volatile uint16_t>();
}
static void next_line() {
*cursor() = ((*cursor() + BYTES_PER_ROW - 1) / BYTES_PER_ROW) * BYTES_PER_ROW;
cursor = ((cursor + BYTES_PER_ROW - 1) / BYTES_PER_ROW) * BYTES_PER_ROW;
}
static void put_char(char ch, uint16_t attr_word) {
@ -29,12 +26,17 @@ static void put_char(char ch, uint16_t attr_word) {
next_line();
return;
}
*vga_cell(*cursor()) = attr_word | (uint8_t)ch;
*cursor() += BYTES_PER_CELL;
*vga_cell(cursor) = attr_word | (uint16_t)ch;
cursor += BYTES_PER_CELL;
}
void initFromLow () {
auto __cursor = read_symbol("__cursor");
cursor = *paddr_t{__cursor}.access<volatile uint32_t>();
}
void clear() {
*cursor() = 0;
cursor = 0;
for (int i = 0; i < VGA_COLS * VGA_ROWS; i++) {
*vga_cell(i * BYTES_PER_CELL) = 0;
}

View file

@ -141,6 +141,12 @@ __clear:
mov $0xb8000, %edi
mov $0x2000, %ecx
rep stosw
mov $0x3D4, %dx
mov $0x0A, %al
out %al, %dx
inc %dx
mov $0x20, %al
out %al, %dx
ret
__print: