diff options
author | Ian Moffett <ian@osmora.org> | 2024-05-14 19:10:10 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-05-14 19:10:10 -0400 |
commit | df8ff1d226a268f56206161c56eeb70321cb5d27 (patch) | |
tree | 9d03fcca2ebdce064bf014d017d5a4bbf59a14c2 /sys/arch/amd64 | |
parent | 2cd356202686b44798eb39037608e9aca10a1f0d (diff) |
kernel/amd64: machdep: Reorganize functions
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 4476053..93bf664 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -111,6 +111,53 @@ is_sse_supported(void) return __TEST(edx, __BIT(25)) && __TEST(edx, __BIT(26)); } +static const char* +backtrace_addr_to_name(uintptr_t addr, off_t *off) +{ + uintptr_t prev_addr = 0; + const char *name = NULL; + + for (size_t i = 0;;) { + if (g_ksym_table[i].addr > addr) { + *off = addr - prev_addr; + return name; + } + + prev_addr = g_ksym_table[i].addr; + name = g_ksym_table[i].name; + if (g_ksym_table[i++].addr == (uint64_t)-1) + break; + } + + return NULL; +} + +static void +backtrace(void) +{ + uintptr_t *rbp; + uintptr_t rip; + + off_t off; + const char *name; + + kprintf("** Backtrace **\n"); + __ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory"); + + while (1) { + rip = rbp[1]; + rbp = (uintptr_t *)rbp[0]; + name = backtrace_addr_to_name(rip, &off); + + if (rbp == NULL) + break; + if (name == NULL) + name = "???"; + + kprintf("[0x%p] <%s+0x%x>\n", rip, name, off); + } +} + void processor_halt(void) { @@ -173,53 +220,6 @@ intr_unmask(void) __ASMV("sti"); } -static const char* -backtrace_addr_to_name(uintptr_t addr, off_t *off) -{ - uintptr_t prev_addr = 0; - const char *name = NULL; - - for (size_t i = 0;;) { - if (g_ksym_table[i].addr > addr) { - *off = addr - prev_addr; - return name; - } - - prev_addr = g_ksym_table[i].addr; - name = g_ksym_table[i].name; - if (g_ksym_table[i++].addr == (uint64_t)-1) - break; - } - - return NULL; -} - -static void -backtrace(void) -{ - uintptr_t *rbp; - uintptr_t rip; - - off_t off; - const char *name; - - kprintf("** Backtrace **\n"); - __ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory"); - - while (1) { - rip = rbp[1]; - rbp = (uintptr_t *)rbp[0]; - name = backtrace_addr_to_name(rip, &off); - - if (rbp == NULL) - break; - if (name == NULL) - name = "???"; - - kprintf("[0x%p] <%s+0x%x>\n", rip, name, off); - } -} - /* * Called last within panic() */ |