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

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