Changeset 102182 in vbox for trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-3-cmn-template.mac
- Timestamp:
- Nov 21, 2023 9:46:33 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-3-cmn-template.mac
r102157 r102182 63 63 %define LEA_ESI 066666616h 64 64 %define LEA_EDI 077777177h 65 66 %define LEA_RAX 01111111111111110h67 %define LEA_RCX 02222222222222202h68 %define LEA_RDX 03333333333333033h69 %define LEA_RBX 04444444444440444h70 %define LEA_RSP 058595a5d51525356h71 %define LEA_RBP 05555555555555551h72 %define LEA_RSI 06666666666666616h73 %define LEA_RDI 07777777777777177h74 %define LEA_R8 08888888888881888h75 %define LEA_R9 09999999999999992h76 %define LEA_R10 0aaaaaaaaaaaaaa2ah77 %define LEA_R11 0bbbbbbbbbbbbb2bbh78 %define LEA_R12 0cccccccccccc2ccch79 %define LEA_R13 0ddddddddddddddd3h80 %define LEA_R14 0eeeeeeeeeeeeee3eh81 %define LEA_R15 0fffffffffffff3ffh82 65 83 66 … … 454 437 BS3_PROC_END_CMN bs3CpuBasic3_lea_32 455 438 456 457 %else ; TMPL_BITS == 64 458 459 460 ;; 461 ; Tests 64-bit addressing using the LEA instruction. 462 ; 463 BS3_PROC_BEGIN_CMN bs3CpuBasic3_lea_64, BS3_PBC_FAR 464 push rax 465 push rcx 466 push rdx 467 push rbx 468 push rbp 469 push rsi 470 push rdi 471 push r8 472 push r9 473 push r10 474 push r11 475 push r12 476 push r13 477 push r14 478 push r15 479 .test_label: 480 mov [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))], rsp 481 482 ; 483 ; Loop thru all the modr/m memory encodings. 484 ; 485 %assign iMod 0 486 %assign iDstReg 0 ; We don't test all destination registers 487 %rep 3 488 %rep 16 ; Destination registers per encoding. Testing all takes too much space. 489 %assign iMemReg 0 490 %rep 16 491 %assign iDstReg_Value %sel(iDstReg+1, LEA_RAX, LEA_RCX, LEA_RDX, LEA_RBX, LEA_RSP, LEA_RBP, LEA_RSI, LEA_RDI, \ 492 LEA_R8, LEA_R9, LEA_R10, LEA_R11, LEA_R12, LEA_R13, LEA_R14, LEA_R15) 493 494 %if (iMemReg & 7) == 4 495 ; 496 ; SIB. 497 ; 498 %assign iBase 0 499 %rep 16 500 %if (iBase & 7) == 5 && iMod == 0 501 %assign iBase_Value 0 502 %else 503 %assign iBase_Value %sel(iBase+1, LEA_RAX, LEA_RCX, LEA_RDX, LEA_RBX, LEA_RSP, LEA_RBP, LEA_RSI, LEA_RDI, \ 504 LEA_R8, LEA_R9, LEA_R10, LEA_R11, LEA_R12, LEA_R13, LEA_R14, LEA_R15) 505 %endif 506 507 %assign iIndex 0 508 %assign cShift 0 ; we don't have enough room for checking all the shifts. 509 %rep 16 510 %assign iBase_Value %sel(iIndex+1, LEA_RAX, LEA_RCX, LEA_RDX, LEA_RBX, 0, LEA_RBP, LEA_RSI, LEA_RDI, \ 511 LEA_R8, LEA_R9, LEA_R10, LEA_R11, LEA_R12, LEA_R13, LEA_R14, LEA_R15) 512 513 ; 514 ; We don't test all shift combinations, there just isn't enough space 515 ; in the image for that. 516 ; 517 %assign cShiftLoops 0 ; Disabled for now 518 %rep cShiftLoops 519 %error asdf 520 ; 521 ; LEA+SIB w/ 64-bit operand size and 64-bit address size. 522 ; 523 call .load_regs 524 %if iBase == 4 || iDstReg == 4 525 mov rsp, LEA_RSP 526 %endif 527 528 ; lea 529 %assign iValue iBase_Value + (iIndex_Value << cShift) 530 db X86_OP_REX_W | ((iBase & 8) >> 3) | ((iIndex & 8) >> 2) | ((iDstReg) & 8 >> 1) 531 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7), X86_SIB_MAKE(iBase & 7, iIndex & 7, cShift) 532 %if iMod == X86_MOD_MEM1 533 db -128 534 %assign iValue iValue - 128 535 %elif iMod == X86_MOD_MEM4 || (iMod == 0 && iBase == 5) 536 dd -07fffffffh 537 %assign iValue iValue - 07fffffffh 538 %endif 539 540 ; cmp iDstReg, iValue 541 %if iValue <= 07fffffffh && iValue >= -080000000h 542 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 543 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 544 dd iValue & 0ffffffffh 545 %elif iDstReg != X86_GREG_xAX 546 mov rax, iValue 547 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 548 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 549 %else 550 mov rcx, iValue 551 cmp rax, rcx 552 %endif 553 %if iDstReg == 4 554 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 555 %endif 556 jz $+3 557 int3 558 %assign cShift (cShift + 1) & 3 559 560 %endrep 561 %assign iIndex iIndex + 1 562 %endrep 563 %assign iBase iBase + 1 564 %endrep 565 566 %else ; !SIB 567 ; 568 ; Plain lea reg, [reg] with disp according to iMod, 569 ; or lea reg, [disp32] if iMemReg == 5 && iMod == 0. 570 ; 571 %if (iMemReg & 7) == 5 && iMod == 0 572 %assign iMemReg_Value 0 573 %else 574 %assign iMemReg_Value %sel(iMemReg+1, LEA_RAX, LEA_RCX, LEA_RDX, LEA_RBX, LEA_RSP, LEA_RBP, LEA_RSI, LEA_RDI, \ 575 LEA_R8, LEA_R9, LEA_R10, LEA_R11, LEA_R12, LEA_R13, LEA_R14, LEA_R15) 576 %endif 577 578 ; 579 ; 64-bit operand and address size first. 580 ; 581 call .load_regs 582 %if iDstReg == 4 583 mov rsp, LEA_RSP 584 %endif 585 586 ; lea 587 %assign iValue iMemReg_Value 588 db X86_OP_REX_W | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 589 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7) 590 %if iMod == X86_MOD_MEM1 591 db 39 592 %assign iValue iValue + 39 593 %elif iMod == 0 && (iMemReg & 7) == 5 594 dd .load_regs - $ - 4 595 %elif iMod == X86_MOD_MEM4 596 dd 058739af8h 597 %assign iValue iValue + 058739af8h 598 %endif 599 600 ; cmp iDstReg, iValue 601 %if (iValue <= 07fffffffh && iValue >= -080000000h) || (iMod == 0 && (iMemReg & 7) == 5) 602 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 603 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 604 %if iMod == 0 && (iMemReg & 7) == 5 605 dd .load_regs wrt BS3FLAT 606 %else 607 dd iValue & 0ffffffffh 608 %endif 609 %else 610 %if iDstReg != iMemReg && iValue == iMemReg_Value ; This isn't entirely safe, but it saves a bit of space. 611 db X86_OP_REX_W | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 612 db 39h, X86_MODRM_MAKE(X86_MOD_REG, iDstReg & 7, iMemReg & 7) 613 %elif iDstReg != X86_GREG_xAX 614 mov rax, iValue 615 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 616 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 617 %else 618 mov rcx, iValue 619 cmp rax, rcx 620 %endif 621 %endif 622 %if iDstReg == 4 623 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 624 %endif 625 jz $+3 626 int3 627 628 ; 629 ; 64-bit operand and 32-bit address size. 630 ; 631 call .load_regs 632 %if iDstReg == 4 633 mov rsp, LEA_RSP 634 %endif 635 636 ; lea 637 %assign iValue iMemReg_Value 638 db X86_OP_PRF_SIZE_ADDR 639 db X86_OP_REX_W | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 640 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7) 641 %if iMod == X86_MOD_MEM1 642 db -92 643 %assign iValue iValue - 92 644 %elif iMod == 0 && (iMemReg & 7) == 5 645 dd .test_label - $ - 4 646 %elif iMod == X86_MOD_MEM4 647 dd -038f8acf3h 648 %assign iValue iValue - 038f8acf3h 649 %endif 650 %assign iValue iValue & 0ffffffffh 651 652 ; cmp iDstReg, iValue 653 %if (iValue <= 07fffffffh && iValue >= 0) || (iMod == 0 && (iMemReg & 7) == 5) 654 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 655 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 656 %if iMod == 0 && (iMemReg & 7) == 5 657 dd .test_label wrt BS3FLAT 658 %else 659 dd iValue 660 %endif 661 %else 662 %if iDstReg != X86_GREG_xAX 663 mov eax, iValue 664 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 665 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 666 %else 667 mov ecx, iValue 668 cmp rax, rcx 669 %endif 670 %endif 671 %if iDstReg == 4 672 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 673 %endif 674 jz $+3 675 int3 676 677 ; 678 ; 32-bit operand and 64-bit address size. 679 ; 680 call .load_regs 681 %if iDstReg == 4 682 mov rsp, LEA_RSP 683 %endif 684 685 ; lea 686 %assign iValue iMemReg_Value 687 %if iDstReg >= 8 || iMemReg >= 8 688 db X86_OP_REX | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 689 %endif 690 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7) 691 %if iMod == X86_MOD_MEM1 692 db 16 693 %assign iValue iValue + 16 694 %elif iMod == 0 && (iMemReg & 7) == 5 695 dd .load_regs - $ - 4 696 %elif iMod == X86_MOD_MEM4 697 dd 0596829deh 698 %assign iValue iValue + 0596829deh 699 %endif 700 %assign iValue iValue & 0ffffffffh 701 702 ; cmp iDstReg, iValue 703 %if (iValue <= 07fffffffh && iValue >= 0) || (iMod == 0 && (iMemReg & 7) == 5) 704 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 705 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 706 %if iMod == 0 && (iMemReg & 7) == 5 707 dd .load_regs wrt BS3FLAT 708 %else 709 dd iValue 710 %endif 711 %else 712 %if iDstReg != X86_GREG_xAX 713 mov eax, iValue 714 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 715 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 716 %else 717 mov ecx, iValue 718 cmp rax, rcx 719 %endif 720 %endif 721 %if iDstReg == 4 722 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 723 %endif 724 jz $+3 725 int3 726 727 ; 728 ; 16-bit operand and 64-bit address size. 729 ; 730 call .load_regs 731 %if iDstReg == 4 732 mov rsp, LEA_RSP 733 %endif 734 735 ; lea 736 %assign iValue iMemReg_Value 737 db X86_OP_PRF_SIZE_OP 738 %if iDstReg >= 8 || iMemReg >= 8 739 db X86_OP_REX | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 740 %endif 741 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7) 742 %if iMod == X86_MOD_MEM1 743 db -16 744 %assign iValue iValue - 16 745 %elif iMod == 0 && (iMemReg & 7) == 5 746 dd _Bs3Text16_StartOfSegment - $ - 4 + 7 wrt BS3FLAT 747 %assign iValue 7 748 %elif iMod == X86_MOD_MEM4 749 dd 075682332h 750 %assign iValue iValue + 075682332h 751 %endif 752 %assign iValue (iValue & 0ffffh) | (iDstReg_Value & 0ffffffffffff0000h) 753 754 ; cmp iDstReg, iValue 755 %if (iValue <= 07fffffffh && iValue >= -080000000h) 756 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 757 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 758 dd iValue 759 %elif iDstReg != X86_GREG_xAX 760 mov rax, iValue 761 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 762 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 763 %else 764 mov rcx, iValue 765 cmp rax, rcx 766 %endif 767 %if iDstReg == 4 768 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 769 %endif 770 jz $+3 771 int3 772 773 ; 774 ; 16-bit operand and 32-bit address size. 775 ; 776 call .load_regs 777 %if iDstReg == 4 778 mov rsp, LEA_RSP 779 %endif 780 781 ; lea 782 %assign iValue iMemReg_Value 783 db X86_OP_PRF_SIZE_OP 784 db X86_OP_PRF_SIZE_ADDR 785 %if iDstReg >= 8 || iMemReg >= 8 786 db X86_OP_REX | ((iDstReg & 8) >> 1) | ((iMemReg & 8) >> 3) 787 %endif 788 db 8dh, X86_MODRM_MAKE(iMod, iDstReg & 7, iMemReg & 7) 789 %if iMod == X86_MOD_MEM1 790 db 99 791 %assign iValue iValue + 99 792 %elif iMod == 0 && (iMemReg & 7) == 5 793 dd _Bs3Text16_StartOfSegment - $ - 4 + 3347 wrt BS3FLAT 794 %assign iValue 3347 795 %elif iMod == X86_MOD_MEM4 796 dd -075623432h 797 %assign iValue iValue - 075623432h 798 %endif 799 %assign iValue (iValue & 0ffffh) | (iDstReg_Value & 0ffffffffffff0000h) 800 801 ; cmp iDstReg, iValue 802 %if (iValue <= 07fffffffh && iValue >= -080000000h) 803 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 804 db 81h, X86_MODRM_MAKE(X86_MOD_REG, 7, iDstReg & 7) 805 dd iValue 806 %elif iDstReg != X86_GREG_xAX 807 mov rax, iValue 808 db X86_OP_REX_W | ((iDstReg & 8) >> 3) 809 db 39h, X86_MODRM_MAKE(X86_MOD_REG, X86_GREG_xAX, iDstReg & 7) 810 %else 811 mov rcx, iValue 812 cmp rax, rcx 813 %endif 814 %if iDstReg == 4 815 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 816 %endif 817 jz $+3 818 int3 819 820 %endif ; !SIB 821 %assign iMemReg iMemReg + 1 822 %endrep 823 %assign iDstReg (iDstReg + 1) & 15 824 %endrep 825 %assign iMod iMod + 1 826 %endrep 827 828 mov rsp, [BS3_DATA16_WRT(BS3_DATA_NM(g_bs3CpuBasic3_lea_rsp))] 829 pop r15 830 pop r14 831 pop r13 832 pop r12 833 pop r11 834 pop r10 835 pop r9 836 pop r8 837 pop rdi 838 pop rsi 839 pop rbp 840 pop rbx 841 pop rdx 842 pop rcx 843 pop rax 844 ret 845 846 .load_regs: 847 mov rax, LEA_RAX 848 mov rcx, LEA_RCX 849 mov rdx, LEA_RDX 850 mov rbx, LEA_RBX 851 mov rbp, LEA_RBP 852 mov rsi, LEA_RSI 853 mov rdi, LEA_RDI 854 mov r8, LEA_R8 855 mov r9, LEA_R9 856 mov r10, LEA_R10 857 mov r11, LEA_R11 858 mov r12, LEA_R12 859 mov r13, LEA_R13 860 mov r14, LEA_R14 861 mov r15, LEA_R15 862 ret 863 BS3_PROC_END_CMN bs3CpuBasic3_lea_64 864 865 %endif ; TMPL_BITS == 64 439 %endif ; TMPL_BITS != 64 866 440 867 441
Note:
See TracChangeset
for help on using the changeset viewer.