working on kernel tasklets

This commit is contained in:
2026-07-22 17:34:00 -05:00
parent 974e23987e
commit 21c66f13fb
7 changed files with 82 additions and 48 deletions

View File

@@ -1,8 +1,13 @@
#include "kbd.h"
#include <stdint.h> #include <stdint.h>
#include <drivers/ps2/ps2.h> #include <drivers/ps2/ps2.h>
#include <lib/print.h>
#include <lib/ringbuf.h>
#include <vfs.h> #include <vfs.h>
#include <scheduler.h>
static const char scancode_to_ascii[] = { static const char scancode_to_ascii[] = {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
@@ -18,6 +23,8 @@ extern void ps2_write_data(uint8_t);
extern void ps2_flush_output_buffer(void); extern void ps2_flush_output_buffer(void);
extern void io_wait(void); extern void io_wait(void);
void ps2_task();
static uint8_t read_ccb() { static uint8_t read_ccb() {
ps2_write_command(CMD_READ_CCB); ps2_write_command(CMD_READ_CCB);
io_wait(); io_wait();
@@ -48,40 +55,7 @@ static void enable_port_1() {
io_wait(); io_wait();
} }
int init_ps2() { static char ps2_get_ascii(uint8_t scancode) {
ps2_write_command(CMD_DISABLE_P1);
ps2_write_command(CMD_DISABLE_P2);
ps2_flush_output_buffer();
uint8_t ccb = read_ccb();
ccb = ccb & 0xEC;
write_ccb(ccb);
int result = perform_self_test();
if (result != SELF_TEST_SUCCESS) {
return -1;
}
result = test_port_1();
if (result != PORT_TEST_SUCCESS) {
return -1;
}
enable_port_1();
ccb = read_ccb();
ccb |= 0x01; // this enables interrupts for port 1, which we want
write_ccb(ccb);
return 0;
}
void ps2_init_kbd(vfs_node_t* dev) {
}
char ps2_get_ascii(uint8_t scancode) {
if (scancode & 0x80) { if (scancode & 0x80) {
return 0; return 0;
} }
@@ -96,3 +70,59 @@ char ps2_get_ascii(uint8_t scancode) {
return 0; return 0;
} }
static ring_buf_t scancode_buf;
static void push_scancode(uint8_t scancode) {
ring_buf_write(&scancode_buf, scancode);
}
int init_ps2() {
ps2_write_command(CMD_DISABLE_P1);
ps2_write_command(CMD_DISABLE_P2);
ps2_flush_output_buffer();
if (perform_self_test() != SELF_TEST_SUCCESS) {
return 0;
}
uint8_t ccb = read_ccb();
ccb &= ~(0x01 | 0x02); // Disable interrupts
ccb |= (1 << 6); // Enable translation
write_ccb(ccb);
if (test_port_1() != PORT_TEST_SUCCESS) {
return 0;
}
enable_port_1();
ccb = read_ccb();
ccb |= 0x01;
write_ccb(ccb);
ps2_flush_output_buffer();
// start the tasklet
ring_buf_init(&scancode_buf);
sched_create_ktask(ps2_task);
return 1;
}
void ps2_task() {
kprintf("started ps2 task\n");
while (1) {
char sc;
ring_buf_read(&scancode_buf, &sc);
kprintf("ps2 read\n");
if (sc == -1) yield(); continue;
kprintf("pushing char\n");
kbd_push(ps2_get_ascii(sc));
}
}
void ps2_handle_scancode(uint8_t scancode) {
push_scancode(scancode);
}

View File

@@ -24,7 +24,8 @@ int init_ps2();
void ps2_init_kbd(vfs_node_t* dev); void ps2_init_kbd(vfs_node_t* dev);
uint8_t ps2_read_data(); uint8_t ps2_read_data();
char ps2_get_ascii(uint8_t scancode); void ps2_handle_scancode(uint8_t scancode);
#endif #endif
#endif #endif

View File

@@ -192,16 +192,9 @@ void common_interrupt_handler(intr_regs_t *args) {
kpanic(); kpanic();
break; break;
} }
case 32: {
break;
}
case 33: { case 33: {
uint8_t data = ps2_read_data(); uint8_t data = inb(PS2_DATA);
char ascii = ps2_get_ascii(data); ps2_handle_scancode(data);
if (ascii != 0) {
kbd_push(ascii);
}
send_eoi_master(); send_eoi_master();
break; break;
} }

View File

@@ -117,17 +117,17 @@ void kmain(multiboot_info* mbi) {
init_gdt(); init_gdt();
init_idt(); init_idt();
init_scheduler();
init_pic(); init_pic();
init_pit(); init_pit();
init_ps2();
uint32_t mmap_virtual_addr = mbi->mmap_addr + 0xC0000000; uint32_t mmap_virtual_addr = mbi->mmap_addr + 0xC0000000;
init_pmm((void*)mmap_virtual_addr, mbi->mmap_length); init_pmm((void*)mmap_virtual_addr, mbi->mmap_length);
init_page_tables(); init_page_tables();
disable_interrupts();
init_scheduler();
enable_interrupts();
vfs_node_t* vfs_root = vfs_create_root(); vfs_node_t* vfs_root = vfs_create_root();
vfs_node_t* initrd_root = load_initrd(); vfs_node_t* initrd_root = load_initrd();
@@ -170,4 +170,5 @@ void kmain(multiboot_info* mbi) {
kprintf("starting rockos\n"); kprintf("starting rockos\n");
load_root_program("/usr/bin/rockterm"); load_root_program("/usr/bin/rockterm");
enable_interrupts();
} }

View File

@@ -201,3 +201,11 @@ process_t* get_task_by_pid(uint32_t pid) {
} }
return cur; return cur;
} }
void sched_create_ktask(void *addr) {
kprintf("sched_create_ktask called\n");
process_t* task = kalloc(sizeof(process_t));
void* cr3 = create_new_pd();
init_task(task, (uint32_t)addr, (uint32_t)cr3, 0, 0);
add_task(task);
}

View File

@@ -14,6 +14,7 @@ process_t* current_task();
process_t* get_task_by_pid(uint32_t pid); process_t* get_task_by_pid(uint32_t pid);
int get_next_pid(); int get_next_pid();
void sched_create_ktask(void* addr);
void add_task(process_t* task); void add_task(process_t* task);
void sleep(uint32_t ms); void sleep(uint32_t ms);

BIN
rlibgui/rlibgui.a Normal file

Binary file not shown.