This source file includes following definitions.
- get_options
- profile_setup
- ramdisk_start_setup
- load_ramdisk
- prompt_ramdisk
- ramdisk_size
- checksetup
- calibrate_delay
- parse_root_dev
- parse_options
- cpu_idle
- start_secondary
- smp_init
- smp_begin
- start_kernel
- printf
- do_rc
- do_shell
- do_linuxrc
- no_initrd
- init
1
2
3
4
5
6
7
8
9
10 #define __KERNEL_SYSCALLS__
11 #include <stdarg.h>
12
13 #include <asm/system.h>
14 #include <asm/io.h>
15
16 #include <linux/types.h>
17 #include <linux/fcntl.h>
18 #include <linux/config.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/tty.h>
22 #include <linux/head.h>
23 #include <linux/unistd.h>
24 #include <linux/string.h>
25 #include <linux/timer.h>
26 #include <linux/fs.h>
27 #include <linux/ctype.h>
28 #include <linux/delay.h>
29 #include <linux/utsname.h>
30 #include <linux/ioport.h>
31 #include <linux/hdreg.h>
32 #include <linux/mm.h>
33 #include <linux/major.h>
34 #include <linux/blk.h>
35 #ifdef CONFIG_ROOT_NFS
36 #include <linux/nfs_fs.h>
37 #endif
38
39 #include <asm/bugs.h>
40
41 extern char _stext, _etext;
42 extern char *linux_banner;
43
44 static char printbuf[1024];
45
46 extern int console_loglevel;
47
48 static int init(void *);
49 extern int bdflush(void *);
50 extern int kswapd(void *);
51
52 extern void init_IRQ(void);
53 extern void init_modules(void);
54 extern long console_init(long, long);
55 extern long kmalloc_init(long,long);
56 extern void sock_init(void);
57 extern long pci_init(long, long);
58 extern void sysctl_init(void);
59
60 extern void no_scroll(char *str, int *ints);
61 extern void swap_setup(char *str, int *ints);
62 extern void buff_setup(char *str, int *ints);
63 extern void panic_setup(char *str, int *ints);
64 extern void bmouse_setup(char *str, int *ints);
65 extern void lp_setup(char *str, int *ints);
66 extern void eth_setup(char *str, int *ints);
67 extern void xd_setup(char *str, int *ints);
68 extern void floppy_setup(char *str, int *ints);
69 extern void st_setup(char *str, int *ints);
70 extern void st0x_setup(char *str, int *ints);
71 extern void advansys_setup(char *str, int *ints);
72 extern void tmc8xx_setup(char *str, int *ints);
73 extern void t128_setup(char *str, int *ints);
74 extern void pas16_setup(char *str, int *ints);
75 extern void generic_NCR5380_setup(char *str, int *intr);
76 extern void generic_NCR53C400_setup(char *str, int *intr);
77 extern void aha152x_setup(char *str, int *ints);
78 extern void aha1542_setup(char *str, int *ints);
79 extern void aic7xxx_setup(char *str, int *ints);
80 extern void AM53C974_setup(char *str, int *ints);
81 extern void BusLogic_Setup(char *str, int *ints);
82 extern void fdomain_setup(char *str, int *ints);
83 extern void in2000_setup(char *str, int *ints);
84 extern void NCR53c406a_setup(char *str, int *ints);
85 extern void ppa_setup(char *str, int *ints);
86 extern void scsi_luns_setup(char *str, int *ints);
87 extern void sound_setup(char *str, int *ints);
88 #ifdef CONFIG_CDU31A
89 extern void cdu31a_setup(char *str, int *ints);
90 #endif CONFIG_CDU31A
91 #ifdef CONFIG_MCD
92 extern void mcd_setup(char *str, int *ints);
93 #endif CONFIG_MCD
94 #ifdef CONFIG_MCDX
95 extern void mcdx_setup(char *str, int *ints);
96 #endif CONFIG_MCDX
97 #ifdef CONFIG_SBPCD
98 extern void sbpcd_setup(char *str, int *ints);
99 #endif CONFIG_SBPCD
100 #ifdef CONFIG_AZTCD
101 extern void aztcd_setup(char *str, int *ints);
102 #endif CONFIG_AZTCD
103 #ifdef CONFIG_CDU535
104 extern void sonycd535_setup(char *str, int *ints);
105 #endif CONFIG_CDU535
106 #ifdef CONFIG_GSCD
107 extern void gscd_setup(char *str, int *ints);
108 #endif CONFIG_GSCD
109 #ifdef CONFIG_CM206
110 extern void cm206_setup(char *str, int *ints);
111 #endif CONFIG_CM206
112 #ifdef CONFIG_OPTCD
113 extern void optcd_setup(char *str, int *ints);
114 #endif CONFIG_OPTCD
115 #ifdef CONFIG_SJCD
116 extern void sjcd_setup(char *str, int *ints);
117 #endif CONFIG_SJCD
118 #ifdef CONFIG_ISP16_CDI
119 extern void isp16_setup(char *str, int *ints);
120 #endif CONFIG_ISP16_CDI
121 #ifdef CONFIG_BLK_DEV_RAM
122 static void ramdisk_start_setup(char *str, int *ints);
123 static void load_ramdisk(char *str, int *ints);
124 static void prompt_ramdisk(char *str, int *ints);
125 static void ramdisk_size(char *str, int *ints);
126 #ifdef CONFIG_BLK_DEV_INITRD
127 static void no_initrd(char *s,int *ints);
128 #endif
129 #endif CONFIG_BLK_DEV_RAM
130 #ifdef CONFIG_ISDN_DRV_ICN
131 extern void icn_setup(char *str, int *ints);
132 #endif
133 #ifdef CONFIG_ISDN_DRV_TELES
134 extern void teles_setup(char *str, int *ints);
135 #endif
136
137 #ifdef CONFIG_ATARIMOUSE
138 extern void atari_mouse_setup (char *str, int *ints);
139 #endif
140 #ifdef CONFIG_DMASOUND
141 extern void dmasound_setup (char *str, int *ints);
142 #endif
143 #ifdef CONFIG_ATARI_SCSI
144 extern void atari_scsi_setup (char *str, int *ints);
145 #endif
146 extern void wd33c93_setup (char *str, int *ints);
147 extern void gvp11_setup (char *str, int *ints);
148
149 #ifdef CONFIG_DIGI
150 extern void pcxx_setup(char *str, int *ints);
151 #endif
152 #ifdef CONFIG_ISDN_DRV_PCBIT
153 extern void pcbit_setup(char *str, int *ints);
154 #endif
155 #ifdef CONFIG_RISCOM8
156 extern void riscom8_setup(char *str, int *ints);
157 #endif
158
159
160 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
161 extern void ipc_init(void);
162 #endif
163
164
165
166
167 #define MAX_INIT_ARGS 8
168 #define MAX_INIT_ENVS 8
169
170 extern void time_init(void);
171
172 static unsigned long memory_start = 0;
173 static unsigned long memory_end = 0;
174
175 int rows, cols;
176
177 #ifdef CONFIG_BLK_DEV_RAM
178 extern int rd_doload;
179 extern int rd_prompt;
180 extern int rd_size;
181 extern int rd_image_start;
182 #ifdef CONFIG_BLK_DEV_INITRD
183 kdev_t real_root_dev;
184 #endif
185 #endif
186
187 int root_mountflags = MS_RDONLY;
188 char *execute_command = 0;
189
190 #ifdef CONFIG_ROOT_NFS
191 char nfs_root_name[NFS_ROOT_NAME_LEN] = { "default" };
192 char nfs_root_addrs[NFS_ROOT_ADDRS_LEN] = { "" };
193 #endif
194
195 extern void dquot_init(void);
196
197 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
198 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
199
200 static char * argv_rc[] = { "/bin/sh", NULL };
201 static char * envp_rc[] = { "HOME=/", "TERM=linux", NULL };
202
203 static char * argv[] = { "-/bin/sh",NULL };
204 static char * envp[] = { "HOME=/usr/root", "TERM=linux", NULL };
205
206 char *get_options(char *str, int *ints)
207 {
208 char *cur = str;
209 int i=1;
210
211 while (cur && isdigit(*cur) && i <= 10) {
212 ints[i++] = simple_strtoul(cur,NULL,0);
213 if ((cur = strchr(cur,',')) != NULL)
214 cur++;
215 }
216 ints[0] = i-1;
217 return(cur);
218 }
219
220 static void profile_setup(char *str, int *ints)
221 {
222 if (ints[0] > 0)
223 prof_shift = (unsigned long) ints[1];
224 else
225 #ifdef CONFIG_PROFILE_SHIFT
226 prof_shift = CONFIG_PROFILE_SHIFT;
227 #else
228 prof_shift = 2;
229 #endif
230 }
231
232 struct {
233 const char *str;
234 void (*setup_func)(char *, int *);
235 } bootsetups[] = {
236 { "reserve=", reserve_setup },
237 { "profile=", profile_setup },
238 #ifdef CONFIG_BLK_DEV_RAM
239 { "ramdisk_start=", ramdisk_start_setup },
240 { "load_ramdisk=", load_ramdisk },
241 { "prompt_ramdisk=", prompt_ramdisk },
242 { "ramdisk=", ramdisk_size },
243 { "ramdisk_size=", ramdisk_size },
244 #ifdef CONFIG_BLK_DEV_INITRD
245 { "noinitrd", no_initrd },
246 #endif
247 #endif
248 { "swap=", swap_setup },
249 { "buff=", buff_setup },
250 { "panic=", panic_setup },
251 { "no-scroll", no_scroll },
252 #ifdef CONFIG_BUGi386
253 { "no-hlt", no_halt },
254 { "no387", no_387 },
255 #endif
256 #ifdef CONFIG_INET
257 { "ether=", eth_setup },
258 #endif
259 #ifdef CONFIG_PRINTER
260 { "lp=", lp_setup },
261 #endif
262 #ifdef CONFIG_SCSI
263 { "max_scsi_luns=", scsi_luns_setup },
264 #endif
265 #ifdef CONFIG_SCSI_ADVANSYS
266 { "advansys=", advansys_setup },
267 #endif
268 #if defined(CONFIG_BLK_DEV_HD)
269 { "hd=", hd_setup },
270 #endif
271 #ifdef CONFIG_CHR_DEV_ST
272 { "st=", st_setup },
273 #endif
274 #ifdef CONFIG_BUSMOUSE
275 { "bmouse=", bmouse_setup },
276 #endif
277 #ifdef CONFIG_SCSI_SEAGATE
278 { "st0x=", st0x_setup },
279 { "tmc8xx=", tmc8xx_setup },
280 #endif
281 #ifdef CONFIG_SCSI_T128
282 { "t128=", t128_setup },
283 #endif
284 #ifdef CONFIG_SCSI_PAS16
285 { "pas16=", pas16_setup },
286 #endif
287 #ifdef CONFIG_SCSI_GENERIC_NCR5380
288 { "ncr5380=", generic_NCR5380_setup },
289 { "ncr53c400=", generic_NCR53C400_setup },
290 #endif
291 #ifdef CONFIG_SCSI_AHA152X
292 { "aha152x=", aha152x_setup},
293 #endif
294 #ifdef CONFIG_SCSI_AHA1542
295 { "aha1542=", aha1542_setup},
296 #endif
297 #ifdef CONFIG_SCSI_AIC7XXX
298 { "aic7xxx=", aic7xxx_setup},
299 #endif
300 #ifdef CONFIG_SCSI_BUSLOGIC
301 { "BusLogic=", BusLogic_Setup},
302 #endif
303 #ifdef CONFIG_SCSI_AM53C974
304 { "AM53C974=", AM53C974_setup},
305 #endif
306 #ifdef CONFIG_SCSI_NCR53C406A
307 { "ncr53c406a=", NCR53c406a_setup},
308 #endif
309 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
310 { "fdomain=", fdomain_setup},
311 #endif
312 #ifdef CONFIG_SCSI_IN2000
313 { "in2000=", in2000_setup},
314 #endif
315 #ifdef CONFIG_SCSI_PPA
316 { "ppa=", ppa_setup },
317 #endif
318 #ifdef CONFIG_BLK_DEV_XD
319 { "xd=", xd_setup },
320 #endif
321 #ifdef CONFIG_BLK_DEV_FD
322 { "floppy=", floppy_setup },
323 #endif
324 #ifdef CONFIG_CDU31A
325 { "cdu31a=", cdu31a_setup },
326 #endif CONFIG_CDU31A
327 #ifdef CONFIG_MCD
328 { "mcd=", mcd_setup },
329 #endif CONFIG_MCD
330 #ifdef CONFIG_MCDX
331 { "mcdx=", mcdx_setup },
332 #endif CONFIG_MCDX
333 #ifdef CONFIG_SBPCD
334 { "sbpcd=", sbpcd_setup },
335 #endif CONFIG_SBPCD
336 #ifdef CONFIG_AZTCD
337 { "aztcd=", aztcd_setup },
338 #endif CONFIG_AZTCD
339 #ifdef CONFIG_CDU535
340 { "sonycd535=", sonycd535_setup },
341 #endif CONFIG_CDU535
342 #ifdef CONFIG_GSCD
343 { "gscd=", gscd_setup },
344 #endif CONFIG_GSCD
345 #ifdef CONFIG_CM206
346 { "cm206=", cm206_setup },
347 #endif CONFIG_CM206
348 #ifdef CONFIG_OPTCD
349 { "optcd=", optcd_setup },
350 #endif CONFIG_OPTCD
351 #ifdef CONFIG_SJCD
352 { "sjcd=", sjcd_setup },
353 #endif CONFIG_SJCD
354 #ifdef CONFIG_ISP16_CDI
355 { "isp16=", isp16_setup },
356 #endif CONFIG_ISP16_CDI
357 #ifdef CONFIG_SOUND
358 { "sound=", sound_setup },
359 #endif
360 #ifdef CONFIG_ISDN_DRV_ICN
361 { "icn=", icn_setup },
362 #endif
363 #ifdef CONFIG_ISDN_DRV_TELES
364 { "teles=", teles_setup },
365 #endif
366 #ifdef CONFIG_ISDN_DRV_PCBIT
367 { "pcbit=", pcbit_setup },
368 #endif
369 #ifdef CONFIG_ATARIMOUSE
370 { "atamouse=", atari_mouse_setup },
371 #endif
372 #ifdef CONFIG_DMASOUND
373 { "dmasound=", dmasound_setup },
374 #endif
375 #ifdef CONFIG_ATARI_SCSI
376 { "atascsi=", atari_scsi_setup },
377 #endif
378 #if defined(CONFIG_A3000_SCSI) || defined(CONFIG_A2091_SCSI) \
379 || defined(CONFIG_GVP11_SCSI)
380 { "wd33c93=", wd33c93_setup },
381 #endif
382 #if defined(CONFIG_GVP11_SCSI)
383 { "gvp11=", gvp11_setup },
384 #endif
385 #ifdef CONFIG_DIGI
386 { "digi=", pcxx_setup },
387 #endif
388 #ifdef CONFIG_RISCOM8
389 { "riscom8=", riscom8_setup },
390 #endif
391 { 0, 0 }
392 };
393
394 #ifdef CONFIG_BLK_DEV_RAM
395 static void ramdisk_start_setup(char *str, int *ints)
396 {
397 if (ints[0] > 0 && ints[1] >= 0)
398 rd_image_start = ints[1];
399 }
400
401 static void load_ramdisk(char *str, int *ints)
402 {
403 if (ints[0] > 0 && ints[1] >= 0)
404 rd_doload = ints[1] & 1;
405 }
406
407 static void prompt_ramdisk(char *str, int *ints)
408 {
409 if (ints[0] > 0 && ints[1] >= 0)
410 rd_prompt = ints[1] & 1;
411 }
412
413 static void ramdisk_size(char *str, int *ints)
414 {
415 if (ints[0] > 0 && ints[1] >= 0)
416 rd_size = ints[1];
417 }
418
419 #endif
420
421 static int checksetup(char *line)
422 {
423 int i = 0;
424 int ints[11];
425
426 #ifdef CONFIG_BLK_DEV_IDE
427
428 if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {
429 ide_setup(line);
430 return 1;
431 }
432 #endif
433 while (bootsetups[i].str) {
434 int n = strlen(bootsetups[i].str);
435 if (!strncmp(line,bootsetups[i].str,n)) {
436 bootsetups[i].setup_func(get_options(line+n,ints), ints);
437 return 1;
438 }
439 i++;
440 }
441 return 0;
442 }
443
444
445
446 unsigned long loops_per_sec = (1<<12);
447
448
449
450
451 #define LPS_PREC 8
452
453 void calibrate_delay(void)
454 {
455 int ticks;
456 int loopbit;
457 int lps_precision = LPS_PREC;
458
459 loops_per_sec = (1<<12);
460
461 printk("Calibrating delay loop.. ");
462 while (loops_per_sec <<= 1) {
463
464 ticks = jiffies;
465 while (ticks == jiffies)
466 ;
467
468 ticks = jiffies;
469 __delay(loops_per_sec);
470 ticks = jiffies - ticks;
471 if (ticks)
472 break;
473 }
474
475
476
477 loops_per_sec >>= 1;
478 loopbit = loops_per_sec;
479 while ( lps_precision-- && (loopbit >>= 1) ) {
480 loops_per_sec |= loopbit;
481 ticks = jiffies;
482 while (ticks == jiffies);
483 ticks = jiffies;
484 __delay(loops_per_sec);
485 if (jiffies != ticks)
486 loops_per_sec &= ~loopbit;
487 }
488
489
490 loops_per_sec *= HZ;
491
492 printk("ok - %lu.%02lu BogoMIPS\n",
493 (loops_per_sec+2500)/500000,
494 ((loops_per_sec+2500)/5000) % 100);
495 }
496
497 static void parse_root_dev(char * line)
498 {
499 int base = 0;
500 static struct dev_name_struct {
501 const char *name;
502 const int num;
503 } devices[] = {
504 { "nfs", 0x00ff },
505 { "hda", 0x0300 },
506 { "hdb", 0x0340 },
507 { "hdc", 0x1600 },
508 { "hdd", 0x1640 },
509 { "sda", 0x0800 },
510 { "sdb", 0x0810 },
511 { "sdc", 0x0820 },
512 { "sdd", 0x0830 },
513 { "sde", 0x0840 },
514 { "fd", 0x0200 },
515 { "xda", 0x0d00 },
516 { "xdb", 0x0d40 },
517 { "ram", 0x0100 },
518 { "scd", 0x0b00 },
519 { "mcd", 0x1700 },
520 { "cdu535", 0x1800 },
521 { "aztcd", 0x1d00 },
522 { "cm206cd", 0x2000 },
523 { "gscd", 0x1000 },
524 { "sbpcd", 0x1900 },
525 { "sonycd", 0x1800 },
526 { NULL, 0 }
527 };
528
529 if (strncmp(line,"/dev/",5) == 0) {
530 struct dev_name_struct *dev = devices;
531 line += 5;
532 do {
533 int len = strlen(dev->name);
534 if (strncmp(line,dev->name,len) == 0) {
535 line += len;
536 base = dev->num;
537 break;
538 }
539 dev++;
540 } while (dev->name);
541 }
542 ROOT_DEV = to_kdev_t(base + simple_strtoul(line,NULL,base?10:16));
543 }
544
545
546
547
548
549
550
551
552
553
554
555 static void parse_options(char *line)
556 {
557 char *next;
558 int args, envs;
559
560 if (!*line)
561 return;
562 args = 0;
563 envs = 1;
564 next = line;
565 while ((line = next) != NULL) {
566 if ((next = strchr(line,' ')) != NULL)
567 *next++ = 0;
568
569
570
571 if (!strncmp(line,"root=",5)) {
572 parse_root_dev(line+5);
573 continue;
574 }
575 #ifdef CONFIG_ROOT_NFS
576 if (!strncmp(line, "nfsroot=", 8)) {
577 int n;
578 line += 8;
579 ROOT_DEV = MKDEV(UNNAMED_MAJOR, 255);
580 if (line[0] == '/' || line[0] == ',' || (line[0] >= '0' && line[0] <= '9')) {
581 strncpy(nfs_root_name, line, sizeof(nfs_root_name));
582 nfs_root_name[sizeof(nfs_root_name)-1] = '\0';
583 continue;
584 }
585 n = strlen(line) + strlen(NFS_ROOT);
586 if (n >= sizeof(nfs_root_name))
587 line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
588 sprintf(nfs_root_name, NFS_ROOT, line);
589 continue;
590 }
591 if (!strncmp(line, "nfsaddrs=", 9)) {
592 line += 9;
593 strncpy(nfs_root_addrs, line, sizeof(nfs_root_addrs));
594 nfs_root_addrs[sizeof(nfs_root_addrs)-1] = '\0';
595 continue;
596 }
597 #endif
598 if (!strcmp(line,"ro")) {
599 root_mountflags |= MS_RDONLY;
600 continue;
601 }
602 if (!strcmp(line,"rw")) {
603 root_mountflags &= ~MS_RDONLY;
604 continue;
605 }
606 if (!strcmp(line,"debug")) {
607 console_loglevel = 10;
608 continue;
609 }
610 if (!strncmp(line,"init=",5)) {
611 line += 5;
612 execute_command = line;
613 continue;
614 }
615 if (checksetup(line))
616 continue;
617
618
619
620
621 if (strchr(line,'=')) {
622 if (envs >= MAX_INIT_ENVS)
623 break;
624 envp_init[++envs] = line;
625 } else {
626 if (args >= MAX_INIT_ARGS)
627 break;
628 argv_init[++args] = line;
629 }
630 }
631 argv_init[args+1] = NULL;
632 envp_init[envs+1] = NULL;
633 }
634
635
636 extern void setup_arch(char **, unsigned long *, unsigned long *);
637 extern void arch_syms_export(void);
638
639 #ifndef __SMP__
640
641
642
643
644
645 int cpu_idle(void *unused)
646 {
647 for(;;)
648 idle();
649 }
650
651 #else
652
653
654
655
656
657 extern int cpu_idle(void * unused);
658
659
660
661
662
663 asmlinkage void start_secondary(void)
664 {
665 trap_init();
666 init_IRQ();
667 smp_callin();
668 cpu_idle(NULL);
669 }
670
671
672
673
674
675
676
677 static void smp_init(void)
678 {
679 int i, j;
680 smp_boot_cpus();
681
682
683
684
685
686
687
688
689 for (i=1; i<smp_num_cpus; i++)
690 {
691 struct task_struct *n, *p;
692
693 j = cpu_logical_map[i];
694
695
696
697
698 kernel_thread(cpu_idle, NULL, CLONE_PID);
699
700
701
702 current_set[j]=task[i];
703 current_set[j]->processor=j;
704 cli();
705 n = task[i]->next_run;
706 p = task[i]->prev_run;
707 nr_running--;
708 n->prev_run = p;
709 p->next_run = n;
710 task[i]->next_run = task[i]->prev_run = task[i];
711 sti();
712 }
713 }
714
715
716
717
718
719
720
721 static void smp_begin(void)
722 {
723 smp_threads_ready=1;
724 smp_commence();
725 }
726
727 #endif
728
729
730
731
732
733 asmlinkage void start_kernel(void)
734 {
735 char * command_line;
736
737
738
739
740
741 #ifdef __SMP__
742 static int first_cpu=1;
743
744 if(!first_cpu)
745 start_secondary();
746 first_cpu=0;
747
748 #endif
749
750
751
752
753 setup_arch(&command_line, &memory_start, &memory_end);
754 memory_start = paging_init(memory_start,memory_end);
755 trap_init();
756 init_IRQ();
757 sched_init();
758 time_init();
759 parse_options(command_line);
760 #ifdef CONFIG_MODULES
761 init_modules();
762 #endif
763 #ifdef CONFIG_PROFILE
764 if (!prof_shift)
765 #ifdef CONFIG_PROFILE_SHIFT
766 prof_shift = CONFIG_PROFILE_SHIFT;
767 #else
768 prof_shift = 2;
769 #endif
770 #endif
771 if (prof_shift) {
772 prof_buffer = (unsigned int *) memory_start;
773
774 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
775 prof_len >>= prof_shift;
776 memory_start += prof_len * sizeof(unsigned int);
777 }
778 memory_start = console_init(memory_start,memory_end);
779 #ifdef CONFIG_PCI
780 memory_start = pci_init(memory_start,memory_end);
781 #endif
782 memory_start = kmalloc_init(memory_start,memory_end);
783 sti();
784 calibrate_delay();
785 memory_start = inode_init(memory_start,memory_end);
786 memory_start = file_table_init(memory_start,memory_end);
787 memory_start = name_cache_init(memory_start,memory_end);
788 #ifdef CONFIG_BLK_DEV_INITRD
789 if (initrd_start && initrd_start < memory_start) {
790 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
791 "disabling it.\n",initrd_start,memory_start);
792 initrd_start = 0;
793 }
794 #endif
795 mem_init(memory_start,memory_end);
796 buffer_init();
797 sock_init();
798 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
799 ipc_init();
800 #endif
801 dquot_init();
802 arch_syms_export();
803 sti();
804 check_bugs();
805
806 printk(linux_banner);
807 #ifdef __SMP__
808 smp_init();
809 #endif
810 sysctl_init();
811
812
813
814
815
816 kernel_thread(init, NULL, 0);
817
818
819
820
821
822
823
824
825
826 cpu_idle(NULL);
827 }
828
829 static int printf(const char *fmt, ...)
830 {
831 va_list args;
832 int i;
833
834 va_start(args, fmt);
835 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
836 va_end(args);
837 return i;
838 }
839
840 static int do_rc(void * rc)
841 {
842 close(0);
843 if (open(rc,O_RDONLY,0))
844 return -1;
845 return execve("/bin/sh", argv_rc, envp_rc);
846 }
847
848 static int do_shell(void * shell)
849 {
850 close(0);close(1);close(2);
851 setsid();
852 (void) open("/dev/tty1",O_RDWR,0);
853 (void) dup(0);
854 (void) dup(0);
855 return execve(shell, argv, envp);
856 }
857
858 #ifdef CONFIG_BLK_DEV_INITRD
859 static int do_linuxrc(void * shell)
860 {
861 static char *argv[] = { "linuxrc", NULL, };
862
863 close(0);close(1);close(2);
864 setsid();
865 (void) open("/dev/tty1",O_RDWR,0);
866 (void) dup(0);
867 (void) dup(0);
868 return execve(shell, argv, envp_init);
869 }
870
871 static void no_initrd(char *s,int *ints)
872 {
873 mount_initrd = 0;
874 }
875 #endif
876
877 static int init(void * unused)
878 {
879 int pid,i;
880 #ifdef CONFIG_BLK_DEV_INITRD
881 int real_root_mountflags;
882 #endif
883
884
885 kernel_thread(bdflush, NULL, 0);
886
887 kernel_thread(kswapd, NULL, 0);
888
889 #ifdef CONFIG_BLK_DEV_INITRD
890 real_root_dev = ROOT_DEV;
891 real_root_mountflags = root_mountflags;
892 if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
893 else mount_initrd =0;
894 #endif
895 setup();
896
897 #ifdef __SMP__
898
899
900
901
902
903 smp_begin();
904 #endif
905
906 #ifdef CONFIG_UMSDOS_FS
907 {
908
909
910
911
912
913 extern struct inode *pseudo_root;
914 if (pseudo_root != NULL){
915 current->fs->root = pseudo_root;
916 current->fs->pwd = pseudo_root;
917 }
918 }
919 #endif
920
921 #ifdef CONFIG_BLK_DEV_INITRD
922 root_mountflags = real_root_mountflags;
923 if (mount_initrd && ROOT_DEV != real_root_dev && ROOT_DEV == MKDEV(RAMDISK_MAJOR,0)) {
924 int error;
925
926 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
927 if (pid>0)
928 while (pid != wait(&i));
929 if (real_root_dev != MKDEV(RAMDISK_MAJOR, 0)) {
930 error = change_root(real_root_dev,"/initrd");
931 if (error)
932 printk(KERN_ERR "Change root to /initrd: "
933 "error %d\n",error);
934 }
935 }
936 #endif
937
938 (void) open("/dev/tty1",O_RDWR,0);
939 (void) dup(0);
940 (void) dup(0);
941
942 if (!execute_command) {
943 execve("/etc/init",argv_init,envp_init);
944 execve("/bin/init",argv_init,envp_init);
945 execve("/sbin/init",argv_init,envp_init);
946
947
948 pid = kernel_thread(do_rc, "/etc/rc", SIGCHLD);
949 if (pid>0)
950 while (pid != wait(&i))
951 ;
952 }
953
954 while (1) {
955 pid = kernel_thread(do_shell,
956 execute_command ? execute_command : "/bin/sh",
957 SIGCHLD);
958 if (pid < 0) {
959 printf("Fork failed in init\n\r");
960 continue;
961 }
962 while (1)
963 if (pid == wait(&i))
964 break;
965 printf("\n\rchild %d died with code %04x\n\r",pid,i);
966 sync();
967 }
968 return -1;
969 }