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 |
|
---|
17 | FORWARD _PROTOTYPE( char *get_value, (_CONST char *params, _CONST char *key));
|
---|
18 | /*===========================================================================*
|
---|
19 | * cstart *
|
---|
20 | *===========================================================================*/
|
---|
21 | PUBLIC void cstart(cs, ds, mds, parmoff, parmsize)
|
---|
22 | U16_t cs, ds; /* kernel code and data segment */
|
---|
23 | U16_t mds; /* monitor data segment */
|
---|
24 | U16_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 |
|
---|
33 | /* Decide if mode is protected; 386 or higher implies protected mode.
|
---|
34 | * This must be done first, because it is needed for, e.g., seg2phys().
|
---|
35 | * For 286 machines we cannot decide on protected mode, yet. This is
|
---|
36 | * done below.
|
---|
37 | */
|
---|
38 | #if _WORD_SIZE != 2
|
---|
39 | machine.protected = 1;
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | /* Record where the kernel and the monitor are. */
|
---|
43 | kinfo.code_base = seg2phys(cs);
|
---|
44 | kinfo.code_size = (phys_bytes) &etext; /* size of code segment */
|
---|
45 | kinfo.data_base = seg2phys(ds);
|
---|
46 | kinfo.data_size = (phys_bytes) &end; /* size of data segment */
|
---|
47 |
|
---|
48 | /* Initialize protected mode descriptors. */
|
---|
49 | prot_init();
|
---|
50 |
|
---|
51 | /* Copy the boot parameters to the local buffer. */
|
---|
52 | kinfo.params_base = seg2phys(mds) + parmoff;
|
---|
53 | kinfo.params_size = MIN(parmsize,sizeof(params)-2);
|
---|
54 | phys_copy(kinfo.params_base, vir2phys(params), kinfo.params_size);
|
---|
55 |
|
---|
56 | /* Record miscellaneous information for user-space servers. */
|
---|
57 | kinfo.nr_procs = NR_PROCS;
|
---|
58 | kinfo.nr_tasks = NR_TASKS;
|
---|
59 | strncpy(kinfo.release, OS_RELEASE, sizeof(kinfo.release));
|
---|
60 | kinfo.release[sizeof(kinfo.release)-1] = '\0';
|
---|
61 | strncpy(kinfo.version, OS_VERSION, sizeof(kinfo.version));
|
---|
62 | kinfo.version[sizeof(kinfo.version)-1] = '\0';
|
---|
63 | kinfo.proc_addr = (vir_bytes) proc;
|
---|
64 | kinfo.kmem_base = vir2phys(0);
|
---|
65 | kinfo.kmem_size = (phys_bytes) &end;
|
---|
66 |
|
---|
67 | /* Processor? 86, 186, 286, 386, ...
|
---|
68 | * Decide if mode is protected for older machines.
|
---|
69 | */
|
---|
70 | machine.processor=atoi(get_value(params, "processor"));
|
---|
71 | #if _WORD_SIZE == 2
|
---|
72 | machine.protected = machine.processor >= 286;
|
---|
73 | #endif
|
---|
74 | if (! machine.protected) mon_return = 0;
|
---|
75 |
|
---|
76 | /* XT, AT or MCA bus? */
|
---|
77 | value = get_value(params, "bus");
|
---|
78 | if (value == NIL_PTR || strcmp(value, "at") == 0) {
|
---|
79 | machine.pc_at = TRUE; /* PC-AT compatible hardware */
|
---|
80 | } else if (strcmp(value, "mca") == 0) {
|
---|
81 | machine.pc_at = machine.ps_mca = TRUE; /* PS/2 with micro channel */
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* Type of VDU: */
|
---|
85 | value = get_value(params, "video"); /* EGA or VGA video unit */
|
---|
86 | if (strcmp(value, "ega") == 0) machine.vdu_ega = TRUE;
|
---|
87 | if (strcmp(value, "vga") == 0) machine.vdu_vga = machine.vdu_ega = TRUE;
|
---|
88 |
|
---|
89 | /* Return to assembler code to switch to protected mode (if 286),
|
---|
90 | * reload selectors and call main().
|
---|
91 | */
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*===========================================================================*
|
---|
95 | * get_value *
|
---|
96 | *===========================================================================*/
|
---|
97 |
|
---|
98 | PRIVATE char *get_value(params, name)
|
---|
99 | _CONST char *params; /* boot monitor parameters */
|
---|
100 | _CONST char *name; /* key to look up */
|
---|
101 | {
|
---|
102 | /* Get environment value - kernel version of getenv to avoid setting up the
|
---|
103 | * usual environment array.
|
---|
104 | */
|
---|
105 | register _CONST char *namep;
|
---|
106 | register char *envp;
|
---|
107 |
|
---|
108 | for (envp = (char *) params; *envp != 0;) {
|
---|
109 | for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
|
---|
110 | ;
|
---|
111 | if (*namep == '\0' && *envp == '=') return(envp + 1);
|
---|
112 | while (*envp++ != 0)
|
---|
113 | ;
|
---|
114 | }
|
---|
115 | return(NIL_PTR);
|
---|
116 | }
|
---|