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