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

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