Changeset 287 in xtideuniversalbios for trunk/Assembly_Library


Ignore:
Timestamp:
Mar 2, 2012, 12:31:39 PM (13 years ago)
Author:
aitotat@…
google:author:
aitotat@gmail.com
Message:

Changes to Assembly Library:

  • Hopefully fixed a problem of wrong sized MDA cursor.
  • Some minor improvements.
Location:
trunk/Assembly_Library
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Assembly_Library/Inc/Delay.inc

    r247 r287  
    2929;   486:         7 cycles for jump + 6 cycles for last comparison
    3030;
     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
    3139; DELAY_WITH_LOOP_INSTRUCTION
    3240;   Parameters
    3341;       CX:     Loop iterations (0 is maximum delay with 65536 iterations)
    3442;   Returns:
     43;       CX:     Zero
     44;   Corrupts registers:
    3545;       Nothing
    36 ;   Corrupts registers:
    37 ;       CX
    3846;--------------------------------------------------------------------
     47%macro DELAY_WITH_LOOP_INSTRUCTION_NA 0
     48%%StartOfLoop:
     49    loop    %%StartOfLoop
     50%endmacro
     51
    3952%macro DELAY_WITH_LOOP_INSTRUCTION 0
     53ALIGN JUMP_ALIGN
    4054%%StartOfLoop:
    4155    loop    %%StartOfLoop
  • trunk/Assembly_Library/Inc/Display.inc

    r186 r287  
    179179
    180180; Cursor shapes
    181 CURSOR_NORMAL               EQU     0607h       ; Two line cursor near or at the bottom of cell
     181CURSOR_NORMAL               EQU     0607h       ; Two line cursor near or at the bottom of cell (not valid for IBM MDA)
    182182CURSOR_HIDDEN               EQU     2000h
    183183
     
    212212
    213213; Non ASCII characters (code page 437)
     214BETA                                        EQU     225
    214215QUOTATION_MARK                              EQU     34
    215216DOUBLE_TOP_RIGHT_CORNER                     EQU     187
  • trunk/Assembly_Library/Inc/Math.inc

    r181 r287  
    6565
    6666;--------------------------------------------------------------------
     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
     79ALIGN JUMP_ALIGN
     80.ShiftNextBit:
     81    shl     ax, 1
     82    rcl     dx, 1
     83    loop    .ShiftNextBit
     84%endmacro
     85
     86
     87;--------------------------------------------------------------------
    6788; SHR_DXAX
    6889;   Parameters:
  • trunk/Assembly_Library/Inc/SystemTimer.inc

    r256 r287  
    3434CONTROL_WORD_REGISTER_out               EQU 43h
    3535
    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.
    3737SPEAKER_CONTROL_REGISTER                EQU 61h
    3838FLG_TIMER_2_OUTPUT_in                   EQU (1<<5)  ; AT+ only
  • trunk/Assembly_Library/Src/Display/DisplayContext.asm

    r201 r287  
    1717DisplayContext_Initialize:
    1818    mov     WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
    19     mov     WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], CURSOR_NORMAL
    2019    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
    2122    ; Fall to .DetectAndSetDisplaySegment
    2223
  • trunk/Assembly_Library/Src/Time/SystemTimer.asm

    r256 r287  
    2929; 2. Use START_PRECISE_EVENT_TIMER macro to start timer
    3030; 3. Use STOP_PRECISE_EVENT_TIMER to stop timer (optional)
    31 ; 4. Call SystemTimer_ReadNanosecsToDXAXfromPreciseEventTimer to get event duration
     31; 4. Call SystemTimer_GetPreciseEventTimerTicksToAX to get event duration
    3232;
    33 ; SystemTimer_ReadNanosecsToDXAXfromPreciseEventTimer
     33; SystemTimer_GetPreciseEventTimerTicksToAX
    3434;   Parameters:
    3535;       Nothing
    3636;   Returns:
    37 ;       DX:AX:  Event duration in nanosecs
     37;       AX:     Event duration in timer ticks
    3838;   Corrupts registers:
    3939;       Nothing
    4040;--------------------------------------------------------------------
    4141ALIGN JUMP_ALIGN
    42 SystemTimer_ReadNanosecsToDXAXfromPreciseEventTimer:
     42SystemTimer_GetPreciseEventTimerTicksToAX:
    4343    OUTPUT_COUNTER_COMMAND_TO TIMER_2, LATCH, MODE_0_SINGLE_TIMEOUT, BINARY_COUNTER
    4444    READ_COUNT_TO_AX_FROM TIMER_2
    4545    neg     ax                  ; 0 - count (Mode 0 counts toward zero)
    46     mov     dx, TIMER_CYCLE_TIME
    47     mul     dx
    4846    ret
  • trunk/Assembly_Library/Src/TimerTest.asm

    r256 r287  
    1212
    1313; Program first instruction.
     14CPU 486
    1415ORG 100h                        ; Code starts at offset 100h (DOS .COM)
    1516Start:
    16     jmp     TimerTest_Start
     17    jmp     BusMeasurements_Start
    1718
    1819; Include library sources
    1920%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
    2036
    2137
     
    2440;--------------------------------------------------------------------
    2541ALIGN JUMP_ALIGN
    26 TimerTest_Start:   
     42BusMeasurements_Start:
    2743    CALL_DISPLAY_LIBRARY InitializeDisplayContext
     44    xor     ax, ax
     45    mov     ds, ax
    2846
    29     call    SystemTimer_IntializePreciseEventTimer
     47    call    MeasureRegAndMemMovDurationDifferenceToAX
     48    call    GetBusCycleTimeToAXfromRegAndMemMovDurationDifferenceInAX
     49    call    GetBusClockRateFromCycleTimeInAX
     50    mov     si, g_szBusMeasurements
     51    call    PrintBusMeasurements
    3052
    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
    3857
    3958    ; Exit to DOS
     
    4261
    4362
    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;--------------------------------------------------------------------
     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:
    49164    mov     bp, sp
    50     ePUSH_T cx, MICROSECONDS_TO_WAIT
     165    push    cx
     166    push    dx
    51167    push    ax
    52     mov     si, g_szMicrosecsWaited
    53168    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
    54169    ret
     
    59174SECTION .data
    60175
    61 MICROSECONDS_TO_WAIT        EQU     7000
     176OFFSET_TO_NEXT_WORD     EQU 32  ; Must be at least 32 (Pentium Cache Line size)
    62177
    63 g_szMicrosecsWaited:
    64     db  "Was supposed to wait %u us but actually waited %u us.",LF,CR,NULL
     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
    65182g_szDashForZero:        db      "- ",NULL
    66183
Note: See TracChangeset for help on using the changeset viewer.