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