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.

bios_timer.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * BIOS timer
  23. *
  24. */
  25. #include <ipxe/timer.h>
  26. #include <realmode.h>
  27. #include <bios.h>
  28. /**
  29. * Get current system time in ticks
  30. *
  31. * @ret ticks Current time, in ticks
  32. *
  33. * Use direct memory access to BIOS variables, longword 0040:006C
  34. * (ticks today) and byte 0040:0070 (midnight crossover flag) instead
  35. * of calling timeofday BIOS interrupt.
  36. */
  37. static unsigned long bios_currticks ( void ) {
  38. static int days = 0;
  39. uint32_t ticks;
  40. uint8_t midnight;
  41. /* Re-enable interrupts so that the timer interrupt can occur */
  42. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  43. "nop\n\t"
  44. "nop\n\t"
  45. "cli\n\t" ) : : );
  46. get_real ( ticks, BDA_SEG, 0x006c );
  47. get_real ( midnight, BDA_SEG, 0x0070 );
  48. if ( midnight ) {
  49. midnight = 0;
  50. put_real ( midnight, BDA_SEG, 0x0070 );
  51. days += 0x1800b0;
  52. }
  53. return ( days + ticks );
  54. }
  55. PROVIDE_TIMER_INLINE ( pcbios, udelay );
  56. PROVIDE_TIMER ( pcbios, currticks, bios_currticks );
  57. PROVIDE_TIMER_INLINE ( pcbios, ticks_per_sec );