ReactOS 0.4.15-dev-8145-ga541a46
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
 
#define NVRAM_START   0x3FE2
 
#define NVRAM_SIZE   0x1C
 
#define NVRAM_UNUSED_REG   0x14
 
#define NVRAM_UNUSED_BIT   0x80
 

Functions

static UCHAR BCD_INT (_In_ UCHAR Bcd)
 
static UCHAR NTAPI HalpReadNvram (_In_ UCHAR Register)
 
 _Requires_lock_held_ (HalpSystemHardwareLock)
 
UCHAR NTAPI HalpReadCmos (_In_ UCHAR Reg)
 
VOID NTAPI HalpWriteCmos (_In_ UCHAR Reg, _In_ UCHAR Value)
 
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

static ULONG_PTR MappedNvram
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmos.c.

◆ NVRAM_SIZE

#define NVRAM_SIZE   0x1C

Definition at line 28 of file cmos.c.

◆ NVRAM_START

#define NVRAM_START   0x3FE2

Definition at line 27 of file cmos.c.

◆ NVRAM_UNUSED_BIT

#define NVRAM_UNUSED_BIT   0x80

Definition at line 30 of file cmos.c.

◆ NVRAM_UNUSED_REG

#define NVRAM_UNUSED_REG   0x14

Definition at line 29 of file cmos.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( HalpSystemHardwareLock  )

Definition at line 53 of file cmos.c.

59{
63}
static ULONG_PTR MappedNvram
Definition: cmos.c:32
PPC_QUAL void __outbyte(unsigned long const Port, const unsigned char Data)
Definition: intrin_ppc.h:605
#define GDC1_IO_o_MODE_FLIPFLOP1
Definition: video.h:238
#define GDC1_NVRAM_PROTECT
Definition: video.h:251
#define GDC1_NVRAM_UNPROTECT
Definition: video.h:252
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)

◆ BCD_INT()

static UCHAR BCD_INT ( _In_ UCHAR  Bcd)
static

Definition at line 39 of file cmos.c.

41{
42 return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
43}

◆ HalGetEnvironmentVariable()

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

Definition at line 183 of file cmos.c.

187{
188 UCHAR Val;
189
190 /* Only variable supported on x86 */
191 if (_stricmp(Name, "LastKnownGood"))
192 return ENOENT;
193
194 if (!MappedNvram)
195 return ENOENT;
196
198
200
202
203 /* Check the flag */
204 if (Val)
205 strncpy(Value, "FALSE", ValueLength);
206 else
207 strncpy(Value, "TRUE", ValueLength);
208
209 return ESUCCESS;
210}
#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
#define NVRAM_UNUSED_REG
Definition: cmos.c:29
#define NVRAM_UNUSED_BIT
Definition: cmos.c:30
static UCHAR NTAPI HalpReadNvram(_In_ UCHAR Register)
Definition: cmos.c:47
@ ESUCCESS
Definition: arc.h:32
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
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 142 of file cmos.c.

147{
148 /* Not supported by hardware */
149 return 0;
150}

◆ HalpInitializeCmos()

VOID NTAPI HalpInitializeCmos ( VOID  )

Definition at line 167 of file cmos.c.

168{
170
171 /* TODO: Detect TVRAM address */
172 if (TRUE)
174 else
177}
#define TRUE
Definition: types.h:120
#define ULONG_PTR
Definition: config.h:101
PVOID NTAPI HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress, IN PFN_COUNT PageCount)
Definition: memory.c:140
#define NVRAM_START
Definition: cmos.c:27
#define NVRAM_SIZE
Definition: cmos.c:28
#define VRAM_NORMAL_TEXT
Definition: video.h:17
#define VRAM_HI_RESO_TEXT
Definition: video.h:32
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
#define BYTES_TO_PAGES(Size)

◆ HalpReadCmos()

◆ HalpReadNvram()

static UCHAR NTAPI HalpReadNvram ( _In_ UCHAR  Register)
static

Definition at line 47 of file cmos.c.

49{
51}
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)

Referenced by HalGetEnvironmentVariable(), and HalSetEnvironmentVariable().

◆ HalpSetCmosData()

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

Definition at line 154 of file cmos.c.

159{
160 /* Not supported by hardware */
161 return 0;
162}

◆ HalpWriteCmos()

