bios_timer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 /** @file
00022  *
00023  * BIOS timer
00024  *
00025  */
00026 
00027 #include <gpxe/timer.h>
00028 #include <realmode.h>
00029 #include <bios.h>
00030 
00031 /**
00032  * Get current system time in ticks
00033  *
00034  * @ret ticks           Current time, in ticks
00035  *
00036  * Use direct memory access to BIOS variables, longword 0040:006C
00037  * (ticks today) and byte 0040:0070 (midnight crossover flag) instead
00038  * of calling timeofday BIOS interrupt.
00039  */
00040 static unsigned long bios_currticks ( void ) {
00041         static int days = 0;
00042         uint32_t ticks;
00043         uint8_t midnight;
00044 
00045         /* Re-enable interrupts so that the timer interrupt can occur */
00046         __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
00047                                            "nop\n\t"
00048                                            "nop\n\t"
00049                                            "cli\n\t" ) : : );
00050 
00051         get_real ( ticks, BDA_SEG, 0x006c );
00052         get_real ( midnight, BDA_SEG, 0x0070 );
00053 
00054         if ( midnight ) {
00055                 midnight = 0;
00056                 put_real ( midnight, BDA_SEG, 0x0070 );
00057                 days += 0x1800b0;
00058         }
00059 
00060         return ( days + ticks );
00061 }
00062 
00063 PROVIDE_TIMER_INLINE ( pcbios, udelay );
00064 PROVIDE_TIMER ( pcbios, currticks, bios_currticks );
00065 PROVIDE_TIMER_INLINE ( pcbios, ticks_per_sec );

Generated on Tue Apr 6 20:00:50 2010 for gPXE by  doxygen 1.5.7.1