Permalink
Browse files

Port to Linux-m68k. A lot of this work was done by Roman Hodek,

Estimated hours taken: 20

Port to Linux-m68k.  A lot of this work was done by Roman Hodek,
<Roman.Hodek@informatik.uni-erlangen.de>.

README.Linux-m68k:
	Mention that we have a port to the 68k.

configure.in:
	Add a test for two different sorts of signal handlers
	  void handler(int signum, struct sigcontext_struct context)
	and
	  void handler(int signum, int code, struct sigcontext_struct context)
	Set HAVE_SIGCONTEXT_STRUCT_2ARG or HAVE_SIGCONTEXT_STRUCT_3ARG
	appropriately.

	Add support for shared libraries on the m68k as they should
	work.

	Make "working struct sigcontext" tests use MR_GET_FAULT_ADDR.

boehm_gc/config.h:
	Add some definitions for the m68k.

boehm_gc/os_dep.c:
	Get fault addresses using m68k specific code.

runtime/mercury_conf.h.in:
	Add new configuration definitions HAVE_SIGCONTEXT_STRUCT_2ARG,
	and HAVE_SIGCONTEXT_STRUCT_3ARG.

runtime/mercury_faultaddr.h:
	Add MR_GET_FAULT_ADDR.

runtime/mercury_goto.h:
	Add support for non-local gotos with Linux-68k.

runtime/mercury_memory_handlers.c:
	Handle 2 or 3 argument signal handlers.
  • Loading branch information...
Tyson Dowd
Tyson Dowd committed Oct 2, 1998
1 parent 389548d commit 09ad0c4f150042a92e6f3f633e77da13d6ecf56f
Showing with 125 additions and 10 deletions.
  1. +9 −0 README.Linux-m68k
  2. +10 −0 runtime/mercury_conf.h.in
  3. +58 −0 runtime/mercury_faultaddr.h
  4. +25 −3 runtime/mercury_goto.h
  5. +23 −7 runtime/mercury_memory_handlers.c
