Changeset 287 in xtideuniversalbios for trunk/Assembly_Library/Src
- Timestamp:
- Mar 2, 2012, 12:31:39 PM (13 years ago)
- google:author:
- aitotat@gmail.com
- Location:
- trunk/Assembly_Library/Src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Assembly_Library/Src/Display/DisplayContext.asm
r201 r287 17 17 DisplayContext_Initialize: 18 18 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT 19 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], CURSOR_NORMAL20 19 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE 20 mov ax, [VIDEO_BDA.wCursorShape] 21 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax 21 22 ; Fall to .DetectAndSetDisplaySegment 22 23 -
trunk/Assembly_Library/Src/Time/SystemTimer.asm
r256 r287 29 29 ; 2. Use START_PRECISE_EVENT_TIMER macro to start timer 30 30 ; 3. Use STOP_PRECISE_EVENT_TIMER to stop timer (optional) 31 ; 4. Call SystemTimer_ ReadNanosecsToDXAXfromPreciseEventTimerto get event duration31 ; 4. Call SystemTimer_GetPreciseEventTimerTicksToAX to get event duration 32 32 ; 33 ; SystemTimer_ ReadNanosecsToDXAXfromPreciseEventTimer33 ; SystemTimer_GetPreciseEventTimerTicksToAX 34 34 ; Parameters: 35 35 ; Nothing 36 36 ; Returns: 37 ; DX:AX: Event duration in nanosecs37 ; AX: Event duration in timer ticks 38 38 ; Corrupts registers: 39 39 ; Nothing 40 40 ;-------------------------------------------------------------------- 41 41 ALIGN JUMP_ALIGN 42 SystemTimer_ ReadNanosecsToDXAXfromPreciseEventTimer:42 SystemTimer_GetPreciseEventTimerTicksToAX: 43 43 OUTPUT_COUNTER_COMMAND_TO TIMER_2, LATCH, MODE_0_SINGLE_TIMEOUT, BINARY_COUNTER 44 44 READ_COUNT_TO_AX_FROM TIMER_2 45 45 neg ax ; 0 - count (Mode 0 counts toward zero) 46 mov dx, TIMER_CYCLE_TIME47 mul dx48 46 ret -
trunk/Assembly_Library/Src/TimerTest.asm
r256 r287 12 12 13 13 ; Program first instruction. 14 CPU 486 14 15 ORG 100h ; Code starts at offset 100h (DOS .COM) 15 16 Start: 16 jmp TimerTest_Start17 jmp BusMeasurements_Start 17 18 18 19 ; Include library sources 19 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 28 ALIGN 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 20 36 21 37 … … 24 40 ;-------------------------------------------------------------------- 25 41 ALIGN JUMP_ALIGN 26 TimerTest_Start: 42 BusMeasurements_Start: 27 43 CALL_DISPLAY_LIBRARY InitializeDisplayContext 44 xor ax, ax 45 mov ds, ax 28 46 29 call SystemTimer_IntializePreciseEventTimer 47 call MeasureRegAndMemMovDurationDifferenceToAX 48 call GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX 49 call GetBusClockRateFromCycleTimeInAX 50 mov si, g_szBusMeasurements 51 call PrintBusMeasurements 30 52 31 START_PRECISE_EVENT_TIMER 32 mov ax, MICROSECONDS_TO_WAIT 33 call Delay_MicrosecondsFromAX 34 STOP_PRECISE_EVENT_TIMER 35 36 call SystemTimer_ReadNanosecsToDXAXfromPreciseEventTimer 37 call PrintNanosecsFromDXAX 53 call AssumeVlbCycleTimeToAXfromBusCycleTimeInCX 54 call GetBusClockRateFromCycleTimeInAX 55 mov si, g_szVlbAssumption 56 call PrintBusMeasurements 38 57 39 58 ; Exit to DOS … … 42 61 43 62 44 ALIGN JUMP_ALIGN 45 PrintNanosecsFromDXAX: 46 mov cx, 1000 47 div cx ; AX = us waited 48 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 ;-------------------------------------------------------------------- 74 MeasureRegAndMemMovDurationDifferenceToAX: 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 ;-------------------------------------------------------------------- 101 GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX: 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 ;-------------------------------------------------------------------- 120 GetBusClockRateFromCycleTimeInAX: 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 ;-------------------------------------------------------------------- 141 AssumeVlbCycleTimeToAXfromBusCycleTimeInCX: 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 ;-------------------------------------------------------------------- 163 PrintBusMeasurements: 49 164 mov bp, sp 50 ePUSH_T cx, MICROSECONDS_TO_WAIT 165 push cx 166 push dx 51 167 push ax 52 mov si, g_szMicrosecsWaited53 168 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI 54 169 ret … … 59 174 SECTION .data 60 175 61 MICROSECONDS_TO_WAIT EQU 7000 176 OFFSET_TO_NEXT_WORD EQU 32 ; Must be at least 32 (Pentium Cache Line size) 62 177 63 g_szMicrosecsWaited: 64 db "Was supposed to wait %u us but actually waited %u us.",LF,CR,NULL 178 g_szBusMeasurements: 179 db "Detected bus cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL 180 g_szVlbAssumption: 181 db "Assuming VLB (if exists) cycle time of %u ns (%u.%u MHz) ",LF,CR,NULL 65 182 g_szDashForZero: db "- ",NULL 66 183
Note:
See TracChangeset
for help on using the changeset viewer.