diff options
author | Marvin Borner | 2021-01-21 17:04:15 +0100 |
---|---|---|
committer | Marvin Borner | 2021-01-21 17:04:15 +0100 |
commit | b3fafef621bb4404208e65ff1f78e15da3b216f7 (patch) | |
tree | 6f1c610b816f574c77615cb03d5507a4281411dd /kernel | |
parent | ef407d1e965674c5278daeb25a72acf446ec3223 (diff) |
Implementing new features...
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/keyboard.c | 4 | ||||
-rw-r--r-- | kernel/drivers/mouse.c | 146 | ||||
-rw-r--r-- | kernel/features/proc.c | 3 | ||||
-rw-r--r-- | kernel/inc/keyboard.h | 2 |
4 files changed, 93 insertions, 62 deletions
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index 744ca99..054849c 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -71,12 +71,12 @@ u32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev) return count; } -u32 keyboard_ready() +u32 keyboard_ready(void) { return !stack_empty(queue); } -void keyboard_reset() +void keyboard_reset(void) { stack_clear(queue); } diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c index f70fb6a..99fb80b 100644 --- a/kernel/drivers/mouse.c +++ b/kernel/drivers/mouse.c @@ -2,13 +2,18 @@ #include <boot.h> #include <cpu.h> +#include <fs.h> #include <interrupts.h> #include <mem.h> #include <print.h> +#include <stack.h> +#include <str.h> #include <sys.h> static char mouse_cycle = 0; static char mouse_byte[3] = { 0 }; +static struct stack *queue = NULL; +static u32 dev_id = 0; static struct event_mouse *event = NULL; @@ -38,7 +43,7 @@ void mouse_handler() event->but1 = mouse_byte[0] & 1; event->but2 = (mouse_byte[0] >> 1) & 1; event->but3 = (mouse_byte[0] >> 2) & 1; - //event_trigger(EVENT_MOUSE, event); + stack_push_bot(queue, event); mouse_cycle = 0; break; @@ -47,7 +52,7 @@ void mouse_handler() } } -void mouse_wait(u8 a_type) +void mouse_serial_wait(u8 a_type) { u32 time_out = 100000; if (a_type == 0) { @@ -63,96 +68,121 @@ void mouse_wait(u8 a_type) } } -void mouse_write(u8 a_write) +void mouse_serial_write(u8 a_write) { - mouse_wait(1); + mouse_serial_wait(1); outb(0x64, 0xD4); - mouse_wait(1); + mouse_serial_wait(1); outb(0x60, a_write); } -u8 mouse_read(void) +u8 mouse_serial_read(void) { - mouse_wait(0); + mouse_serial_wait(0); return inb(0x60); } +u32 mouse_ready(void) +{ + return !stack_empty(queue); +} + +u32 mouse_read(void *buf, u32 offset, u32 count, struct device *dev) +{ + (void)dev; + if (stack_empty(queue)) + return 0; + + struct event *e = stack_pop(queue); + memcpy(buf, (u8 *)e + offset, count); + return count; +} + void mouse_install(void) { u8 status; // Enable auxiliary mouse device - mouse_wait(1); + mouse_serial_wait(1); outb(0x64, 0xA8); // Enable interrupts - mouse_wait(1); + mouse_serial_wait(1); outb(0x64, 0x20); - mouse_wait(0); + mouse_serial_wait(0); status = (u8)(inb(0x60) | 3); - mouse_wait(1); + mouse_serial_wait(1); outb(0x64, 0x60); - mouse_wait(1); + mouse_serial_wait(1); outb(0x60, status); // Enable mousewheel - mouse_write(0xF2); - mouse_read(); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(200); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(100); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(80); - mouse_read(); - mouse_write(0xF2); - mouse_read(); - status = (u8)mouse_read(); + mouse_serial_write(0xF2); + mouse_serial_read(); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(200); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(100); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(80); + mouse_serial_read(); + mouse_serial_write(0xF2); + mouse_serial_read(); + status = (u8)mouse_serial_read(); if (status == 3) printf("Scrollwheel support!\n"); // Activate 4th and 5th mouse buttons - mouse_write(0xF2); - mouse_read(); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(200); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(200); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(80); - mouse_read(); - mouse_write(0xF2); - mouse_read(); - status = (u8)mouse_read(); + mouse_serial_write(0xF2); + mouse_serial_read(); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(200); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(200); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(80); + mouse_serial_read(); + mouse_serial_write(0xF2); + mouse_serial_read(); + status = (u8)mouse_serial_read(); if (status == 4) printf("4th and 5th mouse button support!\n"); /* TODO: Fix mouse laggyness - mouse_write(0xE8); - mouse_read(); - mouse_write(0x03); - mouse_read(); - mouse_write(0xF3); - mouse_read(); - mouse_write(200); - mouse_read(); */ + mouse_serial_write(0xE8); + mouse_serial_read(); + mouse_serial_write(0x03); + mouse_serial_read(); + mouse_serial_write(0xF3); + mouse_serial_read(); + mouse_serial_write(200); + mouse_serial_read(); */ // Enable mouse - mouse_write(0xF4); - mouse_read(); + mouse_serial_write(0xF4); + mouse_serial_read(); // Setup the mouse handler irq_install_handler(12, mouse_handler); + + queue = stack_new(); + struct device *dev = malloc(sizeof(*dev)); + dev->name = strdup("mouse"); + dev->type = DEV_CHAR; + dev->read = mouse_read; + dev->ready = mouse_ready; + device_add(dev); + dev_id = dev->id; } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 5e918b2..1a3c7e1 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -132,7 +132,7 @@ void proc_exit(struct proc *proc, int status) void proc_yield(struct regs *r) { - //proc_clear_quantum(); + proc_clear_quantum(); scheduler(r); } @@ -145,6 +145,7 @@ void proc_enable_waiting(u32 dev_id) if (p && w && w->id == dev_id) { struct regs *r = &p->regs; r->eax = (u32)w->func((char *)r->ebx, (void *)r->ecx, r->edx, r->esi); + memset(&p->wait, 0, sizeof(p->wait)); p->state = PROC_RUNNING; } iterator = iterator->next; diff --git a/kernel/inc/keyboard.h b/kernel/inc/keyboard.h index af74316..22120e5 100644 --- a/kernel/inc/keyboard.h +++ b/kernel/inc/keyboard.h @@ -4,6 +4,6 @@ #define KEYBOARD_H void keyboard_install(void); -void keyboard_reset(); +void keyboard_reset(void); #endif |