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