This source file includes following definitions.
- _syscall0
- get_options
- ramdisk_setup
- checksetup
- calibrate_delay
- parse_options
- copy_options
- 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 #include <linux/hdreg.h>
27
28 #include <asm/bugs.h>
29
30 extern unsigned long * prof_buffer;
31 extern unsigned long prof_len;
32 extern char etext, end;
33 extern char *linux_banner;
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #define __NR__exit __NR_exit
48 static inline _syscall0(int,idle)
49 static inline _syscall0(int,fork)
50 static inline _syscall0(int,pause)
51 static inline _syscall0(int,setup)
52 static inline _syscall0(int,sync)
53 static inline _syscall0(pid_t,setsid)
54 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
55 static inline _syscall1(int,dup,int,fd)
56 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
57 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
58 static inline _syscall1(int,close,int,fd)
59 static inline _syscall1(int,_exit,int,exitcode)
60 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
61
62 static inline pid_t wait(int * wait_stat)
63 {
64 return waitpid(-1,wait_stat,0);
65 }
66
67 static char printbuf[1024];
68
69 extern int console_loglevel;
70
71 extern char empty_zero_page[PAGE_SIZE];
72 extern void init(void);
73 extern void init_IRQ(void);
74 extern void init_modules(void);
75 extern long console_init(long, long);
76 extern long kmalloc_init(long,long);
77 extern long blk_dev_init(long,long);
78 extern long chr_dev_init(long,long);
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 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 buslogic_setup(char *str, int *ints);
99 extern void scsi_luns_setup(char *str, int *ints);
100 extern void sound_setup(char *str, int *ints);
101 extern void sock_setup(char *str, int *ints);
102 #ifdef CONFIG_SBPCD
103 extern void sbpcd_setup(char *str, int *ints);
104 #endif CONFIG_SBPCD
105 #ifdef CONFIG_CDU31A
106 extern void cdu31a_setup(char *str, int *ints);
107 #endif CONFIG_CDU31A
108 void ramdisk_setup(char *str, int *ints);
109
110 #ifdef CONFIG_SYSVIPC
111 extern void ipc_init(void);
112 #endif
113 #ifdef CONFIG_SCSI
114 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
115 #endif
116
117
118
119
120 #define PARAM empty_zero_page
121 #define EXT_MEM_K (*(unsigned short *) (PARAM+2))
122 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
123 #define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
124 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
125 #define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
126 #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
127 #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
128
129
130
131
132 #define MAX_INIT_ARGS 8
133 #define MAX_INIT_ENVS 8
134 #define COMMAND_LINE ((char *) (PARAM+2048))
135 #define COMMAND_LINE_SIZE 256
136
137 extern void time_init(void);
138
139 static unsigned long memory_start = 0;
140
141 static unsigned long memory_end = 0;
142 static unsigned long low_memory_start = 0;
143
144 static char term[21];
145 int rows, cols;
146
147 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
148 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
149
150 static char * argv_rc[] = { "/bin/sh", NULL };
151 static char * envp_rc[] = { "HOME=/", term, NULL };
152
153 static char * argv[] = { "-/bin/sh",NULL };
154 static char * envp[] = { "HOME=/usr/root", term, NULL };
155
156 struct drive_info_struct { char dummy[32]; } drive_info;
157 struct screen_info screen_info;
158
159 unsigned char aux_device_present;
160 int ramdisk_size;
161 int root_mountflags = 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_BUGi386
186 { "no-hlt", no_halt },
187 { "no387", no_387 },
188 #endif
189 #ifdef CONFIG_INET
190 { "ether=", eth_setup },
191 #endif
192 #ifdef CONFIG_SCSI
193 { "max_scsi_luns=", scsi_luns_setup },
194 #endif
195 #ifdef CONFIG_BLK_DEV_IDE
196 { "hda=", hda_setup },
197 { "hdb=", hdb_setup },
198 { "hdc=", hdc_setup },
199 { "hdd=", hdd_setup },
200 { "hd=", ide_setup },
201 #elif defined(CONFIG_BLK_DEV_HD)
202 { "hd=", hd_setup },
203 #endif
204 #ifdef CONFIG_CHR_DEV_ST
205 { "st=", st_setup },
206 #endif
207 #ifdef CONFIG_BUSMOUSE
208 { "bmouse=", bmouse_setup },
209 #endif
210 #ifdef CONFIG_SCSI_SEAGATE
211 { "st0x=", st0x_setup },
212 { "tmc8xx=", tmc8xx_setup },
213 #endif
214 #ifdef CONFIG_SCSI_T128
215 { "t128=", t128_setup },
216 #endif
217 #ifdef CONFIG_SCSI_PAS16
218 { "pas16=", pas16_setup },
219 #endif
220 #ifdef CONFIG_SCSI_GENERIC_NCR5380
221 { "ncr5380=", generic_NCR5380_setup },
222 #endif
223 #ifdef CONFIG_SCSI_AHA152X
224 { "aha152x=", aha152x_setup},
225 #endif
226 #ifdef CONFIG_SCSI_AHA1542
227 { "aha1542=", aha1542_setup},
228 #endif
229 #ifdef CONFIG_SCSI_AHA274X
230 { "aha274x=", aha274x_setup},
231 #endif
232 #ifdef CONFIG_SCSI_BUSLOGIC
233 { "buslogic=", buslogic_setup},
234 #endif
235 #ifdef CONFIG_BLK_DEV_XD
236 { "xd=", xd_setup },
237 #endif
238 #ifdef CONFIG_BLK_DEV_FD
239 { "floppy=", floppy_setup },
240 #endif
241 #ifdef CONFIG_MCD
242 { "mcd=", mcd_setup },
243 #endif
244 #ifdef CONFIG_SOUND
245 { "sound=", sound_setup },
246 #endif
247 #ifdef CONFIG_SBPCD
248 { "sbpcd=", sbpcd_setup },
249 #endif CONFIG_SBPCD
250 #ifdef CONFIG_CDU31A
251 { "cdu31a=", cdu31a_setup },
252 #endif CONFIG_CDU31A
253 { 0, 0 }
254 };
255
256 void ramdisk_setup(char *str, int *ints)
257 {
258 if (ints[0] > 0 && ints[1] >= 0)
259 ramdisk_size = ints[1];
260 }
261
262 static int checksetup(char *line)
263 {
264 int i = 0;
265 int ints[11];
266
267 while (bootsetups[i].str) {
268 int n = strlen(bootsetups[i].str);
269 if (!strncmp(line,bootsetups[i].str,n)) {
270 bootsetups[i].setup_func(get_options(line+n,ints), ints);
271 return 1;
272 }
273 i++;
274 }
275 return 0;
276 }
277
278 unsigned long loops_per_sec = 1;
279
280 static void calibrate_delay(void)
281 {
282 int ticks;
283
284 printk("Calibrating delay loop.. ");
285 while (loops_per_sec <<= 1) {
286
287 ticks = jiffies;
288 while (ticks == jiffies)
289 ;
290
291 ticks = jiffies;
292 __delay(loops_per_sec);
293 ticks = jiffies - ticks;
294 if (ticks >= HZ) {
295 loops_per_sec = muldiv(loops_per_sec, HZ, ticks);
296 printk("ok - %lu.%02lu BogoMips\n",
297 loops_per_sec/500000,
298 (loops_per_sec/5000) % 100);
299 return;
300 }
301 }
302 printk("failed\n");
303 }
304
305
306
307
308
309
310
311
312
313
314
315
316 static void parse_options(char *line)
317 {
318 char *next;
319 char *devnames[] = { "hda", "hdb", "hdc", "hdd", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
320 int devnums[] = { 0x300, 0x340, 0x1600, 0x1640, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
321 int args, envs;
322
323 if (!*line)
324 return;
325 args = 0;
326 envs = 1;
327 next = line;
328 while ((line = next) != NULL) {
329 if ((next = strchr(line,' ')) != NULL)
330 *next++ = 0;
331
332
333
334 if (!strncmp(line,"root=",5)) {
335 int n;
336 line += 5;
337 if (strncmp(line,"/dev/",5)) {
338 ROOT_DEV = simple_strtoul(line,NULL,16);
339 continue;
340 }
341 line += 5;
342 for (n = 0 ; devnames[n] ; n++) {
343 int len = strlen(devnames[n]);
344 if (!strncmp(line,devnames[n],len)) {
345 ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
346 break;
347 }
348 }
349 continue;
350 }
351 if (!strcmp(line,"ro")) {
352 root_mountflags |= MS_RDONLY;
353 continue;
354 }
355 if (!strcmp(line,"rw")) {
356 root_mountflags &= ~MS_RDONLY;
357 continue;
358 }
359 if (!strcmp(line,"debug")) {
360 console_loglevel = 10;
361 continue;
362 }
363 if (checksetup(line))
364 continue;
365
366
367
368
369 if (strchr(line,'=')) {
370 if (envs >= MAX_INIT_ENVS)
371 break;
372 envp_init[++envs] = line;
373 } else {
374 if (args >= MAX_INIT_ARGS)
375 break;
376 argv_init[++args] = line;
377 }
378 }
379 argv_init[args+1] = NULL;
380 envp_init[envs+1] = NULL;
381 }
382
383 static void copy_options(char * to, char * from)
384 {
385 char c = ' ';
386 int len = 0;
387
388 for (;;) {
389 if (c == ' ' && *(unsigned long *)from == *(unsigned long *)"mem=") {
390 memory_end = simple_strtoul(from+4, &from, 0);
391 if ( *from == 'K' || *from == 'k' ) {
392 memory_end = memory_end << 10;
393 from++;
394 } else if ( *from == 'M' || *from == 'm' ) {
395 memory_end = memory_end << 20;
396 from++;
397 }
398 }
399 c = *(from++);
400 if (!c)
401 break;
402 if (COMMAND_LINE_SIZE <= ++len)
403 break;
404 *(to++) = c;
405 }
406 *to = '\0';
407 }
408
409 extern void check_bugs(void);
410
411 asmlinkage void start_kernel(void)
412 {
413
414
415
416
417 ROOT_DEV = ORIG_ROOT_DEV;
418 drive_info = DRIVE_INFO;
419 screen_info = SCREEN_INFO;
420 aux_device_present = AUX_DEVICE_INFO;
421 memory_end = (1<<20) + (EXT_MEM_K<<10);
422 memory_end &= PAGE_MASK;
423 ramdisk_size = RAMDISK_SIZE;
424 copy_options(command_line,COMMAND_LINE);
425 #ifdef CONFIG_MAX_16M
426 if (memory_end > 16*1024*1024)
427 memory_end = 16*1024*1024;
428 #endif
429 if (MOUNT_ROOT_RDONLY)
430 root_mountflags |= MS_RDONLY;
431 if ((unsigned long)&end >= (1024*1024)) {
432 memory_start = (unsigned long) &end;
433 low_memory_start = PAGE_SIZE;
434 } else {
435 memory_start = 1024*1024;
436 low_memory_start = (unsigned long) &end;
437 }
438 low_memory_start = PAGE_ALIGN(low_memory_start);
439 memory_start = paging_init(memory_start,memory_end);
440 if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0)
441 EISA_bus = 1;
442 trap_init();
443 init_IRQ();
444 sched_init();
445 parse_options(command_line);
446 init_modules();
447 #ifdef CONFIG_PROFILE
448 prof_buffer = (unsigned long *) memory_start;
449
450 prof_len = (unsigned long) &etext;
451 prof_len >>= CONFIG_PROFILE_SHIFT;
452 memory_start += prof_len * sizeof(unsigned long);
453 #endif
454 memory_start = console_init(memory_start,memory_end);
455 memory_start = bios32_init(memory_start,memory_end);
456 memory_start = kmalloc_init(memory_start,memory_end);
457 sti();
458 calibrate_delay();
459 cli();
460 memory_start = chr_dev_init(memory_start,memory_end);
461 memory_start = blk_dev_init(memory_start,memory_end);
462 sti();
463 #ifdef CONFIG_SCSI
464 memory_start = scsi_dev_init(memory_start,memory_end);
465 #endif
466 #ifdef CONFIG_INET
467 memory_start = net_dev_init(memory_start,memory_end);
468 #endif
469 memory_start = inode_init(memory_start,memory_end);
470 memory_start = file_table_init(memory_start,memory_end);
471 memory_start = name_cache_init(memory_start,memory_end);
472 mem_init(low_memory_start,memory_start,memory_end);
473 buffer_init();
474 time_init();
475 sock_init();
476 #ifdef CONFIG_SYSVIPC
477 ipc_init();
478 #endif
479 sti();
480 check_bugs();
481
482 printk(linux_banner);
483
484 move_to_user_mode();
485 if (!fork())
486 init();
487
488
489
490
491
492
493
494
495
496 for(;;)
497 idle();
498 }
499
500 static int printf(const char *fmt, ...)
501 {
502 va_list args;
503 int i;
504
505 va_start(args, fmt);
506 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
507 va_end(args);
508 return i;
509 }
510
511 void init(void)
512 {
513 int pid,i;
514
515 setup();
516 sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
517
518 #ifdef CONFIG_UMSDOS_FS
519 {
520
521
522
523
524
525 extern struct inode *pseudo_root;
526 if (pseudo_root != NULL){
527 current->fs->root = pseudo_root;
528 current->fs->pwd = pseudo_root;
529 }
530 }
531 #endif
532
533 (void) open("/dev/tty1",O_RDWR,0);
534 (void) dup(0);
535 (void) dup(0);
536
537 execve("/etc/init",argv_init,envp_init);
538 execve("/bin/init",argv_init,envp_init);
539 execve("/sbin/init",argv_init,envp_init);
540
541
542 if (!(pid=fork())) {
543 close(0);
544 if (open("/etc/rc",O_RDONLY,0))
545 _exit(1);
546 execve("/bin/sh",argv_rc,envp_rc);
547 _exit(2);
548 }
549 if (pid>0)
550 while (pid != wait(&i))
551 ;
552 while (1) {
553 if ((pid = fork()) < 0) {
554 printf("Fork failed in init\n\r");
555 continue;
556 }
557 if (!pid) {
558 close(0);close(1);close(2);
559 setsid();
560 (void) open("/dev/tty1",O_RDWR,0);
561 (void) dup(0);
562 (void) dup(0);
563 _exit(execve("/bin/sh",argv,envp));
564 }
565 while (1)
566 if (pid == wait(&i))
567 break;
568 printf("\n\rchild %d died with code %04x\n\r",pid,i);
569 sync();
570 }
571 _exit(0);
572 }