- Timestamp:
- Mar 2, 2012, 12:31:39 PM (13 years ago)
- google:author:
- aitotat@gmail.com
- Location:
- trunk/Assembly_Library
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Assembly_Library/Inc/Delay.inc
r247 r287 29 29 ; 486: 7 cycles for jump + 6 cycles for last comparison 30 30 ; 31 ; LOOP instruction uses two bytes so aligned fetching will require: 32 ; 8088: 8 cycles (two BYTE reads) 33 ; 8086: 4 cycles (one WORD read) 34 ; 286: 2 cycles + wait states (usually 1) 35 ; 386: ? 36 ; 486: Fetched only once to internal cache 37 ; 38 ; DELAY_WITH_LOOP_INSTRUCTION_NA ; No JUMP_ALIGN 31 39 ; DELAY_WITH_LOOP_INSTRUCTION 32 40 ; Parameters 33 41 ; CX: Loop iterations (0 is maximum delay with 65536 iterations) 34 42 ; Returns: 43 ; CX: Zero 44 ; Corrupts registers: 35 45 ; Nothing 36 ; Corrupts registers:37 ; CX38 46 ;-------------------------------------------------------------------- 47 %macro DELAY_WITH_LOOP_INSTRUCTION_NA 0 48 %%StartOfLoop: 49 loop %%StartOfLoop 50 %endmacro 51 39 52 %macro DELAY_WITH_LOOP_INSTRUCTION 0 53 ALIGN JUMP_ALIGN 40 54 %%StartOfLoop: 41 55 loop %%StartOfLoop -
trunk/Assembly_Library/Inc/Display.inc
r186 r287 179 179 180 180 ; Cursor shapes 181 CURSOR_NORMAL EQU 0607h ; Two line cursor near or at the bottom of cell 181 CURSOR_NORMAL EQU 0607h ; Two line cursor near or at the bottom of cell (not valid for IBM MDA) 182 182 CURSOR_HIDDEN EQU 2000h 183 183 … … 212 212 213 213 ; Non ASCII characters (code page 437) 214 BETA EQU 225 214 215 QUOTATION_MARK EQU 34 215 216 DOUBLE_TOP_RIGHT_CORNER EQU 187 -
trunk/Assembly_Library/Inc/Math.inc
r181 r287 65 65 66 66 ;-------------------------------------------------------------------- 67 ; SHL_DXAX 68 ; Parameters: 69 ; %1: Number of bits to shift 70 ; Returns: 71 ; DX:AX Shifted value 72 ; Corrupts registers: 73 ; CX 74 ;-------------------------------------------------------------------- 75 %macro SHL_DXAX 1 76 %ifnidni %1, cx 77 mov cx, %1 78 %endif 79 ALIGN JUMP_ALIGN 80 .ShiftNextBit: 81 shl ax, 1 82 rcl dx, 1 83 loop .ShiftNextBit 84 %endmacro 85 86 87 ;-------------------------------------------------------------------- 67 88 ; SHR_DXAX 68 89 ; Parameters: -
trunk/Assembly_Library/Inc/SystemTimer.inc
r256 r287 34 34 CONTROL_WORD_REGISTER_out EQU 43h 35 35 36 ; Timer 2 is Connected to PC Speaker that can be controller from port 61h.36 ; Timer 2 is connected to PC Speaker that can be controller from port 61h. 37 37 SPEAKER_CONTROL_REGISTER EQU 61h 38 38 FLG_TIMER_2_OUTPUT_in EQU (1<<5) ; AT+ only -
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.