source: xtideuniversalbios/trunk/Assembly_Library/Src/TimerTest.asm@ 629

Last change on this file since 629 was 526, checked in by krille_n_@…, 12 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 5.7 KB
RevLine 
[256]1; Project name : Assembly Library
2; Description : Tests for Assembly Library.
3
[376]4;
[505]5; XTIDE Universal BIOS and Associated Tools
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[505]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[505]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[505]18;
[376]19
[256]20; Include .inc files
21%define INCLUDE_DISPLAY_LIBRARY
22%define INCLUDE_TIME_LIBRARY
23%include "AssemblyLibrary.inc" ; Assembly Library. Must be included first!
24
25
26; Section containing code
27SECTION .text
28
29; Program first instruction.
[287]30CPU 486
[256]31ORG 100h ; Code starts at offset 100h (DOS .COM)
32Start:
[287]33 jmp BusMeasurements_Start
[256]34
35; Include library sources
36%include "AssemblyLibrary.asm"
37
[287]38%macro MOV_TIMING_LOOP 1
39 xor bx, bx ; Offset for memory transfers
40 mov dx, OFFSET_TO_NEXT_WORD ; Must be at least 32 (Pentium Cache Line size)
41 wbinvd ; Flush and invalidate internal cache
42 cli ; Disable interrupts
43 START_PRECISE_EVENT_TIMER
44ALIGN 8
45%%ReadNextWord:
46 mov ax, %1 ; 2 bytes
47 add bx, dx ; 2 bytes
48 jnc SHORT %%ReadNextWord ; 2 bytes
49 STOP_PRECISE_EVENT_TIMER
50 sti
51%endmacro
[256]52
[287]53
[256]54;--------------------------------------------------------------------
55; Program start
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
[287]58BusMeasurements_Start:
[256]59 CALL_DISPLAY_LIBRARY InitializeDisplayContext
[287]60 xor ax, ax
61 mov ds, ax
[256]62
[287]63 call MeasureRegAndMemMovDurationDifferenceToAX
64 call GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
65 call GetBusClockRateFromCycleTimeInAX
66 mov si, g_szBusMeasurements
67 call PrintBusMeasurements
[256]68
[287]69 call AssumeVlbCycleTimeToAXfromBusCycleTimeInCX
70 call GetBusClockRateFromCycleTimeInAX
71 mov si, g_szVlbAssumption
72 call PrintBusMeasurements
[256]73
74 ; Exit to DOS
75 mov ax, 4C00h ; Exit to DOS
76 int 21h
77
78
[287]79
80;--------------------------------------------------------------------
81; MeasureRegAndMemMovDurationDifferenceToAX
82; Parameters:
83; DS: Segment for memory read tests
84; Returns:
85; AX: Difference in register and memory access durations
86; (Precise Event Timer Ticks)
87; Corrupts registers:
88; BX, CX, DX
89;--------------------------------------------------------------------
90MeasureRegAndMemMovDurationDifferenceToAX:
91 call SystemTimer_IntializePreciseEventTimer
92
93 MOV_TIMING_LOOP bx
94 call SystemTimer_GetPreciseEventTimerTicksToAX
95 xchg cx, ax ; Duration now in CX
96
97 MOV_TIMING_LOOP [bx]
98 call SystemTimer_GetPreciseEventTimerTicksToAX
99 sub ax, cx ; AX = Difference in durations
100 sub ax, cx
101 ret
102
103
104;--------------------------------------------------------------------
105; We must divide the duration by 4 since the timing loop loads
106; whole cache line (4 times the bus width) instead of single BYTE.
107;
108; GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
109; Parameters:
110; AX: Difference in register and memory access durations
[505]111; (Precise Event Timer Ticks)
[287]112; Returns:
113; AX: Duration for single BYTE in nanosecs
114; Corrupts registers:
115; CX, DX
116;--------------------------------------------------------------------
117GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX:
118 mov dx, TIMER_CYCLE_TIME
119 mul dx ; DX:AX = Duration in nanosecs
120 mov cx, (65536 / OFFSET_TO_NEXT_WORD) * 4
121 div cx ; AX = Duration for single BYTE in nanosecs
122 ret
123
124
125;--------------------------------------------------------------------
126; GetBusClockRateFromCycleTimeInAX
127; Parameters:
128; AX: Bus Cycle Time in nanosecs
129; Returns:
130; CX: Bus Cycle Time in nanosecs
131; DX: Bus Clock Rate (MHz)
132; AX: Clock Rate tenths
133; Corrupts registers:
134; Nothing
135;--------------------------------------------------------------------
136GetBusClockRateFromCycleTimeInAX:
137 xchg cx, ax
138 xor dx, dx
139 mov ax, 1000
140 div cl ; AL = MHz, AH = Remainder
141 xchg al, dl ; DX = Bus Clock Rate, AL = 0
142 aad ; AX = 10 * AH (+AL)
143 div cl
144 xor ah, ah ; AX = Tenths
145 ret
146
147
148;--------------------------------------------------------------------
149; AssumeVlbCycleTimeToAXfromBusCycleTimeInCX
150; Parameters:
151; CX: Bus Cycle Time in nanosecs
152; Returns:
153; AX: Assumed VLB Cycle Time in nanosecs
154; Corrupts registers:
155; Nothing
156;--------------------------------------------------------------------
157AssumeVlbCycleTimeToAXfromBusCycleTimeInCX:
158 mov ax, cx
159 cmp al, 24 ; 25 = 40 MHz
160 jb SHORT .AssumePentiumSoDivideBy2
161 ret
162.AssumePentiumSoDivideBy2:
163 shr ax, 1
164 ret
165
166
167;--------------------------------------------------------------------
168; PrintBusMeasurements
169; Parameters:
170; CX: Bus Cycle Time in nanosecs
171; DX: Bus Clock Rate (MHz)
172; AX: Clock Rate tenths
173; SI: Offset to string to format
174; Returns:
175; Nothing
176; Corrupts registers:
177; AX, DX, BP
178;--------------------------------------------------------------------
179PrintBusMeasurements:
[256]180 mov bp, sp
[287]181 push cx
182 push dx
[256]183 push ax
[505]184 JMP_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
[256]185
186
187
188; Section containing initialized data
189SECTION .data
190
[287]191OFFSET_TO_NEXT_WORD EQU 32 ; Must be at least 32 (Pentium Cache Line size)
[256]192
[287]193g_szBusMeasurements:
194 db "Detected bus cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
195g_szVlbAssumption:
196 db "Assuming VLB (if exists) cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
[256]197g_szDashForZero: db "- ",NULL
198
199
200
201; Section containing uninitialized data
202SECTION .bss
Note: See TracBrowser for help on using the repository browser.