1 | ; $Id: support.asm 56292 2015-06-09 14:20:46Z 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 | ifndef VBOX_PC_BIOS
|
---|
25 | public __I4D
|
---|
26 | public __I4M
|
---|
27 | endif
|
---|
28 | public _fmemset_
|
---|
29 | public _fmemcpy_
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | .386p
|
---|
34 |
|
---|
35 | _TEXT segment public 'CODE' use16
|
---|
36 | assume cs:_TEXT
|
---|
37 |
|
---|
38 |
|
---|
39 | ;;
|
---|
40 | ; 32-bit unsigned division.
|
---|
41 | ;
|
---|
42 | ; @param dx:ax Dividend.
|
---|
43 | ; @param cx:bx Divisor.
|
---|
44 | ; @returns dx:ax Quotient.
|
---|
45 | ; cx:bx Reminder.
|
---|
46 | ;
|
---|
47 | __U4D:
|
---|
48 | pushf
|
---|
49 | push eax
|
---|
50 | push edx
|
---|
51 | push ecx
|
---|
52 |
|
---|
53 | rol eax, 16
|
---|
54 | mov ax, dx
|
---|
55 | ror eax, 16
|
---|
56 | xor edx, edx
|
---|
57 |
|
---|
58 | shr ecx, 16
|
---|
59 | mov cx, bx
|
---|
60 |
|
---|
61 | div ecx ; eax:edx / ecx -> eax=quotient, edx=reminder.
|
---|
62 |
|
---|
63 | mov bx, dx
|
---|
64 | pop ecx
|
---|
65 | shr edx, 16
|
---|
66 | mov cx, dx
|
---|
67 |
|
---|
68 | pop edx
|
---|
69 | ror eax, 16
|
---|
70 | mov dx, ax
|
---|
71 | add sp, 2
|
---|
72 | pop ax
|
---|
73 | rol eax, 16
|
---|
74 |
|
---|
75 | popf
|
---|
76 | ret
|
---|
77 |
|
---|
78 |
|
---|
79 | ifndef VBOX_PC_BIOS
|
---|
80 | ;;
|
---|
81 | ; 32-bit signed division.
|
---|
82 | ;
|
---|
83 | ; @param dx:ax Dividend.
|
---|
84 | ; @param cx:bx Divisor.
|
---|
85 | ; @returns dx:ax Quotient.
|
---|
86 | ; cx:bx Reminder.
|
---|
87 | ;
|
---|
88 | __I4D:
|
---|
89 | pushf
|
---|
90 | push eax
|
---|
91 | push edx
|
---|
92 | push ecx
|
---|
93 |
|
---|
94 | rol eax, 16
|
---|
95 | mov ax, dx
|
---|
96 | ror eax, 16
|
---|
97 | xor edx, edx
|
---|
98 |
|
---|
99 | shr ecx, 16
|
---|
100 | mov cx, bx
|
---|
101 |
|
---|
102 | idiv ecx ; eax:edx / ecx -> eax=quotient, edx=reminder.
|
---|
103 |
|
---|
104 | mov bx, dx
|
---|
105 | pop ecx
|
---|
106 | shr edx, 16
|
---|
107 | mov cx, dx
|
---|
108 |
|
---|
109 | pop edx
|
---|
110 | ror eax, 16
|
---|
111 | mov dx, ax
|
---|
112 | add sp, 2
|
---|
113 | pop ax
|
---|
114 | rol eax, 16
|
---|
115 |
|
---|
116 | popf
|
---|
117 | ret
|
---|
118 | endif ; VBOX_PC_BIOS
|
---|
119 |
|
---|
120 |
|
---|
121 | ;;
|
---|
122 | ; 32-bit unsigned multiplication.
|
---|
123 | ;
|
---|
124 | ; @param dx:ax Factor 1.
|
---|
125 | ; @param cx:bx Factor 2.
|
---|
126 | ; @returns dx:ax Result.
|
---|
127 | ;
|
---|
128 | __U4M:
|
---|
129 | pushf
|
---|
130 | push eax
|
---|
131 | push edx
|
---|
132 | push ecx
|
---|
133 |
|
---|
134 | rol eax, 16
|
---|
135 | mov ax, dx
|
---|
136 | ror eax, 16
|
---|
137 | xor edx, edx
|
---|
138 |
|
---|
139 | shr ecx, 16
|
---|
140 | mov cx, bx
|
---|
141 |
|
---|
142 | mul ecx ; eax * ecx -> edx:eax
|
---|
143 |
|
---|
144 | pop ecx
|
---|
145 |
|
---|
146 | pop edx
|
---|
147 | ror eax, 16
|
---|
148 | mov dx, ax
|
---|
149 | add sp, 2
|
---|
150 | pop ax
|
---|
151 | rol eax, 16
|
---|
152 |
|
---|
153 | popf
|
---|
154 | ret
|
---|
155 |
|
---|
156 |
|
---|
157 | ifndef VBOX_PC_BIOS
|
---|
158 | ;;
|
---|
159 | ; 32-bit unsigned multiplication.
|
---|
160 | ; memset taking a far pointer.
|
---|
161 | ;
|
---|
162 | ; @param dx:ax Factor 1.
|
---|
163 | ; @param cx:bx Factor 2.
|
---|
164 | ; @returns dx:ax Result.
|
---|
165 | ; cx, es may be modified; di is preserved
|
---|
166 | ;
|
---|
167 | __I4M:
|
---|
168 | pushf
|
---|
169 | push eax
|
---|
170 | push edx
|
---|
171 | push ecx
|
---|
172 | push ebx
|
---|
173 |
|
---|
174 | rol eax, 16
|
---|
175 | mov ax, dx
|
---|
176 | ror eax, 16
|
---|
177 | xor edx, edx
|
---|
178 |
|
---|
179 | shr ecx, 16
|
---|
180 | mov cx, bx
|
---|
181 |
|
---|
182 | imul ecx ; eax * ecx -> edx:eax
|
---|
183 |
|
---|
184 | pop ebx
|
---|
185 | pop ecx
|
---|
186 |
|
---|
187 | pop edx
|
---|
188 | ror eax, 16
|
---|
189 | mov dx, ax
|
---|
190 | add sp, 2
|
---|
191 | pop ax
|
---|
192 | rol eax, 16
|
---|
193 |
|
---|
194 | popf
|
---|
195 | ret
|
---|
196 | endif ; VBOX_PC_BIOS
|
---|
197 |
|
---|
198 |
|
---|
199 | ;;
|
---|
200 | ; memset taking a far pointer.
|
---|
201 | ;
|
---|
202 | ; cx, es may be modified; di is preserved
|
---|
203 | ;
|
---|
204 | ; @returns dx:ax unchanged.
|
---|
205 | ; @param dx:ax Pointer to the memory.
|
---|
206 | ; @param bl The fill value.
|
---|
207 | ; @param cx The number of bytes to fill.
|
---|
208 | ;
|
---|
209 | _fmemset_:
|
---|
210 | push di
|
---|
211 |
|
---|
212 | mov es, dx
|
---|
213 | mov di, ax
|
---|
214 | xchg al, bl
|
---|
215 | rep stosb
|
---|
216 | xchg al, bl
|
---|
217 |
|
---|
218 | pop di
|
---|
219 | ret
|
---|
220 |
|
---|
221 |
|
---|
222 | ;;
|
---|
223 | ; memset taking far pointers.
|
---|
224 | ;
|
---|
225 | ; cx, es may be modified; si, di are preserved
|
---|
226 | ;
|
---|
227 | ; @returns dx:ax unchanged.
|
---|
228 | ; @param dx:ax Pointer to the destination memory.
|
---|
229 | ; @param cx:bx Pointer to the source memory.
|
---|
230 | ; @param sp+2 The number of bytes to copy (dw).
|
---|
231 | ;
|
---|
232 | _fmemcpy_:
|
---|
233 | push bp
|
---|
234 | mov bp, sp
|
---|
235 | push di
|
---|
236 | push ds
|
---|
237 | push si
|
---|
238 |
|
---|
239 | mov es, dx
|
---|
240 | mov di, ax
|
---|
241 | mov ds, cx
|
---|
242 | mov si, bx
|
---|
243 | mov cx, [bp + 4]
|
---|
244 | rep movsb
|
---|
245 |
|
---|
246 | pop si
|
---|
247 | pop ds
|
---|
248 | pop di
|
---|
249 | leave
|
---|
250 | ret
|
---|
251 |
|
---|
252 |
|
---|
253 | _TEXT ends
|
---|
254 | end
|
---|
255 |
|
---|