VOID NTAPI HalpWriteCmos ( _In_ UCHAR  Reg,
_In_ UCHAR  Value 
)

Definition at line 132 of file cmos.c.

135{
136 /* Not supported by hardware */
137 NOTHING;
138}
#define NOTHING
Definition: input_list.c:10

Referenced by HalpInitializeClock(), HalpInitializeTsc(), HalpSetCmosData(), HalSetEnvironmentVariable(), HalSetRealTimeClock(), HalStartProfileInterrupt(), HalStopProfileInterrupt(), and RtcSetClockRate().

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( _Out_ PTIME_FIELDS  Time)

Definition at line 255 of file cmos.c.

257{
258 UCHAR Temp;
259
261
262 HalpRtcWriteCommand(RTC_CMD_TIME_READ);
263 HalpRtcWriteCommand(RTC_CMD_REGISTER_SHIFT);
265
266 /* Set the time data */
267 Time->Second = BCD_INT(HalpRtcReadByte());
268 Time->Minute = BCD_INT(HalpRtcReadByte());
269 Time->Hour = BCD_INT(HalpRtcReadByte());
270 Time->Day = BCD_INT(HalpRtcReadByte());
271 Temp = HalpRtcReadByte();
272 Time->Weekday = Temp & 0x0F;
273 Time->Month = Temp >> 4;
274 Time->Year = BCD_INT(HalpRtcReadByte());
275 Time->Milliseconds = 0;
276
277 Time->Year += (Time->Year >= 80) ? 1900 : 2000;
278
279 HalpRtcWriteCommand(RTC_CMD_REGISTER_HOLD);
280
282
283 return TRUE;
284}
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
static PLARGE_INTEGER Time
Definition: time.c:105
#define BCD_INT(bcd)
Definition: hwinfo.c:13
#define RTC_CMD_TIME_READ
Definition: rtc.h:19
#define RTC_CMD_REGISTER_HOLD
Definition: rtc.h:16
#define RTC_CMD_REGISTER_SHIFT
Definition: rtc.h:17

◆ HalSetEnvironmentVariable()

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

Definition at line 214 of file cmos.c.

217{
218 UCHAR Val;
219
220 /* Only variable supported on x86 */
221 if (_stricmp(Name, "LastKnownGood"))
222 return ENOMEM;
223
224 if (!MappedNvram)
225 return ENOMEM;
226
227 /* Check if this is true or false */
228 if (!_stricmp(Value, "TRUE"))
229 {
231
233 }
234 else if (!_stricmp(Value, "FALSE"))
235 {
237
238 Val = HalpReadNvram(NVRAM_UNUSED_REG) & ~NVRAM_UNUSED_BIT;
239 }
240 else
241 {
242 /* Fail */
243 return ENOMEM;
244 }
245
246 HalpWriteNvram(NVRAM_UNUSED_REG, Val);
247
249
250 return ESUCCESS;
251}
#define ENOMEM
Definition: acclib.h:84

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( _In_ PTIME_FIELDS  Time)

Definition at line 288 of file cmos.c.

290{
291 UCHAR i, j;
292 UCHAR SysTime[6];
293
295
296 HalpRtcWriteCommand(RTC_CMD_REGISTER_SHIFT);
297
298 SysTime[0] = INT_BCD(Time->Second);
299 SysTime[1] = INT_BCD(Time->Minute);
300 SysTime[2] = INT_BCD(Time->Hour);
301 SysTime[3] = INT_BCD(Time->Day);
302 SysTime[4] = (Time->Month << 4) | (Time->Weekday & 0x0F);
303 SysTime[5] = INT_BCD(Time->Year % 100);
304
305 /* Write time fields to RTC */
306 for (i = 0; i < 6; i++)
307 {
308 for (j = 0; j < 8; j++)
309 HalpRtcWriteBit(SysTime[i] >> j);
310 }
311
312 HalpRtcWriteCommand(RTC_CMD_TIME_SET_COUNTER_HOLD);
313 HalpRtcWriteCommand(RTC_CMD_REGISTER_HOLD);
314
316
317 return TRUE;
318}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define INT_BCD(int)
Definition: halp.h:73
#define RTC_CMD_TIME_SET_COUNTER_HOLD
Definition: rtc.h:18

Variable Documentation

◆ MappedNvram