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

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