ReactOS  0.4.14-dev-317-g96040ec
cmos.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CMOS_CLOCK
 
struct  CMOS_MEMORY
 

Macros

#define RTC_IRQ_NUMBER   8
 
#define CMOS_ADDRESS_PORT   0x70
 
#define CMOS_DATA_PORT   0x71
 
#define CMOS_DISABLE_NMI   (1 << 7)
 
#define CMOS_BATTERY_OK   0x80
 
#define CMOS_STB_DST   (1 << 0)
 
#define CMOS_STB_24HOUR   (1 << 1)
 
#define CMOS_STB_BINARY   (1 << 2)
 
#define CMOS_STB_SQUARE_WAVE   (1 << 3)
 
#define CMOS_STB_INT_ON_UPDATE   (1 << 4)
 
#define CMOS_STB_INT_ON_ALARM   (1 << 5)
 
#define CMOS_STB_INT_PERIODIC   (1 << 6)
 
#define CMOS_STB_UPDATE_CYCLE   (1 << 7)
 
#define CMOS_STC_UF   (1 << 4)
 
#define CMOS_STC_AF   (1 << 5)
 
#define CMOS_STC_PF   (1 << 6)
 
#define CMOS_STC_IRQF   (1 << 7)
 
#define CMOS_DEFAULT_STA   0x26
 
#define CMOS_DEFAULT_STB   CMOS_STB_24HOUR
 
#define CMOS_EQUIPMENT_LIST   0x6F
 
#define WRITE_CMOS_DATA(Cmos, Value)   ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)
 
#define READ_CMOS_DATA(Cmos, Value)   ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)
 

Typedefs

typedef enum _CMOS_REGISTERS CMOS_REGISTERS
 
typedef enum _CMOS_REGISTERSPCMOS_REGISTERS
 
typedef struct CMOS_CLOCKPCMOS_CLOCK
 
typedef struct CMOS_MEMORYPCMOS_MEMORY
 

Enumerations

enum  _CMOS_REGISTERS {
  CMOS_REG_SECONDS, CMOS_REG_ALARM_SEC, CMOS_REG_MINUTES, CMOS_REG_ALARM_MIN,
  CMOS_REG_HOURS, CMOS_REG_ALARM_HRS, CMOS_REG_DAY_OF_WEEK, CMOS_REG_DAY,
  CMOS_REG_MONTH, CMOS_REG_YEAR, CMOS_REG_STATUS_A, CMOS_REG_STATUS_B,
  CMOS_REG_STATUS_C, CMOS_REG_STATUS_D, CMOS_REG_DIAGNOSTICS, CMOS_REG_SHUTDOWN_STATUS,
  CMOS_REG_EQUIPMENT_LIST = 0x14, CMOS_REG_BASE_MEMORY_LOW = 0x15, CMOS_REG_BASE_MEMORY_HIGH = 0x16, CMOS_REG_EXT_MEMORY_LOW = 0x17,
  CMOS_REG_EXT_MEMORY_HIGH = 0x18, CMOS_REG_SYSOP = 0x2D, CMOS_REG_ACTUAL_EXT_MEMORY_LOW = 0x30, CMOS_REG_ACTUAL_EXT_MEMORY_HIGH = 0x31,
  CMOS_REG_CENTURY = 0x32, CMOS_REG_MAX = 0x40
}
 

Functions

 C_ASSERT (sizeof(CMOS_MEMORY)==0x40)
 
BOOLEAN IsNmiEnabled (VOID)
 
DWORD RtcGetTicksPerSecond (VOID)
 
VOID CmosInitialize (VOID)
 
VOID CmosCleanup (VOID)
 

Macro Definition Documentation

◆ CMOS_ADDRESS_PORT

#define CMOS_ADDRESS_PORT   0x70

Definition at line 15 of file cmos.h.

◆ CMOS_BATTERY_OK

#define CMOS_BATTERY_OK   0x80

Definition at line 18 of file cmos.h.

◆ CMOS_DATA_PORT

#define CMOS_DATA_PORT   0x71

Definition at line 16 of file cmos.h.

◆ CMOS_DEFAULT_STA

#define CMOS_DEFAULT_STA   0x26

