[142] | 1 | ; $Id: memutil.asm 142 2000-04-23 14:55:46Z ktk $
|
---|
| 2 |
|
---|
| 3 | ;/* SCCSID = %W% %E% */
|
---|
| 4 | ;/***************************************************************************
|
---|
| 5 | ; *
|
---|
| 6 | ; Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
| 7 | ; *
|
---|
| 8 | ; The following IBM OS/2 source code is provided to you solely for the *
|
---|
| 9 | ; the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
| 10 | ; You may use this code in accordance with the IBM License Agreement *
|
---|
| 11 | ; provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
| 12 | ; *
|
---|
| 13 | ; ***************************************************************************/
|
---|
| 14 | ;/*@internal %W%
|
---|
| 15 | ; @notes
|
---|
| 16 | ; The Watcom __fmemcpy intrinsic function resolves to a movsw instruction
|
---|
| 17 | ; which requires 4 clock cycles to move 2 bytes of data. the movsd instruction
|
---|
| 18 | ; can move 4 bytes in the same 4 clock cycles. Such a deal !!!!!
|
---|
| 19 | ; Since the compiler won't let us write a pragma aux to implement this
|
---|
| 20 | ; function, we have written it in assembler. There is also a memfill function
|
---|
| 21 | ; that uses the stosd instruction to fill memory with the a value in eax.
|
---|
| 22 | ; This function is used to write "silence" into the audio buffer
|
---|
| 23 | ;
|
---|
| 24 | ; @version %I%
|
---|
| 25 | ; @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
|
---|
| 26 | ; <stack context>.
|
---|
| 27 | ; @history
|
---|
| 28 | ;
|
---|
| 29 | ;
|
---|
| 30 |
|
---|
| 31 | .386
|
---|
| 32 | .seq
|
---|
| 33 |
|
---|
| 34 | _HEADER segment dword public use16 'DATA'
|
---|
| 35 | _HEADER ends
|
---|
| 36 |
|
---|
| 37 | _DATA segment dword public use16 'DATA'
|
---|
| 38 | _DATA ends
|
---|
| 39 |
|
---|
| 40 | CONST segment dword public use16 'DATA'
|
---|
| 41 | CONST ends
|
---|
| 42 |
|
---|
| 43 | CONST2 segment dword public use16 'DATA'
|
---|
| 44 | CONST2 ends
|
---|
| 45 |
|
---|
| 46 | _BSS segment dword public use16 'BSS'
|
---|
| 47 | _BSS ends
|
---|
| 48 |
|
---|
| 49 | _ENDDS segment dword public use16 'ENDDS'
|
---|
| 50 | _ENDDS ends
|
---|
| 51 |
|
---|
| 52 | _INITDATA segment dword public use16 'ENDDS'
|
---|
| 53 | _INITDATA ends
|
---|
| 54 |
|
---|
| 55 | _ENDINITDATA segment dword public use16 'ENDDS'
|
---|
| 56 | _ENDINITDATA ends
|
---|
| 57 |
|
---|
| 58 | _TEXT segment dword public use16 'CODE'
|
---|
| 59 | _TEXT ends
|
---|
| 60 |
|
---|
| 61 | RMCODE segment dword public use16 'CODE'
|
---|
| 62 | RMCODE ends
|
---|
| 63 |
|
---|
| 64 | _ENDCS segment dword public use16 'CODE'
|
---|
| 65 | _ENDCS ends
|
---|
| 66 |
|
---|
| 67 | _INITTEXT segment dword public use16 'CODE'
|
---|
| 68 | _INITTEXT ends
|
---|
| 69 |
|
---|
| 70 | DGROUP group _HEADER, CONST, CONST2, _DATA, _BSS, _ENDDS, _INITDATA, _ENDINITDATA
|
---|
| 71 | CGROUP group _TEXT, RMCODE, _ENDCS, _INITTEXT
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | _TEXT SEGMENT DWORD PUBLIC USE16 'CODE'
|
---|
| 75 | assume cs:cgroup, ds:dgroup
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | ; void cdecl ddmemmov(PVOID pdest, PVOID psrc, USHORT count);
|
---|
| 79 |
|
---|
| 80 | public _ddmemmov
|
---|
| 81 | _ddmemmov proc near
|
---|
| 82 |
|
---|
| 83 | DEST1_LOW equ [bp+4]
|
---|
| 84 | DEST1_HIGH equ [bp+6]
|
---|
| 85 | SRC1_LOW equ [bp+8]
|
---|
| 86 | SRC1_HIGH equ [bp+0ah]
|
---|
| 87 | BUF1_LEN equ [bp+0ch]
|
---|
| 88 |
|
---|
| 89 | ; point to parameters and local variables
|
---|
| 90 | push bp
|
---|
| 91 | mov bp,sp
|
---|
| 92 |
|
---|
| 93 | ; save registers
|
---|
| 94 | push cx
|
---|
| 95 | push bx
|
---|
| 96 | push ds
|
---|
| 97 | push es
|
---|
| 98 | push si
|
---|
| 99 | push di
|
---|
| 100 |
|
---|
| 101 | ; store number of bytes to transfer and calculate number of double words
|
---|
| 102 | ; and set of transfer value
|
---|
| 103 | mov bx,BUF1_LEN
|
---|
| 104 | mov cx,bx
|
---|
| 105 | shr cx,2
|
---|
| 106 |
|
---|
| 107 | ; set size in bytes of object to be allocated
|
---|
| 108 | mov es,DEST1_HIGH
|
---|
| 109 | mov di,DEST1_LOW
|
---|
| 110 |
|
---|
| 111 | ; set up pointers to source buffer
|
---|
| 112 | mov ds,SRC1_HIGH
|
---|
| 113 | mov si,SRC1_LOW
|
---|
| 114 |
|
---|
| 115 | ; set up transfer direction
|
---|
| 116 | cld
|
---|
| 117 |
|
---|
| 118 | ; do the transfer
|
---|
| 119 | rep movsd
|
---|
| 120 |
|
---|
| 121 | ; transfer number of odd bytes
|
---|
| 122 | mov cx,bx
|
---|
| 123 | and cx,03h
|
---|
| 124 | rep movsb
|
---|
| 125 |
|
---|
| 126 | ;set up return value and restore registers
|
---|
| 127 | pop di
|
---|
| 128 | pop si
|
---|
| 129 | pop es
|
---|
| 130 | pop ds
|
---|
| 131 | pop bx
|
---|
| 132 | pop cx
|
---|
| 133 | pop bp
|
---|
| 134 |
|
---|
| 135 | ;done
|
---|
| 136 | ret
|
---|
| 137 | _ddmemmov endp
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | ;VOID memfill(UCHAR *destP, ULONG length, UCHAR value)
|
---|
| 141 | ; This function fills a block of memory with a particular value.
|
---|
| 142 | ; The function receives address of the memory, the length of the memory, and
|
---|
| 143 | ; the fill value as parameters on the stack.
|
---|
| 144 | ; The function does not return a value.
|
---|
| 145 |
|
---|
| 146 | public _ddmemfill
|
---|
| 147 | _ddmemfill proc near
|
---|
| 148 |
|
---|
| 149 | DEST2_LOW equ [bp+4]
|
---|
| 150 | DEST2_HIGH equ [bp+6]
|
---|
| 151 | BUF2_LEN equ [bp+8]
|
---|
| 152 | VALUE2 equ [bp+0ah]
|
---|
| 153 |
|
---|
| 154 | ; point to parameters and local variables
|
---|
| 155 | push bp
|
---|
| 156 | mov bp,sp
|
---|
| 157 |
|
---|
| 158 | ; save registers
|
---|
| 159 | push bx
|
---|
| 160 | push cx
|
---|
| 161 | push es
|
---|
| 162 | push di
|
---|
| 163 |
|
---|
| 164 | ; store number of bytes to transfer and calculate number of double words
|
---|
| 165 | ; and set of transfer value
|
---|
| 166 | mov bx,BUF2_LEN
|
---|
| 167 | mov cx,bx
|
---|
| 168 | shr cx,2
|
---|
| 169 |
|
---|
| 170 | ; set size in bytes of object to be allocated
|
---|
| 171 | mov es,DEST2_HIGH
|
---|
| 172 | mov di,DEST2_LOW
|
---|
| 173 |
|
---|
| 174 | ; set up value
|
---|
| 175 | mov ax,VALUE2
|
---|
| 176 | shl eax,010h
|
---|
| 177 | mov ax,VALUE2
|
---|
| 178 |
|
---|
| 179 | ; set up transfer direction
|
---|
| 180 | cld
|
---|
| 181 |
|
---|
| 182 | ; do the transfer
|
---|
| 183 | rep stosd
|
---|
| 184 |
|
---|
| 185 | ; transfer number of odd bytes
|
---|
| 186 | mov cx,bx
|
---|
| 187 | and cx,03h
|
---|
| 188 | rep stosb
|
---|
| 189 |
|
---|
| 190 | ;set up return value and restore registers
|
---|
| 191 | pop di
|
---|
| 192 | pop es
|
---|
| 193 | pop cx
|
---|
| 194 | pop bx
|
---|
| 195 | pop bp
|
---|
| 196 |
|
---|
| 197 | ;done
|
---|
| 198 | ret
|
---|
| 199 | _ddmemfill endp
|
---|
| 200 |
|
---|
| 201 | _TEXT ENDS
|
---|
| 202 |
|
---|
| 203 | end
|
---|