summaryrefslogtreecommitdiffstats
path: root/src/VBox/ValidationKit/bootsectors/bs3-cpu-instr-2-template.mac
blob: acb23b2dda37169e462993ce5f4b400d61df5d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
; $Id: bs3-cpu-instr-2-template.mac $
;; @file
; BS3Kit - bs3-cpu-instr-2 assembly template.
;

;
; Copyright (C) 2007-2023 Oracle and/or its affiliates.
;
; This file is part of VirtualBox base platform packages, as
; available from https://www.virtualbox.org.
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation, in version 3 of the
; License.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, see <https://www.gnu.org/licenses>.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
; in the VirtualBox distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
;


;*********************************************************************************************************************************
;*  Header Files                                                                                                                 *
;*********************************************************************************************************************************
%include "bs3kit-template-header.mac"   ; setup environment


;*********************************************************************************************************************************
;*  Defined Constants And Macros                                                                                                 *
;*********************************************************************************************************************************
;;
; Variant on BS3_PROC_BEGIN_CMN w/ BS3_PBC_NEAR that prefixes the function
; with an instruction length byte.
;
; ASSUMES the length is between the start of the function and the .again label.
;
%ifndef BS3CPUINSTR2_PROC_BEGIN_CMN_DEFINED
 %define BS3CPUINSTR2_PROC_BEGIN_CMN_DEFINED
 %macro BS3CPUINSTR2_PROC_BEGIN_CMN 1
        align   8, db 0cch
        db      BS3_CMN_NM(%1).again - BS3_CMN_NM(%1)
BS3_PROC_BEGIN_CMN %1, BS3_PBC_NEAR
 %endmacro
%endif


;*********************************************************************************************************************************
;*  External Symbols                                                                                                             *
;*********************************************************************************************************************************
TMPL_BEGIN_TEXT


;
; Test code snippets containing code which differs between 16-bit, 32-bit
; and 64-bit CPUs modes.
;
%ifdef BS3_INSTANTIATING_CMN

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mul_xBX_ud2, BS3_PBC_NEAR
        mul     xBX
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mul_xBX_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_imul_xBX_ud2, BS3_PBC_NEAR
        imul    xBX
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_imul_xBX_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_imul_xCX_xBX_ud2, BS3_PBC_NEAR
        imul    xCX, xBX
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_imul_xCX_xBX_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_div_xBX_ud2, BS3_PBC_NEAR
        div     xBX
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_div_xBX_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_idiv_xBX_ud2, BS3_PBC_NEAR
        idiv    xBX
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_idiv_xBX_ud2


;
; BSF / BSR / TZCNT / LZCNT
;
%ifndef EMIT_BITSCAN_DEFINED
%define EMIT_BITSCAN_DEFINED
%macro EMIT_BITSCAN 3
BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _AX_BX_ud2, BS3_PBC_NEAR
        %2
        %1      ax, bx
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _AX_BX_ud2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _AX_FSxBX_ud2, BS3_PBC_NEAR
        %2
        %1      ax, [fs:xBX]
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _AX_FSxBX_ud2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _EAX_EBX_ud2, BS3_PBC_NEAR
        %2
        %1      eax, ebx
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _EAX_EBX_ud2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _EAX_FSxBX_ud2, BS3_PBC_NEAR
        %2
        %1      eax, [fs:xBX]
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _EAX_FSxBX_ud2

 %if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _RAX_RBX_ud2, BS3_PBC_NEAR
        %2
        %1      rax, rbx
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _RAX_RBX_ud2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %3 %+ _RAX_FSxBX_ud2, BS3_PBC_NEAR
        %2
        %1      rax, [fs:xBX]
.again:
        ud2
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %3 %+ _RAX_FSxBX_ud2
 %endif
%endmacro
%endif

