summaryrefslogtreecommitdiffstats
path: root/src/arch/i386/firmware/pcbios/bios.c
blob: bcbe98a88a2cb7307fdf5408bc7d343b12bc2475 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Etherboot routines for PCBIOS firmware.
 *
 * Body of routines taken from old pcbios.S
 */

#include <stdint.h>
#include <realmode.h>
#include <bios.h>

#define CF ( 1 << 0 )

/**************************************************************************
CURRTICKS - Get Time
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.
**************************************************************************/
#if defined(CONFIG_TSC_CURRTICKS)
#undef CONFIG_BIOS_CURRTICKS
#else
#define CONFIG_BIOS_CURRTICKS 1
#endif
#if defined(CONFIG_BIOS_CURRTICKS)
unsigned long currticks ( void ) {
	static uint32_t days = 0;
	uint32_t ticks;
	uint8_t midnight;

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

	get_real ( ticks, BDA_SEG, 0x006c );
	get_real ( midnight, BDA_SEG, 0x0070 );

	if ( midnight ) {
		midnight = 0;
		put_real ( midnight, BDA_SEG, 0x0070 );
		days += 0x1800b0;
	}
	return ( days + ticks );
}
#endif	/* CONFIG_BIOS_CURRTICKS */

/**************************************************************************
CPU_NAP - Save power by halting the CPU until the next interrupt
**************************************************************************/
void cpu_nap ( void ) {
	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
					   "hlt\n\t"
					   "cli\n\t" ) : : );
}