Got memory info from multiboot & minor adjustments

This commit is contained in:
2025-02-19 10:46:35 +01:00
parent 609e10e13c
commit 8674d32f77
10 changed files with 384 additions and 23 deletions
+2 -1
View File
@@ -22,7 +22,7 @@ align 16
; Initialize stack
stack_bottom:
resb 16384 ; 16kB
resb 16384
stack_top:
; Entry point
@@ -31,6 +31,7 @@ global _start
extern kmain
_start:
mov esp, stack_top ; Setup stack
push ebx
call kmain ; Call kernel main
; Hang if kernel returns
+37 -13
View File
@@ -1,25 +1,49 @@
#include <multiboot.h>
#include <kernel.h>
#include <serial.h>
#include <pmm.h>
#include <tty.h>
#define _hlt() while (1) __asm__ volatile ("cli; hlt");
__noreturn
void kmain(void) {
serial_init(COM1);
serial_print(COM1, "kern.\n\n");
while (1) {
char c = serial_recv(COM1);
serial_send(COM1, c);
if (c == '\r') {
serial_send(COM1, '\n');
break;
}
char* itoa(uint8_t n) {
static char str[32];
int i = sizeof(str) - 2;
while (n) {
str[i--] = (n % 10) + '0';
n /= 10;
}
str[sizeof(str) - 1] = '\0';
return &str[i+1];
}
__noreturn
void kmain(void* ptr) {
multiboot_info_t* mbi = ptr;
// Serial console for debugging
serial_init(COM1);
serial_puts(COM1, "\x1b[0H\x1b[Jkern.\n");
// Check if we have a valid memmap
if (!(mbi->flags >> 6 & 1)) {
panic("Invalid memory map.");
}
// VGA tty thingy
tty_init();
tty_puts("Hello, World!\n");
tty_puts("kern.");
// Memory manager init
// pmm_init();
// vmm_init();
// x86 shit
// gdt_init();
// isr_init();
/* TODO: Commeted out stuff */
panic("kmain() reached end!");
panic("kmain() reached end.");
}
+4
View File
@@ -0,0 +1,4 @@
#include <pmm.h>
int pmm_init() { return 0; }
+1 -1
View File
@@ -44,7 +44,7 @@ void serial_write(int dev, char* buf, size_t len) {
}
}
void serial_print(int dev, char* s) {
void serial_puts(int dev, char* s) {
size_t len = 0;
char* p = s;
while (*p++ != '\0') len++;
+42 -4
View File
@@ -1,4 +1,5 @@
#include <kernel.h>
#include <system.h>
#include <tty.h>
struct {
@@ -6,14 +7,17 @@ struct {
size_t col;
uint8_t attr;
uint8_t* buf;
size_t updateWait;
} ctx;
void tty_init(void) {
int tty_init(void) {
ctx.row = 0;
ctx.col = 0;
ctx.attr = 0x07;
ctx.buf = (uint8_t*)VGA_MEMORY;
tty_clear();
return 0;
}
void tty_clear(void) {
@@ -27,6 +31,31 @@ void tty_setattr(uint8_t attr) {
ctx.attr = attr;
}
void tty_enableCursor(uint8_t start, uint8_t end) {
outb(0x3d4, 0x0a);
outb(0x3d5, (inb(0x3d5) & 0xc0) | start);
outb(0x3d4, 0x0b);
outb(0x3d5, (inb(0x3d5) & 0xe0) | end);
}
void tty_disableCursor(void) {
outb(0x3d4, 0x0a);
outb(0x3d5, 0x20);
}
void tty_updateCursor(void) {
if (ctx.updateWait > 0) {
ctx.updateWait--;
return;
}
uint16_t pos = ctx.row * VGA_WIDTH + ctx.col;
outb(0x3d4, 0x0f);
outb(0x3d5, (uint8_t)pos);
outb(0x3d4, 0x0e);
outb(0x3d5, (uint8_t)(pos >> 8));
}
// TODO:
void tty_scroll(void) {
ctx.row = 0;
@@ -44,8 +73,7 @@ void tty_putc(char c) {
if (c == '\n') {
ctx.col = 0;
ctx.row++;
if (ctx.row >= VGA_HEIGHT) tty_scroll();
return;
goto scroll_check;
}
tty_putat(c, ctx.row, ctx.col++);
@@ -54,10 +82,20 @@ void tty_putc(char c) {
ctx.row++;
}
scroll_check:
if (ctx.row >= VGA_HEIGHT) tty_scroll();
tty_updateCursor();
}
void tty_write(char* buf, size_t len) {
ctx.updateWait = len - 1;
for (int i = 0; i < len; i++) tty_putc(buf[i]);
}
void tty_puts(char* s) {
while (*s != '\0') tty_putc(*s++);
size_t len = 0;
char* p = s;
while (*p++ != '\0') len++;
tty_write(s, len);
}