2002-07-09 16:24:59 +04:00
|
|
|
/*
|
2006-01-28 21:11:20 +03:00
|
|
|
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
2004-12-14 18:49:20 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2002-07-18 18:19:53 +04:00
|
|
|
|
2004-10-20 03:21:07 +04:00
|
|
|
/* This is main - initializes processors and starts init */
|
|
|
|
|
2004-12-14 18:49:20 +03:00
|
|
|
|
2004-03-16 05:53:41 +03:00
|
|
|
#include <OS.h>
|
|
|
|
|
2006-01-03 19:26:39 +03:00
|
|
|
#include <arch/platform.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <boot_item.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <cbuf.h>
|
|
|
|
#include <cpu.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <debug.h>
|
|
|
|
#include <elf.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <int.h>
|
2004-05-10 17:28:21 +04:00
|
|
|
#include <kdevice_manager.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <kdriver_settings.h>
|
2003-01-26 20:31:33 +03:00
|
|
|
#include <kernel_daemon.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <kmodule.h>
|
|
|
|
#include <kscheduler.h>
|
|
|
|
#include <ksyscalls.h>
|
2005-01-25 17:48:34 +03:00
|
|
|
#include <messaging.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <port.h>
|
|
|
|
#include <real_time_clock.h>
|
|
|
|
#include <sem.h>
|
|
|
|
#include <smp.h>
|
|
|
|
#include <system_info.h>
|
|
|
|
#include <team.h>
|
|
|
|
#include <timer.h>
|
2005-03-25 21:29:12 +03:00
|
|
|
#include <user_debugger.h>
|
2005-10-25 20:59:12 +04:00
|
|
|
#include <vfs.h>
|
|
|
|
#include <vm.h>
|
|
|
|
#include <boot/kernel_args.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
//#define TRACE_BOOT
|
2004-03-15 01:54:00 +03:00
|
|
|
#ifdef TRACE_BOOT
|
2002-10-08 05:14:44 +04:00
|
|
|
# define TRACE(x) dprintf x
|
|
|
|
#else
|
|
|
|
# define TRACE(x) ;
|
|
|
|
#endif
|
|
|
|
|
2002-11-28 05:25:04 +03:00
|
|
|
bool kernel_startup;
|
2002-10-08 05:14:44 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
static kernel_args sKernelArgs;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-01-27 06:02:24 +03:00
|
|
|
static int32 main2(void *);
|
2005-10-25 20:59:12 +04:00
|
|
|
int _start(kernel_args *bootKernelArgs, int cpu); /* keep compiler happy */
|
2002-10-08 05:14:44 +04:00
|
|
|
|
2003-05-03 20:20:38 +04:00
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
int
|
2005-10-25 20:59:12 +04:00
|
|
|
_start(kernel_args *bootKernelArgs, int currentCPU)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2002-11-28 05:25:04 +03:00
|
|
|
kernel_startup = true;
|
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
if (bootKernelArgs->kernel_args_size != sizeof(kernel_args)
|
|
|
|
|| bootKernelArgs->version != CURRENT_KERNEL_ARGS_VERSION) {
|
2004-10-27 03:31:48 +04:00
|
|
|
// This is something we cannot handle right now - release kernels
|
|
|
|
// should always be able to handle the kernel_args of earlier
|
|
|
|
// released kernels.
|
2005-05-29 17:01:38 +04:00
|
|
|
debug_early_boot_message("Version mismatch between boot loader and kernel!\n");
|
2004-06-15 20:57:13 +04:00
|
|
|
return -1;
|
2004-10-27 03:31:48 +04:00
|
|
|
}
|
2004-06-15 20:57:13 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
memcpy(&sKernelArgs, bootKernelArgs, sizeof(kernel_args));
|
2004-04-21 05:25:23 +04:00
|
|
|
// the passed in kernel args are in a non-allocated range of memory
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
smp_set_num_cpus(sKernelArgs.num_cpus);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// do any pre-booting cpu config
|
2005-10-25 20:59:12 +04:00
|
|
|
cpu_preboot_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// if we're not a boot cpu, spin here until someone wakes us up
|
2005-10-25 20:59:12 +04:00
|
|
|
if (smp_trap_non_boot_cpus(currentCPU)) {
|
|
|
|
thread_id thread;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-12-31 00:20:07 +03:00
|
|
|
// init platform
|
2006-01-03 19:26:39 +03:00
|
|
|
arch_platform_init(&sKernelArgs);
|
2005-12-31 00:20:07 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// setup debug output
|
2005-10-25 20:59:12 +04:00
|
|
|
debug_init(&sKernelArgs);
|
2003-11-11 06:07:53 +03:00
|
|
|
set_dprintf_enabled(true);
|
2002-07-09 16:24:59 +04:00
|
|
|
dprintf("Welcome to kernel debugger output!\n");
|
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
// we're the boot processor, so wait for all of the APs to enter the kernel
|
|
|
|
smp_wait_for_non_boot_cpus();
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// init modules
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init CPU\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
cpu_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init interrupts\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
int_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
vm_init(&sKernelArgs);
|
2004-10-21 05:45:43 +04:00
|
|
|
// Before vm_init_post_sem() is called, we have to make sure that
|
|
|
|
// the boot loader allocated region is not used anymore
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// now we can use the heap and create areas
|
2006-01-03 19:26:39 +03:00
|
|
|
arch_platform_init_post_vm(&sKernelArgs);
|
2005-01-10 10:47:51 +03:00
|
|
|
TRACE(("init driver_settings\n"));
|
2005-06-13 17:01:13 +04:00
|
|
|
boot_item_init();
|
2005-10-25 20:59:12 +04:00
|
|
|
driver_settings_init(&sKernelArgs);
|
|
|
|
debug_init_post_vm(&sKernelArgs);
|
|
|
|
int_init_post_vm(&sKernelArgs);
|
|
|
|
cpu_init_post_vm(&sKernelArgs);
|
2005-01-10 10:47:51 +03:00
|
|
|
TRACE(("init system info\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
system_info_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init SMP\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
smp_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init timer\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
timer_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init real time clock\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
rtc_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init semaphores\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
sem_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// now we can create and use semaphores
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM semaphores\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
vm_init_post_sem(&sKernelArgs);
|
2005-01-10 10:47:51 +03:00
|
|
|
TRACE(("init driver_settings\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
driver_settings_init_post_sem(&sKernelArgs);
|
2004-12-14 18:49:20 +03:00
|
|
|
TRACE(("init generic syscall\n"));
|
|
|
|
generic_syscall_init();
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init cbuf\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
cbuf_init();
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init teams\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
team_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init threads\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
thread_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init ports\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
port_init(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init kernel daemons\n"));
|
2003-01-26 20:31:33 +03:00
|
|
|
kernel_daemon_init();
|
2006-01-28 21:11:20 +03:00
|
|
|
arch_platform_init_post_thread(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM threads\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
vm_init_post_thread(&sKernelArgs);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init ELF loader\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
elf_init(&sKernelArgs);
|
|
|
|
TRACE(("init scheduler\n"));
|
|
|
|
scheduler_init();
|
2005-12-16 19:11:36 +03:00
|
|
|
TRACE(("init VFS\n"));
|
|
|
|
vfs_init(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// start a thread to finish initializing the rest of the system
|
2004-10-27 18:00:40 +04:00
|
|
|
thread = spawn_kernel_thread(&main2, "main2", B_NORMAL_PRIORITY, NULL);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
smp_wake_up_non_boot_cpus();
|
2004-03-15 01:54:00 +03:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
TRACE(("enable interrupts, exit kernel startup\n"));
|
|
|
|
kernel_startup = false;
|
|
|
|
enable_interrupts();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
scheduler_start();
|
2004-10-27 18:00:40 +04:00
|
|
|
resume_thread(thread);
|
2005-10-25 20:59:12 +04:00
|
|
|
} else {
|
|
|
|
// this is run for each non boot processor after they've been set loose
|
|
|
|
smp_per_cpu_init(&sKernelArgs, currentCPU);
|
|
|
|
thread_per_cpu_init(currentCPU);
|
2004-10-27 18:00:40 +04:00
|
|
|
|
2005-10-25 20:59:12 +04:00
|
|
|
enable_interrupts();
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(("main: done... begin idle loop on cpu %d\n", currentCPU));
|
2004-03-15 01:54:00 +03:00
|
|
|
for (;;)
|
2002-07-18 18:19:53 +04:00
|
|
|
arch_cpu_idle();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
|
2003-01-27 06:02:24 +03:00
|
|
|
static int32
|
2002-10-08 05:14:44 +04:00
|
|
|
main2(void *unused)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
(void)(unused);
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("start of main2: initializing devices\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-06-07 21:32:16 +04:00
|
|
|
TRACE(("Init modules\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
module_init(&sKernelArgs);
|
2004-06-07 21:32:16 +04:00
|
|
|
|
2004-11-11 22:43:59 +03:00
|
|
|
// ToDo: the preloaded image debug data is placed in the kernel args, and
|
|
|
|
// thus, if they are enabled, the kernel args shouldn't be freed, so
|
|
|
|
// that we don't have to copy them.
|
|
|
|
// What is yet missing is a mechanism that controls this (via driver settings).
|
|
|
|
if (0) {
|
2004-10-23 17:53:13 +04:00
|
|
|
// module_init() is supposed to be the last user of the kernel args
|
|
|
|
// Note: don't confuse the kernel_args structure (which is never freed)
|
|
|
|
// with the kernel args ranges it contains (and which are freed here).
|
2005-10-25 20:59:12 +04:00
|
|
|
vm_free_kernel_args(&sKernelArgs);
|
2004-11-11 22:43:59 +03:00
|
|
|
}
|
2004-10-23 17:53:13 +04:00
|
|
|
|
2005-03-25 21:29:12 +03:00
|
|
|
// init userland debugging
|
|
|
|
TRACE(("Init Userland debugging\n"));
|
|
|
|
init_user_debug();
|
|
|
|
|
2005-01-25 17:48:34 +03:00
|
|
|
// init the messaging service
|
|
|
|
TRACE(("Init Messaging Service\n"));
|
|
|
|
init_messaging_service();
|
|
|
|
|
2002-07-13 04:55:02 +04:00
|
|
|
/* bootstrap all the filesystems */
|
2004-05-06 05:27:34 +04:00
|
|
|
TRACE(("Bootstrap file systems\n"));
|
|
|
|
vfs_bootstrap_file_systems();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-05-10 17:28:21 +04:00
|
|
|
TRACE(("Init Device Manager\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
device_manager_init(&sKernelArgs);
|
2004-05-10 17:28:21 +04:00
|
|
|
|
2004-05-06 05:27:34 +04:00
|
|
|
// ToDo: device manager starts here, bus_init()/dev_init() won't be necessary anymore,
|
|
|
|
// but instead, the hardware and drivers are rescanned then.
|
|
|
|
|
2006-02-07 05:50:32 +03:00
|
|
|
int_init_post_device_manager(&sKernelArgs);
|
|
|
|
|
2004-05-06 05:27:34 +04:00
|
|
|
TRACE(("Mount boot file system\n"));
|
2005-10-25 20:59:12 +04:00
|
|
|
vfs_mount_boot_file_system(&sKernelArgs);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
The short story: we now have MTRR support on Intel and AMD CPUs (the latter
has not yet been tested, though - I'll do this after this commit):
* Removed the arch_memory_type stuff from vm_area; since there are only 8 memory
ranges on x86, it's simply overkill. The MTRR code now remembers the area ID
and finds the MTRR that way (it could also iterate over the existing MTRRs).
* Introduced some post_modules() init functions.
* If the other x86 CPUs out there don't differ a lot, MTRR functionality might
be put back into the kernel.
* x86_write_msr() was broken, it wrote the 64 bit number with the 32 bit words
switched - it took me some time (and lots of #GPs) to figure that one out.
* Removed the macro read_ebp() and introduced a function x86_read_ebp()
(it's not really a time critical call).
* Followed the Intel docs on how to change MTRRs (symmetrically on all CPUs
with caches turned off).
* Asking for memory types will automatically change the requested length to
a power of two - note that BeOS seems to behave in the same, although that's
not really very clean.
* fixed MTRRs are ignored for now - we should make sure at least, though,
that they are identical on all CPUs (or turn them off, even though I'd
prefer the BIOS stuff to be uncacheable, which we don't enforce yet, though).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15528 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-12-13 19:34:29 +03:00
|
|
|
// CPU specific modules may now be available
|
|
|
|
cpu_init_post_modules(&sKernelArgs);
|
|
|
|
vm_init_post_modules(&sKernelArgs);
|
2005-12-13 03:06:52 +03:00
|
|
|
debug_init_post_modules(&sKernelArgs);
|
2006-11-29 22:09:45 +03:00
|
|
|
device_manager_init_post_modules(&sKernelArgs);
|
2005-12-13 03:06:52 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
// start the init process
|
|
|
|
{
|
2004-11-02 00:44:23 +03:00
|
|
|
const char *shellArgs[] = {"/bin/sh", "/boot/beos/system/boot/Bootscript", NULL};
|
|
|
|
const char *initArgs[] = {"/bin/init", NULL};
|
|
|
|
const char **args;
|
|
|
|
int32 argc;
|
|
|
|
thread_id thread;
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
if (stat(shellArgs[1], &st) == 0) {
|
|
|
|
// start Bootscript
|
|
|
|
args = shellArgs;
|
|
|
|
argc = 2;
|
|
|
|
} else {
|
|
|
|
// ToDo: this is only necessary as long as we have the bootdir mechanism
|
|
|
|
// start init
|
|
|
|
args = initArgs;
|
|
|
|
argc = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
thread = load_image(argc, args, NULL);
|
2004-10-14 22:18:22 +04:00
|
|
|
if (thread >= B_OK) {
|
|
|
|
resume_thread(thread);
|
2004-11-02 00:44:23 +03:00
|
|
|
TRACE(("Bootscript started\n"));
|
2004-10-14 22:18:22 +04:00
|
|
|
} else
|
2004-11-02 00:44:23 +03:00
|
|
|
dprintf("error starting \"%s\" error = %ld \n", args[0], thread);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|