General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

  1. #pragma once
  2. #include <cstdint>
  3. #define no_inline_decl(a) [[gnu::noinline]] a
  4. namespace gp{
  5. namespace specifics {
  6. struct platform_data {
  7. uint64_t rbx, r12, r13, r14, r15;
  8. void* stack_ptr;
  9. void* base_ptr;
  10. void pull() __attribute__((always_inline))
  11. {
  12. __asm__ __volatile__(
  13. "movq %%rsp, %0\n"
  14. "movq %%rbp, %1\n"
  15. "movq %%rbx, %2\n"
  16. "movq %%r12, %3\n"
  17. "movq %%r13, %4\n"
  18. "movq %%r14, %5\n"
  19. "movq %%r15, %6\n"
  20. : "=m"(stack_ptr)
  21. , "=m"(base_ptr)
  22. , "=m"(rbx)
  23. , "=m"(r12)
  24. , "=m"(r13)
  25. , "=m"(r14)
  26. , "=m"(r15));
  27. }
  28. void* push(void* location) __attribute__((always_inline))
  29. {
  30. void* tmp = static_cast<char*>(stack_ptr) - sizeof(void*);
  31. *static_cast<void**>(tmp) = location;
  32. __asm__ __volatile__(
  33. "movq %1, %%rsp\n"
  34. "movq %2, %%rbp\n"
  35. "movq %3, %%r12\n"
  36. "movq %4, %%r13\n"
  37. "movq %5, %%r14\n"
  38. "movq %6, %%r15\n"
  39. "popq %0\n"
  40. : "+r"(location)
  41. : "m"(tmp)
  42. , "m"(base_ptr)
  43. , "m"(r12)
  44. , "m"(r13)
  45. , "m"(r14)
  46. , "m"(r15)
  47. : "memory");
  48. return location;
  49. }
  50. };
  51. }
  52. }