iPXE
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.

Macros

#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.

Macro Definition Documentation

◆ BIOS_TICKS_PER_DAY

#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().

◆ TICKS_PER_BIOS_TICK

#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.

45#define TICKS_PER_BIOS_TICK \
46 ( ( TICKS_PER_SEC * 60 * 60 * 24 ) / BIOS_TICKS_PER_DAY )

Referenced by bios_currticks().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ bios_currticks()

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.

57 {
58 static uint32_t offset;
59 uint32_t ticks;
60 uint8_t midnight;
61
62 /* Re-enable interrupts so that the timer interrupt can occur */
63 __asm__ __volatile__ ( "sti\n\t"
64 "nop\n\t"
65 "nop\n\t"
66 "cli\n\t" );
67
68 /* Read current BIOS time of day */
69 get_real ( ticks, BDA_SEG, BDA_TICKS );
70 get_real ( midnight, BDA_SEG, BDA_MIDNIGHT );
71
72 /* Handle midnight rollover */
73 if ( midnight ) {
74 midnight = 0;
75 put_real ( midnight, BDA_SEG, BDA_MIDNIGHT );
77 }
78 ticks += offset;
79
80 /* Convert to timer ticks */
81 return ( ticks * TICKS_PER_BIOS_TICK );
82}
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
#define BDA_SEG
Definition bios.h:6
#define BDA_MIDNIGHT
Definition bios.h:16
#define BDA_TICKS
Definition bios.h:15
#define BIOS_TICKS_PER_DAY
Number of ticks per day.
Definition bios_timer.c:42
#define TICKS_PER_BIOS_TICK
Number of ticks per BIOS tick.
Definition bios_timer.c:45
uint16_t offset
Offset to command line.
Definition bzimage.h:3
#define put_real
Definition libkir.h:150
#define get_real
Definition libkir.h:151
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")

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

Referenced by __timer().

◆ __timer()

struct timer bios_timer __timer ( TIMER_NORMAL )

BIOS timer.

References __timer, bios_currticks(), and TIMER_NORMAL.