-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN.C
233 lines (167 loc) · 6.75 KB
/
MAIN.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* ************************************************************************ *
* K6INIT *
* AMD K6-II(CXT) / K6-II+ / K6-III+ initialization driver for MS-DOS *
* (C) 2021 Eric Voirin *
* ************************************************************************ */
#include <dos.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <keepc.h>
#include <standard.h>
#include "k6.h"
#include "k6cmdl.h"
/* Hard error trap... I have no idea why this is here, but the
driver hybrid ASM+C example from DOS internals had this in it,
so I am keeping it :P */
static int _far HardErrorTrap (void)
{
return (_HARDERR_FAIL);
}
static const char k_program_name [] = "K6INIT";
static const int k_version_major = 0;
static const int k_version_minor = 91;
static const char k_copyright_text [] = "(C) 2021 Eric \"oerg866\" Voirin";
static const char k_contact_info [] = "Contact me on Discord: EricV#9999";
/* Message output */
static void PutError (char *str, ...);
/* ======================================================================== */
int main (int argc, char **argv)
{
mtrrConfigInfo mtrrSetup; // The MTRR regions to write. By
// default, we don't write anything.
int writeOrderSetup = 1 ; // Write order setup,
// For value see k6init.h, except:
// -1 = don't config
int writeAllocateSetup = 0; // Indicates user wants manual
// Write Allocate setup
// 1 = manual
// 0 = autodetect
// -1 = don't config
int multiplierSetup = 0; // Indicates whether user wants to set
// the CPU multiplier (K6-2+/III+ only)
// 1 = set the multiplier
// 0 = skip
int doLfbScan = 1; // By default, we scan for LFB in VBE.
int cpuType = k6_processorTypeNONE; // the detected CPU type.
int i;
int ret = 1;
unsigned long parsedMtrrAddr = 0UL;
unsigned long parsedMtrrSize = 0UL;
unsigned long parsedWASize = 0UL;
unsigned short parsedMultiplierIndex = 0;
int parsedWAMemoryHole = 0;
memset(&mtrrSetup, 0, sizeof(mtrrConfigInfo));
printf("%s Version %d.%02d\n", k_program_name, k_version_major, k_version_minor);
printf("%s\n", k_copyright_text);
printf("%s\n", k_contact_info);
printf("===============================================================================\n");
showMemoryInfo();
if (!checkAuthenticAMD()) {
printf("You don't have an AMD CPU. Aborting.\n");
goto cleanup;
}
cpuType = getSupportedCPUType();
if (cpuType == k6_processorTypeNONE) {
printf("Aborting\n");
goto cleanup;
}
printf("\n");
for (i = 1; i < argc; i++) {
// Parse an argument.
// Let's make it lowercase first so we support both cases.
toLowercase(argv[i]);
if (stringStartsWith(argv[i], "/wc:")) {
// Write Combine Parameter
ret = getMtrrValues(argv[i], &parsedMtrrAddr, &parsedMtrrSize);
if (ret) {
mtrrConfigInfoAppend(&mtrrSetup, parsedMtrrAddr,
parsedMtrrSize);
}
} else if (stringStartsWith(argv[i], "/wcdisable")) {
// Disable Write Combining compeltely in the CPU.
disableWriteCombining();
} else if (stringStartsWith(argv[i], "/nolfbscan")) {
// Disable LFB Scan
doLfbScan = 0;
} else if (stringStartsWith(argv[i], "/vga")) {
// Add Write Combining for VGA region.
printf("Setting up Write Combine for VGA region.\n");
mtrrConfigInfoAppend(&mtrrSetup, 0x000A0000UL, 131072UL);
} else if (stringStartsWith(argv[i], "/wa:")) {
// Set Write Allocate (disables automatic system scan)
ret = getWriteAllocateValues(argv[i], &writeAllocateSetup,
&parsedWASize, &parsedWAMemoryHole);
} else if (stringStartsWith(argv[i], "/wo:")) {
// Set Write Ordering Mode
ret = getWriteOrderValues(argv[i], &writeOrderSetup);
} else if (stringStartsWith(argv[i], "/multi:")) {
// Set Multiplier (K6-II only!)
ret = getMultiplierValues(argv[i], &multiplierSetup, &parsedMultiplierIndex);
} else if (stringStartsWith(argv[i], "/help")) {
// Print usage info. We exit after this.
printUsageInfo();
goto cleanup;
} else {
// Unknown parameter
printf("Unknown command line parameter: %s\n", argv[i]);
printf("Aborting.\n");
goto cleanup;
}
if (!ret) {
printf("Command line parsing error! Aborting.\n");
goto cleanup;
}
}
printf("\n");
if (!doLfbScan) {
printf("Disabling automatic VBE LFB scan.\n");
}
// Check for supported CPU for Multiplier operation
if (multiplierSetup && (cpuType != k6_processorTypePLUS)) {
printf("ERROR: Multiplier setting not supported on this CPU! Aborting.\n");
goto cleanup;
}
// Setup Write Allocate
if (writeAllocateSetup == 1) {
// Manual Setup, need to invert the presence of the memory hole
// to ENABLE WA for that region.
setWriteAllocateManual(parsedWASize, !parsedWAMemoryHole);
} else if (writeAllocateSetup == 0) {
// Autodetect memory and set WA
setWriteAllocateForSystemRAM();
} else {
printf("Skipping setup of Write Allocate.\n");
}
// Setup Write Combining
if (!configureWriteCombining(&mtrrSetup, doLfbScan)) {
printf("Error configuring Write Combining. Aborting.\n");
goto cleanup;
}
// Setup Write Ordering
if (writeOrderSetup >= 0) {
setWriteOrderMode(writeOrderSetup);
} else {
printf("Skipping setup of Write Ordering.\n");
}
// Setup Multiplier
if (multiplierSetup) {
setMultiplier(parsedMultiplierIndex);
}
/* Tidy up. */
cleanup:
CloseAllFiles ();
FreeEnvironment ();
return 0;
}
static void PutError (char *str, ...)
{
va_list va_start (argptr, str);
printf("\n%s error: ", k_program_name);
vprintf(str, argptr);
printf("\n");
va_end(argptr);
}
/* ************************************************************************ */