vxBoot/src/builtin/ld.c

71 lines
1.4 KiB
C

#include "vxBoot/builtin.h"
#include "vxBoot/terminal.h"
#include "vxBoot/loader.h"
#include <stdlib.h>
#include <string.h>
int ld_main(int argc, char **argv)
{
extern struct ldimg *kernel_img_list;
char const *path;
struct ldimg *img;
char *endptr;
int counter;
int mode;
int idx;
if (argc >= 4) {
terminal_write(
"too much argument, ony the kernel ID is needed\n"
);
return (84);
}
if (argc == 1) {
if (kernel_img_list == NULL) {
terminal_write(
"no kernel found in you storage memroy :(\n"
);
return (0);
}
counter = 0;
img = kernel_img_list;
while (img != NULL) {
terminal_write("[%d] %s\n", counter, img->inode->name);
img = img->next;
counter += 1;
}
return (0);
}
path = argv[1];
mode = LOADER_DEFAULT;
if (strcmp(argv[1], "dump") == 0) {
path = argv[2];
mode = LOADER_DUMP;
}
if (strcmp(argv[1], "trace") == 0) {
path = argv[2];
mode = LOADER_TRACE;
}
if (strcmp(argv[1], "info") == 0) {
path = argv[2];
mode = LOADER_INFO;
}
if (strcmp(argv[1], "check") == 0) {
path = argv[2];
mode = LOADER_CHECK;
}
img = kernel_img_list;
idx = strtol(path, &endptr, 10) + 1;
if (endptr == NULL || endptr[0] != '\0') {
terminal_write("kernel ID is not valid\n");
return (84);
}
while (img != NULL && --idx > 0) { img = img->next; }
if (img == NULL) {
terminal_write("kernel ID '%d' does not exist :(\n");
return (84);
}
return (loader(img->inode, mode));
}