1: /* This file contains the C startup code for Minix on Intel processors.
   2:  * It cooperates with mpx.s to set up a good environment for main().
   3:  *
   4:  * This code runs in real mode for a 16 bit kernel and may have to switch
   5:  * to protected mode for a 286.
   6:  *
   7:  * For a 32 bit kernel this already runs in protected mode, but the selectors
   8:  * are still those given by the BIOS with interrupts disabled, so the
   9:  * descriptors need to be reloaded and interrupt descriptors made.
  10:  */
  11: 
  12: #include "kernel.h"
  13: #include <stdlib.h>
  14: #include "protect.h"
  15: 
  16: /* Environment strings passed by loader. */
  17: PRIVATE char k_environ[128*sizeof(char *)];
  18: 
  19: 
  20: /*==========================================================================*
  21:  *                              cstart                                      *
  22:  *==========================================================================*/
  23: PUBLIC void cstart(cs, ds, mds, parmoff, parmsize)
  24: U16_t cs, ds;                   /* Kernel code and data segment */
  25: U16_t mds;                      /* Monitor data segment */
  26: U16_t parmoff, parmsize;        /* boot parameters offset and length */
  27: {
  28: /* Perform system initializations prior to calling main(). */
  29: 
  30:   register char *envp;
  31:   unsigned mon_start;
  32: 
  33:   /* Record where the kernel and the monitor are. */
  34:   code_base = seg2phys(cs);
  35:   data_base = seg2phys(ds);
  36: 
  37:   /* Initialize protected mode descriptors. */
  38:   prot_init();
  39: 
  40:   /* Copy the boot parameters to kernel memory. */
  41:   mon_params = seg2phys(mds) + parmoff;
  42:   mon_parmsize = parmsize;
  43:   if (parmsize > sizeof k_environ - 2) parmsize = sizeof k_environ - 2;
  44:   phys_copy(mon_params, vir2phys(k_environ), (phys_bytes) parmsize);
  45: 
  46:   /* Type of VDU: */
  47:   envp = getenv("video");
  48:   if (strcmp(envp, "ega") == 0) ega = TRUE;
  49:   if (strcmp(envp, "vga") == 0) vga = ega = TRUE;
  50: 
  51:   /* Processor? */
  52:   processor = atoi(getenv("processor"));  /* 86, 186, 286, 386, ... */
  53: 
  54:   /* XT, AT or MCA bus? */
  55:   envp = getenv("bus");
  56:   if (envp == NIL_PTR || strcmp(envp, "at") == 0) {
  57:         pc_at = TRUE;
  58:   } else
  59:   if (strcmp(envp, "mca") == 0) {
  60:         pc_at = ps_mca = TRUE;
  61:   }
  62: 
  63:   /* Decide if mode is protected. */
  64: #if _WORD_SIZE == 2
  65:   protected_mode = processor >= 286;
  66:   if (!protected_mode) mon_return = 0;
  67: #endif
  68: 
  69:   /* Return to assembler code to switch to protected mode (if 286), reload
  70:    * selectors and call main().
  71:    */
  72: }
  73: 
  74: 
  75: /*==========================================================================*
  76:  *                              getenv                                      *
  77:  *==========================================================================*/
  78: PUBLIC char *getenv(name)
  79: _CONST char *name;
  80: {
  81: /* Get environment value - kernel version of getenv to avoid setting up the
  82:  * usual environment array.
  83:  */
  84: 
  85:   register _CONST char *namep;
  86:   register char *envp;
  87: 
  88:   for (envp = k_environ; *envp != 0;) {
  89:         for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
  90:                 ;
  91:         if (*namep == '\0' && *envp == '=') return(envp + 1);
  92:         while (*envp++ != 0)
  93:                 ;
  94:   }
  95:   return(NIL_PTR);
  96: }