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