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
 
#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)
 
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

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 32 of file cmos.c.

◆ NVRAM_START

#define NVRAM_START   0x3FE2

Definition at line 31 of file cmos.c.

◆ NVRAM_UNUSED_BIT

#define NVRAM_UNUSED_BIT   0x80

Definition at line 34 of file cmos.c.

◆ NVRAM_UNUSED_REG

#define NVRAM_UNUSED_REG   0x14

Definition at line 33 of file cmos.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( HalpSystemHardwareLock  )

Definition at line 57 of file cmos.c.

63 {
67 }
#define GDC1_IO_o_MODE_FLIPFLOP1
Definition: video.h:238
unsigned char * PUCHAR
Definition: retypes.h:3
PPC_QUAL void __outbyte(unsigned long const Port, const unsigned char Data)
Definition: intrin_ppc.h:605
IN UCHAR Value
Definition: halp.h:394
#define GDC1_NVRAM_PROTECT
Definition: video.h:251
#define GDC1_NVRAM_UNPROTECT
Definition: video.h:252
static ULONG_PTR MappedNvram
Definition: cmos.c:36
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 43 of file cmos.c.

45 {
46  return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
47 }

Referenced by HalQueryRealTimeClock().

◆ HalGetEnvironmentVariable()

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

Definition at line 187 of file cmos.c.

191 {
192  UCHAR Val;
193 
194  /* Only variable supported on x86 */
195  if (_stricmp(Name, "LastKnownGood"))
196  return ENOENT;
197 
198  if (!MappedNvram)
199  return ENOENT;
200 
202 
204 
206 
207  /* Check the flag */
208  if (Val)
209  strncpy(Value, "FALSE", ValueLength);
210  else
211  strncpy(Value, "TRUE", ValueLength);
212 
213  return ESUCCESS;
214 }
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
static UCHAR NTAPI HalpReadNvram(_In_ UCHAR Register)
Definition: cmos.c:51
static ULONG_PTR MappedNvram
Definition: cmos.c:36
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define NVRAM_UNUSED_REG
Definition: cmos.c:33
unsigned char UCHAR
Definition: xmlstorage.h:181
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
Definition: arc.h:46
#define NVRAM_UNUSED_BIT
Definition: cmos.c:34

◆ HalpGetCmosData()

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

Definition at line 146 of file cmos.c.

151 {
152  /* Not supported by hardware */
153  return 0;
154 }

◆ HalpInitializeCmos()

INIT_FUNCTION VOID NTAPI HalpInitializeCmos ( VOID  )

Definition at line 171 of file cmos.c.

172 {
174 
175  /* TODO: Detect TVRAM address */
176  if (TRUE)
178  else
181 }
#define TRUE
Definition: types.h:120
#define VRAM_HI_RESO_TEXT
Definition: video.h:32
PVOID NTAPI HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG NumberPage)
Definition: misc.c:28
#define NVRAM_START
Definition: cmos.c:31
static ULONG_PTR MappedNvram
Definition: cmos.c:36
#define BYTES_TO_PAGES(Size)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1081
#define VRAM_NORMAL_TEXT
Definition: video.h:17
#define ULONG_PTR
Definition: config.h:101
#define NVRAM_SIZE
Definition: cmos.c:32
LONGLONG QuadPart
Definition: typedefs.h:114

◆ HalpReadCmos()

UCHAR NTAPI HalpReadCmos ( _In_ UCHAR  Reg)

Definition at line 127 of file cmos.c.

129 {
130  /* Not supported by hardware */
131  return 0;
132 }

◆ HalpReadNvram()

static UCHAR NTAPI HalpReadNvram ( _In_ UCHAR  Register)
static

Definition at line 51 of file cmos.c.

53 {
54  return READ_REGISTER_UCHAR((PUCHAR)(MappedNvram + Register));
55 }
unsigned char * PUCHAR
Definition: retypes.h:3
static ULONG_PTR MappedNvram
Definition: cmos.c:36
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 158 of file cmos.c.

163 {
164  /* Not supported by hardware */
165  return 0;
166 }

◆ HalpWriteCmos()

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

Definition at line 136 of file cmos.c.

139 {
140  /* Not supported by hardware */
141  NOTHING;
142 }
#define NOTHING
Definition: env_spec_w32.h:461

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( _Out_ PTIME_FIELDS  Time)

