From b09100f8b79b77f613f5d68fd661e3cbaf1f5c86 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Mon, 24 Jun 2024 02:07:27 -0500 Subject: arch: i386: add a function that walks the stack Add a function that will walk the stack and save the return addresses into an array. This will allow the kernel to print out stack traces during a panic or on demand inside a debugger. Signed-off-by: Danny Holman --- arch/i386/kernel/stack_trace.s | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 arch/i386/kernel/stack_trace.s (limited to 'arch/i386/kernel') diff --git a/arch/i386/kernel/stack_trace.s b/arch/i386/kernel/stack_trace.s new file mode 100644 index 0000000..fbd77ed --- /dev/null +++ b/arch/i386/kernel/stack_trace.s @@ -0,0 +1,31 @@ +.section .text + +.global walk_stack +.type walk_stack, @function +walk_stack: + pushl %ebp + movl %esp, %ebp + + pushl %edi + movl -4(%ebp), %edi + pushl %ebx + movl -8(%ebp), %ebx + + xorl %eax, %eax + movl 8(%esp), %ebx + movl 16(%esp), %edi + movl 20(%esp), %ecx +walk: + testl %ebx, %ebx + jz done + movl 4(%ebx), %edx + movl 0(%ebx), %ebx + movl %edx, (%edi) + addl $4, %edi + inc %eax + loop walk +done: + popl %ebx + popl %edi + popl %ebp + ret -- cgit v1.2.3