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