xref: /haiku/src/system/libroot/os/arch/x86/system_time_asm.S (revision 3be9edf8da228afd9fec0390f408c964766122aa)
1/*
2** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3** Distributed under the terms of the NewOS License.
4*/
5
6#include <asm_defs.h>
7
8
9/* saves the conversion factor needed for system_time */
10.lcomm cv_factor 4
11
12
13.text
14
15FUNCTION(__x86_setup_system_time):
16	movl	4(%esp),%eax
17	movl	%eax,cv_factor
18	ret
19FUNCTION_END(__x86_setup_system_time)
20
21/* long long system_time(); */
22FUNCTION(system_time):
23	/* load 64-bit factor into %eax (low), %edx (high) */
24	rdtsc		/* time in %edx,%eax */
25
26	pushl	%ebx
27	pushl	%ecx
28	movl	cv_factor, %ebx
29	movl	%edx, %ecx	/* save high half */
30	mull	%ebx 		/* truncate %eax, but keep %edx */
31	movl	%ecx, %eax
32	movl	%edx, %ecx	/* save high half of low */
33	mull	%ebx /*, %eax*/
34	/* now compute  [%edx, %eax] + [%ecx], propagating carry */
35	subl	%ebx, %ebx	/* need zero to propagate carry */
36	addl	%ecx, %eax
37	adc		%ebx, %edx
38	popl	%ecx
39	popl	%ebx
40	ret
41FUNCTION_END(system_time)
42