Index: kernel/Makefile.build
===================================================================
--- kernel/Makefile.build	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/Makefile.build	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -186,4 +186,5 @@
 	generic/src/ddi/device.c \
 	generic/src/debug/symtab.c \
+	generic/src/debug/stacktrace.c \
 	generic/src/interrupt/interrupt.c \
 	generic/src/main/main.c \
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -38,5 +38,5 @@
 
 FPU_NO_CFLAGS = -mno-sse -mno-sse2
-CMN1 = -m64 -mcmodel=kernel -mno-red-zone -fno-unwind-tables
+CMN1 = -m64 -mcmodel=kernel -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
 GCC_CFLAGS += $(CMN1)
 ICC_CFLAGS += $(CMN1)
@@ -60,4 +60,6 @@
 	arch/$(KARCH)/src/boot/boot.S \
 	arch/$(KARCH)/src/boot/memmap.c \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/pm.c \
 	arch/$(KARCH)/src/context.S \
Index: kernel/arch/amd64/include/context.h
===================================================================
--- kernel/arch/amd64/include/context.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/include/context.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -46,4 +46,11 @@
 #define SP_DELTA     16
 
+#define context_set(c, _pc, stack, size) \
+	do { \
+		(c)->pc = (uintptr_t) (_pc); \
+		(c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(c)->rbp = 0; \
+	} while (0)
+
 #endif /* KERNEL */
 
Index: kernel/arch/amd64/include/interrupt.h
===================================================================
--- kernel/arch/amd64/include/interrupt.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/include/interrupt.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -70,5 +70,5 @@
 
 /** This is passed to interrupt handlers */
-typedef struct {
+typedef struct istate {
 	uint64_t rax;
 	uint64_t rcx;
@@ -80,4 +80,5 @@
 	uint64_t r10;
 	uint64_t r11;
+	uint64_t rbp;
 	uint64_t error_word;
 	uint64_t rip;
@@ -101,4 +102,8 @@
 	return istate->rip;
 }
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return istate->rbp;
+}
 
 extern void (* disable_irqs_function)(uint16_t irqmask);
Index: kernel/arch/amd64/src/asm_utils.S
===================================================================
--- kernel/arch/amd64/src/asm_utils.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/src/asm_utils.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -27,5 +27,5 @@
 #
 
-#define IREGISTER_SPACE	72 
+#define IREGISTER_SPACE	80
 
 #define IOFFSET_RAX	0x0
@@ -38,4 +38,5 @@
 #define IOFFSET_R10	0x38
 #define IOFFSET_R11	0x40
+#define IOFFSET_RBP	0x48
 
 #  Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
@@ -179,4 +180,5 @@
 	movq %r10, IOFFSET_R10(%rsp)
 	movq %r11, IOFFSET_R11(%rsp)
+	movq %rbp, IOFFSET_RBP(%rsp)
 .endm
 
@@ -191,4 +193,5 @@
 	movq IOFFSET_R10(%rsp), %r10
 	movq IOFFSET_R11(%rsp), %r11
+	movq IOFFSET_RBP(%rsp), %rbp
 .endm
 
@@ -235,4 +238,7 @@
 	cld
 
+	# Stop stack traces here
+	xorq %rbp, %rbp
+
 	movq $(\i), %rdi   	# %rdi - first parameter
 	movq %rsp, %rsi   	# %rsi - pointer to istate
Index: kernel/arch/amd64/src/boot/boot.S
===================================================================
--- kernel/arch/amd64/src/boot/boot.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/src/boot/boot.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -174,4 +174,8 @@
 	call arch_pre_main
 	
+	# create the first stack frame
+	pushq $0
+	movq %rsp, %rbp
+
 	call main_bsp
 	
Index: kernel/arch/amd64/src/debug/stacktrace.c
===================================================================
--- kernel/arch/amd64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/amd64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+#define FRAME_OFFSET_FP_PREV	0
+#define FRAME_OFFSET_RA		1
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return fp != 0;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	uint64_t *stack = (void *) fp;
+	*prev = stack[FRAME_OFFSET_FP_PREV];
+	return true;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	uint64_t *stack = (void *) fp;
+	*ra = stack[FRAME_OFFSET_RA];
+	return true;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return fp != 0;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return !copy_from_uspace((void *) prev,
+	    (uint64_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return !copy_from_uspace((void *) ra, (uint64_t *) fp + FRAME_OFFSET_RA,
+	    sizeof(*ra));
+}
+
+/** @}
+ */
Index: kernel/arch/amd64/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/amd64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/amd64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	movq %rbp, %rax
+	ret
+
+program_counter_get:
+	movq (%rsp), %rax
+	ret
Index: kernel/arch/amd64/src/interrupt.c
===================================================================
--- kernel/arch/amd64/src/interrupt.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/src/interrupt.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -53,4 +53,5 @@
 #include <ddi/irq.h>
 #include <symtab.h>
+#include <stacktrace.h>
 
 /*
@@ -80,4 +81,6 @@
 	    istate->r10, istate->r11);
 	printf("%%rsp=%#llx\n", &istate->stack[0]);
+	
+	stack_trace_istate(istate);
 }
 
Index: kernel/arch/amd64/src/mm/page.c
===================================================================
--- kernel/arch/amd64/src/mm/page.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/src/mm/page.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -203,5 +203,6 @@
 {
 	if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
-		panic("Unable to map physical memory %p (%d bytes).", physaddr, size)
+		panic("Unable to map physical memory %p (%d bytes).", physaddr,
+		    size);
 	
 	uintptr_t virtaddr = PA2KA(last_frame);
Index: kernel/arch/amd64/src/smp/ap.S
===================================================================
--- kernel/arch/amd64/src/smp/ap.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/amd64/src/smp/ap.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -99,4 +99,6 @@
 start64:
 	movq (ctx), %rsp
+	pushq $0
+	movq %rsp, %rbp
 	call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET   # never returns
 
Index: kernel/arch/arm32/Makefile.inc
===================================================================
--- kernel/arch/arm32/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/arm32/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -57,4 +57,6 @@
 	arch/$(KARCH)/src/exception.c \
 	arch/$(KARCH)/src/userspace.c \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/mm/as.c \
 	arch/$(KARCH)/src/mm/frame.c \
Index: kernel/arch/arm32/include/exception.h
===================================================================
--- kernel/arch/arm32/include/exception.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/arm32/include/exception.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -86,5 +86,5 @@
 
 /** Struct representing CPU state saved when an exception occurs. */
-typedef struct {
+typedef struct istate {
 	uint32_t spsr;
 	uint32_t sp;
@@ -133,4 +133,9 @@
 }
 
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return istate->r11;
+}
+
 
 extern void install_exception_handlers(void);
Index: kernel/arch/arm32/src/debug/stacktrace.c
===================================================================
--- kernel/arch/arm32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/arm32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup arm32
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+/** @}
+ */
Index: kernel/arch/arm32/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/arm32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/arm32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	mov pc, lr
+
+program_counter_get:
+	mov pc, lr
Index: kernel/arch/arm32/src/mm/page.c
===================================================================
--- kernel/arch/arm32/src/mm/page.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/arm32/src/mm/page.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -88,5 +88,5 @@
 	    KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH)) {
 		panic("Unable to map physical memory %p (%d bytes).",
-		    physaddr, size)
+		    physaddr, size);
 	}
 	
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -78,4 +78,6 @@
 	arch/$(KARCH)/src/context.S \
 	arch/$(KARCH)/src/debug/panic.s \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/delay.s \
 	arch/$(KARCH)/src/asm.S \
