diff --git a/include/fs/initfs.h b/include/fs/initfs.h index 11c9857..c47d517 100644 --- a/include/fs/initfs.h +++ b/include/fs/initfs.h @@ -10,5 +10,6 @@ #include int initfs_init(struct limine_file* tar_file); +int tar_lookup(unsigned char* archive, char* filename, char** out); #endif \ No newline at end of file diff --git a/include/kernel.h b/include/kernel.h index f15579a..01cfb42 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -47,6 +47,8 @@ void debug_stack_trace(unsigned int max_frames); const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset); void boot_mem_display(void); +int loader_load_raw(); + #define assert(check) do { if(!(check)) hcf(); } while(0) struct boot_context { diff --git a/src/kapps/kshell.c b/src/kapps/kshell.c index f4a6852..46cd6dc 100644 --- a/src/kapps/kshell.c +++ b/src/kapps/kshell.c @@ -51,7 +51,8 @@ void pedicel_main(void* arg) "pf - trigger a page fault\r\n" "now - get current date\r\n" "smash - smash the stack\r\n" - "mem - get used heap info\r\n"); + "mem - get used heap info\r\n" + "load - load an user executable\r\n"); continue; } @@ -96,6 +97,11 @@ void pedicel_main(void* arg) continue; } + if (strncmp(input_buf, "load", 4) == 0) { + loader_load_raw(); + continue; + } + printf("%s: command not found\r\n", input_buf); } } \ No newline at end of file diff --git a/src/kapps/loader.c b/src/kapps/loader.c new file mode 100644 index 0000000..4ee510d --- /dev/null +++ b/src/kapps/loader.c @@ -0,0 +1,32 @@ +/* + * @author xamidev + * @brief Executable loader + * @license GPL-3.0-only + */ + +#include +#include +#include +#include +#include +#include + +extern void* archive_start_addr; + +int loader_load_raw() +{ + char input_buf[PEDICEL_INPUT_SIZE] = {0}; + do { + printf("file> "); + keyboard_getline(input_buf, PEDICEL_INPUT_SIZE); + } while (strncmp(input_buf, "", 1) == 0); + + char* data = NULL; + int sz = tar_lookup(archive_start_addr, input_buf,&data); + if (sz > 0) { + process_create_user_raw(data, sz, input_buf); + return 0; // TODO: should return something else on error + } + printf("Couldn't load file '%s'\r\n", input_buf); + return 1; +} \ No newline at end of file