ReactOS 0.4.16-dev-297-gc569aee
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
@ CMOS_REG_DAY
Definition: cmos.h:59
@ CMOS_REG_STATUS_A
Definition: cmos.h:62
@ CMOS_REG_EXT_MEMORY_HIGH
Definition: cmos.h:72
@ CMOS_REG_ALARM_HRS
Definition: cmos.h:57
@ CMOS_REG_ACTUAL_EXT_MEMORY_LOW
Definition: cmos.h:74
@ CMOS_REG_SHUTDOWN_STATUS
Definition: cmos.h:67
@ CMOS_REG_STATUS_B
Definition: cmos.h:63
@ CMOS_REG_MAX
Definition: cmos.h:77
@ CMOS_REG_MONTH
Definition: cmos.h:60
@ CMOS_REG_BASE_MEMORY_HIGH
Definition: cmos.h:70
@ CMOS_REG_MINUTES
Definition: cmos.h:54
@ CMOS_REG_DAY_OF_WEEK
Definition: cmos.h:58
@ CMOS_REG_EXT_MEMORY_LOW
Definition: cmos.h:71
@ CMOS_REG_ALARM_MIN
Definition: cmos.h:55
@ CMOS_REG_STATUS_C
Definition: cmos.h:64
@ CMOS_REG_BASE_MEMORY_LOW
Definition: cmos.h:69
@ CMOS_REG_YEAR
Definition: cmos.h:61
@ CMOS_REG_SECONDS
Definition: cmos.h:52
@ CMOS_REG_HOURS
Definition: cmos.h:56
@ CMOS_REG_DIAGNOSTICS
Definition: cmos.h:66
@ CMOS_REG_ALARM_SEC
Definition: cmos.h:53
@ CMOS_REG_ACTUAL_EXT_MEMORY_HIGH
Definition: cmos.h:75
@ CMOS_REG_CENTURY
Definition: cmos.h:76
@ CMOS_REG_EQUIPMENT_LIST
Definition: cmos.h:68
@ CMOS_REG_STATUS_D
Definition: cmos.h:65
@ CMOS_REG_SYSOP
Definition: cmos.h:73

Function Documentation

◆ C_ASSERT()

