ReactOS 0.4.16-dev-2293-g4d8327b
pchw.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for pchw.c:

Go to the source code of this file.

Macros

#define MILLISEC   (10)
 
#define PRECISION   (8)
 
#define CLOCK_TICK_RATE   1193182
 
#define HZ   (100)
 
#define LATCH   (CLOCK_TICK_RATE / HZ)
 

Functions

 DBG_DEFAULT_CHANNEL (HWDETECT)
 
PCHAR GetHarddiskIdentifier (UCHAR DriveNumber)
 
static VOID __StallExecutionProcessor (ULONG Loops)
 
VOID StallExecutionProcessor (ULONG Microseconds)
 
static ULONG Read8254Timer (VOID)
 
static VOID WaitFor8254Wraparound (VOID)
 
VOID HalpCalibrateStallExecution (VOID)
 
static UCHAR GetFloppyType (UCHAR DriveNumber)
 
static PVOID GetInt1eTable (VOID)
 
static VOID DetectBiosFloppyPeripheral (PCONFIGURATION_COMPONENT_DATA ControllerKey)
 
static PCONFIGURATION_COMPONENT_DATA DetectBiosFloppyController (PCONFIGURATION_COMPONENT_DATA BusKey)
 
VOID DetectBiosDisks (PCONFIGURATION_COMPONENT_DATA SystemKey, PCONFIGURATION_COMPONENT_DATA BusKey)
 
VOID FrLdrCheckCpuCompatibility (VOID)
 

Variables

static unsigned int delay_count = 1
 
UCHAR PcBiosDiskCount
 
GET_HARDDISK_CONFIG_DATA GetHarddiskConfigurationData = NULL
 

Macro Definition Documentation

◆ CLOCK_TICK_RATE

#define CLOCK_TICK_RATE   1193182

Definition at line 33 of file pchw.c.

◆ HZ

#define HZ   (100)

Definition at line 36 of file pchw.c.

◆ LATCH

#define LATCH   (CLOCK_TICK_RATE / HZ)

Definition at line 37 of file pchw.c.

◆ MILLISEC

#define MILLISEC   (10)

Definition at line 27 of file pchw.c.

◆ PRECISION

#define PRECISION   (8)

Definition at line 28 of file pchw.c.

Function Documentation

◆ __StallExecutionProcessor()

static VOID __StallExecutionProcessor ( ULONG  Loops)
static

Definition at line 54 of file pchw.c.

55{
56 register volatile unsigned int i;
57 for (i = 0; i < Loops; i++);
58}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by HalpCalibrateStallExecution(), and StallExecutionProcessor().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DetectBiosDisks()

VOID DetectBiosDisks ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
PCONFIGURATION_COMPONENT_DATA  BusKey 
)

Definition at line 342 of file pchw.c.

