main.c revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.31 */
#include <sys/sysmacros.h>
#include <sys/priocntl.h>
#include <sys/bootconf.h>
#include <sys/autoconf.h>
#include <vm/seg_kmem.h>
/* well known processes */
int audit_active;
int interrupts_unleashed; /* set when we do the first spl0() */
/*
* Process 0's lwp directory and lwpid hash table.
*/
/*
* Machine-independent initialization code
* Called from cold start routine as
* soon as a stack and segmentation
* have been established.
* Functions:
* clear and free user core
* turn on clock
* hand craft 0th process
* call all initialization routines
* fork - process 0 to schedule
* - process 1 execute bootstrap
* - process 2 to page out
* create system threads
*/
int cluster_bootflags = 0;
void
cluster_wrapper(void)
{
cluster();
panic("cluster() returned");
}
/*
* Start the initial user process.
* The program [initname] may be invoked with one argument
* containing the boot flags.
*
* It must be a 32-bit program.
*/
void
icode(void)
{
/*
* Allocate user address space and stack segment
*/
proc_init = p;
p->p_model = DATAMODEL_ILP32;
init_core();
halt("Could not start init");
lwp_rtt();
}
int
{
char *ucp;
int argc = 0;
/*
* Construct the exec arguments in userland. That is, make an array
* of pointers to the argument strings, just like for execv(). This
* is done backwards.
*/
ucp = p->p_usrstack;
}
if (useboothowto &&
if (boothowto & RB_RECONFIG)
if (boothowto & RB_VERBOSE)
}
/*
* Move out the arg pointers.
*/
for (i = 0; i < argc + 1; ++i)
if (error != 0) {
"Could not construct stack for init.\n");
return (EFAULT);
}
/*
* Point at the arguments.
*/
/*
* Normally we would just set lwp_argsaved and t_post_sys and
* let post_syscall reset lwp_ap for us. Unfortunately,
* exec_init isn't always called from a system call. Instead
* of making a mess of trap_cleanup, we just reset the args
* pointer here.
*/
switch (error) {
case 0:
return (0);
case ENOENT:
"exec(%s) failed (file not found).\n", initpath);
return (ENOENT);
case EAGAIN:
case EINTR:
++count;
if (count < 5) {
"exec(%s) failed with errno %d. Retrying...\n",
goto again;
}
}
return (error);
}
void
main(void)
{
int (**initptr)();
extern void sched();
extern void fsflush();
extern void thread_reaper();
extern int (*init_tbl[])();
extern int (*mp_init_tbl[])();
extern int swaploaded;
extern int netboot;
extern void vm_init(void);
extern void cbe_init(void);
extern void clock_init(void);
extern void physio_bufs_init(void);
extern void pm_cfb_setup_intr(void);
extern int pm_adjust_timestamps(dev_info_t *, void *);
extern void start_other_cpus(int);
extern void sysevent_evc_thrinit();
extern void lgrp_main_init(void);
extern void lgrp_main_mp_init(void);
/*
* In the horrible world of x86 in-lines, you can't get symbolic
* structure offsets a la genassym. This assertion is here so
* that the next poor slob who innocently changes the offset of
* cpu_thread doesn't waste as much time as I just did finding
* curcpup. You're welcome.
*/
/*
* Setup the first lgroup, and home t0
*/
lgrp_setup();
startup();
segkmem_gc();
callb_init();
callout_init(); /* callout table MUST be init'd before clock starts */
cbe_init();
clock_init();
/*
* May need to probe to determine latencies from CPU 0 after
* gethrtime() comes alive in cbe_init() and before enabling interrupts
*/
/*
* Call all system initialization functions.
*/
(**initptr)();
/*
* initialize vm related stuff.
*/
vm_init();
/*
* initialize buffer pool for raw I/O requests
*/
/*
* Drop the interrupt level and allow interrupts. At this point
* the DDI guarantees that interrupts are enabled.
*/
(void) spl0();
interrupts_unleashed = 1;
vfs_mountroot(); /* Mount the root file system */
errorq_init(); /* after vfs_mountroot() so DDI root is ready */
/* after vfs_mountroot() so hrestime is valid */
post_startup();
swaploaded = 1;
/*
* Initial C2 audit system
*/
#ifdef C2_AUDIT
audit_init(); /* C2 hook */
#endif
/*
* Plumb the protocol modules and drivers only if we are not
* networked booted, in this case we already did it in rootconf().
*/
if (netboot == 0)
(void) strplumb();
gethrestime(&u.u_start);
/*
* Perform setup functions that can only be done after root
* and swap have been set up.
*/
consconfig();
#endif
/*
* attach drivers with ddi-forceattach prop
* from attaching before the upper console stream is plumbed.
* It must be done early enough to load hotplug drivers (e.g.
* pcmcia nexus) so that devices enumerated via hotplug is
* available before I/O subsystem is fully initialized.
*/
/*
* Set the scan rate and other parameters of the paging subsystem.
*/
setupclock(0);
/*
* Create kmem cache for proc structures
*/
/*
* Initialize process 0's lwp directory and lwpid hash table.
*/
p->p_lwpdir_sz = 2;
p->p_tidhash = p0_tidhash;
p->p_tidhash_sz = 2;
lwp_hash_in(p, &p0_lep);
/*
* Initialize extended accounting.
*/
exacct_init();
/*
* Initialize threads of sysevent event channels
*/
/*
* main lgroup initialization
* This must be done after post_startup(), but before
* start_other_cpus()
*/
/*
* Perform MP initialization, if any.
*/
start_other_cpus(0);
/*
* Finish lgrp initialization after all CPUS are brought online.
*/
/*
* After mp_init(), number of cpus are known (this is
* true for the time being, when there are actually
* hot pluggable cpus then this scheme would not do).
* Any per cpu initialization is done here.
*/
kmem_mp_init();
(**initptr)();
/*
* This must be called after start_other_cpus
*/
/*
* Make init process; enter scheduling loop with system process.
*/
/* create init process */
panic("main: unable to fork init.");
/* create pageout daemon */
panic("main: unable to fork pageout()");
/* create fsflush daemon */
panic("main: unable to fork fsflush()");
/* create cluster process if we're a member of one */
if (cluster_bootflags & CLUSTER_BOOTED) {
panic("main: unable to fork cluster()");
}
/*
* Create system threads (threads are associated with p0)
*/
/* create thread_reaper daemon */
/* create module uninstall daemon */
/* BugID 1132273. If swapping over NFS need a bigger stack */
pid_setmin();
sched();
/* NOTREACHED */
}