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

Macros

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

Functions

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

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.

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ bios_currticks()

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.

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 }
#define TICKS_PER_BIOS_TICK
Number of ticks per BIOS tick.
Definition: bios_timer.c:45
#define BIOS_TICKS_PER_DAY
Number of ticks per day.
Definition: bios_timer.c:42
#define get_real
Definition: libkir.h:151
#define BDA_TICKS
Definition: bios.h:15
#define put_real
Definition: libkir.h:150
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned char uint8_t
Definition: stdint.h:10
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
#define BDA_SEG
Definition: bios.h:6
unsigned int uint32_t
Definition: stdint.h:12
__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")
#define BDA_MIDNIGHT
Definition: bios.h:16

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

◆ __timer()

struct timer bios_timer __timer ( TIMER_NORMAL  )

BIOS timer.