Kernel: Add helper functions for reading current rsp and rbp

This commit is contained in:
Bananymous 2023-02-02 23:19:44 +02:00
parent 2403df50bb
commit 777ede328e
1 changed files with 8 additions and 0 deletions

View File

@ -4,4 +4,12 @@
#if !defined(__arch) || (__arch != x86_64 && __arch != i386)
#error "Unsupported architecture"
#endif
#if ARCH(x86_64)
#define read_rsp(rsp) asm volatile("movq %%rsp, %0" : "=r"(rsp))
#define read_rbp(rbp) asm volatile("movq %%rbp, %0" : "=r"(rbp))
#else
#define read_rsp(rsp) asm volatile("movl %%esp, %0" : "=r"(rsp))
#define read_rbp(rbp) asm volatile("movl %%ebp, %0" : "=r"(rbp))
#endif