iPXE
Defines | Functions
bios_timer.c File Reference

BIOS timer. More...

#include <ipxe/timer.h>
#include <realmode.h>
#include <bios.h>
#include <ipxe/pit8254.h>

Go to the source code of this file.

Defines

#define BIOS_TICKS_PER_DAY   0x1800b0
 Number of ticks per day.
#define TICKS_PER_BIOS_TICK   ( ( TICKS_PER_SEC * 60 * 60 * 24 ) / BIOS_TICKS_PER_DAY )
 Number of ticks per BIOS tick.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static unsigned long bios_currticks (void)
 Get current system time in ticks.
struct timer bios_timer __timer (TIMER_NORMAL)
 BIOS timer.

Detailed Description

BIOS timer.

Definition in file bios_timer.c.


Define Documentation

#define BIOS_TICKS_PER_DAY   0x1800b0

Number of ticks per day.

This seems to be the normative value, as used by e.g. SeaBIOS to decide when to set the midnight rollover flag.

Definition at line 42 of file bios_timer.c.

Referenced by bios_currticks().

#define TICKS_PER_BIOS_TICK   ( ( TICKS_PER_SEC * 60 * 60 * 24 ) / BIOS_TICKS_PER_DAY )

Number of ticks per BIOS tick.

Definition at line 45 of file bios_timer.c.

Referenced by bios_currticks().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static unsigned long bios_currticks ( void  ) [static]

Get current system time in ticks.

Return values:
ticksCurrent time, in ticks

Use direct memory access to BIOS variables, longword 0040:006C (ticks today) and byte 0040:0070 (midnight crossover flag) instead of calling timeofday BIOS interrupt.

Definition at line 57 of file bios_timer.c.

References __asm__(), BDA_MIDNIGHT, BDA_SEG, BDA_TICKS, BIOS_TICKS_PER_DAY, get_real, offset, put_real, and TICKS_PER_BIOS_TICK.

                                             {
        static uint32_t offset;
        uint32_t ticks;
        uint8_t midnight;

        /* Re-enable interrupts so that the timer interrupt can occur */
        __asm__ __volatile__ ( "sti\n\t"
                               "nop\n\t"
                               "nop\n\t"
                               "cli\n\t" );

        /* Read current BIOS time of day */
        get_real ( ticks, BDA_SEG, BDA_TICKS );
        get_real ( midnight, BDA_SEG, BDA_MIDNIGHT );

        /* Handle midnight rollover */
        if ( midnight ) {
                midnight = 0;
                put_real ( midnight, BDA_SEG, BDA_MIDNIGHT );
                offset += BIOS_TICKS_PER_DAY;
        }
        ticks += offset;

        /* Convert to timer ticks */
        return ( ticks * TICKS_PER_BIOS_TICK );
}
struct timer bios_timer __timer ( TIMER_NORMAL  ) [read]

BIOS timer.