344{
345 PCONFIGURATION_COMPONENT_DATA ControllerKey, DiskKey;
346 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
347 PCM_INT13_DRIVE_PARAMETER Int13Drives;
348 GEOMETRY Geometry;
349 UCHAR DiskCount, DriveNumber;
350 USHORT i;
351 ULONG Size;
352
353 /* The pre-enumeration of the BIOS disks was already done in InitializeBootDevices() */
354 DiskCount = PcBiosDiskCount;
355
356 /* Use the floppy disk controller as our controller */
357 ControllerKey = DetectBiosFloppyController(BusKey);
358 if (!ControllerKey)
359 {
360 ERR("Failed to detect BIOS disk controller\n");
361 return;
362 }
363
364 /* Allocate resource descriptor */
365 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) +
366 sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
367 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
368 if (PartialResourceList == NULL)
369 {
370 ERR("Failed to allocate resource descriptor\n");
371 return;
372 }
373
374 /* Initialize resource descriptor */
375 RtlZeroMemory(PartialResourceList, Size);
376 PartialResourceList->Version = 1;
377 PartialResourceList->Revision = 1;
378 PartialResourceList->Count = 1;
379 PartialResourceList->PartialDescriptors[0].Type = CmResourceTypeDeviceSpecific;
380 PartialResourceList->PartialDescriptors[0].ShareDisposition = 0;
381 PartialResourceList->PartialDescriptors[0].Flags = 0;
382 PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
383 sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
384
385 /* Get harddisk Int13 geometry data */
386 Int13Drives = (PCM_INT13_DRIVE_PARAMETER)&PartialResourceList->PartialDescriptors[1];
387 for (i = 0; i < DiskCount; i++)
388 {
389 DriveNumber = 0x80 + i;
390
391 if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
392 {
393 Int13Drives[i].DriveSelect = DriveNumber;
394 Int13Drives[i].MaxCylinders = Geometry.Cylinders - 1;
395 Int13Drives[i].SectorsPerTrack = (USHORT)Geometry.SectorsPerTrack;
396 Int13Drives[i].MaxHeads = (USHORT)Geometry.Heads - 1;
397 Int13Drives[i].NumberDrives = DiskCount;
398
399 TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
400 DriveNumber,
401 Geometry.Cylinders - 1,
402 Geometry.Heads - 1,
403 Geometry.SectorsPerTrack,
404 Geometry.BytesPerSector);
405 }
406 }
407
408 /* Update the 'System' key's configuration data with BIOS INT13h information */
409 FldrSetConfigurationData(SystemKey, PartialResourceList, Size);
410
411 /* Create and fill subkey for each harddisk */
412 for (i = 0; i < DiskCount; i++)
413 {
415
416 DriveNumber = 0x80 + i;
417
418 /* Get disk values */
419 PartialResourceList = GetHarddiskConfigurationData(DriveNumber, &Size);
420 Identifier = GetHarddiskIdentifier(DriveNumber);
421
422 /* Create disk key */
423 FldrCreateComponentKey(ControllerKey,
426 Output | Input,
427 i,
428 0xFFFFFFFF,
430 PartialResourceList,
431 Size,
432 &DiskKey);
433 }
434}
VOID FldrCreateComponentKey(_In_ PCONFIGURATION_COMPONENT_DATA SystemNode, _In_ CONFIGURATION_CLASS Class, _In_ CONFIGURATION_TYPE Type, _In_ IDENTIFIER_FLAG Flags, _In_ ULONG Key, _In_ ULONG Affinity, _In_ PCSTR IdentifierString, _In_ PCM_PARTIAL_RESOURCE_LIST ResourceList, _In_ ULONG Size, _Out_ PCONFIGURATION_COMPONENT_DATA *ComponentKey)
Definition: archwsup.c:198
VOID FldrSetConfigurationData(_Inout_ PCONFIGURATION_COMPONENT_DATA ComponentData, _In_ PCM_PARTIAL_RESOURCE_LIST ResourceList, _In_ ULONG Size)
Definition: archwsup.c:124
@ Identifier
Definition: asmpp.cpp:95
#define ERR(fmt,...)
Definition: precomp.h:57
#define MachDiskGetDriveGeometry(Drive, Geom)
Definition: machine.h:122
PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: heap.c:533
#define NULL
Definition: types.h:112
#define for
Definition: utility.h:88
GET_HARDDISK_CONFIG_DATA GetHarddiskConfigurationData
Definition: pchw.c:45
static PCONFIGURATION_COMPONENT_DATA DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: pchw.c:271
PCHAR GetHarddiskIdentifier(UCHAR DriveNumber)
Definition: hwdisk.c:254
UCHAR PcBiosDiskCount
Definition: hwdisk.c:47
unsigned short USHORT
Definition: pedump.c:61
#define CmResourceTypeDeviceSpecific
Definition: restypes.h:108
@ PeripheralClass
Definition: arc.h:104
@ DiskPeripheral
Definition: arc.h:138
@ Input
Definition: arc.h:93
@ Output
Definition: arc.h:94
#define TRACE(s)
Definition: solgame.cpp:4
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@391 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382 u
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
Definition: disk.h:26
ULONG BytesPerSector
Number of bytes per sector.
Definition: disk.h:30
ULONG Cylinders
Number of cylinders on the disk.
Definition: disk.h:27
ULONG SectorsPerTrack
Number of sectors per track.
Definition: disk.h:29
ULONG Heads
Number of heads on the disk.
Definition: disk.h:28
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
const char * PCSTR
Definition: typedefs.h:52
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_HW_RESOURCE_LIST
Definition: uefidisk.c:15
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
struct _CM_INT13_DRIVE_PARAMETER * PCM_INT13_DRIVE_PARAMETER
struct _CM_INT13_DRIVE_PARAMETER CM_INT13_DRIVE_PARAMETER
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DetectIsaBios().

◆ DetectBiosFloppyController()

