This source file includes following definitions.
- _syscall0
- get_options
- ramdisk_setup
- checksetup
- calibrate_delay
- parse_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 #include <linux/mm.h>
28
29 #include <asm/bugs.h>
30
31 extern unsigned long * prof_buffer;
32 extern unsigned long prof_len;
33 extern char etext, end;
34 extern char *linux_banner;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #define __NR__exit __NR_exit
49 static inline _syscall0(int,idle)
50 static inline _syscall0(int,fork)
51 static inline _syscall0(int,pause)
52 static inline _syscall0(int,setup)
53 static inline _syscall0(int,sync)
54 static inline _syscall0(pid_t,setsid)
55 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
56 static inline _syscall1(int,dup,int,fd)
57 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
58 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
59 static inline _syscall1(int,close,int,fd)
60 static inline _syscall1(int,_exit,int,exitcode)
61 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
62
63 static inline pid_t wait(int * wait_stat)
64 {
65 return waitpid(-1,wait_stat,0);
66 }
67
68 static char printbuf[1024];
69
70 extern int console_loglevel;
71
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 aztcd_setup(char *str, int *ints);
90 extern void st_setup(char *str, int *ints);
91 extern void st0x_setup(char *str, int *ints);
92 extern void tmc8xx_setup(char *str, int *ints);
93 extern void t128_setup(char *str, int *ints);
94 extern void pas16_setup(char *str, int *ints);
95 extern void generic_NCR5380_setup(char *str, int *intr);
96 extern void aha152x_setup(char *str, int *ints);
97 extern void aha1542_setup(char *str, int *ints);
98 extern void aha274x_setup(char *str, int *ints);
99 extern void buslogic_setup(char *str, int *ints);
100 extern void scsi_luns_setup(char *str, int *ints);
101 extern void sound_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 #ifdef CONFIG_CDU535
109 extern void sonycd535_setup(char *str, int *ints);
110 #endif CONFIG_CDU535
111 void ramdisk_setup(char *str, int *ints);
112
113 #ifdef CONFIG_SYSVIPC
114 extern void ipc_init(void);
115 #endif
116 #ifdef CONFIG_SCSI
117 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
118 #endif
119
120
121
122
123 #define MAX_INIT_ARGS 8
124 #define MAX_INIT_ENVS 8
125
126 extern void time_init(void);
127
128 static unsigned long memory_start = 0;
129 static unsigned long memory_end = 0;
130
131 static char term[21];
132 int rows, cols;
133
134 int ramdisk_size;
135 int root_mountflags = 0;
136
137 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
138 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
139
140 static char * argv_rc[] = { "/bin/sh", NULL };
141 static char * envp_rc[] = { "HOME=/", term, NULL };
142
143 static char * argv[] = { "-/bin/sh",NULL };
144 static char * envp[] = { "HOME=/usr/root", term, NULL };
145
146 char *get_options(char *str, int *ints)
147 {
148 char *cur = str;
149 int i=1;
150
151 while (cur && isdigit(*cur) && i <= 10) {
152 ints[i++] = simple_strtoul(cur,NULL,0);
153 if ((cur = strchr(cur,',')) != NULL)
154 cur++;
155 }
156 ints[0] = i-1;
157 return(cur);
158 }
159
160 struct {
161 char *str;
162 void (*setup_func)(char *, int *);
163 } bootsetups[] = {
164 { "reserve=", reserve_setup },
165 { "ramdisk=", ramdisk_setup },
166 #ifdef CONFIG_BUGi386
167 { "no-hlt", no_halt },
168 { "no387", no_387 },
169 #endif
170 #ifdef CONFIG_INET
171 { "ether=", eth_setup },
172 #endif
173 #ifdef CONFIG_SCSI
174 { "max_scsi_luns=", scsi_luns_setup },
175 #endif
176 #ifdef CONFIG_BLK_DEV_IDE
177 { "hda=", hda_setup },
178 { "hdb=", hdb_setup },
179 { "hdc=", hdc_setup },
180 { "hdd=", hdd_setup },
181 { "hd=", ide_setup },
182 #elif defined(CONFIG_BLK_DEV_HD)
183 { "hd=", hd_setup },
184 #endif
185 #ifdef CONFIG_CHR_DEV_ST
186 { "st=", st_setup },
187 #endif
188 #ifdef CONFIG_BUSMOUSE
189 { "bmouse=", bmouse_setup },
190 #endif
191 #ifdef CONFIG_SCSI_SEAGATE
192 { "st0x=", st0x_setup },
193 { "tmc8xx=", tmc8xx_setup },
194 #endif
195 #ifdef CONFIG_SCSI_T128
196 { "t128=", t128_setup },
197 #endif
198 #ifdef CONFIG_SCSI_PAS16
199 { "pas16=", pas16_setup },
200 #endif
201 #ifdef CONFIG_SCSI_GENERIC_NCR5380
202 { "ncr5380=", generic_NCR5380_setup },
203 #endif
204 #ifdef CONFIG_SCSI_AHA152X
205 { "aha152x=", aha152x_setup},
206 #endif
207 #ifdef CONFIG_SCSI_AHA1542
208 { "aha1542=", aha1542_setup},
209 #endif
210 #ifdef CONFIG_SCSI_AHA274X
211 { "aha274x=", aha274x_setup},
212 #endif
213 #ifdef CONFIG_SCSI_BUSLOGIC
214 { "buslogic=", buslogic_setup},
215 #endif
216 #ifdef CONFIG_BLK_DEV_XD
217 { "xd=", xd_setup },
218 #endif
219 #ifdef CONFIG_BLK_DEV_FD
220 { "floppy=", floppy_setup },
221 #endif
222 #ifdef CONFIG_MCD
223 { "mcd=", mcd_setup },
224 #endif
225 #ifdef CONFIG_AZTCD
226 { "aztcd=", aztcd_setup },
227 #endif
228 #ifdef CONFIG_CDU535
229 { "sonycd535=", sonycd535_setup },
230 #endif CONFIG_CDU535
231 #ifdef CONFIG_SOUND
232 { "sound=", sound_setup },
233 #endif
234 #ifdef CONFIG_SBPCD
235 { "sbpcd=", sbpcd_setup },
236 #endif CONFIG_SBPCD
237 #ifdef CONFIG_CDU31A
238 { "cdu31a=", cdu31a_setup },
239 #endif CONFIG_CDU31A
240 { 0, 0 }
241 };
242
243 void ramdisk_setup(char *str, int *ints)
244 {
245 if (ints[0] > 0 && ints[1] >= 0)
246 ramdisk_size = ints[1];
247 }
248
249 static int checksetup(char *line)
250 {
251 int i = 0;
252 int ints[11];
253
254 while (bootsetups[i].str) {
255 int n = strlen(bootsetups[i].str);
256 if (!strncmp(line,bootsetups[i].str,n)) {
257 bootsetups[i].setup_func(get_options(line+n,ints), ints);
258 return 1;
259 }
260 i++;
261 }
262 return 0;
263 }
264
265 unsigned long loops_per_sec = 1;
266
267 static void calibrate_delay(void)
268 {
269 int ticks;
270
271 printk("Calibrating delay loop.. ");
272 while (loops_per_sec <<= 1) {
273
274 ticks = jiffies;
275 while (ticks == jiffies)
276 ;
277
278 ticks = jiffies;
279 __delay(loops_per_sec);
280 ticks = jiffies - ticks;
281 if (ticks >= HZ) {
282 loops_per_sec = muldiv(loops_per_sec, HZ, ticks);
283 printk("ok - %lu.%02lu BogoMips\n",
284 loops_per_sec/500000,
285 (loops_per_sec/5000) % 100);
286 return;
287 }
288 }
289 printk("failed\n");
290 }
291
292
293
294
295
296
297
298
299
300
301
302
303 static void parse_options(char *line)
304 {
305 char *next;
306 char *devnames[] = { "hda", "hdb", "hdc", "hdd", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
307 int devnums[] = { 0x300, 0x340, 0x1600, 0x1640, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
308 int args, envs;
309
310 if (!*line)
311 return;
312 args = 0;
313 envs = 1;
314 next = line;
315 while ((line = next) != NULL) {
316 if ((next = strchr(line,' ')) != NULL)
317 *next++ = 0;
318
319
320
321 if (!strncmp(line,"root=",5)) {
322 int n;
323 line += 5;
324 if (strncmp(line,"/dev/",5)) {
325 ROOT_DEV = simple_strtoul(line,NULL,16);
326 continue;
327 }
328 line += 5;
329 for (n = 0 ; devnames[n] ; n++) {
330 int len = strlen(devnames[n]);
331 if (!strncmp(line,devnames[n],len)) {
332 ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
333 break;
334 }
335 }
336 continue;
337 }
338 if (!strcmp(line,"ro")) {
339 root_mountflags |= MS_RDONLY;
340 continue;
341 }
342 if (!strcmp(line,"rw")) {
343 root_mountflags &= ~MS_RDONLY;
344 continue;
345 }
346 if (!strcmp(line,"debug")) {
347 console_loglevel = 10;
348 continue;
349 }
350 if (checksetup(line))
351 continue;
352
353
354
355
356 if (strchr(line,'=')) {
357 if (envs >= MAX_INIT_ENVS)
358 break;
359 envp_init[++envs] = line;
360 } else {
361 if (args >= MAX_INIT_ARGS)
362 break;
363 argv_init[++args] = line;
364 }
365 }
366 argv_init[args+1] = NULL;
367 envp_init[envs+1] = NULL;
368 }
369
370 extern void check_bugs(void);
371 extern void setup_arch(char **, unsigned long *, unsigned long *);
372
373 asmlinkage void start_kernel(void)
374 {
375 char * command_line;
376
377
378
379
380 setup_arch(&command_line, &memory_start, &memory_end);
381 memory_start = paging_init(memory_start,memory_end);
382 trap_init();
383 init_IRQ();
384 sched_init();
385 parse_options(command_line);
386 init_modules();
387 #ifdef CONFIG_PROFILE
388 prof_buffer = (unsigned long *) memory_start;
389
390 prof_len = (unsigned long) &etext;
391 prof_len >>= CONFIG_PROFILE_SHIFT;
392 memory_start += prof_len * sizeof(unsigned long);
393 #endif
394 memory_start = console_init(memory_start,memory_end);
395 memory_start = bios32_init(memory_start,memory_end);
396 memory_start = kmalloc_init(memory_start,memory_end);
397 sti();
398 calibrate_delay();
399 memory_start = chr_dev_init(memory_start,memory_end);
400 memory_start = blk_dev_init(memory_start,memory_end);
401 sti();
402 #ifdef CONFIG_SCSI
403 memory_start = scsi_dev_init(memory_start,memory_end);
404 #endif
405 #ifdef CONFIG_INET
406 memory_start = net_dev_init(memory_start,memory_end);
407 #endif
408 memory_start = inode_init(memory_start,memory_end);
409 memory_start = file_table_init(memory_start,memory_end);
410 memory_start = name_cache_init(memory_start,memory_end);
411 mem_init(memory_start,memory_end);
412 buffer_init();
413 time_init();
414 sock_init();
415 #ifdef CONFIG_SYSVIPC
416 ipc_init();
417 #endif
418 sti();
419 check_bugs();
420
421 printk(linux_banner);
422
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();
454 sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
455
456 #ifdef CONFIG_UMSDOS_FS
457 {
458
459
460
461
462
463 extern struct inode *pseudo_root;
464 if (pseudo_root != NULL){
465 current->fs->root = pseudo_root;
466 current->fs->pwd = pseudo_root;
467 }
468 }
469 #endif
470
471 (void) open("/dev/tty1",O_RDWR,0);
472 (void) dup(0);
473 (void) dup(0);
474
475 execve("/etc/init",argv_init,envp_init);
476 execve("/bin/init",argv_init,envp_init);
477 execve("/sbin/init",argv_init,envp_init);
478
479
480 if (!(pid=fork())) {
481 close(0);
482 if (open("/etc/rc",O_RDONLY,0))
483 _exit(1);
484 execve("/bin/sh",argv_rc,envp_rc);
485 _exit(2);
486 }
487 if (pid>0)
488 while (pid != wait(&i))
489 ;
490 while (1) {
491 if ((pid = fork()) < 0) {
492 printf("Fork failed in init\n\r");
493 continue;
494 }
495 if (!pid) {
496 close(0);close(1);close(2);
497 setsid();
498 (void) open("/dev/tty1",O_RDWR,0);
499 (void) dup(0);
500 (void) dup(0);
501 _exit(execve("/bin/sh",argv,envp));
502 }
503 while (1)
504 if (pid == wait(&i))
505 break;
506 printf("\n\rchild %d died with code %04x\n\r",pid,i);
507 sync();
508 }
509 _exit(0);
510 }