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