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