2002-07-09 16:24:59 +04:00
|
|
|
/* This is main - initializes processors and starts init */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
** Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2002-07-18 18:19:53 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <stage2.h>
|
|
|
|
#include <Errors.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <faults.h>
|
|
|
|
#include <arch/int.h>
|
|
|
|
#include <vm.h>
|
|
|
|
#include <timer.h>
|
|
|
|
#include <smp.h>
|
|
|
|
#include <OS.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>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <arch/cpu.h>
|
|
|
|
#include <arch/faults.h>
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
#define TRACE_BOOT 1
|
|
|
|
#if TRACE_BOOT
|
|
|
|
# define TRACE(x) dprintf x
|
|
|
|
#else
|
|
|
|
# define TRACE(x) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
static kernel_args ka;
|
|
|
|
|
|
|
|
static int main2(void *);
|
|
|
|
|
|
|
|
int _start(kernel_args *oldka, int cpu); /* keep compiler happy */
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
_start(kernel_args *oldka, int cpu_num)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
memcpy(&ka, oldka, sizeof(kernel_args));
|
|
|
|
|
|
|
|
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
|
|
|
|
dbg_init(&ka);
|
|
|
|
dbg_set_serial_debug(true);
|
|
|
|
dprintf("Welcome to kernel debugger output!\n");
|
|
|
|
|
|
|
|
// init modules
|
|
|
|
cpu_init(&ka);
|
|
|
|
int_init(&ka);
|
|
|
|
|
|
|
|
vm_init(&ka);
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("vm up\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// now we can use the heap and create areas
|
|
|
|
dbg_init2(&ka);
|
|
|
|
int_init2(&ka);
|
|
|
|
|
|
|
|
faults_init(&ka);
|
|
|
|
smp_init(&ka);
|
|
|
|
timer_init(&ka);
|
|
|
|
|
|
|
|
arch_cpu_init2(&ka);
|
|
|
|
|
|
|
|
sem_init(&ka);
|
|
|
|
|
|
|
|
// now we can create and use semaphores
|
|
|
|
vm_init_postsem(&ka);
|
|
|
|
cbuf_init();
|
|
|
|
vfs_init(&ka);
|
2002-08-04 03:39:50 +04:00
|
|
|
team_init(&ka);
|
2002-07-09 16:24:59 +04:00
|
|
|
thread_init(&ka);
|
|
|
|
port_init(&ka);
|
|
|
|
|
|
|
|
vm_init_postthread(&ka);
|
|
|
|
elf_init(&ka);
|
|
|
|
|
|
|
|
// start a thread to finish initializing the rest of the system
|
|
|
|
{
|
|
|
|
thread_id tid;
|
|
|
|
tid = thread_create_kernel_thread("main2", &main2, NULL);
|
|
|
|
thread_resume_thread(tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
thread_init_percpu(cpu_num);
|
|
|
|
}
|
2002-07-25 05:05:51 +04:00
|
|
|
enable_interrupts();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("main: done... begin idle loop on cpu %d\n", cpu_num));
|
2002-07-18 18:19:53 +04:00
|
|
|
for(;;)
|
|
|
|
arch_cpu_idle();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
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
|
|
|
|
2002-07-13 04:55:02 +04:00
|
|
|
/* bootstrap all the filesystems */
|
2002-10-08 07:06:55 +04:00
|
|
|
TRACE(("Bootstrap all filesystems\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
vfs_bootstrap_all_filesystems();
|
|
|
|
|
2002-10-08 05:14:44 +04:00
|
|
|
TRACE(("Init modules\n"));
|
2002-07-09 16:24:59 +04:00
|
|
|
module_init(&ka, NULL);
|
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);
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2002-08-03 04:41:27 +04:00
|
|
|
team_id pid;
|
|
|
|
pid = team_create_team("/boot/bin/init", "init", NULL, 0, NULL, 0, 5);
|
2002-10-08 05:14:44 +04:00
|
|
|
|
|
|
|
TRACE(("Init started\n"));
|
2002-09-23 06:41:52 +04:00
|
|
|
if (pid < 0)
|
|
|
|
kprintf("error starting 'init' error = %ld \n", pid);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|