This commit is contained in:
nub31
2025-09-01 20:49:15 +02:00
parent 7c6ff5d52d
commit 5927756988
6 changed files with 53 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ CFLAGS = -m64 -ffreestanding -fno-builtin -Wall -Wextra -Wshadow -std=c23 -g
LDFLAGS = -g
ASFLAGS = -f elf64 -g -F dwarf
SRC_C := src/kernel.c src/string.c src/vga.c src/interrupts.c
SRC_C := src/kernel.c src/string.c src/vga.c src/interrupts.c src/keyboard.c
SRC_ASM := src/start.asm
OBJ_C := $(SRC_C:src/%.c=.build/%.o)

View File

@@ -100,8 +100,6 @@ void handle_irq(const isr_frame_t* frame)
void handle_isr(const isr_frame_t* frame)
{
kprintf("isr");
if (frame->int_no < 32)
{
handle_exception(frame);

View File

@@ -1,15 +1,26 @@
#include "kernel.h"
#include "interrupts.h"
#include "keyboard.h"
#include "string.h"
#include "vga.h"
#include <stdarg.h>
#include <stddef.h>
void handle_keypress(const keyboard_event_t* event)
{
if (event->pressed && event->ascii)
{
kprintf("%c", event->ascii);
}
}
void kmain()
{
vga_clear();
pic_remap();
enable_interrupts();
init_keyboard();
register_keypress_handler(handle_keypress);
kprintf("Welcome to nub OS\n");
khalt();
@@ -18,6 +29,7 @@ void kmain()
void kpanic()
{
kprintf("Kernel panic!\n");
disable_interrupts();
khalt();
}
@@ -33,6 +45,7 @@ void kprintf(const char* fmt, ...)
if (should_format)
{
should_format = false;
if (fmt[i] == '%')
{
vga_put_char('%', 0x0F);
@@ -45,6 +58,11 @@ void kprintf(const char* fmt, ...)
vga_put_char(str[j], 0x0F);
}
}
else if (fmt[i] == 'c')
{
char character = (char)va_arg(args, int64_t);
vga_put_char(character, 0x0F);
}
else if (fmt[i] == 'd')
{
int64_t val = va_arg(args, int64_t);
@@ -65,6 +83,10 @@ void kprintf(const char* fmt, ...)
vga_put_char(buf[j], 0x0F);
}
}
else
{
vga_put_char(fmt[i], 0x0F);
}
}
else if (fmt[i] == '%')
{

View File

@@ -6,7 +6,6 @@ static inline void khalt()
{
while (true)
{
__asm__ volatile ("cli");
__asm__ volatile ("hlt");
}
}

View File

@@ -3,6 +3,7 @@
#include "kernel.h"
#include "vga.h"
#include "util.h"
#include <stddef.h>
#define SCANCODE_LEFT_SHIFT 42
#define SCANCODE_RIGHT_SHIFT 54
@@ -31,7 +32,7 @@ bool caps_lock = false;
// todo(nub): make dynamic when a memory allocator is implemented
static keyboard_handler_t keyboard_handlers[KEYBOARD_HANDLERS_LENGTH];
static int handler_index = 0;
static size_t handler_index = 0;
char scan_code_to_ascii(uint8_t scan_code)
{

View File

@@ -35,6 +35,34 @@ void vga_put_char(char character, uint8_t color)
cursor_col += remainter == 0 ? 4 : remainter;
break;
}
case '\b':
{
if (cursor_col > 0)
{
cursor_col -= 1;
}
else if (cursor_row > 0)
{
cursor_row -= 1;
cursor_col = 0;
for (int col = COLUMNS - 1; col >= 0; col--)
{
vga_char_t cell = vga_buffer[cursor_row * COLUMNS + col];
if (cell.character != ' ')
{
cursor_col = col;
break;
}
}
}
vga_buffer[cursor_row * COLUMNS + cursor_col] = (vga_char_t){
.character = ' ',
.color = VGA_LIGHT_GRAY | VGA_BLACK << 4,
};
break;
}
default:
{
vga_buffer[COLUMNS * cursor_row + cursor_col] = (vga_char_t){