diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 58988fc..519ef6b 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/makefile b/makefile index 1df1132..b619ecb 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc -CFLAGS = -Wall -Wextra -Wno-div-by-zero -Wno-builtin-declaration-mismatch -c -I src/ +CFLAGS = -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/ LDFLAGS = -T link.ld -melf_i386 AS = nasm ASFLAGS = -f elf diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 815fe5a..340f623 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -4,59 +4,68 @@ #include "../programs/programs.h" #define BUFFER_SIZE 256 +#define MAX_COMMANDS 16 + +typedef void (*command_func_t)(); + +typedef struct +{ + const char* name; + command_func_t function; +} shell_command_t; + +shell_command_t shell_commands[MAX_COMMANDS]; +int command_count = 0; + +void register_command(const char* name, command_func_t function) +{ + if (command_count < MAX_COMMANDS) + { + shell_commands[command_count].name = name; + shell_commands[command_count].function = function; + command_count++; + } +} + +command_func_t find_command(const char* name) +{ + for (int i=0; i < command_count; i++) + { + if (strcmp(name, shell_commands[i].name) == 0) + return shell_commands[i].function; + } + return 0; +} void shell_install() { - while (1) // Bad!! + register_command("help", program_help); + register_command("panic", program_panic); + register_command("words", program_words); + register_command("primes", program_primes); + register_command("rainbow", program_rainbow); + register_command("clear", program_clear); + register_command("math", program_math); + register_command("bf", program_bf); + register_command("uptime", program_uptime); + + for (;;) { char input_buffer[BUFFER_SIZE]; colorputs("blankos> ", 9); get_input(input_buffer, BUFFER_SIZE); puts("\n"); - - // Childish shell - if (strcmp(input_buffer, "") == 0) - { - continue; + + if (strcmp(input_buffer, "") == 0) { + continue; } - else if (strcmp(input_buffer, "help") == 0) + + command_func_t command = find_command(input_buffer); + if (command) { - printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\tuptime\n"); - } - else if (strcmp(input_buffer, "panic") == 0) - { - printf("%d", 4/0); - } - else if (strcmp(input_buffer, "words") == 0) - { - program_words(); - } - else if (strcmp(input_buffer, "primes") == 0) - { - program_primes(); - } - else if (strcmp(input_buffer, "rainbow") == 0) - { - program_rainbow(); - } - else if (strcmp(input_buffer, "clear") == 0) - { - program_clear(); - } - else if (strcmp(input_buffer, "math") == 0) - { - program_math(); - } - else if (strcmp(input_buffer, "bf") == 0) - { - program_bf(); - } - else if (strcmp(input_buffer, "uptime") == 0) - { - program_uptime(); - } - else { - printf("Unknown command %s\n", input_buffer); + command(); + } else { + printf("Unknown command %s\n", input_buffer); } } } diff --git a/src/libc/string.c b/src/libc/string.c index 54fedc9..3e2de92 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -1,4 +1,4 @@ -int strlen(char* str) +int strlen(const char* str) { int len = 0; while (*str++) @@ -8,7 +8,7 @@ int strlen(char* str) return len; } -int strcmp(char* str1, char* str2) +int strcmp(const char* str1, const char* str2) { while (*str1 && (*str1 == *str2)) { @@ -16,4 +16,4 @@ int strcmp(char* str1, char* str2) str2++; } return *(const unsigned char*)str1 - *(const unsigned char*)str2; -} \ No newline at end of file +} diff --git a/src/libc/string.h b/src/libc/string.h index 7e406bd..0f64804 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -1,7 +1,7 @@ #ifndef INCLUDE_STRING_H #define INCLUDE_STRING_H -int strlen(char* str); -int strcmp(char* str1, char* str2); +int strlen(const char* str); +int strcmp(const char* str1, const char* str2); #endif diff --git a/src/programs/misc.c b/src/programs/misc.c index c255492..7b3c959 100644 --- a/src/programs/misc.c +++ b/src/programs/misc.c @@ -39,3 +39,15 @@ void program_uptime() double seconds = ticks/18.2065; // PIC channel 0 freq printf("%d ticks\t%f seconds\n", ticks, seconds); } + +// Get help + +void program_help() +{ + printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\tuptime\n"); +} + +void program_panic() +{ + asm volatile("int $0x13"); +} diff --git a/src/programs/programs.h b/src/programs/programs.h index c533b3b..568c570 100644 --- a/src/programs/programs.h +++ b/src/programs/programs.h @@ -10,5 +10,6 @@ void program_bf(); void program_rainbow(); void program_clear(); void program_uptime(); - +void program_panic(); +void program_help(); #endif