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