diff options
author | Marvin Borner | 2019-12-08 12:27:00 +0100 |
---|---|---|
committer | Marvin Borner | 2019-12-08 12:27:00 +0100 |
commit | e3c982ee44cff38bd764fbb6ab94972cf868a10a (patch) | |
tree | 755ed2716a4a3fb6caf04abaef00a784297692fe | |
parent | d94b024b73aeca06de417e0fd3c502495312a8b2 (diff) |
Working text input!
-rw-r--r-- | src/kernel/input/input.h | 2 | ||||
-rw-r--r-- | src/kernel/input/ps2/keyboard.c | 11 | ||||
-rw-r--r-- | src/kernel/kernel.c | 1 | ||||
-rw-r--r-- | src/kernel/lib/stdio/getch.c | 10 | ||||
-rw-r--r-- | src/kernel/paging/paging.c | 2 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_read.c | 23 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_write.c | 5 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.h | 4 | ||||
-rw-r--r-- | src/userspace/main.c | 8 | ||||
-rw-r--r-- | src/userspace/syscall.h | 4 |
10 files changed, 34 insertions, 36 deletions
diff --git a/src/kernel/input/input.h b/src/kernel/input/input.h index 3152622..bacfaaa 100644 --- a/src/kernel/input/input.h +++ b/src/kernel/input/input.h @@ -14,6 +14,8 @@ void keyboard_install(); void keyboard_clear_buffer(); +char keyboard_char_buffer; + char *keyboard_buffer; #endif diff --git a/src/kernel/input/ps2/keyboard.c b/src/kernel/input/ps2/keyboard.c index 9e133ef..223a7c5 100644 --- a/src/kernel/input/ps2/keyboard.c +++ b/src/kernel/input/ps2/keyboard.c @@ -106,7 +106,8 @@ void keyboard_handler(struct regs *r) return; } - keyboard_buffer[strlen(keyboard_buffer)] = current_keymap[scan_code]; + keyboard_char_buffer = current_keymap[scan_code]; + keyboard_buffer[strlen(keyboard_buffer)] = keyboard_char_buffer; } else { // RELEASE if (current_keymap[scan_code] == -107) // TODO: IDK WHY -107?! control_pressed = 0; @@ -127,15 +128,15 @@ void keyboard_rate() void keyboard_clear_buffer() { - memset(keyboard_buffer, 0, 4096); + kfree(keyboard_buffer); + keyboard_buffer = (char *) paging_alloc_pages(1); // 4KiB + paging_set_user((uint32_t) keyboard_buffer, 1); } // Installs the keyboard handler into IRQ1 void keyboard_install() { - keyboard_buffer = (char *) paging_alloc_pages(1); // 4KiB - paging_set_user((uint32_t) keyboard_buffer, 1); - + keyboard_clear_buffer(); keyboard_rate(); irq_install_handler(1, keyboard_handler); shift_pressed = 0; diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index bfd0803..f1b2df8 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -14,6 +14,7 @@ #include <kernel/fs/iso9660/iso9660.h> #include <kernel/fs/atapi_pio.h> #include <kernel/lib/stdlib/liballoc.h> +#include <kernel/lib/stdio.h> extern void jump_userspace(); diff --git a/src/kernel/lib/stdio/getch.c b/src/kernel/lib/stdio/getch.c index 5361c97..f3ccbd9 100644 --- a/src/kernel/lib/stdio/getch.c +++ b/src/kernel/lib/stdio/getch.c @@ -1,9 +1,11 @@ #include <kernel/input/input.h> -#include <kernel/lib/string.h> +#include <kernel/timer/timer.h> char getch() { - keyboard_clear_buffer(); - while (strlen(keyboard_buffer) == 0) {} - return keyboard_buffer[0]; + keyboard_char_buffer = 0; + while (keyboard_char_buffer == 0) { + timer_wait(1); // IDK why! + } + return keyboard_char_buffer; }
\ No newline at end of file diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c index 8540bc6..6fab537 100644 --- a/src/kernel/paging/paging.c +++ b/src/kernel/paging/paging.c @@ -160,4 +160,4 @@ uint32_t paging_get_used_pages() } } return n; -} +}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c index 761eec7..673d2d9 100644 --- a/src/kernel/syscall/actions/sys_read.c +++ b/src/kernel/syscall/actions/sys_read.c @@ -1,21 +1,16 @@ -#include <stdint-gcc.h> +#include <stdint.h> #include <kernel/lib/stdio.h> -#include <kernel/lib/string.h> -#include <kernel/io/io.h> #include <kernel/input/input.h> -#include <kernel/timer/timer.h> +#include <kernel/lib/lib.h> +#include <kernel/lib/string.h> -uint32_t sys_read() +uint32_t sys_read(char *buf) { - serial_write("CALL\n"); - keyboard_clear_buffer(); - while (keyboard_buffer[strlen(keyboard_buffer) - 1] != '\n') { - { - timer_wait(1); // IDK why? - } + keyboard_char_buffer = 0; + while (keyboard_char_buffer != '\n') { + getch(); } - serial_write(keyboard_buffer); - serial_write("\n"); - return (uint32_t) keyboard_buffer; + memcpy(buf, keyboard_buffer, strlen(keyboard_buffer)); + return strlen(buf); }
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c index aef2b2b..e0db9b0 100644 --- a/src/kernel/syscall/actions/sys_write.c +++ b/src/kernel/syscall/actions/sys_write.c @@ -3,9 +3,8 @@ #include <kernel/lib/string.h> #include <kernel/io/io.h> -uint32_t sys_write(unsigned int buf) +uint32_t sys_write(char *buf) { - serial_put(((char *) buf)[0]); - printf((const char *) buf); + printf(buf); return strlen((const char *) buf); }
\ No newline at end of file diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h index 8ed532d..f441cf1 100644 --- a/src/kernel/syscall/syscall.h +++ b/src/kernel/syscall/syscall.h @@ -5,8 +5,8 @@ extern void idt_syscall(); void syscalls_install(); -uint32_t sys_write(unsigned int buf); +uint32_t sys_write(char *buf); -uint32_t sys_read(); +uint32_t sys_read(char *buf); #endif
\ No newline at end of file diff --git a/src/userspace/main.c b/src/userspace/main.c index c85e64d..1e68496 100644 --- a/src/userspace/main.c +++ b/src/userspace/main.c @@ -1,5 +1,4 @@ #include <syscall.h> -#include <mlibc/string.h> void user_main() { @@ -7,9 +6,8 @@ void user_main() syscall_write(hello); while (1) { - char *command = (char *) syscall_read(); - char test[1024]; - strcpy(test, command); - syscall_write(command); + char buffer[20] = {'\0'}; + syscall_read(buffer); + syscall_write(buffer); }; }
\ No newline at end of file diff --git a/src/userspace/syscall.h b/src/userspace/syscall.h index 6750093..d5d8920 100644 --- a/src/userspace/syscall.h +++ b/src/userspace/syscall.h @@ -64,13 +64,13 @@ */ DECL_SYSCALL1(write, char *); -DECL_SYSCALL0(read); +DECL_SYSCALL1(read, char *); /** * DEFINITIONS */ DEFN_SYSCALL1(write, 1, char *); -DEFN_SYSCALL0(read, 2); +DEFN_SYSCALL1(read, 2, char *); #endif |