This source file includes following definitions.
- _syscall0
- time_init
- get_options
- checksetup
- calibrate_delay
- parse_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/mktime.h>
13 #include <linux/types.h>
14 #include <linux/fcntl.h>
15 #include <linux/config.h>
16 #include <linux/sched.h>
17 #include <linux/tty.h>
18 #include <linux/head.h>
19 #include <linux/unistd.h>
20 #include <linux/string.h>
21 #include <linux/timer.h>
22 #include <linux/fs.h>
23 #include <linux/ctype.h>
24 #include <linux/delay.h>
25 #include <linux/utsname.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 extern "C" void lcall7(void);
32 struct desc_struct default_ldt;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 static inline _syscall0(int,idle)
47 static inline _syscall0(int,fork)
48 static inline _syscall0(int,pause)
49 static inline _syscall1(int,setup,void *,BIOS)
50 static inline _syscall0(int,sync)
51 static inline _syscall0(pid_t,setsid)
52 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
53 static inline _syscall1(int,dup,int,fd)
54 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
55 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
56 static inline _syscall1(int,close,int,fd)
57 static inline _syscall1(int,exit,int,exitcode)
58 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
59
60 static inline pid_t wait(int * wait_stat)
61 {
62 return waitpid(-1,wait_stat,0);
63 }
64
65 static char printbuf[1024];
66
67 extern char empty_zero_page[PAGE_SIZE];
68 extern int vsprintf(char *,const char *,va_list);
69 extern void init(void);
70 extern void init_IRQ(void);
71 extern long blk_dev_init(long,long);
72 extern long chr_dev_init(long,long);
73 extern void floppy_init(void);
74 extern void sock_init(void);
75 extern long rd_init(long mem_start, int length);
76 extern long kernel_mktime(struct mktime * time);
77 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
78
79 extern void hd_setup(char *str, int *ints);
80 extern void bmouse_setup(char *str, int *ints);
81 extern void eth_setup(char *str, int *ints);
82
83 #ifdef CONFIG_SYSVIPC
84 extern void ipc_init(void);
85 #endif
86 #ifdef CONFIG_SCSI
87 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
88 #endif
89
90
91
92
93 #define PARAM empty_zero_page
94 #define EXT_MEM_K (*(unsigned short *) (PARAM+2))
95 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
96 #define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
97 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
98 #define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
99 #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
100 #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
101
102
103
104
105 #define MAX_INIT_ARGS 8
106 #define MAX_INIT_ENVS 8
107 #define COMMAND_LINE ((char *) (PARAM+2048))
108
109
110
111
112
113
114
115
116 #define CMOS_READ(addr) ({ \
117 outb_p(addr,0x70); \
118 inb_p(0x71); \
119 })
120
121 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
122
123 static void time_init(void)
124 {
125 struct mktime time;
126 int i;
127
128 for (i = 0 ; i < 1000000 ; i++)
129 if (!(CMOS_READ(10) & 0x80))
130 break;
131 do {
132 time.sec = CMOS_READ(0);
133 time.min = CMOS_READ(2);
134 time.hour = CMOS_READ(4);
135 time.day = CMOS_READ(7);
136 time.mon = CMOS_READ(8);
137 time.year = CMOS_READ(9);
138 } while (time.sec != CMOS_READ(0));
139 BCD_TO_BIN(time.sec);
140 BCD_TO_BIN(time.min);
141 BCD_TO_BIN(time.hour);
142 BCD_TO_BIN(time.day);
143 BCD_TO_BIN(time.mon);
144 BCD_TO_BIN(time.year);
145 time.mon--;
146 startup_time = kernel_mktime(&time);
147 }
148
149 static unsigned long memory_start = 0;
150
151 static unsigned long memory_end = 0;
152 static unsigned long low_memory_start = 0;
153
154 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
155 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=console", NULL, };
156
157 static char * argv_rc[] = { "/bin/sh", NULL };
158 static char * envp_rc[] = { "HOME=/", "TERM=console", NULL };
159
160 static char * argv[] = { "-/bin/sh",NULL };
161 static char * envp[] = { "HOME=/usr/root", "TERM=console", NULL };
162
163 struct drive_info_struct { char dummy[32]; } drive_info;
164 struct screen_info screen_info;
165
166 unsigned char aux_device_present;
167 int ramdisk_size;
168 int root_mountflags = 0;
169
170 static char fpu_error = 0;
171
172 static char command_line[80] = { 0, };
173
174 char *get_options(char *str, int *ints)
175 {
176 char *cur = str;
177 int i=1;
178
179 while (cur && isdigit(*cur) && i <= 10) {
180 ints[i++] = simple_strtoul(cur,NULL,0);
181 if ((cur = strchr(cur,',')) != NULL)
182 cur++;
183 }
184 ints[0] = i-1;
185 return(cur);
186 }
187
188 struct {
189 char *str;
190 void (*setup_func)(char *, int *);
191 } bootsetups[] = {
192 #ifdef CONFIG_INET
193 { "ether=", eth_setup },
194 #endif
195 #ifdef CONFIG_BLK_DEV_HD
196 { "hd=", hd_setup },
197 #endif
198 #ifdef CONFIG_BUSMOUSE
199 { "bmouse=", bmouse_setup },
200 #endif
201 { 0, 0 }
202 };
203
204 int checksetup(char *line)
205 {
206 int i = 0;
207 int ints[11];
208
209 while (bootsetups[i].str) {
210 int n = strlen(bootsetups[i].str);
211 if (!strncmp(line,bootsetups[i].str,n)) {
212 bootsetups[i].setup_func(get_options(line+n,ints), ints);
213 return(0);
214 }
215 i++;
216 }
217 return(1);
218 }
219
220 unsigned long loops_per_sec = 1;
221
222 static void calibrate_delay(void)
223 {
224 int ticks;
225
226 printk("Calibrating delay loop.. ");
227 while (loops_per_sec <<= 1) {
228 ticks = jiffies;
229 __delay(loops_per_sec);
230 ticks = jiffies - ticks;
231 if (ticks >= HZ) {
232 __asm__("mull %1 ; divl %2"
233 :"=a" (loops_per_sec)
234 :"d" (HZ),
235 "r" (ticks),
236 "0" (loops_per_sec)
237 :"dx");
238 printk("ok - %d.%02d BogoMips (tm)\n",
239 loops_per_sec/500000,
240 (loops_per_sec/5000) % 100);
241 return;
242 }
243 }
244 printk("failed\n");
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259 static void parse_options(char *line)
260 {
261 char *next;
262 char *devnames[] = { "hda", "hdb", "sda", "sdb", "sdc", "sdd", "sde", "fd", NULL };
263 int devnums[] = { 0x300, 0x340, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0};
264 int args, envs;
265
266 if (!*line)
267 return;
268 args = 0;
269 envs = 1;
270 next = line;
271 while ((line = next) != NULL) {
272 if ((next = strchr(line,' ')) != NULL)
273 *next++ = 0;
274
275
276
277 if (!strncmp(line,"root=",5)) {
278 int n;
279 line += 5;
280 if (strncmp(line,"/dev/",5)) {
281 ROOT_DEV = simple_strtoul(line,NULL,16);
282 continue;
283 }
284 line += 5;
285 for (n = 0 ; devnames[n] ; n++) {
286 int len = strlen(devnames[n]);
287 if (!strncmp(line,devnames[n],len)) {
288 ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,16);
289 break;
290 }
291 }
292 } else if (!strcmp(line,"ro"))
293 root_mountflags |= MS_RDONLY;
294 else if (!strcmp(line,"rw"))
295 root_mountflags &= ~MS_RDONLY;
296 else if (!strcmp(line,"no387")) {
297 hard_math = 0;
298 __asm__("movl %%cr0,%%eax\n\t"
299 "orl $0xE,%%eax\n\t"
300 "movl %%eax,%%cr0\n\t" : : : "ax");
301 } else
302 checksetup(line);
303
304
305
306
307 if (strchr(line,'=')) {
308 if (envs >= MAX_INIT_ENVS)
309 break;
310 envp_init[++envs] = line;
311 } else {
312 if (args >= MAX_INIT_ARGS)
313 break;
314 argv_init[++args] = line;
315 }
316 }
317 argv_init[args+1] = NULL;
318 envp_init[envs+1] = NULL;
319 }
320
321 static void copro_timeout(void)
322 {
323 fpu_error = 1;
324 timer_table[COPRO_TIMER].expires = jiffies+100;
325 timer_active |= 1<<COPRO_TIMER;
326 printk("387 failed: trying to reset\n");
327 send_sig(SIGFPE, last_task_used_math, 1);
328 outb_p(0,0xf1);
329 outb_p(0,0xf0);
330 }
331
332 extern "C" void start_kernel(void)
333 {
334
335
336
337
338 set_call_gate(&default_ldt,lcall7);
339 ROOT_DEV = ORIG_ROOT_DEV;
340 drive_info = DRIVE_INFO;
341 screen_info = SCREEN_INFO;
342 aux_device_present = AUX_DEVICE_INFO;
343 memory_end = (1<<20) + (EXT_MEM_K<<10);
344 memory_end &= PAGE_MASK;
345 ramdisk_size = RAMDISK_SIZE;
346 strcpy(command_line,COMMAND_LINE);
347 #ifdef CONFIG_MAX_16M
348 if (memory_end > 16*1024*1024)
349 memory_end = 16*1024*1024;
350 #endif
351 if (MOUNT_ROOT_RDONLY)
352 root_mountflags |= MS_RDONLY;
353 if ((unsigned long)&end >= (1024*1024)) {
354 memory_start = (unsigned long) &end;
355 low_memory_start = PAGE_SIZE;
356 } else {
357 memory_start = 1024*1024;
358 low_memory_start = (unsigned long) &end;
359 }
360 low_memory_start = PAGE_ALIGN(low_memory_start);
361 memory_start = paging_init(memory_start,memory_end);
362 trap_init();
363 init_IRQ();
364 sched_init();
365 parse_options(command_line);
366 #ifdef CONFIG_PROFILE
367 prof_buffer = (unsigned long *) memory_start;
368 prof_len = (unsigned long) &end;
369 prof_len >>= 2;
370 memory_start += prof_len * sizeof(unsigned long);
371 #endif
372 memory_start = chr_dev_init(memory_start,memory_end);
373 memory_start = blk_dev_init(memory_start,memory_end);
374 #ifdef CONFIG_SCSI
375 memory_start = scsi_dev_init(memory_start,memory_end);
376 #endif
377 memory_start = inode_init(memory_start,memory_end);
378 memory_start = file_table_init(memory_start,memory_end);
379 mem_init(low_memory_start,memory_start,memory_end);
380 buffer_init();
381 time_init();
382 floppy_init();
383 sock_init();
384 #ifdef CONFIG_SYSVIPC
385 ipc_init();
386 #endif
387 sti();
388 calibrate_delay();
389
390
391
392
393
394
395
396
397
398 if (hard_math) {
399 unsigned short control_word;
400
401 printk("Checking 386/387 coupling... ");
402 timer_table[COPRO_TIMER].expires = jiffies+50;
403 timer_table[COPRO_TIMER].fn = copro_timeout;
404 timer_active |= 1<<COPRO_TIMER;
405 __asm__("clts ; fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
406 control_word &= 0xffc0;
407 __asm__("fldcw %0 ; fwait": :"m" (*&control_word));
408 outb_p(inb_p(0x21) | (1 << 2), 0x21);
409 __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
410 timer_active &= ~(1<<COPRO_TIMER);
411 if (!fpu_error)
412 printk("Ok, fpu using %s error reporting.\n",
413 ignore_irq13?"exception 16":"irq13");
414 }
415 #ifndef CONFIG_MATH_EMULATION
416 else {
417 printk("No coprocessor found and no math emulation present.\n");
418 printk("Giving up.\n");
419 for (;;) ;
420 }
421 #endif
422 move_to_user_mode();
423 if (!fork())
424 init();
425
426
427
428
429
430
431
432
433
434 for(;;)
435 idle();
436 }
437
438 static int printf(const char *fmt, ...)
439 {
440 va_list args;
441 int i;
442
443 va_start(args, fmt);
444 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
445 va_end(args);
446 return i;
447 }
448
449 void init(void)
450 {
451 int pid,i;
452
453 setup((void *) &drive_info);
454 (void) open("/dev/tty1",O_RDWR,0);
455 (void) dup(0);
456 (void) dup(0);
457
458 system_utsname.machine[1] = '0' + x86;
459 printf(linux_banner);
460
461 execve("/etc/init",argv_init,envp_init);
462 execve("/bin/init",argv_init,envp_init);
463 execve("/sbin/init",argv_init,envp_init);
464
465
466 if (!(pid=fork())) {
467 close(0);
468 if (open("/etc/rc",O_RDONLY,0))
469 exit(1);
470 execve("/bin/sh",argv_rc,envp_rc);
471 exit(2);
472 }
473 if (pid>0)
474 while (pid != wait(&i))
475 ;
476 while (1) {
477 if ((pid = fork()) < 0) {
478 printf("Fork failed in init\n\r");
479 continue;
480 }
481 if (!pid) {
482 close(0);close(1);close(2);
483 setsid();
484 (void) open("/dev/tty1",O_RDWR,0);
485 (void) dup(0);
486 (void) dup(0);
487 exit(execve("/bin/sh",argv,envp));
488 }
489 while (1)
490 if (pid == wait(&i))
491 break;
492 printf("\n\rchild %d died with code %04x\n\r",pid,i);
493 sync();
494 }
495 exit(0);
496 }