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