This source file includes following definitions.
- _syscall0
- get_options
- ramdisk_setup
- checksetup
- calibrate_delay
- parse_options
- copy_options
- copro_timeout
- check_fpu
- check_hlt
- check_bugs
- start_kernel
- printf
- init
1
2
3
4
5
6
7 #include <stdarg.h>
8
9 #include <asm/system.h>
10 #include <asm/io.h>
11
12 #include <linux/types.h>
13 #include <linux/fcntl.h>
14 #include <linux/config.h>
15 #include <linux/sched.h>
16 #include <linux/tty.h>
17 #include <linux/head.h>
18 #include <linux/unistd.h>
19 #include <linux/string.h>
20 #include <linux/timer.h>
21 #include <linux/fs.h>
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/utsname.h>
25 #include <linux/ioport.h>
26
27 extern unsigned long * prof_buffer;
28 extern unsigned long prof_len;
29 extern char etext, end;
30 extern char *linux_banner;
31 asmlinkage void lcall7(void);
32 struct desc_struct default_ldt;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #define __NR__exit __NR_exit
47 static inline _syscall0(int,idle)
48 static inline _syscall0(int,fork)
49 static inline _syscall0(int,pause)
50 static inline _syscall0(int,setup)
51 static inline _syscall0(int,sync)
52 static inline _syscall0(pid_t,setsid)
53 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
54 static inline _syscall1(int,dup,int,fd)
55 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
56 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
57 static inline _syscall1(int,close,int,fd)
58 static inline _syscall1(int,_exit,int,exitcode)
59 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
60
61 static inline pid_t wait(int * wait_stat)
62 {
63 return waitpid(-1,wait_stat,0);
64 }
65
66 static char printbuf[1024];
67
68 extern int console_loglevel;
69
70 extern char empty_zero_page[PAGE_SIZE];
71 extern void init(void);
72 extern void init_IRQ(void);
73 extern void init_modules(void);
74 extern long console_init(long, long);
75 extern long kmalloc_init(long,long);
76 extern long blk_dev_init(long,long);
77 extern long chr_dev_init(long,long);
78 extern void sock_init(void);
79 extern long rd_init(long mem_start, int length);
80 unsigned long net_dev_init(unsigned long, unsigned long);
81 extern long bios32_init(long, long);
82
83 extern void hd_setup(char *str, int *ints);
84 extern void bmouse_setup(char *str, int *ints);
85 extern void eth_setup(char *str, int *ints);
86 extern void xd_setup(char *str, int *ints);
87 extern void floppy_setup(char *str, int *ints);
88 extern void mcd_setup(char *str, int *ints);
89 extern void st_setup(char *str, int *ints);
90 extern void st0x_setup(char *str, int *ints);
91 extern void tmc8xx_setup(char *str, int *ints);
92 extern void t128_setup(char *str, int *ints);
93 extern void pas16_setup(char *str, int *ints);
94 extern void generic_NCR5380_setup(char *str, int *intr);
95 extern void aha152x_setup(char *str, int *ints);
96 extern void aha1542_setup(char *str, int *ints);
97 extern void aha274x_setup(char *str, int *ints);
98 extern void buslogic_setup(char *str, int *ints);
99 extern void scsi_luns_setup(char *str, int *ints);
100 extern void sound_setup(char *str, int *ints);
101 #ifdef CONFIG_SBPCD
102 extern void sbpcd_setup(char *str, int *ints);
103 #endif CONFIG_SBPCD
104 #ifdef CONFIG_CDU31A
105 extern void cdu31a_setup(char *str, int *ints);
106 #endif CONFIG_CDU31A
107 void ramdisk_setup(char *str, int *ints);
108
109 #ifdef CONFIG_SYSVIPC
110 extern void ipc_init(void);
111 #endif
112 #ifdef CONFIG_SCSI
113 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
114 #endif
115
116
117
118
119 #define PARAM empty_zero_page
120 #define EXT_MEM_K (*(unsigned short *) (PARAM+2))
121 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
122 #define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
123 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
124 #define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
125 #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
126 #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
127
128
129
130
131 #define MAX_INIT_ARGS 8
132 #define MAX_INIT_ENVS 8
133 #define COMMAND_LINE ((char *) (PARAM+2048))
134 #define COMMAND_LINE_SIZE 256
135
136 extern void time_init(void);
137
138 static unsigned long memory_start = 0;
139
140 static unsigned long memory_end = 0;
141 static unsigned long low_memory_start = 0;
142
143 static char term[21];
144 int rows, cols;
145
146 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
147 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
148
149 static char * argv_rc[] = { "/bin/sh", NULL };
150 static char * envp_rc[] = { "HOME=/", term, NULL };
151
152 static char * argv[] = { "-/bin/sh",NULL };
153 static char * envp[] = { "HOME=/usr/root", term, NULL };
154
155 struct drive_info_struct { char dummy[32]; } drive_info;
156 struct screen_info screen_info;
157
158 unsigned char aux_device_present;
159 int ramdisk_size;
160 int root_mountflags = 0;
161
162 static char fpu_error = 0;
163
164 static char command_line[COMMAND_LINE_SIZE] = { 0, };
165
166 char *get_options(char *str, int *ints)
167 {
168 char *cur = str;
169 int i=1;
170
171 while (cur && isdigit(*cur) && i <= 10) {
172 ints[i++] = simple_strtoul(cur,NULL,0);
173 if ((cur = strchr(cur,',')) != NULL)
174 cur++;
175 }
176 ints[0] = i-1;
177 return(cur);
178 }
179
180 struct {
181 char *str;
182 void (*setup_func)(char *, int *);
183 } bootsetups[] = {
184 { "reserve=", reserve_setup },
185 { "ramdisk=", ramdisk_setup },
186 #ifdef CONFIG_INET
187 { "ether=", eth_setup },
188 #endif
189 #ifdef CONFIG_SCSI
190 { "max_scsi_luns=", scsi_luns_setup },
191 #endif
192 #ifdef CONFIG_BLK_DEV_HD
193 { "hd=", hd_setup },
194 #endif
195 #ifdef CONFIG_CHR_DEV_ST
196 { "st=", st_setup },
197 #endif
198 #ifdef CONFIG_BUSMOUSE
199 { "bmouse=", bmouse_setup },
200 #endif
201 #ifdef CONFIG_SCSI_SEAGATE
202 { "st0x=", st0x_setup },
203 { "tmc8xx=", tmc8xx_setup },
204 #endif
205 #ifdef CONFIG_SCSI_T128
206 { "t128=", t128_setup },
207 #endif
208 #ifdef CONFIG_SCSI_PAS16
209 { "pas16=", pas16_setup },
210 #endif
211 #ifdef CONFIG_SCSI_GENERIC_NCR5380
212 { "ncr5380=", generic_NCR5380_setup },
213 #endif
214 #ifdef CONFIG_SCSI_AHA152X
215 { "aha152x=", aha152x_setup},
216 #endif
217 #ifdef CONFIG_SCSI_AHA1542
218 { "aha1542=", aha1542_setup},
219 #endif
220 #ifdef CONFIG_SCSI_AHA274X
221 { "aha274x=", aha274x_setup},
222 #endif
223 #ifdef CONFIG_SCSI_BUSLOGIC
224 { "buslogic=", buslogic_setup},
225 #endif
226 #ifdef CONFIG_BLK_DEV_XD
227 { "xd=", xd_setup },
228 #endif
229 #ifdef CONFIG_BLK_DEV_FD
230 { "floppy=", floppy_setup },
231 #endif
232 #ifdef CONFIG_MCD
233 { "mcd=", mcd_setup },
234 #endif
235 #ifdef CONFIG_SOUND
236 { "sound=", sound_setup },
237 #endif
238 #ifdef CONFIG_SBPCD
239 { "sbpcd=", sbpcd_setup },
240 #endif CONFIG_SBPCD
241 #ifdef CONFIG_CDU31A
242 { "cdu31a=", cdu31a_setup },
243 #endif CONFIG_CDU31A
244 { 0, 0 }
245 };
246
247 void ramdisk_setup(char *str, int *ints)
248 {
249 if (ints[0] > 0 && ints[1] >= 0)
250 ramdisk_size = ints[1];
251 }
252
253 static int checksetup(char *line)
254 {
255 int i = 0;
256 int ints[11];
257
258 while (bootsetups[i].str) {
259 int n = strlen(bootsetups[i].str);
260 if (!strncmp(line,bootsetups[i].str,n)) {
261 bootsetups[i].setup_func(get_options(line+n,ints), ints);
262 return 1;
263 }
264 i++;
265 }
266 return 0;
267 }
268
269 unsigned long loops_per_sec = 1;
270
271 static void calibrate_delay(void)
272 {
273 int ticks;
274
275 printk("Calibrating delay loop.. ");
276 while (loops_per_sec <<= 1) {
277
278 ticks = jiffies;
279 while (ticks == jiffies)
280 ;
281
282 ticks = jiffies;
283 __delay(loops_per_sec);
284 ticks = jiffies - ticks;
285 if (ticks >= HZ) {
286 loops_per_sec = muldiv(loops_per_sec, HZ, ticks);
287 printk("ok - %lu.%02lu BogoMips\n",
288 loops_per_sec/500000,
289 (loops_per_sec/5000) % 100);
290 return;
291 }
292 }
293 printk("failed\n");
294 }
295
296
297
298
299
300
301
302
303
304
305
306
307
308 static void parse_options(char *line)
309 {
310 char *next;
311 char *devnames[] = { "hda", "hdb", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
312 int devnums[] = { 0x300, 0x340, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
313 int args, envs;
314
315 if (!*line)
316 return;
317 args = 0;
318 envs = 1;
319 next = line;
320 while ((line = next) != NULL) {
321 if ((next = strchr(line,' ')) != NULL)
322 *next++ = 0;
323
324
325
326 if (!strncmp(line,"root=",5)) {
327 int n;
328 line += 5;
329 if (strncmp(line,"/dev/",5)) {
330 ROOT_DEV = simple_strtoul(line,NULL,16);
331 continue;
332 }
333 line += 5;
334 for (n = 0 ; devnames[n] ; n++) {
335 int len = strlen(devnames[n]);
336 if (!strncmp(line,devnames[n],len)) {
337 ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
338 break;
339 }
340 }
341 continue;
342 }
343 if (!strcmp(line,"ro")) {
344 root_mountflags |= MS_RDONLY;
345 continue;
346 }
347 if (!strcmp(line,"rw")) {
348 root_mountflags &= ~MS_RDONLY;
349 continue;
350 }
351 if (!strcmp(line,"debug")) {
352 console_loglevel = 10;
353 continue;
354 }
355 if (!strcmp(line,"no-hlt")) {
356 hlt_works_ok = 0;
357 continue;
358 }
359 if (!strcmp(line,"no387")) {
360 hard_math = 0;
361 __asm__("movl %%cr0,%%eax\n\t"
362 "orl $0xE,%%eax\n\t"
363 "movl %%eax,%%cr0\n\t" : : : "ax");
364 continue;
365 }
366 if (checksetup(line))
367 continue;
368
369
370
371
372 if (strchr(line,'=')) {
373 if (envs >= MAX_INIT_ENVS)
374 break;
375 envp_init[++envs] = line;
376 } else {
377 if (args >= MAX_INIT_ARGS)
378 break;
379 argv_init[++args] = line;
380 }
381 }
382 argv_init[args+1] = NULL;
383 envp_init[envs+1] = NULL;
384 }
385
386 static void copy_options(char * to, char * from)
387 {
388 char c = ' ';
389 int len = 0;
390
391 for (;;) {
392 if (c == ' ' && *(unsigned long *)from == *(unsigned long *)"mem=") {
393 memory_end = simple_strtoul(from+4, &from, 0);
394 if ( *from == 'K' || *from == 'k' ) {
395 memory_end = memory_end << 10;
396 from++;
397 } else if ( *from == 'M' || *from == 'm' ) {
398 memory_end = memory_end << 20;
399 from++;
400 }
401 }
402 c = *(from++);
403 if (!c)
404 break;
405 if (COMMAND_LINE_SIZE <= ++len)
406 break;
407 *(to++) = c;
408 }
409 *to = '\0';
410 }
411
412 static void copro_timeout(void)
413 {
414 fpu_error = 1;
415 timer_table[COPRO_TIMER].expires = jiffies+100;
416 timer_active |= 1<<COPRO_TIMER;
417 printk("387 failed: trying to reset\n");
418 send_sig(SIGFPE, last_task_used_math, 1);
419 outb_p(0,0xf1);
420 outb_p(0,0xf0);
421 }
422
423 static void check_fpu(void)
424 {
425 static double x = 4195835.0;
426 static double y = 3145727.0;
427 unsigned short control_word;
428
429 if (!hard_math) {
430 #ifndef CONFIG_MATH_EMULATION
431 printk("No coprocessor found and no math emulation present.\n");
432 printk("Giving up.\n");
433 for (;;) ;
434 #endif
435 return;
436 }
437
438
439
440
441
442
443
444
445
446 printk("Checking 386/387 coupling... ");
447 timer_table[COPRO_TIMER].expires = jiffies+50;
448 timer_table[COPRO_TIMER].fn = copro_timeout;
449 timer_active |= 1<<COPRO_TIMER;
450 __asm__("clts ; fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
451 control_word &= 0xffc0;
452 __asm__("fldcw %0 ; fwait": :"m" (*&control_word));
453 outb_p(inb_p(0x21) | (1 << 2), 0x21);
454 __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
455 timer_active &= ~(1<<COPRO_TIMER);
456 if (fpu_error)
457 return;
458 if (!ignore_irq13) {
459 printk("Ok, fpu using old IRQ13 error reporting\n");
460 return;
461 }
462 __asm__("fninit\n\t"
463 "fldl %1\n\t"
464 "fdivl %2\n\t"
465 "fmull %2\n\t"
466 "fldl %1\n\t"
467 "fsubp %%st,%%st(1)\n\t"
468 "fistpl %0\n\t"
469 "fwait\n\t"
470 "fninit"
471 : "=m" (*&fdiv_bug)
472 : "m" (*&x), "m" (*&y));
473 if (!fdiv_bug) {
474 printk("Ok, fpu using exception 16 error reporting.\n");
475 return;
476
477 }
478 printk("Ok, FDIV bug i%c86 system\n", '0'+x86);
479 }
480
481 static void check_hlt(void)
482 {
483 printk("Checking 'hlt' instruction... ");
484 if (!hlt_works_ok) {
485 printk("disabled\n");
486 return;
487 }
488 __asm__ __volatile__("hlt ; hlt ; hlt ; hlt");
489 printk("Ok.\n");
490 }
491
492 static void check_bugs(void)
493 {
494 check_fpu();
495 check_hlt();
496 }
497
498 asmlinkage void start_kernel(void)
499 {
500
501
502
503
504 set_call_gate(&default_ldt,lcall7);
505 ROOT_DEV = ORIG_ROOT_DEV;
506 drive_info = DRIVE_INFO;
507 screen_info = SCREEN_INFO;
508 aux_device_present = AUX_DEVICE_INFO;
509 memory_end = (1<<20) + (EXT_MEM_K<<10);
510 memory_end &= PAGE_MASK;
511 ramdisk_size = RAMDISK_SIZE;
512 copy_options(command_line,COMMAND_LINE);
513 #ifdef CONFIG_MAX_16M
514 if (memory_end > 16*1024*1024)
515 memory_end = 16*1024*1024;
516 #endif
517 if (MOUNT_ROOT_RDONLY)
518 root_mountflags |= MS_RDONLY;
519 if ((unsigned long)&end >= (1024*1024)) {
520 memory_start = (unsigned long) &end;
521 low_memory_start = PAGE_SIZE;
522 } else {
523 memory_start = 1024*1024;
524 low_memory_start = (unsigned long) &end;
525 }
526 low_memory_start = PAGE_ALIGN(low_memory_start);
527 memory_start = paging_init(memory_start,memory_end);
528 if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0)
529 EISA_bus = 1;
530 trap_init();
531 init_IRQ();
532 sched_init();
533 parse_options(command_line);
534 init_modules();
535 #ifdef CONFIG_PROFILE
536 prof_buffer = (unsigned long *) memory_start;
537
538 prof_len = (unsigned long) &etext;
539 prof_len >>= CONFIG_PROFILE_SHIFT;
540 memory_start += prof_len * sizeof(unsigned long);
541 #endif
542 memory_start = console_init(memory_start,memory_end);
543 memory_start = bios32_init(memory_start,memory_end);
544 memory_start = kmalloc_init(memory_start,memory_end);
545 memory_start = chr_dev_init(memory_start,memory_end);
546 memory_start = blk_dev_init(memory_start,memory_end);
547 sti();
548 calibrate_delay();
549 #ifdef CONFIG_SCSI
550 memory_start = scsi_dev_init(memory_start,memory_end);
551 #endif
552 #ifdef CONFIG_INET
553 memory_start = net_dev_init(memory_start,memory_end);
554 #endif
555 memory_start = inode_init(memory_start,memory_end);
556 memory_start = file_table_init(memory_start,memory_end);
557 memory_start = name_cache_init(memory_start,memory_end);
558 mem_init(low_memory_start,memory_start,memory_end);
559 buffer_init();
560 time_init();
561 sock_init();
562 #ifdef CONFIG_SYSVIPC
563 ipc_init();
564 #endif
565 sti();
566 check_bugs();
567
568 system_utsname.machine[1] = '0' + x86;
569 printk(linux_banner);
570
571 move_to_user_mode();
572 if (!fork())
573 init();
574
575
576
577
578
579
580
581
582
583 for(;;)
584 idle();
585 }
586
587 static int printf(const char *fmt, ...)
588 {
589 va_list args;
590 int i;
591
592 va_start(args, fmt);
593 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
594 va_end(args);
595 return i;
596 }
597
598 void init(void)
599 {
600 int pid,i;
601
602 setup();
603 sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
604
605 #ifdef CONFIG_UMSDOS_FS
606 {
607
608
609
610
611
612 extern struct inode *pseudo_root;
613 if (pseudo_root != NULL){
614 current->fs->root = pseudo_root;
615 current->fs->pwd = pseudo_root;
616 }
617 }
618 #endif
619
620 (void) open("/dev/tty1",O_RDWR,0);
621 (void) dup(0);
622 (void) dup(0);
623
624 execve("/etc/init",argv_init,envp_init);
625 execve("/bin/init",argv_init,envp_init);
626 execve("/sbin/init",argv_init,envp_init);
627
628
629 if (!(pid=fork())) {
630 close(0);
631 if (open("/etc/rc",O_RDONLY,0))
632 _exit(1);
633 execve("/bin/sh",argv_rc,envp_rc);
634 _exit(2);
635 }
636 if (pid>0)
637 while (pid != wait(&i))
638 ;
639 while (1) {
640 if ((pid = fork()) < 0) {
641 printf("Fork failed in init\n\r");
642 continue;
643 }
644 if (!pid) {
645 close(0);close(1);close(2);
646 setsid();
647 (void) open("/dev/tty1",O_RDWR,0);
648 (void) dup(0);
649 (void) dup(0);
650 _exit(execve("/bin/sh",argv,envp));
651 }
652 while (1)
653 if (pid == wait(&i))
654 break;
655 printf("\n\rchild %d died with code %04x\n\r",pid,i);
656 sync();
657 }
658 _exit(0);
659 }