main.c revision 018afb24c783bb6053481a3b0f9fbe8e4c583c8e
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#include <sys/sysmacros.h>
#include <sys/priocntl.h>
#include <sys/bootconf.h>
#include <sys/ddi_timer.h>
#include <sys/autoconf.h>
#include <vm/seg_kmem.h>
#include <sys/bootprops.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");
}
/*
* Construct a stack for init containing the arguments to it, then
* pass control to exec_common.
*/
int
{
char *scratchargs;
int i, sarg;
int argc = 0;
int brand_action;
args = "";
/*
* We do a quick two state parse of the string to sort out how big
* argc should be.
*/
for (i = 0; i < strlen(scratchargs); i++) {
if (in_arg) {
argc++;
}
} else {
}
}
/*
* We pull off a bit of a hack here. We work our way through the
* args string, putting nulls at the ends of space delimited tokens
* (boot args don't support quoting at this time). Then we just
* copy the whole mess to userland in one go. In other words, we
* transform this: "init -s -r\0" into this on the stack:
*
* -0x00 \0
* -0x01 r
* -0x02 - <--------.
* -0x03 \0 |
* -0x04 s |
* -0x05 - <------. |
* -0x06 \0 | |
* -0x07 t | |
* -0x08 i | |
* -0x09 n | |
* -0x0a i <---. | |
* -0x10 NULL | | | (argv[3])
* -0x14 -----|--|-' (argv[2])
* -0x18 ------|--' (argv[1])
* -0x1c -------' (argv[0])
*
* Since we know the value of ucp at the beginning of this process,
* we can trivially compute the argv[] array which we also need to
* place in userland: argv[i] = ucp - sarg(i), where ucp is the
* stack ptr, and sarg is the string index of the start of the
* argument.
*/
argc = 0;
sarg = 0;
for (i = 0; i < alen; i++) {
scratchargs[i] = '\0';
}
sarg = i;
}
}
uap--; /* advance to be below the word we're in */
if (error != 0) {
"Could not construct stack for init.\n");
return (EFAULT);
}
exec_fnamep = argv[0];
/*
* Point at the arguments.
*/
/*
* If we are executing init from zsched, we may have inherited its
* parent process's signal mask. Clear it now so that we behave in
* the same way as when started from the global zone.
*/
/*
* 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);
}
/*
* This routine does all of the common setup for invoking init; global
* and non-global zones employ this routine for the functionality which is
* in common.
*
* This program (init, presumably) must be a 32-bit process.
*/
int
{
p->p_model = DATAMODEL_ILP32;
init_core();
}
/*
* Start the initial user process for the global zone; once running, if
* init should subsequently fail, it will be automatically be caught in the
* exit(2) path, and restarted by restart_init().
*/
static void
start_init(void)
{
if (start_init_common() != 0)
halt("unix: Could not start init");
lwp_rtt();
}
void
main(void)
{
int (**initptr)();
extern void sched();
extern void fsflush();
extern int (*init_tbl[])();
extern int (*mp_init_tbl[])();
extern int swaploaded;
extern int netboot;
extern ib_boot_prop_t *iscsiboot_prop;
extern void vm_init(void);
extern void cbe_init_pre(void);
extern void cbe_init(void);
extern void clock_tick_init_pre(void);
extern void clock_tick_init_post(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();
#if defined(__x86)
extern void fastboot_post_startup(void);
#endif
/*
* 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 root lgroup and leaf lgroup for CPU 0
*/
/*
* Once 'startup()' completes, the thread_reaper() daemon would be
* created(in thread_init()). After that, it is safe to create threads
* that could exit. These exited threads will get reaped.
*/
startup();
segkmem_gc();
callb_init();
cbe_init_pre(); /* x86 must initialize gethrtimef before timer_init */
timer_init(); /* timer must be initialized before cyclic starts */
cbe_init();
callout_init(); /* callout table MUST be init'd after cyclics */
clock_init();
/*
* On some platforms, clkinitf() changes the timing source that
* gethrtime_unscaled() uses to generate timestamps. cbe_init() calls
* clkinitf(), so re-initialize the microstate counters after the
* timesource has been chosen.
*/
/*
* May need to probe to determine latencies from CPU 0 after
* gethrtime() comes alive in cbe_init() and before enabling interrupts
* and copy and release any temporary memory allocated with BOP_ALLOC()
* before release_bootstrap() frees boot memory
*/
/*
* Call all system initialization functions.
*/
(**initptr)();
/*
* Load iSCSI boot properties
*/
ld_ib_prop();
/*
* 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;
/*
* Create kmem cache for proc structures
*/
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;
/*
* Initialize Solaris Audit Subsystem
*/
audit_init();
/*
* Plumb the protocol modules and drivers only if we are not
* networked booted, in this case we already did it in rootconf().
*/
(void) strplumb();
/*
* Perform setup functions that can only be done after root
* and swap have been set up.
*/
consconfig();
#ifndef __sparc
#endif
/*
* attach drivers with ddi-forceattach prop
* 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);
/*
* 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;
/*
* Initialize extended accounting.
*/
exacct_init();
/*
* Initialize threads of sysevent event channels
*/
/*
* This must be done after post_startup() but before
* start_other_cpus()
*/
/*
* Perform MP initialization, if any.
*/
start_other_cpus(0);
#ifdef __sparc
/*
* Release bootstrap here since PROM interfaces are
* used to start other CPUs above.
*/
#endif
/*
* 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)();
/*
* These must be called after start_other_cpus
*/
#if defined(__x86)
#endif
/*
* Make init process; enter scheduling loop with system process.
*
* Note that we manually assign the pids for these processes, for
* historical reasons. If more pre-assigned pids are needed,
* FAMOUS_PIDS will have to be updated.
*/
/* 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) {
NULL, 0)) {
panic("main: unable to fork cluster()");
}
}
/*
* Create system threads (threads are associated with p0)
*/
/* create module uninstall daemon */
/* BugID 1132273. If swapping over NFS need a bigger stack */
pid_setmin();
sched();
/* NOTREACHED */
}