Index: uspace/app/tester/Makefile.build
===================================================================
--- uspace/app/tester/Makefile.build	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/app/tester/Makefile.build	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -49,4 +49,5 @@
 	fault/fault1.c \
 	fault/fault2.c \
+	fault/fault3.c \
 	vfs/vfs1.c \
 	ipc/ping_pong.c \
Index: uspace/app/tester/fault/fault3.c
===================================================================
--- uspace/app/tester/fault/fault3.c	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/app/tester/fault/fault3.c	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#include "../tester.h"
+#include <stdlib.h>
+
+char *test_fault3(void)
+{
+	abort();
+}
Index: uspace/app/tester/fault/fault3.def
===================================================================
--- uspace/app/tester/fault/fault3.def	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/app/tester/fault/fault3.def	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,6 @@
+{
+	"fault3",
+	"Abort",
+	&test_fault3,
+	true
+},
Index: uspace/app/tester/tester.c
===================================================================
--- uspace/app/tester/tester.c	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/app/tester/tester.c	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -56,4 +56,5 @@
 #include "fault/fault1.def"
 #include "fault/fault2.def"
+#include "fault/fault3.def"
 #include "vfs/vfs1.def"
 #include "ipc/ping_pong.def"
Index: uspace/app/tester/tester.h
===================================================================
--- uspace/app/tester/tester.h	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/app/tester/tester.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -73,4 +73,5 @@
 extern char *test_fault1(void);
 extern char *test_fault2(void);
+extern char *test_fault3(void);
 extern char *test_vfs1(void);
 extern char *test_ping_pong(void);
Index: uspace/lib/libc/Makefile.build
===================================================================
--- uspace/lib/libc/Makefile.build	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/Makefile.build	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -87,5 +87,6 @@
 	generic/udebug.c \
 	generic/vfs/vfs.c \
-	generic/vfs/canonify.c
+	generic/vfs/canonify.c \
+	generic/stacktrace.c
 
 ARCH_SOURCES += \
Index: uspace/lib/libc/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/amd64/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/amd64/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -36,6 +36,8 @@
 ARCH_SOURCES += arch/$(UARCH)/src/syscall.S \
 	arch/$(UARCH)/src/fibril.S \
-	arch/$(UARCH)/src/tls.c
+	arch/$(UARCH)/src/tls.c \
+	arch/$(UARCH)/src/stacktrace.S
 
+GCC_CFLAGS += -fno-omit-frame-pointer
 LFLAGS += -N
 
Index: uspace/lib/libc/arch/amd64/include/fibril.h
===================================================================
--- uspace/lib/libc/arch/amd64/include/fibril.h	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/amd64/include/fibril.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -44,4 +44,12 @@
 #define SP_DELTA     16
 