C_ASSERT ( sizeof(CMOS_MEMORY = =0x40)

◆ CmosCleanup()

VOID CmosCleanup ( VOID  )

Definition at line 568 of file cmos.c.

569{
572
574 {
575 /* Flush the CMOS memory back to the RAM file and close it */
577 DWORD CmosSize = sizeof(CmosMemory);
578
579 Success = CmosWriteFile(hCmosRam, &CmosMemory, CmosSize, &CmosSize);
580 if (!Success || (CmosSize != sizeof(CmosMemory)))
581 {
582 DPRINT1("CMOS saving failed (Error: %u), written %u bytes, expected %u bytes\n",
583 GetLastError(), CmosSize, sizeof(CmosMemory));
584 }
585
588 }
589}
#define DPRINT1
Definition: precomp.h:8
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID DestroyHardwareTimer(PHARDWARE_TIMER Timer)
Definition: clock.c:210
static CMOS_MEMORY CmosMemory
Definition: cmos.c:28
static BOOL CmosWriteFile(_In_ HANDLE FileHandle, _In_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG BytesWritten)
Definition: cmos.c:444
static HANDLE hCmosRam
Definition: cmos.c:27
static PHARDWARE_TIMER ClockTimer
Definition: cmos.c:33
static PHARDWARE_TIMER PeriodicTimer
Definition: cmos.c:34
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by EmulatorCleanup().

◆ CmosInitialize()

VOID CmosInitialize ( VOID  )

Definition at line 460 of file cmos.c.

461{
463 WCHAR CmosPath[_countof(NtVdmPath) + _countof("\\" CMOS_RAM_FILE)];
464
465 /* CMOS file must not be opened before */
467
468 /* Always open (and if needed, create) a RAM file with shared access */
470 sizeof(CmosPath),
471 L"%s\\" L(CMOS_RAM_FILE),
472 NtVdmPath));
473 if (!Success)
474 DPRINT1("Could not create CMOS file path!\n");
475
476 if (Success)
477 {
479 hCmosRam = CreateFileW(CmosPath,
482 NULL,
485 NULL);
487 if (!Success)
488 DPRINT1("CMOS opening failed (Error: %u)\n", GetLastError());
489 }
490
491 /* Clear the CMOS memory */
493
494 /* Load the file only if it already existed and was opened, not newly created */
495 if (Success)
496 {
497 if ((GetLastError() == ERROR_ALREADY_EXISTS) /* || (GetLastError() == ERROR_FILE_EXISTS) */)
498 {
499 /* Attempt to load the CMOS memory from the RAM file */
500 DWORD CmosSize = sizeof(CmosMemory);
501 Success = ReadFile(hCmosRam, &CmosMemory, CmosSize, &CmosSize, NULL);
502 if (!Success)
503 {
504 DPRINT1("CMOS loading failed (Error: %u)\n", GetLastError());
505 }
506 else if (CmosSize != sizeof(CmosMemory))
507 {
508 /* Invalid CMOS RAM file; reinitialize the CMOS memory */
509 DPRINT1("Invalid CMOS file, read %u bytes, expected %u bytes\n",
510 CmosSize, sizeof(CmosMemory));
511 Success = FALSE;
512 }
513 if (!Success)
514 {
515 /* Reset the CMOS memory and its RAM file */
518 }
519 }
520 else
521 {
522 /* Reset the CMOS RAM file */
524 }
526 }
527
528 /* Overwrite some registers with default values */
529 CmosMemory.StatusRegA = CMOS_DEFAULT_STA;
530 CmosMemory.StatusRegB = CMOS_DEFAULT_STB;
531 CmosMemory.StatusRegC = 0x00;
532 CmosMemory.StatusRegD = CMOS_BATTERY_OK; // Our CMOS battery works perfectly forever.
533 CmosMemory.Diagnostics = 0x00; // Diagnostics must not find any errors.
536
537 // HACK: For the moment, set the boot sequence to: 1-Floppy, 2-Hard Disk .
538 CmosMemory.Regs[CMOS_REG_SYSOP] |= (1 << 5);
539
540 /* Memory settings */
541
542 /*
543 * Conventional memory size is 640 kB,
544 * see: http://webpages.charter.net/danrollins/techhelp/0184.HTM
545 * and see Ralf Brown: http://www.ctyme.com/intr/rb-0598.htm
546 * for more information.
547 */
550
552 CmosMemory.ActualExtMemoryLow = LOBYTE((MAX_ADDRESS - 0x100000) / 1024);
554 CmosMemory.ActualExtMemoryHigh = HIBYTE((MAX_ADDRESS - 0x100000) / 1024);
555
556 /* Register the I/O Ports */
559
561 HZ_TO_NS(1),
564 HZ_TO_NS(1000),
566}
#define MAX_ADDRESS
#define HARDWARE_TIMER_ENABLED
Definition: clock.h:15
#define HARDWARE_TIMER_PRECISE
Definition: clock.h:17
#define HZ_TO_NS(Freq)
Definition: clock.h:20
#define CMOS_BATTERY_OK
Definition: cmos.h:18
#define CMOS_EQUIPMENT_LIST
Definition: cmos.h:41
#define CMOS_ADDRESS_PORT
Definition: cmos.h:15
#define CMOS_DEFAULT_STB
Definition: cmos.h:38
#define CMOS_DEFAULT_STA
Definition: cmos.h:37
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define FILE_BEGIN
Definition: compat.h:761
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define SetLastError(x)
Definition: compat.h:752
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define CMOS_DATA_PORT
Definition: halhw.h:12
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define ASSERT(a)
Definition: mode.c:44
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
WCHAR NtVdmPath[MAX_PATH]
Definition: ntvdm.c:35
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
BYTE StatusRegD
Definition: cmos.h:116
BYTE ActualExtMemoryHigh
Definition: cmos.h:131
BYTE ExtMemoryHigh
Definition: cmos.h:127
BYTE ShutdownStatus
Definition: cmos.h:118
BYTE EquipmentList
Definition: cmos.h:123
BYTE ExtMemoryLow
Definition: cmos.h:126
BYTE BaseMemoryHigh
Definition: cmos.h:125
BYTE Diagnostics
Definition: cmos.h:117
BYTE StatusRegC
Definition: cmos.h:115
BYTE Regs[0x40]
Definition: cmos.h:135
BYTE ActualExtMemoryLow
Definition: cmos.h:130
BYTE BaseMemoryLow
Definition: cmos.h:124
PHARDWARE_TIMER CreateHardwareTimer(ULONG Flags, ULONGLONG Delay, PHARDWARE_TIMER_PROC Callback)
Definition: clock.c:144
static VOID FASTCALL RtcTimeUpdate(ULONGLONG ElapsedTime)
Definition: cmos.c:75
static VOID WINAPI CmosWriteAddress(USHORT Port, BYTE Data)
Definition: cmos.c:109
static BYTE WINAPI CmosReadData(USHORT Port)
Definition: cmos.c:131
static VOID FASTCALL RtcPeriodicTick(ULONGLONG ElapsedTime)
Definition: cmos.c:57
#define CMOS_RAM_FILE
Definition: cmos.c:25
static VOID WINAPI CmosWriteData(USHORT Port, BYTE Data)
Definition: cmos.c:266
VOID RegisterIoPort(USHORT Port, EMULATOR_INB_PROC InHandler, EMULATOR_OUTB_PROC OutHandler)
Definition: io.c:320
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by EmulatorInitialize().

◆ IsNmiEnabled()

BOOLEAN IsNmiEnabled ( VOID  )

Definition at line 438 of file cmos.c.

439{
440 return NmiEnabled;
441}
static BOOLEAN NmiEnabled
Definition: cmos.c:30

◆ RtcGetTicksPerSecond()

DWORD RtcGetTicksPerSecond ( VOID  )