Kshell: load executable command

This commit is contained in:
2026-05-04 20:38:10 +02:00
parent ccb6ca89f1
commit c00a247ead
4 changed files with 42 additions and 1 deletions
+1
View File
@@ -10,5 +10,6 @@
#include <limine.h> #include <limine.h>
int initfs_init(struct limine_file* tar_file); int initfs_init(struct limine_file* tar_file);
int tar_lookup(unsigned char* archive, char* filename, char** out);
#endif #endif
+2
View File
@@ -47,6 +47,8 @@ void debug_stack_trace(unsigned int max_frames);
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset); const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset);
void boot_mem_display(void); void boot_mem_display(void);
int loader_load_raw();
#define assert(check) do { if(!(check)) hcf(); } while(0) #define assert(check) do { if(!(check)) hcf(); } while(0)
struct boot_context { struct boot_context {
+7 -1
View File
@@ -51,7 +51,8 @@ void pedicel_main(void* arg)
"pf - trigger a page fault\r\n" "pf - trigger a page fault\r\n"
"now - get current date\r\n" "now - get current date\r\n"
"smash - smash the stack\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; continue;
} }
@@ -96,6 +97,11 @@ void pedicel_main(void* arg)
continue; continue;
} }
if (strncmp(input_buf, "load", 4) == 0) {
loader_load_raw();
continue;
}
printf("%s: command not found\r\n", input_buf); printf("%s: command not found\r\n", input_buf);
} }
} }
+32
View File
@@ -0,0 +1,32 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Executable loader
* @license GPL-3.0-only
*/
#include <stddef.h>
#include <fs/initfs.h>
#include <kernel.h>
#include <sched/process.h>
#include <io/kbd/ps2.h>
#include <string/string.h>
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;
}