Changeset 9271 in vbox for trunk/src/VBox
- Timestamp:
- May 31, 2008 6:11:10 PM (17 years ago)
- Location:
- trunk/src/VBox/Disassembler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Disassembler/DisasmFormatYasm.cpp
r9266 r9271 314 314 #define PUT_SZ(sz) \ 315 315 PUT_STR((sz), sizeof(sz) - 1) 316 #define PUT_SZ_STRICT(szStrict, szRelaxed) \ 317 do { if (fFlags & DIS_FMT_FLAGS_STRICT) PUT_SZ(szStrict); else PUT_SZ(szRelaxed); } while (0) 316 318 #define PUT_PSZ(psz) \ 317 319 do { const size_t cchTmp = strlen(psz); PUT_STR((psz), cchTmp); } while (0) … … 331 333 #define PUT_NUM_32(num) PUT_NUM(10, "0%08xh", (uint32_t)(num)) 332 334 #define PUT_NUM_64(num) PUT_NUM(18, "0%08xh", (uint64_t)(num)) 335 336 #define PUT_NUM_SIGN(cch, fmt, num, stype, utype) \ 337 do { \ 338 if ((stype)(num) >= 0) \ 339 { \ 340 PUT_C('+'); \ 341 PUT_NUM(cch, fmt, (utype)(num)); \ 342 } \ 343 else \ 344 { \ 345 PUT_C('-'); \ 346 PUT_NUM(cch, fmt, (utype)-(stype)(num)); \ 347 } \ 348 } while (0) 349 #define PUT_NUM_S8(num) PUT_NUM_SIGN(4, "0%02xh", num, int8_t, uint8_t) 350 #define PUT_NUM_S16(num) PUT_NUM_SIGN(6, "0%04xh", num, int16_t, uint16_t) 351 #define PUT_NUM_S32(num) PUT_NUM_SIGN(10, "0%08xh", num, int32_t, uint32_t) 352 #define PUT_NUM_S64(num) PUT_NUM_SIGN(18, "0%08xh", num, int64_t, uint64_t) 353 333 354 334 355 /* … … 614 635 * The formatting loop. 615 636 */ 637 RTINTPTR off; 638 char szSymbol[128]; 616 639 char ch; 617 640 while ((ch = *pszFmt++) != '\0') … … 666 689 PUT_C('['); 667 690 } 668 if (pParam->flags & (USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32 | USE_DISPLACEMENT64 | USE_RIPDISPLACEMENT32)) 691 if ( (fFlags & DIS_FMT_FLAGS_STRICT) 692 && (pParam->flags & (USE_DISPLACEMENT8 | USE_DISPLACEMENT16 | USE_DISPLACEMENT32 | USE_DISPLACEMENT64 | USE_RIPDISPLACEMENT32))) 669 693 { 670 694 if ( (pParam->flags & USE_DISPLACEMENT8) … … 753 777 { 754 778 case USE_IMMEDIATE8: 755 if ( (pOp->param1 >= OP_PARM_REG_GEN8_START && pOp->param1 <= OP_PARM_REG_GEN8_END) 756 || (pOp->param2 >= OP_PARM_REG_GEN8_START && pOp->param2 <= OP_PARM_REG_GEN8_END) 757 ) 779 if ( (fFlags & DIS_FMT_FLAGS_STRICT) 780 && ( (pOp->param1 >= OP_PARM_REG_GEN8_START && pOp->param1 <= OP_PARM_REG_GEN8_END) 781 || (pOp->param2 >= OP_PARM_REG_GEN8_START && pOp->param2 <= OP_PARM_REG_GEN8_END)) 782 ) 758 783 PUT_SZ("strict byte "); 759 784 PUT_NUM_8(pParam->parval); … … 761 786 762 787 case USE_IMMEDIATE16: 763 if ( (int8_t)pParam->parval == (int16_t)pParam->parval 764 || (pOp->param1 >= OP_PARM_REG_GEN16_START && pOp->param1 <= OP_PARM_REG_GEN16_END) 765 || (pOp->param2 >= OP_PARM_REG_GEN16_START && pOp->param2 <= OP_PARM_REG_GEN16_END) 766 || pCpu->mode != pCpu->opmode 788 if ( pCpu->mode != pCpu->opmode 789 || ( (fFlags & DIS_FMT_FLAGS_STRICT) 790 && ( (int8_t)pParam->parval == (int16_t)pParam->parval 791 || (pOp->param1 >= OP_PARM_REG_GEN16_START && pOp->param1 <= OP_PARM_REG_GEN16_END) 792 || (pOp->param2 >= OP_PARM_REG_GEN16_START && pOp->param2 <= OP_PARM_REG_GEN16_END)) 793 ) 794 ) 795 { 796 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_b) 797 PUT_SZ_STRICT("strict byte ", "byte "); 798 else if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_v) 799 PUT_SZ_STRICT("strict word ", "word "); 800 } 801 PUT_NUM_16(pParam->parval); 802 break; 803 804 case USE_IMMEDIATE16_SX8: 805 PUT_SZ_STRICT("strict byte ", "byte "); 806 PUT_NUM_16(pParam->parval); 807 break; 808 809 case USE_IMMEDIATE32: 810 if ( pCpu->opmode != (pCpu->mode == CPUMODE_16BIT ? CPUMODE_16BIT : CPUMODE_32BIT) /* not perfect */ 811 || ( (fFlags & DIS_FMT_FLAGS_STRICT) 812 && ( (int8_t)pParam->parval == (int32_t)pParam->parval 813 || (pOp->param1 >= OP_PARM_REG_GEN32_START && pOp->param1 <= OP_PARM_REG_GEN32_END) 814 || (pOp->param2 >= OP_PARM_REG_GEN32_START && pOp->param2 <= OP_PARM_REG_GEN32_END)) 815 ) 767 816 ) 768 817 { 769 818 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_b) 770 PUT_SZ ("strictbyte ");819 PUT_SZ_STRICT("strict byte ", "byte "); 771 820 else if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_v) 772 PUT_SZ("strict word "); 773 } 774 PUT_NUM_16(pParam->parval); 775 break; 776 777 case USE_IMMEDIATE16_SX8: 778 PUT_SZ("strict byte "); 779 PUT_NUM_16(pParam->parval); 780 break; 781 782 case USE_IMMEDIATE32: 783 if ( (int8_t)pParam->parval == (int32_t)pParam->parval 784 || (pOp->param1 >= OP_PARM_REG_GEN32_START && pOp->param1 <= OP_PARM_REG_GEN32_END) 785 || (pOp->param2 >= OP_PARM_REG_GEN32_START && pOp->param2 <= OP_PARM_REG_GEN32_END) 786 || pCpu->opmode != (pCpu->mode == CPUMODE_16BIT ? CPUMODE_16BIT : CPUMODE_32BIT) /* not perfect */ 787 ) 788 { 789 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_b) 790 PUT_SZ("strict byte "); 791 else if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_v) 792 PUT_SZ("strict dword "); 821 PUT_SZ_STRICT("strict dword ", "dword "); 793 822 } 794 823 PUT_NUM_32(pParam->parval); … … 796 825 797 826 case USE_IMMEDIATE32_SX8: 798 PUT_SZ ("strictbyte ");827 PUT_SZ_STRICT("strict byte ", "byte "); 799 828 PUT_NUM_32(pParam->parval); 800 829 break; … … 814 843 int32_t offDisplacement; 815 844 Assert(iParam == 1); 816 bool fPrefix = pOp->opcode != OP_CALL 845 bool fPrefix = (fFlags & DIS_FMT_FLAGS_STRICT) 846 && pOp->opcode != OP_CALL 817 847 && pOp->opcode != OP_LOOP 818 848 && pOp->opcode != OP_LOOPE … … 826 856 offDisplacement = (int8_t)pParam->parval; 827 857 Assert(*pszFmt == 'b'); pszFmt++; 858 859 if (fFlags & DIS_FMT_FLAGS_RELATIVE_BRANCH) 860 PUT_NUM_S8(offDisplacement); 828 861 } 829 862 else if (pParam->flags & USE_IMMEDIATE16_REL) … … 833 866 offDisplacement = (int16_t)pParam->parval; 834 867 Assert(*pszFmt == 'v'); pszFmt++; 868 869 if (fFlags & DIS_FMT_FLAGS_RELATIVE_BRANCH) 870 PUT_NUM_S16(offDisplacement); 835 871 } 836 872 else … … 841 877 Assert(pParam->flags & USE_IMMEDIATE32_REL); 842 878 Assert(*pszFmt == 'v'); pszFmt++; 843 } 879 880 if (fFlags & DIS_FMT_FLAGS_RELATIVE_BRANCH) 881 PUT_NUM_S32(offDisplacement); 882 } 883 if (fFlags & DIS_FMT_FLAGS_RELATIVE_BRANCH) 884 PUT_SZ(" ("); 844 885 845 886 RTUINTPTR uTrgAddr = pCpu->opaddr + pCpu->opsize + offDisplacement; … … 850 891 else 851 892 PUT_NUM_64(uTrgAddr); 893 894 if (pfnGetSymbol) 895 { 896 int rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), uTrgAddr, szSymbol, sizeof(szSymbol), &off, pvUser); 897 if (RT_SUCCESS(rc)) 898 { 899 PUT_SZ(" ["); 900 PUT_PSZ(szSymbol); 901 if (off != 0) 902 { 903 if ((int8_t)off == off) 904 PUT_NUM_S8(off); 905 else if ((int16_t)off == off) 906 PUT_NUM_S16(off); 907 else if ((int32_t)off == off) 908 PUT_NUM_S32(off); 909 else 910 PUT_NUM_S64(off); 911 } 912 PUT_C(']'); 913 } 914 } 915 916 if (fFlags & DIS_FMT_FLAGS_RELATIVE_BRANCH) 917 PUT_C(')'); 852 918 break; 853 919 } 854 920 855 921 case 'A': /* Direct (jump/call) address (ParseImmAddr). */ 922 { 856 923 Assert(*pszFmt == 'p'); pszFmt++; 857 924 PUT_FAR(); 858 925 PUT_SIZE_OVERRIDE(); 859 926 PUT_SEGMENT_OVERRIDE(); 927 int rc; 860 928 switch (pParam->flags & (USE_IMMEDIATE_ADDR_16_16 | USE_IMMEDIATE_ADDR_16_32 | USE_DISPLACEMENT64 | USE_DISPLACEMENT32 | USE_DISPLACEMENT16)) 861 929 { … … 864 932 PUT_C(':'); 865 933 PUT_NUM_16(pParam->parval); 934 if (pfnGetSymbol) 935 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_VALUE(pParam->parval >> 16), (uint16_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 866 936 break; 867 937 case USE_IMMEDIATE_ADDR_16_32: … … 869 939 PUT_C(':'); 870 940 PUT_NUM_32(pParam->parval); 941 if (pfnGetSymbol) 942 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_VALUE(pParam->parval >> 16), (uint32_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 871 943 break; 872 944 case USE_DISPLACEMENT16: 873 945 PUT_NUM_16(pParam->parval); 946 if (pfnGetSymbol) 947 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint16_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 874 948 break; 875 949 case USE_DISPLACEMENT32: 876 950 PUT_NUM_32(pParam->parval); 951 if (pfnGetSymbol) 952 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint32_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 877 953 break; 878 954 case USE_DISPLACEMENT64: 879 955 PUT_NUM_64(pParam->parval); 956 if (pfnGetSymbol) 957 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint64_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 880 958 break; 881 959 default: … … 883 961 break; 884 962 } 963 964 if (pfnGetSymbol && RT_SUCCESS(rc)) 965 { 966 PUT_SZ(" ["); 967 PUT_PSZ(szSymbol); 968 if (off != 0) 969 { 970 if ((int8_t)off == off) 971 PUT_NUM_S8(off); 972 else if ((int16_t)off == off) 973 PUT_NUM_S16(off); 974 else if ((int32_t)off == off) 975 PUT_NUM_S32(off); 976 else 977 PUT_NUM_S64(off); 978 } 979 PUT_C(']'); 980 } 885 981 break; 982 } 886 983 887 984 case 'O': /* No ModRM byte (ParseImmAddr). */ 985 { 888 986 Assert(*pszFmt == 'b' || *pszFmt == 'v'); pszFmt++; 889 987 PUT_FAR(); … … 891 989 PUT_C('['); 892 990 PUT_SEGMENT_OVERRIDE(); 991 int rc; 893 992 switch (pParam->flags & (USE_IMMEDIATE_ADDR_16_16 | USE_IMMEDIATE_ADDR_16_32 | USE_DISPLACEMENT64 | USE_DISPLACEMENT32 | USE_DISPLACEMENT16)) 894 993 { … … 897 996 PUT_C(':'); 898 997 PUT_NUM_16(pParam->parval); 998 if (pfnGetSymbol) 999 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_VALUE(pParam->parval >> 16), (uint16_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 899 1000 break; 900 1001 case USE_IMMEDIATE_ADDR_16_32: … … 902 1003 PUT_C(':'); 903 1004 PUT_NUM_32(pParam->parval); 1005 if (pfnGetSymbol) 1006 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_VALUE(pParam->parval >> 16), (uint32_t)pParam->parval, szSymbol, sizeof(szSymbol), &off, pvUser); 904 1007 break; 905 1008 case USE_DISPLACEMENT16: 906 1009 PUT_NUM_16(pParam->disp16); 1010 if (pfnGetSymbol) 1011 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint16_t)pParam->disp16, szSymbol, sizeof(szSymbol), &off, pvUser); 907 1012 break; 908 1013 case USE_DISPLACEMENT32: 909 1014 PUT_NUM_32(pParam->disp32); 1015 if (pfnGetSymbol) 1016 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint32_t)pParam->disp32, szSymbol, sizeof(szSymbol), &off, pvUser); 910 1017 break; 911 1018 case USE_DISPLACEMENT64: 912 1019 PUT_NUM_64(pParam->disp64); 1020 if (pfnGetSymbol) 1021 rc = pfnGetSymbol(DIS_FMT_SEL_FROM_REG(USE_REG_CS), (uint64_t)pParam->disp64, szSymbol, sizeof(szSymbol), &off, pvUser); 913 1022 break; 914 1023 default: … … 917 1026 } 918 1027 PUT_C(']'); 1028 1029 if (pfnGetSymbol && RT_SUCCESS(rc)) 1030 { 1031 PUT_SZ(" ("); 1032 PUT_PSZ(szSymbol); 1033 if (off != 0) 1034 { 1035 if ((int8_t)off == off) 1036 PUT_NUM_S8(off); 1037 else if ((int16_t)off == off) 1038 PUT_NUM_S16(off); 1039 else if ((int32_t)off == off) 1040 PUT_NUM_S32(off); 1041 else 1042 PUT_NUM_S64(off); 1043 } 1044 PUT_C(')'); 1045 } 919 1046 break; 1047 } 920 1048 921 1049 case 'X': /* DS:SI (ParseXb, ParseXv). */ -
trunk/src/VBox/Disassembler/testcase/tstDisasm-2.cpp
r9266 r9271 95 95 #else 96 96 size_t cch = DISFormatYasmEx(&pState->Cpu, szTmp, sizeof(szTmp), 97 DIS_FMT_FLAGS_ ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_COMMENT97 DIS_FMT_FLAGS_STRICT | DIS_FMT_FLAGS_ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_COMMENT 98 98 | DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_COMMENT | DIS_FMT_FLAGS_BYTES_SPACED, 99 99 NULL, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.