Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/Makefile.inc	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/include/context.h	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/include/interrupt.h	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/src/asm_utils.S	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/src/boot/boot.S	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
+++ kernel/arch/amd64/src/debug/stacktrace.c	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
+++ kernel/arch/amd64/src/debug/stacktrace_asm.S	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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 fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/src/interrupt.c	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -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/smp/ap.S
===================================================================
--- kernel/arch/amd64/src/smp/ap.S	(revision fabc883d64c4961d00f1413b0d4b3f6776217638)
+++ kernel/arch/amd64/src/smp/ap.S	(revision aff0503b76b3e5fb8fac8b68d9813e1a5f514c4f)
@@ -99,4 +99,6 @@
 start64:
 	movq (ctx), %rsp
+	pushq $0
+	movq %rsp, %rbp
 	call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET   # never returns
 
