elf2coff isn't a generic tool for all linux ports
[linux-2.6/linux-mips.git] / init / main.c
blob659f86b2e05ced1ce91943c132856ca2447eec3c
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>
46 #ifdef CONFIG_SGI
47 #include <asm/sgialib.h>
48 #endif
51 * Versions of gcc older than that listed below may actually compile
52 * and link okay, but the end product can have subtle run time bugs.
53 * To avoid associated bogus bug reports, we flatly refuse to compile
54 * with a gcc that is known to be too old from the very beginning.
56 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
57 #error sorry, your GCC is too old. It builds incorrect kernels.
58 #endif
60 extern char _stext, _etext;
61 extern char *linux_banner;
63 extern int console_loglevel;
65 static int init(void *);
66 extern int bdflush(void *);
67 extern int kswapd(void *);
68 extern void kswapd_setup(void);
70 extern void init_IRQ(void);
71 extern void init_modules(void);
72 extern long console_init(long, long);
73 extern void sock_init(void);
74 extern void uidcache_init(void);
75 extern unsigned long pci_init(unsigned long, unsigned long);
76 extern long mca_init(long, long);
77 extern long sbus_init(long, long);
78 extern void sysctl_init(void);
79 extern void filescache_init(void);
81 extern void smp_setup(char *str, int *ints);
82 extern void no_scroll(char *str, int *ints);
83 extern void swap_setup(char *str, int *ints);
84 extern void buff_setup(char *str, int *ints);
85 extern void panic_setup(char *str, int *ints);
86 extern void bmouse_setup(char *str, int *ints);
87 extern void msmouse_setup(char *str, int *ints);
88 #ifdef CONFIG_PRINTER
89 extern void lp_setup(char *str, int *ints);
90 #endif
91 extern void eth_setup(char *str, int *ints);
92 #ifdef CONFIG_DECNET
93 extern void decnet_setup(char *str, int *ints);
94 #endif
95 extern void xd_setup(char *str, int *ints);
96 #ifdef CONFIG_BLK_DEV_EZ
97 extern void ez_setup(char *str, int *ints);
98 #endif
99 extern void floppy_setup(char *str, int *ints);
100 extern void st_setup(char *str, int *ints);
101 extern void st0x_setup(char *str, int *ints);
102 extern void advansys_setup(char *str, int *ints);
103 extern void tmc8xx_setup(char *str, int *ints);
104 extern void t128_setup(char *str, int *ints);
105 extern void pas16_setup(char *str, int *ints);
106 extern void generic_NCR5380_setup(char *str, int *intr);
107 extern void generic_NCR53C400_setup(char *str, int *intr);
108 extern void aha152x_setup(char *str, int *ints);
109 extern void aha1542_setup(char *str, int *ints);
110 extern void aic7xxx_setup(char *str, int *ints);
111 extern void AM53C974_setup(char *str, int *ints);
112 extern void BusLogic_Setup(char *str, int *ints);
113 extern void ncr53c8xx_setup(char *str, int *ints);
114 extern void eata2x_setup(char *str, int *ints);
115 extern void u14_34f_setup(char *str, int *ints);
116 extern void fdomain_setup(char *str, int *ints);
117 extern void ibmmca_scsi_setup(char *str, int *ints);
118 extern void in2000_setup(char *str, int *ints);
119 extern void NCR53c406a_setup(char *str, int *ints);
120 extern void wd7000_setup(char *str, int *ints);
121 #ifdef NOTDEF
122 extern void ppa_setup(char *str, int *ints);
123 #endif
124 extern void scsi_luns_setup(char *str, int *ints);
125 extern void sound_setup(char *str, int *ints);
126 extern void reboot_setup(char *str, int *ints);
127 extern void video_setup(char *str, int *ints);
128 #ifdef CONFIG_CDU31A
129 extern void cdu31a_setup(char *str, int *ints);
130 #endif CONFIG_CDU31A
131 #ifdef CONFIG_BLK_DEV_PS2
132 extern void ed_setup(char *str, int *ints);
133 extern void tp720_setup(char *str, int *ints);
134 #endif CONFIG_BLK_DEV_PS2
135 #ifdef CONFIG_MCD
136 extern void mcd_setup(char *str, int *ints);
137 #endif CONFIG_MCD
138 #ifdef CONFIG_MCDX
139 extern void mcdx_setup(char *str, int *ints);
140 #endif CONFIG_MCDX
141 #ifdef CONFIG_SBPCD
142 extern void sbpcd_setup(char *str, int *ints);
143 #endif CONFIG_SBPCD
144 #ifdef CONFIG_AZTCD
145 extern void aztcd_setup(char *str, int *ints);
146 #endif CONFIG_AZTCD
147 #ifdef CONFIG_CDU535
148 extern void sonycd535_setup(char *str, int *ints);
149 #endif CONFIG_CDU535
150 #ifdef CONFIG_GSCD
151 extern void gscd_setup(char *str, int *ints);
152 #endif CONFIG_GSCD
153 #ifdef CONFIG_BPCD
154 extern void bpcd_setup(char *str, int *ints);
155 #endif CONFIG_BPCD
156 #ifdef CONFIG_CM206
157 extern void cm206_setup(char *str, int *ints);
158 #endif CONFIG_CM206
159 #ifdef CONFIG_OPTCD
160 extern void optcd_setup(char *str, int *ints);
161 #endif CONFIG_OPTCD
162 #ifdef CONFIG_SJCD
163 extern void sjcd_setup(char *str, int *ints);
164 #endif CONFIG_SJCD
165 #ifdef CONFIG_ISP16_CDI
166 extern void isp16_setup(char *str, int *ints);
167 #endif CONFIG_ISP16_CDI
168 #ifdef CONFIG_BLK_DEV_RAM
169 static void ramdisk_start_setup(char *str, int *ints);
170 static void load_ramdisk(char *str, int *ints);
171 static void prompt_ramdisk(char *str, int *ints);
172 static void ramdisk_size(char *str, int *ints);
173 #ifdef CONFIG_BLK_DEV_INITRD
174 static void no_initrd(char *s,int *ints);
175 #endif
176 #endif CONFIG_BLK_DEV_RAM
177 #ifdef CONFIG_ISDN_DRV_ICN
178 extern void icn_setup(char *str, int *ints);
179 #endif
180 #ifdef CONFIG_ISDN_DRV_HISAX
181 extern void HiSax_setup(char *str, int *ints);
182 #endif
183 #ifdef CONFIG_DIGIEPCA
184 extern void epca_setup(char *str, int *ints);
185 #endif
186 #ifdef CONFIG_ISDN_DRV_PCBIT
187 extern void pcbit_setup(char *str, int *ints);
188 #endif
190 #ifdef CONFIG_ATARIMOUSE
191 extern void atari_mouse_setup (char *str, int *ints);
192 #endif
193 #ifdef CONFIG_DMASOUND
194 extern void dmasound_setup (char *str, int *ints);
195 #endif
196 #ifdef CONFIG_ATARI_SCSI
197 extern void atari_scsi_setup (char *str, int *ints);
198 #endif
199 extern void wd33c93_setup (char *str, int *ints);
200 extern void gvp11_setup (char *str, int *ints);
201 extern void ncr53c7xx_setup (char *str, int *ints);
203 #ifdef CONFIG_CYCLADES
204 extern void cy_setup(char *str, int *ints);
205 #endif
206 #ifdef CONFIG_DIGI
207 extern void pcxx_setup(char *str, int *ints);
208 #endif
209 #ifdef CONFIG_RISCOM8
210 extern void riscom8_setup(char *str, int *ints);
211 #endif
212 #ifdef CONFIG_BAYCOM
213 extern void baycom_setup(char *str, int *ints);
214 #endif
215 #ifdef CONFIG_SOUNDMODEM
216 extern void sm_setup(char *str, int *ints);
217 #endif
218 #ifdef CONFIG_WDT
219 extern void wdt_setup(char *str, int *ints);
220 #endif
221 #ifdef CONFIG_PARPORT
222 extern void parport_setup(char *str, int *ints);
223 #endif
224 #ifdef CONFIG_PLIP
225 extern void plip_setup(char *str, int *ints);
226 #endif
228 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
229 extern void ipc_init(void);
230 #endif
231 #ifdef CONFIG_MIPS_JAZZ
232 #include <asm/jazzdma.h>
233 #endif
234 #ifdef CONFIG_REMOTE_DEBUG
235 #include <asm/gdb-stub.h>
236 #endif
238 extern int serial_console;
240 #ifdef __sparc__
241 extern int serial_console;
242 #endif
245 * Boot command-line arguments
247 #define MAX_INIT_ARGS 8
248 #define MAX_INIT_ENVS 8
250 extern void time_init(void);
252 static unsigned long memory_start = 0;
253 static unsigned long memory_end = 0;
255 int rows, cols;
257 #ifdef CONFIG_BLK_DEV_RAM
258 extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
259 extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
260 extern int rd_size; /* Size of the ramdisk(s) */
261 extern int rd_image_start; /* starting block # of image */
262 #ifdef CONFIG_BLK_DEV_INITRD
263 kdev_t real_root_dev;
264 #endif
265 #endif
267 int root_mountflags = MS_RDONLY;
268 char *execute_command = NULL;
270 #ifdef CONFIG_ROOT_NFS
271 char nfs_root_name[NFS_ROOT_NAME_LEN] = { "default" };
272 char nfs_root_addrs[NFS_ROOT_ADDRS_LEN] = { "" };
273 #endif
275 extern void dquot_init(void);
277 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
278 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
280 char *get_options(char *str, int *ints)
282 char *cur = str;
283 int i=1;
285 while (cur && isdigit(*cur) && i <= 10) {
286 ints[i++] = simple_strtoul(cur,NULL,0);
287 if ((cur = strchr(cur,',')) != NULL)
288 cur++;
290 ints[0] = i-1;
291 return(cur);
294 __initfunc(static void profile_setup(char *str, int *ints))
296 if (ints[0] > 0)
297 prof_shift = (unsigned long) ints[1];
298 else
299 #ifdef CONFIG_PROFILE_SHIFT
300 prof_shift = CONFIG_PROFILE_SHIFT;
301 #else
302 prof_shift = 2;
303 #endif
306 struct {
307 const char *str;
308 void (*setup_func)(char *, int *);
309 } bootsetups[] __initdata = {
310 { "reserve=", reserve_setup },
311 { "profile=", profile_setup },
312 #ifdef __SMP__
313 { "nosmp", smp_setup },
314 { "maxcpus=", smp_setup },
315 #endif
316 #ifdef CONFIG_BLK_DEV_RAM
317 { "ramdisk_start=", ramdisk_start_setup },
318 { "load_ramdisk=", load_ramdisk },
319 { "prompt_ramdisk=", prompt_ramdisk },
320 { "ramdisk=", ramdisk_size },
321 { "ramdisk_size=", ramdisk_size },
322 #ifdef CONFIG_BLK_DEV_INITRD
323 { "noinitrd", no_initrd },
324 #endif
325 #endif
326 #if defined (CONFIG_AMIGA) || defined (CONFIG_ATARI)
327 { "video=", video_setup },
328 #endif
329 { "swap=", swap_setup },
330 { "buff=", buff_setup },
331 { "panic=", panic_setup },
332 #ifdef CONFIG_VT
333 { "no-scroll", no_scroll },
334 #endif
335 #ifdef CONFIG_BUGi386
336 { "no-hlt", no_halt },
337 { "no387", no_387 },
338 { "reboot=", reboot_setup },
339 #endif
340 #ifdef CONFIG_INET
341 { "ether=", eth_setup },
342 #endif
343 #ifdef CONFIG_DECNET
344 { "decnet=", decnet_setup },
345 #endif
346 #ifdef CONFIG_PRINTER
347 { "lp=", lp_setup },
348 #endif
349 #ifdef CONFIG_SCSI
350 { "max_scsi_luns=", scsi_luns_setup },
351 #endif
352 #ifdef CONFIG_SCSI_ADVANSYS
353 { "advansys=", advansys_setup },
354 #endif
355 #if defined(CONFIG_BLK_DEV_HD)
356 { "hd=", hd_setup },
357 #endif
358 #ifdef CONFIG_CHR_DEV_ST
359 { "st=", st_setup },
360 #endif
361 #ifdef CONFIG_BUSMOUSE
362 { "bmouse=", bmouse_setup },
363 #endif
364 #ifdef CONFIG_MS_BUSMOUSE
365 { "msmouse=", msmouse_setup },
366 #endif
367 #ifdef CONFIG_SCSI_SEAGATE
368 { "st0x=", st0x_setup },
369 { "tmc8xx=", tmc8xx_setup },
370 #endif
371 #ifdef CONFIG_SCSI_T128
372 { "t128=", t128_setup },
373 #endif
374 #ifdef CONFIG_SCSI_PAS16
375 { "pas16=", pas16_setup },
376 #endif
377 #ifdef CONFIG_SCSI_GENERIC_NCR5380
378 { "ncr5380=", generic_NCR5380_setup },
379 { "ncr53c400=", generic_NCR53C400_setup },
380 #endif
381 #ifdef CONFIG_SCSI_AHA152X
382 { "aha152x=", aha152x_setup},
383 #endif
384 #ifdef CONFIG_SCSI_AHA1542
385 { "aha1542=", aha1542_setup},
386 #endif
387 #ifdef CONFIG_SCSI_AIC7XXX
388 { "aic7xxx=", aic7xxx_setup},
389 #endif
390 #ifdef CONFIG_SCSI_BUSLOGIC
391 { "BusLogic=", BusLogic_Setup},
392 #endif
393 #ifdef CONFIG_SCSI_NCR53C8XX
394 { "ncr53c8xx=", ncr53c8xx_setup},
395 #endif
396 #ifdef CONFIG_SCSI_EATA
397 { "eata=", eata2x_setup},
398 #endif
399 #ifdef CONFIG_SCSI_U14_34F
400 { "u14-34f=", u14_34f_setup},
401 #endif
402 #ifdef CONFIG_SCSI_AM53C974
403 { "AM53C974=", AM53C974_setup},
404 #endif
405 #ifdef CONFIG_SCSI_NCR53C406A
406 { "ncr53c406a=", NCR53c406a_setup},
407 #endif
408 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
409 { "fdomain=", fdomain_setup},
410 #endif
411 #ifdef CONFIG_SCSI_IN2000
412 { "in2000=", in2000_setup},
413 #endif
414 #ifdef CONFIG_SCSI_7000FASST
415 { "wd7000=", wd7000_setup},
416 #endif
417 #ifdef NOTDEF /* CONFIG_SCSI_PPA */
418 { "ppa=", ppa_setup },
419 #endif
420 #ifdef CONFIG_SCSI_IBMMCA
421 { "ibmmcascsi=", ibmmca_scsi_setup },
422 #endif
423 #ifdef CONFIG_BLK_DEV_XD
424 { "xd=", xd_setup },
425 #endif
426 #ifdef CONFIG_BLK_DEV_EZ
427 { "ez=", ez_setup },
428 #endif
429 #ifdef CONFIG_BLK_DEV_FD
430 { "floppy=", floppy_setup },
431 #endif
432 #ifdef CONFIG_BLK_DEV_PS2
433 { "ed=", ed_setup },
434 { "tp720=", tp720_setup },
435 #endif
436 #ifdef CONFIG_CDU31A
437 { "cdu31a=", cdu31a_setup },
438 #endif CONFIG_CDU31A
439 #ifdef CONFIG_MCD
440 { "mcd=", mcd_setup },
441 #endif CONFIG_MCD
442 #ifdef CONFIG_MCDX
443 { "mcdx=", mcdx_setup },
444 #endif CONFIG_MCDX
445 #ifdef CONFIG_SBPCD
446 { "sbpcd=", sbpcd_setup },
447 #endif CONFIG_SBPCD
448 #ifdef CONFIG_AZTCD
449 { "aztcd=", aztcd_setup },
450 #endif CONFIG_AZTCD
451 #ifdef CONFIG_CDU535
452 { "sonycd535=", sonycd535_setup },
453 #endif CONFIG_CDU535
454 #ifdef CONFIG_GSCD
455 { "gscd=", gscd_setup },
456 #endif CONFIG_GSCD
457 #ifdef CONFIG_BPCD
458 { "bpcd=", bpcd_setup },
459 #endif CONFIG_BPCD
460 #ifdef CONFIG_CM206
461 { "cm206=", cm206_setup },
462 #endif CONFIG_CM206
463 #ifdef CONFIG_OPTCD
464 { "optcd=", optcd_setup },
465 #endif CONFIG_OPTCD
466 #ifdef CONFIG_SJCD
467 { "sjcd=", sjcd_setup },
468 #endif CONFIG_SJCD
469 #ifdef CONFIG_ISP16_CDI
470 { "isp16=", isp16_setup },
471 #endif CONFIG_ISP16_CDI
472 #ifdef CONFIG_SOUND
473 { "sound=", sound_setup },
474 #endif
475 #ifdef CONFIG_ISDN_DRV_ICN
476 { "icn=", icn_setup },
477 #endif
478 #ifdef CONFIG_ISDN_DRV_HISAX
479 { "hisax=", HiSax_setup },
480 { "HiSax=", HiSax_setup },
481 #endif
482 #ifdef CONFIG_ISDN_DRV_PCBIT
483 { "pcbit=", pcbit_setup },
484 #endif
485 #ifdef CONFIG_ATARIMOUSE
486 { "atamouse=", atari_mouse_setup },
487 #endif
488 #ifdef CONFIG_DMASOUND
489 { "dmasound=", dmasound_setup },
490 #endif
491 #ifdef CONFIG_ATARI_SCSI
492 { "atascsi=", atari_scsi_setup },
493 #endif
494 #if defined(CONFIG_A4000T_SCSI) || defined(CONFIG_WARPENGINE_SCSI) || defined(CONFIG_A4091_SCSI)
495 { "53c7xx=", ncr53c7xx_setup },
496 #endif
497 #if defined(CONFIG_A3000_SCSI) || defined(CONFIG_A2091_SCSI) \
498 || defined(CONFIG_GVP11_SCSI) || defined(CONFIG_SCSI_SGIWD93)
499 { "wd33c93=", wd33c93_setup },
500 #endif
501 #if defined(CONFIG_GVP11_SCSI)
502 { "gvp11=", gvp11_setup },
503 #endif
504 #ifdef CONFIG_CYCLADES
505 { "cyclades=", cy_setup },
506 #endif
507 #ifdef CONFIG_DIGI
508 { "digi=", pcxx_setup },
509 #endif
510 #ifdef CONFIG_DIGIEPCA
511 { "digiepca=", epca_setup },
512 #endif
513 #ifdef CONFIG_RISCOM8
514 { "riscom8=", riscom8_setup },
515 #endif
516 #ifdef CONFIG_BAYCOM
517 { "baycom=", baycom_setup },
518 #endif
519 #ifdef CONFIG_SOUNDMODEM
520 { "soundmodem=", sm_setup },
521 #endif
522 #ifdef CONFIG_WDT
523 { "wdt=", wdt_setup },
524 #endif
525 #ifdef CONFIG_PARPORT
526 { "parport=", parport_setup },
527 #endif
528 #ifdef CONFIG_PLIP
529 { "plip=", plip_setup },
530 #endif
531 { 0, 0 }
534 #ifdef CONFIG_BLK_DEV_RAM
535 __initfunc(static void ramdisk_start_setup(char *str, int *ints))
537 if (ints[0] > 0 && ints[1] >= 0)
538 rd_image_start = ints[1];
541 __initfunc(static void load_ramdisk(char *str, int *ints))
543 if (ints[0] > 0 && ints[1] >= 0)
544 rd_doload = ints[1] & 1;
547 __initfunc(static void prompt_ramdisk(char *str, int *ints))
549 if (ints[0] > 0 && ints[1] >= 0)
550 rd_prompt = ints[1] & 1;
553 __initfunc(static void ramdisk_size(char *str, int *ints))
555 if (ints[0] > 0 && ints[1] >= 0)
556 rd_size = ints[1];
559 #endif
561 __initfunc(static int checksetup(char *line))
563 int i = 0;
564 int ints[11];
566 #ifdef CONFIG_BLK_DEV_IDE
567 /* ide driver needs the basic string, rather than pre-processed values */
568 if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {
569 ide_setup(line);
570 return 1;
572 #endif
573 while (bootsetups[i].str) {
574 int n = strlen(bootsetups[i].str);
575 if (!strncmp(line,bootsetups[i].str,n)) {
576 bootsetups[i].setup_func(get_options(line+n,ints), ints);
577 return 1;
579 i++;
581 return 0;
584 /* this should be approx 2 Bo*oMips to start (note initial shift), and will
585 still work even if initially too large, it will just take slightly longer */
586 unsigned long loops_per_sec = (1<<12);
588 /* This is the number of bits of precision for the loops_per_second. Each
589 bit takes on average 1.5/HZ seconds. This (like the original) is a little
590 better than 1% */
591 #define LPS_PREC 8
593 __initfunc(void calibrate_delay(void))
595 unsigned long ticks, loopbit;
596 int lps_precision = LPS_PREC;
598 loops_per_sec = (1<<12);
600 printk("Calibrating delay loop.. ");
601 while (loops_per_sec <<= 1) {
602 /* wait for "start of" clock tick */
603 ticks = jiffies;
604 while (ticks == jiffies)
605 /* nothing */;
606 /* Go .. */
607 ticks = jiffies;
608 __delay(loops_per_sec);
609 ticks = jiffies - ticks;
610 if (ticks)
611 break;
614 /* Do a binary approximation to get loops_per_second set to equal one clock
615 (up to lps_precision bits) */
616 loops_per_sec >>= 1;
617 loopbit = loops_per_sec;
618 while ( lps_precision-- && (loopbit >>= 1) ) {
619 loops_per_sec |= loopbit;
620 ticks = jiffies;
621 while (ticks == jiffies);
622 ticks = jiffies;
623 __delay(loops_per_sec);
624 if (jiffies != ticks) /* longer than 1 tick */
625 loops_per_sec &= ~loopbit;
628 /* finally, adjust loops per second in terms of seconds instead of clocks */
629 loops_per_sec *= HZ;
630 /* Round the value and print it */
631 printk("ok - %lu.%02lu BogoMIPS\n",
632 (loops_per_sec+2500)/500000,
633 ((loops_per_sec+2500)/5000) % 100);
636 __initfunc(static void parse_root_dev(char * line))
638 int base = 0;
639 static struct dev_name_struct {
640 const char *name;
641 const int num;
642 } devices[] = {
643 { "nfs", 0x00ff },
644 { "hda", 0x0300 },
645 { "hdb", 0x0340 },
646 { "hdc", 0x1600 },
647 { "hdd", 0x1640 },
648 { "sda", 0x0800 },
649 { "sdb", 0x0810 },
650 { "sdc", 0x0820 },
651 { "sdd", 0x0830 },
652 { "sde", 0x0840 },
653 { "ada", 0x1c00 },
654 { "adb", 0x1c10 },
655 { "adc", 0x1c20 },
656 { "add", 0x1c30 },
657 { "ade", 0x1c40 },
658 { "fd", 0x0200 },
659 { "xda", 0x0d00 },
660 { "xdb", 0x0d40 },
661 { "ram", 0x0100 },
662 { "scd", 0x0b00 },
663 { "mcd", 0x1700 },
664 { "cdu535", 0x1800 },
665 { "aztcd", 0x1d00 },
666 { "cm206cd", 0x2000 },
667 { "gscd", 0x1000 },
668 { "sbpcd", 0x1900 },
669 { "sonycd", 0x1800 },
670 { "eda", 0x2400 },
671 { "eza", 0x2800 },
672 { "bpcd", 0x2900 },
673 #if CONFIG_APBLOCK
674 { "apblock", APBLOCK_MAJOR << 8},
675 #endif
676 #if CONFIG_DDV
677 { "ddv", DDV_MAJOR << 8},
678 #endif
679 { NULL, 0 }
682 if (strncmp(line,"/dev/",5) == 0) {
683 struct dev_name_struct *dev = devices;
684 line += 5;
685 do {
686 int len = strlen(dev->name);
687 if (strncmp(line,dev->name,len) == 0) {
688 line += len;
689 base = dev->num;
690 break;
692 dev++;
693 } while (dev->name);
695 ROOT_DEV = to_kdev_t(base + simple_strtoul(line,NULL,base?10:16));
699 * This is a simple kernel command line parsing function: it parses
700 * the command line, and fills in the arguments/environment to init
701 * as appropriate. Any cmd-line option is taken to be an environment
702 * variable if it contains the character '='.
705 * This routine also checks for options meant for the kernel.
706 * These options are not given to init - they are for internal kernel use only.
708 __initfunc(static void parse_options(char *line))
710 char *next;
711 int args, envs;
713 if (!*line)
714 return;
715 args = 0;
716 envs = 1; /* TERM is set to 'linux' by default */
717 next = line;
718 while ((line = next) != NULL) {
719 if ((next = strchr(line,' ')) != NULL)
720 *next++ = 0;
722 * check for kernel options first..
724 if (!strncmp(line,"root=",5)) {
725 parse_root_dev(line+5);
726 continue;
728 #ifdef CONFIG_ROOT_NFS
729 if (!strncmp(line, "nfsroot=", 8)) {
730 int n;
731 line += 8;
732 ROOT_DEV = MKDEV(UNNAMED_MAJOR, 255);
733 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) {
734 strncpy(nfs_root_name, line, sizeof(nfs_root_name));
735 nfs_root_name[sizeof(nfs_root_name)-1] = '\0';
736 continue;
738 n = strlen(line) + strlen(NFS_ROOT);
739 if (n >= sizeof(nfs_root_name))
740 line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
741 sprintf(nfs_root_name, NFS_ROOT, line);
742 continue;
744 if (!strncmp(line, "nfsaddrs=", 9)) {
745 line += 9;
746 strncpy(nfs_root_addrs, line, sizeof(nfs_root_addrs));
747 nfs_root_addrs[sizeof(nfs_root_addrs)-1] = '\0';
748 continue;
750 #endif
751 if (!strcmp(line,"ro")) {
752 root_mountflags |= MS_RDONLY;
753 continue;
755 if (!strcmp(line,"rw")) {
756 root_mountflags &= ~MS_RDONLY;
757 continue;
759 if (!strcmp(line,"debug")) {
760 console_loglevel = 10;
761 continue;
763 if (!strncmp(line,"init=",5)) {
764 line += 5;
765 execute_command = line;
766 /* In case LILO is going to boot us with default command line,
767 * it prepends "auto" before the whole cmdline which makes
768 * the shell think it should execute a script with such name.
769 * So we ignore all arguments entered _before_ init=... [MJ]
771 args = 0;
772 continue;
774 if (checksetup(line))
775 continue;
778 * Then check if it's an environment variable or
779 * an option.
781 if (strchr(line,'=')) {
782 if (envs >= MAX_INIT_ENVS)
783 break;
784 envp_init[++envs] = line;
785 } else {
786 if (args >= MAX_INIT_ARGS)
787 break;
788 argv_init[++args] = line;
791 argv_init[args+1] = NULL;
792 envp_init[envs+1] = NULL;
796 extern void setup_arch(char **, unsigned long *, unsigned long *);
798 #ifndef __SMP__
801 * Uniprocessor idle thread
804 int cpu_idle(void *unused)
806 for(;;)
807 idle();
810 #else
813 * Multiprocessor idle thread is in arch/...
816 extern int cpu_idle(void * unused);
818 /* Called by boot processor to activate the rest. */
819 __initfunc(static void smp_init(void))
821 /* Get other processors into their bootup holding patterns. */
822 smp_boot_cpus();
826 * The autoprobe routines assume CPU#0 on the i386
827 * so we don't actually set the game in motion until
828 * they are finished.
831 __initfunc(static void smp_begin(void))
833 smp_threads_ready=1;
834 smp_commence();
837 #endif
839 extern void initialize_secondary(void);
842 * Activate the first processor.
845 __initfunc(asmlinkage void start_kernel(void))
847 char * command_line;
849 #ifdef __SMP__
850 static int boot_cpu = 1;
851 /* "current" has been set up, we need to load it now */
852 if (!boot_cpu)
853 initialize_secondary();
854 boot_cpu = 0;
855 #endif
858 * Interrupts are still disabled. Do necessary setups, then
859 * enable them
861 setup_arch(&command_line, &memory_start, &memory_end);
862 memory_start = paging_init(memory_start,memory_end);
863 trap_init();
864 init_IRQ();
865 sched_init();
866 time_init();
867 parse_options(command_line);
868 #ifdef CONFIG_MODULES
869 init_modules();
870 #endif
871 #ifdef CONFIG_PROFILE
872 if (!prof_shift)
873 #ifdef CONFIG_PROFILE_SHIFT
874 prof_shift = CONFIG_PROFILE_SHIFT;
875 #else
876 prof_shift = 2;
877 #endif
878 #endif
879 if (prof_shift) {
880 prof_buffer = (unsigned int *) memory_start;
881 /* only text is profiled */
882 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
883 prof_len >>= prof_shift;
884 memory_start += prof_len * sizeof(unsigned int);
885 memset(prof_buffer, 0, prof_len * sizeof(unsigned int));
887 #ifdef CONFIG_SBUS
888 memory_start = sbus_init(memory_start,memory_end);
889 #endif
890 memory_start = console_init(memory_start,memory_end);
891 #ifdef CONFIG_REMOTE_DEBUG
892 set_debug_traps();
893 /* breakpoint(); */ /* execute a BREAK insn */
894 #endif
895 #ifdef CONFIG_PCI
896 memory_start = pci_init(memory_start,memory_end);
897 #endif
898 #ifdef CONFIG_MCA
899 memory_start = mca_init(memory_start,memory_end);
900 #endif
901 memory_start = kmem_cache_init(memory_start, memory_end);
902 sti();
903 calibrate_delay();
904 #ifdef CONFIG_BLK_DEV_INITRD
905 if (initrd_start && !initrd_below_start_ok && initrd_start < memory_start) {
906 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
907 "disabling it.\n",initrd_start,memory_start);
908 initrd_start = 0;
910 #endif
911 mem_init(memory_start,memory_end);
912 kmem_cache_sizes_init();
913 #ifdef CONFIG_PROC_FS
914 proc_root_init();
915 #endif
916 uidcache_init();
917 filescache_init();
918 dcache_init();
919 vma_init();
920 buffer_init();
921 inode_init();
922 file_table_init();
923 sock_init();
924 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
925 ipc_init();
926 #endif
927 dquot_init();
928 sti();
929 check_bugs();
931 printk(linux_banner);
932 printk("POSIX conformance testing by UNIFIX\n");
933 #ifdef __SMP__
934 smp_init();
935 #endif
936 #ifdef CONFIG_SYSCTL
937 sysctl_init();
938 #endif
940 * We count on the initial thread going ok
941 * Like idlers init is an unlocked kernel thread, which will
942 * make syscalls (and thus be locked).
944 kernel_thread(init, NULL, 0);
946 * task[0] is meant to be used as an "idle" task: it may not sleep, but
947 * it might do some general things like count free pages or it could be
948 * used to implement a reasonable LRU algorithm for the paging routines:
949 * anything that can be useful, but shouldn't take time from the real
950 * processes.
952 * Right now task[0] just does an infinite idle loop.
954 cpu_idle(NULL);
957 #ifdef CONFIG_BLK_DEV_INITRD
958 static int do_linuxrc(void * shell)
960 static char *argv[] = { "linuxrc", NULL, };
962 close(0);close(1);close(2);
963 setsid();
964 (void) open("/dev/tty1",O_RDWR,0);
965 (void) dup(0);
966 (void) dup(0);
967 return execve(shell, argv, envp_init);
970 __initfunc(static void no_initrd(char *s,int *ints))
972 mount_initrd = 0;
974 #endif
976 static int init(void * unused)
978 #ifdef CONFIG_BLK_DEV_INITRD
979 int real_root_mountflags;
980 #endif
982 /* Launch bdflush from here, instead of the old syscall way. */
983 kernel_thread(bdflush, NULL, 0);
984 /* Start the background pageout daemon. */
985 kswapd_setup();
986 kernel_thread(kswapd, NULL, 0);
988 #if CONFIG_AP1000
989 /* Start the async paging daemon. */
991 extern int asyncd(void *);
992 kernel_thread(asyncd, NULL, 0);
994 #endif
996 #ifdef CONFIG_BLK_DEV_INITRD
997 real_root_dev = ROOT_DEV;
998 real_root_mountflags = root_mountflags;
999 if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
1000 else mount_initrd =0;
1001 #endif
1002 setup(0);
1004 #ifdef __SMP__
1006 * With the devices probed and setup we can
1007 * now enter SMP mode.
1010 smp_begin();
1011 #endif
1013 #ifdef CONFIG_UMSDOS_FS
1016 When mounting a umsdos fs as root, we detect
1017 the pseudo_root (/linux) and initialise it here.
1018 pseudo_root is defined in fs/umsdos/inode.c
1020 extern struct inode *pseudo_root;
1021 if (pseudo_root != NULL){
1022 current->fs->root = pseudo_root;
1023 current->fs->pwd = pseudo_root;
1026 #endif
1028 #ifdef CONFIG_BLK_DEV_INITRD
1029 root_mountflags = real_root_mountflags;
1030 if (mount_initrd && ROOT_DEV != real_root_dev && ROOT_DEV == MKDEV(RAMDISK_MAJOR,0)) {
1031 int error;
1032 int i, pid;
1034 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
1035 if (pid>0)
1036 while (pid != wait(&i));
1037 if (real_root_dev != MKDEV(RAMDISK_MAJOR, 0)) {
1038 error = change_root(real_root_dev,"/initrd");
1039 if (error)
1040 printk(KERN_ERR "Change root to /initrd: "
1041 "error %d\n",error);
1044 #endif
1046 setup(1);
1048 if (open("/dev/console",O_RDWR,0) < 0)
1049 printk("Unable to open an initial console.\n");
1051 (void) dup(0);
1052 (void) dup(0);
1055 * We try each of these until one succeeds.
1057 * The Bourne shell can be used instead of init if we are
1058 * trying to recover a really broken machine.
1061 if(execute_command)
1062 execve(execute_command,argv_init,envp_init);
1063 execve("/sbin/init",argv_init,envp_init);
1064 execve("/etc/init",argv_init,envp_init);
1065 execve("/bin/init",argv_init,envp_init);
1066 execve("/bin/sh",argv_init,envp_init);
1067 panic("No init found. Try passing init= option to kernel.");