diff --git a/xtoskrnl/ar/amd64/cpufunc.c b/xtoskrnl/ar/amd64/cpufunc.c index ac89b39..4336b38 100644 --- a/xtoskrnl/ar/amd64/cpufunc.c +++ b/xtoskrnl/ar/amd64/cpufunc.c @@ -67,6 +67,26 @@ ArCpuId(IN OUT PCPUID_REGISTERS Registers) return TRUE; } +/** + * Gets the address of the current stack register. + * + * @return This routine returns the current stack pointer. + * + * @since XT 1.0 + */ +XTASSEMBLY +XTCDECL +ULONG_PTR +ArGetStackPointer() +{ + /* Get current stack pointer */ + asm volatile("movq %%rsp, %%rax\n" + "retq\n" + : + : + :); +} + /** * Halts the central processing unit (CPU). * diff --git a/xtoskrnl/ar/i686/cpufunc.c b/xtoskrnl/ar/i686/cpufunc.c index 17da213..d63a89c 100644 --- a/xtoskrnl/ar/i686/cpufunc.c +++ b/xtoskrnl/ar/i686/cpufunc.c @@ -67,6 +67,26 @@ ArCpuId(IN OUT PCPUID_REGISTERS Registers) return TRUE; } +/** + * Gets the address of the current stack register. + * + * @return This routine returns the current stack pointer. + * + * @since XT 1.0 + */ +XTASSEMBLY +XTCDECL +ULONG_PTR +ArGetStackPointer() +{ + /* Get current stack pointer */ + asm volatile("mov %%esp, %%eax\n" + "ret\n" + : + : + :); +} + /** * Halts the central processing unit (CPU). * diff --git a/xtoskrnl/includes/amd64/ar.h b/xtoskrnl/includes/amd64/ar.h index f681183..96d7fa2 100644 --- a/xtoskrnl/includes/amd64/ar.h +++ b/xtoskrnl/includes/amd64/ar.h @@ -21,6 +21,11 @@ XTCDECL BOOLEAN ArCpuId(IN OUT PCPUID_REGISTERS Registers); +XTASSEMBLY +XTCDECL +ULONG_PTR +ArGetStackPointer(); + XTCDECL VOID ArHalt(); diff --git a/xtoskrnl/includes/i686/ar.h b/xtoskrnl/includes/i686/ar.h index 1576943..c127954 100644 --- a/xtoskrnl/includes/i686/ar.h +++ b/xtoskrnl/includes/i686/ar.h @@ -21,6 +21,11 @@ XTCDECL BOOLEAN ArCpuId(IN OUT PCPUID_REGISTERS Registers); +XTASSEMBLY +XTCDECL +ULONG_PTR +ArGetStackPointer(); + XTCDECL VOID ArHalt();