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