1 | ; $Id: support.asm 58723 2015-11-17 15:30:27Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Compiler support routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2012-2015 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 |
|
---|
18 |
|
---|
19 | ;*******************************************************************************
|
---|
20 | ;* Exported Symbols *
|
---|
21 | ;*******************************************************************************
|
---|
22 | public __U4D
|
---|
23 | public __U4M
|
---|
24 | public __U8LS
|
---|
25 | public __U8RS
|
---|
26 | ifndef VBOX_PC_BIOS
|
---|
27 | public __I4D
|
---|
28 | public __I4M
|
---|
29 | endif
|
---|
30 | public _fmemset_
|
---|
31 | public _fmemcpy_
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | .386p
|
---|
36 |
|
---|
37 | _TEXT segment public 'CODE' use16
|
---|
38 | assume cs:_TEXT
|
---|
39 |
|
---|
40 |
|
---|
41 | ;;
|
---|
42 | ; 32-bit unsigned division.
|
---|
43 | ;
|
---|
44 | ; @param dx:ax Dividend.
|
---|
45 | ; @param cx:bx Divisor.
|
---|
46 | ; @returns dx:ax Quotient.
|
---|
47 | ; cx:bx Remainder.
|
---|
48 | ;
|
---|
49 | __U4D:
|
---|
50 | pushf
|
---|
51 | push eax
|
---|
52 | push edx
|
---|
53 | push ecx
|
---|
54 |
|
---|
55 | rol eax, 16
|
---|
56 | mov ax, dx
|
---|
57 | ror eax, 16
|
---|
58 | xor edx, edx
|
---|
59 |
|
---|
60 | shr ecx, 16
|
---|
61 | mov cx, bx
|
---|
62 |
|
---|
63 | div ecx ; eax:edx / ecx -> eax=quotient, edx=remainder.
|
---|
64 |
|
---|
65 | mov bx, dx
|
---|
66 | pop ecx
|
---|
67 | shr edx, 16
|
---|
68 | mov cx, dx
|
---|
69 |
|
---|
70 | pop edx
|
---|
71 | ror eax, 16
|
---|
72 | mov dx, ax
|
---|
73 | add sp, 2
|
---|
74 | pop ax
|
---|
75 | rol eax, 16
|
---|
76 |
|
---|
77 | popf
|
---|
78 | ret
|
---|
79 |
|
---|
80 |
|
---|
81 | ifndef VBOX_PC_BIOS
|
---|
82 | ;;
|
---|
83 | ; 32-bit signed division.
|
---|
84 | ;
|
---|
85 | ; @param dx:ax Dividend.
|
---|
86 | ; @param cx:bx Divisor.
|
---|
87 | ; @returns dx:ax Quotient.
|
---|
88 | ; cx:bx Remainder.
|
---|
89 | ;
|
---|
90 | __I4D:
|
---|
91 | pushf
|
---|
92 | push eax
|
---|
93 | push edx
|
---|
94 | push ecx
|
---|
95 |
|
---|
96 | rol eax, 16
|
---|
97 | mov ax, dx
|
---|
98 | ror eax, 16
|
---|
99 | xor edx, edx
|
---|
100 |
|
---|
101 | shr ecx, 16
|
---|
102 | mov cx, bx
|
---|
103 |
|
---|
104 | idiv ecx ; eax:edx / ecx -> eax=quotient, edx=remainder.
|
---|
105 |
|
---|
106 | mov bx, dx
|
---|
107 | pop ecx
|
---|
108 | shr edx, 16
|
---|
109 | mov cx, dx
|
---|
110 |
|
---|
111 | pop edx
|
---|
112 | ror eax, 16
|
---|
113 | mov dx, ax
|
---|
114 | add sp, 2
|
---|
115 | pop ax
|
---|
116 | rol eax, 16
|
---|
117 |
|
---|
118 | popf
|
---|
119 | ret
|
---|
120 | endif ; VBOX_PC_BIOS
|
---|
121 |
|
---|
122 |
|
---|
123 | ;;
|
---|
124 | ; 32-bit unsigned multiplication.
|
---|
125 | ;
|
---|
126 | ; @param dx:ax Factor 1.
|
---|
127 | ; @param cx:bx Factor 2.
|
---|
128 | ; @returns dx:ax Result.
|
---|
129 | ;
|
---|
130 | __U4M:
|
---|
131 | pushf
|
---|
132 | push eax
|
---|
133 | push edx
|
---|
134 | push ecx
|
---|
135 |
|
---|
136 | rol eax, 16
|
---|
137 | mov ax, dx
|
---|
138 | ror eax, 16
|
---|
139 | xor edx, edx
|
---|
140 |
|
---|
141 | shr ecx, 16
|
---|
142 | mov cx, bx
|
---|
143 |
|
---|
144 | mul ecx ; eax * ecx -> edx:eax
|
---|
145 |
|
---|
146 | pop ecx
|
---|
147 |
|
---|
148 | pop edx
|
---|
149 | ror eax, 16
|
---|
150 | mov dx, ax
|
---|
151 | add sp, 2
|
---|
152 | pop ax
|
---|
153 | rol eax, 16
|
---|
154 |
|
---|
155 | popf
|
---|
156 | ret
|
---|
157 |
|
---|
158 |
|
---|
159 | ifndef VBOX_PC_BIOS
|
---|
160 | ;;
|
---|
161 | ; 32-bit signed multiplication.
|
---|
162 | ;
|
---|
163 | ; @param dx:ax Factor 1.
|
---|
164 | ; @param cx:bx Factor 2.
|
---|
165 | ; @returns dx:ax Result.
|
---|
166 | ; cx, es may be modified; di is preserved
|
---|
167 | ;
|
---|
168 | __I4M:
|
---|
169 | pushf
|
---|
170 | push eax
|
---|
171 | push edx
|
---|
172 | push ecx
|
---|
173 | push ebx
|
---|
174 |
|
---|
175 | rol eax, 16
|
---|
176 | mov ax, dx
|
---|
177 | ror eax, 16
|
---|
178 | xor edx, edx
|
---|
179 |
|
---|
180 | shr ecx, 16
|
---|
181 | mov cx, bx
|
---|
182 |
|
---|
183 | imul ecx ; eax * ecx -> edx:eax
|
---|
184 |
|
---|
185 | pop ebx
|
---|
186 | pop ecx
|
---|
187 |
|
---|
188 | pop edx
|
---|
189 | ror eax, 16
|
---|
190 | mov dx, ax
|
---|
191 | add sp, 2
|
---|
192 | pop ax
|
---|
193 | rol eax, 16
|
---|
194 |
|
---|
195 | popf
|
---|
196 | ret
|
---|
197 | endif ; VBOX_PC_BIOS
|
---|
198 |
|
---|
199 |
|
---|
200 | ;;
|
---|
201 | ; 64-bit left shift.
|
---|
202 | ;
|
---|
203 | ; @param ax:bx:cx:dx Value.
|
---|
204 | ; @param si Shift count.
|
---|
205 | ; @returns ax:bx:cx:dx Shifted value.
|
---|
206 | ; si is zeroed
|
---|
207 | ;
|
---|
208 | __U8LS:
|
---|
209 |
|
---|
210 | test si, si
|
---|
211 | jz u8ls_quit
|
---|
212 | u8ls_rot:
|
---|
213 | shl dx, 1
|
---|
214 | rcl cx, 1
|
---|
215 | rcl bx, 1
|
---|
216 | rcl ax, 1
|
---|
217 | dec si
|
---|
218 | jnz u8ls_rot
|
---|
219 | u8ls_quit:
|
---|
220 | ret
|
---|
221 |
|
---|
222 |
|
---|
223 | ;;
|
---|
224 | ; 64-bit unsigned right shift.
|
---|
225 | ;
|
---|
226 | ; @param ax:bx:cx:dx Value.
|
---|
227 | ; @param si Shift count.
|
---|
228 | ; @returns ax:bx:cx:dx Shifted value.
|
---|
229 | ; si is zeroed
|
---|
230 | ;
|
---|
231 | __U8RS:
|
---|
232 |
|
---|
233 | test si, si
|
---|
234 | jz u8rs_quit
|
---|
235 | u8rs_rot:
|
---|
236 | shr ax, 1
|
---|
237 | rcr bx, 1
|
---|
238 | rcr cx, 1
|
---|
239 | rcr dx, 1
|
---|
240 | dec si
|
---|
241 | jnz u8rs_rot
|
---|
242 | u8rs_quit:
|
---|
243 | ret
|
---|
244 |
|
---|
245 |
|
---|
246 | ;;
|
---|
247 | ; memset taking a far pointer.
|
---|
248 | ;
|
---|
249 | ; cx, es may be modified; di is preserved
|
---|
250 | ;
|
---|
251 | ; @returns dx:ax unchanged.
|
---|
252 | ; @param dx:ax Pointer to the memory.
|
---|
253 | ; @param bl The fill value.
|
---|
254 | ; @param cx The number of bytes to fill.
|
---|
255 | ;
|
---|
256 | _fmemset_:
|
---|
257 | push di
|
---|
258 |
|
---|
259 | mov es, dx
|
---|
260 | mov di, ax
|
---|
261 | xchg al, bl
|
---|
262 | rep stosb
|
---|
263 | xchg al, bl
|
---|
264 |
|
---|
265 | pop di
|
---|
266 | ret
|
---|
267 |
|
---|
268 |
|
---|
269 | ;;
|
---|
270 | ; memcpy taking far pointers.
|
---|
271 | ;
|
---|
272 | ; cx, es may be modified; si, di are preserved
|
---|
273 | ;
|
---|
274 | ; @returns dx:ax unchanged.
|
---|
275 | ; @param dx:ax Pointer to the destination memory.
|
---|
276 | ; @param cx:bx Pointer to the source memory.
|
---|
277 | ; @param sp+2 The number of bytes to copy (dw).
|
---|
278 | ;
|
---|
279 | _fmemcpy_:
|
---|
280 | push bp
|
---|
281 | mov bp, sp
|
---|
282 | push di
|
---|
283 | push ds
|
---|
284 | push si
|
---|
285 |
|
---|
286 | mov es, dx
|
---|
287 | mov di, ax
|
---|
288 | mov ds, cx
|
---|
289 | mov si, bx
|
---|
290 | mov cx, [bp + 4]
|
---|
291 | rep movsb
|
---|
292 |
|
---|
293 | pop si
|
---|
294 | pop ds
|
---|
295 | pop di
|
---|
296 | leave
|
---|
297 | ret
|
---|
298 |
|
---|
299 |
|
---|
300 | _TEXT ends
|
---|
301 | end
|
---|
302 |
|
---|