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
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 void init(void);
72 extern void init_IRQ(void);
73 extern void init_modules(void);
74 extern long console_init(long, long);
75 extern long kmalloc_init(long,long);
76 extern long blk_dev_init(long,long);
77 extern long chr_dev_init(long,long);
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 extern long bios32_init(long, long);
82
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 floppy_setup(char *str, int *ints);
87 extern void mcd_setup(char *str, int *ints);
88 extern void aztcd_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 MAX_INIT_ARGS 8
120 #define MAX_INIT_ENVS 8
121
122 extern void time_init(void);
123
124 static unsigned long memory_start = 0;
125 static unsigned long memory_end = 0;
126
127 static char term[21];
128 int rows, cols;
129
130 int ramdisk_size;
131 int root_mountflags = 0;
132
133 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
134 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
135
136 static char * argv_rc[] = { "/bin/sh", NULL };
137 static char * envp_rc[] = { "HOME=/", term, NULL };
138
139 static char * argv[] = { "-/bin/sh",NULL };
140 static char * envp[] = { "HOME=/usr/root", term, NULL };
141
142 char *get_options(char *str, int *ints)
143 {
144 char *cur = str;
145 int i=1;
146
147 while (cur && isdigit(*cur) && i <= 10) {
148 ints[i++] = simple_strtoul(cur,NULL,0);
149 if ((cur = strchr(cur,',')) != NULL)
150 cur++;
151 }
152 ints[0] = i-1;
153 return(cur);
154 }
155
156 struct {
157 char *str;
158 void (*setup_func)(char *, int *);
159 } bootsetups[] = {
160 { "reserve=", reserve_setup },
161 { "ramdisk=", ramdisk_setup },
162 #ifdef CONFIG_BUGi386
163 { "no-hlt", no_halt },
164 { "no387", no_387 },
165 #endif
166 #ifdef CONFIG_INET
167 { "ether=", eth_setup },
168 #endif
169 #ifdef CONFIG_SCSI
170 { "max_scsi_luns=", scsi_luns_setup },
171 #endif
172 #ifdef CONFIG_BLK_DEV_IDE
173 { "hda=", hda_setup },
174 { "hdb=", hdb_setup },
175 { "hdc=", hdc_setup },
176 { "hdd=", hdd_setup },
177 { "hd=", ide_setup },
178 #elif defined(CONFIG_BLK_DEV_HD)
179 { "hd=", hd_setup },
180 #endif
181 #ifdef CONFIG_CHR_DEV_ST
182 { "st=", st_setup },
183 #endif
184 #ifdef CONFIG_BUSMOUSE
185 { "bmouse=", bmouse_setup },
186 #endif
187 #ifdef CONFIG_SCSI_SEAGATE
188 { "st0x=", st0x_setup },
189 { "tmc8xx=", tmc8xx_setup },
190 #endif
191 #ifdef CONFIG_SCSI_T128
192 { "t128=", t128_setup },
193 #endif
194 #ifdef CONFIG_SCSI_PAS16
195 { "pas16=", pas16_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_SCSI_AHA1542
204 { "aha1542=", aha1542_setup},
205 #endif
206 #ifdef CONFIG_SCSI_AHA274X
207 { "aha274x=", aha274x_setup},
208 #endif
209 #ifdef CONFIG_SCSI_BUSLOGIC
210 { "buslogic=", buslogic_setup},
211 #endif
212 #ifdef CONFIG_BLK_DEV_XD
213 { "xd=", xd_setup },
214 #endif
215 #ifdef CONFIG_BLK_DEV_FD
216 { "floppy=", floppy_setup },
217 #endif
218 #ifdef CONFIG_MCD
219 { "mcd=", mcd_setup },
220 #endif
221 #ifdef CONFIG_AZTCD
222 { "aztcd=", aztcd_setup },
223 #endif
224 #ifdef CONFIG_SOUND
225 { "sound=", sound_setup },
226 #endif
227 #ifdef CONFIG_SBPCD
228 { "sbpcd=", sbpcd_setup },
229 #endif CONFIG_SBPCD
230 #ifdef CONFIG_CDU31A
231 { "cdu31a=", cdu31a_setup },
232 #endif CONFIG_CDU31A
233 { 0, 0 }
234 };
235
236 void ramdisk_setup(char *str, int *ints)
237 {
238 if (ints[0] > 0 && ints[1] >= 0)
239 ramdisk_size = ints[1];
240 }
241
242 static int checksetup(char *line)
243 {
244 int i = 0;
245 int ints[11];
246
247 while (bootsetups[i].str) {
248 int n = strlen(bootsetups[i].str);
249 if (!strncmp(line,bootsetups[i].str,n)) {
250 bootsetups[i].setup_func(get_options(line+n,ints), ints);
251 return 1;
252 }
253 i++;
254 }
255 return 0;
256 }
257
258 unsigned long loops_per_sec = 1;
259
260 static void calibrate_delay(void)
261 {
262 int ticks;
263
264 printk("Calibrating delay loop.. ");
265 while (loops_per_sec <<= 1) {
266
267 ticks = jiffies;
268 while (ticks == jiffies)
269 ;
270
271 ticks = jiffies;
272 __delay(loops_per_sec);
273 ticks = jiffies - ticks;
274 if (ticks >= HZ) {
275 loops_per_sec = muldiv(loops_per_sec, HZ, ticks);
276 printk("ok - %lu.%02lu BogoMips\n",
277 loops_per_sec/500000,
278 (loops_per_sec/5000) % 100);
279 return;
280 }
281 }
282 printk("failed\n");
283 }
284
285
286
287
288
289
290
291
292
293
294
295
296 static void parse_options(char *line)
297 {
298 char *next;
299 char *devnames[] = { "hda", "hdb", "hdc", "hdd", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
300 int devnums[] = { 0x300, 0x340, 0x1600, 0x1640, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
301 int args, envs;
302
303 if (!*line)
304 return;
305 args = 0;
306 envs = 1;
307 next = line;
308 while ((line = next) != NULL) {
309 if ((next = strchr(line,' ')) != NULL)
310 *next++ = 0;
311
312
313
314 if (!strncmp(line,"root=",5)) {
315 int n;
316 line += 5;
317 if (strncmp(line,"/dev/",5)) {
318 ROOT_DEV = simple_strtoul(line,NULL,16);
319 continue;
320 }
321 line += 5;
322 for (n = 0 ; devnames[n] ; n++) {
323 int len = strlen(devnames[n]);
324 if (!strncmp(line,devnames[n],len)) {
325 ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
326 break;
327 }
328 }
329 continue;
330 }
331 if (!strcmp(line,"ro")) {
332 root_mountflags |= MS_RDONLY;
333 continue;
334 }
335 if (!strcmp(line,"rw")) {
336 root_mountflags &= ~MS_RDONLY;
337 continue;
338 }
339 if (!strcmp(line,"debug")) {
340 console_loglevel = 10;
341 continue;
342 }
343 if (checksetup(line))
344 continue;
345
346
347
348
349 if (strchr(line,'=')) {
350 if (envs >= MAX_INIT_ENVS)
351 break;
352 envp_init[++envs] = line;
353 } else {
354 if (args >= MAX_INIT_ARGS)
355 break;
356 argv_init[++args] = line;
357 }
358 }
359 argv_init[args+1] = NULL;
360 envp_init[envs+1] = NULL;
361 }
362
363 extern void check_bugs(void);
364 extern void setup_arch(char **, unsigned long *, unsigned long *);
365
366 asmlinkage void start_kernel(void)
367 {
368 char * command_line;
369
370
371
372
373 setup_arch(&command_line, &memory_start, &memory_end);
374 memory_start = paging_init(memory_start,memory_end);
375 trap_init();
376 init_IRQ();
377 sched_init();
378 parse_options(command_line);
379 init_modules();
380 #ifdef CONFIG_PROFILE
381 prof_buffer = (unsigned long *) memory_start;
382
383 prof_len = (unsigned long) &etext;
384 prof_len >>= CONFIG_PROFILE_SHIFT;
385 memory_start += prof_len * sizeof(unsigned long);
386 #endif
387 memory_start = console_init(memory_start,memory_end);
388 memory_start = bios32_init(memory_start,memory_end);
389 memory_start = kmalloc_init(memory_start,memory_end);
390 sti();
391 calibrate_delay();
392 memory_start = chr_dev_init(memory_start,memory_end);
393 memory_start = blk_dev_init(memory_start,memory_end);
394 sti();
395 #ifdef CONFIG_SCSI
396 memory_start = scsi_dev_init(memory_start,memory_end);
397 #endif
398 #ifdef CONFIG_INET
399 memory_start = net_dev_init(memory_start,memory_end);
400 #endif
401 memory_start = inode_init(memory_start,memory_end);
402 memory_start = file_table_init(memory_start,memory_end);
403 memory_start = name_cache_init(memory_start,memory_end);
404 mem_init(memory_start,memory_end);
405 buffer_init();
406 time_init();
407 sock_init();
408 #ifdef CONFIG_SYSVIPC
409 ipc_init();
410 #endif
411 sti();
412 check_bugs();
413
414 printk(linux_banner);
415
416 move_to_user_mode();
417 if (!fork())
418 init();
419
420
421
422
423
424
425
426
427
428 for(;;)
429 idle();
430 }
431
432 static int printf(const char *fmt, ...)
433 {
434 va_list args;
435 int i;
436
437 va_start(args, fmt);
438 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
439 va_end(args);
440 return i;
441 }
442
443 void init(void)
444 {
445 int pid,i;
446
447 setup();
448 sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
449
450 #ifdef CONFIG_UMSDOS_FS
451 {
452
453
454
455
456
457 extern struct inode *pseudo_root;
458 if (pseudo_root != NULL){
459 current->fs->root = pseudo_root;
460 current->fs->pwd = pseudo_root;
461 }
462 }
463 #endif
464
465 (void) open("/dev/tty1",O_RDWR,0);
466 (void) dup(0);
467 (void) dup(0);
468
469 execve("/etc/init",argv_init,envp_init);
470 execve("/bin/init",argv_init,envp_init);
471 execve("/sbin/init",argv_init,envp_init);
472
473
474 if (!(pid=fork())) {
475 close(0);
476 if (open("/etc/rc",O_RDONLY,0))
477 _exit(1);
478 execve("/bin/sh",argv_rc,envp_rc);
479 _exit(2);
480 }
481 if (pid>0)
482 while (pid != wait(&i))
483 ;
484 while (1) {
485 if ((pid = fork()) < 0) {
486 printf("Fork failed in init\n\r");
487 continue;
488 }
489 if (!pid) {
490 close(0);close(1);close(2);
491 setsid();
492 (void) open("/dev/tty1",O_RDWR,0);
493 (void) dup(0);
494 (void) dup(0);
495 _exit(execve("/bin/sh",argv,envp));
496 }
497 while (1)
498 if (pid == wait(&i))
499 break;
500 printf("\n\rchild %d died with code %04x\n\r",pid,i);
501 sync();
502 }
503 _exit(0);
504 }