[main] Kernel argument parsing (of a limited sort); qemu vid mode defaults

This commit is contained in:
Kevin Lange 2011-03-26 13:30:08 -05:00
parent 80e993cffb
commit a62649aafe
6 changed files with 63 additions and 18 deletions

View File

@ -30,7 +30,7 @@ install: toaruos-initrd toaruos-kernel
@${ECHO} "\r\033[34;1m -- Kernel and ramdisk installed.\033[0m"
run: toaruos-kernel toaruos-initrd
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -serial stdio -vga std
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -append vid=qemu -serial stdio -vga std
#################
# Documentation #

32
kernel/core/args.c Normal file
View File

@ -0,0 +1,32 @@
/*
* vim:tabstop=4
* vim:noexpandtab
*
* Kernel Argument Parser
*/
#include <system.h>
void
parse_args(char * arg) {
char * pch;
char * cmd;
char * save;
pch = strtok_r(arg," ",&save);
cmd = pch;
if (!cmd) { return; }
char * argv[1024]; /* Command tokens (space-separated elements) */
int tokenid = 0;
while (pch != NULL) {
argv[tokenid] = (char *)pch;
++tokenid;
pch = strtok_r(NULL," ",&save);
}
argv[tokenid] = NULL;
for (int i = 0; i < tokenid; ++i) {
if (!strcmp(argv[i],"vid=qemu")) {
/* QEMU Video Mode, we are free to set things for 1024x768 */
graphics_install_bochs();
bochs_draw_logo();
}
}
}

View File

@ -213,23 +213,7 @@ start_shell() {
}
}
} else if (!strcmp(cmd, "logo")) {
fs_node_t * file = kopen("/bs.bmp",0);
char *bufferb = malloc(file->length);
size_t bytes_read = read_fs(file, 0, file->length, (uint8_t *)bufferb);
size_t i;
uint16_t x = 0;
uint16_t y = 0;
for (i = 54; i < bytes_read; i += 3) {
uint32_t color = bufferb[i] +
bufferb[i+1] * 0x100 +
bufferb[i+2] * 0x10000;
bochs_set_coord(406 + x, 350 + (68 - y), color);
++x;
if (x == 212) {
x = 0;
++y;
}
}
bochs_draw_logo();
} else {
kprintf("Unrecognized command: %s\n", cmd);
}

View File

@ -6,6 +6,7 @@
*/
#include <system.h>
#include <fs.h>
uint16_t bochs_resolution_x = 1024;
uint16_t bochs_resolution_y = 768;
@ -63,3 +64,24 @@ bochs_set_coord(
uint32_t offset = location % BOCHS_BANK_SIZE;
BOCHS_VID_MEMORY[offset] = color;
}
void
bochs_draw_logo() {
fs_node_t * file = kopen("/bs.bmp",0);
char *bufferb = malloc(file->length);
size_t bytes_read = read_fs(file, 0, file->length, (uint8_t *)bufferb);
size_t i;
uint16_t x = 0;
uint16_t y = 0;
for (i = 54; i < bytes_read; i += 3) {
uint32_t color = bufferb[i] +
bufferb[i+1] * 0x100 +
bufferb[i+2] * 0x10000;
bochs_set_coord(406 + x, 350 + (68 - y), color);
++x;
if (x == 212) {
x = 0;
++y;
}
}
}

View File

@ -177,6 +177,9 @@ extern uint32_t getpid();
uintptr_t initial_esp;
/* Kernel Argument Parser */
extern void parse_args(char * argv);
/* CMOS */
extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
@ -185,5 +188,6 @@ extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
extern void graphics_install_bochs();
extern void bochs_set_bank(uint16_t bank);
extern void bochs_set_coord(uint16_t x, uint16_t y, uint32_t color);
extern void bochs_draw_logo();
#endif

View File

@ -125,6 +125,9 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp)
initrd_mount((uintptr_t)ramdisk, 0);
}
}
/* Parse the command-line arguments */
parse_args((char *)mboot_ptr->cmdline);
}
/*