ReactOS 0.4.15-dev-8116-gf69e256
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_reads_bytes_(Length) 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 CMOS_CONTROL_PORT
Definition: halhw.h:11
#define CMOS_DATA_PORT
Definition: halhw.h:12
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

◆ HalGetEnvironmentVariable()

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

Definition at line 176 of file cmos.c.

180{
181 UCHAR Val;
182
183 /* Only variable supported on x86 */
184 if (_stricmp(Name, "LastKnownGood")) return ENOENT;
185
186 /* Acquire CMOS Lock */
188
189 /* Query the current value */
190 Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
191
192 /* Release CMOS lock */
194
195 /* Check the flag */
196 if (Val)
197 {
198 /* Return false */
199 strncpy(Value, "FALSE", ValueLength);
200 }
201 else
202 {
203 /* Return true */
204 strncpy(Value, "TRUE", ValueLength);
205 }
206
207 /* Return success */
208 return ESUCCESS;
209}
#define ENOENT
Definition: acclib.h:79
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:243
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:226
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
#define RTC_REGISTER_B
Definition: halhw.h:15
@ ESUCCESS
Definition: arc.h:32
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ 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{
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}
Definition: bufpool.h:45
#define Len
Definition: deflate.h:82
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
static WCHAR Address[46]
Definition: ping.c:68
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160

Referenced by HalGetBusDataByOffset(), and HalpcGetCmosData().

◆ HalpInitializeCmos()

VOID NTAPI HalpInitializeCmos ( VOID  )

Definition at line 160 of file cmos.c.

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

Referenced by HalInitSystem().

◆ HalpSetCmosData()

ULONG NTAPI HalpSetCmosData ( _In_ ULONG  BusNumber,
_In_ ULONG  SlotNumber,
_In_reads_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length 
)

Definition at line 104 of file cmos.c.

109{
112 ULONG Len = Length;
113
114 /* Do nothing if we don't have a length */
115 if (!Length) return 0;
116
117 /* Acquire CMOS Lock */
119
120 /* Check if this is simple CMOS */
121 if (BusNumber == 0)
122 {
123 /* Loop the buffer up to 0xFF */
124 while ((Len > 0) && (Address < 0x100))
125 {
126 /* Write the data */
128
129 /* Update position and length */
130 Ptr++;
131 Address++;
132 Len--;
133 }
134 }
135 else if (BusNumber == 1)
136 {
137 /* Loop the buffer up to 0xFFFF */
138 while ((Len > 0) && (Address < 0x10000))
139 {
140 /* Write the data */
142
143 /* Update position and length */
144 Ptr++;
145 Address++;
146 Len--;
147 }
148 }
149
150 /* Release CMOS Lock */
152
153 /* Return length read */
154 return Length - Len;
155}
VOID NTAPI HalpWriteCmos(_In_ UCHAR Reg, _In_ UCHAR Value)
Definition: cmos.c:132

Referenced by HalpcSetCmosData(), and HalSetBusDataByOffset().

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( OUT PTIME_FIELDS  Time)

Definition at line 260 of file cmos.c.

261{
262 /* Acquire CMOS Lock */
264
265 /* Loop while update is in progress */
267
268 /* Set the time data */
269 Time->Second = BCD_INT(HalpReadCmos(0));
270 Time->Minute = BCD_INT(HalpReadCmos(2));
271 Time->Hour = BCD_INT(HalpReadCmos(4));
272 Time->Weekday = BCD_INT(HalpReadCmos(6));
273 Time->Day = BCD_INT(HalpReadCmos(7));
274 Time->Month = BCD_INT(HalpReadCmos(8));
275 Time->Year = BCD_INT(HalpReadCmos(9));
276 Time->Milliseconds = 0;
277
278 /* FIXME: Check century byte */
279
280 /* Compensate for the century field */
281 Time->Year += (Time->Year > 80) ? 1900: 2000;
282
283 /* Release CMOS lock */
285
286 /* Always return TRUE */
287 return TRUE;
288}
#define TRUE
Definition: types.h:120
static PLARGE_INTEGER Time
Definition: time.c:105
#define BCD_INT(bcd)
Definition: hwinfo.c:13
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
#define RTC_REGISTER_A
Definition: xboxrtc.c:21

◆ HalSetEnvironmentVariable()

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

Definition at line 216 of file cmos.c.

218{
219 UCHAR Val;
220
221 /* Only variable supported on x86 */
222 if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
223
224 /* Check if this is true or false */
225 if (!_stricmp(Value, "TRUE"))
226 {
227 /* It's true, acquire CMOS lock */
229
230 /* Read the current value and add the flag */
231 Val = HalpReadCmos(RTC_REGISTER_B) | 1;
232 }
233 else if (!_stricmp(Value, "FALSE"))
234 {
235 /* It's false, acquire CMOS lock */
237
238 /* Read the current value and mask out the flag */
239 Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
240 }
241 else
242 {
243 /* Fail */
244 return ENOMEM;
245 }
246
247 /* Write new value */
249
250 /* Release the lock and return success */
252 return ESUCCESS;
253}
#define ENOMEM
Definition: acclib.h:84

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( IN PTIME_FIELDS  Time)

Definition at line 295 of file cmos.c.

296{
297 /* Acquire CMOS Lock */
299
300 /* Loop while update is in progress */
302
303 /* Write time fields to CMOS RTC */
304 HalpWriteCmos(0, INT_BCD(Time->Second));
305 HalpWriteCmos(2, INT_BCD(Time->Minute));
306 HalpWriteCmos(4, INT_BCD(Time->Hour));
307 HalpWriteCmos(6, INT_BCD(Time->Weekday));
308 HalpWriteCmos(7, INT_BCD(Time->Day));
309 HalpWriteCmos(8, INT_BCD(Time->Month));
310 HalpWriteCmos(9, INT_BCD(Time->Year % 100));
311
312 /* FIXME: Set the century byte */
313
314 /* Release CMOS lock */
316
317 /* Always return TRUE */
318 return TRUE;
319}
#define INT_BCD(int)
Definition: halp.h:73

Variable Documentation

◆ HalpCmosCenturyOffset

UCHAR HalpCmosCenturyOffset

Definition at line 18 of file cmos.c.

Referenced by HalpInitializeCmos().