Definition at line 259 of file cmos.c.

261 {
262  UCHAR Temp;
263 
265 
266  HalpRtcWriteCommand(RTC_CMD_TIME_READ);
267  HalpRtcWriteCommand(RTC_CMD_REGISTER_SHIFT);
269 
270  /* Set the time data */
271  Time->Second = BCD_INT(HalpRtcReadByte());
272  Time->Minute = BCD_INT(HalpRtcReadByte());
273  Time->Hour = BCD_INT(HalpRtcReadByte());
274  Time->Day = BCD_INT(HalpRtcReadByte());
275  Temp = HalpRtcReadByte();
276  Time->Weekday = Temp & 0x0F;
277  Time->Month = Temp >> 4;
278  Time->Year = BCD_INT(HalpRtcReadByte());
279  Time->Milliseconds = 0;
280 
281  Time->Year += (Time->Year >= 80) ? 1900 : 2000;
282 
283  HalpRtcWriteCommand(RTC_CMD_REGISTER_HOLD);
284 
286 
287  return TRUE;
288 }
#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
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_CMD_REGISTER_HOLD
Definition: rtc.h:16
unsigned char UCHAR
Definition: xmlstorage.h:181
#define RTC_CMD_TIME_READ
Definition: rtc.h:19
#define RTC_CMD_REGISTER_SHIFT
Definition: rtc.h:17
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:95
static PLARGE_INTEGER Time
Definition: time.c:105

◆ HalSetEnvironmentVariable()

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

Definition at line 218 of file cmos.c.

221 {
222  UCHAR Val;
223 
224  /* Only variable supported on x86 */
225  if (_stricmp(Name, "LastKnownGood"))
226  return ENOMEM;
227 
228  if (!MappedNvram)
229  return ENOMEM;
230 
231  /* Check if this is true or false */
232  if (!_stricmp(Value, "TRUE"))
233  {
235 
237  }
238  else if (!_stricmp(Value, "FALSE"))
239  {
241 
243  }
244  else
245  {
246  /* Fail */
247  return ENOMEM;
248  }
249 
250  HalpWriteNvram(NVRAM_UNUSED_REG, Val);
251 
253 
254  return ESUCCESS;
255 }
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
static UCHAR NTAPI HalpReadNvram(_In_ UCHAR Register)
Definition: cmos.c:51
static ULONG_PTR MappedNvram
Definition: cmos.c:36
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define NVRAM_UNUSED_REG
Definition: cmos.c:33
unsigned char UCHAR
Definition: xmlstorage.h:181
#define NVRAM_UNUSED_BIT
Definition: cmos.c:34

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( _In_ PTIME_FIELDS  Time)

Definition at line 292 of file cmos.c.

294 {
295  UCHAR i, j;
296  UCHAR SysTime[6];
297 
299 
300  HalpRtcWriteCommand(RTC_CMD_REGISTER_SHIFT);
301 
302  SysTime[0] = INT_BCD(Time->Second);
303  SysTime[1] = INT_BCD(Time->Minute);
304  SysTime[2] = INT_BCD(Time->Hour);
305  SysTime[3] = INT_BCD(Time->Day);
306  SysTime[4] = (Time->Month << 4) | (Time->Weekday & 0x0F);
307  SysTime[5] = INT_BCD(Time->Year % 100);
308 
309  /* Write time fields to RTC */
310  for (i = 0; i < 6; i++)
311  {
312  for (j = 0; j < 8; j++)
313  HalpRtcWriteBit(SysTime[i] >> j);
314  }
315 
316  HalpRtcWriteCommand(RTC_CMD_TIME_SET_COUNTER_HOLD);
317  HalpRtcWriteCommand(RTC_CMD_REGISTER_HOLD);
318 
320 
321  return TRUE;
322 }
#define TRUE
Definition: types.h:120
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
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
#define RTC_CMD_TIME_SET_COUNTER_HOLD
Definition: rtc.h:18
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
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_CMD_REGISTER_HOLD
Definition: rtc.h:16
unsigned char UCHAR
Definition: xmlstorage.h:181
#define RTC_CMD_REGISTER_SHIFT
Definition: rtc.h:17
#define INT_BCD(int)
Definition: halp.h:31
static PLARGE_INTEGER Time
Definition: time.c:105

Variable Documentation

◆ MappedNvram