Definition at line 37 of file cmos.h.

◆ CMOS_DEFAULT_STB

#define CMOS_DEFAULT_STB   CMOS_STB_24HOUR

Definition at line 38 of file cmos.h.

◆ CMOS_DISABLE_NMI

#define CMOS_DISABLE_NMI   (1 << 7)

Definition at line 17 of file cmos.h.

◆ CMOS_EQUIPMENT_LIST

#define CMOS_EQUIPMENT_LIST   0x6F

Definition at line 41 of file cmos.h.

◆ CMOS_STB_24HOUR

#define CMOS_STB_24HOUR   (1 << 1)

Definition at line 22 of file cmos.h.

◆ CMOS_STB_BINARY

#define CMOS_STB_BINARY   (1 << 2)

Definition at line 23 of file cmos.h.

◆ CMOS_STB_DST

#define CMOS_STB_DST   (1 << 0)

Definition at line 21 of file cmos.h.

◆ CMOS_STB_INT_ON_ALARM

#define CMOS_STB_INT_ON_ALARM   (1 << 5)

Definition at line 26 of file cmos.h.

◆ CMOS_STB_INT_ON_UPDATE

#define CMOS_STB_INT_ON_UPDATE   (1 << 4)

Definition at line 25 of file cmos.h.

◆ CMOS_STB_INT_PERIODIC

#define CMOS_STB_INT_PERIODIC   (1 << 6)

Definition at line 27 of file cmos.h.

◆ CMOS_STB_SQUARE_WAVE

#define CMOS_STB_SQUARE_WAVE   (1 << 3)

Definition at line 24 of file cmos.h.

◆ CMOS_STB_UPDATE_CYCLE

#define CMOS_STB_UPDATE_CYCLE   (1 << 7)

Definition at line 28 of file cmos.h.

◆ CMOS_STC_AF

#define CMOS_STC_AF   (1 << 5)

Definition at line 32 of file cmos.h.

◆ CMOS_STC_IRQF

#define CMOS_STC_IRQF   (1 << 7)

Definition at line 34 of file cmos.h.

◆ CMOS_STC_PF

#define CMOS_STC_PF   (1 << 6)

Definition at line 33 of file cmos.h.

◆ CMOS_STC_UF

#define CMOS_STC_UF   (1 << 4)

Definition at line 31 of file cmos.h.

◆ READ_CMOS_DATA

#define READ_CMOS_DATA (   Cmos,
  Value 
)    ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BINARY_TO_BCD(Value)

Definition at line 47 of file cmos.h.

◆ RTC_IRQ_NUMBER

#define RTC_IRQ_NUMBER   8

Definition at line 14 of file cmos.h.

◆ WRITE_CMOS_DATA

#define WRITE_CMOS_DATA (   Cmos,
  Value 
)    ((Cmos).StatusRegB & CMOS_STB_BINARY) ? (Value) : BCD_TO_BINARY(Value)

Definition at line 44 of file cmos.h.

Typedef Documentation

◆ CMOS_REGISTERS

◆ PCMOS_CLOCK

◆ PCMOS_MEMORY

◆ PCMOS_REGISTERS

Enumeration Type Documentation

◆ _CMOS_REGISTERS

Enumerator
CMOS_REG_SECONDS 
CMOS_REG_ALARM_SEC 
CMOS_REG_MINUTES 
CMOS_REG_ALARM_MIN 
CMOS_REG_HOURS 
CMOS_REG_ALARM_HRS 
CMOS_REG_DAY_OF_WEEK 
CMOS_REG_DAY 
CMOS_REG_MONTH 
CMOS_REG_YEAR 
CMOS_REG_STATUS_A 
CMOS_REG_STATUS_B 
CMOS_REG_STATUS_C 
CMOS_REG_STATUS_D 
CMOS_REG_DIAGNOSTICS 
CMOS_REG_SHUTDOWN_STATUS 
CMOS_REG_EQUIPMENT_LIST 
CMOS_REG_BASE_MEMORY_LOW 
CMOS_REG_BASE_MEMORY_HIGH 
CMOS_REG_EXT_MEMORY_LOW 
CMOS_REG_EXT_MEMORY_HIGH 
CMOS_REG_SYSOP 
CMOS_REG_ACTUAL_EXT_MEMORY_LOW 
CMOS_REG_ACTUAL_EXT_MEMORY_HIGH 
CMOS_REG_CENTURY 
CMOS_REG_MAX 

