ReactOS  0.4.15-dev-3302-ga37d9a4
cmos.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for cmos.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 _Requires_lock_held_ (HalpSystemHardwareLock)
 
ULONG NTAPI HalpGetCmosData (_In_ ULONG BusNumber, _In_ ULONG SlotNumber, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length)
 
ULONG NTAPI HalpSetCmosData (IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
 
VOID NTAPI HalpInitializeCmos (VOID)
 
ARC_STATUS NTAPI HalGetEnvironmentVariable (_In_ PCH Name, _In_ USHORT ValueLength, _Out_writes_z_(ValueLength) PCH Value)
 
ARC_STATUS NTAPI HalSetEnvironmentVariable (IN PCH Name, IN PCH Value)
 
BOOLEAN NTAPI HalQueryRealTimeClock (OUT PTIME_FIELDS Time)
 
BOOLEAN NTAPI HalSetRealTimeClock (IN PTIME_FIELDS Time)
 

Variables

UCHAR HalpCmosCenturyOffset
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file cmos.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( HalpSystemHardwareLock  )

Definition at line 22 of file cmos.c.

26 {
27  /* Select the register */
29 
30  /* Query the value */
32 }
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define CMOS_CONTROL_PORT
Definition: halhw.h:11
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
#define CMOS_DATA_PORT
Definition: halhw.h:12

◆ HalGetEnvironmentVariable()

ARC_STATUS NTAPI HalGetEnvironmentVariable ( _In_ PCH  Name,
_In_ USHORT  ValueLength,
_Out_writes_z_(ValueLength) PCH  Value 
)

Definition at line 175 of file cmos.c.

179 {
180  UCHAR Val;
181 
182  /* Only variable supported on x86 */
183  if (_stricmp(Name, "LastKnownGood")) return ENOENT;
184 
185  /* Acquire CMOS Lock */
187 
188  /* Query the current value */
189  Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
190 
191  /* Release CMOS lock */
193 
194  /* Check the flag */
195  if (Val)
196  {
197  /* Return false */
198  strncpy(Value, "FALSE", ValueLength);
199  }
200  else
201  {
202  /* Return true */
203  strncpy(Value, "TRUE", ValueLength);
204  }
205 
206  /* Return success */
207  return ESUCCESS;
208 }
Definition: arc.h:32
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define _stricmp
Definition: cat.c:22
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
unsigned char UCHAR
Definition: xmlstorage.h:181
#define RTC_REGISTER_B
Definition: halhw.h:15
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
Definition: arc.h:46
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271

◆ HalpGetCmosData()

ULONG NTAPI HalpGetCmosData ( _In_ ULONG  BusNumber,
_In_ ULONG  SlotNumber,
_Out_writes_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length 
)

Definition at line 49 of file cmos.c.

54 {
57  ULONG Len = Length;
58 
59  /* Do nothing if we don't have a length */
60  if (!Length) return 0;
61 
62  /* Acquire CMOS Lock */
64 
65  /* Check if this is simple CMOS */
66  if (BusNumber == 0)
67  {
68  /* Loop the buffer up to 0xFF */
69  while ((Len > 0) && (Address < 0x100))
70  {
71  /* Read the data */
73 
74  /* Update position and length */
75  Ptr++;
76  Address++;
77  Len--;
78  }
79  }
80  else if (BusNumber == 1)
81  {
82  /* Loop the buffer up to 0xFFFF */
83  while ((Len > 0) && (Address < 0x10000))
84  {
85  /* Write the data */
87 
88  /* Update position and length */
89  Ptr++;
90  Address++;
91  Len--;
92  }
93  }
94 
95  /* Release CMOS Lock */
97 
98  /* Return length read */
99  return Length - Len;
100 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define Len
Definition: deflate.h:82
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
unsigned char UCHAR
Definition: xmlstorage.h:181
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
unsigned int ULONG
Definition: retypes.h:1

Referenced by HalGetBusDataByOffset().

◆ HalpInitializeCmos()

VOID NTAPI HalpInitializeCmos ( VOID  )

Definition at line 159 of file cmos.c.

160 {
161  /* Set default century offset byte */
163 
164  /* No support for EISA or MCA */
166 }
ULONG HalpBusType
Definition: pcibus.c:18
#define ASSERT(a)
Definition: mode.c:44
#define MACHINE_TYPE_ISA
Definition: ketypes.h:52
UCHAR HalpCmosCenturyOffset
Definition: cmos.c:18

Referenced by HalInitSystem().

◆ HalpSetCmosData()

ULONG NTAPI HalpSetCmosData ( IN ULONG  BusNumber,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 104 of file cmos.c.

108 {
109  PUCHAR Ptr = (PUCHAR)Buffer;
111  ULONG Len = Length;
112 
113  /* Do nothing if we don't have a length */
114  if (!Length) return 0;
115 
116  /* Acquire CMOS Lock */
118 
119  /* Check if this is simple CMOS */
120  if (BusNumber == 0)
121  {
122  /* Loop the buffer up to 0xFF */
123  while ((Len > 0) && (Address < 0x100))
124  {
125  /* Write the data */
127 
128  /* Update position and length */
129  Ptr++;
130  Address++;
131  Len--;
132  }
133  }
134  else if (BusNumber == 1)
135  {
136  /* Loop the buffer up to 0xFFFF */
137  while ((Len > 0) && (Address < 0x10000))
138  {
139  /* Write the data */
141 
142  /* Update position and length */
143  Ptr++;
144  Address++;
145  Len--;
146  }
147  }
148 
149  /* Release CMOS Lock */
151 
152  /* Return length read */
153  return Length - Len;
154 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
VOID NTAPI HalpWriteCmos(_In_ UCHAR Reg, _In_ UCHAR Value)
Definition: cmos.c:132
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define Len
Definition: deflate.h:82
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

Referenced by HalSetBusDataByOffset().

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( OUT PTIME_FIELDS  Time)

Definition at line 259 of file cmos.c.

260 {
261  /* Acquire CMOS Lock */
263 
264  /* Loop while update is in progress */
266 
267  /* Set the time data */
268  Time->Second = BCD_INT(HalpReadCmos(0));
269  Time->Minute = BCD_INT(HalpReadCmos(2));
270  Time->Hour = BCD_INT(HalpReadCmos(4));
271  Time->Weekday = BCD_INT(HalpReadCmos(6));
272  Time->Day = BCD_INT(HalpReadCmos(7));
273  Time->Month = BCD_INT(HalpReadCmos(8));
274  Time->Year = BCD_INT(HalpReadCmos(9));
275  Time->Milliseconds = 0;
276 
277  /* FIXME: Check century byte */
278 
279  /* Compensate for the century field */
280  Time->Year += (Time->Year > 80) ? 1900: 2000;
281 
282  /* Release CMOS lock */
284 
285  /* Always return TRUE */
286  return TRUE;
287 }
#define TRUE
Definition: types.h:120
static UCHAR BCD_INT(_In_ UCHAR Bcd)
Definition: cmos.c:39
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
static PLARGE_INTEGER Time
Definition: time.c:105

◆ HalSetEnvironmentVariable()

ARC_STATUS NTAPI HalSetEnvironmentVariable ( IN PCH  Name,
IN PCH  Value 
)

Definition at line 215 of file cmos.c.

217 {
218  UCHAR Val;
219 
220  /* Only variable supported on x86 */
221  if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
222 
223  /* Check if this is true or false */
224  if (!_stricmp(Value, "TRUE"))
225  {
226  /* It's true, acquire CMOS lock */
228 
229  /* Read the current value and add the flag */
230  Val = HalpReadCmos(RTC_REGISTER_B) | 1;
231  }
232  else if (!_stricmp(Value, "FALSE"))
233  {
234  /* It's false, acquire CMOS lock */
236 
237  /* Read the current value and mask out the flag */
238  Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
239  }
240  else
241  {
242  /* Fail */
243  return ENOMEM;
244  }
245 
246  /* Write new value */
248 
249  /* Release the lock and return success */
251  return ESUCCESS;
252 }
VOID NTAPI HalpWriteCmos(_In_ UCHAR Reg, _In_ UCHAR Value)
Definition: cmos.c:132
Definition: arc.h:32
#define _stricmp
Definition: cat.c:22
Definition: arc.h:48
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
unsigned char UCHAR
Definition: xmlstorage.h:181
#define RTC_REGISTER_B
Definition: halhw.h:15
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( IN PTIME_FIELDS  Time)

Definition at line 294 of file cmos.c.

295 {
296  /* Acquire CMOS Lock */
298 
299  /* Loop while update is in progress */
301 
302  /* Write time fields to CMOS RTC */
303  HalpWriteCmos(0, INT_BCD(Time->Second));
304  HalpWriteCmos(2, INT_BCD(Time->Minute));
305  HalpWriteCmos(4, INT_BCD(Time->Hour));
306  HalpWriteCmos(6, INT_BCD(Time->Weekday));
307  HalpWriteCmos(7, INT_BCD(Time->Day));
308  HalpWriteCmos(8, INT_BCD(Time->Month));
309  HalpWriteCmos(9, INT_BCD(Time->Year % 100));
310 
311  /* FIXME: Set the century byte */
312 
313  /* Release CMOS lock */
315 
316  /* Always return TRUE */
317  return TRUE;
318 }
VOID NTAPI HalpWriteCmos(_In_ UCHAR Reg, _In_ UCHAR Value)
Definition: cmos.c:132
#define TRUE
Definition: types.h:120
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
#define INT_BCD(int)
Definition: halp.h:59
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
static PLARGE_INTEGER Time
Definition: time.c:105

Variable Documentation

◆ HalpCmosCenturyOffset

UCHAR HalpCmosCenturyOffset

Definition at line 18 of file cmos.c.

Referenced by HalpInitializeCmos().