ReactOS  0.4.15-dev-1201-gb2cf5a4
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)
 
INIT_FUNCTION 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 26 of file cmos.c.

30 {
31  /* Select the register */
33 
34  /* Query the value */
36 }
#define CMOS_CONTROL_PORT
Definition: halp.h:14
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:21
#define CMOS_DATA_PORT
Definition: halp.h:15
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:20

◆ HalGetEnvironmentVariable()

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

Definition at line 179 of file cmos.c.

183 {
184  UCHAR Val;
185 
186  /* Only variable supported on x86 */
187  if (_stricmp(Name, "LastKnownGood")) return ENOENT;
188 
189  /* Acquire CMOS Lock */
191 
192  /* Query the current value */
193  Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
194 
195  /* Release CMOS lock */
197 
198  /* Check the flag */
199  if (Val)
200  {
201  /* Return false */
202  strncpy(Value, "FALSE", ValueLength);
203  }
204  else
205  {
206  /* Return true */
207  strncpy(Value, "TRUE", ValueLength);
208  }
209 
210  /* Return success */
211  return ESUCCESS;
212 }
Definition: arc.h:32
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define _stricmp
Definition: cat.c:22
IN UCHAR Value
Definition: halp.h:394
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_REGISTER_B
Definition: halp.h:17
unsigned char UCHAR
Definition: xmlstorage.h:181
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
Definition: arc.h:46

◆ HalpGetCmosData()

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

Definition at line 53 of file cmos.c.

58 {
61  ULONG Len = Length;
62 
63  /* Do nothing if we don't have a length */
64  if (!Length) return 0;
65 
66  /* Acquire CMOS Lock */
68 
69  /* Check if this is simple CMOS */
70  if (BusNumber == 0)
71  {
72  /* Loop the buffer up to 0xFF */
73  while ((Len > 0) && (Address < 0x100))
74  {
75  /* Read the data */
77 
78  /* Update position and length */
79  Ptr++;
80  Address++;
81  Len--;
82  }
83  }
84  else if (BusNumber == 1)
85  {
86  /* Loop the buffer up to 0xFFFF */
87  while ((Len > 0) && (Address < 0x10000))
88  {
89  /* Write the data */
91 
92  /* Update position and length */
93  Ptr++;
94  Address++;
95  Len--;
96  }
97  }
98 
99  /* Release CMOS Lock */
101 
102  /* Return length read */
103  return Length - Len;
104 }
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:244
static WCHAR Address[46]
Definition: ping.c:68
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
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:227
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

◆ HalpInitializeCmos()

INIT_FUNCTION VOID NTAPI HalpInitializeCmos ( VOID  )

Definition at line 163 of file cmos.c.

164 {
165  /* Set default century offset byte */
167 
168  /* No support for EISA or MCA */
170 }
ULONG HalpBusType
Definition: bus.c:17
#define MACHINE_TYPE_ISA
Definition: ketypes.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
UCHAR HalpCmosCenturyOffset
Definition: cmos.c:22

Referenced by HalInitSystem().

◆ HalpSetCmosData()

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

Definition at line 108 of file cmos.c.

112 {
113  PUCHAR Ptr = (PUCHAR)Buffer;
115  ULONG Len = Length;
116 
117  /* Do nothing if we don't have a length */
118  if (!Length) return 0;
119 
120  /* Acquire CMOS Lock */
122 
123  /* Check if this is simple CMOS */
124  if (BusNumber == 0)
125  {
126  /* Loop the buffer up to 0xFF */
127  while ((Len > 0) && (Address < 0x100))
128  {
129  /* Write the data */
131 
132  /* Update position and length */
133  Ptr++;
134  Address++;
135  Len--;
136  }
137  }
138  else if (BusNumber == 1)
139  {
140  /* Loop the buffer up to 0xFFFF */
141  while ((Len > 0) && (Address < 0x10000))
142  {
143  /* Write the data */
145 
146  /* Update position and length */
147  Ptr++;
148  Address++;
149  Len--;
150  }
151  }
152 
153  /* Release CMOS Lock */
155 
156  /* Return length read */
157  return Length - Len;
158 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
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:244
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:227
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( OUT PTIME_FIELDS  Time)

Definition at line 263 of file cmos.c.

264 {
265  /* Acquire CMOS Lock */
267 
268  /* Loop while update is in progress */
270 
271  /* Set the time data */
272  Time->Second = BCD_INT(HalpReadCmos(0));
273  Time->Minute = BCD_INT(HalpReadCmos(2));
274  Time->Hour = BCD_INT(HalpReadCmos(4));
275  Time->Weekday = BCD_INT(HalpReadCmos(6));
276  Time->Day = BCD_INT(HalpReadCmos(7));
277  Time->Month = BCD_INT(HalpReadCmos(8));
278  Time->Year = BCD_INT(HalpReadCmos(9));
279  Time->Milliseconds = 0;
280 
281  /* FIXME: Check century byte */
282 
283  /* Compensate for the century field */
284  Time->Year += (Time->Year > 80) ? 1900: 2000;
285 
286  /* Release CMOS lock */
288 
289  /* Always return TRUE */
290  return TRUE;
291 }
#define TRUE
Definition: types.h:120
static UCHAR BCD_INT(_In_ UCHAR Bcd)
Definition: cmos.c:43
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#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 219 of file cmos.c.

221 {
222  UCHAR Val;
223 
224  /* Only variable supported on x86 */
225  if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
226 
227  /* Check if this is true or false */
228  if (!_stricmp(Value, "TRUE"))
229  {
230  /* It's true, acquire CMOS lock */
232 
233  /* Read the current value and add the flag */
234  Val = HalpReadCmos(RTC_REGISTER_B) | 1;
235  }
236  else if (!_stricmp(Value, "FALSE"))
237  {
238  /* It's false, acquire CMOS lock */
240 
241  /* Read the current value and mask out the flag */
242  Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
243  }
244  else
245  {
246  /* Fail */
247  return ENOMEM;
248  }
249 
250  /* Write new value */
252 
253  /* Release the lock and return success */
255  return ESUCCESS;
256 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
Definition: arc.h:32
#define _stricmp
Definition: cat.c:22
Definition: arc.h:48
IN UCHAR Value
Definition: halp.h:394
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_REGISTER_B
Definition: halp.h:17
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( IN PTIME_FIELDS  Time)

Definition at line 298 of file cmos.c.

299 {
300  /* Acquire CMOS Lock */
302 
303  /* Loop while update is in progress */
305 
306  /* Write time fields to CMOS RTC */
307  HalpWriteCmos(0, INT_BCD(Time->Second));
308  HalpWriteCmos(2, INT_BCD(Time->Minute));
309  HalpWriteCmos(4, INT_BCD(Time->Hour));
310  HalpWriteCmos(6, INT_BCD(Time->Weekday));
311  HalpWriteCmos(7, INT_BCD(Time->Day));
312  HalpWriteCmos(8, INT_BCD(Time->Month));
313  HalpWriteCmos(9, INT_BCD(Time->Year % 100));
314 
315  /* FIXME: Set the century byte */
316 
317  /* Release CMOS lock */
319 
320  /* Always return TRUE */
321  return TRUE;
322 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
#define TRUE
Definition: types.h:120
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
#define INT_BCD(int)
Definition: halp.h:31
#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 22 of file cmos.c.

Referenced by HalpInitializeCmos().