static PCONFIGURATION_COMPONENT_DATA DetectBiosFloppyController ( PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 271 of file pchw.c.

272{
273 PCONFIGURATION_COMPONENT_DATA ControllerKey;
274 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
275 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
276 ULONG Size;
277 ULONG FloppyCount;
278
279 FloppyCount = MachGetFloppyCount();
280 TRACE("Floppy count: %u\n", FloppyCount);
281
282 /* Always create a BIOS disk controller, no matter if we have floppy drives or not */
283 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[3]);
284 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
285 if (PartialResourceList == NULL)
286 {
287 ERR("Failed to allocate resource descriptor\n");
288 return NULL;
289 }
290
291 /* Initialize resource descriptor */
292 RtlZeroMemory(PartialResourceList, Size);
293 PartialResourceList->Version = 1;
294 PartialResourceList->Revision = 1;
295 PartialResourceList->Count = 3;
296
297 /* Set IO Port */
298 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
299 PartialDescriptor->Type = CmResourceTypePort;
301 PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
302 PartialDescriptor->u.Port.Start.LowPart = 0x03F0;
303 PartialDescriptor->u.Port.Start.HighPart = 0x0;
304 PartialDescriptor->u.Port.Length = 8;
305
306 /* Set Interrupt */
307 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
308 PartialDescriptor->Type = CmResourceTypeInterrupt;
310 PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
311 PartialDescriptor->u.Interrupt.Level = 6;
312 PartialDescriptor->u.Interrupt.Vector = 6;
313 PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
314
315 /* Set DMA channel */
316 PartialDescriptor = &PartialResourceList->PartialDescriptors[2];
317 PartialDescriptor->Type = CmResourceTypeDma;
319 PartialDescriptor->Flags = 0;
320 PartialDescriptor->u.Dma.Channel = 2;
321 PartialDescriptor->u.Dma.Port = 0;
322
323 /* Create floppy disk controller */
327 Output | Input,
328 0x0,
329 0xFFFFFFFF,
330 NULL,
331 PartialResourceList,
332 Size,
333 &ControllerKey);
334
335 if (FloppyCount)
336 DetectBiosFloppyPeripheral(ControllerKey);
337
338 return ControllerKey;
339}
@ DiskController
Definition: arcname.c:68
#define MachGetFloppyCount()
Definition: machine.h:118
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
static VOID DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
Definition: pchw.c:200
#define CmResourceTypeDma
Definition: restypes.h:107
#define CmResourceTypePort
Definition: restypes.h:104
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: restypes.h:117
#define CmResourceTypeInterrupt
Definition: restypes.h:105
@ ControllerClass
Definition: arc.h:103
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@388 Dma
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@384 Port
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@385 Interrupt
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241
@ CmResourceShareUndetermined
Definition: cmtypes.h:240

Referenced by DetectBiosDisks().

◆ DetectBiosFloppyPeripheral()

static VOID DetectBiosFloppyPeripheral ( PCONFIGURATION_COMPONENT_DATA  ControllerKey)
static

Definition at line 200 of file pchw.c.

201{
202 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
203 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
204 PCM_FLOPPY_DEVICE_DATA FloppyData;
205 CHAR Identifier[20];
206 PCONFIGURATION_COMPONENT_DATA PeripheralKey;
207 ULONG Size;
208 UCHAR FloppyNumber;
209 UCHAR FloppyType;
210 ULONG MaxDensity[6] = {0, 360, 1200, 720, 1440, 2880};
211 PUCHAR Ptr;
212
213 for (FloppyNumber = 0; FloppyNumber < 2; FloppyNumber++)
214 {
215 FloppyType = GetFloppyType(FloppyNumber);
216
217 if ((FloppyType > 5) || (FloppyType == 0))
218 continue;
219
220 if (!DiskResetController(FloppyNumber))
221 continue;
222
223 Ptr = GetInt1eTable();
224
225 /* Set 'Identifier' value */
226 RtlStringCbPrintfA(Identifier, sizeof(Identifier), "FLOPPY%d", FloppyNumber + 1);
227
228 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) + sizeof(*FloppyData);
229 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
230 if (PartialResourceList == NULL)
231 {
232 ERR("Failed to allocate resource descriptor! Ignoring remaining floppy peripherals. (FloppyNumber = %u)\n",
233 FloppyNumber);
234 return;
235 }
236
237 RtlZeroMemory(PartialResourceList, Size);
238 PartialResourceList->Version = 1;
239 PartialResourceList->Revision = 1;
240 PartialResourceList->Count = 1;
241
242 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
243 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
245 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(*FloppyData);
246
247 FloppyData = (PCM_FLOPPY_DEVICE_DATA)(PartialDescriptor + 1);
248 FloppyData->Version = 2;
249 FloppyData->Revision = 0;
250 FloppyData->MaxDensity = MaxDensity[FloppyType];
251 FloppyData->MountDensity = 0;
252 RtlCopyMemory(&FloppyData->StepRateHeadUnloadTime, Ptr, 11);
253 FloppyData->MaximumTrackValue = (FloppyType == 1) ? 39 : 79;
254 FloppyData->DataTransferRate = 0;
255
256 FldrCreateComponentKey(ControllerKey,
259 Input | Output,
260 FloppyNumber,
261 0xFFFFFFFF,
263 PartialResourceList,
264 Size,
265 &PeripheralKey);
266 }
267}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
BOOLEAN DiskResetController(UCHAR DriveNumber)
Definition: pcdisk.c:195
static PVOID GetInt1eTable(VOID)
Definition: pchw.c:190
static UCHAR GetFloppyType(UCHAR DriveNumber)
Definition: pchw.c:173
@ FloppyDiskPeripheral
Definition: arc.h:139
UCHAR StepRateHeadUnloadTime
Definition: cmtypes.h:489
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
struct _CM_FLOPPY_DEVICE_DATA * PCM_FLOPPY_DEVICE_DATA
char CHAR
Definition: xmlstorage.h:175

