summaryrefslogtreecommitdiff
path: root/core/timer.inc
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-09-02 17:44:32 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-09-02 17:44:32 -0700
commit75d4dec2f651c9f25fa95d6b6960db7c4dcfd7a0 (patch)
tree1fc477d5f43577a31eaaff7c5a17f719c4e69e1d /core/timer.inc
parent94a6e382a7a253fdab67a3bff981844dd5f6d4cb (diff)
downloadsyslinux-75d4dec2f651c9f25fa95d6b6960db7c4dcfd7a0.tar.gz
core: hook INT 1Ch for a simple monotonic timer
The BIOS_timer variable at 4C6h is somewhat unreliable... it is documented to wrap at "midnight", norminally after 1627419 ticks (0x18d51b), which is a rather awkward number to deal with modulo. Instead, hook the INT 1Ch secondary timer interrupt and just count a simple incrementing variable. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'core/timer.inc')
-rw-r--r--core/timer.inc45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/timer.inc b/core/timer.inc
new file mode 100644
index 00000000..caae8265
--- /dev/null
+++ b/core/timer.inc
@@ -0,0 +1,45 @@
+;; -----------------------------------------------------------------------
+;;
+;; 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.
+;;
+
+ 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
+
+timer_irq:
+ inc dword [cs:__jiffies]
+ jmp 0:0
+BIOS_timer_next equ $-4
+
+ section .bss16
+ global __jiffies
+__jiffies resd 1 ; The actual timer variable