| | 842 | |
|---|
| | 843 | |
|---|
| | 844 | %if 0 |
|---|
| | 845 | ;; |
|---|
| | 846 | ; Emulate LOCK CMPXCHG instruction, CDECL calling conv. |
|---|
| | 847 | ; EMDECL(uint32_t) EMEmulateLockCmpXchg32(RTHCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize); |
|---|
| | 848 | ; |
|---|
| | 849 | ; @returns EFLAGS after the operation, only arithmetic flags is valid. |
|---|
| | 850 | ; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to first parameter |
|---|
| | 851 | ; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - pointer to second parameter (eax) |
|---|
| | 852 | ; @param [esp + 0ch] gcc:rdx msc:r8 Param 3 - third parameter |
|---|
| | 853 | ; @param [esp + 10h] gcc:rcx msc:r9 Param 4 - Size of parameters, only 1/2/4 is valid |
|---|
| | 854 | ; @uses eax, ecx, edx |
|---|
| | 855 | ; |
|---|
| | 856 | align 16 |
|---|
| | 857 | BEGINPROC EMEmulateLockCmpXchg32 |
|---|
| | 858 | push ebx |
|---|
| | 859 | mov ecx, [esp + 04h + 4] ; ecx = first parameter |
|---|
| | 860 | mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax) |
|---|
| | 861 | mov edx, [esp + 0ch + 4] ; edx = third parameter |
|---|
| | 862 | mov eax, [esp + 10h + 4] ; eax = size of parameters |
|---|
| | 863 | |
|---|
| | 864 | cmp al, 4 |
|---|
| | 865 | je short .do_dword ; 4 bytes variant |
|---|
| | 866 | cmp al, 2 |
|---|
| | 867 | je short .do_word ; 2 byte variant |
|---|
| | 868 | cmp al, 1 |
|---|
| | 869 | je short .do_byte ; 1 bytes variant |
|---|
| | 870 | int3 |
|---|
| | 871 | |
|---|
| | 872 | .do_dword: |
|---|
| | 873 | ; load 2nd parameter's value |
|---|
| | 874 | mov eax, dword [ebx] |
|---|
| | 875 | |
|---|
| | 876 | lock cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG |
|---|
| | 877 | mov dword [ebx], eax |
|---|
| | 878 | jmp short .done |
|---|
| | 879 | |
|---|
| | 880 | .do_word: |
|---|
| | 881 | ; load 2nd parameter's value |
|---|
| | 882 | mov eax, dword [ebx] |
|---|
| | 883 | |
|---|
| | 884 | lock cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG |
|---|
| | 885 | mov word [ebx], ax |
|---|
| | 886 | jmp short .done |
|---|
| | 887 | |
|---|
| | 888 | .do_byte: |
|---|
| | 889 | ; load 2nd parameter's value |
|---|
| | 890 | mov eax, dword [ebx] |
|---|
| | 891 | |
|---|
| | 892 | lock cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG |
|---|
| | 893 | mov byte [ebx], al |
|---|
| | 894 | |
|---|
| | 895 | .done: |
|---|
| | 896 | ; collect flags and return. |
|---|
| | 897 | pushf |
|---|
| | 898 | pop eax |
|---|
| | 899 | |
|---|
| | 900 | mov edx, [esp + 14h + 4] ; eflags pointer |
|---|
| | 901 | mov dword [edx], eax |
|---|
| | 902 | |
|---|
| | 903 | pop ebx |
|---|
| | 904 | mov eax, VINF_SUCCESS |
|---|
| | 905 | retn |
|---|
| | 906 | |
|---|
| | 907 | ; Read error - we will be here after our page fault handler. |
|---|
| | 908 | GLOBALNAME EMEmulateLockCmpXchg32_Error |
|---|
| | 909 | pop ebx |
|---|
| | 910 | mov eax, VERR_ACCESS_DENIED |
|---|
| | 911 | ret |
|---|
| | 912 | |
|---|
| | 913 | ENDPROC EMEmulateLockCmpXchg32 |
|---|
| | 914 | |
|---|
| | 915 | ;; |
|---|
| | 916 | ; Emulate CMPXCHG instruction, CDECL calling conv. |
|---|
| | 917 | ; EMDECL(uint32_t) EMEmulateCmpXchg32(RTHCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize); |
|---|
| | 918 | ; |
|---|
| | 919 | ; @returns EFLAGS after the operation, only arithmetic flags is valid. |
|---|
| | 920 | ; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to first parameter |
|---|
| | 921 | ; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - pointer to second parameter (eax) |
|---|
| | 922 | ; @param [esp + 0ch] gcc:rdx msc:r8 Param 3 - third parameter |
|---|
| | 923 | ; @param [esp + 10h] gcc:rcx msc:r9 Param 4 - Size of parameters, only 1/2/4 is valid. |
|---|
| | 924 | ; @uses eax, ecx, edx |
|---|
| | 925 | ; |
|---|
| | 926 | align 16 |
|---|
| | 927 | BEGINPROC EMEmulateCmpXchg32 |
|---|
| | 928 | push ebx |
|---|
| | 929 | mov ecx, [esp + 04h + 4] ; ecx = first parameter |
|---|
| | 930 | mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax) |
|---|
| | 931 | mov edx, [esp + 0ch + 4] ; edx = third parameter |
|---|
| | 932 | mov eax, [esp + 10h + 4] ; eax = size of parameters |
|---|
| | 933 | |
|---|
| | 934 | cmp al, 4 |
|---|
| | 935 | je short .do_dword ; 4 bytes variant |
|---|
| | 936 | cmp al, 2 |
|---|
| | 937 | je short .do_word ; 2 byte variant |
|---|
| | 938 | cmp al, 1 |
|---|
| | 939 | je short .do_byte ; 1 bytes variant |
|---|
| | 940 | int3 |
|---|
| | 941 | |
|---|
| | 942 | .do_dword: |
|---|
| | 943 | ; load 2nd parameter's value |
|---|
| | 944 | mov eax, dword [ebx] |
|---|
| | 945 | |
|---|
| | 946 | cmpxchg dword [ecx], edx ; do 4 bytes CMPXCHG |
|---|
| | 947 | mov dword [ebx], eax |
|---|
| | 948 | jmp short .done |
|---|
| | 949 | |
|---|
| | 950 | .do_word: |
|---|
| | 951 | ; load 2nd parameter's value |
|---|
| | 952 | mov eax, dword [ebx] |
|---|
| | 953 | |
|---|
| | 954 | cmpxchg word [ecx], dx ; do 2 bytes CMPXCHG |
|---|
| | 955 | mov word [ebx], ax |
|---|
| | 956 | jmp short .done |
|---|
| | 957 | |
|---|
| | 958 | .do_byte: |
|---|
| | 959 | ; load 2nd parameter's value |
|---|
| | 960 | mov eax, dword [ebx] |
|---|
| | 961 | |
|---|
| | 962 | cmpxchg byte [ecx], dl ; do 1 bytes CMPXCHG |
|---|
| | 963 | mov byte [ebx], al |
|---|
| | 964 | |
|---|
| | 965 | .done: |
|---|
| | 966 | ; collect flags and return. |
|---|
| | 967 | pushf |
|---|
| | 968 | pop eax |
|---|
| | 969 | |
|---|
| | 970 | mov edx, [esp + 14h + 4] ; eflags pointer |
|---|
| | 971 | mov dword [edx], eax |
|---|
| | 972 | |
|---|
| | 973 | pop ebx |
|---|
| | 974 | mov eax, VINF_SUCCESS |
|---|
| | 975 | retn |
|---|
| | 976 | |
|---|
| | 977 | ; Read error - we will be here after our page fault handler. |
|---|
| | 978 | GLOBALNAME EMEmulateCmpXchg32_Error |
|---|
| | 979 | pop ebx |
|---|
| | 980 | mov eax, VERR_ACCESS_DENIED |
|---|
| | 981 | ret |
|---|
| | 982 | ENDPROC EMEmulateCmpXchg32 |
|---|
| | 983 | |
|---|
| | 984 | ;; |
|---|
| | 985 | ; Emulate LOCK CMPXCHG8B instruction, CDECL calling conv. |
|---|
| | 986 | ; EMDECL(uint32_t) EMEmulateLockCmpXchg8b(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX); |
|---|
| | 987 | ; |
|---|
| | 988 | ; @returns EFLAGS after the operation, only arithmetic flags is valid. |
|---|
| | 989 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter |
|---|
| | 990 | ; @param [esp + 08h] Param 2 - Address of the eax register |
|---|
| | 991 | ; @param [esp + 0ch] Param 3 - Address of the edx register |
|---|
| | 992 | ; @param [esp + 10h] Param 4 - EBX |
|---|
| | 993 | ; @param [esp + 14h] Param 5 - ECX |
|---|
| | 994 | ; @uses eax, ecx, edx |
|---|
| | 995 | ; |
|---|
| | 996 | align 16 |
|---|
| | 997 | BEGINPROC EMEmulateLockCmpXchg8b32 |
|---|
| | 998 | push ebp |
|---|
| | 999 | push ebx |
|---|
| | 1000 | mov ebp, [esp + 04h + 8] ; ebp = first parameter |
|---|
| | 1001 | mov eax, [esp + 08h + 8] ; &EAX |
|---|
| | 1002 | mov eax, dword [eax] |
|---|
| | 1003 | mov edx, [esp + 0ch + 8] ; &EDX |
|---|
| | 1004 | mov edx, dword [edx] |
|---|
| | 1005 | mov ebx, [esp + 10h + 8] ; EBX |
|---|
| | 1006 | mov ecx, [esp + 14h + 8] ; ECX |
|---|
| | 1007 | |
|---|
| | 1008 | lock cmpxchg8b qword [ebp] ; do CMPXCHG8B |
|---|
| | 1009 | mov dword [esp + 08h + 8], eax |
|---|
| | 1010 | mov dword [esp + 0ch + 8], edx |
|---|
| | 1011 | |
|---|
| | 1012 | ; collect flags and return. |
|---|
| | 1013 | pushf |
|---|
| | 1014 | pop eax |
|---|
| | 1015 | |
|---|
| | 1016 | mov edx, [esp + 18h + 8] ; eflags pointer |
|---|
| | 1017 | mov dword [edx], eax |
|---|
| | 1018 | |
|---|
| | 1019 | pop ebx |
|---|
| | 1020 | pop ebp |
|---|
| | 1021 | mov eax, VINF_SUCCESS |
|---|
| | 1022 | retn |
|---|
| | 1023 | |
|---|
| | 1024 | ; Read error - we will be here after our page fault handler. |
|---|
| | 1025 | GLOBALNAME EMEmulateLockCmpXchg8b32_Error |
|---|
| | 1026 | pop ebx |
|---|
| | 1027 | pop ebp |
|---|
| | 1028 | mov eax, VERR_ACCESS_DENIED |
|---|
| | 1029 | ret |
|---|
| | 1030 | |
|---|
| | 1031 | ENDPROC EMEmulateLockCmpXchg8b32 |
|---|
| | 1032 | |
|---|
| | 1033 | ;; |
|---|
| | 1034 | ; Emulate CMPXCHG8B instruction, CDECL calling conv. |
|---|
| | 1035 | ; EMDECL(uint32_t) EMEmulateCmpXchg8b32(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX); |
|---|
| | 1036 | ; |
|---|
| | 1037 | ; @returns EFLAGS after the operation, only arithmetic flags is valid. |
|---|
| | 1038 | ; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter |
|---|
| | 1039 | ; @param [esp + 08h] Param 2 - Address of the eax register |
|---|
| | 1040 | ; @param [esp + 0ch] Param 3 - Address of the edx register |
|---|
| | 1041 | ; @param [esp + 10h] Param 4 - EBX |
|---|
| | 1042 | ; @param [esp + 14h] Param 5 - ECX |
|---|
| | 1043 | ; @uses eax, ecx, edx |
|---|
| | 1044 | ; |
|---|
| | 1045 | align 16 |
|---|
| | 1046 | BEGINPROC EMEmulateCmpXchg8b32 |
|---|
| | 1047 | push ebp |
|---|
| | 1048 | push ebx |
|---|
| | 1049 | mov ebp, [esp + 04h + 8] ; ebp = first parameter |
|---|
| | 1050 | mov eax, [esp + 08h + 8] ; &EAX |
|---|
| | 1051 | mov eax, dword [eax] |
|---|
| | 1052 | mov edx, [esp + 0ch + 8] ; &EDX |
|---|
| | 1053 | mov edx, dword [edx] |
|---|
| | 1054 | mov ebx, [esp + 10h + 8] ; EBX |
|---|
| | 1055 | mov ecx, [esp + 14h + 8] ; ECX |
|---|
| | 1056 | |
|---|
| | 1057 | cmpxchg8b qword [ebp] ; do CMPXCHG8B |
|---|
| | 1058 | mov dword [esp + 08h + 8], eax |
|---|
| | 1059 | mov dword [esp + 0ch + 8], edx |
|---|
| | 1060 | |
|---|
| | 1061 | ; collect flags and return. |
|---|
| | 1062 | pushf |
|---|
| | 1063 | pop eax |
|---|
| | 1064 | |
|---|
| | 1065 | mov edx, [esp + 18h + 8] ; eflags pointer |
|---|
| | 1066 | mov dword [edx], eax |
|---|
| | 1067 | |
|---|
| | 1068 | pop ebx |
|---|
| | 1069 | pop ebp |
|---|
| | 1070 | mov eax, VINF_SUCCESS |
|---|
| | 1071 | retn |
|---|
| | 1072 | |
|---|
| | 1073 | ; Read error - we will be here after our page fault handler. |
|---|
| | 1074 | GLOBALNAME EMEmulateCmpXchg8b32_Error |
|---|
| | 1075 | pop ebx |
|---|
| | 1076 | pop ebp |
|---|
| | 1077 | mov eax, VERR_ACCESS_DENIED |
|---|
| | 1078 | ret |
|---|
| | 1079 | ENDPROC EMEmulateCmpXchg8b32 |
|---|
| | 1080 | |
|---|
| | 1081 | %endif |
|---|