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