aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2020-05-06 22:34:38 +0200
committerMarvin Borner2020-05-06 22:34:38 +0200
commit8083536f321ad8a12ad4668c2bf41a65c3e3b2f6 (patch)
tree427d7da11944b299bdce3041259bf8fd31971ede /src
parentd94ffac4a584dc7a4f6f2ec567b8caab05ce9253 (diff)
Added event mapping driver
Diffstat (limited to 'src')
-rw-r--r--src/kernel/events/event.c34
-rw-r--r--src/kernel/events/event.h9
-rw-r--r--src/kernel/input/ps2/keyboard.c5
-rw-r--r--src/kernel/input/ps2/mouse.c26
-rw-r--r--src/kernel/syscall/actions/sys_get.c7
-rw-r--r--src/kernel/syscall/actions/sys_map.c8
-rw-r--r--src/kernel/syscall/syscall.c4
-rw-r--r--src/kernel/syscall/syscall.h4
-rw-r--r--src/shared/common.h39
-rw-r--r--src/userspace/libc/syscall.c6
-rw-r--r--src/userspace/libc/syscall.h4
-rw-r--r--src/userspace/programs/init.c10
12 files changed, 133 insertions, 23 deletions
diff --git a/src/kernel/events/event.c b/src/kernel/events/event.c
new file mode 100644
index 0000000..cfefb67
--- /dev/null
+++ b/src/kernel/events/event.c
@@ -0,0 +1,34 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <common.h>
+#include <system.h>
+
+typedef u32 (*event_func)(u8 *);
+
+u32 (*event_table[])() = { [MAP_KEYBOARD] = NULL, [MAP_MOUSE] = NULL };
+
+u32 event_map(u32 id, u8 *function)
+{
+ if (id >= sizeof(event_map) / sizeof(*event_map))
+ return -1;
+
+ event_table[id] = (u32)function;
+ return 0;
+}
+
+u32 event_trigger(u32 id, u8 *data)
+{
+ if (id >= sizeof(event_map) / sizeof(*event_map)) {
+ panic("Unknown event id!");
+ return -1;
+ }
+
+ event_func location = (event_func)event_table[id];
+ if (!location) {
+ warn("Event %d not mapped!", id);
+ return -1;
+ }
+
+ location(data);
+ return 0;
+} \ No newline at end of file
diff --git a/src/kernel/events/event.h b/src/kernel/events/event.h
new file mode 100644
index 0000000..3f46632
--- /dev/null
+++ b/src/kernel/events/event.h
@@ -0,0 +1,9 @@
+#ifndef MELVIX_EVENT_H
+#define MELVIX_EVENT_H
+
+#include <stdint.h>
+
+u32 event_map(u32 id, u8 *function);
+u32 event_trigger(u32 id, u8 *data);
+
+#endif \ No newline at end of file
diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c
index dceba05..41ab1bb 100644
--- a/src/kernel/input/ps2/keyboard.c
+++ b/src/kernel/input/ps2/keyboard.c
@@ -1,3 +1,5 @@
+#include <common.h>
+#include <events/event.h>
#include <interrupts/interrupts.h>
#include <io/io.h>
#include <graphics/vesa.h>
@@ -10,6 +12,9 @@ u8 scancode;
void keyboard_handler(struct regs *r)
{
scancode = inb(0x60);
+ struct keyboard_event *event = umalloc(sizeof(struct keyboard_event));
+ event->scancode = scancode;
+ event_trigger(MAP_KEYBOARD, (u8 *)event);
}
void keyboard_acknowledge()
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index c1e39ba..ce3158e 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -1,3 +1,6 @@
+#include <common.h>
+#include <events/event.h>
+#include <memory/alloc.h>
#include <interrupts/interrupts.h>
#include <io/io.h>
#include <graphics/vesa.h>
@@ -11,7 +14,9 @@ int mouse_but_1 = 0;
int mouse_but_2 = 0;
int mouse_but_3 = 0;
-void mouse_handler(struct regs *a_r)
+struct mouse_event *event;
+
+void mouse_handler(struct regs *r)
{
switch (mouse_cycle) {
case 0:
@@ -42,14 +47,18 @@ void mouse_handler(struct regs *a_r)
mouse_x = vbe_width - 1;
if (mouse_y > vbe_height - 1)
mouse_y = vbe_height - 1;
- vesa_draw_cursor(mouse_x, mouse_y);
+ // vesa_draw_cursor(mouse_x, mouse_y);
+
+ event->mouse_x = mouse_x;
+ event->mouse_y = mouse_y;
+ event_trigger(MAP_MOUSE, (u8 *)event);
break;
default:
break;
}
}
-void mouse_wait(unsigned char a_type)
+void mouse_wait(u8 a_type)
{
unsigned int time_out = 100000;
if (a_type == 0) {
@@ -65,7 +74,7 @@ void mouse_wait(unsigned char a_type)
}
}
-void mouse_write(unsigned char a_write)
+void mouse_write(u8 a_write)
{
mouse_wait(1);
outb(0x64, 0xD4);
@@ -81,7 +90,8 @@ char mouse_read()
void mouse_install()
{
- unsigned char status;
+ event = umalloc(sizeof(struct mouse_event));
+ u8 status;
// Enable auxiliary mouse device
mouse_wait(1);
@@ -91,7 +101,7 @@ void mouse_install()
mouse_wait(1);
outb(0x64, 0x20);
mouse_wait(0);
- status = (unsigned char)(inb(0x60) | 3);
+ status = (u8)(inb(0x60) | 3);
mouse_wait(1);
outb(0x64, 0x60);
mouse_wait(1);
@@ -115,7 +125,7 @@ void mouse_install()
mouse_read();
mouse_write(0xF2);
mouse_read();
- status = (unsigned char)mouse_read();
+ status = (u8)mouse_read();
if (status == 3)
log("Scrollwheel support!");
@@ -137,7 +147,7 @@ void mouse_install()
mouse_read();
mouse_write(0xF2);
mouse_read();
- status = (unsigned char)mouse_read();
+ status = (u8)mouse_read();
if (status == 4)
log("4th and 5th mouse button support!");
diff --git a/src/kernel/syscall/actions/sys_get.c b/src/kernel/syscall/actions/sys_get.c
new file mode 100644
index 0000000..8a4a643
--- /dev/null
+++ b/src/kernel/syscall/actions/sys_get.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+u32 sys_get(u32 id)
+{
+ // TODO: Implement get syscall
+ return -1;
+} \ No newline at end of file
diff --git a/src/kernel/syscall/actions/sys_map.c b/src/kernel/syscall/actions/sys_map.c
new file mode 100644
index 0000000..63bfd9d
--- /dev/null
+++ b/src/kernel/syscall/actions/sys_map.c
@@ -0,0 +1,8 @@
+#include <stdint.h>
+#include <events/event.h>
+
+u32 sys_map(u32 id, u32 *function)
+{
+ event_map(id, function);
+ return -1;
+} \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index 92c0dbe..820afc7 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -17,7 +17,9 @@ u32 (*syscalls[])() = { [SYS_HALT] = (u32(*)())halt_loop, // DEBUG!
[SYS_EXEC] = sys_exec,
[SYS_GET_PID] = sys_get_pid,
[SYS_MALLOC] = sys_malloc,
- [SYS_FREE] = sys_free };
+ [SYS_FREE] = sys_free,
+ [SYS_GET] = sys_get,
+ [SYS_MAP] = sys_map };
void syscall_handler(struct regs *r)
{
diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h
index 7261afc..0cfa3a7 100644
--- a/src/kernel/syscall/syscall.h
+++ b/src/kernel/syscall/syscall.h
@@ -24,4 +24,8 @@ u32 sys_malloc(u32 count);
u32 sys_free(u32 ptr);
+u32 sys_get(u32 id);
+
+u32 sys_map(u32 id, u32 *function);
+
#endif \ No newline at end of file
diff --git a/src/shared/common.h b/src/shared/common.h
index aa9b281..9680b1b 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -2,18 +2,33 @@
#define MELVIX_COMMON_H
// Syscalls
-#define SYS_HALT 0
-#define SYS_EXIT 1
-#define SYS_FORK 2
-#define SYS_READ 3
-#define SYS_WRITE 4
-#define SYS_EXEC 5
-#define SYS_GET_PID 6
-#define SYS_MALLOC 7
-#define SYS_FREE 8
+#define SYS_HALT 0 // Halt (debug)
+#define SYS_EXIT 1 // Exit process
+#define SYS_FORK 2 // Fork process
+#define SYS_READ 3 // Read file
+#define SYS_WRITE 4 // Write file
+#define SYS_EXEC 5 // Execute file
+#define SYS_GET_PID 6 // Get process id
+#define SYS_MALLOC 7 // Allocate memory
+#define SYS_FREE 8 // Free memory
+#define SYS_GET 9 // Get kernel variable
+#define SYS_MAP 10 // Map input to function
-// Registration
-#define REG_KEYBOARD 0
-#define REG_MOUSE 1
+// Get
+#define GET_FRAMEBUFFER 0
+
+// Mappings
+#define MAP_KEYBOARD 0
+#define MAP_MOUSE 1
+
+// Common event structs
+struct keyboard_event {
+ int scancode;
+};
+
+struct mouse_event {
+ int mouse_x;
+ int mouse_y;
+};
#endif \ No newline at end of file
diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c
index cf9dc89..d5c6708 100644
--- a/src/userspace/libc/syscall.c
+++ b/src/userspace/libc/syscall.c
@@ -21,4 +21,8 @@ DEFN_SYSCALL0(get_pid, SYS_GET_PID);
DEFN_SYSCALL1(malloc, SYS_MALLOC, u32);
-DEFN_SYSCALL1(free, SYS_FREE, u32); \ No newline at end of file
+DEFN_SYSCALL1(free, SYS_FREE, u32);
+
+DEFN_SYSCALL1(get, SYS_GET, u32);
+
+DEFN_SYSCALL2(map, SYS_MAP, u32, u8 *); \ No newline at end of file
diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h
index 038f985..30925da 100644
--- a/src/userspace/libc/syscall.h
+++ b/src/userspace/libc/syscall.h
@@ -86,4 +86,8 @@ DECL_SYSCALL1(malloc, u32);
DECL_SYSCALL1(free, u32);
+DECL_SYSCALL1(get, u32);
+
+DECL_SYSCALL2(map, u32, u8 *);
+
#endif \ No newline at end of file
diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c
index 732c104..5ff1864 100644
--- a/src/userspace/programs/init.c
+++ b/src/userspace/programs/init.c
@@ -1,15 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
+#include <common.h>
#include <syscall.h>
#include <unistd.h>
#include <gui.h>
+void test(u8 *data)
+{
+ syscall_halt();
+}
+
void main()
{
/* gui_init(); */
/* gui_screen_clear(); */
//printf("Initializing userspace...\n");
- syscall_exec("/bin/sh");
+ syscall_map(MAP_KEYBOARD, (u8 *)&test);
+
+ //syscall_exec("/bin/sh");
while (1) {
};