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.

313 lines
7.2 KiB

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