brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 1dfbe31 Raw
52 lines · cpp
1#include <cinttypes>2#include <cstdint>3#include <cstdio>4 5int main() {6  constexpr uint32_t fill = 0x0F0F0F0F;7 8  uint32_t eax, ebx, ecx, edx, esi, edi;9  // need to use 64-bit types due to bug in clang10  // https://bugs.llvm.org/show_bug.cgi?id=4174811  uint64_t esp, ebp;12 13  asm volatile(14    // save esp & ebp15    "movd    %%esp, %%mm0\n\t"16    "movd    %%ebp, %%mm1\n\t"17    "\n\t"18    "movl    %8, %%eax\n\t"19    "movl    %8, %%ebx\n\t"20    "movl    %8, %%ecx\n\t"21    "movl    %8, %%edx\n\t"22    "movl    %8, %%esp\n\t"23    "movl    %8, %%ebp\n\t"24    "movl    %8, %%esi\n\t"25    "movl    %8, %%edi\n\t"26    "\n\t"27    "int3\n\t"28    "\n\t"29    // copy new values of esp & ebp30    "movd    %%esp, %4\n\t"31    "movd    %%ebp, %5\n\t"32    // restore saved esp & ebp33    "movd    %%mm0, %%esp\n\t"34    "movd    %%mm1, %%ebp\n\t"35    : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx), "=y"(esp), "=y"(ebp),36      "=S"(esi), "=D"(edi)37    : "i"(fill)38    : "%mm0", "%mm1"39  );40 41  printf("eax = 0x%08" PRIx32 "\n", eax);42  printf("ebx = 0x%08" PRIx32 "\n", ebx);43  printf("ecx = 0x%08" PRIx32 "\n", ecx);44  printf("edx = 0x%08" PRIx32 "\n", edx);45  printf("esp = 0x%08" PRIx32 "\n", static_cast<uint32_t>(esp));46  printf("ebp = 0x%08" PRIx32 "\n", static_cast<uint32_t>(ebp));47  printf("esi = 0x%08" PRIx32 "\n", esi);48  printf("edi = 0x%08" PRIx32 "\n", edi);49 50  return 0;51}52