This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC]: MD_FALLBACK_FRAME_STATE_FOR macro for darwin PPC


Hello,

My six week old son is responsible for this patch. While he couldn't sleep I had to stay up ....

Here the outcome, hopefully useful.

There are two issues, first, the struct sigframe is a bit guess work and I only found it by luck. It would be great if an expert could verify/correct me if I do it right.

Second, this patch will probably only work on powerpc-apple-darwin7*. I don't expect it to run under darwin6.x. Things improved and changed from 6.x to 7.x. (signal handling works without mach msg handler, glibc changed....)

So, the question is, how do I check inside darwin.h which OS version I have?

I tested this patch on powerpc-apple-darwin-7.2.0 with a static & a dylib build. Mainly in the area of libjava. At the moment I run a clean build from todays cvs to check over night. (dylib)

In the area of libjava I could successfully eliminate the magic Throw_2 failure. Also some mauve tests succeed now (afair).

To test the macro I used also the catcher.cc app from here:
http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00652.html

Thanks David, made the work much easier.

Also a thanks to Andrew for motivating me and for clarifying thinkos.

The part needed for libjava signal handling will follow in a separate mail to java patches.


Any feedback welcome, and please review!


Andreas

Index: config/rs6000/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/darwin.h,v
retrieving revision 1.46
diff -u -r1.46 darwin.h
--- config/rs6000/darwin.h	17 Jan 2004 19:48:50 -0000	1.46
+++ config/rs6000/darwin.h	20 Jan 2004 20:07:37 -0000
@@ -1,5 +1,5 @@
 /* Target definitions for PowerPC running Darwin (Mac OS X).
-   Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1997, 2000, 2001, 2003 2004 Free Software Foundation, Inc.
    Contributed by Apple Computer Inc.
 
    This file is part of GCC.
@@ -321,3 +321,64 @@
 #undef REGISTER_TARGET_PRAGMAS
 #define REGISTER_TARGET_PRAGMAS DARWIN_REGISTER_TARGET_PRAGMAS
 
+#ifdef IN_LIBGCC2
+
+#include <signal.h>
+#include <sys/ucontext.h>
+
+enum { SIGNAL_FRAMESIZE = 0x0 }; /* Not used at the moment.  */
+
+#endif
+
+#define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
+  do {									\
+    unsigned int *pc_ = (CONTEXT)->ra;					\
+    struct mcontext *mc_;						\
+    long new_cfa_;							\
+    int i_;								\
+    									\
+    if (*(unsigned int *) (pc_ + 0) != 0x2e1e0032)			\
+      break;								\
+    if (*(unsigned int *) (pc_ + 4) == 0x40be0050			\
+	|| *(unsigned int *) (pc_ + 4) == 0x41920010)			\
+      {									\
+	struct sigframe {						\
+	  char redzone[216];						\
+	  struct ucontext uc;						\
+	  siginfo_t st;							\
+	  struct mcontext mc;						\
+	  char gap[SIGNAL_FRAMESIZE];					\
+	} *rt_ = (CONTEXT)->cfa;					\
+	mc_ = &rt_->mc;							\
+      }									\
+    else								\
+      break;		       						\
+									\
+    new_cfa_ = mc_->ss.r1;						\
+    (FS)->cfa_how = CFA_REG_OFFSET;					\
+    (FS)->cfa_reg = STACK_POINTER_REGNUM;				\
+    (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;		\
+    									\
+    /* r0 to r31 are variable names in the ppc_thread_state struct	\
+       since we need the address we just increment the r0 by i_ * 4	\
+       to get the other vars addresses.  */				\
+    									\
+    for (i_ = 0; i_ < 32; i_++) {					\
+      if (i_ != STACK_POINTER_REGNUM)					\
+	{								\
+	  (FS)->regs.reg[i_].how = REG_SAVED_OFFSET;			\
+	  (FS)->regs.reg[i_].loc.offset					\
+	    = (long)&(mc_->ss.r0) + (i_*4) - new_cfa_;			\
+	}								\
+    }									\
+    									\
+    (FS)->regs.reg[LINK_REGISTER_REGNUM].how = REG_SAVED_OFFSET;	\
+    (FS)->regs.reg[LINK_REGISTER_REGNUM].loc.offset			\
+      = (long)&(mc_->ss.lr) - new_cfa_;					\
+    									\
+    (FS)->regs.reg[CR0_REGNO].how = REG_SAVED_OFFSET;			\
+    (FS)->regs.reg[CR0_REGNO].loc.offset				\
+      = (long)&(mc_->ss.srr0) - new_cfa_;				\
+    (FS)->retaddr_column = CR0_REGNO;					\
+    goto SUCCESS;							\
+  } while (0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]