Got basic tty driver & implemented Stack Smash Protector

This commit is contained in:
2025-02-17 21:02:10 +01:00
parent 983174a081
commit f9dece59ce
8 changed files with 114 additions and 24 deletions
+42 -10
View File
@@ -12,20 +12,52 @@ void tty_init(void) {
ctx.row = 0;
ctx.col = 0;
ctx.attr = 0x07;
ctx.buf = (u8*)VGA_MEMORY;
ctx.buf = (uint8_t*)VGA_MEMORY;
tty_clear();
}
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
size_t i = (y * VGA_WIDTH + x) * 2;
ctx.buf[i] = ' ';
ctx.buf[i + 1] = ctx.attr;
}
void tty_clear(void) {
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
ctx.buf[i * 2] = ' ';
ctx.buf[i * 2 + 1] = ctx.attr;
}
}
int tty_write(char* buf, size_t len) {}
void tty_setattr(uint8_t attr) {
ctx.attr = attr;
}
int tty_putc(char c) {}
// TODO:
void tty_scroll(void) {
ctx.row = 0;
ctx.col = 0;
tty_clear();
}
int tty_puts(char* s) {}
void tty_putat(char c, size_t row, size_t col) {
size_t i = row * VGA_WIDTH + col;
ctx.buf[i * 2] = c;
ctx.buf[i * 2 + 1] = ctx.attr;
}
void tty_putc(char c) {
if (c == '\n') {
ctx.col = 0;
ctx.row++;
if (ctx.row >= VGA_HEIGHT) tty_scroll();
return;
}
tty_putat(c, ctx.row, ctx.col++);
if (ctx.col >= VGA_WIDTH) {
ctx.col = 0;
ctx.row++;
}
if (ctx.row >= VGA_HEIGHT) tty_scroll();
}
void tty_puts(char* s) {
while (*s != '\0') tty_putc(*s++);
}