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

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