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