VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-instr-2-gen-asm.asm@ 107231

Last change on this file since 107231 was 107101, checked in by vboxsync, 3 months ago

ValidationKit/bootsectors: Save some image space by coalescing format strings & code; bugref:9898; bugref:10658; jiraref:VBP-1207

Save about 4K in bs3-cpu-instr-2, 2K in bs3-cpu-instr-3 -- enough to turn on asserts

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1; $Id: bs3-cpu-instr-2-gen-asm.asm 107101 2024-11-22 07:56:43Z 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
44BEGINCODE
45
46preface_0:
47%ifdef ASM_CALL64_GCC
48 mov r9, rcx
49 mov r8, rdx
50 mov rdx, rsi
51 mov rcx, rdi
52%endif
53 ret
54
55preface_1:
56%ifdef ASM_CALL64_GCC
57 mov r9, rcx
58 mov r8, rdx
59 mov rdx, rsi
60 mov rcx, rdi
61%endif
62 lahf
63 and ah, 0xfe
64 shl r8d, 8
65 or eax, r8d
66 sahf
67 ret
68
69preface_2:
70%ifdef ASM_CALL64_GCC
71 mov r9, rcx
72 mov r8, rdx
73 mov rdx, rsi
74 mov rcx, rdi
75%endif
76 pushf
77 and dword [rsp], ~X86_EFL_STATUS_BITS
78 or dword [rsp], r8d
79 popf
80 ret
81
82;;
83; @param 1 which preface to use:
84; 0 = no flags meddling
85; 1 = takes carry flag in
86; 2 = takes entire flags register in
87%macro DO_PREFACE 1
88 call preface_ %+ %1
89%endmacro
90
91;;
92; @param 1 instruction
93; @param 2 Whether it takes carry in.
94; @param 3 Whether it has an 8-bit form.
95%macro DO_BINARY 3
96
97 %if %3 != 0
98BEGINPROC GenU8_ %+ %1
99 DO_PREFACE %2
100 %1 cl, dl
101 mov [r9], cl
102 pushf
103 pop rax
104 ret
105ENDPROC GenU8_ %+ %1
106 %endif
107
108BEGINPROC GenU16_ %+ %1
109 DO_PREFACE %2
110 %1 cx, dx
111 mov [r9], cx
112 pushf
113 pop rax
114 ret
115ENDPROC GenU16_ %+ %1
116
117BEGINPROC GenU32_ %+ %1
118 DO_PREFACE %2
119 %1 ecx, edx
120 mov [r9], ecx
121 pushf
122 pop rax
123 ret
124ENDPROC GenU32_ %+ %1
125
126BEGINPROC GenU64_ %+ %1
127 DO_PREFACE %2
128 %1 rcx, rdx
129 mov [r9], rcx
130 pushf
131 pop rax
132 ret
133ENDPROC GenU64_ %+ %1
134
135%endmacro
136
137DO_BINARY and, 0, 1
138DO_BINARY or, 0, 1
139DO_BINARY xor, 0, 1
140DO_BINARY test, 0, 1
141
142DO_BINARY add, 0, 1
143DO_BINARY adc, 1, 1
144DO_BINARY sub, 0, 1
145DO_BINARY sbb, 1, 1
146DO_BINARY cmp, 0, 1
147
148DO_BINARY bt, 0, 0
149DO_BINARY btc, 0, 0
150DO_BINARY btr, 0, 0
151DO_BINARY bts, 0, 0
152
153
154;;
155; @param 1 instruction
156; @param 2 Whether it takes carry in.
157%macro DO_SHIFT 2
158
159BEGINPROC GenU8_ %+ %1
160 DO_PREFACE 2
161 xchg rcx, rdx
162 %1 dl, cl
163 mov [r9], dl
164 pushf
165 pop rax
166 ret
167ENDPROC GenU8_ %+ %1
168
169BEGINPROC GenU16_ %+ %1
170 DO_PREFACE 2
171 xchg cx, dx
172 %1 dx, cl
173 mov [r9], dx
174 pushf
175 pop rax
176 ret
177ENDPROC GenU16_ %+ %1
178
179BEGINPROC GenU32_ %+ %1
180 DO_PREFACE 2
181 xchg rcx, rdx
182 %1 edx, cl
183 mov [r9], edx
184 pushf
185 pop rax
186 ret
187ENDPROC GenU32_ %+ %1
188
189BEGINPROC GenU64_ %+ %1
190 DO_PREFACE 2
191 xchg rcx, rdx
192 %1 rdx, cl
193 mov [r9], rdx
194 pushf
195 pop rax
196 ret
197ENDPROC GenU64_ %+ %1
198
199
200BEGINPROC GenU8_ %+ %1 %+ _Ib
201 DO_PREFACE 2
202 movzx r11d, dl
203 mov al, cl
204 mov rdx, r9
205
206 lea r10, [.first_imm wrt rip]
207 lea r10, [r10 + r11 * 8] ;; @todo assert that the entry size is 8 bytes
208 jmp r10
209.return:
210 mov [rdx], al
211 pushf
212 pop rax
213 ret
214
215 ALIGNCODE(8)
216.first_imm:
217 %assign i 0
218 %rep 256
219 %1 al, i
220 jmp near .return
221 %if i == 1
222 db 0cch
223 %endif
224 %assign i i+1
225 %endrep
226ENDPROC GenU8_ %+ %1 %+ _Ib
227
228BEGINPROC GenU16_ %+ %1 %+ _Ib
229 DO_PREFACE 2
230 movzx r11d, dl
231 mov ax, cx
232 mov rdx, r9
233
234 lea r10, [.first_imm wrt rip]
235 lea r10, [r10 + r11] ;; @todo assert that the entry size is 9 bytes
236 lea r10, [r10 + r11 * 8]
237 jmp r10
238.return:
239 mov [rdx], ax
240 pushf
241 pop rax
242 ret
243
244 ALIGNCODE(8)
245.first_imm:
246 %assign i 0
247 %rep 256
248 %1 ax, i
249 jmp near .return
250 %if i == 1
251 db 0cch
252 %endif
253 %assign i i+1
254 %endrep
255ENDPROC GenU16_ %+ %1 %+ _Ib
256
257BEGINPROC GenU32_ %+ %1 %+ _Ib
258 DO_PREFACE 2
259 movzx r11d, dl
260 mov eax, ecx
261 mov rdx, r9
262
263 lea r10, [.first_imm wrt rip]
264 lea r10, [r10 + r11 * 8] ;; @todo assert that the entry size is 8 bytes
265 jmp r10
266.return:
267 mov [rdx], eax
268 pushf
269 pop rax
270 ret
271
272 ALIGNCODE(8)
273.first_imm:
274 %assign i 0
275 %rep 256
276 %1 eax, i
277 jmp near .return
278 %if i == 1
279 db 0cch
280 %endif
281 %assign i i+1
282 %endrep
283ENDPROC GenU32_ %+ %1 %+ _Ib
284
285BEGINPROC GenU64_ %+ %1 %+ _Ib
286 DO_PREFACE 2
287 movzx r11d, dl
288 mov rax, rcx
289 mov rdx, r9
290
291 lea r10, [.first_imm wrt rip]
292 lea r10, [r10 + r11] ;; @todo assert that the entry size is 9 bytes
293 lea r10, [r10 + r11 * 8]
294 jmp r10
295.return:
296 mov [rdx], rax
297 pushf
298 pop rax
299 ret
300
301 ALIGNCODE(8)
302.first_imm:
303 %assign i 0
304 %rep 256
305 %1 rax, i
306 jmp near .return
307 %if i == 1
308 db 0cch
309 %endif
310 %assign i i+1
311 %endrep
312ENDPROC GenU64_ %+ %1 %+ _Ib
313
314
315%endmacro
316
317DO_SHIFT shl, 0
318DO_SHIFT shr, 0
319DO_SHIFT sar, 0
320DO_SHIFT rol, 0
321DO_SHIFT ror, 0
322DO_SHIFT rcl, 1
323DO_SHIFT rcr, 1
324
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette