1
2
3
4
5
6
7
8
9
10
11
12#define __KERNEL_SYSCALLS__
13
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
39
40#include <asm/system.h>
41#include <asm/io.h>
42#include <asm/bugs.h>
43
44#include <stdarg.h>
45
46
47
48
49
50
51
52
53#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
54#error sorry, your GCC is too old. It builds incorrect kernels.
55#endif
56
57extern char _stext, _etext;
58extern char *linux_banner;
59
60extern int console_loglevel;
61
62static int init(void *);
63extern int bdflush(void *);
64extern int kswapd(void *);
65extern void kswapd_setup(void);
66
67extern void init_IRQ(void);
68extern void init_modules(void);
69extern long console_init(long, long);
70extern void sock_init(void);
71extern void uidcache_init(void);
72extern unsigned long pci_init(unsigned long, unsigned long);
73extern long mca_init(long, long);
74extern long sbus_init(long, long);
75extern long powermac_init(unsigned long, unsigned long);
76extern void sysctl_init(void);
77extern void filescache_init(void);
78
79extern void smp_setup(char *str, int *ints);
80extern void no_scroll(char *str, int *ints);
81extern void swap_setup(char *str, int *ints);
82extern void buff_setup(char *str, int *ints);
83extern void panic_setup(char *str, int *ints);
84extern void bmouse_setup(char *str, int *ints);
85extern void msmouse_setup(char *str, int *ints);
86#ifdef CONFIG_PRINTER
87extern void lp_setup(char *str, int *ints);
88#endif
89extern void eth_setup(char *str, int *ints);
90#ifdef CONFIG_ARCNET_COM20020
91extern void com20020_setup(char *str, int *ints);
92#endif
93#ifdef CONFIG_ARCNET_RIM_I
94extern void arcrimi_setup(char *str, int *ints);
95#endif
96#ifdef CONFIG_ARCNET_COM90xxIO
97extern void com90io_setup(char *str, int *ints);
98#endif
99#ifdef CONFIG_ARCNET_COM90xx
100extern void com90xx_setup(char *str, int *ints);
101#endif
102#ifdef CONFIG_DECNET
103extern void decnet_setup(char *str, int *ints);
104#endif
105extern void xd_setup(char *str, int *ints);
106#ifdef CONFIG_BLK_DEV_EZ
107extern void ez_setup(char *str, int *ints);
108#endif
109extern void floppy_setup(char *str, int *ints);
110extern void st_setup(char *str, int *ints);
111extern void st0x_setup(char *str, int *ints);
112extern void advansys_setup(char *str, int *ints);
113extern void tmc8xx_setup(char *str, int *ints);
114extern void t128_setup(char *str, int *ints);
115extern void pas16_setup(char *str, int *ints);
116extern void generic_NCR5380_setup(char *str, int *intr);
117extern void generic_NCR53C400_setup(char *str, int *intr);
118extern void aha152x_setup(char *str, int *ints);
119extern void aha1542_setup(char *str, int *ints);
120extern void aic7xxx_setup(char *str, int *ints);
121extern void AM53C974_setup(char *str, int *ints);
122extern void BusLogic_Setup(char *str, int *ints);
123extern void ncr53c8xx_setup(char *str, int *ints);
124extern void eata2x_setup(char *str, int *ints);
125extern void u14_34f_setup(char *str, int *ints);
126extern void fdomain_setup(char *str, int *ints);
127extern void ibmmca_scsi_setup(char *str, int *ints);
128extern void in2000_setup(char *str, int *ints);
129extern void NCR53c406a_setup(char *str, int *ints);
130extern void wd7000_setup(char *str, int *ints);
131#ifdef NOTDEF
132extern void ppa_setup(char *str, int *ints);
133#endif
134extern void scsi_luns_setup(char *str, int *ints);
135extern void sound_setup(char *str, int *ints);
136extern void reboot_setup(char *str, int *ints);
137extern void video_setup(char *str, int *ints);
138#ifdef CONFIG_CDU31A
139extern void cdu31a_setup(char *str, int *ints);
140#endif CONFIG_CDU31A
141#ifdef CONFIG_BLK_DEV_PS2
142extern void ed_setup(char *str, int *ints);
143extern void tp720_setup(char *str, int *ints);
144#endif CONFIG_BLK_DEV_PS2
145#ifdef CONFIG_MCD
146extern void mcd_setup(char *str, int *ints);
147#endif CONFIG_MCD
148#ifdef CONFIG_MCDX
149extern void mcdx_setup(char *str, int *ints);
150#endif CONFIG_MCDX
151#ifdef CONFIG_SBPCD
152extern void sbpcd_setup(char *str, int *ints);
153#endif CONFIG_SBPCD
154#ifdef CONFIG_AZTCD
155extern void aztcd_setup(char *str, int *ints);
156#endif CONFIG_AZTCD
157#ifdef CONFIG_CDU535
158extern void sonycd535_setup(char *str, int *ints);
159#endif CONFIG_CDU535
160#ifdef CONFIG_GSCD
161extern void gscd_setup(char *str, int *ints);
162#endif CONFIG_GSCD
163#ifdef CONFIG_BPCD
164extern void bpcd_setup(char *str, int *ints);
165#endif CONFIG_BPCD
166#ifdef CONFIG_CM206
167extern void cm206_setup(char *str, int *ints);
168#endif CONFIG_CM206
169#ifdef CONFIG_OPTCD
170extern void optcd_setup(char *str, int *ints);
171#endif CONFIG_OPTCD
172#ifdef CONFIG_SJCD
173extern void sjcd_setup(char *str, int *ints);
174#endif CONFIG_SJCD
175#ifdef CONFIG_ISP16_CDI
176extern void isp16_setup(char *str, int *ints);
177#endif CONFIG_ISP16_CDI
178#ifdef CONFIG_BLK_DEV_RAM
179static void ramdisk_start_setup(char *str, int *ints);
180static void load_ramdisk(char *str, int *ints);
181static void prompt_ramdisk(char *str, int *ints);
182static void ramdisk_size(char *str, int *ints);
183#ifdef CONFIG_BLK_DEV_INITRD
184static void no_initrd(char *s,int *ints);
185#endif
186#endif CONFIG_BLK_DEV_RAM
187#ifdef CONFIG_ISDN_DRV_ICN
188extern void icn_setup(char *str, int *ints);
189#endif
190#ifdef CONFIG_ISDN_DRV_HISAX
191extern void HiSax_setup(char *str, int *ints);
192#endif
193#ifdef CONFIG_DIGIEPCA
194extern void epca_setup(char *str, int *ints);
195#endif
196#ifdef CONFIG_ISDN_DRV_PCBIT
197extern void pcbit_setup(char *str, int *ints);
198#endif
199
200#ifdef CONFIG_ATARIMOUSE
201extern void atari_mouse_setup (char *str, int *ints);
202#endif
203#ifdef CONFIG_DMASOUND
204extern void dmasound_setup (char *str, int *ints);
205#endif
206#ifdef CONFIG_ATARI_SCSI
207extern void atari_scsi_setup (char *str, int *ints);
208#endif
209extern void wd33c93_setup (char *str, int *ints);
210extern void gvp11_setup (char *str, int *ints);
211extern void ncr53c7xx_setup (char *str, int *ints);
212
213#ifdef CONFIG_CYCLADES
214extern void cy_setup(char *str, int *ints);
215#endif
216#ifdef CONFIG_DIGI
217extern void pcxx_setup(char *str, int *ints);
218#endif
219#ifdef CONFIG_RISCOM8
220extern void riscom8_setup(char *str, int *ints);
221#endif
222#ifdef CONFIG_BAYCOM
223extern void baycom_setup(char *str, int *ints);
224#endif
225#ifdef CONFIG_SOUNDMODEM
226extern void sm_setup(char *str, int *ints);
227#endif
228#ifdef CONFIG_PMAC_CONSOLE
229extern void pmac_cons_setup(char *str, int *ints);
230extern void pmac_vmode_setup(char *str, int *ints);
231#endif
232#ifdef CONFIG_WDT
233extern void wdt_setup(char *str, int *ints);
234#endif
235#ifdef CONFIG_PARPORT
236extern void parport_setup(char *str, int *ints);
237#endif
238#ifdef CONFIG_PLIP
239extern void plip_setup(char *str, int *ints);
240#endif
241#ifdef CONFIG_HFMODEM
242extern void hfmodem_setup(char *str, int *ints);
243#endif
244
245#if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
246extern void ipc_init(void);
247#endif
248
249#ifdef __sparc__
250extern int serial_console;
251#endif
252
253
254
255
256#define MAX_INIT_ARGS 8
257#define MAX_INIT_ENVS 8
258
259extern void time_init(void);
260
261static unsigned long memory_start = 0;
262static unsigned long memory_end = 0;
263
264int rows, cols;
265
266#ifdef CONFIG_BLK_DEV_RAM
267extern int rd_doload;
268extern int rd_prompt;
269extern int rd_size;
270extern int rd_image_start;
271#ifdef CONFIG_BLK_DEV_INITRD
272kdev_t real_root_dev;
273#endif
274#endif
275
276int root_mountflags = MS_RDONLY;
277char *execute_command = NULL;
278
279#ifdef CONFIG_ROOT_NFS
280char nfs_root_name[NFS_ROOT_NAME_LEN] = { "default" };
281char nfs_root_addrs[NFS_ROOT_ADDRS_LEN] = { "" };
282#endif
283
284extern void dquot_init(void);
285
286static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
287static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
288
289char *get_options(char *str, int *ints)
290{
291 char *cur = str;
292 int i=1;
293
294 while (cur && isdigit(*cur) && i <= 10) {
295 ints[i++] = simple_strtoul(cur,NULL,0);
296 if ((cur = strchr(cur,',')) != NULL)
297 cur++;
298 }
299 ints[0] = i-1;
300 return(cur);
301}
302
303__initfunc(static void profile_setup(char *str, int *ints))
304{
305 if (ints[0] > 0)
306 prof_shift = (unsigned long) ints[1];
307 else
308#ifdef CONFIG_PROFILE_SHIFT
309 prof_shift = CONFIG_PROFILE_SHIFT;
310#else
311 prof_shift = 2;
312#endif
313}
314
315struct {
316 const char *str;
317 void (*setup_func)(char *, int *);
318} bootsetups[] __initdata = {
319 { "reserve=", reserve_setup },
320 { "profile=", profile_setup },
321#ifdef __SMP__
322 { "nosmp", smp_setup },
323 { "maxcpus=", smp_setup },
324#endif
325#ifdef CONFIG_BLK_DEV_RAM
326 { "ramdisk_start=", ramdisk_start_setup },
327 { "load_ramdisk=", load_ramdisk },
328 { "prompt_ramdisk=", prompt_ramdisk },
329 { "ramdisk=", ramdisk_size },
330 { "ramdisk_size=", ramdisk_size },
331#ifdef CONFIG_BLK_DEV_INITRD
332 { "noinitrd", no_initrd },
333#endif
334#endif
335#if defined (CONFIG_AMIGA) || defined (CONFIG_ATARI)
336 { "video=", video_setup },
337#endif
338 { "swap=", swap_setup },
339 { "buff=", buff_setup },
340 { "panic=", panic_setup },
341#ifdef CONFIG_VT
342 { "no-scroll", no_scroll },
343#endif
344#ifdef CONFIG_BUGi386
345 { "no-hlt", no_halt },
346 { "no387", no_387 },
347 { "reboot=", reboot_setup },
348#endif
349#ifdef CONFIG_INET
350 { "ether=", eth_setup },
351#endif
352#ifdef CONFIG_ARCNET_COM20020
353 { "com20020=", com20020_setup },
354#endif
355#ifdef CONFIG_ARCNET_RIM_I
356 { "arcrimi=", arcrimi_setup },
357#endif
358#ifdef CONFIG_ARCNET_COM90xxIO
359 { "com90io=", com90io_setup },
360#endif
361#ifdef CONFIG_ARCNET_COM90xx
362 { "com90xx=", com90xx_setup },
363#endif
364#ifdef CONFIG_DECNET
365 { "decnet=", decnet_setup },
366#endif
367#ifdef CONFIG_PRINTER
368 { "lp=", lp_setup },
369#endif
370#ifdef CONFIG_SCSI
371 { "max_scsi_luns=", scsi_luns_setup },
372#endif
373#ifdef CONFIG_SCSI_ADVANSYS
374 { "advansys=", advansys_setup },
375#endif
376#if defined(CONFIG_BLK_DEV_HD)
377 { "hd=", hd_setup },
378#endif
379#ifdef CONFIG_CHR_DEV_ST
380 { "st=", st_setup },
381#endif
382#ifdef CONFIG_BUSMOUSE
383 { "bmouse=", bmouse_setup },
384#endif
385#ifdef CONFIG_MS_BUSMOUSE
386 { "msmouse=", msmouse_setup },
387#endif
388#ifdef CONFIG_SCSI_SEAGATE
389 { "st0x=", st0x_setup },
390 { "tmc8xx=", tmc8xx_setup },
391#endif
392#ifdef CONFIG_SCSI_T128
393 { "t128=", t128_setup },
394#endif
395#ifdef CONFIG_SCSI_PAS16
396 { "pas16=", pas16_setup },
397#endif
398#ifdef CONFIG_SCSI_GENERIC_NCR5380
399 { "ncr5380=", generic_NCR5380_setup },
400 { "ncr53c400=", generic_NCR53C400_setup },
401#endif
402#ifdef CONFIG_SCSI_AHA152X
403 { "aha152x=", aha152x_setup},
404#endif
405#ifdef CONFIG_SCSI_AHA1542
406 { "aha1542=", aha1542_setup},
407#endif
408#ifdef CONFIG_SCSI_AIC7XXX
409 { "aic7xxx=", aic7xxx_setup},
410#endif
411#ifdef CONFIG_SCSI_BUSLOGIC
412 { "BusLogic=", BusLogic_Setup},
413#endif
414#ifdef CONFIG_SCSI_NCR53C8XX
415 { "ncr53c8xx=", ncr53c8xx_setup},
416#endif
417#ifdef CONFIG_SCSI_EATA
418 { "eata=", eata2x_setup},
419#endif
420#ifdef CONFIG_SCSI_U14_34F
421 { "u14-34f=", u14_34f_setup},
422#endif
423#ifdef CONFIG_SCSI_AM53C974
424 { "AM53C974=", AM53C974_setup},
425#endif
426#ifdef CONFIG_SCSI_NCR53C406A
427 { "ncr53c406a=", NCR53c406a_setup},
428#endif
429#ifdef CONFIG_SCSI_FUTURE_DOMAIN
430 { "fdomain=", fdomain_setup},
431#endif
432#ifdef CONFIG_SCSI_IN2000
433 { "in2000=", in2000_setup},
434#endif
435#ifdef CONFIG_SCSI_7000FASST
436 { "wd7000=", wd7000_setup},
437#endif
438#ifdef NOTDEF
439 { "ppa=", ppa_setup },
440#endif
441#ifdef CONFIG_SCSI_IBMMCA
442 { "ibmmcascsi=", ibmmca_scsi_setup },
443#endif
444#ifdef CONFIG_BLK_DEV_XD
445 { "xd=", xd_setup },
446#endif
447#ifdef CONFIG_BLK_DEV_EZ
448 { "ez=", ez_setup },
449#endif
450#ifdef CONFIG_BLK_DEV_FD
451 { "floppy=", floppy_setup },
452#endif
453#ifdef CONFIG_BLK_DEV_PS2
454 { "ed=", ed_setup },
455 { "tp720=", tp720_setup },
456#endif
457#ifdef CONFIG_CDU31A
458 { "cdu31a=", cdu31a_setup },
459#endif CONFIG_CDU31A
460#ifdef CONFIG_MCD
461 { "mcd=", mcd_setup },
462#endif CONFIG_MCD
463#ifdef CONFIG_MCDX
464 { "mcdx=", mcdx_setup },
465#endif CONFIG_MCDX
466#ifdef CONFIG_SBPCD
467 { "sbpcd=", sbpcd_setup },
468#endif CONFIG_SBPCD
469#ifdef CONFIG_AZTCD
470 { "aztcd=", aztcd_setup },
471#endif CONFIG_AZTCD
472#ifdef CONFIG_CDU535
473 { "sonycd535=", sonycd535_setup },
474#endif CONFIG_CDU535
475#ifdef CONFIG_GSCD
476 { "gscd=", gscd_setup },
477#endif CONFIG_GSCD
478#ifdef CONFIG_BPCD
479 { "bpcd=", bpcd_setup },
480#endif CONFIG_BPCD
481#ifdef CONFIG_CM206
482 { "cm206=", cm206_setup },
483#endif CONFIG_CM206
484#ifdef CONFIG_OPTCD
485 { "optcd=", optcd_setup },
486#endif CONFIG_OPTCD
487#ifdef CONFIG_SJCD
488 { "sjcd=", sjcd_setup },
489#endif CONFIG_SJCD
490#ifdef CONFIG_ISP16_CDI
491 { "isp16=", isp16_setup },
492#endif CONFIG_ISP16_CDI
493#ifdef CONFIG_SOUND
494 { "sound=", sound_setup },
495#endif
496#ifdef CONFIG_ISDN_DRV_ICN
497 { "icn=", icn_setup },
498#endif
499#ifdef CONFIG_ISDN_DRV_HISAX
500 { "hisax=", HiSax_setup },
501 { "HiSax=", HiSax_setup },
502#endif
503#ifdef CONFIG_ISDN_DRV_PCBIT
504 { "pcbit=", pcbit_setup },
505#endif
506#ifdef CONFIG_ATARIMOUSE
507 { "atamouse=", atari_mouse_setup },
508#endif
509#ifdef CONFIG_DMASOUND
510 { "dmasound=", dmasound_setup },
511#endif
512#ifdef CONFIG_ATARI_SCSI
513 { "atascsi=", atari_scsi_setup },
514#endif
515#if defined(CONFIG_A4000T_SCSI) || defined(CONFIG_WARPENGINE_SCSI) || defined(CONFIG_A4091_SCSI)
516 { "53c7xx=", ncr53c7xx_setup },
517#endif
518#if defined(CONFIG_A3000_SCSI) || defined(CONFIG_A2091_SCSI) \
519 || defined(CONFIG_GVP11_SCSI)
520 { "wd33c93=", wd33c93_setup },
521#endif
522#if defined(CONFIG_GVP11_SCSI)
523 { "gvp11=", gvp11_setup },
524#endif
525#ifdef CONFIG_CYCLADES
526 { "cyclades=", cy_setup },
527#endif
528#ifdef CONFIG_DIGI
529 { "digi=", pcxx_setup },
530#endif
531#ifdef CONFIG_DIGIEPCA
532 { "digiepca=", epca_setup },
533#endif
534#ifdef CONFIG_RISCOM8
535 { "riscom8=", riscom8_setup },
536#endif
537#ifdef CONFIG_BAYCOM
538 { "baycom=", baycom_setup },
539#endif
540#ifdef CONFIG_SOUNDMODEM
541 { "soundmodem=", sm_setup },
542#endif
543#ifdef CONFIG_WDT
544 { "wdt=", wdt_setup },
545#endif
546#ifdef CONFIG_PARPORT
547 { "parport=", parport_setup },
548#endif
549#ifdef CONFIG_PLIP
550 { "plip=", plip_setup },
551#endif
552#ifdef CONFIG_SOUNDMODEM
553 { "hfmodem=", hfmodem_setup },
554#endif
555#ifdef CONFIG_PMAC_CONSOLE
556 { "console=", pmac_cons_setup },
557 { "vmode=", pmac_vmode_setup },
558#endif
559 { 0, 0 }
560};
561
562#ifdef CONFIG_BLK_DEV_RAM
563__initfunc(static void ramdisk_start_setup(char *str, int *ints))
564{
565 if (ints[0] > 0 && ints[1] >= 0)
566 rd_image_start = ints[1];
567}
568
569__initfunc(static void load_ramdisk(char *str, int *ints))
570{
571 if (ints[0] > 0 && ints[1] >= 0)
572 rd_doload = ints[1] & 1;
573}
574
575__initfunc(static void prompt_ramdisk(char *str, int *ints))
576{
577 if (ints[0] > 0 && ints[1] >= 0)
578 rd_prompt = ints[1] & 1;
579}
580
581__initfunc(static void ramdisk_size(char *str, int *ints))
582{
583 if (ints[0] > 0 && ints[1] >= 0)
584 rd_size = ints[1];
585}
586
587#endif
588
589__initfunc(static int checksetup(char *line))
590{
591 int i = 0;
592 int ints[11];
593
594#ifdef CONFIG_BLK_DEV_IDE
595
596 if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {
597 ide_setup(line);
598 return 1;
599 }
600#endif
601 while (bootsetups[i].str) {
602 int n = strlen(bootsetups[i].str);
603 if (!strncmp(line,bootsetups[i].str,n)) {
604 bootsetups[i].setup_func(get_options(line+n,ints), ints);
605 return 1;
606 }
607 i++;
608 }
609 return 0;
610}
611
612
613
614unsigned long loops_per_sec = (1<<12);
615
616
617
618
619#define LPS_PREC 8
620
621__initfunc(void calibrate_delay(void))
622{
623 unsigned long ticks, loopbit;
624 int lps_precision = LPS_PREC;
625
626 loops_per_sec = (1<<12);
627
628 printk("Calibrating delay loop.. ");
629 while (loops_per_sec <<= 1) {
630
631 ticks = jiffies;
632 while (ticks == jiffies)
633 ;
634
635 ticks = jiffies;
636 __delay(loops_per_sec);
637 ticks = jiffies - ticks;
638 if (ticks)
639 break;
640 }
641
642
643
644 loops_per_sec >>= 1;
645 loopbit = loops_per_sec;
646 while ( lps_precision-- && (loopbit >>= 1) ) {
647 loops_per_sec |= loopbit;
648 ticks = jiffies;
649 while (ticks == jiffies);
650 ticks = jiffies;
651 __delay(loops_per_sec);
652 if (jiffies != ticks)
653 loops_per_sec &= ~loopbit;
654 }
655
656
657 loops_per_sec *= HZ;
658
659 printk("ok - %lu.%02lu BogoMIPS\n",
660 (loops_per_sec+2500)/500000,
661 ((loops_per_sec+2500)/5000) % 100);
662}
663
664__initfunc(static void parse_root_dev(char * line))
665{
666 int base = 0;
667 static struct dev_name_struct {
668 const char *name;
669 const int num;
670 } devices[] = {
671 { "nfs", 0x00ff },
672 { "hda", 0x0300 },
673 { "hdb", 0x0340 },
674 { "hdc", 0x1600 },
675 { "hdd", 0x1640 },
676 { "sda", 0x0800 },
677 { "sdb", 0x0810 },
678 { "sdc", 0x0820 },
679 { "sdd", 0x0830 },
680 { "sde", 0x0840 },
681 { "ada", 0x1c00 },
682 { "adb", 0x1c10 },
683 { "adc", 0x1c20 },
684 { "add", 0x1c30 },
685 { "ade", 0x1c40 },
686 { "fd", 0x0200 },
687 { "xda", 0x0d00 },
688 { "xdb", 0x0d40 },
689 { "ram", 0x0100 },
690 { "scd", 0x0b00 },
691 { "mcd", 0x1700 },
692 { "cdu535", 0x1800 },
693 { "aztcd", 0x1d00 },
694 { "cm206cd", 0x2000 },
695 { "gscd", 0x1000 },
696 { "sbpcd", 0x1900 },
697 { "sonycd", 0x1800 },
698 { "eda", 0x2400 },
699 { "eza", 0x2800 },
700 { "bpcd", 0x2900 },
701#if CONFIG_APBLOCK
702 { "apblock", APBLOCK_MAJOR << 8},
703#endif
704#if CONFIG_DDV
705 { "ddv", DDV_MAJOR << 8},
706#endif
707 { NULL, 0 }
708 };
709
710 if (strncmp(line,"/dev/",5) == 0) {
711 struct dev_name_struct *dev = devices;
712 line += 5;
713 do {
714 int len = strlen(dev->name);
715 if (strncmp(line,dev->name,len) == 0) {
716 line += len;
717 base = dev->num;
718 break;
719 }
720 dev++;
721 } while (dev->name);
722 }
723 ROOT_DEV = to_kdev_t(base + simple_strtoul(line,NULL,base?10:16));
724}
725
726
727
728
729
730
731
732
733
734
735
736__initfunc(static void parse_options(char *line))
737{
738 char *next;
739 int args, envs;
740
741 if (!*line)
742 return;
743 args = 0;
744 envs = 1;
745 next = line;
746 while ((line = next) != NULL) {
747 if ((next = strchr(line,' ')) != NULL)
748 *next++ = 0;
749
750
751
752 if (!strncmp(line,"root=",5)) {
753 parse_root_dev(line+5);
754 continue;
755 }
756#ifdef CONFIG_ROOT_NFS
757 if (!strncmp(line, "nfsroot=", 8)) {
758 int n;
759 line += 8;
760 ROOT_DEV = MKDEV(UNNAMED_MAJOR, 255);
761 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) {
762 strncpy(nfs_root_name, line, sizeof(nfs_root_name));
763 nfs_root_name[sizeof(nfs_root_name)-1] = '\0';
764 continue;
765 }
766 n = strlen(line) + strlen(NFS_ROOT);
767 if (n >= sizeof(nfs_root_name))
768 line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
769 sprintf(nfs_root_name, NFS_ROOT, line);
770 continue;
771 }
772 if (!strncmp(line, "nfsaddrs=", 9)) {
773 line += 9;
774 strncpy(nfs_root_addrs, line, sizeof(nfs_root_addrs));
775 nfs_root_addrs[sizeof(nfs_root_addrs)-1] = '\0';
776 continue;
777 }
778#endif
779 if (!strcmp(line,"ro")) {
780 root_mountflags |= MS_RDONLY;
781 continue;
782 }
783 if (!strcmp(line,"rw")) {
784 root_mountflags &= ~MS_RDONLY;
785 continue;
786 }
787 if (!strcmp(line,"debug")) {
788 console_loglevel = 10;
789 continue;
790 }
791 if (!strncmp(line,"init=",5)) {
792 line += 5;
793 execute_command = line;
794
795
796
797
798
799 args = 0;
800 continue;
801 }
802 if (checksetup(line))
803 continue;
804
805
806
807
808
809 if (strchr(line,'=')) {
810 if (envs >= MAX_INIT_ENVS)
811 break;
812 envp_init[++envs] = line;
813 } else {
814 if (args >= MAX_INIT_ARGS)
815 break;
816 argv_init[++args] = line;
817 }
818 }
819 argv_init[args+1] = NULL;
820 envp_init[envs+1] = NULL;
821}
822
823
824extern void setup_arch(char **, unsigned long *, unsigned long *);
825
826#ifndef __SMP__
827
828
829
830
831
832int cpu_idle(void *unused)
833{
834 for(;;)
835 idle();
836}
837
838#else
839
840
841
842
843
844extern int cpu_idle(void * unused);
845
846
847__initfunc(static void smp_init(void))
848{
849
850 smp_boot_cpus();
851}
852
853
854
855
856
857
858
859__initfunc(static void smp_begin(void))
860{
861 smp_threads_ready=1;
862 smp_commence();
863}
864
865#endif
866
867extern void initialize_secondary(void);
868
869
870
871
872
873__initfunc(asmlinkage void start_kernel(void))
874{
875 char * command_line;
876
877#ifdef __SMP__
878 static int boot_cpu = 1;
879
880 if (!boot_cpu)
881 initialize_secondary();
882 boot_cpu = 0;
883#endif
884
885
886
887
888
889 setup_arch(&command_line, &memory_start, &memory_end);
890 memory_start = paging_init(memory_start,memory_end);
891 trap_init();
892 init_IRQ();
893 sched_init();
894 time_init();
895 parse_options(command_line);
896#ifdef CONFIG_MODULES
897 init_modules();
898#endif
899#ifdef CONFIG_PROFILE
900 if (!prof_shift)
901#ifdef CONFIG_PROFILE_SHIFT
902 prof_shift = CONFIG_PROFILE_SHIFT;
903#else
904 prof_shift = 2;
905#endif
906#endif
907 if (prof_shift) {
908 prof_buffer = (unsigned int *) memory_start;
909
910 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
911 prof_len >>= prof_shift;
912 memory_start += prof_len * sizeof(unsigned int);
913 memset(prof_buffer, 0, prof_len * sizeof(unsigned int));
914 }
915#ifdef CONFIG_SBUS
916 memory_start = sbus_init(memory_start,memory_end);
917#endif
918#ifdef CONFIG_PMAC
919 memory_start = powermac_init(memory_start, memory_end);
920#endif
921 memory_start = console_init(memory_start,memory_end);
922#ifdef CONFIG_PCI
923 memory_start = pci_init(memory_start,memory_end);
924#endif
925#ifdef CONFIG_MCA
926 memory_start = mca_init(memory_start,memory_end);
927#endif
928 memory_start = kmem_cache_init(memory_start, memory_end);
929 sti();
930 calibrate_delay();
931#ifdef CONFIG_BLK_DEV_INITRD
932 if (initrd_start && !initrd_below_start_ok && initrd_start < memory_start) {
933 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
934 "disabling it.\n",initrd_start,memory_start);
935 initrd_start = 0;
936 }
937#endif
938 mem_init(memory_start,memory_end);
939 kmem_cache_sizes_init();
940#ifdef CONFIG_PROC_FS
941 proc_root_init();
942#endif
943 uidcache_init();
944 filescache_init();
945 dcache_init();
946 vma_init();
947 buffer_init();
948 inode_init();
949 file_table_init();
950 sock_init();
951#if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
952 ipc_init();
953#endif
954 dquot_init();
955 sti();
956 check_bugs();
957
958 printk(linux_banner);
959 printk("POSIX conformance testing by UNIFIX\n");
960#ifdef __SMP__
961 smp_init();
962#endif
963#ifdef CONFIG_SYSCTL
964 sysctl_init();
965#endif
966
967
968
969
970
971 kernel_thread(init, NULL, 0);
972
973
974
975
976
977
978
979
980
981 cpu_idle(NULL);
982}
983
984#ifdef CONFIG_BLK_DEV_INITRD
985static int do_linuxrc(void * shell)
986{
987 static char *argv[] = { "linuxrc", NULL, };
988
989 close(0);close(1);close(2);
990 setsid();
991 (void) open("/dev/tty1",O_RDWR,0);
992 (void) dup(0);
993 (void) dup(0);
994 return execve(shell, argv, envp_init);
995}
996
997__initfunc(static void no_initrd(char *s,int *ints))
998{
999 mount_initrd = 0;
1000}
1001#endif
1002
1003static int init(void * unused)
1004{
1005#ifdef CONFIG_BLK_DEV_INITRD
1006 int real_root_mountflags;
1007#endif
1008
1009
1010 kernel_thread(bdflush, NULL, 0);
1011
1012 kswapd_setup();
1013 kernel_thread(kswapd, NULL, 0);
1014
1015#if CONFIG_AP1000
1016
1017 {
1018 extern int asyncd(void *);
1019 kernel_thread(asyncd, NULL, 0);
1020 }
1021#endif
1022
1023#ifdef CONFIG_BLK_DEV_INITRD
1024 real_root_dev = ROOT_DEV;
1025 real_root_mountflags = root_mountflags;
1026 if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
1027 else mount_initrd =0;
1028#endif
1029 setup(0);
1030
1031#ifdef __SMP__
1032
1033
1034
1035
1036
1037 smp_begin();
1038#endif
1039
1040#ifdef CONFIG_UMSDOS_FS
1041 {
1042
1043
1044
1045
1046
1047 extern struct inode *pseudo_root;
1048 if (pseudo_root != NULL){
1049 current->fs->root = pseudo_root;
1050 current->fs->pwd = pseudo_root;
1051 }
1052 }
1053#endif
1054
1055#ifdef CONFIG_BLK_DEV_INITRD
1056 root_mountflags = real_root_mountflags;
1057 if (mount_initrd && ROOT_DEV != real_root_dev && ROOT_DEV == MKDEV(RAMDISK_MAJOR,0)) {
1058 int error;
1059 int i, pid;
1060
1061 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
1062 if (pid>0)
1063 while (pid != wait(&i));
1064 if (real_root_dev != MKDEV(RAMDISK_MAJOR, 0)) {
1065 error = change_root(real_root_dev,"/initrd");
1066 if (error)
1067 printk(KERN_ERR "Change root to /initrd: "
1068 "error %d\n",error);
1069 }
1070 }
1071#endif
1072
1073 setup(1);
1074
1075 if (open("/dev/console",O_RDWR,0) < 0)
1076 printk("Unable to open an initial console.\n");
1077
1078 (void) dup(0);
1079 (void) dup(0);
1080
1081
1082
1083
1084
1085
1086
1087
1088 if(execute_command)
1089 execve(execute_command,argv_init,envp_init);
1090 execve("/sbin/init",argv_init,envp_init);
1091 execve("/etc/init",argv_init,envp_init);
1092 execve("/bin/init",argv_init,envp_init);
1093 execve("/bin/sh",argv_init,envp_init);
1094 panic("No init found. Try passing init= option to kernel.");
1095}
1096