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. start_secondary
  10. smp_idle
  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 extern void setup_arch(char **, unsigned long *, unsigned long *);
 492 
 493 #ifdef __SMP__
 494 /*
 495  *      Activate a secondary processor.
 496  */
 497  
 498 asmlinkage void start_secondary(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 499 {
 500         trap_init();
 501         init_IRQ();
 502         smp_callin();
 503         for(;;)
 504                 idle();
 505 }
 506 
 507 int smp_idle(void * unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 508 {
 509         for (;;)
 510                 idle();
 511 }
 512 
 513 /*
 514  *      Called by CPU#0 to activate the rest.
 515  */
 516  
 517 static void smp_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 518 {
 519         int i=0;
 520         smp_boot_cpus();
 521         
 522         /*
 523          *      Create the slave init tasks as sharing pid 0.
 524          */
 525 
 526         for(i=1;i<smp_num_cpus;i++)
 527         {
 528                 kernel_thread(smp_idle, NULL, CLONE_PID);
 529                 /*
 530                  *      Assume linear processor numbering
 531                  */
 532                 current_set[i]=task[i];
 533                 current_set[i]->processor=i;
 534         }
 535 }               
 536 
 537 /*
 538  *      The autoprobe routines assume CPU#0 on the i386
 539  *      so we don't actually set the game in motion until
 540  *      they are finished.
 541  */
 542  
 543 static void smp_begin(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 544 {
 545         smp_threads_ready=1;
 546         smp_commence();
 547 }
 548         
 549 #endif
 550 
 551 /*
 552  *      Activate the first processor.
 553  */
 554  
 555 asmlinkage void start_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 556 {
 557         char * command_line;
 558 
 559 /*
 560  *      This little check will move.
 561  */
 562 
 563 #ifdef __SMP__
 564         static int first_cpu=1;
 565         
 566         if(!first_cpu)
 567                 start_secondary();
 568         first_cpu=0;
 569         
 570 #endif  
 571 /*
 572  * Interrupts are still disabled. Do necessary setups, then
 573  * enable them
 574  */
 575         setup_arch(&command_line, &memory_start, &memory_end);
 576         memory_start = paging_init(memory_start,memory_end);
 577         trap_init();
 578         init_IRQ();
 579         sched_init();
 580         time_init();
 581         parse_options(command_line);
 582         init_modules();
 583 #ifdef CONFIG_PROFILE
 584         if (!prof_shift)
 585 #ifdef CONFIG_PROFILE_SHIFT
 586                 prof_shift = CONFIG_PROFILE_SHIFT;
 587 #else
 588                 prof_shift = 2;
 589 #endif
 590 #endif
 591         if (prof_shift) {
 592                 prof_buffer = (unsigned long *) memory_start;
 593                 /* only text is profiled */
 594                 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
 595                 prof_len >>= prof_shift;
 596                 memory_start += prof_len * sizeof(unsigned long);
 597         }
 598         memory_start = console_init(memory_start,memory_end);
 599 #ifdef CONFIG_PCI
 600         memory_start = pci_init(memory_start,memory_end);
 601 #endif
 602         memory_start = kmalloc_init(memory_start,memory_end);
 603         sti();
 604         calibrate_delay();
 605         memory_start = inode_init(memory_start,memory_end);
 606         memory_start = file_table_init(memory_start,memory_end);
 607         memory_start = name_cache_init(memory_start,memory_end);
 608         mem_init(memory_start,memory_end);
 609         buffer_init();
 610         sock_init();
 611 #ifdef CONFIG_SYSVIPC
 612         ipc_init();
 613 #endif
 614 #ifdef CONFIG_APM
 615         apm_bios_init();
 616 #endif
 617         dquot_init();
 618         sti();
 619         check_bugs();
 620 
 621         printk(linux_banner);
 622 #ifdef __SMP__
 623         smp_init();
 624 #endif
 625         /* we count on the initial thread going ok */
 626         kernel_thread(init, NULL, 0);
 627 /*
 628  * task[0] is meant to be used as an "idle" task: it may not sleep, but
 629  * it might do some general things like count free pages or it could be
 630  * used to implement a reasonable LRU algorithm for the paging routines:
 631  * anything that can be useful, but shouldn't take time from the real
 632  * processes.
 633  *
 634  * Right now task[0] just does a infinite idle loop.
 635  */
 636         for(;;)
 637                 idle();
 638 }
 639 
 640 static int printf(const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 641 {
 642         va_list args;
 643         int i;
 644 
 645         va_start(args, fmt);
 646         write(1,printbuf,i=vsprintf(printbuf, fmt, args));
 647         va_end(args);
 648         return i;
 649 }
 650 
 651 static int do_rc(void * rc)
     /* [previous][next][first][last][top][bottom][index][help] */
 652 {
 653         close(0);
 654         if (open(rc,O_RDONLY,0))
 655                 return -1;
 656         return execve("/bin/sh", argv_rc, envp_rc);
 657 }
 658 
 659 static int do_shell(void * shell)
     /* [previous][next][first][last][top][bottom][index][help] */
 660 {
 661         close(0);close(1);close(2);
 662         setsid();
 663         (void) open("/dev/tty1",O_RDWR,0);
 664         (void) dup(0);
 665         (void) dup(0);
 666         return execve(shell, argv, envp);
 667 }
 668 
 669 static int init(void * unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 670 {
 671         int pid,i;
 672 
 673         /* Launch bdflush from here, instead of the old syscall way. */
 674         kernel_thread(bdflush, NULL, 0);
 675 
 676         setup();
 677 
 678 #ifdef __SMP__
 679         /*
 680          *      With the devices probed and setup we can
 681          *      now enter SMP mode.
 682          */
 683         
 684         smp_begin();
 685 #endif  
 686 
 687         #ifdef CONFIG_UMSDOS_FS
 688         {
 689                 /*
 690                         When mounting a umsdos fs as root, we detect
 691                         the pseudo_root (/linux) and initialise it here.
 692                         pseudo_root is defined in fs/umsdos/inode.c
 693                 */
 694                 extern struct inode *pseudo_root;
 695                 if (pseudo_root != NULL){
 696                         current->fs->root = pseudo_root;
 697                         current->fs->pwd  = pseudo_root;
 698                 }
 699         }
 700         #endif
 701 
 702         (void) open("/dev/tty1",O_RDWR,0);
 703         (void) dup(0);
 704         (void) dup(0);
 705 
 706         if (!execute_command) {
 707                 execve("/etc/init",argv_init,envp_init);
 708                 execve("/bin/init",argv_init,envp_init);
 709                 execve("/sbin/init",argv_init,envp_init);
 710                 /* if this fails, fall through to original stuff */
 711 
 712                 pid = kernel_thread(do_rc, "/etc/rc", SIGCHLD);
 713                 if (pid>0)
 714                         while (pid != wait(&i))
 715                                 /* nothing */;
 716                 }
 717 
 718         while (1) {
 719                 pid = kernel_thread(do_shell,
 720                         execute_command ? execute_command : "/bin/sh",
 721                         SIGCHLD);
 722                 if (pid < 0) {
 723                         printf("Fork failed in init\n\r");
 724                         continue;
 725                 }
 726                 while (1)
 727                         if (pid == wait(&i))
 728                                 break;
 729                 printf("\n\rchild %d died with code %04x\n\r",pid,i);
 730                 sync();
 731         }
 732         return -1;
 733 }

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