From d63a30728c7ed50f1deead0390908dbfa31c100d Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 22 Aug 2020 16:34:58 -0700 Subject: [PATCH] [kernel] Add get_caller function Added a function to get the callsite of the current function invocation. --- src/kernel/debug.h | 1 + src/kernel/debug.s | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/kernel/debug.h b/src/kernel/debug.h index de08ffe..0f9c8b6 100644 --- a/src/kernel/debug.h +++ b/src/kernel/debug.h @@ -7,6 +7,7 @@ extern "C" { uintptr_t get_rsp(); uintptr_t get_rip(); + uintptr_t get_caller(); uintptr_t get_frame(int frame); uintptr_t get_gsbase(); void _halt(); diff --git a/src/kernel/debug.s b/src/kernel/debug.s index 646dc0d..421695c 100644 --- a/src/kernel/debug.s +++ b/src/kernel/debug.s @@ -8,6 +8,12 @@ get_rip: pop rax ; do the same thing as 'ret', except with 'jmp' jmp rax ; with the return address still in rax +global get_caller +get_caller: + ; No prelude - don't touch rsp or rbp + mov rax, [rbp+8] + ret + global get_gsbase get_gsbase: rdgsbase rax