root/init/main.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_options
  2. profile_setup
  3. ramdisk_start_setup
  4. load_ramdisk
  5. prompt_ramdisk
  6. checksetup
  7. calibrate_delay
  8. parse_options
  9. cpu_idle
  10. start_secondary
  11. smp_init
  12. smp_begin
  13. start_kernel
  14. printf
  15. do_rc
  16. do_shell
  17. init

   1 /*
   2  *  linux/init/main.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  *
   6  *  GK 2/5/95  -  Changed to support mounting root fs via NFS
   7  */
   8 
   9 #define __KERNEL_SYSCALLS__
  10 #include <stdarg.h>
  11 
  12 #include <asm/system.h>
  13 #include <asm/io.h>
  14 
  15 #include <linux/types.h>
  16 #include <linux/fcntl.h>
  17 #include <linux/config.h>
  18 #include <linux/sched.h>
  19 #include <linux/tty.h>
  20 #include <linux/head.h>
  21 #include <linux/unistd.h>
  22 #include <linux/string.h>
  23 #include <linux/timer.h>
  24 #include <linux/fs.h>
  25 #include <linux/ctype.h>
  26 #include <linux/delay.h>
  27 #include <linux/utsname.h>
  28 #include <linux/ioport.h>
  29 #include <linux/hdreg.h>
  30 #include <linux/mm.h>
  31 #include <linux/major.h>
  32 #ifdef CONFIG_APM
  33 #include <linux/apm_bios.h>
  34 #endif
  35 
  36 #include <asm/bugs.h>
  37 
  38 extern char _stext, _etext;
  39 extern char *linux_banner;
  40 
  41 static char printbuf[1024];
  42 
  43 extern int console_loglevel;
  44 
  45 static int init(void *);
  46 extern int bdflush(void *);
  47 extern int kswapd(void *);
  48 
  49 extern void init_IRQ(void);
  50 extern void init_modules(void);
  51 extern long console_init(long, long);
  52 extern long kmalloc_init(long,long);
  53 extern void sock_init(void);
  54 extern long pci_init(long, long);
  55 extern void sysctl_init(void);
  56 
  57 extern void swap_setup(char *str, int *ints);
  58 extern void buff_setup(char *str, int *ints);
  59 extern void panic_setup(char *str, int *ints);
  60 extern void bmouse_setup(char *str, int *ints);
  61 extern void eth_setup(char *str, int *ints);
  62 extern void xd_setup(char *str, int *ints);
  63 extern void floppy_setup(char *str, int *ints);
  64 extern void st_setup(char *str, int *ints);
  65 extern void st0x_setup(char *str, int *ints);
  66 extern void advansys_setup(char *str, int *ints);
  67 extern void tmc8xx_setup(char *str, int *ints);
  68 extern void t128_setup(char *str, int *ints);
  69 extern void pas16_setup(char *str, int *ints);
  70 extern void generic_NCR5380_setup(char *str, int *intr);
  71 extern void generic_NCR53C400_setup(char *str, int *intr);
  72 extern void aha152x_setup(char *str, int *ints);
  73 extern void aha1542_setup(char *str, int *ints);
  74 extern void aic7xxx_setup(char *str, int *ints);
  75 extern void AM53C974_setup(char *str, int *ints);
  76 extern void BusLogic_Setup(char *str, int *ints);
  77 extern void fdomain_setup(char *str, int *ints);
  78 extern void NCR53c406a_setup(char *str, int *ints);
  79 extern void scsi_luns_setup(char *str, int *ints);
  80 extern void sound_setup(char *str, int *ints);
  81 #ifdef CONFIG_CDU31A
  82 extern void cdu31a_setup(char *str, int *ints);
  83 #endif CONFIG_CDU31A
  84 #ifdef CONFIG_MCD
  85 extern void mcd_setup(char *str, int *ints);
  86 #endif CONFIG_MCD
  87 #ifdef CONFIG_MCDX
  88 extern void mcdx_setup(char *str, int *ints);
  89 #endif CONFIG_MCDX
  90 #ifdef CONFIG_SBPCD
  91 extern void sbpcd_setup(char *str, int *ints);
  92 #endif CONFIG_SBPCD
  93 #ifdef CONFIG_AZTCD
  94 extern void aztcd_setup(char *str, int *ints);
  95 #endif CONFIG_AZTCD
  96 #ifdef CONFIG_CDU535
  97 extern void sonycd535_setup(char *str, int *ints);
  98 #endif CONFIG_CDU535
  99 #ifdef CONFIG_GSCD
 100 extern void gscd_setup(char *str, int *ints);
 101 #endif CONFIG_GSCD
 102 #ifdef CONFIG_CM206
 103 extern void cm206_setup(char *str, int *ints);
 104 #endif CONFIG_CM206
 105 #ifdef CONFIG_OPTCD
 106 extern void optcd_setup(char *str, int *ints);
 107 #endif CONFIG_OPTCD
 108 #ifdef CONFIG_SJCD
 109 extern void sjcd_setup(char *str, int *ints);
 110 #endif CONFIG_SJCD
 111 #ifdef CONFIG_ISP16_CDI
 112 extern void isp16_setup(char *str, int *ints);
 113 #endif CONFIG_ISP16_CDI
 114 #ifdef CONFIG_BLK_DEV_RAM
 115 static void ramdisk_start_setup(char *str, int *ints);
 116 static void load_ramdisk(char *str, int *ints);
 117 static void prompt_ramdisk(char *str, int *ints);
 118 #endif CONFIG_BLK_DEV_RAM
 119 #ifdef CONFIG_ISDN_DRV_ICN
 120 extern void icn_setup(char *str, int *ints);
 121 #endif
 122 #ifdef CONFIG_ISDN_DRV_TELES
 123 extern void teles_setup(char *str, int *ints);
 124 #endif
 125 
 126 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
 127 extern void ipc_init(void);
 128 #endif
 129 
 130 /*
 131  * Boot command-line arguments
 132  */
 133 #define MAX_INIT_ARGS 8
 134 #define MAX_INIT_ENVS 8
 135 
 136 extern void time_init(void);
 137 
 138 static unsigned long memory_start = 0;
 139 static unsigned long memory_end = 0;
 140 
 141 int rows, cols;
 142 
 143 #ifdef CONFIG_BLK_DEV_RAM
 144 extern int rd_doload;           /* 1 = load ramdisk, 0 = don't load */
 145 extern int rd_prompt;           /* 1 = prompt for ramdisk, 0 = don't prompt */
 146 extern int rd_image_start;      /* starting block # of image */
 147 #endif
 148 
 149 int root_mountflags = MS_RDONLY;
 150 char *execute_command = 0;
 151 
 152 #ifdef CONFIG_ROOT_NFS
 153 char nfs_root_name[256] = { NFS_ROOT };
 154 char nfs_root_addrs[128] = { "" };
 155 #endif
 156 
 157 extern void dquot_init(void);
 158 
 159 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
 160 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
 161 
 162 static char * argv_rc[] = { "/bin/sh", NULL };
 163 static char * envp_rc[] = { "HOME=/", "TERM=linux", NULL };
 164 
 165 static char * argv[] = { "-/bin/sh",NULL };
 166 static char * envp[] = { "HOME=/usr/root", "TERM=linux", NULL };
 167 
 168 char *get_options(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170         char *cur = str;
 171         int i=1;
 172 
 173         while (cur && isdigit(*cur) && i <= 10) {
 174                 ints[i++] = simple_strtoul(cur,NULL,0);
 175                 if ((cur = strchr(cur,',')) != NULL)
 176                         cur++;
 177         }
 178         ints[0] = i-1;
 179         return(cur);
 180 }
 181 
 182 static void profile_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184         if (ints[0] > 0)
 185                 prof_shift = (unsigned long) ints[1];
 186         else
 187 #ifdef CONFIG_PROFILE_SHIFT
 188                 prof_shift = CONFIG_PROFILE_SHIFT;
 189 #else
 190                 prof_shift = 2;
 191 #endif
 192 }
 193 
 194 struct {
 195         const char *str;
 196         void (*setup_func)(char *, int *);
 197 } bootsetups[] = {
 198         { "reserve=", reserve_setup },
 199         { "profile=", profile_setup },
 200 #ifdef CONFIG_BLK_DEV_RAM
 201         { "ramdisk_start=", ramdisk_start_setup },
 202         { "load_ramdisk=", load_ramdisk },
 203         { "prompt_ramdisk=", prompt_ramdisk },
 204 #endif
 205         { "swap=", swap_setup },
 206         { "buff=", buff_setup },
 207         { "panic=", panic_setup },
 208 #ifdef CONFIG_BUGi386
 209         { "no-hlt", no_halt },
 210         { "no387", no_387 },
 211 #endif
 212 #ifdef CONFIG_INET
 213         { "ether=", eth_setup },
 214 #endif
 215 #ifdef CONFIG_SCSI
 216         { "max_scsi_luns=", scsi_luns_setup },
 217 #endif
 218 #ifdef CONFIG_SCSI_ADVANSYS
 219         { "advansys=", advansys_setup },
 220 #endif
 221 #if defined(CONFIG_BLK_DEV_HD)
 222         { "hd=", hd_setup },
 223 #endif
 224 #ifdef CONFIG_CHR_DEV_ST
 225         { "st=", st_setup },
 226 #endif
 227 #ifdef CONFIG_BUSMOUSE
 228         { "bmouse=", bmouse_setup },
 229 #endif
 230 #ifdef CONFIG_SCSI_SEAGATE
 231         { "st0x=", st0x_setup },
 232         { "tmc8xx=", tmc8xx_setup },
 233 #endif
 234 #ifdef CONFIG_SCSI_T128
 235         { "t128=", t128_setup },
 236 #endif
 237 #ifdef CONFIG_SCSI_PAS16
 238         { "pas16=", pas16_setup },
 239 #endif
 240 #ifdef CONFIG_SCSI_GENERIC_NCR5380
 241         { "ncr5380=", generic_NCR5380_setup },
 242         { "ncr53c400=", generic_NCR53C400_setup },
 243 #endif
 244 #ifdef CONFIG_SCSI_AHA152X
 245         { "aha152x=", aha152x_setup},
 246 #endif
 247 #ifdef CONFIG_SCSI_AHA1542
 248         { "aha1542=", aha1542_setup},
 249 #endif
 250 #ifdef CONFIG_SCSI_AIC7XXX
 251         { "aic7xxx=", aic7xxx_setup},
 252 #endif
 253 #ifdef CONFIG_SCSI_BUSLOGIC
 254         { "BusLogic=", BusLogic_Setup},
 255 #endif
 256 #ifdef CONFIG_SCSI_AM53C974
 257         { "AM53C974=", AM53C974_setup},
 258 #endif
 259 #ifdef CONFIG_SCSI_NCR53C406A
 260         { "ncr53c406a=", NCR53c406a_setup},
 261 #endif
 262 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
 263         { "fdomain=", fdomain_setup},
 264 #endif
 265 #ifdef CONFIG_BLK_DEV_XD
 266         { "xd=", xd_setup },
 267 #endif
 268 #ifdef CONFIG_BLK_DEV_FD
 269         { "floppy=", floppy_setup },
 270 #endif
 271 #ifdef CONFIG_CDU31A
 272         { "cdu31a=", cdu31a_setup },
 273 #endif CONFIG_CDU31A
 274 #ifdef CONFIG_MCD
 275         { "mcd=", mcd_setup },
 276 #endif CONFIG_MCD
 277 #ifdef CONFIG_MCDX
 278         { "mcdx=", mcdx_setup },
 279 #endif CONFIG_MCDX
 280 #ifdef CONFIG_SBPCD
 281         { "sbpcd=", sbpcd_setup },
 282 #endif CONFIG_SBPCD
 283 #ifdef CONFIG_AZTCD
 284         { "aztcd=", aztcd_setup },
 285 #endif CONFIG_AZTCD
 286 #ifdef CONFIG_CDU535
 287         { "sonycd535=", sonycd535_setup },
 288 #endif CONFIG_CDU535
 289 #ifdef CONFIG_GSCD
 290         { "gscd=", gscd_setup },
 291 #endif CONFIG_GSCD
 292 #ifdef CONFIG_CM206
 293         { "cm206=", cm206_setup },
 294 #endif CONFIG_CM206
 295 #ifdef CONFIG_OPTCD
 296         { "optcd=", optcd_setup },
 297 #endif CONFIG_OPTCD
 298 #ifdef CONFIG_SJCD
 299         { "sjcd=", sjcd_setup },
 300 #endif CONFIG_SJCD
 301 #ifdef CONFIG_ISP16_CDI
 302         { "isp16=", isp16_setup },
 303 #endif CONFIG_ISP16_CDI
 304 #ifdef CONFIG_SOUND
 305         { "sound=", sound_setup },
 306 #endif
 307 #ifdef CONFIG_ISDN_DRV_ICN
 308         { "icn=", icn_setup },
 309 #endif
 310 #ifdef CONFIG_ISDN_DRV_TELES
 311         { "teles=", teles_setup },
 312 #endif
 313         { 0, 0 }
 314 };
 315 
 316 #ifdef CONFIG_BLK_DEV_RAM
 317 static void ramdisk_start_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319    if (ints[0] > 0 && ints[1] >= 0)
 320       rd_image_start = ints[1];
 321 }
 322 
 323 static void load_ramdisk(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 324 {
 325    if (ints[0] > 0 && ints[1] >= 0)
 326       rd_doload = ints[1] & 1;
 327 }
 328 
 329 static void prompt_ramdisk(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 330 {
 331    if (ints[0] > 0 && ints[1] >= 0)
 332       rd_prompt = ints[1] & 1;
 333 }
 334 #endif
 335 
 336 static int checksetup(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 337 {
 338         int i = 0;
 339         int ints[11];
 340 
 341 #ifdef CONFIG_BLK_DEV_IDE
 342         /* ide driver needs the basic string, rather than pre-processed values */
 343         if (!strncmp(line,"ide",3) || (!strncmp(line,"hd",2) && line[2] != '=')) {
 344                 ide_setup(line);
 345                 return 1;
 346         }
 347 #endif
 348         while (bootsetups[i].str) {
 349                 int n = strlen(bootsetups[i].str);
 350                 if (!strncmp(line,bootsetups[i].str,n)) {
 351                         bootsetups[i].setup_func(get_options(line+n,ints), ints);
 352                         return 1;
 353                 }
 354                 i++;
 355         }
 356         return 0;
 357 }
 358 
 359 /* this should be approx 2 Bo*oMips to start (note initial shift), and will
 360    still work even if initally too large, it will just take slightly longer */
 361 unsigned long loops_per_sec = (1<<12);
 362 
 363 /* This is the number of bits of precision for the loops_per_second.  Each
 364    bit takes on average 1.5/HZ seconds.  This (like the original) is a little
 365    better than 1% */
 366 #define LPS_PREC 8
 367 
 368 void calibrate_delay(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 369 {
 370         int ticks;
 371         int loopbit;
 372         int lps_precision = LPS_PREC;
 373 
 374         loops_per_sec = (1<<12);
 375 
 376         printk("Calibrating delay loop.. ");
 377         while (loops_per_sec <<= 1) {
 378                 /* wait for "start of" clock tick */
 379                 ticks = jiffies;
 380                 while (ticks == jiffies)
 381                         /* nothing */;
 382                 /* Go .. */
 383                 ticks = jiffies;
 384                 __delay(loops_per_sec);
 385                 ticks = jiffies - ticks;
 386                 if (ticks)
 387                         break;
 388                 }
 389 
 390 /* Do a binary approximation to get loops_per_second set to equal one clock
 391    (up to lps_precision bits) */
 392         loops_per_sec >>= 1;
 393         loopbit = loops_per_sec;
 394         while ( lps_precision-- && (loopbit >>= 1) ) {
 395                 loops_per_sec |= loopbit;
 396                 ticks = jiffies;
 397                 while (ticks == jiffies);
 398                 ticks = jiffies;
 399                 __delay(loops_per_sec);
 400                 if (jiffies != ticks)   /* longer than 1 tick */
 401                         loops_per_sec &= ~loopbit;
 402         }
 403 
 404 /* finally, adjust loops per second in terms of seconds instead of clocks */    
 405         loops_per_sec *= HZ;
 406 /* Round the value and print it */      
 407         printk("ok - %lu.%02lu BogoMIPS\n",
 408                 (loops_per_sec+2500)/500000,
 409                 ((loops_per_sec+2500)/5000) % 100);
 410 }
 411 
 412 /*
 413  * This is a simple kernel command line parsing function: it parses
 414  * the command line, and fills in the arguments/environment to init
 415  * as appropriate. Any cmd-line option is taken to be an environment
 416  * variable if it contains the character '='.
 417  *
 418  *
 419  * This routine also checks for options meant for the kernel.
 420  * These options are not given to init - they are for internal kernel use only.
 421  */
 422 static void parse_options(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 423 {
 424         char *next;
 425         char *devnames[] = { "nfs", "hda", "hdb", "hdc", "hdd", "sda", "sdb",
 426                 "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
 427         int devnums[]    = { 0x0FF, 0x300, 0x340, 0x1600, 0x1640, 0x800,
 428                 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
 429         int args, envs;
 430         if (!*line)
 431                 return;
 432         args = 0;
 433         envs = 1;       /* TERM is set to 'linux' by default */
 434         next = line;
 435         while ((line = next) != NULL) {
 436                 if ((next = strchr(line,' ')) != NULL)
 437                         *next++ = 0;
 438                 /*
 439                  * check for kernel options first..
 440                  */
 441                 if (!strncmp(line,"root=",5)) {
 442                         int n;
 443                         line += 5;
 444                         if (strncmp(line,"/dev/",5)) {
 445                                 ROOT_DEV = to_kdev_t(
 446                                              simple_strtoul(line,NULL,16));
 447                                 continue;
 448                         }
 449                         line += 5;
 450                         for (n = 0 ; devnames[n] ; n++) {
 451                                 int len = strlen(devnames[n]);
 452                                 if (!strncmp(line,devnames[n],len)) {
 453                                         ROOT_DEV = to_kdev_t(devnums[n]+
 454                                              simple_strtoul(line+len,NULL,0));
 455                                         break;
 456                                 }
 457                         }
 458                         continue;
 459                 }
 460 #ifdef CONFIG_ROOT_NFS
 461                 if (!strncmp(line, "nfsroot=", 8)) {
 462                         int n;
 463                         line += 8;
 464                         ROOT_DEV = MKDEV(UNNAMED_MAJOR, 255);
 465                         if (line[0] == '/' || (line[0] >= '0' && line[0] <= '9')) {
 466                                 strncpy(nfs_root_name, line, sizeof(nfs_root_name));
 467                                 nfs_root_name[sizeof(nfs_root_name)-1] = '\0';
 468                                 continue;
 469                         }
 470                         n = strlen(line) + strlen(NFS_ROOT);
 471                         if (n >= sizeof(nfs_root_name))
 472                                 line[sizeof(nfs_root_name) - strlen(NFS_ROOT) - 1] = '\0';
 473                         sprintf(nfs_root_name, NFS_ROOT, line);
 474                         continue;
 475                 }
 476                 if (!strncmp(line, "nfsaddrs=", 9)) {
 477                         line += 9;
 478                         strncpy(nfs_root_addrs, line, sizeof(nfs_root_addrs));
 479                         nfs_root_addrs[sizeof(nfs_root_addrs)-1] = '\0';
 480                         continue;
 481                 }
 482 #endif
 483                 if (!strcmp(line,"ro")) {
 484                         root_mountflags |= MS_RDONLY;
 485                         continue;
 486                 }
 487                 if (!strcmp(line,"rw")) {
 488                         root_mountflags &= ~MS_RDONLY;
 489                         continue;
 490                 }
 491                 if (!strcmp(line,"debug")) {
 492                         console_loglevel = 10;
 493                         continue;
 494                 }
 495                 if (!strncmp(line,"init=",5)) {
 496                         line += 5;
 497                         execute_command = line;
 498                         continue;
 499                 }
 500                 if (checksetup(line))
 501                         continue;
 502                 /*
 503                  * Then check if it's an environment variable or
 504                  * an option.
 505                  */
 506                 if (strchr(line,'=')) {
 507                         if (envs >= MAX_INIT_ENVS)
 508                                 break;
 509                         envp_init[++envs] = line;
 510                 } else {
 511                         if (args >= MAX_INIT_ARGS)
 512                                 break;
 513                         argv_init[++args] = line;
 514                 }
 515         }
 516         argv_init[args+1] = NULL;
 517         envp_init[envs+1] = NULL;
 518 }
 519 
 520 
 521 extern void setup_arch(char **, unsigned long *, unsigned long *);
 522 extern void arch_syms_export(void);
 523 
 524 #ifndef __SMP__
 525 
 526 /*
 527  *      Uniprocessor idle thread
 528  */
 529  
 530 int cpu_idle(void *unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 531 {
 532         for(;;)
 533                 idle();
 534 }
 535 
 536 #else
 537 
 538 /*
 539  *      Multiprocessor idle thread is in arch/...
 540  */
 541  
 542 extern int cpu_idle(void * unused);
 543 
 544 /*
 545  *      Activate a secondary processor.
 546  */
 547  
 548 asmlinkage void start_secondary(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 549 {
 550         trap_init();
 551         init_IRQ();
 552         smp_callin();
 553         cpu_idle(NULL);
 554 }
 555 
 556 
 557 
 558 /*
 559  *      Called by CPU#0 to activate the rest.
 560  */
 561  
 562 static void smp_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 563 {
 564         int i=0;
 565         smp_boot_cpus();
 566         
 567         /*
 568          *      Create the slave init tasks as sharing pid 0.
 569          */
 570 
 571         for (i=0; i<NR_CPUS; i++)
 572         {
 573                 /*
 574                  *      This should only do anything if the mapping
 575                  *      corresponds to a live CPU which is not the boot CPU.
 576                  */
 577                 if (cpu_number_map[i] > 0)
 578                 {
 579                         /*
 580                          *      We use kernel_thread for the idlers which are
 581                          *      unlocked tasks running in kernel space.
 582                          */
 583                         kernel_thread(cpu_idle, NULL, CLONE_PID);
 584                         /*
 585                          *      Don't assume linear processor numbering
 586                          */
 587                         current_set[i]=task[cpu_number_map[i]];
 588                         current_set[i]->processor=i;
 589                 }
 590         }
 591 }               
 592 
 593 /*
 594  *      The autoprobe routines assume CPU#0 on the i386
 595  *      so we don't actually set the game in motion until
 596  *      they are finished.
 597  */
 598  
 599 static void smp_begin(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 600 {
 601         smp_threads_ready=1;
 602         smp_commence();
 603 }
 604         
 605 #endif
 606 
 607 /*
 608  *      Activate the first processor.
 609  */
 610  
 611 asmlinkage void start_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 612 {
 613         char * command_line;
 614 
 615 /*
 616  *      This little check will move.
 617  */
 618 
 619 #ifdef __SMP__
 620         static int first_cpu=1;
 621         
 622         if(!first_cpu)
 623                 start_secondary();
 624         first_cpu=0;
 625         
 626 #endif  
 627 /*
 628  * Interrupts are still disabled. Do necessary setups, then
 629  * enable them
 630  */
 631         setup_arch(&command_line, &memory_start, &memory_end);
 632         memory_start = paging_init(memory_start,memory_end);
 633         trap_init();
 634         init_IRQ();
 635         sched_init();
 636         time_init();
 637         parse_options(command_line);
 638 #ifdef CONFIG_MODULES
 639         init_modules();
 640 #endif
 641 #ifdef CONFIG_PROFILE
 642         if (!prof_shift)
 643 #ifdef CONFIG_PROFILE_SHIFT
 644                 prof_shift = CONFIG_PROFILE_SHIFT;
 645 #else
 646                 prof_shift = 2;
 647 #endif
 648 #endif
 649         if (prof_shift) {
 650                 prof_buffer = (unsigned int *) memory_start;
 651                 /* only text is profiled */
 652                 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
 653                 prof_len >>= prof_shift;
 654                 memory_start += prof_len * sizeof(unsigned int);
 655         }
 656         memory_start = console_init(memory_start,memory_end);
 657 #ifdef CONFIG_PCI
 658         memory_start = pci_init(memory_start,memory_end);
 659 #endif
 660         memory_start = kmalloc_init(memory_start,memory_end);
 661         sti();
 662         calibrate_delay();
 663         memory_start = inode_init(memory_start,memory_end);
 664         memory_start = file_table_init(memory_start,memory_end);
 665         memory_start = name_cache_init(memory_start,memory_end);
 666         mem_init(memory_start,memory_end);
 667         buffer_init();
 668         sock_init();
 669 #if defined(CONFIG_SYSVIPC) || defined(CONFIG_KERNELD)
 670         ipc_init();
 671 #endif
 672 #ifdef CONFIG_APM
 673         apm_bios_init();
 674 #endif
 675         dquot_init();
 676         arch_syms_export();
 677         sti();
 678         check_bugs();
 679 
 680         printk(linux_banner);
 681 #ifdef __SMP__
 682         smp_init();
 683 #endif
 684         sysctl_init();
 685         /* 
 686          *      We count on the initial thread going ok 
 687          *      Like idlers init is an unlocked kernel thread, which will
 688          *      make syscalls (and thus be locked).
 689          */
 690         kernel_thread(init, NULL, 0);
 691 /*
 692  * task[0] is meant to be used as an "idle" task: it may not sleep, but
 693  * it might do some general things like count free pages or it could be
 694  * used to implement a reasonable LRU algorithm for the paging routines:
 695  * anything that can be useful, but shouldn't take time from the real
 696  * processes.
 697  *
 698  * Right now task[0] just does a infinite idle loop.
 699  */
 700         cpu_idle(NULL);
 701 }
 702 
 703 static int printf(const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 704 {
 705         va_list args;
 706         int i;
 707 
 708         va_start(args, fmt);
 709         write(1,printbuf,i=vsprintf(printbuf, fmt, args));
 710         va_end(args);
 711         return i;
 712 }
 713 
 714 static int do_rc(void * rc)
     /* [previous][next][first][last][top][bottom][index][help] */
 715 {
 716         close(0);
 717         if (open(rc,O_RDONLY,0))
 718                 return -1;
 719         return execve("/bin/sh", argv_rc, envp_rc);
 720 }
 721 
 722 static int do_shell(void * shell)
     /* [previous][next][first][last][top][bottom][index][help] */
 723 {
 724         close(0);close(1);close(2);
 725         setsid();
 726         (void) open("/dev/tty1",O_RDWR,0);
 727         (void) dup(0);
 728         (void) dup(0);
 729         return execve(shell, argv, envp);
 730 }
 731 
 732 static int init(void * unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 733 {
 734         int pid,i;
 735 
 736         /* Launch bdflush from here, instead of the old syscall way. */
 737         kernel_thread(bdflush, NULL, 0);
 738         /* Start the background pageout daemon. */
 739         kernel_thread(kswapd, NULL, 0);
 740 
 741         setup();
 742 
 743 #ifdef __SMP__
 744         /*
 745          *      With the devices probed and setup we can
 746          *      now enter SMP mode.
 747          */
 748         
 749         smp_begin();
 750 #endif  
 751 
 752         #ifdef CONFIG_UMSDOS_FS
 753         {
 754                 /*
 755                         When mounting a umsdos fs as root, we detect
 756                         the pseudo_root (/linux) and initialise it here.
 757                         pseudo_root is defined in fs/umsdos/inode.c
 758                 */
 759                 extern struct inode *pseudo_root;
 760                 if (pseudo_root != NULL){
 761                         current->fs->root = pseudo_root;
 762                         current->fs->pwd  = pseudo_root;
 763                 }
 764         }
 765         #endif
 766 
 767         (void) open("/dev/tty1",O_RDWR,0);
 768         (void) dup(0);
 769         (void) dup(0);
 770 
 771         if (!execute_command) {
 772                 execve("/etc/init",argv_init,envp_init);
 773                 execve("/bin/init",argv_init,envp_init);
 774                 execve("/sbin/init",argv_init,envp_init);
 775                 /* if this fails, fall through to original stuff */
 776 
 777                 pid = kernel_thread(do_rc, "/etc/rc", SIGCHLD);
 778                 if (pid>0)
 779                         while (pid != wait(&i))
 780                                 /* nothing */;
 781                 }
 782 
 783         while (1) {
 784                 pid = kernel_thread(do_shell,
 785                         execute_command ? execute_command : "/bin/sh",
 786                         SIGCHLD);
 787                 if (pid < 0) {
 788                         printf("Fork failed in init\n\r");
 789                         continue;
 790                 }
 791                 while (1)
 792                         if (pid == wait(&i))
 793                                 break;
 794                 printf("\n\rchild %d died with code %04x\n\r",pid,i);
 795                 sync();
 796         }
 797         return -1;
 798 }

/* [previous][next][first][last][top][bottom][index][help] */