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

Last change on this file since 287 was 287, checked in by aitotat@…, 12 years ago

Changes to Assembly Library:

  • Hopefully fixed a problem of wrong sized MDA cursor.
  • Some minor improvements.
File size: 5.1 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Tests for Assembly Library.
3
4; Include .inc files
5%define INCLUDE_DISPLAY_LIBRARY
6%define INCLUDE_TIME_LIBRARY
7%include "AssemblyLibrary.inc"  ; Assembly Library. Must be included first!
8
9
10; Section containing code
11SECTION .text
12
13; Program first instruction.
14CPU 486
15ORG 100h                        ; Code starts at offset 100h (DOS .COM)
16Start:
17    jmp     BusMeasurements_Start
18
19; Include library sources
20%include "AssemblyLibrary.asm"
21
22%macro MOV_TIMING_LOOP 1
23    xor     bx, bx                  ; Offset for memory transfers
24    mov     dx, OFFSET_TO_NEXT_WORD ; Must be at least 32 (Pentium Cache Line size)
25    wbinvd                          ; Flush and invalidate internal cache
26    cli                             ; Disable interrupts
27    START_PRECISE_EVENT_TIMER
28ALIGN 8
29%%ReadNextWord:
30    mov     ax, %1                  ; 2 bytes
31    add     bx, dx                  ; 2 bytes
32    jnc     SHORT %%ReadNextWord    ; 2 bytes
33    STOP_PRECISE_EVENT_TIMER
34    sti
35%endmacro
36
37
38;--------------------------------------------------------------------
39; Program start
40;--------------------------------------------------------------------
41ALIGN JUMP_ALIGN
42BusMeasurements_Start:
43    CALL_DISPLAY_LIBRARY InitializeDisplayContext
44    xor     ax, ax
45    mov     ds, ax
46
47    call    MeasureRegAndMemMovDurationDifferenceToAX
48    call    GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
49    call    GetBusClockRateFromCycleTimeInAX
50    mov     si, g_szBusMeasurements
51    call    PrintBusMeasurements
52
53    call    AssumeVlbCycleTimeToAXfromBusCycleTimeInCX
54    call    GetBusClockRateFromCycleTimeInAX
55    mov     si, g_szVlbAssumption
56    call    PrintBusMeasurements
57
58    ; Exit to DOS
59    mov     ax, 4C00h           ; Exit to DOS
60    int     21h
61
62
63
64;--------------------------------------------------------------------
65; MeasureRegAndMemMovDurationDifferenceToAX
66;   Parameters:
67;       DS:     Segment for memory read tests
68;   Returns:
69;       AX:     Difference in register and memory access durations
70;               (Precise Event Timer Ticks)
71;   Corrupts registers:
72;       BX, CX, DX
73;--------------------------------------------------------------------
74MeasureRegAndMemMovDurationDifferenceToAX:
75    call    SystemTimer_IntializePreciseEventTimer
76
77    MOV_TIMING_LOOP bx
78    call    SystemTimer_GetPreciseEventTimerTicksToAX
79    xchg    cx, ax      ; Duration now in CX
80
81    MOV_TIMING_LOOP [bx]
82    call    SystemTimer_GetPreciseEventTimerTicksToAX
83    sub     ax, cx      ; AX = Difference in durations
84    sub     ax, cx
85    ret
86
87
88;--------------------------------------------------------------------
89; We must divide the duration by 4 since the timing loop loads
90; whole cache line (4 times the bus width) instead of single BYTE.
91;
92; GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
93;   Parameters:
94;       AX:     Difference in register and memory access durations
95;               (Precise Event Timer Ticks) 
96;   Returns:
97;       AX:     Duration for single BYTE in nanosecs
98;   Corrupts registers:
99;       CX, DX
100;--------------------------------------------------------------------
101GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX:
102    mov     dx, TIMER_CYCLE_TIME
103    mul     dx          ; DX:AX = Duration in nanosecs
104    mov     cx, (65536 / OFFSET_TO_NEXT_WORD) * 4
105    div     cx          ; AX = Duration for single BYTE in nanosecs
106    ret
107
108
109;--------------------------------------------------------------------
110; GetBusClockRateFromCycleTimeInAX
111;   Parameters:
112;       AX:     Bus Cycle Time in nanosecs
113;   Returns:
114;       CX:     Bus Cycle Time in nanosecs
115;       DX:     Bus Clock Rate (MHz)
116;       AX:     Clock Rate tenths
117;   Corrupts registers:
118;       Nothing
119;--------------------------------------------------------------------
120GetBusClockRateFromCycleTimeInAX:
121    xchg    cx, ax
122    xor     dx, dx
123    mov     ax, 1000
124    div     cl          ; AL = MHz, AH = Remainder
125    xchg    al, dl      ; DX = Bus Clock Rate, AL = 0
126    aad                 ; AX = 10 * AH (+AL)
127    div     cl
128    xor     ah, ah      ; AX = Tenths
129    ret
130
131
132;--------------------------------------------------------------------
133; AssumeVlbCycleTimeToAXfromBusCycleTimeInCX
134;   Parameters:
135;       CX:     Bus Cycle Time in nanosecs
136;   Returns:
137;       AX:     Assumed VLB Cycle Time in nanosecs
138;   Corrupts registers:
139;       Nothing
140;--------------------------------------------------------------------
141AssumeVlbCycleTimeToAXfromBusCycleTimeInCX:
142    mov     ax, cx
143    cmp     al, 24      ; 25 = 40 MHz
144    jb      SHORT .AssumePentiumSoDivideBy2
145    ret
146.AssumePentiumSoDivideBy2:
147    shr     ax, 1
148    ret
149
150
151;--------------------------------------------------------------------
152; PrintBusMeasurements
153;   Parameters:
154;       CX:     Bus Cycle Time in nanosecs
155;       DX:     Bus Clock Rate (MHz)
156;       AX:     Clock Rate tenths
157;       SI:     Offset to string to format
158;   Returns:
159;       Nothing
160;   Corrupts registers:
161;       AX, DX, BP
162;--------------------------------------------------------------------
163PrintBusMeasurements:
164    mov     bp, sp
165    push    cx
166    push    dx
167    push    ax
168    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
169    ret
170
171
172
173; Section containing initialized data
174SECTION .data
175
176OFFSET_TO_NEXT_WORD     EQU 32  ; Must be at least 32 (Pentium Cache Line size)
177
178g_szBusMeasurements:
179    db  "Detected bus cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
180g_szVlbAssumption:
181    db  "Assuming VLB (if exists) cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL
182g_szDashForZero:        db      "- ",NULL
183
184
185
186; Section containing uninitialized data
187SECTION .bss
Note: See TracBrowser for help on using the repository browser.