Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

bios_timer.c 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * BIOS timer
  27. *
  28. */
  29. #include <ipxe/timer.h>
  30. #include <realmode.h>
  31. #include <bios.h>
  32. #include <ipxe/pit8254.h>
  33. /** Number of ticks per day
  34. *
  35. * This seems to be the normative value, as used by e.g. SeaBIOS to
  36. * decide when to set the midnight rollover flag.
  37. */
  38. #define BIOS_TICKS_PER_DAY 0x1800b0
  39. /** Number of ticks per BIOS tick */
  40. #define TICKS_PER_BIOS_TICK \
  41. ( ( TICKS_PER_SEC * 60 * 60 * 24 ) / BIOS_TICKS_PER_DAY )
  42. /**
  43. * Get current system time in ticks
  44. *
  45. * @ret ticks Current time, in ticks
  46. *
  47. * Use direct memory access to BIOS variables, longword 0040:006C
  48. * (ticks today) and byte 0040:0070 (midnight crossover flag) instead
  49. * of calling timeofday BIOS interrupt.
  50. */
  51. static unsigned long bios_currticks ( void ) {
  52. static uint32_t offset;
  53. uint32_t ticks;
  54. uint8_t midnight;
  55. /* Re-enable interrupts so that the timer interrupt can occur */
  56. __asm__ __volatile__ ( "sti\n\t"
  57. "nop\n\t"
  58. "nop\n\t"
  59. "cli\n\t" );
  60. /* Read current BIOS time of day */
  61. get_real ( ticks, BDA_SEG, BDA_TICKS );
  62. get_real ( midnight, BDA_SEG, BDA_MIDNIGHT );
  63. /* Handle midnight rollover */
  64. if ( midnight ) {
  65. midnight = 0;
  66. put_real ( midnight, BDA_SEG, BDA_MIDNIGHT );
  67. offset += BIOS_TICKS_PER_DAY;
  68. }
  69. ticks += offset;
  70. /* Convert to timer ticks */
  71. return ( ticks * TICKS_PER_BIOS_TICK );
  72. }
  73. /** BIOS timer */
  74. struct timer bios_timer __timer ( TIMER_NORMAL ) = {
  75. .name = "bios",
  76. .currticks = bios_currticks,
  77. .udelay = pit8254_udelay,
  78. };