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