1 | ; $Id: bs3-cpu-instr-2-gen-asm.asm 104002 2024-03-22 16:07:19Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - bs3-cpu-instr-2-gen - assembly helpers for test data generator.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2024 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 | ;*********************************************************************************************************************************
|
---|
39 | ;* Header Files *
|
---|
40 | ;*********************************************************************************************************************************
|
---|
41 | %include "iprt/asmdefs.mac"
|
---|
42 | %include "iprt/x86.mac"
|
---|
43 |
|
---|
44 | BEGINCODE
|
---|
45 |
|
---|
46 | %ifdef ASM_CALL64_MSC
|
---|
47 | %define EFLAGS_PARAM_REG r8d
|
---|
48 | %else
|
---|
49 | %define EFLAGS_PARAM_REG edx
|
---|
50 | %endif
|
---|
51 |
|
---|
52 |
|
---|
53 | ;;
|
---|
54 | ; @param 1 instruction
|
---|
55 | ; @param 2 Whether it takes carry in.
|
---|
56 | ; @param 3 Whether it has an 8-bit form.
|
---|
57 | %macro DO_BINARY 3
|
---|
58 |
|
---|
59 | %if %3 != 0
|
---|
60 | BEGINPROC GenU8_ %+ %1
|
---|
61 | %ifdef ASM_CALL64_GCC
|
---|
62 | mov r9, rcx
|
---|
63 | mov r8, rdx
|
---|
64 | mov rdx, rsi
|
---|
65 | mov rcx, rdi
|
---|
66 | %endif
|
---|
67 | %if %2 != 0
|
---|
68 | lahf
|
---|
69 | and ah, 0xfe
|
---|
70 | shl r8d, 8
|
---|
71 | or eax, r8d
|
---|
72 | sahf
|
---|
73 | %endif
|
---|
74 | %1 cl, dl
|
---|
75 | mov [r9], cl
|
---|
76 | pushf
|
---|
77 | pop rax
|
---|
78 | ret
|
---|
79 | ENDPROC GenU8_ %+ %1
|
---|
80 | %endif
|
---|
81 |
|
---|
82 | BEGINPROC GenU16_ %+ %1
|
---|
83 | %ifdef ASM_CALL64_GCC
|
---|
84 | mov r9, rcx
|
---|
85 | mov r8, rdx
|
---|
86 | mov rdx, rsi
|
---|
87 | mov rcx, rdi
|
---|
88 | %endif
|
---|
89 | %if %2 != 0
|
---|
90 | lahf
|
---|
91 | and ah, 0xfe
|
---|
92 | shl r8d, 8
|
---|
93 | or eax, r8d
|
---|
94 | sahf
|
---|
95 | %endif
|
---|
96 | %1 cx, dx
|
---|
97 | mov [r9], cx
|
---|
98 | pushf
|
---|
99 | pop rax
|
---|
100 | ret
|
---|
101 | ENDPROC GenU16_ %+ %1
|
---|
102 |
|
---|
103 | BEGINPROC GenU32_ %+ %1
|
---|
104 | %ifdef ASM_CALL64_GCC
|
---|
105 | mov r9, rcx
|
---|
106 | mov r8, rdx
|
---|
107 | mov rdx, rsi
|
---|
108 | mov rcx, rdi
|
---|
109 | %endif
|
---|
110 | %if %2 != 0
|
---|
111 | lahf
|
---|
112 | and ah, 0xfe
|
---|
113 | shl r8d, 8
|
---|
114 | or eax, r8d
|
---|
115 | sahf
|
---|
116 | %endif
|
---|
117 | %1 ecx, edx
|
---|
118 | mov [r9], ecx
|
---|
119 | pushf
|
---|
120 | pop rax
|
---|
121 | ret
|
---|
122 | ENDPROC GenU32_ %+ %1
|
---|
123 |
|
---|
124 | BEGINPROC GenU64_ %+ %1
|
---|
125 | %ifdef ASM_CALL64_GCC
|
---|
126 | mov r9, rcx
|
---|
127 | mov r8, rdx
|
---|
128 | mov rdx, rsi
|
---|
129 | mov rcx, rdi
|
---|
130 | %endif
|
---|
131 | %if %2 != 0
|
---|
132 | lahf
|
---|
133 | and ah, 0xfe
|
---|
134 | shl r8d, 8
|
---|
135 | or eax, r8d
|
---|
136 | sahf
|
---|
137 | %endif
|
---|
138 | %1 rcx, rdx
|
---|
139 | mov [r9], rcx
|
---|
140 | pushf
|
---|
141 | pop rax
|
---|
142 | ret
|
---|
143 | ENDPROC GenU64_ %+ %1
|
---|
144 |
|
---|
145 | %endmacro
|
---|
146 |
|
---|
147 | DO_BINARY and, 0, 1
|
---|
148 | DO_BINARY or, 0, 1
|
---|
149 | DO_BINARY xor, 0, 1
|
---|
150 | DO_BINARY test, 0, 1
|
---|
151 |
|
---|
152 | DO_BINARY add, 0, 1
|
---|
153 | DO_BINARY adc, 1, 1
|
---|
154 | DO_BINARY sub, 0, 1
|
---|
155 | DO_BINARY sbb, 1, 1
|
---|
156 | DO_BINARY cmp, 0, 1
|
---|
157 |
|
---|
158 | DO_BINARY bt, 0, 0
|
---|
159 | DO_BINARY btc, 0, 0
|
---|
160 | DO_BINARY btr, 0, 0
|
---|
161 | DO_BINARY bts, 0, 0
|
---|
162 |
|
---|
163 |
|
---|
164 | ;;
|
---|
165 | ; @param 1 instruction
|
---|
166 | ; @param 2 Whether it takes carry in.
|
---|
167 | %macro DO_SHIFT 2
|
---|
168 |
|
---|
169 | BEGINPROC GenU8_ %+ %1
|
---|
170 | %ifdef ASM_CALL64_GCC
|
---|
171 | mov r9, rcx
|
---|
172 | mov r8, rdx
|
---|
173 | mov rdx, rsi
|
---|
174 | mov rcx, rdi
|
---|
175 | %endif
|
---|
176 | pushf
|
---|
177 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
178 | or dword [rsp], r8d
|
---|
179 | popf
|
---|
180 | xchg rcx, rdx
|
---|
181 | %1 dl, cl
|
---|
182 | mov [r9], dl
|
---|
183 | pushf
|
---|
184 | pop rax
|
---|
185 | ret
|
---|
186 | ENDPROC GenU8_ %+ %1
|
---|
187 |
|
---|
188 | BEGINPROC GenU16_ %+ %1
|
---|
189 | %ifdef ASM_CALL64_GCC
|
---|
190 | mov r9, rcx
|
---|
191 | mov r8, rdx
|
---|
192 | mov rdx, rsi
|
---|
193 | mov rcx, rdi
|
---|
194 | %endif
|
---|
195 | pushf
|
---|
196 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
197 | or dword [rsp], r8d
|
---|
198 | popf
|
---|
199 | xchg cx, dx
|
---|
200 | %1 dx, cl
|
---|
201 | mov [r9], dx
|
---|
202 | pushf
|
---|
203 | pop rax
|
---|
204 | ret
|
---|
205 | ENDPROC GenU16_ %+ %1
|
---|
206 |
|
---|
207 | BEGINPROC GenU32_ %+ %1
|
---|
208 | %ifdef ASM_CALL64_GCC
|
---|
209 | mov r9, rcx
|
---|
210 | mov r8, rdx
|
---|
211 | mov rdx, rsi
|
---|
212 | mov rcx, rdi
|
---|
213 | %endif
|
---|
214 | pushf
|
---|
215 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
216 | or dword [rsp], r8d
|
---|
217 | popf
|
---|
218 | xchg rcx, rdx
|
---|
219 | %1 edx, cl
|
---|
220 | mov [r9], edx
|
---|
221 | pushf
|
---|
222 | pop rax
|
---|
223 | ret
|
---|
224 | ENDPROC GenU32_ %+ %1
|
---|
225 |
|
---|
226 | BEGINPROC GenU64_ %+ %1
|
---|
227 | %ifdef ASM_CALL64_GCC
|
---|
228 | mov r9, rcx
|
---|
229 | mov r8, rdx
|
---|
230 | mov rdx, rsi
|
---|
231 | mov rcx, rdi
|
---|
232 | %endif
|
---|
233 | pushf
|
---|
234 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
235 | or dword [rsp], r8d
|
---|
236 | popf
|
---|
237 | xchg rcx, rdx
|
---|
238 | %1 rdx, cl
|
---|
239 | mov [r9], rdx
|
---|
240 | pushf
|
---|
241 | pop rax
|
---|
242 | ret
|
---|
243 | ENDPROC GenU64_ %+ %1
|
---|
244 |
|
---|
245 |
|
---|
246 | BEGINPROC GenU8_ %+ %1 %+ _Ib
|
---|
247 | %ifdef ASM_CALL64_GCC
|
---|
248 | mov r9, rcx
|
---|
249 | mov r8, rdx
|
---|
250 | mov rdx, rsi
|
---|
251 | mov rcx, rdi
|
---|
252 | %endif
|
---|
253 | pushf
|
---|
254 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
255 | or dword [rsp], r8d
|
---|
256 | popf
|
---|
257 |
|
---|
258 | movzx r11d, dl
|
---|
259 | mov al, cl
|
---|
260 | mov rdx, r9
|
---|
261 |
|
---|
262 | lea r10, [.first_imm wrt rip]
|
---|
263 | lea r10, [r10 + r11 * 8] ;; @todo assert that the entry size is 8 bytes
|
---|
264 | jmp r10
|
---|
265 | .return:
|
---|
266 | mov [rdx], al
|
---|
267 | pushf
|
---|
268 | pop rax
|
---|
269 | ret
|
---|
270 |
|
---|
271 | ALIGNCODE(8)
|
---|
272 | .first_imm:
|
---|
273 | %assign i 0
|
---|
274 | %rep 256
|
---|
275 | %1 al, i
|
---|
276 | jmp near .return
|
---|
277 | %if i == 1
|
---|
278 | db 0cch
|
---|
279 | %endif
|
---|
280 | %assign i i+1
|
---|
281 | %endrep
|
---|
282 | ENDPROC GenU8_ %+ %1 %+ _Ib
|
---|
283 |
|
---|
284 | BEGINPROC GenU16_ %+ %1 %+ _Ib
|
---|
285 | %ifdef ASM_CALL64_GCC
|
---|
286 | mov r9, rcx
|
---|
287 | mov r8, rdx
|
---|
288 | mov rdx, rsi
|
---|
289 | mov rcx, rdi
|
---|
290 | %endif
|
---|
291 | pushf
|
---|
292 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
293 | or dword [rsp], r8d
|
---|
294 | popf
|
---|
295 |
|
---|
296 | movzx r11d, dl
|
---|
297 | mov ax, cx
|
---|
298 | mov rdx, r9
|
---|
299 |
|
---|
300 | lea r10, [.first_imm wrt rip]
|
---|
301 | lea r10, [r10 + r11] ;; @todo assert that the entry size is 9 bytes
|
---|
302 | lea r10, [r10 + r11 * 8]
|
---|
303 | jmp r10
|
---|
304 | .return:
|
---|
305 | mov [rdx], ax
|
---|
306 | pushf
|
---|
307 | pop rax
|
---|
308 | ret
|
---|
309 |
|
---|
310 | ALIGNCODE(8)
|
---|
311 | .first_imm:
|
---|
312 | %assign i 0
|
---|
313 | %rep 256
|
---|
314 | %1 ax, i
|
---|
315 | jmp near .return
|
---|
316 | %if i == 1
|
---|
317 | db 0cch
|
---|
318 | %endif
|
---|
319 | %assign i i+1
|
---|
320 | %endrep
|
---|
321 | ENDPROC GenU16_ %+ %1 %+ _Ib
|
---|
322 |
|
---|
323 | BEGINPROC GenU32_ %+ %1 %+ _Ib
|
---|
324 | %ifdef ASM_CALL64_GCC
|
---|
325 | mov r9, rcx
|
---|
326 | mov r8, rdx
|
---|
327 | mov rdx, rsi
|
---|
328 | mov rcx, rdi
|
---|
329 | %endif
|
---|
330 | pushf
|
---|
331 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
332 | or dword [rsp], r8d
|
---|
333 | popf
|
---|
334 |
|
---|
335 | movzx r11d, dl
|
---|
336 | mov eax, ecx
|
---|
337 | mov rdx, r9
|
---|
338 |
|
---|
339 | lea r10, [.first_imm wrt rip]
|
---|
340 | lea r10, [r10 + r11 * 8] ;; @todo assert that the entry size is 8 bytes
|
---|
341 | jmp r10
|
---|
342 | .return:
|
---|
343 | mov [rdx], eax
|
---|
344 | pushf
|
---|
345 | pop rax
|
---|
346 | ret
|
---|
347 |
|
---|
348 | ALIGNCODE(8)
|
---|
349 | .first_imm:
|
---|
350 | %assign i 0
|
---|
351 | %rep 256
|
---|
352 | %1 eax, i
|
---|
353 | jmp near .return
|
---|
354 | %if i == 1
|
---|
355 | db 0cch
|
---|
356 | %endif
|
---|
357 | %assign i i+1
|
---|
358 | %endrep
|
---|
359 | ENDPROC GenU32_ %+ %1 %+ _Ib
|
---|
360 |
|
---|
361 | BEGINPROC GenU64_ %+ %1 %+ _Ib
|
---|
362 | %ifdef ASM_CALL64_GCC
|
---|
363 | mov r9, rcx
|
---|
364 | mov r8, rdx
|
---|
365 | mov rdx, rsi
|
---|
366 | mov rcx, rdi
|
---|
367 | %endif
|
---|
368 | pushf
|
---|
369 | and dword [rsp], ~X86_EFL_STATUS_BITS
|
---|
370 | or dword [rsp], r8d
|
---|
371 | popf
|
---|
372 |
|
---|
373 | movzx r11d, dl
|
---|
374 | mov rax, rcx
|
---|
375 | mov rdx, r9
|
---|
376 |
|
---|
377 | lea r10, [.first_imm wrt rip]
|
---|
378 | lea r10, [r10 + r11] ;; @todo assert that the entry size is 9 bytes
|
---|
379 | lea r10, [r10 + r11 * 8]
|
---|
380 | jmp r10
|
---|
381 | .return:
|
---|
382 | mov [rdx], rax
|
---|
383 | pushf
|
---|
384 | pop rax
|
---|
385 | ret
|
---|
386 |
|
---|
387 | ALIGNCODE(8)
|
---|
388 | .first_imm:
|
---|
389 | %assign i 0
|
---|
390 | %rep 256
|
---|
391 | %1 rax, i
|
---|
392 | jmp near .return
|
---|
393 | %if i == 1
|
---|
394 | db 0cch
|
---|
395 | %endif
|
---|
396 | %assign i i+1
|
---|
397 | %endrep
|
---|
398 | ENDPROC GenU64_ %+ %1 %+ _Ib
|
---|
399 |
|
---|
400 |
|
---|
401 | %endmacro
|
---|
402 |
|
---|
403 | DO_SHIFT shl, 0
|
---|
404 | DO_SHIFT shr, 0
|
---|
405 | DO_SHIFT sar, 0
|
---|
406 | DO_SHIFT rol, 0
|
---|
407 | DO_SHIFT ror, 0
|
---|
408 | DO_SHIFT rcl, 1
|
---|
409 | DO_SHIFT rcr, 1
|
---|
410 |
|
---|