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