[lldb] [lit] Simplify general-purpose register tests

Use output constraints for specific general-purpose registers in order
to simplify the tests.  They save us from having to manually put
the values in correct registers, and reduce the number of registers
needed as a result.

llvm-svn: 359978
This commit is contained in:
Michal Gorny 2019-05-05 12:06:32 +00:00
parent dca69eb29c
commit 60211cb872
4 changed files with 27 additions and 61 deletions

View File

@ -15,14 +15,8 @@ int main() {
"movq %%rsp, %%r8\n\t"
"movq %%rbp, %%r9\n\t"
"\n\t"
"movq %0, %%rax\n\t"
"movq %1, %%rbx\n\t"
"movq %2, %%rcx\n\t"
"movq %3, %%rdx\n\t"
"movq %4, %%rsp\n\t"
"movq %5, %%rbp\n\t"
"movq %6, %%rsi\n\t"
"movq %7, %%rdi\n\t"
"\n\t"
"int3\n\t"
"\n\t"
@ -30,10 +24,9 @@ int main() {
"movq %%r8, %%rsp\n\t"
"movq %%r9, %%rbp"
:
: "i"(rax), "i"(rbx), "i"(rcx), "i"(rdx), "i"(rsp), "i"(rbp), "i"(rsi),
"i"(rdi)
: "%rax", "%rbx", "%rcx", "%rdx", "%rsp", "%rbp", "%rsi", "%rdi", "%r8",
"%r9"
: "a"(rax), "b"(rbx), "c"(rcx), "d"(rdx), "i"(rsp), "i"(rbp), "S"(rsi),
"D"(rdi)
: "%r8", "%r9"
);
return 0;

View File

@ -9,8 +9,8 @@ int main() {
asm volatile(
// save rsp & rbp
"movq %%rsp, %%mm0\n\t"
"movq %%rbp, %%mm1\n\t"
"movq %%rsp, %4\n\t"
"movq %%rbp, %5\n\t"
"\n\t"
"movq %8, %%rax\n\t"
"movq %8, %%rbx\n\t"
@ -23,23 +23,13 @@ int main() {
"\n\t"
"int3\n\t"
"\n\t"
"movq %%rax, %0\n\t"
"movq %%rbx, %1\n\t"
"movq %%rcx, %2\n\t"
"movq %%rdx, %3\n\t"
"movq %%rsp, %4\n\t"
"movq %%rbp, %5\n\t"
"movq %%rsi, %6\n\t"
"movq %%rdi, %7\n\t"
"\n\t"
// restore rsp & rbp
"movq %%mm0, %%rsp\n\t"
"movq %%mm1, %%rbp\n\t"
: "=r"(rax), "=r"(rbx), "=r"(rcx), "=r"(rdx), "=r"(rsp), "=r"(rbp),
"=r"(rsi), "=r"(rdi)
// swap saved & current rsp & rbp
"xchgq %%rsp, %4\n\t"
"xchgq %%rbp, %5\n\t"
: "=a"(rax), "=b"(rbx), "=c"(rcx), "=d"(rdx), "=r"(rsp), "=r"(rbp),
"=S"(rsi), "=D"(rdi)
: "g"(fill)
: "%rax", "%rbx", "%rcx", "%rdx", "%rsp", "%rbp", "%rsi", "%rdi", "%mm0",
"%mm1"
:
);
printf("rax = 0x%016" PRIx64 "\n", rax);

View File

@ -15,14 +15,8 @@ int main() {
"movd %%esp, %%mm0\n\t"
"movd %%ebp, %%mm1\n\t"
"\n\t"
"movl %0, %%eax\n\t"
"movl %1, %%ebx\n\t"
"movl %2, %%ecx\n\t"
"movl %3, %%edx\n\t"
"movl %4, %%esp\n\t"
"movl %5, %%ebp\n\t"
"movl %6, %%esi\n\t"
"movl %7, %%edi\n\t"
"\n\t"
"int3\n\t"
"\n\t"
@ -30,10 +24,9 @@ int main() {
"movd %%mm0, %%esp\n\t"
"movd %%mm1, %%ebp\n\t"
:
: "i"(eax), "i"(ebx), "i"(ecx), "i"(edx), "i"(esp), "i"(ebp), "i"(esi),
"i"(edi)
: "%eax", "%ebx", "%ecx", "%edx", "%esp", "%ebp", "%esi", "%edi", "%mm0",
"%mm1"
: "a"(eax), "b"(ebx), "c"(ecx), "d"(edx), "i"(esp), "i"(ebp), "S"(esi),
"D"(edi)
: "%mm0", "%mm1"
);
return 0;

View File

@ -5,7 +5,10 @@
int main() {
constexpr uint32_t fill = 0x0F0F0F0F;
uint32_t eax, ebx, ecx, edx, esp, ebp, esi, edi;
uint32_t eax, ebx, ecx, edx, esi, edi;
// need to use 64-bit types due to bug in clang
// https://bugs.llvm.org/show_bug.cgi?id=41748
uint64_t esp, ebp;
asm volatile(
// save esp & ebp
@ -23,37 +26,24 @@ int main() {
"\n\t"
"int3\n\t"
"\n\t"
// first save new esp & ebp, and restore their original values, so that
// we can output values via memory
"movd %%esp, %%mm2\n\t"
"movd %%ebp, %%mm3\n\t"
// copy new values of esp & ebp
"movd %%esp, %4\n\t"
"movd %%ebp, %5\n\t"
// restore saved esp & ebp
"movd %%mm0, %%esp\n\t"
"movd %%mm1, %%ebp\n\t"
"\n\t"
// output values via memory
"movl %%eax, %0\n\t"
"movl %%ebx, %1\n\t"
"movl %%ecx, %2\n\t"
"movl %%edx, %3\n\t"
"movl %%esi, %6\n\t"
"movl %%edi, %7\n\t"
"\n\t"
// output saved esp & ebp
"movd %%mm2, %4\n\t"
"movd %%mm3, %5\n\t"
: "=m"(eax), "=m"(ebx), "=m"(ecx), "=m"(edx), "=a"(esp), "=b"(ebp),
"=m"(esi), "=m"(edi)
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx), "=y"(esp), "=y"(ebp),
"=S"(esi), "=D"(edi)
: "i"(fill)
: "%ecx", "%edx", "%esp", "%ebp", "%esi", "%edi", "%mm0", "%mm1", "%mm2",
"%mm3"
: "%mm0", "%mm1"
);
printf("eax = 0x%08" PRIx32 "\n", eax);
printf("ebx = 0x%08" PRIx32 "\n", ebx);
printf("ecx = 0x%08" PRIx32 "\n", ecx);
printf("edx = 0x%08" PRIx32 "\n", edx);
printf("esp = 0x%08" PRIx32 "\n", esp);
printf("ebp = 0x%08" PRIx32 "\n", ebp);
printf("esp = 0x%08" PRIx32 "\n", static_cast<uint32_t>(esp));
printf("ebp = 0x%08" PRIx32 "\n", static_cast<uint32_t>(ebp));
printf("esi = 0x%08" PRIx32 "\n", esi);
printf("edi = 0x%08" PRIx32 "\n", edi);