mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Got basic tty driver & implemented Stack Smash Protector
This commit is contained in:
+5
-1
@@ -1,9 +1,13 @@
|
||||
#include <kernel.h>
|
||||
#include <tty.h>
|
||||
|
||||
#define _hlt() while (1) __asm__ volatile ("cli; hlt");
|
||||
|
||||
__noreturn
|
||||
void kmain(void) {
|
||||
tty_init();
|
||||
printk("Hello, World!\n");
|
||||
tty_puts("Hello, World!\n");
|
||||
|
||||
_hlt();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Stack Smash Protector
|
||||
* Source: https://wiki.osdev.org/Stack_Smashing_Protector
|
||||
*/
|
||||
#include <kernel.h>
|
||||
|
||||
// TODO: Make this randomized
|
||||
#define STACK_CHK_GUARD 0x27a1abd8
|
||||
|
||||
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
|
||||
__noreturn void __stack_chk_fail(void) {
|
||||
panic("Stack smashing detected!");
|
||||
}
|
||||
|
||||
+42
-10
@@ -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++);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user