rtc.S 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#rct */
  2. /*
  3. * Reference: https://wiki.osdev.org/CMOS
  4. Register Contents Range
  5. 0x00 Seconds 0–59
  6. 0x02 Minutes 0–59
  7. 0x04 Hours 0–23 in 24-hour mode,
  8. 1–12 in 12-hour mode, highest bit set if pm
  9. 0x07 Day of Month 1–31
  10. 0x08 Month 1–12
  11. 0x09 Year 0–99
  12. 0x0A Status Register A
  13. RTC has an "Update in progress" flag (bit 7 of Status Register A).
  14. To read the time and date properly you have to wait until
  15. the "Update in progress" flag goes from "set" to "clear".
  16. */
  17. .equ RTCaddress, 0x70
  18. .equ RTCdata, 0x71
  19. #include "common.h"
  20. BEGIN
  21. update_in_progress:
  22. mov $0x0A, %al
  23. out %al, $RTCaddress
  24. in $RTCdata, %al
  25. testb $0x80, %al
  26. jne update_in_progress
  27. /* Second. */
  28. mov $0x00, %al
  29. out %al, $RTCaddress
  30. in $RTCdata, %al
  31. /* Only print if second changed. */
  32. cmp %al, %cl
  33. je update_in_progress
  34. mov %al, %cl
  35. PRINT_HEX <%al>
  36. PUTC
  37. /* Minute. */
  38. mov $0x02, %al
  39. out %al, $RTCaddress
  40. in $RTCdata, %al
  41. PRINT_HEX <%al>
  42. PUTC
  43. /* Hour. */
  44. mov $0x04, %al
  45. out %al, $RTCaddress
  46. in $RTCdata, %al
  47. PRINT_HEX <%al>
  48. PUTC
  49. /* Day. */
  50. mov $0x07, %al
  51. out %al, $RTCaddress
  52. in $RTCdata, %al
  53. PRINT_HEX <%al>
  54. PUTC
  55. /* Month. */
  56. mov $0x08, %al
  57. out %al, $RTCaddress
  58. in $RTCdata, %al
  59. PRINT_HEX <%al>
  60. PUTC
  61. /* Year. */
  62. mov $0x09, %al
  63. out %al, $RTCaddress
  64. in $RTCdata, %al
  65. PRINT_HEX <%al>
  66. PRINT_NEWLINE
  67. jmp update_in_progress