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

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