+#define context_set(c, _pc, stack, size, ptls) \
+	do { \
+		(c)->pc = (sysarg_t) (_pc); \
+		(c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
+		(c)->tls = (sysarg_t) (ptls); \
+		(c)->rbp = 0; \
+	} while (0)
+
 /* We include only registers that must be preserved
  * during function call
Index: uspace/lib/libc/arch/amd64/src/entry.s
===================================================================
--- uspace/lib/libc/arch/amd64/src/entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/amd64/src/entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -38,4 +38,10 @@
 #
 __entry:
+	#
+	# Create the first stack frame.
+	#
+	pushq $0
+	mov %rsp, %rbp
+	
 	# %rdi was deliberately chosen as the first argument is also in %rdi
 	# Pass PCB pointer to __main (no operation)
Index: uspace/lib/libc/arch/amd64/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/amd64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/amd64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,55 @@
+#
+# 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.
+#
+
+.text
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+	movq %rbp, %rax
+	ret
+
+frame_pointer_prev:
+	movq (%rdi), %rax
+	ret
+
+frame_pointer_validate:
+	movq %rdi, %rax
+	ret
+
+return_address_get:
+	movq 8(%rdi), %rax
+	ret
+
+program_counter_get:
+	movq (%rsp), %rax
+	ret
Index: uspace/lib/libc/arch/amd64/src/thread_entry.s
===================================================================
--- uspace/lib/libc/arch/amd64/src/thread_entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/amd64/src/thread_entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -36,4 +36,10 @@
 __thread_entry:
 	#
+	# Create the first stack frame.
+	#
+	pushq $0
+	movq %rsp, %rbp
+
+	#
 	# RAX contains address of uarg
 	#
Index: uspace/lib/libc/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/arm32/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/arm32/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -37,5 +37,6 @@
 	arch/$(UARCH)/src/fibril.S \
 	arch/$(UARCH)/src/tls.c \
-	arch/$(UARCH)/src/eabi.S
+	arch/$(UARCH)/src/eabi.S \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -ffixed-r9 -mtp=soft
Index: uspace/lib/libc/arch/arm32/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/arm32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/arm32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,44 @@
+#
+# 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.
+#
+
+.text
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+frame_pointer_prev:
+frame_pointer_validate:
+return_address_get:
+program_counter_get:
+	mov r0, #0
+	mov pc, lr
+
Index: uspace/lib/libc/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ia32/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ia32/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -37,5 +37,6 @@
 	arch/$(UARCH)/src/fibril.S \
 	arch/$(UARCH)/src/tls.c \
-	arch/$(UARCH)/src/setjmp.S
+	arch/$(UARCH)/src/setjmp.S \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -march=pentium
Index: uspace/lib/libc/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/libc/arch/ia32/include/fibril.h	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ia32/include/fibril.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -44,4 +44,12 @@
 #define SP_DELTA     (12)
 
+#define context_set(c, _pc, stack, size, ptls) \
+	do { \
+		(c)->pc = (sysarg_t) (_pc); \
+		(c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
+		(c)->tls = (sysarg_t) (ptls); \
+		(c)->ebp = 0; \
+	} while (0)
+	
 /* We include only registers that must be preserved
  * during function call
Index: uspace/lib/libc/arch/ia32/src/entry.s
===================================================================
--- uspace/lib/libc/arch/ia32/src/entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ia32/src/entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -55,4 +55,9 @@
 	movl $__syscall_fast, (%eax)
 0:
+	#
+	# Create the first stack frame.
+	#
+	pushl $0 
+	movl %esp, %ebp
 
 	# Pass the PCB pointer to __main as the first argument
Index: uspace/lib/libc/arch/ia32/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/ia32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/ia32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,57 @@
+#
+# 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.
+#
+
+.text
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+	movl %ebp, %eax
+	ret
+
+frame_pointer_prev:
+	movl 4(%esp), %eax
+	movl (%eax), %eax
+	ret
+
+frame_pointer_validate:
+	movl 4(%esp), %eax
+	ret
+
+return_address_get:
+	movl 4(%esp), %eax
+	movl 4(%eax), %eax
+	ret
+
+program_counter_get:
+	movl (%esp), %eax
+	ret
Index: uspace/lib/libc/arch/ia32/src/thread_entry.s
===================================================================
--- uspace/lib/libc/arch/ia32/src/thread_entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ia32/src/thread_entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -42,4 +42,10 @@
 
 	#
+	# Create the first stack frame.
+	#
+	pushl $0
+	mov %esp, %ebp
+
+	#
 	# EAX contains address of uarg.
 	#
Index: uspace/lib/libc/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ia64/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ia64/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -36,5 +36,6 @@
 	arch/$(UARCH)/src/fibril.S \
 	arch/$(UARCH)/src/tls.c \
-	arch/$(UARCH)/src/ddi.c
+	arch/$(UARCH)/src/ddi.c \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -fno-unwind-tables
Index: uspace/lib/libc/arch/ia64/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/ia64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/ia64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,43 @@
+#
+# 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.
+#
+
+.text
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+frame_pointer_prev:
+frame_pointer_validate:
+return_address_get:
+program_counter_get:
+	mov r8 = r0
+	br.ret.sptk.many b0
Index: uspace/lib/libc/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/mips32/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/mips32/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -35,5 +35,6 @@
 ARCH_SOURCES += arch/$(UARCH)/src/syscall.c \
 	arch/$(UARCH)/src/fibril.S \
-	arch/$(UARCH)/src/tls.c
+	arch/$(UARCH)/src/tls.c \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -mips3
Index: uspace/lib/libc/arch/mips32/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/mips32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/mips32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+
+.text
+
+.set noat
+.set noreorder
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+frame_pointer_prev:
+frame_pointer_validate:
+return_address_get:
+program_counter_get:
+	j $ra
+	xor $v0, $v0
Index: uspace/lib/libc/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ppc32/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/ppc32/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -35,5 +35,6 @@
 ARCH_SOURCES += arch/$(UARCH)/src/syscall.c \
 	arch/$(UARCH)/src/fibril.S \
-	arch/$(UARCH)/src/tls.c
+	arch/$(UARCH)/src/tls.c \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -mcpu=powerpc -msoft-float -m32
Index: uspace/lib/libc/arch/ppc32/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/ppc32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/ppc32/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,45 @@
+#
+# 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.
+#
+
+.text
+
+#include <libarch/regname.h>
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+frame_pointer_prev:
+frame_pointer_validate:
+return_address_get:
+program_counter_get:
+	li r3, 0
+	blr
Index: uspace/lib/libc/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/sparc64/Makefile.inc	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/sparc64/Makefile.inc	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -34,5 +34,6 @@
 
 ARCH_SOURCES += arch/$(UARCH)/src/fibril.S \
-	arch/$(UARCH)/src/tls.c
+	arch/$(UARCH)/src/tls.c \
+	arch/$(UARCH)/src/stacktrace.S
 
 GCC_CFLAGS += -mcpu=ultrasparc -m64
Index: uspace/lib/libc/arch/sparc64/include/fibril.h
===================================================================
--- uspace/lib/libc/arch/sparc64/include/fibril.h	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/sparc64/include/fibril.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -46,10 +46,12 @@
 #endif
 
-#define context_set(c, _pc, stack, size, ptls)			\
-	(c)->pc = ((uintptr_t) _pc) - 8;			\
-	(c)->sp = ((uintptr_t) stack) + ALIGN_UP((size),	\
-		STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA);	\
-	(c)->fp = -STACK_BIAS;					\
-	(c)->tp = ptls
+#define context_set(c, _pc, stack, size, ptls) \
+	do { \
+		(c)->pc = ((uintptr_t) _pc) - 8; \
+		(c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), \
+		    STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \
+		(c)->fp = -STACK_BIAS; \
+		(c)->tp = ptls; \
+	} while (0)
 	
 /*
Index: uspace/lib/libc/arch/sparc64/src/entry.s
===================================================================
--- uspace/lib/libc/arch/sparc64/src/entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/sparc64/src/entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -39,6 +39,13 @@
 #
 __entry:
+	#
+	# Create the first stack frame.
+	#
+	save %sp, -176, %sp
+	flushw
+	add %g0, -0x7ff, %fp
+
 	# Pass pcb_ptr as the first argument to __main()
-	mov %o1, %o0
+	mov %i1, %o0
 	sethi %hi(_gp), %l7
 	call __main
Index: uspace/lib/libc/arch/sparc64/src/stacktrace.S
===================================================================
--- uspace/lib/libc/arch/sparc64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/arch/sparc64/src/stacktrace.S	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,71 @@
+#
+# 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.
+#
+
+#include <libarch/stack.h>
+
+.text
+
+.global frame_pointer_get
+.global frame_pointer_prev
+.global frame_pointer_validate
+.global return_address_get
+.global program_counter_get
+
+frame_pointer_get:
+	# Add the stack bias to %sp to get the actual address.
+	retl
+	add %sp, STACK_BIAS, %o0
+
+frame_pointer_prev:
+	save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp
+	# Flush all other windows to memory so that we can read their contents.
+	flushw
+	# Read the %fp from the window save area.
+	ldx [%i0 + 14 * 8], %i0
+	# Add the stack bias to the %fp read from the window save area.
+	add %i0, STACK_BIAS, %i0
+	ret
+	restore
+
+frame_pointer_validate:
+	retl
+	nop
+
+return_address_get:
+	save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp
+	# Flush all other windows to memory so that we can read their contents.
+	flushw
+	# Read the %i7 from the window save area.
+	ldx [%i0 + 15 * 8], %i0
+	ret
+	restore
+
+program_counter_get:
+	retl
+	mov %o7, %o0
+
Index: uspace/lib/libc/arch/sparc64/src/thread_entry.s
===================================================================
--- uspace/lib/libc/arch/sparc64/src/thread_entry.s	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/arch/sparc64/src/thread_entry.s	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -35,4 +35,11 @@
 #
 __thread_entry:
+	#
+	# Create the first stack frame.
+	#
+	save %sp, -176, %sp
+	flushw
+	add %g0, -0x7ff, %fp
+
 	sethi %hi(_gp), %l7
 	call __thread_main		! %o0 contains address of uarg
Index: uspace/lib/libc/generic/stacktrace.c
===================================================================
--- uspace/lib/libc/generic/stacktrace.c	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/generic/stacktrace.c	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,57 @@
+/*
+ * 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#include <stacktrace.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+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);
+		pc = return_address_get(fp);
+		fp = frame_pointer_prev(fp);
+	}
+	printf("=====================\n");
+}
+
+void stack_trace(void)
+{
+	stack_trace_fp_pc(frame_pointer_get(), program_counter_get());
+}
+
+/** @}
+ */
Index: uspace/lib/libc/include/stacktrace.h
===================================================================
--- uspace/lib/libc/include/stacktrace.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
+++ uspace/lib/libc/include/stacktrace.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -0,0 +1,56 @@
+/*
+ * 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_STACKTRACE_H_
+#define LIBC_STACKTRACE_H_
+
+#include <sys/types.h>
+#include <bool.h>
+
+extern void stack_trace(void);
+extern void stack_trace_fp_pc(uintptr_t, uintptr_t);
+
+/*
+ * The following interface is to be implemented by each architecture.
+ */
+extern bool frame_pointer_validate(uintptr_t);
+extern uintptr_t frame_pointer_get(void);
+extern uintptr_t frame_pointer_prev(uintptr_t);
+extern uintptr_t return_address_get(uintptr_t);
+extern uintptr_t program_counter_get();
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/stdlib.h
===================================================================
--- uspace/lib/libc/include/stdlib.h	(revision 26b50cb018ed2bfdca81893e0151dd1f72c161fb)
+++ uspace/lib/libc/include/stdlib.h	(revision 40cb845e27b2621bd75305a3dd0b262cd21ab995)
@@ -38,6 +38,12 @@
 #include <unistd.h>
 #include <malloc.h>
+#include <stacktrace.h>
 
-#define abort()       _exit(1)
+#define abort() \
+	do { \
+		stack_trace(); \
+		_exit(1); \
+	} while (0)
+
 #define exit(status)  _exit((status))
 
