Changeset 2827 for trunk/src/win32k/misc/buffer.asm
- Timestamp:
- Feb 19, 2000, 9:40:31 AM (26 years ago)
- 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 $ 2 2 ; 3 3 ; Simple resident buffer for use when overloading tkExecPgm. … … 8 8 ; 9 9 .486p 10 11 12 ; 13 ; Defined Constants And Macros 14 ; 15 NBR_BUFFERS EQU 20 16 BUFFER_SIZE EQU 1536 10 17 11 18 ; … … 20 27 public ReleaseBuffer 21 28 public QueryBufferSegmentOffset 22 ; public cbBuffer 29 public QueryBufferPointerFromFilename 30 31 32 ; 33 ; Imported Functions 34 ; 35 extrn stricmp:PROC 23 36 24 37 … … 27 40 ; 28 41 DATA16 SEGMENT 29 ;DATA32 SEGMENT 30 achBuffer db 4096 dup(?) 42 aachBuffer db BUFFER_SIZE*NBR_BUFFERS dup(?) ; The buffer 31 43 DATA16 ENDS 32 ;DATA32 ENDS 33 34 ;DATA16 SEGMENT 44 35 45 DATA32 SEGMENT 36 fBuffer db 0 ;Access "semaphore" 46 afBuffer db NBR_BUFFERS dup(0) ; Access "semaphore" 47 ; 0 - not in use 48 ; 1 - in use 37 49 DATA32 ENDS 38 50 … … 46 58 ; @returns Pointer to buffer 47 59 ; @uses eax 48 ; @sketch if fBuffer == 0 then60 ; @sketch if AfBuffer == 0 then 49 61 ; ok! 50 62 ; fBuffer <- 1 … … 59 71 AcquireBuffer PROC NEAR 60 72 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 65 79 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 86 AcquireBuffer_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 74 94 AcquireBuffer_nok: 75 95 xor eax,eax 96 jmp AcquireBuffer_ret 97 98 ;success - calc buffer pointer 99 AcquireBuffer_ok: 100 mov eax, BUFFER_SIZE 101 dec ecx 102 imul eax, ecx ; ecx has the buffer number 103 add eax, offset FLAT:aachBuffer 104 AcquireBuffer_ret: 105 pop edx 106 pop ecx 76 107 pop ds 77 108 ret … … 85 116 ; @uses eax 86 117 ; @equiv 87 ; @sketch if eax == achBuffer then88 ; set fBuffer to 0 if 1.89 ; if fBuffer was not 1 then fail with rc = 87!90 ; else91 ; fail with rc = 8792 ; endif93 118 ; @status 94 119 ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) … … 97 122 ASSUME DS:NOTHING 98 123 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 103 131 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" 106 150 mov al, 1 107 151 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 110 155 ReleaseBuffer_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 114 172 ReleaseBuffer_nok: 173 ;failure 174 pop eax 115 175 mov eax, 87 ;some error 176 177 ReleaseBuffer_ret: 178 pop edx 179 pop ecx 116 180 pop ds 117 181 ret … … 132 196 ASSUME DS:NOTHING 133 197 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 138 203 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 143 212 144 213 QueryBufferSegmentOffset_ok: 145 xor eax, eax146 214 jmp far ptr CODE16:GetBufferSegmentOffset16 147 215 QueryBufferSegmentOffset_Back:: … … 156 224 157 225 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. 237 QueryBufferPointerFromFilename 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). 250 QueryBufferPointerFromFilename_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 267 QueryBufferPointerFromFilename_next: 268 loop QueryBufferPointerFromFilename_loop 269 ; when we exit this loop we have failed! 270 271 QueryBufferPointerFromFilename_nok: 272 ; The buffer was not found, return NULL pointer. 273 xor eax, eax 274 pop edx 275 pop ecx 276 ret 277 278 QueryBufferPointerFromFilename_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 286 QueryBufferPointerFromFilename ENDP 287 288 289 290 158 291 CODE32 ENDS 159 292 293 160 294 CODE16 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 164 298 ; Jumps back to GetBufferOffset32 165 299 GetBufferSegmentOffset16: 166 300 ASSUME CS:CODE16, DS:NOTHING 167 mov ax, seg achBuffer 301 push ax 302 mov ax, seg aachBuffer 168 303 mov es, ax 169 mov ax, offset achBuffer 304 pop ax 305 add ax, offset aachBuffer 170 306 jmp far ptr FLAT:QueryBufferSegmentOffset_Back 171 307 CODE16 ENDS
Note:
See TracChangeset
for help on using the changeset viewer.