[misc] Fix some general boot issues with some Grubs

This commit is contained in:
Kevin Lange 2011-12-25 18:18:41 -06:00
parent c0f45e0b7f
commit c440ab6477
3 changed files with 44 additions and 48 deletions

View File

@ -40,7 +40,7 @@
#include <fs.h>
#include <logging.h>
extern uintptr_t heap_end;
extern void * end;
/*
* kernel entry point
@ -65,49 +65,46 @@ extern uintptr_t heap_end;
*/
int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
{
memcpy((void*)0x1E00000, (void*)0x0, 0x500);
initial_esp = esp;
enum BOOTMODE boot_mode = unknown; /* Boot Mode */
char * cmdline = NULL;
/* Immediately initialize the video service so we can spew usable error messages */
init_video();
if (mboot_mag == MULTIBOOT_EAX_MAGIC) {
/*
* Multiboot (GRUB, native QEMU, PXE)
*/
boot_mode = multiboot;
mboot_ptr = mboot;
/*
* Realign memory to the end of the multiboot modules
*/
uint32_t module_start = *((uint32_t *) mboot_ptr->mods_addr); /* Start address */
uint32_t module_end = *(uint32_t *) (mboot_ptr->mods_addr + 4); /* End address */
kmalloc_startat(module_end + 1024);
/* Relocate the command line */
size_t len = strlen((char *)mboot_ptr->cmdline);
cmdline = (char *)kmalloc(len + 1);
memmove(cmdline, (char *)mboot_ptr->cmdline, len + 1);
/* Relocate any available modules */
if (mboot_ptr->flags & (1 << 3)) {
ramdisk = (char *)module_start;
/*
* Mboot modules are available.
*/
if (mboot_ptr->mods_count > 0) {
/*
* Ramdisk image was provided. (hopefully)
*/
uint32_t module_start = *((uint32_t *) mboot_ptr->mods_addr); /* Start address */
uint32_t module_end = *(uint32_t *) (mboot_ptr->mods_addr + 4); /* End address */
ramdisk = (char *)kmalloc(module_end - module_start); /* New chunk of ram for it. */
memcpy(ramdisk, (char *)module_start, module_end - module_start); /* Copy it over. */
ramdisk = (char *)kmalloc(module_end - module_start);
memmove(ramdisk, (char *)module_start, module_end - module_start); /* Copy it over. */
}
}
} else {
/*
* This isn't a multiboot attempt. We were probably loaded by
* Mr. Boots, our dedicated boot loader. Verify this...
* Mr. Boots, our (non-existent) dedicated boot loader. Verify this...
*/
boot_mode = mrboots;
}
/* Initialize core modules */
init_video(); /* VGA driver */
gdt_install(); /* Global descriptor table */
idt_install(); /* IDT */
isrs_install(); /* Interrupt service requests */
@ -129,29 +126,16 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
enable_fpu(); /* Enable the floating point unit */
syscalls_install(); /* Install the system calls */
memcpy((void *)0x0, (void*)0x1E00000, 0x500);
if (boot_mode == multiboot) {
if (mboot_ptr->flags & (1 << 3)) {
/*
* If we have an initial ramdisk, mount it.
*/
if (mboot_ptr->mods_count > 0) {
initrd_mount((uintptr_t)ramdisk, 0);
}
}
if (ramdisk) {
initrd_mount((uintptr_t)ramdisk, 0);
}
mouse_install(); /* Mouse driver */
if (boot_mode == multiboot) {
/* Parse the command-line arguments */
parse_args((char *)mboot_ptr->cmdline);
if (cmdline) {
parse_args(cmdline);
}
kprintf("\033[2J");
start_shell();
return 0;

View File

@ -656,6 +656,7 @@ start_shell() {
init_shell();
install_commands();
add_path_contents();
kprintf("\033[2J");
while (1) {
/* Read buffer */
shell_update_time();

View File

@ -8,6 +8,8 @@
#include <types.h>
#include <vesa.h>
#define PROMPT_FOR_MODE 0
/* Friggin' frick, this should be a config option
* because it's 4096 on some instances of Qemu,
* ie the one on my laptop, but it's 2048 on
@ -242,7 +244,7 @@ graphics_install_vesa(uint16_t x, uint16_t y) {
for (int i = RME_BLOCK_SIZE; i < 0x100000; i += RME_BLOCK_SIZE) {
emu->Memory[i/RME_BLOCK_SIZE] = (void*)i;
}
int ret;
int ret, mode;
/* Find modes */
uint16_t * modes;
@ -252,11 +254,12 @@ graphics_install_vesa(uint16_t x, uint16_t y) {
emu->DI.W = 0;
ret = RME_CallInt(emu, 0x10);
if (info->Version < 0x200 || info->Version > 0x300) {
kprintf("You have attempted to use the VESA/VBE2 driver\nwith a card that does not support VBE2.\n");
kprintf("System boot has been halted.\nPlease check your kernel command line options.\n");
kprintf("\033[JYou have attempted to use the VESA/VBE2 driver\nwith a card that does not support VBE2.\n");
kprintf("\nSystem responded to VBE request with version: 0x%x\n", info->Version);
STOP;
}
modes = (void*)FP_TO_LINEAR(info->Videomodes.Segment,info->Videomodes.Offset); //(void*)((info->Videomodes.Segment * 16) + info->Videomodes.Offset);
modes = (void*)FP_TO_LINEAR(info->Videomodes.Segment,info->Videomodes.Offset);
uint16_t best_x = 0;
uint16_t best_y = 0;
@ -269,6 +272,15 @@ graphics_install_vesa(uint16_t x, uint16_t y) {
emu->ES = 0x0900;
emu->DI.W = 0x0000;
RME_CallInt(emu, 0x10);
#if PROMPT_FOR_MODE
kprintf("%d = %dx%d:%d\n", i, modeinfo->Xres, modeinfo->Yres, modeinfo->bpp);
}
kprintf("Please select a mode: ");
char buf[10];
kgets(buf, 10);
mode = atoi(buf);
#else
if ((abs(modeinfo->Xres - x) < abs(best_x - x)) && (abs(modeinfo->Yres - y) < abs(best_y - y))) {
best_mode = i;
best_x = modeinfo->Xres;
@ -289,24 +301,23 @@ graphics_install_vesa(uint16_t x, uint16_t y) {
}
}
}
#if 0
kprintf("%d = %dx%d:%d\n", i, modeinfo->Xres, modeinfo->Yres, modeinfo->bpp);
kprintf("Please select a mode: ");
char buf[10];
kgets(buf, 10);
int mode = atoi(buf);
#endif
if (best_b < 24) {
kprintf("!!! Rendering at this bit depth (%d) is not currently supported.\n", best_b);
STOP;
}
int mode = best_mode;
mode = best_mode;
#endif
emu->AX.W = 0x4F01;
emu->CX.W = modes[mode];
if (mode < 100) {
emu->CX.W = modes[mode];
} else {
emu->CX.W = mode;
}
emu->ES = 0x0900;
emu->DI.W = 0x0000;
RME_CallInt(emu, 0x10);