~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Minix Cross Reference
Minix/kernel/misc.c


  1 /* This file contains a collection of miscellaneous procedures:
  2  *      mem_init:       initialize memory tables.  Some memory is reported
  3  *                      by the BIOS, some is guesstimated and checked later
  4  *      env_parse       parse environment variable.
  5  *      bad_assertion   for debugging
  6  *      bad_compare     for debugging
  7  */
  8 
  9 #include "kernel.h"
 10 #include "assert.h"
 11 #include <stdlib.h>
 12 #include <minix/com.h>
 13 
 14 #if (CHIP == INTEL)
 15 
 16 #define EM_BASE     0x100000L   /* base of extended memory on AT's */
 17 #define SHADOW_BASE 0xFA0000L   /* base of RAM shadowing ROM on some AT's */
 18 #define SHADOW_MAX  0x060000L   /* maximum usable shadow memory (16M limit) */
 19 #endif
 20 
 21 /*=========================================================================*
 22  *                              mem_init                                   *
 23  *=========================================================================*/
 24 PUBLIC void mem_init()
 25 {
 26 #if (MACHINE == SUN)
 27   /*
 28    * Smx "physical" memory is a single chunk that runs from the bottom of
 29    * the kernrel text segment.
 30    */
 31   mem[0].base = code_base >> CLICK_SHIFT;
 32   mem[0].size = tot_mem_size;
 33 #else
 34 /* Initialize the memory size tables.  This is complicated by fragmentation
 35  * and different access strategies for protected mode.  There must be a
 36  * chunk at 0 big enough to hold Minix proper.  For 286 and 386 processors,
 37  * there can be extended memory (memory above 1MB).  This usually starts at
 38  * 1MB, but there may be another chunk just below 16MB, reserved under DOS
 39  * for shadowing ROM, but available to Minix if the hardware can be re-mapped.
 40  * In protected mode, extended memory is accessible assuming CLICK_SIZE is
 41  * large enough, and is treated as ordinary memory.
 42  */
 43 
 44   u32_t ext_clicks;
 45   phys_clicks max_clicks;
 46 
 47   /* Get the size of ordinary memory from the BIOS. */
 48   mem[0].size = k_to_click(low_memsize);        /* base = 0 */
 49 
 50   if (pc_at && protected_mode) {
 51         /* Get the size of extended memory from the BIOS.  This is special
 52          * except in protected mode, but protected mode is now normal.
 53          * Note that no more than 16M can be addressed in 286 mode, so make
 54          * sure that the highest memory address fits in a short when counted
 55          * in clicks.
 56          */
 57         ext_clicks = k_to_click((u32_t) ext_memsize);
 58         max_clicks = USHRT_MAX - (EM_BASE >> CLICK_SHIFT);
 59         mem[1].size = MIN(ext_clicks, max_clicks);
 60         mem[1].base = EM_BASE >> CLICK_SHIFT;
 61 
 62         if (ext_memsize <= (unsigned) ((SHADOW_BASE - EM_BASE) / 1024)
 63                         && check_mem(SHADOW_BASE, SHADOW_MAX) == SHADOW_MAX) {
 64                 /* Shadow ROM memory. */
 65                 mem[2].size = SHADOW_MAX >> CLICK_SHIFT;
 66                 mem[2].base = SHADOW_BASE >> CLICK_SHIFT;
 67         }
 68   }
 69 
 70   /* Total system memory. */
 71   tot_mem_size = mem[0].size + mem[1].size + mem[2].size;
 72 #endif /* (CHIP == INTEL) */
 73 }
 74 
 75 
 76 #if (CHIP == INTEL)
 77 /*=========================================================================*
 78  *                              env_parse                                  *
 79  *=========================================================================*/
 80 PUBLIC int env_parse(env, fmt, field, param, min, max)
 81 char *env;              /* environment variable to inspect */
 82 char *fmt;              /* template to parse it with */
 83 int field;              /* field number of value to return */
 84 long *param;            /* address of parameter to get */
 85 long min, max;          /* minimum and maximum values for the parameter */
 86 {
 87 /* Parse an environment variable setting, something like "DPETH0=300:3".
 88  * Panic if the parsing fails.  Return EP_UNSET if the environment variable
 89  * is not set, EP_OFF if it is set to "off", EP_ON if set to "on" or a
 90  * field is left blank, or EP_SET if a field is given (return value through
 91  * *param).  Commas and colons may be used in the environment and format
 92  * string, fields in the environment string may be empty, and punctuation
 93  * may be missing to skip fields.  The format string contains characters
 94  * 'd', 'o', 'x' and 'c' to indicate that 10, 8, 16, or 0 is used as the
 95  * last argument to strtol.
 96  */
 97 
 98   char *val, *end;
 99   long newpar;
100   int i = 0, radix, r;
101 
102   if ((val = k_getenv(env)) == NIL_PTR) return(EP_UNSET);
103   if (strcmp(val, "off") == 0) return(EP_OFF);
104   if (strcmp(val, "on") == 0) return(EP_ON);
105 
106   r = EP_ON;
107   for (;;) {
108         while (*val == ' ') val++;
109 
110         if (*val == 0) return(r);       /* the proper exit point */
111 
112         if (*fmt == 0) break;           /* too many values */
113 
114         if (*val == ',' || *val == ':') {
115                 /* Time to go to the next field. */
116                 if (*fmt == ',' || *fmt == ':') i++;
117                 if (*fmt++ == *val) val++;
118         } else {
119                 /* Environment contains a value, get it. */
120                 switch (*fmt) {
121                 case 'd':       radix =   10;   break;
122                 case 'o':       radix =  010;   break;
123                 case 'x':       radix = 0x10;   break;
124                 case 'c':       radix =    0;   break;
125                 default:        goto badenv;
126                 }
127                 newpar = strtol(val, &end, radix);
128 
129                 if (end == val) break;  /* not a number */
130                 val = end;
131 
132                 if (i == field) {
133                         /* The field requested. */
134                         if (newpar < min || newpar > max) break;
135                         *param = newpar;
136                         r = EP_SET;
137                 }
138         }
139   }
140 badenv:
141   printf("Bad environment setting: '%s = %s'\n", env, k_getenv(env));
142   panic("", NO_NUM);
143   /*NOTREACHED*/
144 }
145 #endif /* (CHIP == INTEL) */
146 
147 #if DEBUG
148 /*=========================================================================*
149  *                              bad_assertion                              *
150  *=========================================================================*/
151 PUBLIC void bad_assertion(file, line, what)
152 char *file;
153 int line;
154 char *what;
155 {
156   printf("panic at %s(%d): assertion \"%s\" failed\n", file, line, what);
157   panic(NULL, NO_NUM);
158 }
159 
160 /*=========================================================================*
161  *                              bad_compare                                *
162  *=========================================================================*/
163 PUBLIC void bad_compare(file, line, lhs, what, rhs)
164 char *file;
165 int line;
166 int lhs;
167 char *what;
168 int rhs;
169 {
170   printf("panic at %s(%d): compare (%d) %s (%d) failed\n",
171         file, line, lhs, what, rhs);
172   panic(NULL, NO_NUM);
173 }
174 #endif /* DEBUG */
175 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.