Index: configure.in
===================================================================
RCS file: /pub/cvs/ruby/src/ruby/configure.in,v
retrieving revision 1.187
diff -u -2 -p -r1.187 configure.in
--- configure.in	15 Aug 2003 03:01:51 -0000	1.187
+++ configure.in	17 Aug 2003 10:50:20 -0000
@@ -349,5 +349,5 @@ AC_CHECK_HEADERS(stdlib.h string.h unist
 		 fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
 		 syscall.h pwd.h grp.h a.out.h utime.h memory.h direct.h sys/resource.h \
-		 sys/mkdev.h sys/utime.h float.h)
+		 sys/mkdev.h sys/utime.h float.h unwind.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -477,4 +477,20 @@ AC_C_CHAR_UNSIGNED
 AC_C_INLINE
 AC_C_VOLATILE
+
+if test x"$target_cpu" = xia64; then
+    if test x"$ac_cv_header_unwind_h" = xyes; then
+	LIBS="-lunwind $LIBS"
+    else
+	AC_CACHE_CHECK(IA64 backing store member in mcontext_t, rb_cv_ia64_bspstore,
+	    [rb_cv_ia64_bspstore=no;
+	    for mem in mc_special.bspstore sc_ar_bsp; do
+	    AC_TRY_COMPILE([#include <ucontext.h>
+],[ucontext_t ctx; ctx.uc_mcontext.$mem = 0;], [rb_cv_ia64_bspstore=$mem; break])
+	    done])
+	if test "$rb_cv_ia64_bspstore" != no; then
+	    AC_DEFINE_UNQUOTED(IA64_BSPSTORE, $rb_cv_ia64_bspstore)
+	fi
+    fi
+fi
 
 AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
Index: eval.c
===================================================================
RCS file: /pub/cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.515
diff -u -2 -p -r1.515 eval.c
--- eval.c	14 Aug 2003 17:19:23 -0000	1.515
+++ eval.c	17 Aug 2003 10:44:46 -0000
@@ -7752,7 +7752,11 @@ Init_Proc()
 #ifdef __ia64__
 #include <ucontext.h>
+#ifdef HAVE_UNWIND_H
+#include <unwind.h>
+#else
 #pragma weak __libc_ia64_register_backing_store_base
 extern unsigned long __libc_ia64_register_backing_store_base;
 #endif
+#endif
 
 /* Windows SEH refers data on the stack. */
@@ -8215,17 +8219,22 @@ rb_thread_save_context(th)
 #ifdef __ia64__
     {
-	ucontext_t ctx;
 	VALUE *top, *bot;
+#ifdef HAVE_UNWIND_H
+	_Unwind_Context *unwctx = _UNW_createContextForSelf();
+
+	_UNW_currentContext(unwctx);
+	bot = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSP);
+	top = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSPSTORE);
+	_UNW_destroyContext(unwctx);
+#else
+	ucontext_t ctx;
 
 	getcontext(&ctx);
 	bot = (VALUE*)__libc_ia64_register_backing_store_base;
-#if defined(__FreeBSD__)
-	top = (VALUE*)ctx.uc_mcontext.mc_special.bspstore;
-#else
-	top = (VALUE*)ctx.uc_mcontext.sc_ar_bsp;
+	top = (VALUE*)ctx.uc_mcontext.IA64_BSPSTORE;
 #endif
 	th->bstr_len = top - bot;
 	REALLOC_N(th->bstr_ptr, VALUE, th->bstr_len);
-	MEMCPY(th->bstr_ptr, (VALUE*)__libc_ia64_register_backing_store_base, VALUE, th->bstr_len);
+	MEMCPY(th->bstr_ptr, bot, VALUE, th->bstr_len);
     }
 #endif
@@ -8368,5 +8377,17 @@ rb_thread_restore_context(th, exit)
     MEMCPY(tmp->stk_pos, tmp->stk_ptr, VALUE, tmp->stk_len);
 #ifdef __ia64__
-    MEMCPY((VALUE*)__libc_ia64_register_backing_store_base, tmp->bstr_ptr, VALUE, tmp->bstr_len);
+    {
+	VALUE *base;
+#ifdef HAVE_UNWIND_H
+	_Unwind_Context *unwctx = _UNW_createContextForSelf();
+	
+	_UNW_currentContext(unwctx);
+	base = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSP);
+	_UNW_destroyContext(unwctx);
+#else
+	base = (VALUE*)__libc_ia64_register_backing_store_base;
+#endif
+	MEMCPY(base, tmp->bstr_ptr, VALUE, tmp->bstr_len);
+    }
 #endif
 
Index: gc.c
===================================================================
RCS file: /pub/cvs/ruby/src/ruby/gc.c,v
retrieving revision 1.155
diff -u -2 -p -r1.155 gc.c
--- gc.c	14 Aug 2003 17:19:23 -0000	1.155
+++ gc.c	17 Aug 2003 10:44:55 -0000
@@ -33,7 +33,11 @@
 #ifdef __ia64__
 #include <ucontext.h>
+#ifdef HAVE_UNWIND_H
+#include <unwind.h>
+#else
 #pragma weak __libc_ia64_register_backing_store_base
 extern unsigned long __libc_ia64_register_backing_store_base;
 #endif
+#endif
 
 void re_free_registers _((struct re_registers*));
@@ -1256,12 +1260,19 @@ rb_gc()
 	ucontext_t ctx;
 	VALUE *top, *bot;
+#ifdef HAVE_UNWIND_H
+	_Unwind_Context *unwctx = _UNW_createContextForSelf();
+#endif
+
 	getcontext(&ctx);
 	mark_locations_array((VALUE*)&ctx.uc_mcontext,
 			     ((size_t)(sizeof(VALUE)-1 + sizeof ctx.uc_mcontext)/sizeof(VALUE)));
-	bot = (VALUE*)__libc_ia64_register_backing_store_base;
-#if defined(__FreeBSD__)
-	top = (VALUE*)ctx.uc_mcontext.mc_special.bspstore;
+#ifdef HAVE_UNWIND_H
+	_UNW_currentContext(unwctx);
+	bot = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSP);
+	top = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSPSTORE);
+	_UNW_destroyContext(unwctx);
 #else
-	top = (VALUE*)ctx.uc_mcontext.sc_ar_bsp;
+	bot = (VALUE*)__libc_ia64_register_backing_store_base;
+	top = (VALUE*)ctx.uc_mcontext.IA64_BSPSTORE;
 #endif
 	rb_gc_mark_locations(bot, top);
