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