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

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