Kshell: load executable command
This commit is contained in:
@@ -10,5 +10,6 @@
|
||||
#include <limine.h>
|
||||
|
||||
int initfs_init(struct limine_file* tar_file);
|
||||
int tar_lookup(unsigned char* archive, char* filename, char** out);
|
||||
|
||||
#endif
|
||||
@@ -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 {
|
||||
|
||||
+7
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user