Referenced by DetectBiosFloppyController().

◆ FrLdrCheckCpuCompatibility()

VOID FrLdrCheckCpuCompatibility ( VOID  )

Definition at line 437 of file pchw.c.

438{
439 INT CpuInformation[4] = {-1};
440 ULONG NumberOfIds;
441
442 /* Check if the processor first supports ID 1 */
443 __cpuid(CpuInformation, 0);
444
445 NumberOfIds = CpuInformation[0];
446
447 if (NumberOfIds == 0)
448 {
450 __FILE__,
451 __LINE__,
452 "ReactOS requires the CPUID instruction to return "
453 "more than one supported ID.\n\n");
454 }
455
456 /* NumberOfIds will be greater than 1 if the processor is new enough */
457 if (NumberOfIds == 1)
458 {
459 INT ProcessorFamily;
460
461 /* Get information */
462 __cpuid(CpuInformation, 1);
463
464 ProcessorFamily = (CpuInformation[0] >> 8) & 0xF;
465
466 /* If it's Family 4 or lower, bugcheck */
467 if (ProcessorFamily < 5)
468 {
470 __FILE__,
471 __LINE__,
472 "Processor is too old (family %u < 5)\n"
473 "ReactOS requires a Pentium-level processor or newer.",
474 ProcessorFamily);
475 }
476 }
477}
DECLSPEC_NORETURN VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: debug.c:29
@ MISSING_HARDWARE_REQUIREMENTS
Definition: debug.h:146
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
int32_t INT
Definition: typedefs.h:58

◆ GetFloppyType()

static UCHAR GetFloppyType ( UCHAR  DriveNumber)
static

Definition at line 173 of file pchw.c.

174{
175 UCHAR Data;
176
177 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x10);
178 Data = READ_PORT_UCHAR((PUCHAR)0x71);
179
180 if (DriveNumber == 0)
181 return Data >> 4;
182 else if (DriveNumber == 1)
183 return Data & 0x0F;
184
185 return 0;
186}
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

Referenced by DetectBiosFloppyPeripheral().

◆ GetHarddiskIdentifier()

PCHAR GetHarddiskIdentifier ( UCHAR  DriveNumber)

Definition at line 254 of file hwdisk.c.

255{
256 return PcDiskIdentifier[DriveNumber - FIRST_BIOS_DISK];
257}
static CHAR PcDiskIdentifier[32][20]
Definition: hwdisk.c:48
#define FIRST_BIOS_DISK
Definition: hwdisk.c:31

Referenced by DetectBiosDisks().

◆ GetInt1eTable()

static PVOID GetInt1eTable ( VOID  )
static

Definition at line 190 of file pchw.c.

191{
192 PUSHORT SegPtr = (PUSHORT)0x7A;
193 PUSHORT OfsPtr = (PUSHORT)0x78;
194
195 return (PVOID)((ULONG_PTR)(((ULONG)(*SegPtr)) << 4) + (ULONG)(*OfsPtr));
196}
#define ULONG_PTR
Definition: config.h:101
uint16_t * PUSHORT
Definition: typedefs.h:56

