Ignore:
Timestamp:
Feb 19, 2000, 9:40:31 AM (26 years ago)
Author:
bird
Message:

g_tkExecPgm is overloaded, so we may change paramerters for a process later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/misc/buffer.asm

    r2823 r2827  
    1 ; $Id: buffer.asm,v 1.2 2000-02-18 19:27:31 bird Exp $
     1; $Id: buffer.asm,v 1.3 2000-02-19 08:40:31 bird Exp $
    22;
    33; Simple resident buffer for use when overloading tkExecPgm.
     
    88;
    99    .486p
     10
     11
     12;
     13;   Defined Constants And Macros
     14;
     15NBR_BUFFERS     EQU 20
     16BUFFER_SIZE     EQU 1536
    1017
    1118;
     
    2027    public ReleaseBuffer
    2128    public QueryBufferSegmentOffset
    22 ;    public cbBuffer
     29    public QueryBufferPointerFromFilename
     30
     31
     32;
     33;   Imported Functions
     34;
     35    extrn stricmp:PROC
    2336
    2437
     
    2740;
    2841DATA16 SEGMENT
    29 ;DATA32 SEGMENT
    30 achBuffer   db 4096 dup(?)
     42aachBuffer  db BUFFER_SIZE*NBR_BUFFERS dup(?) ; The buffer
    3143DATA16 ENDS
    32 ;DATA32 ENDS
    33 
    34 ;DATA16 SEGMENT
     44
    3545DATA32 SEGMENT
    36 fBuffer     db 0            ;Access "semaphore"
     46afBuffer    db NBR_BUFFERS dup(0)       ; Access "semaphore"
     47                                        ; 0 - not in use
     48                                        ; 1 - in use
    3749DATA32 ENDS
    3850
     
    4658; @returns   Pointer to buffer
    4759; @uses      eax
    48 ; @sketch    if fBuffer == 0 then
     60; @sketch    if AfBuffer == 0 then
    4961;               ok!
    5062;               fBuffer <- 1
     
    5971AcquireBuffer PROC NEAR
    6072    push    ds
    61     ;mov     ax,
    62 ;    push    FLAT
    63     pop     ds
    64     ;mov     ds, ax
     73    push    ecx
     74    push    edx
     75
     76    ; make ds flat
     77    mov     ax, seg FLAT:DATA32
     78    mov     ds, ax
    6579    ASSUME  DS:FLAT
    66     mov     al, 0
    67     mov     ah, 1
    68     lock cmpxchg fBuffer, ah
    69     jnz     AcquireBuffer_nok
    70 AcquireBuffer_ok:
    71     mov     eax, offset achBuffer
    72     pop     ds
    73     ret
     80
     81    ; loop thru all buffers and try reserve one
     82    mov     ah, 1                       ; afBuffer[ecx] is set to this value (if equal to al)
     83    mov     ecx, NBR_BUFFERS            ; interations.
     84    mov     edx, offset FLAT:afBuffer
     85    add     edx, ecx
     86AcquireBuffer_loop:
     87    dec     edx
     88    mov     al, 0                       ; afBuffer[ecx] should have this value
     89    lock cmpxchg [edx], ah
     90    je      AcquireBuffer_ok
     91    loop    AcquireBuffer_loop
     92
     93    ; failure
    7494AcquireBuffer_nok:
    7595    xor     eax,eax
     96    jmp     AcquireBuffer_ret
     97
     98    ;success - calc buffer pointer
     99AcquireBuffer_ok:
     100    mov     eax, BUFFER_SIZE
     101    dec     ecx
     102    imul    eax, ecx                    ; ecx has the buffer number
     103    add     eax, offset FLAT:aachBuffer
     104AcquireBuffer_ret:
     105    pop     edx
     106    pop     ecx
    76107    pop     ds
    77108    ret
     
    85116; @uses      eax
    86117; @equiv
    87 ; @sketch    if eax == achBuffer then
    88 ;                set fBuffer to 0 if 1.
    89 ;                if fBuffer was not 1 then fail with rc = 87!
    90 ;            else
    91 ;                fail with rc = 87
    92 ;            endif
    93118; @status
    94119; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     
    97122    ASSUME  DS:NOTHING
    98123    push    ds
    99 ;    mov     ax, DATA16
    100 ;    mov     ds, ax
    101 ;    push    FLAT
    102     pop     ds
     124    push    ecx
     125    push    edx
     126
     127    ; make ds flat
     128    push    eax
     129    mov     ax, seg FLAT:DATA32
     130    mov     ds, ax
    103131    ASSUME  DS:FLAT
    104     cmp     eax, offset achBuffer
    105     jne     ReleaseBuffer_nok
     132    pop     eax
     133    push    eax
     134
     135    ; validate input and calc buffer number
     136    cmp     eax, offset FLAT:aachBuffer
     137    jl      ReleaseBuffer_nok           ; if eax (buffer pointer) is less than the first buffer, then fail.
     138    sub     eax, offset FLAT:aachBuffer ; eax <- offset to buffer from aachBuffer
     139    xor     edx, edx
     140    mov     ecx, BUFFER_SIZE
     141    div     ecx                         ; eax <- buffer number, edx <- offset into buffer (should be NULL)
     142    or      edx, edx
     143    jnz     ReleaseBuffer_nok           ; if offset into buffer not 0 the fail.
     144    cmp     eax, NBR_BUFFERS
     145    jge     ReleaseBuffer_nok           ; if buffernumber >= number of buffers then fail.
     146
     147    ; unlock buffer - if locked
     148    mov     edx, eax
     149    add     edx, offset FLAT:afBuffer   ; ds:edx  points at buffer "semaphore"
    106150    mov     al, 1
    107151    mov     ah, 0
    108     lock cmpxchg fBuffer, ah
    109     jnz     ReleaseBuffer_nok
     152    lock cmpxchg [edx], ah
     153    jne     ReleaseBuffer_nok           ; fail if buffer was not locked
     154
    110155ReleaseBuffer_ok:
    111     xor     eax, eax
    112     pop     ds
    113     ret
     156    ;swipe out buffer
     157    pop     eax
     158    push    edi
     159    push    es
     160    mov     edi, eax
     161    mov     ax, ds
     162    mov     es, ax
     163    ASSUME  es:FLAT
     164    xor     eax, eax                    ; ecx is allready BUFFER_SIZE
     165    rep     stosb
     166    pop     es
     167    pop     edi
     168
     169    ;return successfully
     170    jmp     ReleaseBuffer_ret
     171
    114172ReleaseBuffer_nok:
     173    ;failure
     174    pop     eax
    115175    mov     eax, 87 ;some error
     176
     177ReleaseBuffer_ret:
     178    pop     edx
     179    pop     ecx
    116180    pop     ds
    117181    ret
     
    132196    ASSUME  DS:NOTHING
    133197    push    ds
    134 ;    mov     ax, DATA16
    135 ;    mov     ds, ax
    136 ;    push    FLAT
    137     pop     ds
     198
     199    ; make ds FLAT
     200    push    eax
     201    mov     ax, seg FLAT:DATA32
     202    mov     ds, ax
    138203    ASSUME  DS:FLAT
    139     cmp     eax, offset achBuffer
    140     jne     QueryBufferSegmentOffset_nok
    141     cmp     fBuffer, 1
    142     jne     QueryBufferSegmentOffset_nok
     204    pop     eax
     205
     206    ; validate parameter and calc offset relative to aachBuffer
     207    cmp     eax, offset FLAT:aachBuffer
     208    jl      QueryBufferSegmentOffset_nok
     209    sub     eax, offset FLAT:aachBuffer
     210    cmp     eax, NBR_BUFFERS * BUFFER_SIZE
     211    jge     QueryBufferSegmentOffset_nok
    143212
    144213QueryBufferSegmentOffset_ok:
    145     xor     eax, eax
    146214    jmp     far ptr CODE16:GetBufferSegmentOffset16
    147215QueryBufferSegmentOffset_Back::
     
    156224
    157225
     226;;
     227; Special function which checks all used buffers for the string passed in in eax.
     228; @cproto    PCHAR _Optlink QueryBufferPointerFromFilename(const char *pszFilename)
     229; @returns   Pointer to Buffer. NULL on error/notfound.
     230; @param     ds:eax   Pointer to filename. The filename will later be compared to the string at buffer start.
     231;                     Currently this parameter is not used, since there is only one buffer.
     232; @uses      eax.
     233; @sketch
     234; @status    completely implemented
     235; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     236; @remark    assumes ds flat on call.
     237QueryBufferPointerFromFilename PROC NEAR
     238    ASSUME  cs:CODE32, ds:FLAT
     239    push    ecx
     240    push    edx
     241    push    ebx
     242
     243    ; loop thru all buffers until found or non left
     244    mov     ecx, NBR_BUFFERS
     245    mov     edx, BUFFER_SIZE
     246    imul    edx, ecx                    ; edx <- sizeof(aachBuffer)
     247    add     edx, offset FLAT:aachBuffer ; edx points at the first byte after the buffers.
     248    mov     ebx, offset FLAT:afBuffer
     249    add     ebx, ecx                    ; edx points at the first byte after the "semaphore" array (afBuffer).
     250QueryBufferPointerFromFilename_loop:
     251    sub     edx, BUFFER_SIZE            ; edx points at the buffer being concidered.
     252    dec     ebx                         ; ebx points at the "semaphore" for the buffer being concidered.
     253    cmp     byte ptr [edx], 1           ; Is buffer in use?
     254    jne     QueryBufferPointerFromFilename_next
     255
     256    ; buffer is active - lets compare
     257    push    eax
     258    push    ecx
     259    push    edx
     260    call    stricmp
     261    pop     edx
     262    pop     ecx
     263    or      eax, eax
     264    jz      QueryBufferPointerFromFilename_found
     265    pop     eax
     266
     267QueryBufferPointerFromFilename_next:
     268    loop QueryBufferPointerFromFilename_loop
     269    ; when we exit this loop we have failed!
     270
     271QueryBufferPointerFromFilename_nok:
     272    ; The buffer was not found, return NULL pointer.
     273    xor     eax, eax
     274    pop     edx
     275    pop     ecx
     276    ret
     277
     278QueryBufferPointerFromFilename_found:
     279    ; The buffer was found, return the pointer to it!
     280    pop     eax
     281    mov     eax, edx
     282    pop     edx
     283    pop     ecx
     284    ret
     285
     286QueryBufferPointerFromFilename ENDP
     287
     288
     289
     290
    158291CODE32 ENDS
    159292
     293
    160294CODE16 SEGMENT
    161 
    162 ;;
    163 ; Gets the segment(->es) and offset(->ax) of the achBuffer.
     295;;
     296; Gets the segment(->es) and offset(+ax -> ax) of the achBuffer.
     297; @param    ax  offset to buffer relative to aachBuffer
    164298; Jumps back to GetBufferOffset32
    165299GetBufferSegmentOffset16:
    166300    ASSUME CS:CODE16, DS:NOTHING
    167     mov     ax, seg achBuffer
     301    push    ax
     302    mov     ax, seg aachBuffer
    168303    mov     es, ax
    169     mov     ax, offset achBuffer
     304    pop     ax
     305    add     ax, offset aachBuffer
    170306    jmp     far ptr FLAT:QueryBufferSegmentOffset_Back
    171307CODE16 ENDS
Note: See TracChangeset for help on using the changeset viewer.