EMIT_BITSCAN bsf,   .ignored:, bsf
EMIT_BITSCAN bsr,   .ignored:, bsr
EMIT_BITSCAN tzcnt, .ignored:, tzcnt
EMIT_BITSCAN lzcnt, .ignored:, lzcnt
EMIT_BITSCAN bsf,   db 0f2h,   f2_bsf
EMIT_BITSCAN bsr,   db 0f2h,   f2_bsr
EMIT_BITSCAN tzcnt, db 0f2h,   f2_tzcnt
EMIT_BITSCAN lzcnt, db 0f2h,   f2_lzcnt


;
; RORX - VEX instruction with a couple of questions about non-standard encodings.
;
;;%define icebp ud2
BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_EDX_2_icebp, BS3_PBC_NEAR
        rorx    ebx, edx, 2
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_EDX_2_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_RBX_RDX_2_icebp, BS3_PBC_NEAR
%if TMPL_BITS == 64
        rorx    rbx, rdx, 2
%else
        db      0C4h,0E3h,0FBh,0F0h,0DAh,002h    ; 32-bit ignores VEX.W=1 (10980xe)
%endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_RBX_RDX_2_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_EDX_2_icebp_L1, BS3_PBC_NEAR
        db 0C4h, 0E3h, 07Bh | 4h, 0F0h, 0DAh, 002h          ; VEX.L=1 should #UD according to the docs
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_EDX_2_icebp_L1

BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_EDX_2_icebp_V1, BS3_PBC_NEAR
        db 0C4h, 0E3h, 003h | ~(1 << 3), 0F0h, 0DAh, 002h   ; VEX.VVVV=1 - behaviour is undocumented - 10980xe #UD
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_EDX_2_icebp_V1

BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_EDX_2_icebp_V15, BS3_PBC_NEAR
        db 0C4h, 0E3h, 003h | ~(15 << 3), 0F0h, 0DAh, 002h  ; VEX.VVVV=15 - behaviour is not documented - 10980xe #UD
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_EDX_2_icebp_V15

 %if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_EDX_2_icebp_X1, BS3_PBC_NEAR
        db 0C4h, 0E3h & ~40h, 07Bh, 0F0h, 0DAh, 002h        ; VEX.X=0 - behaviour is not documented - ignored by 10980xe
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_EDX_2_icebp_X1
 %endif

; A couple of memory variants
BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_EBX_DSxDI_36_icebp, BS3_PBC_NEAR
        rorx    ebx, [xDI], 36
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_EBX_DSxDI_36_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_rorx_RBX_DSxDI_68_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        rorx    rbx, [xDI], 68
 %elif TMPL_BITS == 32
        db      0C4h,0E3h,07Bh,0F0h,01Fh,044h   ; 16-bit ignores VEX.W=1 (10980xe)
 %else
        db      0C4h,0E3h,0FBh,0F0h,01Dh,044h   ; 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_rorx_RBX_DSxDI_68_icebp

;
; ANDN (BMI1)
;
BS3_PROC_BEGIN_CMN bs3CpuInstr2_andn_RAX_RCX_RBX_icebp, BS3_PBC_NEAR
%if TMPL_BITS == 64
        andn    rax, rcx, rbx
%else
        db      0C4h,0E2h,0F0h,0F2h,0C3h    ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
%endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_andn_RAX_RCX_RBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_andn_EAX_ECX_EBX_icebp, BS3_PBC_NEAR
        andn    eax, ecx, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_andn_EAX_ECX_EBX_icebp


BS3_PROC_BEGIN_CMN bs3CpuInstr2_andn_RAX_RCX_FSxBX_icebp, BS3_PBC_NEAR
%if TMPL_BITS == 64
        andn    rax, rcx, [fs:rbx]
%elif TMPL_BITS == 32
        db      064h,0C4h,0E2h,0F0h,0F2h,003h   ; andn    rax, rcx, [fs:ebx]
%else
        db      064h,0C4h,0E2h,0F0h,0F2h,007h   ; andn    rax, rcx, [fs:bx]
%endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_andn_RAX_RCX_FSxBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_andn_EAX_ECX_FSxBX_icebp, BS3_PBC_NEAR
        andn    eax, ecx, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_andn_EAX_ECX_FSxBX_icebp


;
; BEXTR / SHLX / SARX / SHRX - BMI1 (opcode f7h)
; BZHI                       - BMI2 (opcode f5h)
;
; @param %1 instruction
; @param %2 opcode
; @param %3 prefix
;
%ifndef SHLX_SARX_SHRX_DEFINED
%define SHLX_SARX_SHRX_DEFINED
%macro SHLX_SARX_SHRX 3

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_RBX_RCX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, rbx, rcx                   ; SHLX=C4E2F1F7C3
 %else
        db      0C4h,0E2h,0F0h|%3,%2,0C3h       ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_RBX_RCX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_EBX_ECX_icebp, BS3_PBC_NEAR
        %1      eax, ebx, ecx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_EBX_ECX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_FSxBX_RCX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, [fs:rbx], rcx              ; SHLX=64C4E2F1F703
 %elif TMPL_BITS == 32
        db      064h,0C4h,0E2h,0F0h|%3,%2,003h
 %else
        db      064h,0C4h,0E2h,0F0h|%3,%2,007h
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_FSxBX_RCX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_FSxBX_ECX_icebp, BS3_PBC_NEAR
        %1      eax, [fs:xBX], ecx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_FSxBX_ECX_icebp

%endmacro
%endif

SHLX_SARX_SHRX bextr, 0f7h, 0 ; none
SHLX_SARX_SHRX shlx,  0f7h, 1 ; 66h
SHLX_SARX_SHRX sarx,  0f7h, 2 ; f3h
SHLX_SARX_SHRX shrx,  0f7h, 3 ; f2h
SHLX_SARX_SHRX bzhi,  0f5h, 0 ; none

;
; PPEP / PEXT - BMI2 (opcode f5h)
;
; @param %1 instruction
; @param %2 opcode
; @param %3 prefix
;
%ifndef PDEP_PEXT_DEFINED
%define PDEP_PEXT_DEFINED
%macro PDEP_PEXT_ 3

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_RCX_RBX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, rcx, rbx
 %else
        db      0C4h,0E2h,0F0h|%3,%2,0C3h       ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_RCX_RBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_ECX_EBX_icebp, BS3_PBC_NEAR
        %1      eax, ecx, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_ECX_EBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_RCX_FSxBX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, rcx, [fs:rbx]
 %elif TMPL_BITS == 32
        db      064h,0C4h,0E2h,0F0h|%3,%2,003h
 %else
        db      064h,0C4h,0E2h,0F0h|%3,%2,007h
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_RCX_FSxBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_ECX_FSxBX_icebp, BS3_PBC_NEAR
        %1      eax, ecx, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_ECX_FSxBX_icebp

%endmacro
%endif

PDEP_PEXT_ pext,  0f5h, 2 ; f3h
PDEP_PEXT_ pdep,  0f5h, 3 ; f2h

;
; BLSR / BLSMSK / BLSI
; These are encoded in the exact same way, only the /r differs (%2).
;
%ifndef BLSR_BLSMSK_BLSI_DEFINED
%define BLSR_BLSMSK_BLSI_DEFINED
%macro BLSR_BLSMSK_BLSI 2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_RBX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, rbx                                ; BLSR=C4E2F8F3CB
 %else
        db      0C4h,0E2h,0F8h,0F3h,0C3h | (%2 << 3)    ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_RBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_EBX_icebp, BS3_PBC_NEAR
        %1      eax, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_EBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _RAX_FSxBX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        %1      rax, [fs:rbx]                           ; BSLR=64C4E2F8F30B
 %elif TMPL_BITS == 32
        db      064h,0C4h,0E2h,0F8h,0F3h,003h | (%2 << 3)
 %else
        db      064h,0C4h,0E2h,0F8h,0F3h,007h | (%2 << 3)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _RAX_FSxBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_ %+ %1 %+ _EAX_FSxBX_icebp, BS3_PBC_NEAR
        %1      eax, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_ %+ %1 %+ _EAX_FSxBX_icebp

