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.

377 lines
8.6 KiB

4 years ago
  1. // #pragma comment(exestr, "@(#) jxtime.c 1.1 95/09/28 15:41:57 nec")
  2. /*++
  3. Copyright (c) 1991 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. Author:
  10. David N. Cutler (davec) 5-May-1991
  11. Environment:
  12. Kernel mode
  13. Revision History:
  14. M0001 1994.9.9 kbnes!A.Kuriyama
  15. Modify for R94A
  16. HalpReadClockRegister() - R94A use RTC Index register except EISA NmiEnable
  17. register.
  18. HalpWriteClockRegister() - R94A use RTC Index register except EISA NmiEnable
  19. register.
  20. M0002 1994.10.8 kbnes!kuriyama(A)
  21. HalpReadClockRegister()
  22. -add specify Read Data register
  23. HalpWritelockRegister()
  24. -add specify Write Data register
  25. M0003 1994.10.14 kbnes!kuriyama(A)
  26. define error clear
  27. M0004 1994.12.19 kbnes!kuriyama(A)
  28. define miss fix
  29. --*/
  30. #include "halp.h"
  31. #include "jazzrtc.h"
  32. #include "eisa.h"
  33. //
  34. // Define forward referenced procedure prototypes.
  35. //
  36. UCHAR
  37. HalpReadClockRegister (
  38. UCHAR Register
  39. );
  40. VOID
  41. HalpWriteClockRegister (
  42. UCHAR Register,
  43. UCHAR Value
  44. );
  45. BOOLEAN
  46. HalQueryRealTimeClock (
  47. OUT PTIME_FIELDS TimeFields
  48. )
  49. /*++
  50. Routine Description:
  51. This routine queries the realtime clock.
  52. N.B. This routine is required to provide any synchronization necessary
  53. to query the realtime clock information.
  54. Arguments:
  55. TimeFields - Supplies a pointer to a time structure that receives
  56. the realtime clock information.
  57. Return Value:
  58. If the power to the realtime clock has not failed, then the time
  59. values are read from the realtime clock and a value of TRUE is
  60. returned. Otherwise, a value of FALSE is returned.
  61. --*/
  62. {
  63. UCHAR DataByte;
  64. KIRQL OldIrql;
  65. //
  66. // If the realtime clock battery is still functioning, then read
  67. // the realtime clock values, and return a function value of TRUE.
  68. // Otherwise, return a function value of FALSE.
  69. //
  70. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  71. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERD);
  72. if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {
  73. //
  74. // Wait until the realtime clock is not being updated.
  75. //
  76. do {
  77. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERA);
  78. } while (((PRTC_CONTROL_REGISTER_A)(&DataByte))->UpdateInProgress == 1);
  79. //
  80. // Read the realtime clock values.
  81. //
  82. TimeFields->Year = 1980 + (CSHORT)HalpReadClockRegister(RTC_YEAR);
  83. TimeFields->Month = (CSHORT)HalpReadClockRegister(RTC_MONTH);
  84. TimeFields->Day = (CSHORT)HalpReadClockRegister(RTC_DAY_OF_MONTH);
  85. TimeFields->Weekday = (CSHORT)HalpReadClockRegister(RTC_DAY_OF_WEEK) - 1;
  86. TimeFields->Hour = (CSHORT)HalpReadClockRegister(RTC_HOUR);
  87. TimeFields->Minute = (CSHORT)HalpReadClockRegister(RTC_MINUTE);
  88. TimeFields->Second = (CSHORT)HalpReadClockRegister(RTC_SECOND);
  89. TimeFields->Milliseconds = 0;
  90. KeLowerIrql(OldIrql);
  91. return TRUE;
  92. } else {
  93. KeLowerIrql(OldIrql);
  94. return FALSE;
  95. }
  96. }
  97. BOOLEAN
  98. HalSetRealTimeClock (
  99. IN PTIME_FIELDS TimeFields
  100. )
  101. /*++
  102. Routine Description:
  103. This routine sets the realtime clock.
  104. N.B. This routine is required to provide any synchronization necessary
  105. to set the realtime clock information.
  106. Arguments:
  107. TimeFields - Supplies a pointer to a time structure that specifies the
  108. realtime clock information.
  109. Return Value:
  110. If the power to the realtime clock has not failed, then the time
  111. values are written to the realtime clock and a value of TRUE is
  112. returned. Otherwise, a value of FALSE is returned.
  113. --*/
  114. {
  115. UCHAR DataByte;
  116. KIRQL OldIrql;
  117. //
  118. // If the realtime clock battery is still functioning, then write
  119. // the realtime clock values, and return a function value of TRUE.
  120. // Otherwise, return a function value of FALSE.
  121. //
  122. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  123. DataByte = HalpReadClockRegister(RTC_CONTROL_REGISTERD);
  124. if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {
  125. //
  126. // Set the realtime clock control to set the time.
  127. //
  128. DataByte = 0;
  129. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->HoursFormat = 1;
  130. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->DataMode = 1;
  131. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 1;
  132. HalpWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  133. //
  134. // Write the realtime clock values.
  135. //
  136. HalpWriteClockRegister(RTC_YEAR, (UCHAR)(TimeFields->Year - 1980));
  137. HalpWriteClockRegister(RTC_MONTH, (UCHAR)TimeFields->Month);
  138. HalpWriteClockRegister(RTC_DAY_OF_MONTH, (UCHAR)TimeFields->Day);
  139. HalpWriteClockRegister(RTC_DAY_OF_WEEK, (UCHAR)(TimeFields->Weekday + 1));
  140. HalpWriteClockRegister(RTC_HOUR, (UCHAR)TimeFields->Hour);
  141. HalpWriteClockRegister(RTC_MINUTE, (UCHAR)TimeFields->Minute);
  142. HalpWriteClockRegister(RTC_SECOND, (UCHAR)TimeFields->Second);
  143. //
  144. // Set the realtime clock control to update the time.
  145. //
  146. ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 0;
  147. HalpWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
  148. KeLowerIrql(OldIrql);
  149. return TRUE;
  150. } else {
  151. KeLowerIrql(OldIrql);
  152. return FALSE;
  153. }
  154. }
  155. UCHAR
  156. HalpReadClockRegister (
  157. UCHAR Register
  158. )
  159. /*++
  160. Routine Description:
  161. This routine reads the specified realtime clock register.
  162. Arguments:
  163. Register - Supplies the number of the register whose value is read.
  164. Return Value:
  165. The value of the register is returned as the function value.
  166. --*/
  167. {
  168. /* start M0001 */
  169. #if defined(_R94A_) /* M0003 */
  170. // Insert the realtime clock register number, and write the value back
  171. // to RTC Index register. This selects the realtime clock register
  172. // that is read.
  173. //
  174. WRITE_REGISTER_UCHAR(&((PRTC_REGISTERS) HalpRealTimeClockBase)->Index,
  175. Register);
  176. #else // _R94A_
  177. //
  178. // Insert the realtime clock register number, and write the value back
  179. // to the EISA NMI enable register. This selects the realtime clock register
  180. // that is read. Note this is a write only register and the EISA NMI
  181. // is always enabled.
  182. //
  183. //
  184. // TEMPTEMP Disable NMI's for now because this is causing machines in the
  185. // build lab to get NMI's during boot.
  186. //
  187. Register |= 0x80;
  188. WRITE_REGISTER_UCHAR(&((PEISA_CONTROL) HalpEisaControlBase)->NmiEnable,
  189. Register);
  190. #endif // _R94A_
  191. /* end M0001 */
  192. //
  193. // Read the realtime clock register value.
  194. //
  195. /* start M0002 */
  196. #if defined(_R94A_) // M0004
  197. return READ_REGISTER_UCHAR( &((PRTC_REGISTERS) HalpRealTimeClockBase)->Data);
  198. #else // _R94A_
  199. return READ_REGISTER_UCHAR((PUCHAR)HalpRealTimeClockBase);
  200. #endif // _R94A_
  201. /* end M0002 */
  202. }
  203. VOID
  204. HalpWriteClockRegister (
  205. UCHAR Register,
  206. UCHAR Value
  207. )
  208. /*++
  209. Routine Description:
  210. This routine writes the specified value to the specified realtime
  211. clock register.
  212. Arguments:
  213. Register - Supplies the number of the register whose value is written.
  214. Value - Supplies the value that is written to the specified register.
  215. Return Value:
  216. The value of the register is returned as the function value.
  217. --*/
  218. {
  219. /* start M0001 */
  220. #if defined(_R94A_)
  221. //
  222. // Insert the realtime clock register number, and write the value back
  223. // to RTC Index register. This selects the realtime clock
  224. // register that is written.
  225. //
  226. WRITE_REGISTER_UCHAR(&((PRTC_REGISTERS) HalpRealTimeClockBase)->Index,
  227. Register);
  228. #else // _R94A_
  229. //
  230. // Insert the realtime clock register number, and write the value back
  231. // to the EISA NMI enable register. This selects the realtime clock
  232. // register that is written. Note this is a write only register and
  233. // the EISA NMI is always enabled.
  234. //
  235. Register |= 0x80;
  236. WRITE_REGISTER_UCHAR(&((PEISA_CONTROL) HalpEisaControlBase)->NmiEnable,
  237. Register);
  238. #endif // _R94A_
  239. /* end M0001 */
  240. //
  241. // Write the realtime clock register value.
  242. //
  243. /* start M0002 */
  244. #if defined(_R94A_) // M0004
  245. WRITE_REGISTER_UCHAR( &((PRTC_REGISTERS) HalpRealTimeClockBase)->Data, Value);
  246. #else // _R94A_
  247. WRITE_REGISTER_UCHAR((PUCHAR)HalpRealTimeClockBase, Value);
  248. #endif // _R94A_
  249. /* end M0002 */
  250. return;
  251. }