1
2
3
4
5
6
7
8
9
10
11
12#define __KERNEL_SYSCALLS__
13
14#include <linux/config.h>
15#include <linux/proc_fs.h>
16#include <linux/devfs_fs_kernel.h>
17#include <linux/unistd.h>
18#include <linux/string.h>
19#include <linux/ctype.h>
20#include <linux/delay.h>
21#include <linux/utsname.h>
22#include <linux/ioport.h>
23#include <linux/init.h>
24#include <linux/smp_lock.h>
25#include <linux/blk.h>
26#include <linux/hdreg.h>
27#include <linux/iobuf.h>
28#include <linux/bootmem.h>
29#include <linux/tty.h>
30
31#include <asm/io.h>
32#include <asm/bugs.h>
33
34#if defined(CONFIG_ARCH_S390)
35#include <asm/s390mach.h>
36#include <asm/ccwcache.h>
37#endif
38
39#ifdef CONFIG_PCI
40#include <linux/pci.h>
41#endif
42
43#ifdef CONFIG_DIO
44#include <linux/dio.h>
45#endif
46
47#ifdef CONFIG_ZORRO
48#include <linux/zorro.h>
49#endif
50
51#ifdef CONFIG_MTRR
52# include <asm/mtrr.h>
53#endif
54
55#ifdef CONFIG_NUBUS
56#include <linux/nubus.h>
57#endif
58
59#ifdef CONFIG_ISAPNP
60#include <linux/isapnp.h>
61#endif
62
63#ifdef CONFIG_IRDA
64extern int irda_proto_init(void);
65extern int irda_device_init(void);
66#endif
67
68#ifdef CONFIG_X86_LOCAL_APIC
69#include <asm/smp.h>
70#endif
71
72
73
74
75
76
77
78#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 91)
79#error Sorry, your GCC is too old. It builds incorrect kernels.
80#endif
81
82extern char _stext, _etext;
83extern char *linux_banner;
84
85static int init(void *);
86
87extern void init_IRQ(void);
88extern void init_modules(void);
89extern void sock_init(void);
90extern void fork_init(unsigned long);
91extern void mca_init(void);
92extern void sbus_init(void);
93extern void ppc_init(void);
94extern void sysctl_init(void);
95extern void signals_init(void);
96extern int init_pcmcia_ds(void);
97
98extern void free_initmem(void);
99
100#ifdef CONFIG_TC
101extern void tc_init(void);
102#endif
103
104extern void ecard_init(void);
105
106#if defined(CONFIG_SYSVIPC)
107extern void ipc_init(void);
108#endif
109
110
111
112
113#define MAX_INIT_ARGS 8
114#define MAX_INIT_ENVS 8
115
116extern void time_init(void);
117extern void softirq_init(void);
118
119int rows, cols;
120
121char *execute_command;
122
123static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
124char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
125
126static int __init profile_setup(char *str)
127{
128 int par;
129 if (get_option(&str,&par)) prof_shift = par;
130 return 1;
131}
132
133__setup("profile=", profile_setup);
134
135static int __init checksetup(char *line)
136{
137 struct kernel_param *p;
138
139 p = &__setup_start;
140 do {
141 int n = strlen(p->str);
142 if (!strncmp(line,p->str,n)) {
143 if (p->setup_func(line+n))
144 return 1;
145 }
146 p++;
147 } while (p < &__setup_end);
148 return 0;
149}
150
151
152
153unsigned long loops_per_jiffy = (1<<12);
154
155
156
157
158#define LPS_PREC 8
159
160void __init calibrate_delay(void)
161{
162 unsigned long ticks, loopbit;
163 int lps_precision = LPS_PREC;
164
165 loops_per_jiffy = (1<<12);
166
167 printk("Calibrating delay loop... ");
168 while (loops_per_jiffy <<= 1) {
169
170 ticks = jiffies;
171 while (ticks == jiffies)
172 ;
173
174 ticks = jiffies;
175 __delay(loops_per_jiffy);
176 ticks = jiffies - ticks;
177 if (ticks)
178 break;
179 }
180
181
182
183 loops_per_jiffy >>= 1;
184 loopbit = loops_per_jiffy;
185 while ( lps_precision-- && (loopbit >>= 1) ) {
186 loops_per_jiffy |= loopbit;
187 ticks = jiffies;
188 while (ticks == jiffies);
189 ticks = jiffies;
190 __delay(loops_per_jiffy);
191 if (jiffies != ticks)
192 loops_per_jiffy &= ~loopbit;
193 }
194
195
196 printk("%lu.%02lu BogoMIPS\n",
197 loops_per_jiffy/(500000/HZ),
198 (loops_per_jiffy/(5000/HZ)) % 100);
199}
200
201static int __init debug_kernel(char *str)
202{
203 if (*str)
204 return 0;
205 console_loglevel = 10;
206 return 1;
207}
208
209static int __init quiet_kernel(char *str)
210{
211 if (*str)
212 return 0;
213 console_loglevel = 4;
214 return 1;
215}
216
217__setup("debug", debug_kernel);
218__setup("quiet", quiet_kernel);
219
220
221
222
223
224
225
226
227
228
229static void __init parse_options(char *line)
230{
231 char *next,*quote;
232 int args, envs;
233
234 if (!*line)
235 return;
236 args = 0;
237 envs = 1;
238 next = line;
239 while ((line = next) != NULL) {
240 quote = strchr(line,'"');
241 next = strchr(line, ' ');
242 while (next != NULL && quote != NULL && quote < next) {
243
244
245
246 next = strchr(quote+1, '"');
247 if (next != NULL) {
248 quote = strchr(next+1, '"');
249 next = strchr(next+1, ' ');
250 }
251 }
252 if (next != NULL)
253 *next++ = 0;
254 if (!strncmp(line,"init=",5)) {
255 line += 5;
256 execute_command = line;
257
258
259
260
261
262 args = 0;
263 continue;
264 }
265 if (checksetup(line))
266 continue;
267
268
269
270
271
272 if (strchr(line,'=')) {
273 if (envs >= MAX_INIT_ENVS)
274 break;
275 envp_init[++envs] = line;
276 } else {
277 if (args >= MAX_INIT_ARGS)
278 break;
279 if (*line)
280 argv_init[++args] = line;
281 }
282 }
283 argv_init[args+1] = NULL;
284 envp_init[envs+1] = NULL;
285}
286
287
288extern void setup_arch(char **);
289extern void cpu_idle(void);
290
291unsigned long wait_init_idle;
292
293#ifndef CONFIG_SMP
294
295#ifdef CONFIG_X86_LOCAL_APIC
296static void __init smp_init(void)
297{
298 APIC_init_uniprocessor();
299}
300#else
301#define smp_init() do { } while (0)
302#endif
303
304#else
305
306
307
308static void __init smp_init(void)
309{
310
311 smp_boot_cpus();
312 wait_init_idle = cpu_online_map;
313 clear_bit(current->processor, &wait_init_idle);
314
315 smp_threads_ready=1;
316 smp_commence();
317
318
319 printk("Waiting on wait_init_idle (map = 0x%lx)\n", wait_init_idle);
320 while (wait_init_idle) {
321 cpu_relax();
322 barrier();
323 }
324 printk("All processors have done init_idle\n");
325}
326
327#endif
328
329
330
331
332
333
334
335
336static void rest_init(void)
337{
338 kernel_thread(init, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
339 unlock_kernel();
340 current->need_resched = 1;
341 cpu_idle();
342}
343
344
345
346
347
348asmlinkage void __init start_kernel(void)
349{
350 char * command_line;
351 extern char saved_command_line[];
352
353
354
355
356 lock_kernel();
357 printk(linux_banner);
358 setup_arch(&command_line);
359 printk("Kernel command line: %s\n", saved_command_line);
360 parse_options(command_line);
361 trap_init();
362 init_IRQ();
363 sched_init();
364 softirq_init();
365 time_init();
366
367
368
369
370
371
372 console_init();
373#ifdef CONFIG_MODULES
374 init_modules();
375#endif
376 if (prof_shift) {
377 unsigned int size;
378
379 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
380 prof_len >>= prof_shift;
381
382 size = prof_len * sizeof(unsigned int) + PAGE_SIZE-1;
383 prof_buffer = (unsigned int *) alloc_bootmem(size);
384 }
385
386 kmem_cache_init();
387 sti();
388 calibrate_delay();
389#ifdef CONFIG_BLK_DEV_INITRD
390 if (initrd_start && !initrd_below_start_ok &&
391 initrd_start < min_low_pfn << PAGE_SHIFT) {
392 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
393 "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
394 initrd_start = 0;
395 }
396#endif
397 mem_init();
398 kmem_cache_sizes_init();
399 pgtable_cache_init();
400
401
402
403
404
405
406
407
408 if (num_mappedpages == 0)
409 num_mappedpages = num_physpages;
410
411 fork_init(num_mappedpages);
412 proc_caches_init();
413 vfs_caches_init(num_physpages);
414 buffer_init(num_physpages);
415 page_cache_init(num_physpages);
416#if defined(CONFIG_ARCH_S390)
417 ccwcache_init();
418#endif
419 signals_init();
420#ifdef CONFIG_PROC_FS
421 proc_root_init();
422#endif
423#if defined(CONFIG_SYSVIPC)
424 ipc_init();
425#endif
426 check_bugs();
427 printk("POSIX conformance testing by UNIFIX\n");
428
429
430
431
432
433
434 smp_init();
435 rest_init();
436}
437
438struct task_struct *child_reaper = &init_task;
439
440static void __init do_initcalls(void)
441{
442 initcall_t *call;
443
444 call = &__initcall_start;
445 do {
446 (*call)();
447 call++;
448 } while (call < &__initcall_end);
449
450
451 flush_scheduled_tasks();
452}
453
454
455
456
457
458
459
460
461static void __init do_basic_setup(void)
462{
463
464
465
466
467
468
469
470
471
472 child_reaper = current;
473
474#if defined(CONFIG_MTRR)
475
476
477
478
479
480 mtrr_init();
481#endif
482
483#ifdef CONFIG_SYSCTL
484 sysctl_init();
485#endif
486
487
488
489
490
491#if defined(CONFIG_ARCH_S390)
492 s390_init_machine_check();
493#endif
494
495#ifdef CONFIG_PCI
496 pci_init();
497#endif
498#ifdef CONFIG_SBUS
499 sbus_init();
500#endif
501#if defined(CONFIG_PPC)
502 ppc_init();
503#endif
504#ifdef CONFIG_MCA
505 mca_init();
506#endif
507#ifdef CONFIG_ARCH_ACORN
508 ecard_init();
509#endif
510#ifdef CONFIG_ZORRO
511 zorro_init();
512#endif
513#ifdef CONFIG_DIO
514 dio_init();
515#endif
516#ifdef CONFIG_NUBUS
517 nubus_init();
518#endif
519#ifdef CONFIG_ISAPNP
520 isapnp_init();
521#endif
522#ifdef CONFIG_TC
523 tc_init();
524#endif
525
526
527 sock_init();
528
529 start_context_thread();
530 do_initcalls();
531
532#ifdef CONFIG_IRDA
533 irda_proto_init();
534 irda_device_init();
535#endif
536#ifdef CONFIG_PCMCIA
537 init_pcmcia_ds();
538#endif
539}
540
541extern void prepare_namespace(void);
542
543static int init(void * unused)
544{
545 lock_kernel();
546 do_basic_setup();
547
548 prepare_namespace();
549
550
551
552
553
554
555 free_initmem();
556 unlock_kernel();
557
558 if (open("/dev/console", O_RDWR, 0) < 0)
559 printk("Warning: unable to open an initial console.\n");
560
561 (void) dup(0);
562 (void) dup(0);
563
564
565
566
567
568
569
570
571 if (execute_command)
572 execve(execute_command,argv_init,envp_init);
573 execve("/sbin/init",argv_init,envp_init);
574 execve("/etc/init",argv_init,envp_init);
575 execve("/bin/init",argv_init,envp_init);
576 execve("/bin/sh",argv_init,envp_init);
577 panic("No init found. Try passing init= option to kernel.");
578}
579