%endmacro
%endif

BLSR_BLSMSK_BLSI blsr,    1
BLSR_BLSMSK_BLSI blsmsk,  2
BLSR_BLSMSK_BLSI blsi,    3

;
; MULX
;
BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_RAX_RCX_RBX_RDX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        mulx    rax, rcx, rbx                   ; C4E2F3F6C3
 %else
        db      0C4h,0E2h,0F3h,0F6h,0C3h        ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_RAX_RCX_RBX_RDX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_RCX_RCX_RBX_RDX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        mulx    rcx, rcx, rbx                   ; C4E2F3F6CB
 %else
        db      0C4h,0E2h,0F3h,0F6h,0CBh        ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_RCX_RCX_RBX_RDX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_RAX_RCX_FSxBX_RDX_icebp, BS3_PBC_NEAR
 %if TMPL_BITS == 64
        mulx    rax, rcx, [fs:rbx]              ; 64C4E2F3F603
 %elif TMPL_BITS == 32
        db      064h,0C4h,0E2h,0F3h,0F6h,003h   ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %else
        db      064h,0C4h,0E2h,0F3h,0F6h,007h   ; 32-bit & 16-bit ignores VEX.W=1 (10980xe)
 %endif
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_RAX_RCX_FSxBX_RDX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_EAX_ECX_EBX_EDX_icebp, BS3_PBC_NEAR
        mulx    eax, ecx, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_EAX_ECX_EBX_EDX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_ECX_ECX_EBX_EDX_icebp, BS3_PBC_NEAR
        mulx    ecx, ecx, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_ECX_ECX_EBX_EDX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_mulx_EAX_ECX_FSxBX_EDX_icebp, BS3_PBC_NEAR
        mulx    eax, ecx, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_mulx_EAX_ECX_FSxBX_EDX_icebp


;
; POPCNT
;
BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_AX_BX_icebp, BS3_PBC_NEAR
        popcnt  ax, bx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_AX_BX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_EAX_EBX_icebp, BS3_PBC_NEAR
        popcnt  eax, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_EAX_EBX_icebp

 %if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_RAX_RBX_icebp, BS3_PBC_NEAR
        popcnt  rax, rbx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_RAX_RBX_icebp
 %endif


BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_AX_FSxBX_icebp, BS3_PBC_NEAR
        popcnt  ax, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_AX_FSxBX_icebp

BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_EAX_FSxBX_icebp, BS3_PBC_NEAR
        popcnt  eax, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_EAX_FSxBX_icebp

 %if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuInstr2_popcnt_RAX_FSxBX_icebp, BS3_PBC_NEAR
        popcnt  rax, [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN   bs3CpuInstr2_popcnt_RAX_FSxBX_icebp
 %endif


;
; CRC32
;
BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_BL_icebp
        crc32   eax, bl
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_BL_icebp

BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_BX_icebp
        crc32   eax, bx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_BX_icebp

BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_EBX_icebp
        crc32   eax, ebx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_EBX_icebp

 %if TMPL_BITS == 64
BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_RBX_icebp
        crc32   rax, rbx
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_RBX_icebp
 %endif


BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_byte_FSxBX_icebp
        crc32   eax, byte [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_byte_FSxBX_icebp

BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_word_FSxBX_icebp
        crc32   eax, word [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_word_FSxBX_icebp

BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_dword_FSxBX_icebp
        crc32   eax, dword [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_dword_FSxBX_icebp

 %if TMPL_BITS == 64
BS3CPUINSTR2_PROC_BEGIN_CMN bs3CpuInstr2_crc32_EAX_qword_FSxBX_icebp
        crc32   rax, qword [fs:xBX]
.again:
        icebp
        jmp     .again
BS3_PROC_END_CMN            bs3CpuInstr2_crc32_EAX_qword_FSxBX_icebp
 %endif


;
; CMPXCHG16B
;
 %if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuInstr2_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 4)
BS3_PROC_END_CMN   bs3CpuInstr2_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        lock cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        o16 cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        db 0f0h, 066h
        cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 6)
BS3_PROC_END_CMN   bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        repz cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        db 0f0h, 0f3h
        cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 6)
BS3_PROC_END_CMN   bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2

BS3_PROC_BEGIN_CMN bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        repnz cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
        db 0f0h, 0f2h
        cmpxchg16b [rdi]
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 6)
BS3_PROC_END_CMN   bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrfsbase_rbx_ud2, BS3_PBC_NEAR
        wrfsbase rbx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_wrfsbase_rbx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrfsbase_ebx_ud2, BS3_PBC_NEAR
        wrfsbase ebx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 4)
