2002-07-09 16:24:59 +04:00
|
|
|
/*
|
2004-10-20 03:21:07 +04:00
|
|
|
** Copyright 2002-2004, The Haiku Team. All rights reserved.
|
|
|
|
** Distributed under the terms of the Haiku License.
|
2004-03-15 01:54:00 +03:00
|
|
|
**
|
2002-07-09 16:24:59 +04:00
|
|
|
** 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-03-16 05:53:41 +03:00
|
|
|
#include <OS.h>
|
|
|
|
|
2003-10-08 03:12:37 +04:00
|
|
|
#include <boot/kernel_args.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <console.h>
|
|
|
|
#include <debug.h>
|
2003-05-03 20:20:38 +04:00
|
|
|
#include <arch/faults.h>
|
2004-10-27 03:31:48 +04:00
|
|
|
#include <arch/dbg_console.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <vm.h>
|
|
|
|
#include <timer.h>
|
|
|
|
#include <smp.h>
|
|
|
|
#include <sem.h>
|
|
|
|
#include <port.h>
|
|
|
|
#include <vfs.h>
|
|
|
|
#include <dev.h>
|
|
|
|
#include <cbuf.h>
|
|
|
|
#include <elf.h>
|
|
|
|
#include <cpu.h>
|
|
|
|
#include <devs.h>
|
|
|
|
#include <bus.h>
|
2002-09-23 06:41:52 +04:00
|
|
|
#include <kmodule.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <int.h>
|
2004-03-16 05:53:41 +03:00
|
|
|
#include <team.h>
|
2004-05-10 17:28:21 +04:00
|
|
|
#include <kdevice_manager.h>
|
2003-10-24 14:21:10 +04:00
|
|
|
#include <real_time_clock.h>
|
2003-01-26 20:31:33 +03:00
|
|
|
#include <kernel_daemon.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
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
static kernel_args ka;
|
|
|
|
|
2003-01-27 06:02:24 +03:00
|
|
|
static int32 main2(void *);
|
2002-07-09 16:24:59 +04:00
|
|
|
int _start(kernel_args *oldka, 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
|
|
|
|
_start(kernel_args *oldka, int cpu_num)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2004-10-27 18:00:40 +04:00
|
|
|
thread_id thread = -1;
|
|
|
|
|
2002-11-28 05:25:04 +03:00
|
|
|
kernel_startup = true;
|
|
|
|
|
2004-06-15 20:57:13 +04:00
|
|
|
if (oldka->kernel_args_size != sizeof(kernel_args)
|
2004-10-27 03:31:48 +04:00
|
|
|
|| oldka->version != CURRENT_KERNEL_ARGS_VERSION) {
|
|
|
|
// This is something we cannot handle right now - release kernels
|
|
|
|
// should always be able to handle the kernel_args of earlier
|
|
|
|
// released kernels.
|
|
|
|
arch_dbg_con_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
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
memcpy(&ka, oldka, 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
|
|
|
|
|
|
|
smp_set_num_cpus(ka.num_cpus);
|
|
|
|
|
|
|
|
// do any pre-booting cpu config
|
|
|
|
cpu_preboot_init(&ka);
|
|
|
|
|
|
|
|
// if we're not a boot cpu, spin here until someone wakes us up
|
2002-07-18 18:19:53 +04:00
|
|
|
if (smp_trap_non_boot_cpus(&ka, cpu_num) == B_NO_ERROR) {
|
2002-07-09 16:24:59 +04:00
|
|
|
// we're the boot processor, so wait for all of the APs to enter the kernel
|
|
|
|
smp_wait_for_ap_cpus(&ka);
|
|
|
|
|
|
|
|
// setup debug output
|
2004-10-21 05:45:43 +04:00
|
|
|
debug_init(&ka);
|
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");
|
|
|
|
|
|
|
|
// init modules
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init CPU\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
cpu_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init interrupts\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
int_init(&ka);
|
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
vm_init(&ka);
|
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
|
2004-10-21 05:45:43 +04:00
|
|
|
debug_init_post_vm(&ka);
|
|
|
|
int_init_post_vm(&ka);
|
|
|
|
cpu_init_post_vm(&ka);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init faults\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
faults_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init SMP\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
smp_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init timer\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
timer_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init real time clock\n"));
|
|
|
|
rtc_init(&ka);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init semaphores\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
sem_init(&ka);
|
|
|
|
|
|
|
|
// now we can create and use semaphores
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM semaphores\n"));
|
2004-10-20 03:21:07 +04:00
|
|
|
vm_init_post_sem(&ka);
|
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 VFS\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
vfs_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init teams\n"));
|
2002-08-04 03:39:50 +04:00
|
|
|
team_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init threads\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
thread_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init ports\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
port_init(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init kernel daemons\n"));
|
2003-01-26 20:31:33 +03:00
|
|
|
kernel_daemon_init();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init VM threads\n"));
|
2004-10-20 03:21:07 +04:00
|
|
|
vm_init_post_thread(&ka);
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("init ELF loader\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
elf_init(&ka);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
smp_wake_up_all_non_boot_cpus();
|
|
|
|
smp_enable_ici(); // ici's were previously being ignored
|
2002-08-04 03:39:50 +04:00
|
|
|
start_scheduler();
|
2002-07-09 16:24:59 +04:00
|
|
|
} else {
|
|
|
|
// this is run per cpu for each AP processor after they've been set loose
|
2004-03-15 01:54:00 +03:00
|
|
|
smp_per_cpu_init(&ka, cpu_num);
|
2004-03-17 18:28:08 +03:00
|
|
|
thread_per_cpu_init(cpu_num);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2004-03-15 01:54:00 +03:00
|
|
|
|
2004-11-08 17:37:07 +03:00
|
|
|
TRACE(("enable interrupts, exit kernel startup\n"));
|
2002-11-28 05:25:04 +03:00
|
|
|
kernel_startup = false;
|
2002-07-25 05:05:51 +04:00
|
|
|
enable_interrupts();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2004-10-27 18:00:40 +04:00
|
|
|
if (thread >= B_OK)
|
|
|
|
resume_thread(thread);
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("main: done... begin idle loop on cpu %d\n", cpu_num));
|
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"));
|
|
|
|
module_init(&ka);
|
|
|
|
|
2004-10-23 17:53:13 +04:00
|
|
|
vm_free_kernel_args(&ka);
|
|
|
|
// 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).
|
|
|
|
|
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"));
|
|
|
|
device_manager_init(&ka);
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
TRACE(("Mount boot file system\n"));
|
|
|
|
vfs_mount_boot_file_system();
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("Init busses\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
bus_init(&ka);
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
TRACE(("Init devices\n"));
|
2002-07-13 04:55:02 +04:00
|
|
|
dev_init(&ka);
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
TRACE(("Init console\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
con_init(&ka);
|
2002-10-08 05:14:44 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
//net_init_postdev(&ka);
|
|
|
|
|
2002-12-03 20:54:09 +03:00
|
|
|
//module_test();
|
2002-07-09 16:24:59 +04:00
|
|
|
#if 0
|
|
|
|
// XXX remove
|
|
|
|
vfs_test();
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
// XXX remove
|
|
|
|
thread_test();
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
vm_test();
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
panic("debugger_test\n");
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
cbuf_test();
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
port_test();
|
|
|
|
#endif
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|