-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbus.c
More file actions
500 lines (425 loc) · 12.3 KB
/
bus.c
File metadata and controls
500 lines (425 loc) · 12.3 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/***************************************************************************
*
* Copyright (c) 1997, 1998 Timpanogas Research Group, Inc. All Rights
* Reserved.
*
* AUTHOR : Jeff V. Merkey
* FILE : BUS.C
* DESCRIP : BUS and Machine Specific Code for MANOS v1.0
* DATE : April 13, 1998
*
* THIS MODULE CURRENTLY SUPPORTS MCA/EISA/PCI
*
***************************************************************************/
#include "stdarg.h"
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
#include "kernel.h"
#include "keyboard.h"
#include "screen.h"
#include "types.h"
#include "emit.h"
#include "os.h"
#include "dos.h"
#include "tss.h"
#include "mps.h"
#include "hal.h"
#include "xcall.h"
#include "window.h"
#include "line.h"
#include "loader.h"
#include "menu.h"
#include "dosfile.h"
extern void *AllocateMemoryBelow1MB(LONG);
extern void FreeMemoryBelow1MB(void *);
// MCA slot/function masks and value locations
#define MEM_ABOVE_16 0x0E
// EISA slot/function masks and value locations
#define MEM_PRESENT 0x00000002
#define ENTRY_CONT 0x00000080
#define MEM_SYSTEM 0x00000001
#define MEM_MASK 0x00000019
#define FUNCTION_INFO 0x00000022
#define EFI_FREE_FORM 0x00000073
#define MAX_EISA_FUNCTIONS 256
#define MAX_EISA_SLOTS 16
typedef struct _PCI_BIOS {
BYTE PCISignature[4];
LONG PCIEntry;
BYTE StructureRevision;
BYTE StructureLength;
BYTE StructureChecksum;
BYTE PCIReserved[5];
} PCI_BIOS_INFO;
#define PCI_BIOS_ENTRY_32 0x000FFE6E
//
// PCI BIOS/BUS SUPPORT FUNCTIONS
//
// PCI BIOS Present
//
// ah = 0xB1 test PCI bios present
// al = 0x01
//
// Returns:
//
// BIOS Not Present = carry flag is set
//
// BIOS Present = carry flag clear
//
// edx = ' PCI'
// dl = 'P'
// dh = 'C'
// ah = 0
// al bits 0 = Host/PCI Bridge Uses Config 1
// al bits 1 = Host/PCI Bridge Uses Config 2
// al bits 2-3 = Reserved
// al bits 4 = Special Cycle Supported Config 1
// al bits 5 = Special Cycle Supported Config 2
// al bits 6-7 = Reserved
// bh = BIOS major version BCD
// bl = BIOS minor version BCD
// cl = Number Of Last PIC bus in system
//
// PCI BIOS is present only if:
//
// A. EDX contains the name string 'PCI ' (AND)
// B. AL contains PCI settings (AND)
// C. Carry Flag is Clear
//
LONG PCIBIOSPresent(void)
{
register LONG retCode;
register LONG p, RealModeBuffer;
register REGS *inregs, *outregs;
inregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!inregs)
return 0;
outregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!outregs)
{
FreeMemoryBelow1MB(inregs);
return 0;
}
RealModeBuffer = (LONG) AllocateMemoryBelow1MB(0x1000);
if (!RealModeBuffer)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
return 0;
}
SetData((LONG *) inregs, 0, sizeof(REGS));
p = (LONG) RealModeBuffer;
inregs->ds = ((LONG)(p >> 4) & (LONG) 0xFFFF);
inregs->esi = ((LONG) p & (LONG) 0xF);
inregs->eax = 0xB101;
retCode = int86x(0x1A, inregs, outregs);
if (retCode || outregs->flags & 1)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return (0);
}
if (!outregs->eax >> 8 & 0xFF)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return (0);
}
if (outregs->edx != 0x20494350)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return (0);
}
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return (1);
}
//
// MICRO-CHANNEL BUS SUPPORT FUNCTIONS
//
//
// GetMCAMemoryMap
//
// ah = 0xC7
// al = 0x00
// ds:si address of 4K buffer for MCA memory map
//
// Returns:
//
// 00h Success (carry flag clear)
// 80h Function Unsupported (carry flag set)
// 86h Function Unsupported (carry flag set)
//
// [MCAMap + 0x0E] = Memory Above 16MB (1K Blocks)
// [MCAMap + 0x0E] << 10 = Memory Above 16MB (bytes)
//
LONG GetMCAMemory(void)
{
register LONG retCode;
register BYTE *ptr;
register LONG p, *lp, memory, RealModeBuffer;
register REGS *inregs, *outregs;
inregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!inregs)
return 0;
outregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!outregs)
{
FreeMemoryBelow1MB(inregs);
return 0;
}
RealModeBuffer = (LONG) AllocateMemoryBelow1MB(0x1000);
if (!RealModeBuffer)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
return 0;
}
SetData((LONG *) inregs, 0, sizeof(REGS));
p = (LONG) RealModeBuffer;
inregs->eax = 0xC700;
inregs->ds = ((LONG)(p >> 4) & (LONG) 0xFFFF);
inregs->esi = ((LONG) p & (LONG) 0xF);
retCode = int86x(0x15, inregs, outregs);
if (retCode || outregs->flags & 1)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
return (0);
}
ptr = (BYTE *) RealModeBuffer;
// memory above 16 MB returned from the
// MCA Memory Map
lp = (LONG *) &ptr[MEM_ABOVE_16];
// shift value << 10 to convert 1K blocks to bytes
// this function assumes if any size is returned
// for memory above 16MB, then we should add
// 16MB to any value we get except zero.
memory = (LONG)*lp << 10;
if (memory)
{
// round to MB boundry
memory &= 0xFFF00000;
memory += 0x01000000;
}
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return (memory);
}
//
// EISA BUS SUPPORT FUNCTIONS
//
//
// EISA Read Slot Configuration Request:
//
// ah = 0xD8
// al = 0x00 16 bit segments in CS/DS
// 0x80 32 bit segments in CS/DS
// cl = slot number
//
//
// EISA Read Slot Configuration Returns:
//
// ah = Completion code
//
// 0x00 Successful (CF is clear)
// 0x80 Invalid slot number (CF is set)
// 0x82 Invalid system configuration (CF set)
// 0x83 Empty slot (CF set)
// 0x86 Invalid BIOS routine call (CF set)
// 0x87 Invalid system configuration (CF set)
//
// al bits 0-3 = Duplicate ID number
// al bits 4-5 = Slot type
// al bit 6 = Product ID
// al bit 7 = Duplicate ID
// bh = Major revision level of configuration utility
// bl = Minor revision level of configuration utility
// cx = Checksum of configuration file
// dh = Number of device functions
// dl bit 0 = Slot has function type definitions
// dl bit 1 = Slot has memory entries
// dl bit 2 = Slot has interrupt entries
// dl bit 3 = Slot has DMA entries
// dl bit 4 = Slot has I/O port range entries
// dl bit 5 = Slot has I/O port initialization entries
// dl bit 6-7 = Reserved
// ds:si Compressed ID
//
// Determine which slot/functions have memory
//
// EISA Read Function Configuration Request
//
// ah = 0xD8
// al = 0x01 for 16 bit segments in CS and DS
// 0x81 for 32 bit segments in CS and DS
// cl = slot number
// ch = function number
// ds:si = pointer to 0x140 (320) byte buffer
//
//
// EISA Read Function Configuration Returns:
//
// ah = Completion code
// 0x00 Successful (CF is clear)
// 0x80 Invalid slot number (CF is set)
// 0x81 Invalid function number (CF is set)
// 0x82 Invalid system configuration (CF set)
// 0x83 Empty slot (CF set)
// 0x86 Invalid BIOS routine call (CF set)
// 0x87 Invalid System Configuration
// Buffer pointed to by ds:si is filled in with
// configuration data block information
//
LONG GetEISAConfigInfo(LONG slot, LONG function, BYTE *EISAData)
{
register LONG p, RealModeBuffer, retCode;
register REGS *inregs, *outregs;
inregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!inregs)
return 0;
outregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!outregs)
{
FreeMemoryBelow1MB(inregs);
return 0;
}
RealModeBuffer = (LONG) AllocateMemoryBelow1MB(0x1000);
if (!RealModeBuffer)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
return 0;
}
SetData((LONG *) inregs, 0, sizeof(REGS));
p = (LONG) RealModeBuffer;
inregs->eax = 0xD801;
inregs->ecx = (function << 8 | slot);
inregs->ds = ((LONG)(p >> 4) & (LONG) 0xFFFF);
inregs->esi = ((LONG) p & (LONG) 0xF);
retCode = int86x(0x15, inregs, outregs);
if (retCode)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return 0;
}
if (EISAData)
CopyDataB((LONG *) RealModeBuffer, (LONG *) EISAData, 320);
retCode = outregs->eax;
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
return retCode;
}
LONG GetEISAMemory(void)
{
register LONG retCode;
BYTE EISAConfig[512];
register LONG RealModeBuffer, p, Slot, Function, memory = 0;
register REGS *inregs, *outregs;
inregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!inregs)
return 0;
outregs = AllocateMemoryBelow1MB(sizeof(REGS));
if (!outregs)
{
FreeMemoryBelow1MB(inregs);
return 0;
}
RealModeBuffer = (LONG) AllocateMemoryBelow1MB(0x1000);
if (!RealModeBuffer)
{
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
return 0;
}
SetData((LONG *) inregs, 0, sizeof(REGS));
p = (LONG) RealModeBuffer;
inregs->ds = ((LONG)(p >> 4) & (LONG) 0xFFFF);
inregs->esi = ((LONG) p & (LONG) 0xF);
// scan each EISA slot, and get config info
for (Slot=0; Slot < MAX_EISA_SLOTS; Slot++)
{
inregs->eax = 0xD800;
inregs->ecx = Slot;
retCode = int86x(0x15, inregs, outregs);
if (retCode || outregs->flags & 1)
{
// if invalid slot number, then exit
if (outregs->eax >> 8 == 0x80)
break;
}
// if slot reports memory, scan functions for type
// of memory
if (outregs->edx & MEM_PRESENT)
{
// scan functions for a particular slot and read
// EISA configuration information
for (Function=0; Function < MAX_EISA_FUNCTIONS; Function++)
{
register BYTE *bp;
register LONG *lp;
register WORD *wp, wlen;
register LONG address, length, retCode;
retCode = GetEISAConfigInfo(Slot, Function, &EISAConfig[0]);
// if invalid Function number, then try next slot
if (retCode >> 8 == 0x81)
break;
// see if this slot has memory
if (EISAConfig[FUNCTION_INFO] & MEM_PRESENT)
{
// if this slot has memory, get a pointer
// into the EISA config information
bp = (BYTE *) &EISAConfig[EFI_FREE_FORM];
while (1)
{
// if this slot reports system memory, extract
// values
if (((LONG)*bp & MEM_MASK) == MEM_SYSTEM)
{
lp = (LONG *) &bp[1]; // get address entry
address = *lp;
address &= 0xFFFFFF00;
if (address >= 0x1000000) // if address is above 16MB
{
wp = (WORD *) &bp[5]; // get size entry
wlen = *wp;
length = (LONG) wlen;
length <<= 10; // convert 1K blocks to bytes
if (!length) // if we find a length of 0,
length = 0x4000000; // then assume size is 64MB
memory += length;
}
}
if (*bp & ENTRY_CONT) // move to next entry in this table
bp += 7; // if flags state there are more
else // entries
break;
}
}
}
}
}
FreeMemoryBelow1MB(inregs);
FreeMemoryBelow1MB(outregs);
FreeMemoryBelow1MB((void *)RealModeBuffer);
// if we found entries above 16MB, then assume a base
// of 16MB, and add to total
if (memory)
{
// round to MB boundry
memory &= 0xFFF00000;
memory += 0x01000000;
}
return memory;
}