1 | ; Project name : Assembly Library
|
---|
2 | ; Description : Functions for memory access.
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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.
|
---|
12 | ;
|
---|
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
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 | ; Section containing code
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ; OPTIMIZE_STRING_OPERATION
|
---|
25 | ; Parameters
|
---|
26 | ; %1: String instruction without size (only MOVS and STOS is supported)
|
---|
27 | ; CX: Number of BYTEs to operate
|
---|
28 | ; DS:SI: Ptr to source data (for MOVS)
|
---|
29 | ; ES:DI: Ptr to destination
|
---|
30 | ; Returns:
|
---|
31 | ; CF: Cleared
|
---|
32 | ; CX: Zero
|
---|
33 | ; SI, DI: Updated by number of bytes operated
|
---|
34 | ; Corrupts registers:
|
---|
35 | ; Nothing
|
---|
36 | ;--------------------------------------------------------------------
|
---|
37 | %macro OPTIMIZE_STRING_OPERATION 1
|
---|
38 | shr cx, 1
|
---|
39 | rep %1w
|
---|
40 | eRCL_IM cx, 1
|
---|
41 | rep %1b
|
---|
42 | %endmacro
|
---|
43 |
|
---|
44 |
|
---|
45 | ;--------------------------------------------------------------------
|
---|
46 | ; Memory_CopyCXbytesFromDSSItoESDI
|
---|
47 | ; Parameters
|
---|
48 | ; CX: Number of bytes to copy
|
---|
49 | ; DS:SI: Ptr to source data
|
---|
50 | ; ES:DI: Ptr to destination buffer
|
---|
51 | ; Returns:
|
---|
52 | ; CF: Cleared
|
---|
53 | ; SI, DI: Updated by number of bytes copied
|
---|
54 | ; Corrupts registers:
|
---|
55 | ; Nothing
|
---|
56 | ;--------------------------------------------------------------------
|
---|
57 | %ifndef EXCLUDE_FROM_XUB
|
---|
58 | ALIGN JUMP_ALIGN
|
---|
59 | Memory_CopyCXbytesFromDSSItoESDI:
|
---|
60 | push cx
|
---|
61 | OPTIMIZE_STRING_OPERATION movs
|
---|
62 | pop cx
|
---|
63 | ret
|
---|
64 | %endif
|
---|
65 |
|
---|
66 |
|
---|
67 | ;--------------------------------------------------------------------
|
---|
68 | ; Memory_ZeroSSBPwithSizeInCX
|
---|
69 | ; Parameters
|
---|
70 | ; CX: Number of bytes to zero
|
---|
71 | ; SS:BP: Ptr to buffer to zero
|
---|
72 | ; Returns:
|
---|
73 | ; Nothing
|
---|
74 | ; Corrupts registers:
|
---|
75 | ; CX
|
---|
76 | ;--------------------------------------------------------------------
|
---|
77 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
78 | ALIGN JUMP_ALIGN
|
---|
79 | Memory_ZeroSSBPwithSizeInCX:
|
---|
80 | push es
|
---|
81 | push di
|
---|
82 | push ax
|
---|
83 | call Registers_CopySSBPtoESDI
|
---|
84 | call Memory_ZeroESDIwithSizeInCX
|
---|
85 | pop ax
|
---|
86 | pop di
|
---|
87 | pop es
|
---|
88 | ret
|
---|
89 | %endif
|
---|
90 |
|
---|
91 |
|
---|
92 | ;--------------------------------------------------------------------
|
---|
93 | ; Memory_ZeroESDIwithSizeInCX
|
---|
94 | ; Parameters
|
---|
95 | ; CX: Number of bytes to zero
|
---|
96 | ; ES:DI: Ptr to destination buffer
|
---|
97 | ; Returns:
|
---|
98 | ; DI: Updated by number of BYTEs stored
|
---|
99 | ; Corrupts registers:
|
---|
100 | ; AX, CX
|
---|
101 | ;--------------------------------------------------------------------
|
---|
102 | ALIGN JUMP_ALIGN
|
---|
103 | Memory_ZeroESDIwithSizeInCX:
|
---|
104 | xor ax, ax
|
---|
105 | ; Fall to Memory_StoreCXbytesFromAccumToESDI
|
---|
106 |
|
---|
107 | ;--------------------------------------------------------------------
|
---|
108 | ; Memory_StoreCXbytesFromAccumToESDI
|
---|
109 | ; Parameters
|
---|
110 | ; AX: Word to use to fill buffer
|
---|
111 | ; CX: Number of BYTEs to store
|
---|
112 | ; ES:DI: Ptr to destination buffer
|
---|
113 | ; Returns:
|
---|
114 | ; DI: Updated by number of BYTEs stored
|
---|
115 | ; Corrupts registers:
|
---|
116 | ; CX
|
---|
117 | ;--------------------------------------------------------------------
|
---|
118 | Memory_StoreCXbytesFromAccumToESDI:
|
---|
119 | OPTIMIZE_STRING_OPERATION stos
|
---|
120 | ret
|
---|
121 |
|
---|
122 |
|
---|
123 | ;--------------------------------------------------------------------
|
---|
124 | ; Memory_ReserveCXbytesFromStackToDSSI
|
---|
125 | ; Parameters
|
---|
126 | ; CX: Number of bytes to reserve
|
---|
127 | ; Returns:
|
---|
128 | ; DS:SI: Ptr to reserved buffer
|
---|
129 | ; Corrupts registers:
|
---|
130 | ; AX
|
---|
131 | ;--------------------------------------------------------------------
|
---|
132 | %ifndef EXCLUDE_FROM_XUB
|
---|
133 | ALIGN JUMP_ALIGN
|
---|
134 | Memory_ReserveCXbytesFromStackToDSSI:
|
---|
135 | pop ax
|
---|
136 | push ss
|
---|
137 | pop ds
|
---|
138 | sub sp, cx
|
---|
139 | mov si, sp
|
---|
140 | jmp ax
|
---|
141 | %endif
|
---|
142 |
|
---|
143 |
|
---|
144 | ;--------------------------------------------------------------------
|
---|
145 | ; Memory_SumCXbytesFromESSItoAL
|
---|
146 | ; Parameters
|
---|
147 | ; CX: Number of bytes to sum (0=65536)
|
---|
148 | ; ES:SI: Ptr to buffer containing the bytes to sum
|
---|
149 | ; Returns:
|
---|
150 | ; AL: Sum of bytes
|
---|
151 | ; ZF: Set if result is zero
|
---|
152 | ; Cleared if result is non-zero
|
---|
153 | ; Corrupts registers:
|
---|
154 | ; CX
|
---|
155 | ;--------------------------------------------------------------------
|
---|
156 | %ifndef EXCLUDE_FROM_XTIDECFG OR NO_ATAID_VALIDATION
|
---|
157 | ALIGN JUMP_ALIGN
|
---|
158 | Memory_SumCXbytesFromESSItoAL:
|
---|
159 | push si
|
---|
160 | dec si
|
---|
161 | xor al, al
|
---|
162 | ALIGN JUMP_ALIGN
|
---|
163 | .AddNextByteToAL:
|
---|
164 | inc si
|
---|
165 | add al, [es:si]
|
---|
166 | loop .AddNextByteToAL
|
---|
167 | pop si
|
---|
168 | ret
|
---|
169 | %endif
|
---|