⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/init/main.c * *  Copyright (C) 1991, 1992  Linus Torvalds * *  GK 2/5/95  -  Changed to support mounting root fs via NFS *  Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 *  Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 */#define __KERNEL_SYSCALLS__#include <stdarg.h>#include <asm/system.h>#include <asm/io.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/config.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/tty.h>#include <linux/head.h>#include <linux/unistd.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/fs.h>#include <linux/ctype.h>#include <linux/delay.h>#include <linux/utsname.h>#include <linux/ioport.h>#include <linux/hdreg.h>#include <linux/mm.h>#include <linux/major.h>#include <linux/blk.h>#ifdef CONFIG_ROOT_NFS#include <linux/nfs_fs.h>#endif#ifdef CONFIG_MTRR#include <asm/mtrr.h>#endif#include <asm/bugs.h>/* * Versions of gcc older than that listed below may actually compile * and link okay, but the end product can have subtle run time bugs. * To avoid associated bogus bug reports, we flatly refuse to compile * with a gcc that is known to be too old from the very beginning. */#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)#error sorry, your GCC is too old. It builds incorrect kernels.#endifextern char _stext, _etext;extern const char *linux_banner;static char printbuf[1024];extern int console_loglevel;static int init(void *);extern int bdflush(void *);extern int kswapd(void *);extern void kswapd_setup(void);extern void init_IRQ(void);extern void init_modules(void);extern long console_init(long, long);extern long kmalloc_init(long,long);extern void sock_init(void);extern unsigned long pci_init(unsigned long, unsigned long);extern void sysctl_init(void);extern void no_scroll(char *str, int *ints);extern void swap_setup(char *str, int *ints);extern void buff_setup(char *str, int *ints);extern void panic_setup(char *str, int *ints);extern void bmouse_setup(char *str, int *ints);extern void msmouse_setup(char *str, int *ints);extern void lp_setup(char *str, int *ints);extern void eth_setup(char *str, int *ints);extern void xd_setup(char *str, int *ints);extern void xd_manual_geo_init(char *str, int *ints);extern void floppy_setup(char *str, int *ints);extern void st_setup(char *str, int *ints);extern void st0x_setup(char *str, int *ints);extern void advansys_setup(char *str, int *ints);extern void tmc8xx_setup(char *str, int *ints);extern void t128_setup(char *str, int *ints);extern void pas16_setup(char *str, int *ints);extern void generic_NCR5380_setup(char *str, int *intr);extern void generic_NCR53C400_setup(char *str, int *intr);extern void aha152x_setup(char *str, int *ints);extern void aha1542_setup(char *str, int *ints);extern void gdth_setup(char *str, int *ints);extern void aic7xxx_setup(char *str, int *ints);extern void AM53C974_setup(char *str, int *ints);extern void BusLogic_Setup(char *str, int *ints);extern void ncr53c8xx_setup(char *str, int *ints);extern void eata2x_setup(char *str, int *ints);extern void u14_34f_setup(char *str, int *ints);extern void fdomain_setup(char *str, int *ints);extern void in2000_setup(char *str, int *ints);extern void NCR53c406a_setup(char *str, int *ints);extern void wd7000_setup(char *str, int *ints);extern void ppa_setup(char *str, int *ints);extern void scsi_luns_setup(char *str, int *ints);extern void sound_setup(char *str, int *ints);extern void apm_setup(char *str, int *ints);extern void reboot_setup(char *str, int *ints);#ifdef CONFIG_CDU31Aextern void cdu31a_setup(char *str, int *ints);#endif CONFIG_CDU31A#ifdef CONFIG_MCDextern void mcd_setup(char *str, int *ints);#endif CONFIG_MCD#ifdef CONFIG_MCDXextern void mcdx_setup(char *str, int *ints);#endif CONFIG_MCDX#ifdef CONFIG_SBPCDextern void sbpcd_setup(char *str, int *ints);#endif CONFIG_SBPCD#ifdef CONFIG_AZTCDextern void aztcd_setup(char *str, int *ints);#endif CONFIG_AZTCD#ifdef CONFIG_CDU535extern void sonycd535_setup(char *str, int *ints);#endif CONFIG_CDU535#ifdef CONFIG_GSCDextern void gscd_setup(char *str, int *ints);#endif CONFIG_GSCD#ifdef CONFIG_CM206extern void cm206_setup(char *str, int *ints);#endif CONFIG_CM206#ifdef CONFIG_OPTCDextern void optcd_setup(char *str, int *ints);#endif CONFIG_OPTCD#ifdef CONFIG_SJCDextern void sjcd_setup(char *str, int *ints);#endif CONFIG_SJCD#ifdef CONFIG_ISP16_CDIextern void isp16_setup(char *str, int *ints);#endif CONFIG_ISP16_CDI#ifdef CONFIG_BLK_DEV_RAMstatic void ramdisk_start_setup(char *str, int *ints);static void load_ramdisk(char *str, int *ints);static void prompt_ramdisk(char *str, int *ints);static void ramdisk_size(char *str, int *ints);#ifdef CONFIG_BLK_DEV_INITRDstatic void no_initrd(char *s,int *ints);#endif#endif CONFIG_BLK_DEV_RAM#ifdef CONFIG_ISDN_DRV_ICNextern void icn_setup(char *str, int *ints);#endif#ifdef CONFIG_ISDN_DRV_HISAXextern void HiSax_setup(char *str, int *ints);#endif#ifdef CONFIG_ISDN_DRV_PCBITextern void pcbit_setup(char *str, int *ints);#endif#ifdef CONFIG_ATARIMOUSEextern void atari_mouse_setup (char *str, int *ints);#endif#ifdef CONFIG_DMASOUNDextern void dmasound_setup (char *str, int *ints);#endif#ifdef CONFIG_ATARI_SCSIextern void atari_scsi_setup (char *str, int *ints);#endifextern void wd33c93_setup (char *str, int *ints);extern void gvp11_setup (char *str, int *ints);#ifdef CONFIG_CYCLADESextern void cy_setup(char *str, int *ints);#endif#ifdef CONFIG_DIGIextern void pcxx_setup(char *str, int *ints);#endif#ifdef CONFIG_RISCOM8extern void riscom8_setup(char *str, int *ints);#endif#ifdef CONFIG_SPECIALIXextern void specialix_setup(char *str, int *ints);#endif#ifdef CONFIG_BAYCOMextern void baycom_setup(char *str, int *ints);#endif#ifdef CONFIG_PARIDE_PDextern void pd_setup(char *str, int *ints);#endif#ifdef CONFIG_PARIDE_PFextern void pf_setup(char *str, int *ints);#endif#ifdef CONFIG_PARIDE_PTextern void pt_setup(char *str, int *ints);#endif#ifdef CONFIG_PARIDE_PGextern void pg_setup(char *str, int *ints);#endif#ifdef CONFIG_PARIDE_PCDextern void pcd_setup(char *str, int *ints);#endif#if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)extern void ipc_init(void);#endif/* * Boot command-line arguments */#define MAX_INIT_ARGS 8#define MAX_INIT_ENVS 8extern void time_init(void);static unsigned long memory_start = 0;static unsigned long memory_end = 0;int rows, cols;#ifdef CONFIG_BLK_DEV_RAMextern int rd_doload;		/* 1 = load ramdisk, 0 = don't load */extern int rd_prompt;		/* 1 = prompt for ramdisk, 0 = don't prompt */extern int rd_size;		/* Size of the ramdisk(s) */extern int rd_image_start;	/* starting block # of image */#ifdef CONFIG_BLK_DEV_INITRDkdev_t real_root_dev;#endif#endifint root_mountflags = MS_RDONLY;char *execute_command = 0;#ifdef CONFIG_ROOT_NFSchar nfs_root_name[NFS_ROOT_NAME_LEN] = { "default" };char nfs_root_addrs[NFS_ROOT_ADDRS_LEN] = { "" };#endifextern void dquot_init(void);static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };static char * argv_rc[] = { "/bin/sh", NULL };static char * envp_rc[] = { "HOME=/", "TERM=linux", NULL };static char * argv[] = { "-/bin/sh",NULL };static char * envp[] = { "HOME=/usr/root", "TERM=linux", NULL };char *get_options(char *str, int *ints){	char *cur = str;	int i=1;	while (cur && isdigit(*cur) && i <= 10) {		ints[i++] = simple_strtoul(cur,NULL,0);		if ((cur = strchr(cur,',')) != NULL)			cur++;	}	ints[0] = i-1;	return(cur);}static void profile_setup(char *str, int *ints){	if (ints[0] > 0)		prof_shift = (unsigned long) ints[1];	else#ifdef CONFIG_PROFILE_SHIFT		prof_shift = CONFIG_PROFILE_SHIFT;#else		prof_shift = 2;#endif}struct kernel_param {	const char *str;	void (*setup_func)(char *, int *);} ;struct kernel_param bootsetups[] = {	{ "reserve=", reserve_setup },	{ "profile=", profile_setup },#ifdef CONFIG_BLK_DEV_RAM	{ "ramdisk_start=", ramdisk_start_setup },	{ "load_ramdisk=", load_ramdisk },	{ "prompt_ramdisk=", prompt_ramdisk },	{ "ramdisk=", ramdisk_size },	{ "ramdisk_size=", ramdisk_size },#ifdef CONFIG_BLK_DEV_INITRD	{ "noinitrd", no_initrd },#endif#endif	{ "swap=", swap_setup },	{ "buff=", buff_setup },	{ "panic=", panic_setup },	{ "no-scroll", no_scroll },#ifdef CONFIG_BUGi386	{ "no-hlt", no_halt },	{ "no387", no_387 },	{ "reboot=", reboot_setup },#endif#ifdef CONFIG_INET	{ "ether=", eth_setup },#endif#ifdef CONFIG_PRINTER        { "lp=", lp_setup },#endif#ifdef CONFIG_SCSI	{ "max_scsi_luns=", scsi_luns_setup },#endif#ifdef CONFIG_SCSI_ADVANSYS	{ "advansys=", advansys_setup },#endif#if defined(CONFIG_BLK_DEV_HD)	{ "hd=", hd_setup },#endif#ifdef CONFIG_CHR_DEV_ST	{ "st=", st_setup },#endif#ifdef CONFIG_BUSMOUSE	{ "bmouse=", bmouse_setup },#endif#ifdef CONFIG_MS_BUSMOUSE	{ "msmouse=", msmouse_setup },#endif#ifdef CONFIG_SCSI_SEAGATE	{ "st0x=", st0x_setup },	{ "tmc8xx=", tmc8xx_setup },#endif#ifdef CONFIG_SCSI_T128	{ "t128=", t128_setup },#endif#ifdef CONFIG_SCSI_PAS16	{ "pas16=", pas16_setup },#endif#ifdef CONFIG_SCSI_GENERIC_NCR5380	{ "ncr5380=", generic_NCR5380_setup },	{ "ncr53c400=", generic_NCR53C400_setup },#endif#ifdef CONFIG_SCSI_AHA152X	{ "aha152x=", aha152x_setup},#endif#ifdef CONFIG_SCSI_AHA1542	{ "aha1542=", aha1542_setup},#endif#ifdef CONFIG_SCSI_GDTH	{ "gdth=", gdth_setup},#endif#ifdef CONFIG_SCSI_AIC7XXX	{ "aic7xxx=", aic7xxx_setup},#endif#ifdef CONFIG_SCSI_BUSLOGIC	{ "BusLogic=", BusLogic_Setup},#endif#ifdef CONFIG_SCSI_NCR53C8XX	{ "ncr53c8xx=", ncr53c8xx_setup},#endif#ifdef CONFIG_SCSI_EATA	{ "eata=", eata2x_setup},#endif#ifdef CONFIG_SCSI_U14_34F	{ "u14-34f=", u14_34f_setup},#endif#ifdef CONFIG_SCSI_AM53C974        { "AM53C974=", AM53C974_setup},#endif#ifdef CONFIG_SCSI_NCR53C406A	{ "ncr53c406a=", NCR53c406a_setup},#endif#ifdef CONFIG_SCSI_FUTURE_DOMAIN	{ "fdomain=", fdomain_setup},#endif#ifdef CONFIG_SCSI_IN2000	{ "in2000=", in2000_setup},#endif#ifdef CONFIG_SCSI_7000FASST	{ "wd7000=", wd7000_setup},#endif#ifdef CONFIG_SCSI_PPA        { "ppa=", ppa_setup },#endif#ifdef CONFIG_BLK_DEV_XD	{ "xd=", xd_setup },	{ "xd_geo=", xd_manual_geo_init },#endif#ifdef CONFIG_BLK_DEV_FD	{ "floppy=", floppy_setup },#endif#ifdef CONFIG_CDU31A	{ "cdu31a=", cdu31a_setup },#endif CONFIG_CDU31A#ifdef CONFIG_MCD	{ "mcd=", mcd_setup },#endif CONFIG_MCD#ifdef CONFIG_MCDX	{ "mcdx=", mcdx_setup },#endif CONFIG_MCDX#ifdef CONFIG_SBPCD	{ "sbpcd=", sbpcd_setup },#endif CONFIG_SBPCD#ifdef CONFIG_AZTCD	{ "aztcd=", aztcd_setup },#endif CONFIG_AZTCD#ifdef CONFIG_CDU535	{ "sonycd535=", sonycd535_setup },#endif CONFIG_CDU535#ifdef CONFIG_GSCD	{ "gscd=", gscd_setup },#endif CONFIG_GSCD#ifdef CONFIG_CM206	{ "cm206=", cm206_setup },#endif CONFIG_CM206#ifdef CONFIG_OPTCD	{ "optcd=", optcd_setup },#endif CONFIG_OPTCD#ifdef CONFIG_SJCD	{ "sjcd=", sjcd_setup },#endif CONFIG_SJCD#ifdef CONFIG_ISP16_CDI	{ "isp16=", isp16_setup },#endif CONFIG_ISP16_CDI#ifdef CONFIG_SOUND	{ "sound=", sound_setup },#endif#ifdef CONFIG_ISDN_DRV_ICN	{ "icn=", icn_setup },#endif#ifdef CONFIG_ISDN_DRV_HISAX       { "hisax=", HiSax_setup },       { "HiSax=", HiSax_setup },#endif#ifdef CONFIG_ISDN_DRV_PCBIT	{ "pcbit=", pcbit_setup },#endif#ifdef CONFIG_ATARIMOUSE	{ "atamouse=", atari_mouse_setup },#endif#ifdef CONFIG_DMASOUND	{ "dmasound=", dmasound_setup },#endif#ifdef CONFIG_ATARI_SCSI	{ "atascsi=", atari_scsi_setup },#endif#if defined(CONFIG_A3000_SCSI) || defined(CONFIG_A2091_SCSI) \	    || defined(CONFIG_GVP11_SCSI)	{ "wd33c93=", wd33c93_setup },#endif#if defined(CONFIG_GVP11_SCSI)	{ "gvp11=", gvp11_setup },#endif#ifdef CONFIG_CYCLADES	{ "cyclades=", cy_setup },#endif#ifdef CONFIG_DIGI	{ "digi=", pcxx_setup },#endif#ifdef CONFIG_RISCOM8	{ "riscom8=", riscom8_setup },#endif#ifdef CONFIG_SPECIALIX	{ "specialix=", specialix_setup },#endif#ifdef CONFIG_BAYCOM	{ "baycom=", baycom_setup },#endif#ifdef CONFIG_APM	{ "apm=", apm_setup },#endif	{ 0, 0 }};static struct kernel_param raw_params[] = {#ifdef CONFIG_PARIDE_PD       { "pd.", pd_setup },#endif#ifdef CONFIG_PARIDE_PCD       { "pcd.", pcd_setup },#endif#ifdef CONFIG_PARIDE_PF       { "pf.", pf_setup },#endif#ifdef CONFIG_PARIDE_PT       { "pt.", pt_setup },#endif#ifdef CONFIG_PARIDE_PG       { "pg.", pg_setup },#endif       { 0, 0 }} ;#ifdef CONFIG_BLK_DEV_RAMstatic void ramdisk_start_setup(char *str, int *ints){   if (ints[0] > 0 && ints[1] >= 0)      rd_image_start = ints[1];}static void load_ramdisk(char *str, int *ints){   if (ints[0] > 0 && ints[1] >= 0)      rd_doload = ints[1] & 3;}static void prompt_ramdisk(char *str, int *ints){   if (ints[0] > 0 && ints[1] >= 0)      rd_prompt = ints[1] & 1;}static void ramdisk_size(char *str, int *ints){	if (ints[0] > 0 && ints[1] >= 0)		rd_size = ints[1];}#endifstatic int checksetup(char *line){	int i = 0;	int ints[11];#ifdef CONFIG_BLK_DEV_IDE	/* ide driver needs the basic string, rather than pre-processed values */	if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {		ide_setup(line);		return 1;	}#endif	while (bootsetups[i].str) {		int n = strlen(bootsetups[i].str);		if (!strncmp(line,bootsetups[i].str,n)) {			bootsetups[i].setup_func(get_options(line+n,ints), ints);			return 1;		}		i++;	}        for (i=0; raw_params[i].str; i++) {                int n = strlen(raw_params[i].str);                if (!strncmp(line,raw_params[i].str,n)) {                        raw_params[i].setup_func(line+n, NULL);                        return 1;                }        }	return 0;}/* this should be approx 2 Bo*oMips to start (note initial shift), and will   still work even if initially too large, it will just take slightly longer */unsigned long loops_per_sec = (1<<12);#if defined(__SMP__) && defined(__i386__)unsigned long smp_loops_per_tick = 1000000;#endif/* This is the number of bits of precision for the loops_per_second.  Each   bit takes on average 1.5/HZ seconds.  This (like the original) is a little   better than 1% */#define LPS_PREC 8

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -