3.1.7 branch.
[minix.git] / kernel / start.c
blob3b4786309799653693e5a342e491ac9e5babffd1
2 /* First C file used by the kernel. */
4 #include "kernel.h"
5 #include "proc.h"
6 #include <stdlib.h>
7 #include <string.h>
8 #include "proto.h"
10 #ifdef CONFIG_WATCHDOG
11 #include "watchdog.h"
12 #endif
14 /*===========================================================================*
15 * cstart *
16 *===========================================================================*/
17 PUBLIC void cstart(
18 u16_t cs, /* kernel code segment */
19 u16_t ds, /* kernel data segment */
20 u16_t mds, /* monitor data segment */
21 u16_t parmoff, /* boot parameters offset */
22 u16_t parmsize /* boot parameters length */
25 /* Perform system initializations prior to calling main(). Most settings are
26 * determined with help of the environment strings passed by MINIX' loader.
28 register char *value; /* value in key=value pair */
29 extern int etext, end;
30 int h;
32 /* Record where the kernel and the monitor are. */
33 kinfo.code_base = seg2phys(cs);
34 kinfo.code_size = (phys_bytes) &etext; /* size of code segment */
35 kinfo.data_base = seg2phys(ds);
36 kinfo.data_size = (phys_bytes) &end; /* size of data segment */
38 /* protection initialization */
39 prot_init();
41 /* Copy the boot parameters to the local buffer. */
42 arch_get_params(params_buffer, sizeof(params_buffer));
44 /* determine verbosity */
45 if ((value = env_get(VERBOSEBOOTVARNAME)))
46 verboseboot = atoi(value);
48 DEBUGEXTRA(("cstart\n"));
50 /* Record miscellaneous information for user-space servers. */
51 kinfo.nr_procs = NR_PROCS;
52 kinfo.nr_tasks = NR_TASKS;
53 strncpy(kinfo.release, OS_RELEASE, sizeof(kinfo.release));
54 kinfo.release[sizeof(kinfo.release)-1] = '\0';
55 strncpy(kinfo.version, OS_VERSION, sizeof(kinfo.version));
56 kinfo.version[sizeof(kinfo.version)-1] = '\0';
57 kinfo.proc_addr = (vir_bytes) proc;
59 /* Load average data initialization. */
60 kloadinfo.proc_last_slot = 0;
61 for(h = 0; h < _LOAD_HISTORY; h++)
62 kloadinfo.proc_load_history[h] = 0;
64 /* Processor? Decide if mode is protected for older machines. */
65 machine.processor=atoi(env_get("processor"));
67 /* XT, AT or MCA bus? */
68 value = env_get("bus");
69 if (value == NULL || strcmp(value, "at") == 0) {
70 machine.pc_at = TRUE; /* PC-AT compatible hardware */
71 } else if (strcmp(value, "mca") == 0) {
72 machine.pc_at = machine.ps_mca = TRUE; /* PS/2 with micro channel */
75 /* Type of VDU: */
76 value = env_get("video"); /* EGA or VGA video unit */
77 if (strcmp(value, "ega") == 0) machine.vdu_ega = TRUE;
78 if (strcmp(value, "vga") == 0) machine.vdu_vga = machine.vdu_ega = TRUE;
80 /* Get clock tick frequency. */
81 value = env_get("hz");
82 if(value)
83 system_hz = atoi(value);
84 if(!value || system_hz < 2 || system_hz > 50000) /* sanity check */
85 system_hz = DEFAULT_HZ;
86 value = env_get(SERVARNAME);
87 if(value && atoi(value) == 0)
88 do_serial_debug=1;
90 #ifdef CONFIG_APIC
91 value = env_get("no_apic");
92 if(value)
93 config_no_apic = atoi(value);
94 else
95 config_no_apic = 1;
96 #endif
98 #ifdef CONFIG_WATCHDOG
99 value = env_get("watchdog");
100 if (value)
101 watchdog_enabled = atoi(value);
102 #endif
104 /* Return to assembler code to switch to protected mode (if 286),
105 * reload selectors and call main().
108 DEBUGEXTRA(("intr_init(%d, 0)\n", INTS_MINIX));
109 intr_init(INTS_MINIX, 0);
112 /*===========================================================================*
113 * get_value *
114 *===========================================================================*/
116 PRIVATE char *get_value(
117 const char *params, /* boot monitor parameters */
118 const char *name /* key to look up */
121 /* Get environment value - kernel version of getenv to avoid setting up the
122 * usual environment array.
124 register const char *namep;
125 register char *envp;
127 for (envp = (char *) params; *envp != 0;) {
128 for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
130 if (*namep == '\0' && *envp == '=') return(envp + 1);
131 while (*envp++ != 0)
134 return(NULL);
137 /*===========================================================================*
138 * env_get *
139 *===========================================================================*/
140 PUBLIC char *env_get(const char *name)
142 return get_value(params_buffer, name);