forked from PoliEcho-holding-org/kern
Got basic tty driver & implemented Stack Smash Protector
This commit is contained in:
+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