5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #undef MachConsPutChar
25 #undef MachVideoClearScreen
26 #undef MachVideoSetDisplayMode
27 #undef MachVideoGetDisplaySize
28 #undef MachVideoGetBufferSize
29 #undef MachVideoSetTextCursorPosition
30 #undef MachVideoHideShowTextCursor
31 #undef MachVideoPutChar
32 #undef MachVideoCopyOffScreenBufferToVRAM
33 #undef MachVideoIsPaletteFixed
34 #undef MachVideoSetPaletteColor
35 #undef MachVideoGetPaletteColor
38 #undef MachPrepareForReactOS
39 #undef MachDiskGetBootVolume
40 #undef MachDiskGetSystemVolume
41 #undef MachDiskGetBootPath
42 #undef MachDiskGetBootDevice
43 #undef MachDiskBootingFromFloppy
44 #undef MachDiskNormalizeSystemPath
45 #undef MachDiskReadLogicalSectors
46 #undef MachDiskGetPartitionEntry
47 #undef MachDiskGetDriveGeometry
48 #undef MachDiskGetCacheableBlockCount
54 MachConsPutChar(int Ch
)
56 MachVtbl
.ConsPutChar(Ch
);
62 return MachVtbl
.ConsKbHit();
68 return MachVtbl
.ConsGetCh();
72 MachVideoClearScreen(UCHAR Attr
)
74 MachVtbl
.VideoClearScreen(Attr
);
78 MachVideoSetDisplayMode(char *DisplayMode
, BOOLEAN Init
)
80 return MachVtbl
.VideoSetDisplayMode(DisplayMode
, Init
);
84 MachVideoGetDisplaySize(PULONG Width
, PULONG Height
, PULONG Depth
)
86 return MachVtbl
.VideoGetDisplaySize(Width
, Height
, Depth
);
90 MachVideoGetBufferSize(VOID
)
92 return MachVtbl
.VideoGetBufferSize();
96 MachVideoSetTextCursorPosition(ULONG X
, ULONG Y
)
98 return MachVtbl
.VideoSetTextCursorPosition(X
, Y
);
102 MachVideoHideShowTextCursor(BOOLEAN Show
)
104 MachVtbl
.VideoHideShowTextCursor(Show
);
108 MachVideoPutChar(int Ch
, UCHAR Attr
, unsigned X
, unsigned Y
)
110 MachVtbl
.VideoPutChar(Ch
, Attr
, X
, Y
);
114 MachVideoCopyOffScreenBufferToVRAM(PVOID Buffer
)
116 MachVtbl
.VideoCopyOffScreenBufferToVRAM(Buffer
);
120 MachVideoIsPaletteFixed(VOID
)
122 return MachVtbl
.VideoIsPaletteFixed();
126 MachVideoSetPaletteColor(UCHAR Color
, UCHAR Red
, UCHAR Green
, UCHAR Blue
)
128 return MachVtbl
.VideoSetPaletteColor(Color
, Red
, Green
, Blue
);
132 MachVideoGetPaletteColor(UCHAR Color
, UCHAR
*Red
, UCHAR
*Green
, UCHAR
*Blue
)
134 return MachVtbl
.VideoGetPaletteColor(Color
, Red
, Green
, Blue
);
140 MachVtbl
.VideoSync();
150 MachPrepareForReactOS(IN BOOLEAN Setup
)
152 MachVtbl
.PrepareForReactOS(Setup
);
159 BOOLEAN GeneratedDescriptor
;
160 } MEMORY_DESCRIPTOR_INT
;
161 static const MEMORY_DESCRIPTOR_INT MemoryDescriptors
[] =
163 #if defined (__i386__) || defined (_M_AMD64)
164 { { MemoryFirmwarePermanent
, 0x00, 1 }, 0, }, // realmode int vectors
165 { { MemoryFirmwareTemporary
, 0x01, 7 }, 1, }, // freeldr stack + cmdline
166 { { MemoryLoadedProgram
, 0x08, 0x70 }, 2, }, // freeldr image (roughly max. 0x64 pages)
167 { { MemorySpecialMemory
, 0x78, 8 }, 3, }, // prot mode stack. BIOSCALLBUFFER
168 { { MemoryFirmwareTemporary
, 0x80, 0x10 }, 4, }, // File system read buffer. FILESYSBUFFER
169 { { MemoryFirmwareTemporary
, 0x90, 0x10 }, 5, }, // Disk read buffer for int 13h. DISKREADBUFFER
170 { { MemoryFirmwarePermanent
, 0xA0, 0x60 }, 6, }, // ROM / Video
171 { { MemorySpecialMemory
, 0xFFF, 1 }, 7, }, // unusable memory
173 { { MemoryFirmwarePermanent
, 0x00, 1 }, 0, }, // arm exception handlers
174 { { MemoryFirmwareTemporary
, 0x01, 7 }, 1, }, // arm board block + freeldr stack + cmdline
175 { { MemoryLoadedProgram
, 0x08, 0x70 }, 2, }, // freeldr image (roughly max. 0x64 pages)
179 ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR
* Current
)
181 MEMORY_DESCRIPTOR_INT
* CurrentDescriptor
;
182 BIOS_MEMORY_MAP BiosMemoryMap
[32];
183 static ULONG BiosMemoryMapEntryCount
;
184 static MEMORY_DESCRIPTOR_INT BiosMemoryDescriptors
[32];
185 static BOOLEAN MemoryMapInitialized
= FALSE
;
189 // Does machine provide an override for this function?
191 if (MachVtbl
.GetMemoryDescriptor
)
194 // Yes. Use it instead
196 return MachVtbl
.GetMemoryDescriptor(Current
);
200 // Check if it is the first time we're called
202 if (!MemoryMapInitialized
)
205 // Get the machine generated memory map
207 RtlZeroMemory(BiosMemoryMap
, sizeof(BIOS_MEMORY_MAP
) * 32);
208 BiosMemoryMapEntryCount
= MachVtbl
.GetMemoryMap(BiosMemoryMap
,
209 sizeof(BiosMemoryMap
) / sizeof(BIOS_MEMORY_MAP
));
212 // Copy the entries to our structure
214 for (i
= 0, j
= 0; i
< BiosMemoryMapEntryCount
; i
++)
217 // Is it suitable memory?
219 if (BiosMemoryMap
[i
].Type
!= BiosMemoryUsable
)
222 // No. Process next descriptor
228 // Copy this memory descriptor
230 BiosMemoryDescriptors
[j
].m
.MemoryType
= MemoryFree
;
231 BiosMemoryDescriptors
[j
].m
.BasePage
= BiosMemoryMap
[i
].BaseAddress
/ MM_PAGE_SIZE
;
232 BiosMemoryDescriptors
[j
].m
.PageCount
= BiosMemoryMap
[i
].Length
/ MM_PAGE_SIZE
;
233 BiosMemoryDescriptors
[j
].Index
= j
;
234 BiosMemoryDescriptors
[j
].GeneratedDescriptor
= TRUE
;
239 // Remember how much descriptors we found
241 BiosMemoryMapEntryCount
= j
;
244 // Mark memory map as already retrieved and initialized
246 MemoryMapInitialized
= TRUE
;
249 CurrentDescriptor
= CONTAINING_RECORD(Current
, MEMORY_DESCRIPTOR_INT
, m
);
254 // First descriptor requested
256 if (BiosMemoryMapEntryCount
> 0)
259 // Return first generated memory descriptor
261 return &BiosMemoryDescriptors
[0].m
;
263 else if (sizeof(MemoryDescriptors
) > 0)
266 // Return first fixed memory descriptor
268 return (MEMORY_DESCRIPTOR
*)&MemoryDescriptors
[0].m
;
273 // Strange case, we have no memory descriptor
278 else if (CurrentDescriptor
->GeneratedDescriptor
)
281 // Current entry is a generated descriptor
283 if (CurrentDescriptor
->Index
+ 1 < BiosMemoryMapEntryCount
)
286 // Return next generated descriptor
288 return &BiosMemoryDescriptors
[CurrentDescriptor
->Index
+ 1].m
;
290 else if (sizeof(MemoryDescriptors
) > 0)
293 // Return first fixed memory descriptor
295 return (MEMORY_DESCRIPTOR
*)&MemoryDescriptors
[0].m
;
300 // No fixed memory descriptor; end of memory map
308 // Current entry is a fixed descriptor
310 if (CurrentDescriptor
->Index
+ 1 < sizeof(MemoryDescriptors
) / sizeof(MemoryDescriptors
[0]))
313 // Return next fixed descriptor
315 return (MEMORY_DESCRIPTOR
*)&MemoryDescriptors
[CurrentDescriptor
->Index
+ 1].m
;
320 // No more fixed memory descriptor; end of memory map
328 MachDiskGetBootVolume(PULONG DriveNumber
, PULONGLONG StartSector
, PULONGLONG SectorCount
, int *FsType
)
330 return MachVtbl
.DiskGetBootVolume(DriveNumber
, StartSector
, SectorCount
, FsType
);
334 MachDiskGetSystemVolume(char *SystemPath
,
338 PULONGLONG StartSector
,
339 PULONGLONG SectorCount
,
342 return MachVtbl
.DiskGetSystemVolume(SystemPath
, RemainingPath
, Device
,
343 DriveNumber
, StartSector
, SectorCount
,
348 MachDiskGetBootPath(char *BootPath
, unsigned Size
)
350 return MachVtbl
.DiskGetBootPath(BootPath
, Size
);
354 MachDiskGetBootDevice(PULONG BootDevice
)
356 MachVtbl
.DiskGetBootDevice(BootDevice
);
360 MachDiskBootingFromFloppy()
362 return MachVtbl
.DiskBootingFromFloppy();
366 MachDiskNormalizeSystemPath(char *SystemPath
, unsigned Size
)
368 return MachVtbl
.DiskNormalizeSystemPath(SystemPath
, Size
);
372 MachDiskReadLogicalSectors(ULONG DriveNumber
, ULONGLONG SectorNumber
, ULONG SectorCount
, PVOID Buffer
)
374 return MachVtbl
.DiskReadLogicalSectors(DriveNumber
, SectorNumber
, SectorCount
, Buffer
);
378 MachDiskGetPartitionEntry(ULONG DriveNumber
, ULONG PartitionNumber
, PPARTITION_TABLE_ENTRY PartitionTableEntry
)
380 return MachVtbl
.DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, PartitionTableEntry
);
384 MachDiskGetDriveGeometry(ULONG DriveNumber
, PGEOMETRY DriveGeometry
)
386 return MachVtbl
.DiskGetDriveGeometry(DriveNumber
, DriveGeometry
);
390 MachDiskGetCacheableBlockCount(ULONG DriveNumber
)
392 return MachVtbl
.DiskGetCacheableBlockCount(DriveNumber
);
398 return MachVtbl
.GetTime();
402 ArcGetRelativeTime(VOID
)
407 if (MachVtbl
.GetRelativeTime
)
408 return MachVtbl
.GetRelativeTime();
410 TimeInfo
= ArcGetTime();
411 ret
= ((TimeInfo
->Hour
* 24) + TimeInfo
->Minute
) * 60 + TimeInfo
->Second
;