2011-12-11 03:45:04 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
2012-03-11 01:03:59 +04:00
|
|
|
*
|
|
|
|
* The ToAruOS kernel is released under the terms of the
|
|
|
|
* University of Illinois / NCSA License.
|
2011-11-29 23:06:17 +04:00
|
|
|
*
|
2013-01-05 08:42:18 +04:00
|
|
|
* Copyright (c) 2011-2013 Kevin Lange. All rights reserved.
|
2011-01-29 01:45:27 +03:00
|
|
|
*
|
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-12-15 03:47:30 +04:00
|
|
|
#include <logging.h>
|
2012-01-25 10:19:52 +04:00
|
|
|
#include <process.h>
|
2012-02-06 00:16:59 +04:00
|
|
|
#include <shm.h>
|
2011-01-16 04:01:19 +03:00
|
|
|
|
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
|
|
|
*/
|
2012-01-29 22:46:34 +04:00
|
|
|
int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
2011-03-02 02:48:39 +03:00
|
|
|
initial_esp = esp;
|
2011-12-27 05:23:58 +04:00
|
|
|
uintptr_t ramdisk_top = 0;
|
2013-03-18 11:52:12 +04:00
|
|
|
extern char * cmdline;
|
|
|
|
|
2011-02-08 08:51:11 +03:00
|
|
|
if (mboot_mag == MULTIBOOT_EAX_MAGIC) {
|
2012-01-29 22:46:34 +04:00
|
|
|
/* Multiboot (GRUB, native QEMU, PXE) */
|
2012-12-08 06:33:07 +04:00
|
|
|
debug_print(NOTICE, "Relocating Multiboot structures...");
|
2011-04-07 02:06:07 +04:00
|
|
|
mboot_ptr = mboot;
|
2012-09-18 12:19:30 +04:00
|
|
|
char cmdline_[1024];
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2012-12-03 11:28:29 +04:00
|
|
|
if (mboot_ptr->vbe_mode_info) {
|
|
|
|
lfb_vid_memory = (uint8_t *)((vbe_info_t *)(mboot_ptr->vbe_mode_info))->physbase;
|
|
|
|
}
|
|
|
|
|
2012-09-18 12:19:30 +04:00
|
|
|
size_t len = strlen((char *)mboot_ptr->cmdline);
|
|
|
|
memmove(cmdline_, (char *)mboot_ptr->cmdline, len + 1);
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2011-12-26 04:18:41 +04:00
|
|
|
/* Relocate any available modules */
|
2011-02-10 10:08:54 +03:00
|
|
|
if (mboot_ptr->flags & (1 << 3)) {
|
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 */
|
2013-04-22 04:33:16 +04:00
|
|
|
ramdisk = (char *)0x30000000; //(char *)kmalloc(module_end - module_start);
|
2011-12-27 05:23:58 +04:00
|
|
|
ramdisk_top = (uintptr_t)ramdisk + (module_end - module_start);
|
2013-04-28 09:04:20 +04:00
|
|
|
debug_print(INFO, "Ramdisk top = 0x%x", ramdisk_top);
|
2012-09-18 11:06:32 +04:00
|
|
|
|
2011-12-26 04:18:41 +04:00
|
|
|
memmove(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
|
|
|
}
|
2012-09-18 11:06:32 +04:00
|
|
|
|
|
|
|
/* Relocate the command line */
|
|
|
|
cmdline = (char *)kmalloc(len + 1);
|
2012-09-18 12:19:30 +04:00
|
|
|
memcpy(cmdline, cmdline_, len + 1);
|
2011-02-08 08:51:11 +03:00
|
|
|
}
|
2011-01-29 01:45:27 +03:00
|
|
|
|
|
|
|
/* Initialize core modules */
|
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-04-11 23:17:15 +04:00
|
|
|
/* Memory management */
|
2011-12-16 09:00:43 +04:00
|
|
|
paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower); /* Paging */
|
2011-04-11 23:17:15 +04:00
|
|
|
heap_install(); /* Kernel heap */
|
|
|
|
|
2013-03-15 11:20:55 +04:00
|
|
|
vfs_install();
|
|
|
|
|
2011-01-29 01:45:27 +03:00
|
|
|
/* Hardware drivers */
|
2011-03-05 03:18:14 +03:00
|
|
|
timer_install(); /* PIC driver */
|
|
|
|
serial_install(); /* Serial console */
|
2011-01-29 01:45:27 +03:00
|
|
|
|
2011-04-11 23:17:15 +04:00
|
|
|
tasking_install(); /* Multi-tasking */
|
2013-04-16 10:23:56 +04:00
|
|
|
auto_fpu();
|
2011-04-11 23:17:15 +04:00
|
|
|
syscalls_install(); /* Install the system calls */
|
|
|
|
|
2012-02-06 00:16:59 +04:00
|
|
|
shm_install(); /* Install shared memory */
|
|
|
|
|
2012-01-25 10:19:52 +04:00
|
|
|
keyboard_install(); /* Keyboard interrupt handler */
|
2012-01-25 23:50:30 +04:00
|
|
|
mouse_install(); /* Mouse driver */
|
2012-12-01 07:32:38 +04:00
|
|
|
keyboard_reset_ps2();
|
2011-11-18 09:29:08 +04:00
|
|
|
|
2011-12-26 04:18:41 +04:00
|
|
|
if (cmdline) {
|
|
|
|
parse_args(cmdline);
|
2011-11-19 00:38:27 +04:00
|
|
|
}
|
2011-12-16 07:47:46 +04:00
|
|
|
|
2013-03-15 11:20:55 +04:00
|
|
|
serial_mount_devices();
|
|
|
|
vfs_mount("/dev/null", null_device_create());
|
2013-04-01 00:01:05 +04:00
|
|
|
vfs_mount("/dev/zero", zero_device_create());
|
2013-03-15 11:20:55 +04:00
|
|
|
vfs_mount("/dev/hello", hello_device_create());
|
2013-03-23 09:38:10 +04:00
|
|
|
vfs_mount("/dev/random", random_device_create());
|
2013-04-22 10:17:26 +04:00
|
|
|
vfs_mount("/tmp", tmpfs_create());
|
2013-03-15 11:20:55 +04:00
|
|
|
|
2013-03-18 11:52:12 +04:00
|
|
|
vfs_mount("/proc", procfs_create());
|
|
|
|
|
2013-03-15 11:20:55 +04:00
|
|
|
debug_print_vfs_tree();
|
|
|
|
|
2012-09-18 12:19:30 +04:00
|
|
|
if (ramdisk && !fs_root) {
|
2013-04-28 09:04:20 +04:00
|
|
|
debug_print(NOTICE, "---- ramdisk[0x%x:0x%x]\n", ramdisk, ramdisk_top);
|
|
|
|
for (uintptr_t i = (uintptr_t)ramdisk; i < (uintptr_t)ramdisk_top; i += 0x1000) {
|
2012-09-19 09:20:04 +04:00
|
|
|
dma_frame(get_page(i, 1, kernel_directory), 0, 1, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
ext2_ramdisk_mount((uintptr_t)ramdisk);
|
2012-09-18 12:19:30 +04:00
|
|
|
}
|
|
|
|
|
2012-09-18 09:58:49 +04:00
|
|
|
if (!fs_root) {
|
2012-12-05 08:09:06 +04:00
|
|
|
debug_print(CRITICAL, "There is no file system mounted.");
|
|
|
|
debug_print(CRITICAL, "You have done something wrong;");
|
|
|
|
debug_print(CRITICAL, "Did you forget to mount a hard disk?");
|
2012-09-18 09:58:49 +04:00
|
|
|
while (1) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 22:10:53 +04:00
|
|
|
/* Prepare to run /bin/init */
|
2012-01-25 10:19:52 +04:00
|
|
|
char * argv[] = {
|
2012-01-30 22:10:53 +04:00
|
|
|
"/bin/init",
|
2012-03-28 06:47:25 +04:00
|
|
|
boot_arg,
|
2012-09-02 13:24:25 +04:00
|
|
|
boot_arg_extra,
|
2012-01-25 10:19:52 +04:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int argc = 0;
|
|
|
|
while (argv[argc]) {
|
|
|
|
argc++;
|
|
|
|
}
|
2012-01-30 22:10:53 +04:00
|
|
|
system(argv[0], argc, argv); /* Run init */
|
2011-04-09 02:53:52 +04:00
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-11 03:45:04 +04:00
|
|
|
|