📄 msic.c
字号:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/kernel/misc.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
08800 /* This file contains a collection of miscellaneous procedures:
08801 * mem_init: initialize memory tables. Some memory is reported
08802 * by the BIOS, some is guesstimated and checked later
08803 * env_parse parse environment variable.
08804 * bad_assertion for debugging
08805 * bad_compare for debugging
08806 */
08807
08808 #include "kernel.h"
08809 #include "assert.h"
08810 #include <stdlib.h>
08811 #include <minix/com.h>
08812
08813 #define EM_BASE 0x100000L /* base of extended memory on AT's */
08814 #define SHADOW_BASE 0xFA0000L /* base of RAM shadowing ROM on some AT's */
08815 #define SHADOW_MAX 0x060000L /* maximum usable shadow memory (16M limit) */
08816
08817 /*=========================================================================*
08818 * mem_init *
08819 *=========================================================================*/
08820 PUBLIC void mem_init()
08821 {
08822 /* Initialize the memory size tables. This is complicated by fragmentation
08823 * and different access strategies for protected mode. There must be a
08824 * chunk at 0 big enough to hold Minix proper. For 286 and 386 processors,
08825 * there can be extended memory (memory above 1MB). This usually starts at
08826 * 1MB, but there may be another chunk just below 16MB, reserved under DOS
08827 * for shadowing ROM, but available to Minix if the hardware can be re-mapped.
08828 * In protected mode, extended memory is accessible assuming CLICK_SIZE is
08829 * large enough, and is treated as ordinary memory.
08830 */
08831
08832 u32_t ext_clicks;
08833 phys_clicks max_clicks;
08834
08835 /* Get the size of ordinary memory from the BIOS. */
08836 mem[0].size = k_to_click(low_memsize); /* base = 0 */
08837
08838 if (pc_at && protected_mode) {
08839 /* Get the size of extended memory from the BIOS. This is special
08840 * except in protected mode, but protected mode is now normal.
08841 * Note that no more than 16M can be addressed in 286 mode, so make
08842 * sure that the highest memory address fits in a short when counted
08843 * in clicks.
08844 */
08845 ext_clicks = k_to_click((u32_t) ext_memsize);
08846 max_clicks = USHRT_MAX - (EM_BASE >> CLICK_SHIFT);
08847 mem[1].size = MIN(ext_clicks, max_clicks);
08848 mem[1].base = EM_BASE >> CLICK_SHIFT;
08849
08850 if (ext_memsize <= (unsigned) ((SHADOW_BASE - EM_BASE) / 1024)
08851 && check_mem(SHADOW_BASE, SHADOW_MAX) == SHADOW_MAX) {
08852 /* Shadow ROM memory. */
08853 mem[2].size = SHADOW_MAX >> CLICK_SHIFT;
08854 mem[2].base = SHADOW_BASE >> CLICK_SHIFT;
08855 }
08856 }
08857
08858 /* Total system memory. */
08859 tot_mem_size = mem[0].size + mem[1].size + mem[2].size;
08860 }
08862 /*=========================================================================*
08863 * env_parse *
08864 *=========================================================================*/
08865 PUBLIC int env_parse(env, fmt, field, param, min, max)
08866 char *env; /* environment variable to inspect */
08867 char *fmt; /* template to parse it with */
08868 int field; /* field number of value to return */
08869 long *param; /* address of parameter to get */
08870 long min, max; /* minimum and maximum values for the parameter */
08871 {
08872 /* Parse an environment variable setting, something like "DPETH0=300:3".
08873 * Panic if the parsing fails. Return EP_UNSET if the environment variable
08874 * is not set, EP_OFF if it is set to "off", EP_ON if set to "on" or a
08875 * field is left blank, or EP_SET if a field is given (return value through
08876 * *param). Commas and colons may be used in the environment and format
08877 * string, fields in the environment string may be empty, and punctuation
08878 * may be missing to skip fields. The format string contains characters
08879 * 'd', 'o', 'x' and 'c' to indicate that 10, 8, 16, or 0 is used as the
08880 * last argument to strtol.
08881 */
08882
08883 char *val, *end;
08884 long newpar;
08885 int i = 0, radix, r;
08886
08887 if ((val = k_getenv(env)) == NIL_PTR) return(EP_UNSET);
08888 if (strcmp(val, "off") == 0) return(EP_OFF);
08889 if (strcmp(val, "on") == 0) return(EP_ON);
08890
08891 r = EP_ON;
08892 for (;;) {
08893 while (*val == ' ') val++;
08894
08895 if (*val == 0) return(r); /* the proper exit point */
08896
08897 if (*fmt == 0) break; /* too many values */
08898
08899 if (*val == ',' || *val == ':') {
08900 /* Time to go to the next field. */
08901 if (*fmt == ',' || *fmt == ':') i++;
08902 if (*fmt++ == *val) val++;
08903 } else {
08904 /* Environment contains a value, get it. */
08905 switch (*fmt) {
08906 case 'd': radix = 10; break;
08907 case 'o': radix = 010; break;
08908 case 'x': radix = 0x10; break;
08909 case 'c': radix = 0; break;
08910 default: goto badenv;
08911 }
08912 newpar = strtol(val, &end, radix);
08913
08914 if (end == val) break; /* not a number */
08915 val = end;
08916
08917 if (i == field) {
08918 /* The field requested. */
08919 if (newpar < min || newpar > max) break;
08920 *param = newpar;
08921 r = EP_SET;
08922 }
08923 }
08924 }
08925 badenv:
08926 printf("Bad environment setting: '%s = %s'\n", env, k_getenv(env));
08927 panic("", NO_NUM);
08928 /*NOTREACHED*/
08929 }
08931 #if DEBUG
08932 /*=========================================================================*
08933 * bad_assertion *
08934 *=========================================================================*/
08935 PUBLIC void bad_assertion(file, line, what)
08936 char *file;
08937 int line;
08938 char *what;
08939 {
08940 printf("panic at %s(%d): assertion \"%s\" failed\n", file, line, what);
08941 panic(NULL, NO_NUM);
08942 }
08944 /*=========================================================================*
08945 * bad_compare *
08946 *=========================================================================*/
08947 PUBLIC void bad_compare(file, line, lhs, what, rhs)
08948 char *file;
08949 int line;
08950 int lhs;
08951 char *what;
08952 int rhs;
08953 {
08954 printf("panic at %s(%d): compare (%d) %s (%d) failed\n",
08955 file, line, lhs, what, rhs);
08956 panic(NULL, NO_NUM);
08957 }
08958 #endif /* DEBUG */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -