summaryrefslogtreecommitdiffstats
path: root/contrib/syslinux-4.02/core/timer.inc
blob: b01ff917950664e4b05bf18de36e3e54e8f31d41 (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
56
57
;; -----------------------------------------------------------------------
;;
;;   Copyright 2009 Intel Corporation; author: H. Peter Anvin
;;
;;   This program is free software; you can redistribute it and/or modify
;;   it under the terms of the GNU General Public License as published by
;;   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
;;   Boston MA 02110-1301, USA; either version 2 of the License, or
;;   (at your option) any later version; incorporated herein by reference.
;;
;; -----------------------------------------------------------------------

;;
;; timer.inc
;;
;; Very simple counting timer
;;
;; This lets us have a simple incrementing variable without worrying
;; about the BIOS_timer variable wrapping around at "midnight" and other
;; weird things.
;;
;; This also maintains a timer variable calibrated in milliseconds
;; (wraparound time = 49.7 days!)
;;

		section .text16

timer_init:
		; Hook INT 1Ch
		mov eax,[BIOS_timer_hook]
		mov [BIOS_timer_next],eax
		mov dword [BIOS_timer_hook],timer_irq
		ret

timer_cleanup:
		; Unhook INT 1Ch
		mov eax,[BIOS_timer_next]
		mov [BIOS_timer_hook],eax
		ret

;
; The specified frequency is 14.31818 MHz/12/65536; this turns out
; to be a period of 54.92542 ms, or 0x36.ece8(187c) hexadecimal.
;
timer_irq:
		inc dword [cs:__jiffies]
		add word  [cs:__ms_timer_adj],0xece8
		adc dword [cs:__ms_timer],0x36
		jmp 0:0
BIOS_timer_next	equ $-4

		section .data16
		alignz 4
		global __jiffies, __ms_timer
__jiffies	dd 0			; Clock tick timer
__ms_timer	dd 0			; Millisecond timer
__ms_timer_adj	dw 0			; Millisecond timer correction factor