source: trunk/minix/kernel/start.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 4.3 KB
Line 
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 * For a 32 bit kernel this already runs in protected mode, but the selectors
7 * are still those given by the BIOS with interrupts disabled, so the
8 * descriptors need to be reloaded and interrupt descriptors made.
9 */
10
11#include "kernel.h"
12#include "protect.h"
13#include "proc.h"
14#include <stdlib.h>
15#include <string.h>
16
17FORWARD _PROTOTYPE( char *get_value, (_CONST char *params, _CONST char *key));
18/*===========================================================================*
19 * cstart *
20 *===========================================================================*/
21PUBLIC void cstart(cs, ds, mds, parmoff, parmsize)
22U16_t cs, ds; /* kernel code and data segment */
23U16_t mds; /* monitor data segment */
24U16_t parmoff, parmsize; /* boot parameters offset and length */
25{
26/* Perform system initializations prior to calling main(). Most settings are
27 * determined with help of the environment strings passed by MINIX' loader.
28 */
29 char params[128*sizeof(char *)]; /* boot monitor parameters */
30 register char *value; /* value in key=value pair */
31 extern int etext, end;
32 int h;
33
34 /* Decide if mode is protected; 386 or higher implies protected mode.
35 * This must be done first, because it is needed for, e.g., seg2phys().
36 * For 286 machines we cannot decide on protected mode, yet. This is
37 * done below.
38 */
39#if _WORD_SIZE != 2
40 machine.prot = 1;
41#endif
42
43 /* Record where the kernel and the monitor are. */
44 kinfo.code_base = seg2phys(cs);
45 kinfo.code_size = (phys_bytes) &etext; /* size of code segment */
46 kinfo.data_base = seg2phys(ds);
47 kinfo.data_size = (phys_bytes) &end; /* size of data segment */
48
49 /* Initialize protected mode descriptors. */
50 prot_init();
51
52 /* Copy the boot parameters to the local buffer. */
53 kinfo.params_base = seg2phys(mds) + parmoff;
54 kinfo.params_size = MIN(parmsize,sizeof(params)-2);
55 phys_copy(kinfo.params_base, vir2phys(params), kinfo.params_size);
56
57 /* Record miscellaneous information for user-space servers. */
58 kinfo.nr_procs = NR_PROCS;
59 kinfo.nr_tasks = NR_TASKS;
60 strncpy(kinfo.release, OS_RELEASE, sizeof(kinfo.release));
61 kinfo.release[sizeof(kinfo.release)-1] = '\0';
62 strncpy(kinfo.version, OS_VERSION, sizeof(kinfo.version));
63 kinfo.version[sizeof(kinfo.version)-1] = '\0';
64 kinfo.proc_addr = (vir_bytes) proc;
65 kinfo.kmem_base = vir2phys(0);
66 kinfo.kmem_size = (phys_bytes) &end;
67
68 /* Load average data initialization. */
69 kloadinfo.proc_last_slot = 0;
70 for(h = 0; h < _LOAD_HISTORY; h++)
71 kloadinfo.proc_load_history[h] = 0;
72
73 /* Processor? 86, 186, 286, 386, ...
74 * Decide if mode is protected for older machines.
75 */
76 machine.processor=atoi(get_value(params, "processor"));
77#if _WORD_SIZE == 2
78 machine.prot = machine.processor >= 286;
79#endif
80 if (! machine.prot) mon_return = 0;
81
82 /* XT, AT or MCA bus? */
83 value = get_value(params, "bus");
84 if (value == NIL_PTR || strcmp(value, "at") == 0) {
85 machine.pc_at = TRUE; /* PC-AT compatible hardware */
86 } else if (strcmp(value, "mca") == 0) {
87 machine.pc_at = machine.ps_mca = TRUE; /* PS/2 with micro channel */
88 }
89
90 /* Type of VDU: */
91 value = get_value(params, "video"); /* EGA or VGA video unit */
92 if (strcmp(value, "ega") == 0) machine.vdu_ega = TRUE;
93 if (strcmp(value, "vga") == 0) machine.vdu_vga = machine.vdu_ega = TRUE;
94
95 /* Return to assembler code to switch to protected mode (if 286),
96 * reload selectors and call main().
97 */
98}
99
100/*===========================================================================*
101 * get_value *
102 *===========================================================================*/
103
104PRIVATE char *get_value(params, name)
105_CONST char *params; /* boot monitor parameters */
106_CONST char *name; /* key to look up */
107{
108/* Get environment value - kernel version of getenv to avoid setting up the
109 * usual environment array.
110 */
111 register _CONST char *namep;
112 register char *envp;
113
114 for (envp = (char *) params; *envp != 0;) {
115 for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
116 ;
117 if (*namep == '\0' && *envp == '=') return(envp + 1);
118 while (*envp++ != 0)
119 ;
120 }
121 return(NIL_PTR);
122}
Note: See TracBrowser for help on using the repository browser.