Index: kernel/arch/ia32/include/context.h
===================================================================
--- kernel/arch/ia32/include/context.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/include/context.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -49,4 +49,11 @@
 #define SP_DELTA	(8 + STACK_ITEM_SIZE)
 
+#define context_set(c, _pc, stack, size) \
+	do { \
+		(c)->pc = (uintptr_t) (_pc); \
+		(c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(c)->ebp = 0; \
+	} while (0)
+
 #endif /* KERNEL */
 
Index: kernel/arch/ia32/include/interrupt.h
===================================================================
--- kernel/arch/ia32/include/interrupt.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/include/interrupt.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -69,8 +69,9 @@
 #define VECTOR_DEBUG_IPI		(IVT_FREEBASE + 2)
 
-typedef struct {
+typedef struct istate {
 	uint32_t eax;
 	uint32_t ecx;
 	uint32_t edx;
+	uint32_t ebp;
 
 	uint32_t gs;
@@ -102,4 +103,9 @@
 }
 
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return istate->ebp;
+}
+
 extern void (* disable_irqs_function)(uint16_t irqmask);
 extern void (* enable_irqs_function)(uint16_t irqmask);
Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/src/asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -269,4 +269,5 @@
 	pushl %gs
 
+	pushl %ebp
 	pushl %edx
 	pushl %ecx
@@ -278,5 +279,6 @@
 	movw %ax, %es
 
-	cld
+	# stop stack traces here
+	xorl %ebp, %ebp
 
 	pushl %esp          # *istate
@@ -290,4 +292,5 @@
 	popl %ecx
 	popl %edx
+	popl %ebp
 	
 	popl %gs
Index: kernel/arch/ia32/src/boot/boot.S
===================================================================
--- kernel/arch/ia32/src/boot/boot.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/src/boot/boot.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -94,4 +94,8 @@
 	pushl grub_eax
 	call arch_pre_main
+
+	# Create the first stack frame
+	pushl $0
+	movl %esp, %ebp
 	
 	call main_bsp
Index: kernel/arch/ia32/src/debug/stacktrace.c
===================================================================
--- kernel/arch/ia32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ia32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ia32
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+#define FRAME_OFFSET_FP_PREV	0
+#define FRAME_OFFSET_RA		1
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return fp != 0;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	uint32_t *stack = (void *) fp;
+	*prev = stack[FRAME_OFFSET_FP_PREV];
+	return true;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	uint32_t *stack = (void *) fp;
+	*ra = stack[FRAME_OFFSET_RA];
+	return true;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return fp != 0;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return !copy_from_uspace((void *) prev,
+	    (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,
+	    sizeof(*ra));
+}
+
+/** @}
+ */
Index: kernel/arch/ia32/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/ia32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ia32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	movl %ebp, %eax
+	ret
+
+program_counter_get:
+	movl (%esp), %eax
+	ret
Index: kernel/arch/ia32/src/interrupt.c
===================================================================
--- kernel/arch/ia32/src/interrupt.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/src/interrupt.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -53,4 +53,5 @@
 #include <ddi/irq.h>
 #include <symtab.h>
+#include <stacktrace.h>
 
 /*
@@ -79,4 +80,6 @@
 	printf("stack: %#lx, %#lx, %#lx, %#lx\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
 	printf("       %#lx, %#lx, %#lx, %#lx\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
+
+	stack_trace_istate(istate);
 }
 
Index: kernel/arch/ia32/src/mm/page.c
===================================================================
--- kernel/arch/ia32/src/mm/page.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/src/mm/page.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -80,5 +80,5 @@
 {
 	if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
-		panic("Unable to map physical memory %p (%d bytes).", physaddr, size)
+		panic("Unable to map physical memory %p (%d bytes).", physaddr, size);
 	
 	uintptr_t virtaddr = PA2KA(last_frame);
Index: kernel/arch/ia32/src/smp/ap.S
===================================================================
--- kernel/arch/ia32/src/smp/ap.S	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia32/src/smp/ap.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -78,4 +78,7 @@
 	addl $0x80000000, %esp			# PA2KA(ctx.sp)
 	
+	pushl $0				# create the first stack frame
+	movl %esp, %ebp
+
 	jmpl $KTEXT, $main_ap
 
Index: kernel/arch/ia64/Makefile.inc
===================================================================
--- kernel/arch/ia64/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia64/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -53,4 +53,6 @@
 	arch/$(KARCH)/src/context.S \
 	arch/$(KARCH)/src/cpu/cpu.c \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/ivt.S \
 	arch/$(KARCH)/src/interrupt.c \
Index: kernel/arch/ia64/include/interrupt.h
===================================================================
--- kernel/arch/ia64/include/interrupt.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ia64/include/interrupt.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -72,5 +72,5 @@
 #define EOI  0  /**< The actual value doesn't matter. */
 
-typedef struct {
+typedef struct istate {
 	uint128_t f2;
 	uint128_t f3;
@@ -143,4 +143,9 @@
 }
 
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return 0;	/* FIXME */
+}
+
 static inline int istate_from_uspace(istate_t *istate)
 {
Index: kernel/arch/ia64/src/debug/stacktrace.c
===================================================================
--- kernel/arch/ia64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ia64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ia64
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+/** @}
+ */
Index: kernel/arch/ia64/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/ia64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ia64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	mov r8 = r0
+	br.ret.sptk.many b0
+
+program_counter_get:
+	mov r8 = r0
+	br.ret.sptk.many b0
Index: kernel/arch/mips32/Makefile.inc
===================================================================
--- kernel/arch/mips32/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/mips32/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -70,4 +70,6 @@
 	arch/$(KARCH)/src/debugger.c \
 	arch/$(KARCH)/src/cpu/cpu.c \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/mm/frame.c \
 	arch/$(KARCH)/src/mm/page.c \
Index: kernel/arch/mips32/include/exception.h
===================================================================
--- kernel/arch/mips32/include/exception.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/mips32/include/exception.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -58,5 +58,5 @@
 #define EXC_VCED	31
 
-typedef struct {
+typedef struct istate {
 	uint32_t at;
 	uint32_t v0;
@@ -102,4 +102,8 @@
 	return istate->epc;
 }
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return 0;	/* FIXME */
+}
 
 extern void exception(istate_t *istate);
Index: kernel/arch/mips32/src/debug/stacktrace.c
===================================================================
--- kernel/arch/mips32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/mips32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup mips32
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+/** @}
+ */
Index: kernel/arch/mips32/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/mips32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/mips32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.set noat
+.set noreorder
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	j $ra
+	xor $v0, $v0
+
+program_counter_get:
+	j $ra
+	xor $v0, $v0
Index: kernel/arch/ppc32/Makefile.inc
===================================================================
--- kernel/arch/ppc32/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ppc32/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -46,4 +46,6 @@
 	arch/$(KARCH)/src/context.S \
 	arch/$(KARCH)/src/debug/panic.s \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/fpu_context.S \
 	arch/$(KARCH)/src/boot/boot.S \
Index: kernel/arch/ppc32/include/exception.h
===================================================================
--- kernel/arch/ppc32/include/exception.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ppc32/include/exception.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -39,5 +39,5 @@
 #include <arch/regutils.h>
 
-typedef struct {
+typedef struct istate {
 	uint32_t r0;
 	uint32_t r2;
@@ -98,4 +98,9 @@
 }
 
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return istate->sp;
+}
+
 #endif
 
Index: kernel/arch/ppc32/src/debug/stacktrace.c
===================================================================
--- kernel/arch/ppc32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ppc32/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/ppc32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/ppc32/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	blr
+
+program_counter_get:
+	blr
Index: kernel/arch/ppc32/src/mm/page.c
===================================================================
--- kernel/arch/ppc32/src/mm/page.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/ppc32/src/mm/page.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -51,5 +51,5 @@
 	    KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
 		panic("Unable to map physical memory %p (%" PRIs " bytes).",
-		    physaddr, size)
+		    physaddr, size);
 	
 	uintptr_t virtaddr = PA2KA(last_frame);
Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/sparc64/Makefile.inc	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -54,4 +54,6 @@
 ARCH_SOURCES = \
 	arch/$(KARCH)/src/cpu/cpu.c \
+	arch/$(KARCH)/src/debug/stacktrace.c \
+	arch/$(KARCH)/src/debug/stacktrace_asm.S \
 	arch/$(KARCH)/src/asm.S \
 	arch/$(KARCH)/src/panic.S \
Index: kernel/arch/sparc64/include/interrupt.h
===================================================================
--- kernel/arch/sparc64/include/interrupt.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/arch/sparc64/include/interrupt.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -50,5 +50,5 @@
 };		
 
