kbd_fix #12

Merged
xamidev merged 3 commits from kbd_fix into main 2026-03-09 09:30:42 +01:00
9 changed files with 71 additions and 33 deletions
Showing only changes of commit 42c7a55d3f - Show all commits

View File

@@ -41,8 +41,9 @@ PepperOS wouldn't be possible without the following freely-licensed software:
- the [Limine](https://codeberg.org/Limine/Limine) portable bootloader - the [Limine](https://codeberg.org/Limine/Limine) portable bootloader
- Marco Paland's freestanding [printf implementation](https://github.com/mpaland) - Marco Paland's freestanding [printf implementation](https://github.com/mpaland)
- the [ZAP](https://www.zap.org.au/projects/console-fonts-zap/) PSF console fonts - Mintuski's [Flanterm](https://codeberg.org/Mintsuki/Flanterm) terminal emulator
...and without these amazing resources: ...and without these amazing resources:
- the [OSDev](https://osdev.org) wiki & forums - the [OSDev](https://osdev.org) wiki & forums
- Intel 64 and IA-32 Architectures Software Developer's Manual

View File

@@ -22,7 +22,7 @@ struct idtr idt_reg;
extern char vector_0_handler[]; extern char vector_0_handler[];
// Timer ticks // Timer ticks
extern uint64_t ticks; extern volatile uint64_t ticks;
void idt_set_entry(uint8_t vector, void* handler, uint8_t dpl) void idt_set_entry(uint8_t vector, void* handler, uint8_t dpl)
{ {

View File

@@ -17,6 +17,8 @@ uint8_t key_status = 0b00000000;
unsigned char* keymap; unsigned char* keymap;
unsigned char* keymap_shifted; unsigned char* keymap_shifted;
extern struct init_status init;
unsigned char kbdus[128] = unsigned char kbdus[128] =
{ {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */ 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
@@ -205,6 +207,10 @@ void keyboard_handler()
if (c) if (c)
{ {
if (c == '\n')
{
_putchar('\r');
}
// Should probably have a keyboard buffer here... instead of this // Should probably have a keyboard buffer here... instead of this
_putchar(c); _putchar(c);
} }
@@ -247,4 +253,5 @@ void keyboard_init(unsigned char layout)
outb(0x21, mask); outb(0x21, mask);
DEBUG("PS/2 Keyboard initialized"); DEBUG("PS/2 Keyboard initialized");
init.keyboard = true;
} }

View File

@@ -7,6 +7,8 @@
#include <kernel.h> #include <kernel.h>
#include "serial.h" #include "serial.h"
extern struct init_status init;
void outb(int port, unsigned char data) void outb(int port, unsigned char data)
{ {
__asm__ __volatile__("outb %%al, %%dx" :: "a" (data),"d" (port)); __asm__ __volatile__("outb %%al, %%dx" :: "a" (data),"d" (port));
@@ -43,6 +45,7 @@ int serial_init()
outb(PORT + 4, 0x0F); outb(PORT + 4, 0x0F);
DEBUG("*** Welcome to PepperOS! ***"); DEBUG("*** Welcome to PepperOS! ***");
init.serial = true;
return 0; return 0;
} }

View File

@@ -16,8 +16,12 @@ because this shitty implementation will be replaced one day by Flanterm
#include "term.h" #include "term.h"
#include "config.h" #include "config.h"
#include "flanterm.h" #include "flanterm.h"
#include "flanterm_backends/fb.h"
#include "mem/heap/kheap.h"
#include "limine.h"
extern struct flanterm_context* ft_ctx; extern struct flanterm_context* ft_ctx;
extern struct init_status init;
// Overhead that could be avoided, right? (for printf) // Overhead that could be avoided, right? (for printf)
void _putchar(char character) void _putchar(char character)
@@ -36,4 +40,35 @@ void kputs(const char* str)
i++; i++;
} }
_putchar('\r'); _putchar('\r');
}
extern struct flanterm_context* ft_ctx;
extern struct boot_context boot_ctx;
void flanterm_free_wrapper(void* ptr, size_t size)
{
(void)size;
kfree(ptr);
}
void term_init()
{
uint32_t bgColor = 0x252525;
ft_ctx = flanterm_fb_init(
kmalloc,
flanterm_free_wrapper,
boot_ctx.fb->address, boot_ctx.fb->width, boot_ctx.fb->height, boot_ctx.fb->pitch,
boot_ctx.fb->red_mask_size, boot_ctx.fb->red_mask_shift,
boot_ctx.fb->green_mask_size, boot_ctx.fb->green_mask_shift,
boot_ctx.fb->blue_mask_size, boot_ctx.fb->blue_mask_shift,
NULL,
NULL, NULL,
&bgColor, NULL,
NULL, NULL,
NULL, 0, 0, 1,
0, 0,
0,
0
);
init.terminal = true;
} }

View File

@@ -9,5 +9,6 @@
void kputs(const char* str); void kputs(const char* str);
void _putchar(char character); void _putchar(char character);
void term_init();
#endif #endif

View File

@@ -19,8 +19,11 @@ enum ErrorCodes
#include "io/serial/serial.h" #include "io/serial/serial.h"
#include "io/term/printf.h" #include "io/term/printf.h"
#include "idt/idt.h" #include "idt/idt.h"
#include <stdbool.h>
#define DEBUG(log, ...) fctprintf((void*)&skputc, 0, "debug: [%s]: " log "\r\n", __FILE__, ##__VA_ARGS__) extern volatile uint64_t ticks;
#define DEBUG(log, ...) fctprintf((void*)&skputc, 0, "[%8u] debug: [%s]: " log "\r\n", ticks, __FILE__, ##__VA_ARGS__)
/* #define DEBUG(log, ...) \ /* #define DEBUG(log, ...) \
@@ -38,6 +41,7 @@ void panic(struct cpu_status_t* ctx, const char* str);
void hcf(); void hcf();
void idle(); void idle();
/* debug */
void debug_stack_trace(unsigned int max_frames); void debug_stack_trace(unsigned int max_frames);
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset); const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset);
void boot_mem_display(); void boot_mem_display();
@@ -52,4 +56,13 @@ struct boot_context
struct limine_kernel_address_response* kaddr; struct limine_kernel_address_response* kaddr;
}; };
// Are these modules initialized yet?
struct init_status
{
bool terminal;
bool serial;
bool keyboard;
bool timer;
};
#endif #endif

