diff options
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 36 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/mp.c | 2 |
2 files changed, 33 insertions, 5 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 19dcf44..9ff96e1 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -47,6 +47,13 @@ #include <dev/cons/cons.h> #include <string.h> +/* + * This defines the max number of frames + * we will pass while walking the callstack + * in md_backtrace() + */ +#define MAX_FRAME_DEPTH 16 + #define pr_trace(fmt, ...) kprintf("cpu: " fmt, ##__VA_ARGS__) #define pr_error(...) pr_trace(__VA_ARGS__) #define pr_trace_bsp(...) \ @@ -259,24 +266,43 @@ void md_backtrace(void) { uintptr_t *rbp; - uintptr_t rip; + uintptr_t rip, tmp; off_t off; const char *name; char line[256]; + uint8_t n = 0; __ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory"); while (1) { + if (n >= MAX_FRAME_DEPTH) { + break; + } + rip = rbp[1]; rbp = (uintptr_t *)rbp[0]; - name = backtrace_addr_to_name(rip, &off); - if (rbp == NULL) + /* + * RBP should be aligned on an 8-byte + * boundary... Don't trust this state + * anymore if it is not. + */ + tmp = (uintptr_t)rbp; + if ((tmp & (8 - 1)) != 0) { + break; + } + + /* + * This is not a valid value, get out + * of this loop!! + */ + if (rbp == NULL || rip == 0) { break; - if (name == NULL) - name = "???"; + } + name = backtrace_addr_to_name(rip, &off); snprintf(line, sizeof(line), "%p @ <%s+0x%x>\n", rip, name, off); cons_putstr(&g_root_scr, line, strlen(line)); + ++n; } } diff --git a/sys/arch/amd64/amd64/mp.c b/sys/arch/amd64/amd64/mp.c index 20f550f..43830ba 100644 --- a/sys/arch/amd64/amd64/mp.c +++ b/sys/arch/amd64/amd64/mp.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/limine.h> #include <sys/limits.h> +#include <sys/systm.h> #include <sys/syslog.h> #include <sys/proc.h> #include <sys/spinlock.h> @@ -149,4 +150,5 @@ mp_bootstrap_aps(struct cpu_info *ci) /* Wait for all cores to be ready */ while ((ncpu_up - 1) < cpu_init_counter); + cpu_report_count(ncpu_up); } |