-typedef struct {
+typedef struct istate {
 	uint64_t	tnpc;
 	uint64_t	tpc;
@@ -71,4 +71,9 @@
 }
 
+static inline unative_t istate_get_fp(istate_t *istate)
+{
+	return 0;	/* TODO */
+}
+
 #endif
 
Index: kernel/arch/sparc64/src/debug/stacktrace.c
===================================================================
--- kernel/arch/sparc64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/sparc64/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup sparc64
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <syscall/copy.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+bool kernel_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_validate(uintptr_t fp)
+{
+	return false;
+}
+
+bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
+{
+	return false;
+}
+
+bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
+{
+	return false;
+}
+
+/** @}
+ */
Index: kernel/arch/sparc64/src/debug/stacktrace_asm.S
===================================================================
--- kernel/arch/sparc64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/arch/sparc64/src/debug/stacktrace_asm.S	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2010 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global frame_pointer_get
+.global program_counter_get
+
+frame_pointer_get:
+	retl
+	nop
+
+program_counter_get:
+	retl
+	nop
+
Index: kernel/generic/include/debug.h
===================================================================
--- kernel/generic/include/debug.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/generic/include/debug.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -75,5 +75,5 @@
 #	define LOG(format, ...) \
 		printf("%s() at %s:%u: " format "\n", __func__, __FILE__, \
-			__LINE__, ##__VA_ARGS__);
+		    __LINE__, ##__VA_ARGS__);
 #else
 #	define LOG(format, ...)
@@ -92,5 +92,5 @@
 		{ \
 			printf("%s() at %s:%u: " #fnc "\n", __func__, __FILE__, \
-			__LINE__); \
+			    __LINE__); \
 			fnc; \
 		}
Index: kernel/generic/include/interrupt.h
===================================================================
--- kernel/generic/include/interrupt.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/generic/include/interrupt.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -42,4 +42,5 @@
 #include <arch.h>
 #include <ddi/irq.h>
+#include <stacktrace.h>
 
 typedef void (* iroutine)(int n, istate_t *istate);
@@ -49,6 +50,8 @@
 	if (istate_from_uspace(istate)) { \
 		task_t *task = TASK; \
-		printf("Task %s (%" PRIu64 ") killed due to an exception at %p: ", task->name, task->taskid, istate_get_pc(istate)); \
-		printf(fmt "\n", ##__VA_ARGS__); \
+		printf("Task %s (%" PRIu64 ") killed due to an exception at " \
+		    "program counter %p.\n", task->name, task->taskid, istate_get_pc(istate)); \
+		stack_trace_istate(istate); \
+		printf("Kill message: " fmt "\n", ##__VA_ARGS__); \
 		task_kill(task->taskid); \
 		thread_exit(); \
Index: kernel/generic/include/panic.h
===================================================================
--- kernel/generic/include/panic.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/generic/include/panic.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -36,8 +36,16 @@
 #define KERN_PANIC_H_
 
+#include <stacktrace.h>
+#include <print.h>
+
 #ifdef CONFIG_DEBUG
 #	define panic(format, ...) \
-		panic_printf("Kernel panic in %s() at %s:%u: " format "\n", \
-		__func__, __FILE__, __LINE__, ##__VA_ARGS__);
+		do { \
+			printf("Kernel panic in %s() at %s:%u.\n", \
+			    __func__, __FILE__, __LINE__); \
+			stack_trace(); \
+			panic_printf("Panic message: " format "\n", \
+			    ##__VA_ARGS__);\
+		} while (0)
 #else
 #	define panic(format, ...) \
Index: kernel/generic/include/stacktrace.h
===================================================================
--- kernel/generic/include/stacktrace.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/generic/include/stacktrace.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2009 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericdebug 
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_STACKTRACE_H_
+#define KERN_STACKTRACE_H_
+
+#include <arch/types.h>
+#include <typedefs.h>
+
+/* Forward declarations. */
+struct istate;
+
+typedef struct {
+	bool (* frame_pointer_validate)(uintptr_t);
+	bool (* frame_pointer_prev)(uintptr_t, uintptr_t *);
+	bool (* return_address_get)(uintptr_t, uintptr_t *);
+	bool (* symbol_resolve)(uintptr_t, char **, uintptr_t *);
+} stack_trace_ops_t;
+
+extern stack_trace_ops_t kst_ops;
+extern stack_trace_ops_t ust_ops;
+
+extern void stack_trace(void);
+extern void stack_trace_istate(struct istate *);
+extern void stack_trace_fp_pc(stack_trace_ops_t *, uintptr_t, uintptr_t);
+
+/*
+ * The following interface is to be implemented by each architecture.
+ */
+extern uintptr_t frame_pointer_get(void);
+extern uintptr_t program_counter_get();
+
+extern bool kernel_frame_pointer_validate(uintptr_t);
+extern bool kernel_frame_pointer_prev(uintptr_t, uintptr_t *);
+extern bool kernel_return_address_get(uintptr_t, uintptr_t *);
+
+extern bool uspace_frame_pointer_validate(uintptr_t);
+extern bool uspace_frame_pointer_prev(uintptr_t, uintptr_t *);
+extern bool uspace_return_address_get(uintptr_t, uintptr_t *);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/symtab.h
===================================================================
--- kernel/generic/include/symtab.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/generic/include/symtab.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -45,9 +45,9 @@
 };
 
-extern int symtab_name_lookup(unative_t addr, char **name);
-extern char *symtab_fmt_name_lookup(unative_t addr);
-extern int symtab_addr_lookup(const char *name, uintptr_t *addr);
-extern void symtab_print_search(const char *name);
-extern int symtab_compl(char *input, size_t size);
+extern int symtab_name_lookup(uintptr_t, char **, uintptr_t *);
+extern char *symtab_fmt_name_lookup(uintptr_t);
+extern int symtab_addr_lookup(const char *, uintptr_t *);
+extern void symtab_print_search(const char *);
+extern int symtab_compl(char *, size_t);
 
 #ifdef CONFIG_SYMTAB
Index: kernel/generic/src/debug/stacktrace.c
===================================================================
--- kernel/generic/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
+++ kernel/generic/src/debug/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2009 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericdebug 
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <interrupt.h>
+#include <arch/types.h>
+#include <symtab.h>
+
+#define STACK_FRAMES_MAX	20
+
+void
+stack_trace_fp_pc(stack_trace_ops_t *ops, uintptr_t fp, uintptr_t pc)
+{
+	int cnt = 0;
+	char *symbol;
+	uintptr_t offset;
+
+	while (cnt++ < STACK_FRAMES_MAX && ops->frame_pointer_validate(fp)) {
+		if (ops->symbol_resolve &&
+		    ops->symbol_resolve(pc, &symbol, &offset)) {
+		    	if (offset)
+				printf("%p: %s+%p()\n", fp, symbol, offset);
+			else
+				printf("%p: %s()\n", fp, symbol);
+		} else {
+			printf("%p: %p()\n", fp, pc);
+		}
+		if (!ops->return_address_get(fp, &pc))
+			break;
+		if (!ops->frame_pointer_prev(fp, &fp))
+			break;
+	}
+}
+
+void stack_trace(void)
+{
+	stack_trace_fp_pc(&kst_ops, frame_pointer_get(), program_counter_get());
+
+	/*
+	 * Prevent the tail call optimization of the previous call by
+	 * making it a non-tail call.
+	 */
+	(void) frame_pointer_get();
+}
+
+void stack_trace_istate(istate_t *istate)
+{
+	if (istate_from_uspace(istate))
+		stack_trace_fp_pc(&ust_ops, istate_get_fp(istate),
+		    istate_get_pc(istate));
+	else
+		stack_trace_fp_pc(&kst_ops, istate_get_fp(istate),
+		    istate_get_pc(istate));
+}
+
+static bool kernel_symbol_resolve(uintptr_t addr, char **sp, uintptr_t *op)
+{
+	return (symtab_name_lookup(addr, sp, op) == 0);
+}
+
+stack_trace_ops_t kst_ops = {
+	.frame_pointer_validate = kernel_frame_pointer_validate,
+	.frame_pointer_prev = kernel_frame_pointer_prev,
+	.return_address_get = kernel_return_address_get,
+	.symbol_resolve = kernel_symbol_resolve
+};
+
+stack_trace_ops_t ust_ops = {
+	.frame_pointer_validate = uspace_frame_pointer_validate,
+	.frame_pointer_prev = uspace_frame_pointer_prev,
+	.return_address_get = uspace_return_address_get,
+	.symbol_resolve = NULL
+};
+
+/** @}
+ */
Index: kernel/generic/src/debug/symtab.c
===================================================================
--- kernel/generic/src/debug/symtab.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ kernel/generic/src/debug/symtab.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -46,6 +46,7 @@
 /** Get name of a symbol that seems most likely to correspond to address.
  *
- * @param addr Address.
- * @param name Place to store pointer to the symbol name.
+ * @param addr		Address.
+ * @param name		Place to store pointer to the symbol name.
+ * @param offset	Place to store offset from the symbol address.
  *
  * @return Zero on success or negative error code, ENOENT if not found,
@@ -53,5 +54,5 @@
  *
  */
-int symtab_name_lookup(unative_t addr, char **name)
+int symtab_name_lookup(uintptr_t addr, char **name, uintptr_t *offset)
 {
 #ifdef CONFIG_SYMTAB
@@ -65,4 +66,7 @@
 	if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le)) {
 		*name = symbol_table[i - 1].symbol_name;
+		if (offset)
+			*offset = addr -
+			    uint64_t_le2host(symbol_table[i - 1].address_le);
 		return EOK;
 	}
@@ -88,8 +92,8 @@
  *
  */
-char *symtab_fmt_name_lookup(unative_t addr)
+char *symtab_fmt_name_lookup(uintptr_t addr)
 {
 	char *name;
-	int rc = symtab_name_lookup(addr, &name);
+	int rc = symtab_name_lookup(addr, &name, NULL);
 	
 	switch (rc) {
Index: uspace/lib/libc/generic/stacktrace.c
===================================================================
--- uspace/lib/libc/generic/stacktrace.c	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ uspace/lib/libc/generic/stacktrace.c	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -39,6 +39,4 @@
 void stack_trace_fp_pc(uintptr_t fp, uintptr_t pc)
 {
-	printf("Printing stack trace:\n");
-	printf("=====================\n");
 	while (frame_pointer_validate(fp)) {
 		printf("%p: %p()\n", fp, pc);
@@ -46,5 +44,4 @@
 		fp = frame_pointer_prev(fp);
 	}
-	printf("=====================\n");
 }
 
Index: uspace/lib/libc/include/assert.h
===================================================================
--- uspace/lib/libc/include/assert.h	(revision 92454138de3db76b779e4a3ddf80182cb677196d)
+++ uspace/lib/libc/include/assert.h	(revision 234e39e658dc0c08fdabeeb8bbb0f20fee1eb942)
@@ -51,5 +51,12 @@
 
 #ifndef NDEBUG
-#	define assert(expr) if (!(expr)) { printf("Assertion failed (%s) at file '%s', line %d.\n", #expr, __FILE__, __LINE__); abort();}
+#	define assert(expr) \
+		do { \
+			if (!(expr)) { \
+				printf("Assertion failed (%s) at file '%s', " \
+				    "line %d.\n", #expr, __FILE__, __LINE__); \
+				abort(); \
+			} \
+		} while (0)
 #else
 #	define assert(expr)
