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