diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.asm | 2 | ||||
-rw-r--r-- | src/commands/command.c | 19 | ||||
-rw-r--r-- | src/graphics/graphics.h | 2 | ||||
-rw-r--r-- | src/graphics/vga.c | 22 | ||||
-rw-r--r-- | src/interrupts/idt.c | 2 | ||||
-rw-r--r-- | src/interrupts/interrupts.h | 2 | ||||
-rw-r--r-- | src/interrupts/irq.c | 4 | ||||
-rw-r--r-- | src/io/io.asm | 11 | ||||
-rw-r--r-- | src/kernel.c | 4 | ||||
-rw-r--r-- | src/lib/lib.h | 10 | ||||
-rw-r--r-- | src/lib/memory.c (renamed from src/memory/memory.c) | 12 | ||||
-rw-r--r-- | src/lib/string.c | 19 | ||||
-rw-r--r-- | src/memory/memory.h | 10 |
13 files changed, 88 insertions, 31 deletions
diff --git a/src/boot.asm b/src/boot.asm index 681bf10..0581eb6 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -42,6 +42,8 @@ stublet: %include "src/interrupts/irq.asm" +%include "src/io/io.asm" + ; Store the stack SECTION .bss resb 8192 ; Reserve 8KiB diff --git a/src/commands/command.c b/src/commands/command.c index ee53c90..eeac08e 100644 --- a/src/commands/command.c +++ b/src/commands/command.c @@ -1,17 +1,24 @@ #include "../graphics/graphics.h" #include "../lib/lib.h" +#include "../io/io.h" int32_t starts_with(const char *a, const char *b) { - if (strcmp(a, b, strlen(b)) == 0) - return 1 - return 0 + size_t length_pre = strlen(b); + size_t length_main = strlen(a); + return length_main < length_pre ? 0 : memory_compare(b, a, length_pre) == 0; } +extern void shutdown(); + void exec_command(char *command) { if (starts_with(command, "ls")) - terminal_write_string("// listing files"); + terminal_write_line("Listing files"); else if (starts_with(command, "help")) - terminal_write_string("I can't help you write now"); + terminal_write_line("I can't help you write now"); else if (starts_with(command, "ping")) - terminal_write_string("pong!") + terminal_write_line("pong!"); + else if (starts_with(command, "shutdown")) + shutdown(); + else + terminal_write_line("Command not found!"); } diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 7c449f1..a9ed917 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -16,4 +16,6 @@ void terminal_write_string(const char *data); void terminal_put_char(char c); +void terminal_write_line(const char *data); + #endif
\ No newline at end of file diff --git a/src/graphics/vga.c b/src/graphics/vga.c index 5fb205b..86c00ff 100644 --- a/src/graphics/vga.c +++ b/src/graphics/vga.c @@ -3,6 +3,7 @@ #include "../io/io.h" #include "../lib/lib.h" #include "../commands/command.h" +#include "../interrupts/interrupts.h" // Hardware text mode color constants enum vga_color { @@ -40,6 +41,8 @@ size_t terminal_column; uint8_t terminal_color; uint16_t *terminal_buffer; +char text[1024] = {0}; + void terminal_clear() { for (size_t y = 0; y < VGA_HEIGHT; y++) { for (size_t x = 0; x < VGA_WIDTH; x++) { @@ -94,14 +97,6 @@ void terminal_put_entry_at(char c, uint8_t color, size_t x, size_t y) { terminal_buffer[index] = vga_entry(c, color); } -char* terminal_get_line() { - char* line = ""; - for (size_t x = 0; x < terminal_column; i++) { - line += terminal_buffer[terminal_row * VGA_WIDTH + x]; - // TODO: Fix returning line.. - return line; -} - void terminal_put_char(char c) { if (c == 0x08) { if (terminal_column != 0) terminal_column--; @@ -110,13 +105,15 @@ void terminal_put_char(char c) { } else if (c == '\r') { terminal_column = 0; } else if (c == '\n') { - exec_command(terminal_get_line()); + if (irq_is_installed(1)) exec_command(text); + memory_set(text, 0, sizeof(text)); terminal_column = 0; terminal_row++; terminal_scroll(); terminal_put_entry_at('$', terminal_color, terminal_column, terminal_row); terminal_column = 2; } else if (c >= ' ') { // Any printable character + strcat(text, &c); terminal_put_entry_at(c, terminal_color, terminal_column, terminal_row); terminal_column++; } @@ -139,3 +136,10 @@ void terminal_write(const char *data, size_t size) { void terminal_write_string(const char *data) { terminal_write(data, strlen(data)); } + +void terminal_write_line(const char *data) { + terminal_row++; + terminal_column = 0; + terminal_write_string(data); + terminal_column = 0; +} diff --git a/src/interrupts/idt.c b/src/interrupts/idt.c index 0fb95df..ba71339 100644 --- a/src/interrupts/idt.c +++ b/src/interrupts/idt.c @@ -1,4 +1,4 @@ -#include "../memory/memory.h" +#include "../lib/lib.h" struct idt_entry { unsigned short base_lo; diff --git a/src/interrupts/interrupts.h b/src/interrupts/interrupts.h index b91e91c..755a633 100644 --- a/src/interrupts/interrupts.h +++ b/src/interrupts/interrupts.h @@ -25,4 +25,6 @@ void irq_uninstall_handler(int irq); void irq_handler(struct regs *r); +int irq_is_installed(int irq); + #endif diff --git a/src/interrupts/irq.c b/src/interrupts/irq.c index 70f1eff..cf9e1fe 100644 --- a/src/interrupts/irq.c +++ b/src/interrupts/irq.c @@ -50,6 +50,10 @@ void irq_uninstall_handler(int irq) { irq_routines[irq] = 0; } +int irq_is_installed(int irq) { + return irq_routines[irq] != 0; +} + // Remap IRQs for protected mode compatibility via the PIC void irq_remap(void) { send(0x20, 0x11); diff --git a/src/io/io.asm b/src/io/io.asm new file mode 100644 index 0000000..6776c56 --- /dev/null +++ b/src/io/io.asm @@ -0,0 +1,11 @@ +global shutdown +shutdown: + mov ax, 0x1000 + mov ax, ss + mov sp, 0xf000 + mov ax, 0x5307 + mov bx, 0x0001 + mov cx, 0x0003 + int 0x15 + + ret
\ No newline at end of file diff --git a/src/kernel.c b/src/kernel.c index ca4150e..e08c370 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -14,12 +14,12 @@ void kernel_main(void) { __asm__ __volatile__ ("sti"); terminal_initialize(); + terminal_write_string("Melvix loaded successfully!\n"); + timer_install(); keyboard_install(); mouse_install(); - terminal_write_string("Melvix loaded successfully!\n"); - beep(262, 20); beep(294, 20); beep(330, 20); diff --git a/src/lib/lib.h b/src/lib/lib.h index aa5d3bc..f0d7d1b 100644 --- a/src/lib/lib.h +++ b/src/lib/lib.h @@ -1,8 +1,18 @@ #ifndef MELVIX_LIB_H #define MELVIX_LIB_H +#include <stddef.h> + size_t strlen(const char *str); size_t strcmp(const char *s1, const char *s2); +char *strcat(char *dst, const char *src); + +void *memory_copy(void *dest, const void *src, size_t count); + +void *memory_set(void *dest, char val, size_t count); + +int memory_compare(const void *a_ptr, const void *b_ptr, size_t size); + #endif diff --git a/src/memory/memory.c b/src/lib/memory.c index b978bcf..e306ada 100644 --- a/src/memory/memory.c +++ b/src/lib/memory.c @@ -12,3 +12,15 @@ void *memory_set(void *dest, char val, size_t count) { for (; count != 0; count--) *temp++ = val; return dest; } + +int memory_compare(const void *a_ptr, const void *b_ptr, size_t size) { + const unsigned char *a = (const unsigned char *) a_ptr; + const unsigned char *b = (const unsigned char *) b_ptr; + for (size_t i = 0; i < size; i++) { + if (a[i] < b[i]) + return -1; + else if (b[i] < a[i]) + return 1; + } + return 0; +}
\ No newline at end of file diff --git a/src/lib/string.c b/src/lib/string.c index a4be160..6ef0316 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -1,3 +1,5 @@ +#include <stddef.h> + size_t strlen(const char *str) { size_t len = 0; while (str[len]) @@ -7,8 +9,19 @@ size_t strlen(const char *str) { size_t strcmp(const char *s1, const char *s2) { while (*s1 && (*s1 == *s2)) { - s1++; - s2++; + s1++; + s2++; + } + return *(const unsigned char *) s1 - *(const unsigned char *) s2; +} + +char *strcat(char *dst, const char *src) { + unsigned int i = 0; + unsigned int j = 0; + for (i = 0; dst[i] != 0; i++) {} + for (j = 0; src[j] != 0; j++) { + dst[i + j] = src[j]; } - return *(const unsigned char*)s1 - *(const unsigned char*)s2; + dst[i + j] = 0; + return dst; } diff --git a/src/memory/memory.h b/src/memory/memory.h deleted file mode 100644 index d605299..0000000 --- a/src/memory/memory.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MELVIX_MEMORY_H -#define MELVIX_MEMORY_H - -#include <stddef.h> - -void *memory_copy(void *dest, const void *src, size_t count); - -void *memory_set(void *dest, char val, size_t count); - -#endif |