• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "tests/asm.h"
2 #include <stdio.h>
3 
4 typedef unsigned long long int ULong;
5 typedef unsigned int UInt;
6 
7 ULong m64;
8 
9 UInt eax;
10 UInt ebx;
11 UInt ecx;
12 UInt edx;
13 UInt zout;
14 
15 extern void foo ( void );
16 asm("\n"
17     VG_SYM(foo) ":\n"
18     "\tpushl %eax\n"
19     "\tpushl %ebx\n"
20     "\tpushl %ecx\n"
21     "\tpushl %edx\n"
22 
23     "\txorl %eax, %eax\n" // get eflags in a known state
24 
25     "\tmovl " VG_SYM(eax) ",%eax\n"
26     "\tmovl " VG_SYM(ebx) ",%ebx\n"
27     "\tmovl " VG_SYM(ecx) ",%ecx\n"
28     "\tmovl " VG_SYM(edx) ",%edx\n"
29     "\tcmpxchg8b " VG_SYM(m64) "\n"
30     "\tmovl %eax," VG_SYM(eax) "\n"
31     "\tmovl %ebx," VG_SYM(ebx) "\n"
32     "\tmovl %ecx," VG_SYM(ecx) "\n"
33     "\tmovl %edx," VG_SYM(edx) "\n"
34     "\tpushfl\n"
35     "\tpopl %eax\n"
36     "\tmovl %eax," VG_SYM(zout) "\n"
37 
38     "\tpopl %edx\n"
39     "\tpopl %ecx\n"
40     "\tpopl %ebx\n"
41     "\tpopl %eax\n"
42     "\tret\n"
43     );
44 
main(void)45 int main ( void )
46 {
47    edx  = 0x11111111; eax = 0x22222222;
48    ecx  = 0x33333333; ebx = 0x44444444;
49    zout = 0x55555555;
50    m64  = 0x1111111122222222ULL;
51    foo();
52    printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n",
53 	  eax, ebx, ecx, edx, zout & 0xFFFF, m64 );
54 
55    edx  = 0x11111111; eax = 0x22222222;
56    ecx  = 0x33333333; ebx = 0x44444444;
57    zout = 0x55555555;
58    m64  = 0x1111111122222222ULL;
59    m64 += 0x1ULL;
60    foo();
61    printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n",
62 	  eax, ebx, ecx, edx, zout & 0xFFFF, m64 );
63 
64    edx  = 0x11111111; eax = 0x22222222;
65    ecx  = 0x33333333; ebx = 0x44444444;
66    zout = 0x55555555;
67    m64  = 0x1111111122222222ULL;
68    m64 += 0x100000000ULL;
69    foo();
70    printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n",
71 	  eax, ebx, ecx, edx, zout & 0xFFFF, m64 );
72 
73    edx  = 0x11111111; eax = 0x22222222;
74    ecx  = 0x33333333; ebx = 0x44444444;
75    zout = 0x55555555;
76    m64  = 0x6666666677777777ULL;
77    foo();
78    printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n",
79 	  eax, ebx, ecx, edx, zout & 0xFFFF, m64 );
80 
81    return 0;
82 }
83