Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
6.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. jxtime.c
  5. Abstract:
  6. This module implements the HAL set/query realtime clock routines for
  7. a MIPS R3000 or R4000 Jazz system.
  8. Author:
  9. David N. Cutler (davec) 5-May-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "halp.h"
  15. #include "jazzrtc.h"
  16. #include "eisa.h"
  17. //
  18. // Define forward referenced procedure prototypes.
  19. //
  20. UCHAR
  21. HalpReadClockRegister (
  22. UCHAR Register
  23. );
  24. VOID
  25. HalpWriteClockRegister (
  26. UCHAR Register,
  27. UCHAR Value
  28. );
  29. BOOLEAN
  30. HalQueryRealTimeClock (
  31. OUT PTIME_FIELDS TimeFields
  32. )
  33. /*++
  34. Routine Description:
  35. This routine queries the realtime clock.
  36. N.B. This routine is required to provide any synchronization necessary
  37. to query the realtime clock information.
  38. Arguments:
  39. TimeFields - Supplies a pointer to a time structure that receives
  40. the realtime clock information.
  41. Return Value:
  42. If the power to the realtime clock has not failed, then the time
  43. values are read from the realtime clock and a value of TRUE is
  44. returned. Otherwise, a value of FALSE is returned.
  45. --*/
  46. {
  47. UCHAR DataByte;
  48. KIRQL OldIrql;
  49. //
  50. // If the realtime clock battery is still functioning, then read
  51. // the realtime clock values, and return a function value of TRUE.
  52. // Otherwise, return a function value of FALSE.
  53. //
  54. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  55. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERD);
  56. if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {
  57. //
  58. // Wait until the realtime clock is not being updated.
  59. //
  60. do {
  61. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERA);
  62. } while (((PRTC_CONTROL_REGISTER_A)(&DataByte))->UpdateInProgress == 1);
  63. //
  64. // Read the realtime clock values.
  65. //
  66. TimeFields->Year = 1980 + (CSHORT)HalpReadClockRegister(RTC_YEAR);
  67. TimeFields->Month = (CSHORT)HalpReadClockRegister(RTC_MONTH);
  68. TimeFields->Day = (CSHORT)HalpReadClockRegister(RTC_DAY_OF_MONTH);
  69. TimeFields->Weekday = (CSHORT)HalpReadClockRegister(RTC_DAY_OF_WEEK) - 1;
  70. TimeFields->Hour = (CSHORT)HalpReadClockRegister(RTC_HOUR);
  71. TimeFields->Minute = (CSHORT)HalpReadClockRegister(RTC_MINUTE);
  72. TimeFields->Second = (CSHORT)HalpReadClockRegister(RTC_SECOND);
  73. TimeFields->Milliseconds = 0;
  74. KeLowerIrql(OldIrql);
  75. return TRUE;
  76. } else {
  77. KeLowerIrql(OldIrql);
  78. return FALSE;
  79. }
  80. }
  81. BOOLEAN
  82. HalSetRealTimeClock (
  83. IN PTIME_FIELDS TimeFields
  84. )
  85. /*++
  86. Routine Description:
  87. This routine sets the realtime clock.
  88. N.B. This routine is required to provide any synchronization necessary
  89. to set the realtime clock information.
  90. Arguments:
  91. TimeFields - Supplies a pointer to a time structure that specifies the
  92. realtime clock information.
  93. Return Value:
  94. If the power to the realtime clock has not failed, then the time
  95. values are written to the realtime clock and a value of TRUE is
  96. returned. Otherwise, a value of FALSE is returned.
  97. --*/
  98. {
  99. UCHAR DataByte;
  100. KIRQL OldIrql;
  101. //
  102. // If the realtime clock battery is still functioning, then write
  103. // the realtime clock values, and return a function value of TRUE.
  104. // Otherwise, return a function value of FALSE.
  105. //
  106. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  107. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERD);
  108. if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {
  109. //
  110. // Set the realtime clock control to set the time.
  111. //
  112. DataByte = 0;
  113. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->HoursFormat = 1;
  114. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->DataMode = 1;
  115. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 1;
  116. HalpWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  117. //
  118. // Write the realtime clock values.
  119. //
  120. HalpWriteClockRegister(RTC_YEAR, (UCHAR)(TimeFields->Year - 1980));
  121. HalpWriteClockRegister(RTC_MONTH, (UCHAR)TimeFields->Month);
  122. HalpWriteClockRegister(RTC_DAY_OF_MONTH, (UCHAR)TimeFields->Day);
  123. HalpWriteClockRegister(RTC_DAY_OF_WEEK, (UCHAR)(TimeFields->Weekday + 1));
  124. HalpWriteClockRegister(RTC_HOUR, (UCHAR)TimeFields->Hour);
  125. HalpWriteClockRegister(RTC_MINUTE, (UCHAR)TimeFields->Minute);
  126. HalpWriteClockRegister(RTC_SECOND, (UCHAR)TimeFields->Second);
  127. //
  128. // Set the realtime clock control to update the time.
  129. //
  130. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 0;
  131. HalpWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  132. KeLowerIrql(OldIrql);
  133. return TRUE;
  134. } else {
  135. KeLowerIrql(OldIrql);
  136. return FALSE;
  137. }
  138. }
  139. UCHAR
  140. HalpReadClockRegister (
  141. UCHAR Register
  142. )
  143. /*++
  144. Routine Description:
  145. This routine reads the specified realtime clock register.
  146. Arguments:
  147. Register - Supplies the number of the register whose value is read.
  148. Return Value:
  149. The value of the register is returned as the function value.
  150. --*/
  151. {
  152. //
  153. // Insert the realtime clock register number, and write the value back
  154. // to the EISA NMI enable register. This selects the realtime clock register
  155. // that is read. Note this is a write only register and the EISA NMI
  156. // is always enabled.
  157. //
  158. //
  159. // TEMPTEMP Disable NMI's for now because this is causing machines in the
  160. // build lab to get NMI's during boot.
  161. //
  162. Register |= 0x80;
  163. WRITE_REGISTER_UCHAR(&((PEISA_CONTROL) HalpEisaControlBase)->NmiEnable,
  164. Register);
  165. //
  166. // Read the realtime clock register value.
  167. //
  168. return READ_REGISTER_UCHAR((PUCHAR)HalpRealTimeClockBase);
  169. }
  170. VOID
  171. HalpWriteClockRegister (
  172. UCHAR Register,
  173. UCHAR Value
  174. )
  175. /*++
  176. Routine Description:
  177. This routine writes the specified value to the specified realtime
  178. clock register.
  179. Arguments:
  180. Register - Supplies the number of the register whose value is written.
  181. Value - Supplies the value that is written to the specified register.
  182. Return Value:
  183. The value of the register is returned as the function value.
  184. --*/
  185. {
  186. //
  187. // Insert the realtime clock register number, and write the value back
  188. // to the EISA NMI enable register. This selects the realtime clock
  189. // register that is written. Note this is a write only register and
  190. // the EISA NMI is always enabled.
  191. //
  192. Register |= 0x80;
  193. WRITE_REGISTER_UCHAR(&((PEISA_CONTROL) HalpEisaControlBase)->NmiEnable,
  194. Register);
  195. //
  196. // Write the realtime clock register value.
  197. //
  198. WRITE_REGISTER_UCHAR((PUCHAR)HalpRealTimeClockBase, Value);
  199. return;
  200. }