Import 2.1.42pre1
[davej-history.git] / init / main.c
blobf1b0a8db333f3a5f5f5e9a7c7b9c42979c415d43
1 /*
2 * linux/init/main.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * GK 2/5/95 - Changed to support mounting root fs via NFS
7 * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
8 * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
9 * Simplified starting of init: Michael A. Griffith <grif@acm.org>
12 #define __KERNEL_SYSCALLS__
14 #include <linux/types.h>
15 #include <linux/fcntl.h>
16 #include <linux/config.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/tty.h>
20 #include <linux/head.h>
21 #include <linux/unistd.h>
22 #include <linux/string.h>
23 #include <linux/timer.h>
24 #include <linux/fs.h>
25 #include <linux/proc_fs.h>
26 #include <linux/ctype.h>
27 #include <linux/delay.h>
28 #include <linux/utsname.h>
29 #include <linux/ioport.h>
30 #include <linux/hdreg.h>
31 #include <linux/mm.h>
32 #include <linux/slab.h>
33 #include <linux/major.h>
34 #include <linux/blk.h>
35 #include <linux/init.h>
36 #ifdef CONFIG_ROOT_NFS
37 #include <linux/nfs_fs.h>
38 #endif
40 #include <asm/system.h>
41 #include <asm/io.h>
42 #include <asm/bugs.h>
44 #include <stdarg.h>
48 * Versions of gcc older than that listed below may actually compile
49 * and link okay, but the end product can have subtle run time bugs.
50 * To avoid associated bogus bug reports, we flatly refuse to compile
51 * with a gcc that is known to be too old from the very beginning.
53 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
54 #error sorry, your GCC is too old. It builds incorrect kernels.
55 #endif
57 extern char _stext, _etext;
58 extern char *linux_banner;
60 extern int console_loglevel;
62 static int init(void *);
63 extern int bdflush(void *);
64 extern int kswapd(void *);
66 extern void init_IRQ(void);
67 extern void init_modules(void);
68 extern long console_init(long, long);
69 extern void sock_init(void);
70 extern void uidcache_init(void);
71 extern unsigned long pci_init(unsigned long, unsigned long);
72 extern long mca_init(long, long);
73 extern long sbus_init(long, long);
74 extern void sysctl_init(void);
76 extern void smp_setup(char *str, int *ints);
77 extern void no_scroll(char *str, int *ints);
78 extern void swap_setup(char *str, int *ints);
79 extern void buff_setup(char *str, int *ints);
80 extern void panic_setup(char *str, int *ints);
81 extern void bmouse_setup(char *str, int *ints);
82 extern void msmouse_setup(char *str, int *ints);
83 #ifdef CONFIG_PRINTER
84 extern void lp_setup(char *str, int *ints);
85 #endif
86 extern void eth_setup(char *str, int *ints);
87 extern void xd_setup(char *str, int *ints);
88 #ifdef CONFIG_BLK_DEV_EZ
89 extern void ez_setup(char *str, int *ints);
90 #endif
91 extern void floppy_setup(char *str, int *ints);
92 extern void st_setup(char *str, int *ints);
93 extern void st0x_setup(char *str, int *ints);
94 extern void advansys_setup(char *str, int *ints);
95 extern void tmc8xx_setup(char *str, int *ints);
96 extern void t128_setup(char *str, int *ints);
97 extern void pas16_setup(char *str, int *ints);
98 extern void generic_NCR5380_setup(char *str, int *intr);
99 extern void generic_NCR53C400_setup(char *str, int *intr);
100 extern void aha152x_setup(char *str, int *ints);
101 extern void aha1542_setup(char *str, int *ints);
102 extern void aic7xxx_setup(char *str, int *ints);
103 extern void AM53C974_setup(char *str, int *ints);
104 extern void BusLogic_Setup(char *str, int *ints);
105 extern void ncr53c8xx_setup(char *str, int *ints);
106 extern void eata2x_setup(char *str, int *ints);
107 extern void u14_34f_setup(char *str, int *ints);
108 extern void fdomain_setup(char *str, int *ints);
109 extern void ibmmca_scsi_setup(char *str, int *ints);
110 extern void in2000_setup(char *str, int *ints);
111 extern void NCR53c406a_setup(char *str, int *ints);
112 extern void wd7000_setup(char *str, int *ints);
113 #ifdef NOTDEF
114 extern void ppa_setup(char *str, int *ints);
115 #endif
116 extern void scsi_luns_setup(char *str, int *ints);
117 extern void sound_setup(char *str, int *ints);
118 extern void reboot_setup(char *str, int *ints);
119 extern void video_setup(char *str, int *ints);
120 #ifdef CONFIG_CDU31A
121 extern void cdu31a_setup(char *str, int *ints);
122 #endif CONFIG_CDU31A
123 #ifdef CONFIG_BLK_DEV_PS2
124 extern void ed_setup(char *str, int *ints);
125 extern void tp720_setup(char *str, int *ints);
126 #endif CONFIG_BLK_DEV_PS2
127 #ifdef CONFIG_MCD
128 extern void mcd_setup(char *str, int *ints);
129 #endif CONFIG_MCD
130 #ifdef CONFIG_MCDX
131 extern void mcdx_setup(char *str, int *ints);
132 #endif CONFIG_MCDX
133 #ifdef CONFIG_SBPCD
134 extern void sbpcd_setup(char *str, int *ints);
135 #endif CONFIG_SBPCD
136 #ifdef CONFIG_AZTCD
137 extern void aztcd_setup(char *str, int *ints);
138 #endif CONFIG_AZTCD
139 #ifdef CONFIG_CDU535
140 extern void sonycd535_setup(char *str, int *ints);
141 #endif CONFIG_CDU535
142 #ifdef CONFIG_GSCD
143 extern void gscd_setup(char *str, int *ints);
144 #endif CONFIG_GSCD
145 #ifdef CONFIG_BPCD
146 extern void bpcd_setup(char *str, int *ints);
147 #endif CONFIG_BPCD
148 #ifdef CONFIG_CM206
149 extern void cm206_setup(char *str, int *ints);
150 #endif CONFIG_CM206
151 #ifdef CONFIG_OPTCD
152 extern void optcd_setup(char *str, int *ints);
153 #endif CONFIG_OPTCD
154 #ifdef CONFIG_SJCD
155 extern void sjcd_setup(char *str, int *ints);
156 #endif CONFIG_SJCD
157 #ifdef CONFIG_ISP16_CDI
158 extern void isp16_setup(char *str, int *ints);
159 #endif CONFIG_ISP16_CDI
160 #ifdef CONFIG_BLK_DEV_RAM
161 static void ramdisk_start_setup(char *str, int *ints);
162 static void load_ramdisk(char *str, int *ints);
163 static void prompt_ramdisk(char *str, int *ints);
164 static void ramdisk_size(char *str, int *ints);
165 #ifdef CONFIG_BLK_DEV_INITRD
166 static void no_initrd(char *s,int *ints);
167 #endif
168 #endif CONFIG_BLK_DEV_RAM
169 #ifdef CONFIG_ISDN_DRV_ICN
170 extern void icn_setup(char *str, int *ints);
171 #endif
172 #ifdef CONFIG_ISDN_DRV_HISAX
173 extern void HiSax_setup(char *str, int *ints);
174 #endif
175 #ifdef CONFIG_DIGIEPCA
176 extern void epca_setup(char *str, int *ints);
177 #endif
178 #ifdef CONFIG_ISDN_DRV_PCBIT
179 extern void pcbit_setup(char *str, int *ints);
180 #endif
182 #ifdef CONFIG_ATARIMOUSE
183 extern void atari_mouse_setup (char *str, int *ints);
184 #endif
185 #ifdef CONFIG_DMASOUND
186 extern void dmasound_setup (char *str, int *ints);
187 #endif
188 #ifdef CONFIG_ATARI_SCSI
189 extern void atari_scsi_setup (char *str, int *ints);
190 #endif
191 extern void wd33c93_setup (char *str, int *ints);
192 extern void gvp11_setup (char *str, int *ints);
193 extern void ncr53c7xx_setup (char *str, int *ints);
195 #ifdef CONFIG_CYCLADES
196 extern void cy_setup(char *str, int *ints);
197 #endif
198 #ifdef CONFIG_DIGI
199 extern void pcxx_setup(char *str, int *ints);
200 #endif
201 #ifdef CONFIG_RISCOM8
202 extern void riscom8_setup(char *str, int *ints);
203 #endif
204 #ifdef CONFIG_BAYCOM
205 extern void baycom_setup(char *str, int *ints);
206 #endif
207 #ifdef CONFIG_SOUNDMODEM
208 extern void sm_setup(char *str, int *ints);
209 #endif
210 #ifdef CONFIG_WDT
211 extern void wdt_setup(char *str, int *ints);
212 #endif
213 #ifdef CONFIG_PNP_PARPORT
214 extern void parport_setup(char *str, int *ints);
215 #endif
216 #ifdef CONFIG_PLIP
217 extern void plip_setup(char *str, int *ints);
218 #endif
220 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
221 extern void ipc_init(void);
222 #endif
224 #ifdef __sparc__
225 extern int serial_console;
226 #endif
229 * Boot command-line arguments
231 #define MAX_INIT_ARGS 8
232 #define MAX_INIT_ENVS 8
234 extern void time_init(void);
236 static unsigned long memory_start = 0;
237 static unsigned long memory_end = 0;
239 int rows, cols;
241 #ifdef CONFIG_BLK_DEV_RAM
242 extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
243 extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
244 extern int rd_size; /* Size of the ramdisk(s) */
245 extern int rd_image_start; /* starting block # of image */
246 #ifdef CONFIG_BLK_DEV_INITRD
247 kdev_t real_root_dev;
248 #endif
249 #endif
251 int root_mountflags = MS_RDONLY;
252 char *execute_command = NULL;
254 #ifdef CONFIG_ROOT_NFS
255 char nfs_root_name[NFS_ROOT_NAME_LEN] = { "default" };
256 char nfs_root_addrs[NFS_ROOT_ADDRS_LEN] = { "" };
257 #endif
259 extern void dquot_init(void);
261 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
262 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
264 char *get_options(char *str, int *ints)
266 char *cur = str;
267 int i=1;
269 while (cur && isdigit(*cur) && i <= 10) {
270 ints[i++] = simple_strtoul(cur,NULL,0);
271 if ((cur = strchr(cur,',')) != NULL)
272 cur++;
274 ints[0] = i-1;
275 return(cur);
278 __initfunc(static void profile_setup(char *str, int *ints))
280 if (ints[0] > 0)
281 prof_shift = (unsigned long) ints[1];
282 else
283 #ifdef CONFIG_PROFILE_SHIFT
284 prof_shift = CONFIG_PROFILE_SHIFT;
285 #else
286 prof_shift = 2;
287 #endif
290 struct {
291 const char *str;
292 void (*setup_func)(char *, int *);
293 } bootsetups[] __initdata = {
294 { "reserve=", reserve_setup },
295 { "profile=", profile_setup },
296 #ifdef __SMP__
297 { "nosmp", smp_setup },
298 { "maxcpus=", smp_setup },
299 #endif
300 #ifdef CONFIG_BLK_DEV_RAM
301 { "ramdisk_start=", ramdisk_start_setup },
302 { "load_ramdisk=", load_ramdisk },
303 { "prompt_ramdisk=", prompt_ramdisk },
304 { "ramdisk=", ramdisk_size },
305 { "ramdisk_size=", ramdisk_size },
306 #ifdef CONFIG_BLK_DEV_INITRD
307 { "noinitrd", no_initrd },
308 #endif
309 #endif
310 #if defined (CONFIG_AMIGA) || defined (CONFIG_ATARI)
311 { "video=", video_setup },
312 #endif
313 { "swap=", swap_setup },
314 { "buff=", buff_setup },
315 { "panic=", panic_setup },
316 #ifdef CONFIG_VT
317 { "no-scroll", no_scroll },
318 #endif
319 #ifdef CONFIG_BUGi386
320 { "no-hlt", no_halt },
321 { "no387", no_387 },
322 { "reboot=", reboot_setup },
323 #endif
324 #ifdef CONFIG_INET
325 { "ether=", eth_setup },
326 #endif
327 #ifdef CONFIG_PRINTER
328 { "lp=", lp_setup },
329 #endif
330 #ifdef CONFIG_SCSI
331 { "max_scsi_luns=", scsi_luns_setup },
332 #endif
333 #ifdef CONFIG_SCSI_ADVANSYS
334 { "advansys=", advansys_setup },
335 #endif
336 #if defined(CONFIG_BLK_DEV_HD)
337 { "hd=", hd_setup },
338 #endif
339 #ifdef CONFIG_CHR_DEV_ST
340 { "st=", st_setup },
341 #endif
342 #ifdef CONFIG_BUSMOUSE
343 { "bmouse=", bmouse_setup },
344 #endif
345 #ifdef CONFIG_MS_BUSMOUSE
346 { "msmouse=", msmouse_setup },
347 #endif
348 #ifdef CONFIG_SCSI_SEAGATE
349 { "st0x=", st0x_setup },
350 { "tmc8xx=", tmc8xx_setup },
351 #endif
352 #ifdef CONFIG_SCSI_T128
353 { "t128=", t128_setup },
354 #endif
355 #ifdef CONFIG_SCSI_PAS16
356 { "pas16=", pas16_setup },
357 #endif
358 #ifdef CONFIG_SCSI_GENERIC_NCR5380
359 { "ncr5380=", generic_NCR5380_setup },
360 { "ncr53c400=", generic_NCR53C400_setup },
361 #endif
362 #ifdef CONFIG_SCSI_AHA152X
363 { "aha152x=", aha152x_setup},
364 #endif
365 #ifdef CONFIG_SCSI_AHA1542
366 { "aha1542=", aha1542_setup},
367 #endif
368 #ifdef CONFIG_SCSI_AIC7XXX
369 { "aic7xxx=", aic7xxx_setup},
370 #endif
371 #ifdef CONFIG_SCSI_BUSLOGIC
372 { "BusLogic=", BusLogic_Setup},
373 #endif
374 #ifdef CONFIG_SCSI_NCR53C8XX
375 { "ncr53c8xx=", ncr53c8xx_setup},
376 #endif
377 #ifdef CONFIG_SCSI_EATA
378 { "eata=", eata2x_setup},
379 #endif
380 #ifdef CONFIG_SCSI_U14_34F
381 { "u14-34f=", u14_34f_setup},
382 #endif
383 #ifdef CONFIG_SCSI_AM53C974
384 { "AM53C974=", AM53C974_setup},
385 #endif
386 #ifdef CONFIG_SCSI_NCR53C406A
387 { "ncr53c406a=", NCR53c406a_setup},
388 #endif
389 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
390 { "fdomain=", fdomain_setup},
391 #endif
392 #ifdef CONFIG_SCSI_IN2000
393 { "in2000=", in2000_setup},
394 #endif
395 #ifdef CONFIG_SCSI_7000FASST
396 { "wd7000=", wd7000_setup},
397 #endif
398 #ifdef NOTDEF /* CONFIG_SCSI_PPA */
399 { "ppa=", ppa_setup },
400 #endif
401 #ifdef CONFIG_SCSI_IBMMCA
402 { "ibmmcascsi=", ibmmca_scsi_setup },
403 #endif
404 #ifdef CONFIG_BLK_DEV_XD
405 { "xd=", xd_setup },
406 #endif
407 #ifdef CONFIG_BLK_DEV_EZ
408 { "ez=", ez_setup },
409 #endif
410 #ifdef CONFIG_BLK_DEV_FD
411 { "floppy=", floppy_setup },
412 #endif
413 #ifdef CONFIG_BLK_DEV_PS2
414 { "ed=", ed_setup },
415 { "tp720=", tp720_setup },
416 #endif
417 #ifdef CONFIG_CDU31A
418 { "cdu31a=", cdu31a_setup },
419 #endif CONFIG_CDU31A
420 #ifdef CONFIG_MCD
421 { "mcd=", mcd_setup },
422 #endif CONFIG_MCD
423 #ifdef CONFIG_MCDX
424 { "mcdx=", mcdx_setup },
425 #endif CONFIG_MCDX
426 #ifdef CONFIG_SBPCD
427 { "sbpcd=", sbpcd_setup },
428 #endif CONFIG_SBPCD
429 #ifdef CONFIG_AZTCD
430 { "aztcd=", aztcd_setup },
431 #endif CONFIG_AZTCD
432 #ifdef CONFIG_CDU535
433 { "sonycd535=", sonycd535_setup },
434 #endif CONFIG_CDU535
435 #ifdef CONFIG_GSCD
436 { "gscd=", gscd_setup },
437 #endif CONFIG_GSCD
438 #ifdef CONFIG_BPCD
439 { "bpcd=", bpcd_setup },
440 #endif CONFIG_BPCD
441 #ifdef CONFIG_CM206
442 { "cm206=", cm206_setup },
443 #endif CONFIG_CM206
444 #ifdef CONFIG_OPTCD
445 { "optcd=", optcd_setup },
446 #endif CONFIG_OPTCD
447 #ifdef CONFIG_SJCD
448 { "sjcd=", sjcd_setup },
449 #endif CONFIG_SJCD
450 #ifdef CONFIG_ISP16_CDI
451 { "isp16=", isp16_setup },
452 #endif CONFIG_ISP16_CDI
453 #ifdef CONFIG_SOUND
454 { "sound=", sound_setup },
455 #endif
456 #ifdef CONFIG_ISDN_DRV_ICN
457 { "icn=", icn_setup },
458 #endif
459 #ifdef CONFIG_ISDN_DRV_HISAX
460 { "hisax=", HiSax_setup },
461 { "HiSax=", HiSax_setup },
462 #endif
463 #ifdef CONFIG_ISDN_DRV_PCBIT
464 { "pcbit=", pcbit_setup },
465 #endif
466 #ifdef CONFIG_ATARIMOUSE
467 { "atamouse=", atari_mouse_setup },
468 #endif
469 #ifdef CONFIG_DMASOUND
470 { "dmasound=", dmasound_setup },
471 #endif
472 #ifdef CONFIG_ATARI_SCSI
473 { "atascsi=", atari_scsi_setup },
474 #endif
475 #if defined(CONFIG_A4000T_SCSI) || defined(CONFIG_WARPENGINE_SCSI) || defined(CONFIG_A4091_SCSI)
476 { "53c7xx=", ncr53c7xx_setup },
477 #endif
478 #if defined(CONFIG_A3000_SCSI) || defined(CONFIG_A2091_SCSI) \
479 || defined(CONFIG_GVP11_SCSI)
480 { "wd33c93=", wd33c93_setup },
481 #endif
482 #if defined(CONFIG_GVP11_SCSI)
483 { "gvp11=", gvp11_setup },
484 #endif
485 #ifdef CONFIG_CYCLADES
486 { "cyclades=", cy_setup },
487 #endif
488 #ifdef CONFIG_DIGI
489 { "digi=", pcxx_setup },
490 #endif
491 #ifdef CONFIG_DIGIEPCA
492 { "digiepca=", epca_setup },
493 #endif
494 #ifdef CONFIG_RISCOM8
495 { "riscom8=", riscom8_setup },
496 #endif
497 #ifdef CONFIG_BAYCOM
498 { "baycom=", baycom_setup },
499 #endif
500 #ifdef CONFIG_SOUNDMODEM
501 { "soundmodem=", sm_setup },
502 #endif
503 #ifdef CONFIG_WDT
504 { "wdt=", wdt_setup },
505 #endif
506 #ifdef CONFIG_PNP_PARPORT
507 { "parport=", parport_setup },
508 #endif
509 #ifdef CONFIG_PLIP
510 { "plip=", plip_setup },
511 #endif
512 { 0, 0 }
515 #ifdef CONFIG_BLK_DEV_RAM
516 __initfunc(static void ramdisk_start_setup(char *str, int *ints))
518 if (ints[0] > 0 && ints[1] >= 0)
519 rd_image_start = ints[1];
522 __initfunc(static void load_ramdisk(char *str, int *ints))
524 if (ints[0] > 0 && ints[1] >= 0)
525 rd_doload = ints[1] & 1;
528 __initfunc(static void prompt_ramdisk(char *str, int *ints))
530 if (ints[0] > 0 && ints[1] >= 0)
531 rd_prompt = ints[1] & 1;
534 __initfunc(static void ramdisk_size(char *str, int *ints))
536 if (ints[0] > 0 && ints[1] >= 0)
537 rd_size = ints[1];
540 #endif
542 __initfunc(static int checksetup(char *line))
544 int i = 0;
545 int ints[11];
547 #ifdef CONFIG_BLK_DEV_IDE
548 /* ide driver needs the basic string, rather than pre-processed values */
549 if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {
550 ide_setup(line);
551 return 1;
553 #endif
554 while (bootsetups[i].str) {
555 int n = strlen(bootsetups[i].str);
556 if (!strncmp(line,bootsetups[i].str,n)) {
557 bootsetups[i].setup_func(get_options(line+n,ints), ints);
558 return 1;
560 i++;
562 return 0;
565 /* this should be approx 2 Bo*oMips to start (note initial shift), and will
566 still work even if initially too large, it will just take slightly longer */
567 unsigned long loops_per_sec = (1<<12);
569 /* This is the number of bits of precision for the loops_per_second. Each
570 bit takes on average 1.5/HZ seconds. This (like the original) is a little
571 better than 1% */
572 #define LPS_PREC 8
574 __initfunc(void calibrate_delay(void))
576 unsigned long ticks, loopbit;
577 int lps_precision = LPS_PREC;
579 loops_per_sec = (1<<12);
581 printk("Calibrating delay loop.. ");
582 while (loops_per_sec <<= 1) {
583 /* wait for "start of" clock tick */
584 ticks = jiffies;
585 while (ticks == jiffies)
586 /* nothing */;
587 /* Go .. */
588 ticks = jiffies;
589 __delay(loops_per_sec);
590 ticks = jiffies - ticks;
591 if (ticks)
592 break;
595 /* Do a binary approximation to get loops_per_second set to equal one clock
596 (up to lps_precision bits) */
597 loops_per_sec >>= 1;
598 loopbit = loops_per_sec;
599 while ( lps_precision-- && (loopbit >>= 1) ) {
600 loops_per_sec |= loopbit;
601 ticks = jiffies;
602 while (ticks == jiffies);
603 ticks = jiffies;
604 __delay(loops_per_sec);
605 if (jiffies != ticks) /* longer than 1 tick */
606 loops_per_sec &= ~loopbit;
609 /* finally, adjust loops per second in terms of seconds instead of clocks */
610 loops_per_sec *= HZ;
611 /* Round the value and print it */
612 printk("ok - %lu.%02lu BogoMIPS\n",
613 (loops_per_sec+2500)/500000,
614 ((loops_per_sec+2500)/5000) % 100);
617 __initfunc(static void parse_root_dev(char * line))
619 int base = 0;
620 static struct dev_name_struct {
621 const char *name;
622 const int num;
623 } devices[] = {
624 { "nfs", 0x00ff },
625 { "hda", 0x0300 },
626 { "hdb", 0x0340 },
627 { "hdc", 0x1600 },
628 { "hdd", 0x1640 },
629 { "sda", 0x0800 },
630 { "sdb", 0x0810 },
631 { "sdc", 0x0820 },
632 { "sdd", 0x0830 },
633 { "sde", 0x0840 },
634 { "ada", 0x1c00 },
635 { "adb", 0x1c10 },
636 { "adc", 0x1c20 },
637 { "add", 0x1c30 },
638 { "ade", 0x1c40 },
639 { "fd", 0x0200 },
640 { "xda", 0x0d00 },
641 { "xdb", 0x0d40 },
642 { "ram", 0x0100 },
643 { "scd", 0x0b00 },
644 { "mcd", 0x1700 },
645 { "cdu535", 0x1800 },
646 { "aztcd", 0x1d00 },
647 { "cm206cd", 0x2000 },
648 { "gscd", 0x1000 },
649 { "sbpcd", 0x1900 },
650 { "sonycd", 0x1800 },
651 { "eda", 0x2400 },
652 { "eza", 0x2800 },
653 { "bpcd", 0x2900 },
654 #if CONFIG_APBLOCK
655 { "apblock", APBLOCK_MAJOR << 8},
656 #endif
657 #if CONFIG_DDV
658 { "ddv", DDV_MAJOR << 8},
659 #endif
660 { NULL, 0 }
663 if (strncmp(line,"/dev/",5) == 0) {
664 struct dev_name_struct *dev = devices;
665 line += 5;
666 do {
667 int len = strlen(dev->name);
668 if (strncmp(line,dev->name,len) == 0) {
669 line += len;
670 base = dev->num;
671 break;
673 dev++;
674 } while (dev->name);
676 ROOT_DEV = to_kdev_t(base + simple_strtoul(line,NULL,base?10:16));
680 * This is a simple kernel command line parsing function: it parses
681 * the command line, and fills in the arguments/environment to init
682 * as appropriate. Any cmd-line option is taken to be an environment
683 * variable if it contains the character '='.
686 * This routine also checks for options meant for the kernel.
687 * These options are not given to init - they are for internal kernel use only.
689 __initfunc(static void parse_options(char *line))
691 char *next;
692 int args, envs;
694 if (!*line)
695 return;
696 args = 0;
697 envs = 1; /* TERM is set to 'linux' by default */
698 next = line;
699 while ((line = next) != NULL) {
700 if ((next = strchr(line,' ')) != NULL)
701 *next++ = 0;
703 * check for kernel options first..
705 if (!strncmp(line,"root=",5)) {
706 parse_root_dev(line+5);
707 continue;
709 #ifdef CONFIG_ROOT_NFS
710 if (!strncmp(line, "nfsroot=", 8)) {
711 int n;
712 line += 8;
713 ROOT_DEV = MKDEV(UNNAMED_MAJOR, 255);
714 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) {
715 strncpy(nfs_root_name, line, sizeof(nfs_root_name));
716 nfs_root_name[sizeof(nfs_root_name)-1] = '\0';
717 continue;
719 n = strlen(line) + strlen(NFS_ROOT);
720 if (n >= sizeof(nfs_root_name))
721 line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
722 sprintf(nfs_root_name, NFS_ROOT, line);
723 continue;
725 if (!strncmp(line, "nfsaddrs=", 9)) {
726 line += 9;
727 strncpy(nfs_root_addrs, line, sizeof(nfs_root_addrs));
728 nfs_root_addrs[sizeof(nfs_root_addrs)-1] = '\0';
729 continue;
731 #endif
732 if (!strcmp(line,"ro")) {
733 root_mountflags |= MS_RDONLY;
734 continue;
736 if (!strcmp(line,"rw")) {
737 root_mountflags &= ~MS_RDONLY;
738 continue;
740 if (!strcmp(line,"debug")) {
741 console_loglevel = 10;
742 continue;
744 if (!strncmp(line,"init=",5)) {
745 line += 5;
746 execute_command = line;
747 continue;
749 if (checksetup(line))
750 continue;
753 * Then check if it's an environment variable or
754 * an option.
756 if (strchr(line,'=')) {
757 if (envs >= MAX_INIT_ENVS)
758 break;
759 envp_init[++envs] = line;
760 } else {
761 if (args >= MAX_INIT_ARGS)
762 break;
763 argv_init[++args] = line;
766 argv_init[args+1] = NULL;
767 envp_init[envs+1] = NULL;
771 extern void setup_arch(char **, unsigned long *, unsigned long *);
773 #ifndef __SMP__
776 * Uniprocessor idle thread
779 int cpu_idle(void *unused)
781 for(;;)
782 idle();
785 #else
788 * Multiprocessor idle thread is in arch/...
791 extern int cpu_idle(void * unused);
793 /* Called by boot processor to activate the rest. */
794 __initfunc(static void smp_init(void))
796 /* Get other processors into their bootup holding patterns. */
797 smp_boot_cpus();
801 * The autoprobe routines assume CPU#0 on the i386
802 * so we don't actually set the game in motion until
803 * they are finished.
806 __initfunc(static void smp_begin(void))
808 smp_threads_ready=1;
809 smp_commence();
812 #endif
814 extern void initialize_secondary(void);
817 * Activate the first processor.
820 __initfunc(asmlinkage void start_kernel(void))
822 char * command_line;
824 #ifdef __SMP__
825 static int boot_cpu = 1;
826 /* "current" has been set up, we need to load it now */
827 if (!boot_cpu)
828 initialize_secondary();
829 boot_cpu = 0;
830 #endif
833 * Interrupts are still disabled. Do necessary setups, then
834 * enable them
836 setup_arch(&command_line, &memory_start, &memory_end);
837 memory_start = paging_init(memory_start,memory_end);
838 trap_init();
839 init_IRQ();
840 sched_init();
841 time_init();
842 parse_options(command_line);
843 #ifdef CONFIG_MODULES
844 init_modules();
845 #endif
846 #ifdef CONFIG_PROFILE
847 if (!prof_shift)
848 #ifdef CONFIG_PROFILE_SHIFT
849 prof_shift = CONFIG_PROFILE_SHIFT;
850 #else
851 prof_shift = 2;
852 #endif
853 #endif
854 if (prof_shift) {
855 prof_buffer = (unsigned int *) memory_start;
856 /* only text is profiled */
857 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
858 prof_len >>= prof_shift;
859 memory_start += prof_len * sizeof(unsigned int);
860 memset(prof_buffer, 0, prof_len * sizeof(unsigned int));
862 #ifdef CONFIG_SBUS
863 memory_start = sbus_init(memory_start,memory_end);
864 #endif
865 memory_start = console_init(memory_start,memory_end);
866 #ifdef CONFIG_PCI
867 memory_start = pci_init(memory_start,memory_end);
868 #endif
869 #ifdef CONFIG_MCA
870 memory_start = mca_init(memory_start,memory_end);
871 #endif
872 memory_start = kmem_cache_init(memory_start, memory_end);
873 sti();
874 calibrate_delay();
875 memory_start = name_cache_init(memory_start,memory_end);
876 #ifdef CONFIG_BLK_DEV_INITRD
877 if (initrd_start && !initrd_below_start_ok && initrd_start < memory_start) {
878 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
879 "disabling it.\n",initrd_start,memory_start);
880 initrd_start = 0;
882 #endif
883 mem_init(memory_start,memory_end);
884 kmem_cache_sizes_init();
885 #ifdef CONFIG_PROC_FS
886 proc_root_init();
887 #endif
888 uidcache_init();
889 vma_init();
890 buffer_init();
891 inode_init();
892 file_table_init();
893 sock_init();
894 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
895 ipc_init();
896 #endif
897 dquot_init();
898 sti();
899 check_bugs();
901 printk(linux_banner);
902 printk("POSIX conformance testing by UNIFIX\n");
903 #ifdef __SMP__
904 smp_init();
905 #endif
906 #ifdef CONFIG_SYSCTL
907 sysctl_init();
908 #endif
910 * We count on the initial thread going ok
911 * Like idlers init is an unlocked kernel thread, which will
912 * make syscalls (and thus be locked).
914 kernel_thread(init, NULL, 0);
916 * task[0] is meant to be used as an "idle" task: it may not sleep, but
917 * it might do some general things like count free pages or it could be
918 * used to implement a reasonable LRU algorithm for the paging routines:
919 * anything that can be useful, but shouldn't take time from the real
920 * processes.
922 * Right now task[0] just does an infinite idle loop.
924 cpu_idle(NULL);
927 #ifdef CONFIG_BLK_DEV_INITRD
928 static int do_linuxrc(void * shell)
930 static char *argv[] = { "linuxrc", NULL, };
932 close(0);close(1);close(2);
933 setsid();
934 (void) open("/dev/tty1",O_RDWR,0);
935 (void) dup(0);
936 (void) dup(0);
937 return execve(shell, argv, envp_init);
940 __initfunc(static void no_initrd(char *s,int *ints))
942 mount_initrd = 0;
944 #endif
946 static int init(void * unused)
948 #ifdef CONFIG_BLK_DEV_INITRD
949 int real_root_mountflags;
950 #endif
952 /* Launch bdflush from here, instead of the old syscall way. */
953 kernel_thread(bdflush, NULL, 0);
954 /* Start the background pageout daemon. */
955 kernel_thread(kswapd, NULL, 0);
957 #if CONFIG_AP1000
958 /* Start the async paging daemon. */
960 extern int asyncd(void *);
961 kernel_thread(asyncd, NULL, 0);
963 #endif
965 #ifdef CONFIG_BLK_DEV_INITRD
966 real_root_dev = ROOT_DEV;
967 real_root_mountflags = root_mountflags;
968 if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
969 else mount_initrd =0;
970 #endif
971 setup(0);
973 #ifdef __SMP__
975 * With the devices probed and setup we can
976 * now enter SMP mode.
979 smp_begin();
980 #endif
982 #ifdef CONFIG_UMSDOS_FS
985 When mounting a umsdos fs as root, we detect
986 the pseudo_root (/linux) and initialise it here.
987 pseudo_root is defined in fs/umsdos/inode.c
989 extern struct inode *pseudo_root;
990 if (pseudo_root != NULL){
991 current->fs->root = pseudo_root;
992 current->fs->pwd = pseudo_root;
995 #endif
997 #ifdef CONFIG_BLK_DEV_INITRD
998 root_mountflags = real_root_mountflags;
999 if (mount_initrd && ROOT_DEV != real_root_dev && ROOT_DEV == MKDEV(RAMDISK_MAJOR,0)) {
1000 int error;
1001 int i, pid;
1003 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
1004 if (pid>0)
1005 while (pid != wait(&i));
1006 if (real_root_dev != MKDEV(RAMDISK_MAJOR, 0)) {
1007 error = change_root(real_root_dev,"/initrd");
1008 if (error)
1009 printk(KERN_ERR "Change root to /initrd: "
1010 "error %d\n",error);
1013 #endif
1015 setup(1);
1017 if (open("/dev/console",O_RDWR,0) < 0)
1018 printk("Unable to open an initial console.\n");
1020 (void) dup(0);
1021 (void) dup(0);
1024 * We try each of these until one succeeds.
1026 * The Bourne shell can be used instead of init if we are
1027 * trying to recover a really broken machine.
1030 if(execute_command)
1031 execve(execute_command,argv_init,envp_init);
1032 execve("/sbin/init",argv_init,envp_init);
1033 execve("/etc/init",argv_init,envp_init);
1034 execve("/bin/init",argv_init,envp_init);
1035 execve("/bin/sh",argv_init,envp_init);
1036 panic("No init found. Try passing init= option to kernel.");