X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/0b4e3aa066abc0728aacb4bbeb86f53f9737156e..a3d08fcd5120d2aa8303b6349ca8b14e3f284af3:/osfmk/kern/startup.c diff --git a/osfmk/kern/startup.c b/osfmk/kern/startup.c index b3a5b0094..c6668bd8c 100644 --- a/osfmk/kern/startup.c +++ b/osfmk/kern/startup.c @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,7 @@ #include #include #include +#include #include #ifdef __ppc__ @@ -102,9 +104,8 @@ extern void rtclock_reset(void); /* Forwards */ void cpu_launch_first_thread( - thread_t thread); + thread_t thread); void start_kernel_threads(void); -void swapin_thread(); /* * Running in virtual memory, on the interrupt stack. @@ -151,9 +152,7 @@ setup_main(void) */ ledger_init(); task_init(); - act_init(); thread_init(); - subsystem_init(); /* * Initialize the Event Trace Analysis Package. @@ -163,27 +162,16 @@ setup_main(void) /* * Create a kernel thread to start the other kernel - * threads. Thread_resume (from kernel_thread) calls - * thread_setrun, which may look at current thread; - * we must avoid this, since there is no current thread. + * threads. */ - startup_thread = kernel_thread_with_priority( - kernel_task, MAXPRI_KERNEL, - start_kernel_threads, TRUE, FALSE); - - /* - * Pretend it is already running, and resume it. - * Since it looks as if it is running, thread_resume - * will not try to put it on the run queues. - * - * We can do all of this without locking, because nothing - * else is running yet. - */ - startup_thread->state = TH_RUN; - (void) thread_resume(startup_thread->top_act); + startup_thread = kernel_thread_create(start_kernel_threads, MAXPRI_KERNEL); + /* * Start the thread. */ + startup_thread->state = TH_RUN; + pset_run_incr(startup_thread->processor_set); + cpu_launch_first_thread(startup_thread); /*NOTREACHED*/ panic("cpu_launch_first_thread returns!"); @@ -209,20 +197,24 @@ start_kernel_threads(void) thread_t thread; spl_t s; - thread = kernel_thread_with_priority( - kernel_task, MAXPRI_KERNEL, - idle_thread, TRUE, FALSE); + thread = kernel_thread_create(idle_thread, MAXPRI_KERNEL); + s = splsched(); thread_lock(thread); - thread_bind_locked(thread, processor); + thread->bound_processor = processor; processor->idle_thread = thread; thread->ref_count++; - thread->state |= TH_IDLE; - thread_go_locked(thread, THREAD_AWAKENED); + thread->sched_pri = thread->priority = IDLEPRI; + thread->state = (TH_RUN | TH_IDLE); thread_unlock(thread); splx(s); } + /* + * Initialize the thread reaper mechanism. + */ + thread_reaper_init(); + /* * Initialize the stack swapin mechanism. */ @@ -245,11 +237,6 @@ start_kernel_threads(void) mapping_adjust(); #endif - /* - * Initialize the thread reaper mechanism. - */ - thread_reaper(); - /* * Create the clock service. */ @@ -260,20 +247,25 @@ start_kernel_threads(void) */ device_service_create(); - shared_file_boot_time_init(); + shared_file_boot_time_init(ENV_DEFAULT_ROOT, machine_slot[cpu_number()].cpu_type); #ifdef IOKIT { PE_init_iokit(); } #endif + + (void) spllo(); /* Allow interruptions */ + + /* + * Fill in the comm area (mapped into every task address space.) + */ + commpage_populate(); /* * Start the user bootstrap. */ - (void) spllo(); /* Allow interruptions */ - #ifdef MACH_BSD { extern void bsd_init(void); @@ -281,6 +273,10 @@ start_kernel_threads(void) } #endif +#if __ppc__ + serial_keyboard_init(); /* Start serial keyboard if wanted */ +#endif + thread_bind(current_thread(), PROCESSOR_NULL); /* @@ -302,8 +298,8 @@ slave_main(void) if (thread == THREAD_NULL) { thread = machine_wake_thread; machine_wake_thread = THREAD_NULL; - thread_bind(thread, myprocessor); } + cpu_launch_first_thread(thread); /*NOTREACHED*/ panic("slave_main"); @@ -315,17 +311,8 @@ slave_main(void) void start_cpu_thread(void) { - processor_t processor; - - processor = cpu_to_processor(cpu_number()); - slave_machine_init(); - if (processor->processor_self == IP_NULL) { - ipc_processor_init(processor); - ipc_processor_enable(processor); - } - (void) thread_terminate(current_act()); } @@ -337,33 +324,28 @@ cpu_launch_first_thread( thread_t thread) { register int mycpu = cpu_number(); + processor_t processor = cpu_to_processor(mycpu); - /* initialize preemption disabled */ - cpu_data[mycpu].preemption_level = 1; - - cpu_up(mycpu); + clock_get_uptime(&processor->last_dispatch); start_timer(&kernel_timer[mycpu]); - clock_get_uptime(&cpu_to_processor(mycpu)->last_dispatch); - - if (thread == THREAD_NULL) { - thread = cpu_to_processor(mycpu)->idle_thread; - if (thread == THREAD_NULL) - panic("cpu_launch_first_thread"); - } + machine_thread_set_current(thread); + cpu_up(mycpu); rtclock_reset(); /* start realtime clock ticking */ PMAP_ACTIVATE_KERNEL(mycpu); - thread_machine_set_current(thread); thread_lock(thread); thread->state &= ~TH_UNINT; - _mk_sp_thread_begin(thread); + thread->last_processor = processor; + processor->active_thread = thread; + processor->current_pri = thread->sched_pri; + _mk_sp_thread_begin(thread, processor); thread_unlock(thread); timer_switch(&thread->system_timer); PMAP_ACTIVATE_USER(thread->top_act, mycpu); /* preemption enabled by load_context */ - load_context(thread); + machine_load_context(thread); /*NOTREACHED*/ }