2011-01-29 01:45:27 +03:00
|
|
|
/*
|
2011-03-02 02:48:39 +03:00
|
|
|
* vim:tabstop=4
|
|
|
|
* vim:noexpandtab
|
2011-01-29 01:45:27 +03:00
|
|
|
* Copyright (c) 2011 Kevin Lange. All rights reserved.
|
|
|
|
*
|
2011-10-13 08:24:19 +04:00
|
|
|
* Dedicated to the memory of
|
|
|
|
* Dennis Ritchie
|
|
|
|
* 1941-2011
|
|
|
|
*
|
2011-01-29 01:45:27 +03:00
|
|
|
* Developed by: ToAruOS Kernel Development Team
|
|
|
|
* http://github.com/klange/osdev
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal with the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimers.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimers in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the names of the ToAruOS Kernel Development Team, Kevin Lange,
|
|
|
|
* nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this Software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* WITH THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
#include <system.h>
|
2011-02-20 04:27:46 +03:00
|
|
|
#include <boot.h>
|
2011-01-29 08:09:09 +03:00
|
|
|
#include <ext2.h>
|
2011-04-16 01:56:25 +04:00
|
|
|
#include <fs.h>
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-04-12 05:05:40 +04:00
|
|
|
extern uintptr_t heap_end;
|
|
|
|
|
2011-01-21 08:21:32 +03:00
|
|
|
/*
|
|
|
|
* kernel entry point
|
2011-01-29 01:45:27 +03:00
|
|
|
*
|
|
|
|
* This is the C entry point for the kernel.
|
|
|
|
* It is called by the assembly loader and is passed
|
|
|
|
* multiboot information, if available, from the bootloader.
|
|
|
|
*
|
|
|
|
* The kernel boot process does the following:
|
|
|
|
* - Align the dumb allocator's heap pointer
|
|
|
|
* - Initialize the x86 descriptor tables (global, interrupts)
|
|
|
|
* - Initialize the interrupt handlers (ISRS, IRQ)
|
|
|
|
* - Load up the VGA driver.
|
|
|
|
* - Initialize the hardware drivers (PIC, keyboard)
|
|
|
|
* - Set up paging
|
|
|
|
* - Initialize the kernel heap (klmalloc)
|
|
|
|
* [Further booting]
|
|
|
|
*
|
|
|
|
* After booting, the kernel will display its version and dump the
|
|
|
|
* multiboot data from the bootloader. It will then proceed to print
|
|
|
|
* out the contents of the initial ramdisk image.
|
2011-01-21 08:21:32 +03:00
|
|
|
*/
|
2011-04-07 01:50:37 +04:00
|
|
|
int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
2011-01-31 01:59:19 +03:00
|
|
|
{
|
2011-03-02 02:48:39 +03:00
|
|
|
initial_esp = esp;
|
2011-02-20 04:27:46 +03:00
|
|
|
enum BOOTMODE boot_mode = unknown; /* Boot Mode */
|
2011-02-08 08:51:11 +03:00
|
|
|
if (mboot_mag == MULTIBOOT_EAX_MAGIC) {
|
2011-03-05 03:18:14 +03:00
|
|
|
/*
|
|
|
|
* Multiboot (GRUB, native QEMU, PXE)
|
|
|
|
*/
|
2011-02-20 04:27:46 +03:00
|
|
|
boot_mode = multiboot;
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2011-04-07 02:06:07 +04:00
|
|
|
mboot_ptr = mboot;
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2011-03-05 03:18:14 +03:00
|
|
|
/*
|
|
|
|
* Realign memory to the end of the multiboot modules
|
|
|
|
*/
|
2011-04-07 01:50:37 +04:00
|
|
|
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);
|
|
|
|
|
2011-02-10 10:08:54 +03:00
|
|
|
if (mboot_ptr->flags & (1 << 3)) {
|
2011-04-07 01:50:37 +04:00
|
|
|
ramdisk = (char *)module_start;
|
2011-03-05 03:18:14 +03:00
|
|
|
/*
|
|
|
|
* Mboot modules are available.
|
|
|
|
*/
|
2011-02-09 23:32:49 +03:00
|
|
|
if (mboot_ptr->mods_count > 0) {
|
2011-03-05 03:18:14 +03:00
|
|
|
/*
|
|
|
|
* 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. */
|
2011-02-09 23:32:49 +03:00
|
|
|
}
|
2011-02-08 08:51:11 +03:00
|
|
|
}
|
2011-02-20 04:27:46 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This isn't a multiboot attempt. We were probably loaded by
|
|
|
|
* Mr. Boots, our dedicated boot loader. Verify this...
|
|
|
|
*/
|
|
|
|
boot_mode = mrboots;
|
2011-02-08 08:51:11 +03:00
|
|
|
}
|
2011-01-29 01:45:27 +03:00
|
|
|
|
|
|
|
/* Initialize core modules */
|
2011-04-07 01:50:37 +04:00
|
|
|
init_video(); /* VGA driver */
|
2011-01-31 01:59:19 +03:00
|
|
|
gdt_install(); /* Global descriptor table */
|
|
|
|
idt_install(); /* IDT */
|
|
|
|
isrs_install(); /* Interrupt service requests */
|
|
|
|
irq_install(); /* Hardware interrupt requests */
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2011-01-29 01:45:27 +03:00
|
|
|
|
2011-04-11 23:17:15 +04:00
|
|
|
/* Memory management */
|
|
|
|
paging_install(mboot_ptr->mem_upper); /* Paging */
|
|
|
|
heap_install(); /* Kernel heap */
|
|
|
|
|
2011-01-29 01:45:27 +03:00
|
|
|
/* Hardware drivers */
|
2011-03-05 03:18:14 +03:00
|
|
|
timer_install(); /* PIC driver */
|
|
|
|
keyboard_install(); /* Keyboard interrupt handler */
|
|
|
|
serial_install(); /* Serial console */
|
2011-10-29 09:33:45 +04:00
|
|
|
mouse_install(); /* Mouse driver */
|
2011-01-29 01:45:27 +03:00
|
|
|
|
2011-04-11 23:17:15 +04:00
|
|
|
tasking_install(); /* Multi-tasking */
|
|
|
|
enable_fpu(); /* Enable the floating point unit */
|
|
|
|
syscalls_install(); /* Install the system calls */
|
|
|
|
|
|
|
|
/* Initialize the standard VGA display */
|
2011-04-06 04:12:08 +04:00
|
|
|
ansi_init(&writech, 80, 25);
|
2011-01-22 08:57:08 +03:00
|
|
|
|
2011-02-20 04:27:46 +03:00
|
|
|
if (boot_mode == multiboot) {
|
2011-01-22 08:57:08 +03:00
|
|
|
|
2011-02-10 10:08:54 +03:00
|
|
|
if (mboot_ptr->flags & (1 << 3)) {
|
2011-03-05 03:18:14 +03:00
|
|
|
/*
|
|
|
|
* If we have an initial ramdisk, mount it.
|
|
|
|
*/
|
2011-02-09 23:32:49 +03:00
|
|
|
if (mboot_ptr->mods_count > 0) {
|
|
|
|
initrd_mount((uintptr_t)ramdisk, 0);
|
|
|
|
}
|
2011-02-08 08:51:11 +03:00
|
|
|
}
|
2011-03-26 21:30:08 +03:00
|
|
|
|
|
|
|
/* Parse the command-line arguments */
|
|
|
|
parse_args((char *)mboot_ptr->cmdline);
|
2011-02-08 08:51:11 +03:00
|
|
|
}
|
2011-03-25 08:09:23 +03:00
|
|
|
|
|
|
|
cls();
|
2011-02-07 23:30:17 +03:00
|
|
|
|
2011-04-09 02:53:52 +04:00
|
|
|
start_shell();
|
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|