View File

@@ -30,8 +30,6 @@
__attribute__((used, section(".limine_requests"))) __attribute__((used, section(".limine_requests")))
volatile LIMINE_BASE_REVISION(3); volatile LIMINE_BASE_REVISION(3);
struct flanterm_context *ft_ctx;
// Halt and catch fire (makes machine stall) // Halt and catch fire (makes machine stall)
void hcf() void hcf()
{ {
@@ -41,9 +39,9 @@ void hcf()
// Doing nothing (can be interrupted) // Doing nothing (can be interrupted)
void idle() {SET_INTERRUPTS; for(;;)asm("hlt");} void idle() {SET_INTERRUPTS; for(;;)asm("hlt");}
// uint8_t kernel_stack[KERNEL_STACK_SIZE] __attribute__((aligned(16))); struct flanterm_context *ft_ctx;
struct boot_context boot_ctx; struct boot_context boot_ctx;
struct init_status init = {0};
extern volatile struct limine_framebuffer_request framebuffer_request; extern volatile struct limine_framebuffer_request framebuffer_request;
extern volatile struct limine_memmap_request memmap_request; extern volatile struct limine_memmap_request memmap_request;
@@ -64,12 +62,6 @@ void idle_main(void* arg)
for(;;)asm("hlt"); for(;;)asm("hlt");
} }
void flanterm_free_wrapper(void* ptr, size_t size)
{
(void)size;
kfree(ptr);
}
extern uintptr_t kheap_start; extern uintptr_t kheap_start;
// This is our entry point // This is our entry point
@@ -79,6 +71,7 @@ void kmain()
if (!LIMINE_BASE_REVISION_SUPPORTED) hcf(); if (!LIMINE_BASE_REVISION_SUPPORTED) hcf();
serial_init(); serial_init();
timer_init();
// Populate boot context // Populate boot context
boot_ctx.fb = framebuffer_request.response ? framebuffer_request.response->framebuffers[0] : NULL; boot_ctx.fb = framebuffer_request.response ? framebuffer_request.response->framebuffers[0] : NULL;
@@ -95,29 +88,10 @@ void kmain()
keyboard_init(FR); keyboard_init(FR);
uint32_t bgColor = 0x252525; term_init();
ft_ctx = flanterm_fb_init(
kmalloc,
flanterm_free_wrapper,
boot_ctx.fb->address, boot_ctx.fb->width, boot_ctx.fb->height, boot_ctx.fb->pitch,
boot_ctx.fb->red_mask_size, boot_ctx.fb->red_mask_shift,
boot_ctx.fb->green_mask_size, boot_ctx.fb->green_mask_shift,
boot_ctx.fb->blue_mask_size, boot_ctx.fb->blue_mask_shift,
NULL,
NULL, NULL,
&bgColor, NULL, // &bgColor
NULL, NULL,
NULL, 0, 0, 1,
0, 0,
0,
0
);
gdt_init(); gdt_init();
idt_init(); idt_init();
timer_init();
vmm_init();
process_init(); process_init();
struct process_t* idle_proc = process_create("idle", (void*)idle_main, 0); struct process_t* idle_proc = process_create("idle", (void*)idle_main, 0);
@@ -131,5 +105,6 @@ void kmain()
current_process->status = RUNNING; current_process->status = RUNNING;
kputs(PEPPEROS_SPLASH); kputs(PEPPEROS_SPLASH);
//panic(NULL, "Test panic");
idle(); idle();
} }

View File

@@ -18,6 +18,8 @@ interested in multi-core functionnality like SMP)
volatile uint64_t ticks = 0; volatile uint64_t ticks = 0;
extern struct init_status init;
void pic_remap() void pic_remap()
{ {
uint8_t master_mask = inb(0x21); uint8_t master_mask = inb(0x21);
@@ -91,4 +93,5 @@ void timer_init()
pic_enable(); pic_enable();
pit_init(); pit_init();
DEBUG("PIT initialized"); DEBUG("PIT initialized");
init.timer = true;
} }