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

Last change on this file since 390 was 376, checked in by gregli@…, 12 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 5.8 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Tests for Assembly Library.
3
4;
5; XTIDE Universal BIOS and Associated Tools 
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
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.
12; 
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
16; GNU General Public License for more details.     
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;       
19
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.
30CPU 486
31ORG 100h                        ; Code starts at offset 100h (DOS .COM)
32Start:
33    jmp     BusMeasurements_Start
34
35; Include library sources
36%include "AssemblyLibrary.asm"
37
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
52
53
54;--------------------------------------------------------------------
55; Program start
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
58BusMeasurements_Start:
59    CALL_DISPLAY_LIBRARY InitializeDisplayContext
60    xor     ax, ax
61    mov     ds, ax
62
63    call    MeasureRegAndMemMovDurationDifferenceToAX
64    call    GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
65    call    GetBusClockRateFromCycleTimeInAX
66    mov     si, g_szBusMeasurements
67    call    PrintBusMeasurements
68
69    call    AssumeVlbCycleTimeToAXfromBusCycleTimeInCX
70    call    GetBusClockRateFromCycleTimeInAX
71    mov     si, g_szVlbAssumption
72    call    PrintBusMeasurements
73
74    ; Exit to DOS
75    mov     ax, 4C00h           ; Exit to DOS
76    int     21h
77
78
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
111;               (Precise Event Timer Ticks) 
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:
180    mov     bp, sp
181    push    cx
182    push    dx
183    push    ax
184    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
185    ret
186
187
188
189; Section containing initialized data
190SECTION .data
191
192OFFSET_TO_NEXT_WORD     EQU 32  ; Must be at least 32 (Pentium Cache Line size)
193
194g_szBusMeasurements:
195    db  "Detected bus cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
196g_szVlbAssumption:
197    db  "Assuming VLB (if exists) cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
198g_szDashForZero:        db      "- ",NULL
199
200
201
202; Section containing uninitialized data
203SECTION .bss
Note: See TracBrowser for help on using the repository browser.