BS3_PROC_END_CMN   bs3CpuInstr2_wrfsbase_ebx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrgsbase_rbx_ud2, BS3_PBC_NEAR
        wrgsbase rbx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_wrgsbase_rbx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrgsbase_ebx_ud2, BS3_PBC_NEAR
        wrgsbase ebx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 4)
BS3_PROC_END_CMN   bs3CpuInstr2_wrgsbase_ebx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrfsbase_rbx_rdfsbase_rcx_ud2, BS3_PBC_NEAR
        wrfsbase rbx
        mov      ebx, 0
        rdfsbase rcx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 15)
BS3_PROC_END_CMN   bs3CpuInstr2_wrfsbase_rbx_rdfsbase_rcx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrfsbase_ebx_rdfsbase_ecx_ud2, BS3_PBC_NEAR
        wrfsbase ebx
        mov      ebx, 0
        rdfsbase ecx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 13)
BS3_PROC_END_CMN   bs3CpuInstr2_wrfsbase_ebx_rdfsbase_ecx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrgsbase_rbx_rdgsbase_rcx_ud2, BS3_PBC_NEAR
        wrgsbase rbx
        mov      ebx, 0
        rdgsbase rcx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 15)
BS3_PROC_END_CMN   bs3CpuInstr2_wrgsbase_rbx_rdgsbase_rcx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_wrgsbase_ebx_rdgsbase_ecx_ud2, BS3_PBC_NEAR
        wrgsbase ebx
        mov      ebx, 0
        rdgsbase ecx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 13)
BS3_PROC_END_CMN   bs3CpuInstr2_wrfgbase_ebx_rdgsbase_ecx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_rdfsbase_rbx_ud2, BS3_PBC_NEAR
        rdfsbase rbx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_rdfsbase_rbx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_rdfsbase_ebx_ud2, BS3_PBC_NEAR
        rdfsbase ebx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 4)
BS3_PROC_END_CMN   bs3CpuInstr2_rdfsbase_ebx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_rdgsbase_rbx_ud2, BS3_PBC_NEAR
        rdgsbase rbx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 5)
BS3_PROC_END_CMN   bs3CpuInstr2_rdgsbase_rbx_ud2


BS3_PROC_BEGIN_CMN bs3CpuInstr2_rdgsbase_ebx_ud2, BS3_PBC_NEAR
        rdgsbase ebx
.again:
        ud2
        jmp     .again
AssertCompile(.again - BS3_LAST_LABEL == 4)
BS3_PROC_END_CMN   bs3CpuInstr2_rdgsbase_ebx_ud2


;; @todo figure out this fudge. sigh.
times (348) db 0cch ; fudge to avoid 'rderr' during boot.

 %endif ; TMPL_BITS == 64


%endif ; BS3_INSTANTIATING_CMN

%include "bs3kit-template-footer.mac"   ; reset environment