diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2019-05-26 19:28:27 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2019-05-26 19:28:27 +0100 |
| commit | bd77381c27ef5b61bf1c123efef3895b98a7a615 (patch) | |
| tree | ba798b442305ad4e174d79cf5bb7a822b7e1e2e9 | |
| parent | eb4de24523e8f0832daae89a083844c8e9a261e9 (diff) | |
| download | tinyOS-bd77381c27ef5b61bf1c123efef3895b98a7a615.tar.xz tinyOS-bd77381c27ef5b61bf1c123efef3895b98a7a615.zip | |
Proxy keypress from kernel to focused program
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | kernel/io/keyboard/keyboard_handler.c | 15 | ||||
| -rw-r--r-- | kernel/kernel.c | 24 | ||||
| -rw-r--r-- | os/main.c | 42 | ||||
| -rw-r--r-- | os/main.h | 13 | ||||
| -rw-r--r-- | os/shell/shell.c | 23 | ||||
| -rw-r--r-- | os/shell/shell.h | 3 |
7 files changed, 88 insertions, 34 deletions
@@ -13,6 +13,8 @@ build: setup kernel/kernel.c kernel/global_descriptor_table.c kernel/gpu/text_mo $(CC) $(CFLAGS) -c kernel/global_descriptor_table.c -o bin/global_descriptor_table.o $(CC) $(CFLAGS) -c kernel/gpu/text_mode/display.c -o bin/text_mode_display.o $(CC) $(CFLAGS) -c kernel/io/keyboard/keyboard_handler.c -o bin/keyboard_handler.o + $(CC) $(CFLAGS) -c os/main.c -o bin/main.o + $(CC) $(CFLAGS) -c os/shell/shell.c -o bin/shell.o ld -m elf_i386 -T link.ld -o bin/kernel.bin bin/*.o clean: diff --git a/kernel/io/keyboard/keyboard_handler.c b/kernel/io/keyboard/keyboard_handler.c index 26b4586..e06936d 100644 --- a/kernel/io/keyboard/keyboard_handler.c +++ b/kernel/io/keyboard/keyboard_handler.c @@ -1,6 +1,7 @@ #include "../../interrupt_descriptor_table.h" #include "../../gpu/text_mode/display.h" #include "scancode_map.h" +#include "../../../os/main.h" extern void keyboard_handler(void); extern char read_port(unsigned short port); @@ -66,18 +67,8 @@ void handle_keypress() { if(!isKeyup(scancode)) { - char pressed_key = scancode_map[scancode]; - switch(pressed_key) - { - case '\b': - scrn_backspace(); - break; - case '\n': - scrn_newline(); - break; - default: - scrn_putchar(pressed_key); - } + unsigned char pressed_key = scancode_map[scancode]; + os_proxy_keypress(pressed_key); } } diff --git a/kernel/kernel.c b/kernel/kernel.c index 7f702e7..bd90a3f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -2,32 +2,12 @@ #include "./gpu/text_mode/colours.h" #include "./io/keyboard/keyboard_handler.h" #include "global_descriptor_table.h" - -void run_kern_demo() -{ - scrn_enable_cursor(10, 12); - scrn_clear(); - scrn_set_text_colour(COLOUR_LIGHT_GREEN, COLOUR_BLACK); - - scrn_println(" _ _ ____ _____ "); - scrn_println(" | | (_) / __ \\ / ____|"); - scrn_println(" | |_ _ _ __ _ _| | | | (___ "); - scrn_println(" | __| | '_ \\| | | | | | |\\___ \\ "); - scrn_println(" | |_| | | | | |_| | |__| |____) |"); - scrn_println(" \\__|_|_| |_|\\__, |\\____/|_____/ "); - scrn_println(" __/ | "); - scrn_println(" |___/ "); - - scrn_set_text_colour(COLOUR_WHITE, COLOUR_BLACK); - scrn_newline(); -} - - +#include "../os/main.h" void kernel_entrypoint() { init_gdt(); init_keyboard_handler(); - run_kern_demo(); + os_start(); while(1); } diff --git a/os/main.c b/os/main.c new file mode 100644 index 0000000..905b0f7 --- /dev/null +++ b/os/main.c @@ -0,0 +1,42 @@ +#include "../kernel/gpu/text_mode/display.h" +#include "../kernel/gpu/text_mode/colours.h" +#include "main.h" +#include "./shell/shell.h" + +Program_t focused_program; + +void os_show_splash() +{ + scrn_enable_cursor(10, 12); + scrn_clear(); + scrn_set_text_colour(COLOUR_LIGHT_GREEN, COLOUR_BLACK); + + scrn_println(" _ _ ____ _____ "); + scrn_println(" | | (_) / __ \\ / ____|"); + scrn_println(" | |_ _ _ __ _ _| | | | (___ "); + scrn_println(" | __| | '_ \\| | | | | | |\\___ \\ "); + scrn_println(" | |_| | | | | |_| | |__| |____) |"); + scrn_println(" \\__|_|_| |_|\\__, |\\____/|_____/ "); + scrn_println(" __/ | "); + scrn_println(" |___/ "); + + scrn_set_text_colour(COLOUR_WHITE, COLOUR_BLACK); + scrn_newline(); +} + +void os_start() +{ + os_show_splash(); +} + +// TODO keep a stack of running programs +void os_update_focused_program(Program_t program) { + focused_program = shell_run(); +} + +// Send keypress from kernel to the currently focused programs keypress handler +void os_proxy_keypress(unsigned char key) { + (focused_program.keypress_handler)(key); +} + +// TODO display handling
\ No newline at end of file diff --git a/os/main.h b/os/main.h new file mode 100644 index 0000000..a632750 --- /dev/null +++ b/os/main.h @@ -0,0 +1,13 @@ +#ifndef MAIN_H +#define MAIN_H + +typedef struct +{ + char *name; + void (*keypress_handler)(unsigned char); +} Program_t; + +void os_start(); +void os_proxy_keypress(unsigned char key); + +#endif
\ No newline at end of file diff --git a/os/shell/shell.c b/os/shell/shell.c new file mode 100644 index 0000000..933b19c --- /dev/null +++ b/os/shell/shell.c @@ -0,0 +1,23 @@ +#include "../../os/main.h" +#include "../../kernel/gpu/text_mode/display.h" + +void keypress_handler(unsigned char key) { + switch(key) + { + case '\b': + scrn_backspace(); + break; + case '\n': + scrn_newline(); + break; + default: + scrn_putchar(key); + } +} + +Program_t shell_run() { + Program_t this; + this.keypress_handler = keypress_handler; + this.name = "shell"; + return this; +}
\ No newline at end of file diff --git a/os/shell/shell.h b/os/shell/shell.h new file mode 100644 index 0000000..2a8f508 --- /dev/null +++ b/os/shell/shell.h @@ -0,0 +1,3 @@ +#include "../../os/main.h" + +Program_t shell_run();
\ No newline at end of file |