Referenced by DetectBiosFloppyPeripheral().

◆ HalpCalibrateStallExecution()

VOID HalpCalibrateStallExecution ( VOID  )

Definition at line 105 of file pchw.c.

106{
107 ULONG i;
108 ULONG calib_bit;
109 ULONG CurCount;
110
111 /* Initialise timer interrupt with MILLISECOND ms interval */
112 WRITE_PORT_UCHAR((PUCHAR)0x43, 0x34); /* binary, mode 2, LSB/MSB, ch 0 */
113 WRITE_PORT_UCHAR((PUCHAR)0x40, LATCH & 0xff); /* LSB */
114 WRITE_PORT_UCHAR((PUCHAR)0x40, LATCH >> 8); /* MSB */
115
116 /* Stage 1: Coarse calibration */
117
118 delay_count = 1;
119
120 do
121 {
122 /* Next delay count to try */
123 delay_count <<= 1;
124
126
127 /* Do the delay */
129
130 CurCount = Read8254Timer();
131 }
132 while (CurCount > LATCH / 2);
133
134 /* Get bottom value for delay */
135 delay_count >>= 1;
136
137 /* Stage 2: Fine calibration */
138
139 /* Which bit are we going to test */
140 calib_bit = delay_count;
141
142 for (i = 0; i < PRECISION; i++)
143 {
144 /* Next bit to calibrate */
145 calib_bit >>= 1;
146
147 /* If we have done all bits, stop */
148 if (!calib_bit) break;
149
150 /* Set the bit in delay_count */
151 delay_count |= calib_bit;
152
154
155 /* Do the delay */
157
158 CurCount = Read8254Timer();
159 /* If a tick has passed, turn the calibrated bit back off */
160 if (CurCount <= LATCH / 2)
161 delay_count &= ~calib_bit;
162 }
163
164 /* We're finished: Do the finishing touches */
165
166 /* Calculate delay_count for 1ms */
167 delay_count /= (MILLISEC / 2);
168}
#define MILLISEC
Definition: pchw.c:27
static VOID WaitFor8254Wraparound(VOID)
Definition: pchw.c:81
static VOID __StallExecutionProcessor(ULONG Loops)
Definition: pchw.c:54
#define PRECISION
Definition: pchw.c:28
#define LATCH
Definition: pchw.c:37
static unsigned int delay_count
Definition: pchw.c:39
static ULONG Read8254Timer(VOID)
Definition: pchw.c:68

Referenced by HalInitSystem(), and MachInit().

◆ Read8254Timer()

static ULONG Read8254Timer ( VOID  )
static

Definition at line 68 of file pchw.c.

69{
71
72 WRITE_PORT_UCHAR((PUCHAR)0x43, 0x00);
74 Count |= READ_PORT_UCHAR((PUCHAR)0x40) << 8;
75
76 return Count;
77}
int Count
Definition: noreturn.cpp:7

Referenced by HalpCalibrateStallExecution(), and WaitFor8254Wraparound().

◆ StallExecutionProcessor()

◆ WaitFor8254Wraparound()

static VOID WaitFor8254Wraparound ( VOID  )
static

Definition at line 81 of file pchw.c.

82{
83 ULONG CurCount;
84 ULONG PrevCount = ~0;
85 LONG Delta;
86
87 CurCount = Read8254Timer();
88
89 do
90 {
91 PrevCount = CurCount;
92 CurCount = Read8254Timer();
93 Delta = CurCount - PrevCount;
94
95 /*
96 * This limit for delta seems arbitrary, but it isn't, it's
97 * slightly above the level of error a buggy Mercury/Neptune
98 * chipset timer can cause.
99 */
100 }
101 while (Delta < 300);
102}
long LONG
Definition: pedump.c:60

Referenced by HalpCalibrateStallExecution().

Variable Documentation

◆ delay_count

unsigned int delay_count = 1
static

Definition at line 39 of file pchw.c.

Referenced by HalpCalibrateStallExecution(), and StallExecutionProcessor().

◆ GetHarddiskConfigurationData

GET_HARDDISK_CONFIG_DATA GetHarddiskConfigurationData = NULL

Definition at line 45 of file pchw.c.

Referenced by DetectBiosDisks(), PcHwDetect(), and XboxHwDetect().

◆ PcBiosDiskCount

UCHAR PcBiosDiskCount
extern

Definition at line 47 of file hwdisk.c.

Referenced by DetectBiosDisks().