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