View
@@ -0,0 +1,9 @@
+
+Mercury has been ported to Linux/m68k thanks to Roman Hodek
+<Roman.Hodek@informatik.uni-erlangen.de>.
+
+The port is relatively untested -- if you have an m68k machine
+running Linux and run Mercury successfully please let us know.
+
+
+
View
@@ -125,10 +125,20 @@
** HAVE_SIGCONTEXT_STRUCT defined iff normal signal handlers are given
** sigcontext_struct arguments that we can use to
** figure out the fault address for SIGSEGVs.
+** HAVE_SIGCONTEXT_STRUCT_3ARG
+** defined iff signal handlers have three
+** parameters, the third being the
+** sigcontext struct.
+** HAVE_SIGCONTEXT_STRUCT_2ARG
+** defined iff signal handlers have two
+** parameters, the second being the
+** sigcontext struct.
*/
#undef HAVE_SIGINFO
#undef HAVE_SIGINFO_T
#undef HAVE_SIGCONTEXT_STRUCT
+#undef HAVE_SIGCONTEXT_STRUCT_3ARG
+#undef HAVE_SIGCONTEXT_STRUCT_2ARG
/*
** For debugging purposes, if we get a fatal signal, we print out the
@@ -0,0 +1,58 @@
+/*
+** Copyright (C) 1998 The University of Melbourne.
+** This file may only be copied under the terms of the GNU Library General
+** Public License - see the file COPYING.LIB in the Mercury distribution.
+*/
+
+/*
+** mercury_faultaddr.h:
+** Macros for determining the fault address of a signal.
+** This is usually non-portable, so architecture specific versions
+** are given here, so a single macro can be used elsewhere in the
+** system (in particular, this code is necessary both in the
+** runtime and in the configuration scripts).
+*/
+
+#ifndef MERCURY_FAULT_ADDR_H
+#define MERCURY_FAULT_ADDR_H
+
+
+#if defined(__i386__)
+
+ #define MR_GET_FAULT_ADDR(sc) \
+ ((void *)(((struct sigcontext_struct)(sc)).cr2))
+
+#elif defined(__mc68000__)
+
+ #define MR_GET_FAULT_ADDR(sc) \
+ ({ \
+ struct sigcontext *scp = (struct sigcontext *)(&sc); \
+ int format = (scp->sc_formatvec >> 12) & 0xf; \
+ unsigned long *framedata = (unsigned long *)(scp + 1); \
+ unsigned long ea; \
+ if (format == 0xa || format == 0xb) \
+ /* 68020/030 */ \
+ ea = framedata[2]; \
+ else if (format == 7) \
+ /* 68040 */ \
+ ea = framedata[3]; \
+ else if (format == 4) { \
+ /* 68060 */ \
+ ea = framedata[0]; \
+ if (framedata[1] & 0x08000000) \
+ /* correct addr on misaligned access */ \
+ ea = (ea+4095)&(~4095); \
+ } \
+ (void *)ea; \
+ })
+#else
+
+/*
+** This space deliberately left blank.
+**
+** We will get a compile error if it is used but not defined.
+*/
+
+#endif
+
+#endif /* not MERCURY_FAULT_ADDR_H */
View
@@ -111,10 +111,12 @@
#define ASM_FALLTHROUGH(label) \
goto skip(label);
-#elif defined(__i386__)
+#elif defined(__i386__) || defined(__mc68000__)
/*
** The following hack works around a stack leak on the i386.
+ ** (and apparently the 68000 too).
+ **
** The problem is that gcc pushes function parameters onto
** the stack when calling C functions such as GC_malloc(),
** and only restores the stack pointer in the epilogue.
@@ -135,10 +137,17 @@
**
** I know this is awful. It wasn't _my_ idea to use non-local gotos ;-)
*/
- #define ASM_JUMP(label) \
+ #if defined(__i386__)
+ #define ASM_JUMP(label) \
{ register int stack_pointer __asm__("esp"); \
__asm__("" : : "g"(stack_pointer)); } \
goto *(label)
+ #elif defined(__mc68000__)
+ #define ASM_JUMP(label) \
+ { register int stack_pointer __asm__("sp"); \
+ __asm__("" : : "g"(stack_pointer)); } \
+ goto *(label)
+ #endif
/*
** That hack above needs to be done for all non-local jumps,
@@ -178,7 +187,9 @@
** setjmp()/longjmp() will do that for us automatically,
** precisely because it is a callee-save register.
*/
- #define INLINE_ASM_FIXUP_REGS \
+ #if defined(__i386__)
+
+ #define INLINE_ASM_FIXUP_REGS \
" call 0f\n" \
"0:\n" \
" popl %%ebx\n" \
@@ -192,6 +203,17 @@
/* tell gcc we clobber ebx and memory */ \
: : : "%ebx", "memory"
#endif
+ #elif defined(__mc68000__)
+
+ /*
+ ** This piece of magic thanks to Roman Hodek
+ ** <Roman.Hodek@informatik.uni-erlangen.de>
+ */
+
+ #define INLINE_ASM_FIXUP_REGS \
+ " lea (%%pc,_GLOBAL_OFFSET_TABLE_@GOTPC),%%a5\n" : : : "memory"
+
+ #endif
/*
** It is safe to fall through into INLINE_ASM_FIXUP_REGS,
@@ -68,12 +68,18 @@
#include "mercury_trace_base.h"
#include "mercury_memory_zones.h"
#include "mercury_memory_handlers.h"
+#include "mercury_faultaddr.h"
/*---------------------------------------------------------------------------*/
#ifdef HAVE_SIGINFO
#if defined(HAVE_SIGCONTEXT_STRUCT)
- static void complex_sighandler(int, struct sigcontext_struct);
+ #if defined(HAVE_SIGCONTEXT_STRUCT_3ARG)
+ static void complex_sighandler_3arg(int, int,
+ struct sigcontext_struct);
+ #else
+ static void complex_sighandler(int, struct sigcontext_struct);
+ #endif
#elif defined(HAVE_SIGINFO_T)
static void complex_bushandler(int, siginfo_t *, void *);
static void complex_segvhandler(int, siginfo_t *, void *);
@@ -87,8 +93,13 @@
#ifdef HAVE_SIGINFO
#if defined(HAVE_SIGCONTEXT_STRUCT)
- #define bus_handler complex_sighandler
- #define segv_handler complex_sighandler
+ #if defined(HAVE_SIGCONTEXT_STRUCT_3ARG)
+ #define bus_handler complex_sighandler_3arg
+ #define segv_handler complex_sighandler_3arg
+ #else
+ #define bus_handler complex_sighandler
+ #define segv_handler complex_sighandler
+ #endif
#elif defined(HAVE_SIGINFO_T)
#define bus_handler complex_bushandler
#define segv_handler complex_segvhandler
@@ -306,11 +317,16 @@ explain_context(void *the_context)
}
#if defined(HAVE_SIGCONTEXT_STRUCT)
-
-static void
-complex_sighandler(int sig, struct sigcontext_struct sigcontext)
+ #if defined(HAVE_SIGCONTEXT_STRUCT_3ARG)
+ static void
+ complex_sighandler_3arg(int sig, int code,
+ struct sigcontext_struct sigcontext)
+ #else
+ static void
+ complex_sighandler(int sig, struct sigcontext_struct sigcontext)
+ #endif
{
- void *address = (void *) sigcontext.cr2;
+ void *address = (void *) MR_GET_FAULT_ADDR(sigcontext);
#ifdef PC_ACCESS
void *pc_at_signal = (void *) sigcontext.PC_ACCESS;
#endif

0 comments on commit 09ad0c4

Please sign in to comment.