Definition at line 50 of file cmos.h.

51 {
73  CMOS_REG_SYSOP = 0x2D,
76  CMOS_REG_CENTURY = 0x32,
77  CMOS_REG_MAX = 0x40
enum _CMOS_REGISTERS * PCMOS_REGISTERS
enum _CMOS_REGISTERS CMOS_REGISTERS

Function Documentation

◆ C_ASSERT()

C_ASSERT ( sizeof(CMOS_MEMORY = =0x40)

◆ CmosCleanup()

VOID CmosCleanup ( VOID  )

Definition at line 519 of file cmos.c.

520 {
521  DWORD CmosSize = sizeof(CmosMemory);
522 
523  if (hCmosRam == INVALID_HANDLE_VALUE) return;
524 
527 
528  /* Flush the CMOS memory back to the RAM file and close it */
530  WriteFile(hCmosRam, &CmosMemory, CmosSize, &CmosSize, NULL);
531 
534 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:398
static HANDLE hCmosRam
Definition: cmos.c:25
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
static CMOS_MEMORY CmosMemory
Definition: cmos.c:26
smooth NULL
Definition: ftsmooth.c:416
static PHARDWARE_TIMER PeriodicTimer
Definition: cmos.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
static PHARDWARE_TIMER ClockTimer
Definition: cmos.c:31
#define FILE_BEGIN
Definition: winbase.h:112
VOID DestroyHardwareTimer(PHARDWARE_TIMER Timer)
Definition: clock.c:210

Referenced by EmulatorCleanup().

◆ CmosInitialize()

VOID CmosInitialize ( VOID  )

Definition at line 441 of file cmos.c.

442 {
443  DWORD CmosSize = sizeof(CmosMemory);
444 
445  /* File must not be opened before */
447 
448  /* Clear the CMOS memory */
450 
451  /* Always open (and if needed, create) a RAM file with shared access */
452  SetLastError(0); // For debugging purposes
453  hCmosRam = CreateFileW(L"cmos.ram",
456  NULL,
457  OPEN_ALWAYS,
459  NULL);
460  DPRINT1("CMOS opening %s (Error: %u)\n", hCmosRam != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError());
461 
463  {
464  BOOL Success;
465 
466  /* Attempt to fill the CMOS memory with the RAM file */
467  SetLastError(0); // For debugging purposes
468  Success = ReadFile(hCmosRam, &CmosMemory, CmosSize, &CmosSize, NULL);
469  if (CmosSize != sizeof(CmosMemory))
470  {
471  /* Bad CMOS RAM file. Reinitialize the CMOS memory. */
472  DPRINT1("Invalid CMOS file, read bytes %u, expected bytes %u\n", CmosSize, sizeof(CmosMemory));
474  }
475  DPRINT1("CMOS loading %s (Error: %u)\n", Success ? "succeeded" : "failed", GetLastError());
477  }
478 
479  /* Overwrite some registers with default values */
480  CmosMemory.StatusRegA = CMOS_DEFAULT_STA;
481  CmosMemory.StatusRegB = CMOS_DEFAULT_STB;
482  CmosMemory.StatusRegC = 0x00;
483  CmosMemory.StatusRegD = CMOS_BATTERY_OK; // Our CMOS battery works perfectly forever.
484  CmosMemory.Diagnostics = 0x00; // Diagnostics must not find any errors.
485  CmosMemory.ShutdownStatus = 0x00;
487 
488  // HACK: For the moment, set the boot sequence to: 1-Floppy, 2-Hard Disk .
489  CmosMemory.Regs[CMOS_REG_SYSOP] |= (1 << 5);
490 
491  /* Memory settings */
492 
493  /*
494  * Conventional memory size is 640 kB,
495  * see: http://webpages.charter.net/danrollins/techhelp/0184.HTM
496  * and see Ralf Brown: http://www.ctyme.com/intr/rb-0598.htm
497  * for more information.
498  */
499  CmosMemory.BaseMemoryLow = LOBYTE(0x0280);
500  CmosMemory.BaseMemoryHigh = HIBYTE(0x0280);
501 
503  CmosMemory.ActualExtMemoryLow = LOBYTE((MAX_ADDRESS - 0x100000) / 1024);
505  CmosMemory.ActualExtMemoryHigh = HIBYTE((MAX_ADDRESS - 0x100000) / 1024);
506 
507  /* Register the I/O Ports */
510 
512  HZ_TO_NS(1),
513  RtcTimeUpdate);
515  HZ_TO_NS(1000),
517 }
BYTE Regs[0x40]
Definition: cmos.h:135
BYTE StatusRegD
Definition: cmos.h:116
BYTE Diagnostics
Definition: cmos.h:117
#define CMOS_ADDRESS_PORT
Definition: cmos.h:15
#define LOBYTE(W)
Definition: jmemdos.c:487
static HANDLE hCmosRam
Definition: cmos.c:25
#define HIBYTE(W)
Definition: jmemdos.c:486
static VOID WINAPI CmosWriteData(USHORT Port, BYTE Data)
Definition: cmos.c:264
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define MAX_ADDRESS
VOID RegisterIoPort(USHORT Port, EMULATOR_INB_PROC InHandler, EMULATOR_OUTB_PROC OutHandler)
Definition: io.c:320
BYTE StatusRegC
Definition: cmos.h:115
BYTE ActualExtMemoryLow
Definition: cmos.h:130
static VOID FASTCALL RtcTimeUpdate(ULONGLONG ElapsedTime)
Definition: cmos.c:73
static CMOS_MEMORY CmosMemory
Definition: cmos.c:26
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONGLONG Delay, PHARDWARE_TIMER_PROC Callback)
Definition: clock.c:144
smooth NULL
Definition: ftsmooth.c:416
static PHARDWARE_TIMER PeriodicTimer
Definition: cmos.c:32
#define CMOS_BATTERY_OK
Definition: cmos.h:18
BYTE ExtMemoryHigh
Definition: cmos.h:127
#define CMOS_DEFAULT_STA
Definition: cmos.h:37
#define HARDWARE_TIMER_PRECISE
Definition: clock.h:17
#define CMOS_DATA_PORT
Definition: halp.h:15
#define HARDWARE_TIMER_ENABLED
Definition: clock.h:15
static VOID WINAPI CmosWriteAddress(USHORT Port, BYTE Data)
Definition: cmos.c:107
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define OPEN_ALWAYS
Definition: disk.h:70
BYTE EquipmentList
Definition: cmos.h:123
BYTE BaseMemoryLow
Definition: cmos.h:124
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
BYTE ShutdownStatus
Definition: cmos.h:118
static PHARDWARE_TIMER ClockTimer
Definition: cmos.c:31
#define FILE_BEGIN
Definition: winbase.h:112
#define CMOS_EQUIPMENT_LIST
Definition: cmos.h:41
BYTE ExtMemoryLow
Definition: cmos.h:126
#define CMOS_DEFAULT_STB
Definition: cmos.h:38
#define DPRINT1
Definition: precomp.h:8
#define CreateFileW
Definition: compat.h:400
#define HZ_TO_NS(Freq)
Definition: clock.h:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BYTE BaseMemoryHigh
Definition: cmos.h:125
static VOID FASTCALL RtcPeriodicTick(ULONGLONG ElapsedTime)
Definition: cmos.c:55
BYTE ActualExtMemoryHigh
Definition: cmos.h:131
static BYTE WINAPI CmosReadData(USHORT Port)
Definition: cmos.c:129
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123

Referenced by EmulatorInitialize().

◆ IsNmiEnabled()

BOOLEAN IsNmiEnabled ( VOID  )

Definition at line 436 of file cmos.c.

437 {
438  return NmiEnabled;
439 }
static BOOLEAN NmiEnabled
Definition: cmos.c:28

◆ RtcGetTicksPerSecond()

DWORD RtcGetTicksPerSecond ( VOID  )