2011-12-11 03:34:10 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
2011-03-26 21:30:08 +03:00
|
|
|
* Kernel Argument Parser
|
2011-04-15 05:36:51 +04:00
|
|
|
*
|
|
|
|
* Parses arguments passed by, ie, a Multiboot bootloader.
|
|
|
|
*
|
|
|
|
* Part of the ToAruOS Kernel.
|
|
|
|
* (C) 2011 Kevin Lange
|
2011-03-26 21:30:08 +03:00
|
|
|
*/
|
|
|
|
#include <system.h>
|
|
|
|
|
2011-11-19 00:38:27 +04:00
|
|
|
extern void bochs_install_wallpaper(char *);
|
|
|
|
|
2011-04-15 05:36:51 +04:00
|
|
|
/**
|
|
|
|
* Parse the given arguments to the kernel.
|
|
|
|
*
|
|
|
|
* @param arg A string containing all arguments, separated by spaces.
|
|
|
|
*/
|
2011-03-26 21:30:08 +03:00
|
|
|
void
|
2011-04-15 05:36:51 +04:00
|
|
|
parse_args(
|
|
|
|
char * arg /* Arguments */
|
|
|
|
) {
|
|
|
|
/* Sanity check... */
|
2011-03-29 05:34:53 +04:00
|
|
|
if (!arg) { return; }
|
2011-04-15 05:36:51 +04:00
|
|
|
char * pch; /* Tokenizer pointer */
|
|
|
|
char * save; /* We use the reentrant form of strtok */
|
|
|
|
char * argv[1024]; /* Command tokens (space-separated elements) */
|
|
|
|
int tokenid = 0; /* argc, basically */
|
|
|
|
|
|
|
|
/* Tokenize the arguments, splitting at spaces */
|
2011-03-26 21:30:08 +03:00
|
|
|
pch = strtok_r(arg," ",&save);
|
2011-04-15 05:36:51 +04:00
|
|
|
if (!pch) { return; }
|
2011-03-26 21:30:08 +03:00
|
|
|
while (pch != NULL) {
|
|
|
|
argv[tokenid] = (char *)pch;
|
|
|
|
++tokenid;
|
|
|
|
pch = strtok_r(NULL," ",&save);
|
|
|
|
}
|
|
|
|
argv[tokenid] = NULL;
|
2011-04-15 05:36:51 +04:00
|
|
|
/* Tokens are now stored in argv. */
|
|
|
|
|
|
|
|
|
2011-03-26 21:30:08 +03:00
|
|
|
for (int i = 0; i < tokenid; ++i) {
|
2011-04-15 05:36:51 +04:00
|
|
|
/* Parse each provided argument */
|
2011-11-19 00:38:27 +04:00
|
|
|
char * pch_i;
|
|
|
|
char * save_i;
|
|
|
|
char * argp[1024];
|
|
|
|
int argc = 0;
|
2012-08-16 09:44:20 +04:00
|
|
|
pch_i = strtok_r(argv[i],"=",&save_i);
|
2011-11-19 00:38:27 +04:00
|
|
|
if (!pch_i) { continue; }
|
|
|
|
while (pch_i != NULL) {
|
|
|
|
argp[argc] = (char *)pch_i;
|
|
|
|
++argc;
|
2012-08-16 09:44:20 +04:00
|
|
|
pch_i = strtok_r(NULL,"=",&save_i);
|
2011-11-19 00:38:27 +04:00
|
|
|
}
|
|
|
|
argp[argc] = NULL;
|
2011-04-15 05:36:51 +04:00
|
|
|
|
2011-11-19 00:38:27 +04:00
|
|
|
if (!strcmp(argp[0],"vid")) {
|
|
|
|
if (argc < 2) { kprintf("vid=?\n"); continue; }
|
2011-12-17 00:00:48 +04:00
|
|
|
uint16_t x, y;
|
|
|
|
if (argc < 4) {
|
|
|
|
x = 1024;
|
|
|
|
y = 768;
|
|
|
|
} else {
|
|
|
|
x = atoi(argp[2]);
|
|
|
|
y = atoi(argp[3]);
|
|
|
|
}
|
2012-08-16 09:44:20 +04:00
|
|
|
kprintf("--> Requested display resolution is %dx%d\n", x, y);
|
2011-11-19 00:38:27 +04:00
|
|
|
if (!strcmp(argp[1],"qemu")) {
|
|
|
|
/* Bochs / Qemu Video Device */
|
2011-12-16 23:39:34 +04:00
|
|
|
graphics_install_bochs(x,y);
|
2011-12-17 00:00:48 +04:00
|
|
|
} else if (!strcmp(argp[1],"vesa")) {
|
|
|
|
graphics_install_vesa(x,y);
|
2011-11-19 00:38:27 +04:00
|
|
|
} else {
|
|
|
|
kprintf("Unrecognized video adapter: %s\n", argp[1]);
|
|
|
|
}
|
2011-12-15 08:30:46 +04:00
|
|
|
} else if (!strcmp(argp[0],"hdd")) {
|
|
|
|
extern void ext2_disk_mount(void);
|
|
|
|
ext2_disk_mount();
|
2012-03-28 06:47:25 +04:00
|
|
|
} else if (!strcmp(argp[0],"single")) {
|
|
|
|
boot_arg = "--single";
|
2012-04-11 08:35:12 +04:00
|
|
|
} else if (!strcmp(argp[0],"vgaterm")) {
|
|
|
|
boot_arg = "--vga";
|
2011-03-26 21:30:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-15 05:36:51 +04:00
|
|
|
|