[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for memory access.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[445] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[376] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[445] | 12 | ;
|
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[445] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[445] | 18 | ;
|
---|
[376] | 19 |
|
---|
[41] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[46] | 24 | ; OPTIMIZE_STRING_OPERATION
|
---|
[41] | 25 | ; Parameters
|
---|
[46] | 26 | ; %1: Repeat instruction
|
---|
| 27 | ; %2: String instruction without size (for example MOVS and not MOVSB or MOVSW)
|
---|
| 28 | ; CX: Number of BYTEs to operate
|
---|
| 29 | ; DS:SI: Ptr to source data
|
---|
| 30 | ; ES:DI: Ptr to destination
|
---|
[41] | 31 | ; Returns:
|
---|
[46] | 32 | ; SI, DI: Updated by number of bytes operated
|
---|
| 33 | ; Corrupts registers:
|
---|
[41] | 34 | ; Nothing
|
---|
[46] | 35 | ;--------------------------------------------------------------------
|
---|
| 36 | %macro OPTIMIZE_STRING_OPERATION 2
|
---|
| 37 | push cx
|
---|
| 38 |
|
---|
| 39 | shr cx, 1 ; Operate with WORDs for performance
|
---|
[103] | 40 | jz %%HandleRemainingByte
|
---|
[46] | 41 | %1 %2w
|
---|
| 42 | %%HandleRemainingByte:
|
---|
| 43 | jnc SHORT %%OperationCompleted
|
---|
| 44 | %2b
|
---|
| 45 |
|
---|
| 46 | ALIGN JUMP_ALIGN
|
---|
| 47 | %%OperationCompleted:
|
---|
| 48 | pop cx
|
---|
| 49 | %endmacro
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | ;--------------------------------------------------------------------
|
---|
| 53 | ; Memory_CopyCXbytesFromDSSItoESDI
|
---|
| 54 | ; Parameters
|
---|
| 55 | ; CX: Number of bytes to copy
|
---|
| 56 | ; DS:SI: Ptr to source data
|
---|
| 57 | ; ES:DI: Ptr to destination buffer
|
---|
| 58 | ; Returns:
|
---|
| 59 | ; SI, DI: Updated by number of bytes copied
|
---|
[41] | 60 | ; Corrupts registers:
|
---|
[46] | 61 | ; Nothing
|
---|
[41] | 62 | ;--------------------------------------------------------------------
|
---|
[131] | 63 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[41] | 64 | ALIGN JUMP_ALIGN
|
---|
[46] | 65 | Memory_CopyCXbytesFromDSSItoESDI:
|
---|
| 66 | OPTIMIZE_STRING_OPERATION rep, movs
|
---|
| 67 | ret
|
---|
[131] | 68 | %endif
|
---|
[41] | 69 |
|
---|
[46] | 70 |
|
---|
[41] | 71 | ;--------------------------------------------------------------------
|
---|
[46] | 72 | ; Memory_ZeroSSBPwithSizeInCX
|
---|
[41] | 73 | ; Parameters
|
---|
[46] | 74 | ; CX: Number of bytes to zero
|
---|
[41] | 75 | ; SS:BP: Ptr to buffer to zero
|
---|
| 76 | ; Returns:
|
---|
| 77 | ; Nothing
|
---|
| 78 | ; Corrupts registers:
|
---|
| 79 | ; Nothing
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
| 81 | ALIGN JUMP_ALIGN
|
---|
[46] | 82 | Memory_ZeroSSBPwithSizeInCX:
|
---|
[50] | 83 | push es
|
---|
| 84 | push di
|
---|
[41] | 85 | push ax
|
---|
[105] | 86 | call Registers_CopySSBPtoESDI
|
---|
[46] | 87 | call Memory_ZeroESDIwithSizeInCX
|
---|
[41] | 88 | pop ax
|
---|
[50] | 89 | pop di
|
---|
| 90 | pop es
|
---|
[41] | 91 | ret
|
---|
| 92 |
|
---|
| 93 | ;--------------------------------------------------------------------
|
---|
[46] | 94 | ; Memory_ZeroESDIwithSizeInCX
|
---|
[41] | 95 | ; Parameters
|
---|
[46] | 96 | ; CX: Number of bytes to zero
|
---|
| 97 | ; ES:DI: Ptr to destination buffer
|
---|
[41] | 98 | ; Returns:
|
---|
[50] | 99 | ; DI: Updated by number of BYTEs stored
|
---|
[41] | 100 | ; Corrupts registers:
|
---|
| 101 | ; AX
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
| 103 | ALIGN JUMP_ALIGN
|
---|
[46] | 104 | Memory_ZeroESDIwithSizeInCX:
|
---|
[41] | 105 | xor ax, ax
|
---|
[46] | 106 | ; Fall to Memory_StoreCXbytesFromAccumToESDI
|
---|
[41] | 107 |
|
---|
| 108 | ;--------------------------------------------------------------------
|
---|
[46] | 109 | ; Memory_StoreCXbytesFromAccumToESDI
|
---|
[41] | 110 | ; Parameters
|
---|
| 111 | ; AX: Word to use to fill buffer
|
---|
[46] | 112 | ; CX: Number of BYTEs to store
|
---|
| 113 | ; ES:DI: Ptr to destination buffer
|
---|
[41] | 114 | ; Returns:
|
---|
[50] | 115 | ; DI: Updated by number of BYTEs stored
|
---|
[41] | 116 | ; Corrupts registers:
|
---|
| 117 | ; Nothing
|
---|
| 118 | ;--------------------------------------------------------------------
|
---|
| 119 | ALIGN JUMP_ALIGN
|
---|
[46] | 120 | Memory_StoreCXbytesFromAccumToESDI:
|
---|
| 121 | OPTIMIZE_STRING_OPERATION rep, stos
|
---|
[41] | 122 | ret
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | ;--------------------------------------------------------------------
|
---|
| 126 | ; Memory_ReserveCXbytesFromStackToDSSI
|
---|
| 127 | ; Parameters
|
---|
| 128 | ; CX: Number of bytes to reserve
|
---|
| 129 | ; Returns:
|
---|
| 130 | ; DS:SI: Ptr to reserved buffer
|
---|
| 131 | ; Corrupts registers:
|
---|
| 132 | ; AX
|
---|
| 133 | ;--------------------------------------------------------------------
|
---|
[194] | 134 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[41] | 135 | ALIGN JUMP_ALIGN
|
---|
| 136 | Memory_ReserveCXbytesFromStackToDSSI:
|
---|
| 137 | pop ax
|
---|
| 138 | push ss
|
---|
| 139 | pop ds
|
---|
| 140 | sub sp, cx
|
---|
| 141 | mov si, sp
|
---|
| 142 | jmp ax
|
---|
[194] | 143 | %endif
|
---|
[440] | 144 |
|
---|
| 145 |
|
---|
| 146 | ;--------------------------------------------------------------------
|
---|
| 147 | ; Memory_SumCXbytesFromESSItoAL
|
---|
| 148 | ; Parameters
|
---|
| 149 | ; CX: Number of bytes to sum (0=65536)
|
---|
| 150 | ; ES:SI: Ptr to buffer containing the bytes to sum
|
---|
| 151 | ; Returns:
|
---|
| 152 | ; AL: Sum of bytes
|
---|
[445] | 153 | ; ZF: Set if result is zero
|
---|
| 154 | ; Cleared if result is non-zero
|
---|
[440] | 155 | ; Corrupts registers:
|
---|
| 156 | ; CX
|
---|
| 157 | ;--------------------------------------------------------------------
|
---|
[445] | 158 | %ifndef EXCLUDE_FROM_XTIDECFG
|
---|
[440] | 159 | ALIGN JUMP_ALIGN
|
---|
| 160 | Memory_SumCXbytesFromESSItoAL:
|
---|
| 161 | push si
|
---|
[445] | 162 | dec si
|
---|
[440] | 163 | xor al, al
|
---|
| 164 | ALIGN JUMP_ALIGN
|
---|
| 165 | .AddNextByteToAL:
|
---|
[445] | 166 | inc si
|
---|
[440] | 167 | add al, [es:si]
|
---|
| 168 | loop .AddNextByteToAL
|
---|
| 169 | pop si
|
---|
| 170 | ret
|
---|
[445] | 171 | %endif
|
---|