1#include "tests/asm.h" 2#include <stdio.h> 3 4/* This test only checks register/register cmpxchg */ 5 6typedef unsigned long long int ULong; 7typedef unsigned int UInt; 8 9ULong m64; 10 11ULong rax; 12ULong rbx; 13ULong rcx; 14ULong rdx; 15ULong rax_out; 16ULong rbx_out; 17ULong rcx_out; 18 19int main ( void ) 20{ 21 22 /* 8-bit */ 23 24 rdx = 0x11111111; rax = 0x22222222; 25 rcx = 0x33333333; rbx = 0x44444444; 26 27 printf("cmpxchg %%bl,%%cl (al=%llx bl=%llx cl=%llx)\n", 28 rax&0xff,rbx&0xff,rcx&0xff); 29 30 asm("\n" 31 "\tpush %rax\n" 32 "\tpush %rbx\n" 33 "\tpush %rcx\n" 34 "\tpush %rdx\n" 35 "\txor %rax, %rax\n" // get eflags in a known state 36 "\tmov " VG_SYM(rax) ",%rax\n" 37 "\tmov " VG_SYM(rbx) ",%rbx\n" 38 "\tmov " VG_SYM(rcx) ",%rcx\n" 39 "\tmov " VG_SYM(rdx) ",%rdx\n" 40 "\tcmpxchg %bl,%cl \n" 41 "\tmov %rax," VG_SYM(rax_out) "\n" 42 "\tmov %rbx," VG_SYM(rbx_out) "\n" 43 "\tmov %rcx," VG_SYM(rcx_out) "\n" 44 "\tpop %rdx\n" 45 "\tpop %rcx\n" 46 "\tpop %rbx\n" 47 "\tpop %rax\n" 48 ); 49 50 printf(" al!=cl so al should equal cl (Result al=%llx bl=%llx cl=%llx)\n", 51 rax_out&0xff,rbx_out&0xff,rcx_out&0xff); 52 53 54 55 rdx = 0x99999999; rax = 0x77777777; 56 rcx = 0x55555555; rbx = 0x55555555; 57 58 printf("cmpxchg %%bl,%%cl (al=%llx bl=%llx cl=%llx)\n", 59 rax&0xff,rbx&0xff,rcx&0xff); 60 61 asm("\n" 62 "\tpush %rax\n" 63 "\tpush %rbx\n" 64 "\tpush %rcx\n" 65 "\tpush %rdx\n" 66 "\txor %rax, %rax\n" // get eflags in a known state 67 "\tmov " VG_SYM(rax) ",%rax\n" 68 "\tmov " VG_SYM(rbx) ",%rbx\n" 69 "\tmov " VG_SYM(rcx) ",%rcx\n" 70 "\tmov " VG_SYM(rdx) ",%rdx\n" 71 "\tcmpxchg %bl,%cl \n" 72 "\tmov %rax," VG_SYM(rax_out) "\n" 73 "\tmov %rbx," VG_SYM(rbx_out) "\n" 74 "\tmov %rcx," VG_SYM(rcx_out) "\n" 75 "\tpop %rdx\n" 76 "\tpop %rcx\n" 77 "\tpop %rbx\n" 78 "\tpop %rax\n" 79 ); 80 81 printf(" al==cl so cl should equal bl (Result al=%llx bl=%llx cl=%llx)\n", 82 rax_out&0xff,rbx_out&0xff,rcx_out&0xff); 83 84 /* 16-bit */ 85 86 rdx = 0x11111111; rax = 0x22222222; 87 rcx = 0x33333333; rbx = 0x44444444; 88 89 printf("cmpxchg %%bx,%%cx (ax=%llx bx=%llx cx=%llx)\n", 90 rax&0xffff,rbx&0xffff,rcx&0xffff); 91 92 asm("\n" 93 "\tpush %rax\n" 94 "\tpush %rbx\n" 95 "\tpush %rcx\n" 96 "\tpush %rdx\n" 97 "\txor %rax, %rax\n" // get eflags in a known state 98 "\tmov " VG_SYM(rax) ",%rax\n" 99 "\tmov " VG_SYM(rbx) ",%rbx\n" 100 "\tmov " VG_SYM(rcx) ",%rcx\n" 101 "\tmov " VG_SYM(rdx) ",%rdx\n" 102 "\tcmpxchg %bx,%cx \n" 103 "\tmov %rax," VG_SYM(rax_out) "\n" 104 "\tmov %rbx," VG_SYM(rbx_out) "\n" 105 "\tmov %rcx," VG_SYM(rcx_out) "\n" 106 "\tpop %rdx\n" 107 "\tpop %rcx\n" 108 "\tpop %rbx\n" 109 "\tpop %rax\n" 110 ); 111 112 printf(" ax!=cx so ax should equal cx (Result ax=%llx bx=%llx cx=%llx)\n", 113 rax_out&0xffff,rbx_out&0xffff,rcx_out&0xffff); 114 115 116 117 rdx = 0x99999999; rax = 0x77777777; 118 rcx = 0x55555555; rbx = 0x55555555; 119 120 printf("cmpxchg %%bx,%%cx (ax=%llx bx=%llx cx=%llx)\n", 121 rax&0xffff,rbx&0xffff,rcx&0xffff); 122 123 asm("\n" 124 "\tpush %rax\n" 125 "\tpush %rbx\n" 126 "\tpush %rcx\n" 127 "\tpush %rdx\n" 128 "\txor %rax, %rax\n" // get eflags in a known state 129 "\tmov " VG_SYM(rax) ",%rax\n" 130 "\tmov " VG_SYM(rbx) ",%rbx\n" 131 "\tmov " VG_SYM(rcx) ",%rcx\n" 132 "\tmov " VG_SYM(rdx) ",%rdx\n" 133 "\tcmpxchg %bx,%cx \n" 134 "\tmov %rax," VG_SYM(rax_out) "\n" 135 "\tmov %rbx," VG_SYM(rbx_out) "\n" 136 "\tmov %rcx," VG_SYM(rcx_out) "\n" 137 "\tpop %rdx\n" 138 "\tpop %rcx\n" 139 "\tpop %rbx\n" 140 "\tpop %rax\n" 141 ); 142 143 printf(" ax==cx so cx should equal bx (Result ax=%llx bx=%llx cx=%llx)\n", 144 rax_out&0xffff,rbx_out&0xffff,rcx_out&0xffff); 145 146 147 /* 32-bit */ 148 149 rdx = 0x11111111; rax = 0x22222222; 150 rcx = 0x33333333; rbx = 0x44444444; 151 152 printf("cmpxchg %%ebx,%%ecx (eax=%llx ebx=%llx ecx=%llx)\n", 153 rax&0xffffffff,rbx&0xffffffff,rcx&0xffffffff); 154 155 asm("\n" 156 "\tpush %rax\n" 157 "\tpush %rbx\n" 158 "\tpush %rcx\n" 159 "\tpush %rdx\n" 160 "\txor %rax, %rax\n" // get eflags in a known state 161 "\tmov " VG_SYM(rax) ",%rax\n" 162 "\tmov " VG_SYM(rbx) ",%rbx\n" 163 "\tmov " VG_SYM(rcx) ",%rcx\n" 164 "\tmov " VG_SYM(rdx) ",%rdx\n" 165 "\tcmpxchg %ebx,%ecx \n" 166 "\tmov %rax," VG_SYM(rax_out) "\n" 167 "\tmov %rbx," VG_SYM(rbx_out) "\n" 168 "\tmov %rcx," VG_SYM(rcx_out) "\n" 169 "\tpop %rdx\n" 170 "\tpop %rcx\n" 171 "\tpop %rbx\n" 172 "\tpop %rax\n" 173 ); 174 175 printf(" eax!=ecx so eax should equal ecx (Result eax=%llx ebx=%llx ecx=%llx)\n", 176 rax_out&0xffffffff,rbx_out&0xffffffff,rcx_out&0xffffffff); 177 178 179 180 rdx = 0x99999999; rax = 0x77777777; 181 rcx = 0x55555555; rbx = 0x55555555; 182 183 printf("cmpxchg %%ebx,%%ecx (eax=%llx ebx=%llx ecx=%llx)\n", 184 rax&0xffffffff,rbx&0xffffffff,rcx&0xffffffff); 185 186 asm("\n" 187 "\tpush %rax\n" 188 "\tpush %rbx\n" 189 "\tpush %rcx\n" 190 "\tpush %rdx\n" 191 "\txor %rax, %rax\n" // get eflags in a known state 192 "\tmov " VG_SYM(rax) ",%rax\n" 193 "\tmov " VG_SYM(rbx) ",%rbx\n" 194 "\tmov " VG_SYM(rcx) ",%rcx\n" 195 "\tmov " VG_SYM(rdx) ",%rdx\n" 196 "\tcmpxchg %ebx,%ecx \n" 197 "\tmov %rax," VG_SYM(rax_out) "\n" 198 "\tmov %rbx," VG_SYM(rbx_out) "\n" 199 "\tmov %rcx," VG_SYM(rcx_out) "\n" 200 "\tpop %rdx\n" 201 "\tpop %rcx\n" 202 "\tpop %rbx\n" 203 "\tpop %rax\n" 204 ); 205 206 printf(" eax==ecx so ecx should equal ebx (Result eax=%llx ebx=%llx ecx=%llx)\n", 207 rax_out&0xffffffff,rbx_out&0xffffffff,rcx_out&0xffffffff); 208 209 210 /* 64-bit */ 211 212 rdx = 0x111111111; rax = 0x222222222; 213 rcx = 0x333333333; rbx = 0x444444444; 214 215 printf("cmpxchg %%rbx,%%rcx (rax=%llx rbx=%llx rcx=%llx)\n", 216 rax,rbx,rcx); 217 218 asm("\n" 219 "\tpush %rax\n" 220 "\tpush %rbx\n" 221 "\tpush %rcx\n" 222 "\tpush %rdx\n" 223 "\txor %rax, %rax\n" // get eflags in a known state 224 "\tmov " VG_SYM(rax) ",%rax\n" 225 "\tmov " VG_SYM(rbx) ",%rbx\n" 226 "\tmov " VG_SYM(rcx) ",%rcx\n" 227 "\tmov " VG_SYM(rdx) ",%rdx\n" 228 "\tcmpxchg %rbx,%rcx \n" 229 "\tmov %rax," VG_SYM(rax_out) "\n" 230 "\tmov %rbx," VG_SYM(rbx_out) "\n" 231 "\tmov %rcx," VG_SYM(rcx_out) "\n" 232 "\tpop %rdx\n" 233 "\tpop %rcx\n" 234 "\tpop %rbx\n" 235 "\tpop %rax\n" 236 ); 237 238 printf(" rax!=rcx so rax should equal rcx (Result rax=%llx rbx=%llx rcx=%llx)\n", 239 rax_out,rbx_out,rcx_out); 240 241 242 243 rdx = 0x999999999; rax = 0x777777777; 244 rcx = 0x555555555; rbx = 0x555555555; 245 246 printf("cmpxchg %%rbx,%%rcx (rax=%llx rbx=%llx rcx=%llx)\n", 247 rax,rbx,rcx); 248 249 asm("\n" 250 "\tpush %rax\n" 251 "\tpush %rbx\n" 252 "\tpush %rcx\n" 253 "\tpush %rdx\n" 254 "\txor %rax, %rax\n" // get eflags in a known state 255 "\tmov " VG_SYM(rax) ",%rax\n" 256 "\tmov " VG_SYM(rbx) ",%rbx\n" 257 "\tmov " VG_SYM(rcx) ",%rcx\n" 258 "\tmov " VG_SYM(rdx) ",%rdx\n" 259 "\tcmpxchg %rbx,%rcx \n" 260 "\tmov %rax," VG_SYM(rax_out) "\n" 261 "\tmov %rbx," VG_SYM(rbx_out) "\n" 262 "\tmov %rcx," VG_SYM(rcx_out) "\n" 263 "\tpop %rdx\n" 264 "\tpop %rcx\n" 265 "\tpop %rbx\n" 266 "\tpop %rax\n" 267 ); 268 269 printf(" rax==rcx so ecx should equal rbx (Result rax=%llx rbx=%llx rcx=%llx)\n", 270 rax_out,rbx_out,rcx_out); 271 272 return 0; 273} 274