Changeset 13637


Ignore:
Timestamp:
Apr 18, 2010, 9:24:51 AM (10 years ago)
Author:
gb
Message:

Move some PPC exception stuff to platform header.

Location:
trunk/source/lisp-kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/platform-darwinppc.h

    r13627 r13637  
    3636#include "lisptypes.h"
    3737#include "ppc-constants32.h"
     38
     39/* xp accessors.  Logically identical on darwinppc32/64. */
     40#define xpGPRvector(x) (&(UC_MCONTEXT(x)->__ss.__r0))
     41#define xpGPR(x,gprno) ((xpGPRvector(x))[gprno])
     42#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (UInt32)(new)
     43#define xpPC(x) (*((pc*) &(UC_MCONTEXT(x)->__ss.__srr0)))
     44#define set_xpPC(x,new) (xpPC(x) = (pc)(new))
     45#define xpLR(x) (*((pc*)(&(UC_MCONTEXT(x)->__ss.__lr))))
     46#define xpCTR(x) (*(pc*)(&(UC_MCONTEXT(x)->__ss.__ctr)))
     47#define xpXER(x) (UC_MCONTEXT(x)->__ss.__xer)
     48#define xpCCR(x) (UC_MCONTEXT(x)->__ss.__cr)
     49#define xpMSR(x) (UC_MCONTEXT(x)->__ss.__srr1)
     50#define xpDSISR(x) (UC_MCONTEXT(x)->__es.__dsisr)
     51#define xpDAR(x) (UC_MCONTEXT(x)->__es.__dar)
     52#define xpTRAP(x) (UC_MCONTEXT(x)->__es.__exception)
     53#define xpFPSCR(x) (UC_MCONTEXT(x)->__fs.__fpscr)
     54#define xpFPRvector(x) (UC_MCONTEXT(x)->__fs.__fpregs)
     55#define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
     56
     57/* Late versions of OSX 10.2 had a bug in 32-bit exception handling;
     58   machine context wasn't restored correctly if it wasn't modified
     59   by the exception handler.  DarwinSigReturn() was a macro that
     60   tried to work around this.
     61*/
     62#define DarwinSigReturn(x)
     63
     64/* On some platforms, we may need to do something more than returning
     65   from a signal handler in order to return to the kernel and let it
     66   restore context.  On DarwinPPC, that's not a factor.
     67*/
     68#define SIGRETURN(context)
     69
  • trunk/source/lisp-kernel/platform-darwinppc64.h

    r13627 r13637  
    3636#include "lisptypes.h"
    3737#include "ppc-constants64.h"
     38
     39
     40/* xp accessors.  Logically identical on darwinppc32/64. */
     41#define xpGPRvector(x) (&(UC_MCONTEXT(x)->__ss.__r0))
     42#define xpGPR(x,gprno) ((xpGPRvector(x))[gprno])
     43#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (UInt32)(new)
     44#define xpPC(x) (*((pc*) &(UC_MCONTEXT(x)->__ss.__srr0)))
     45#define set_xpPC(x,new) (xpPC(x) = (pc)(new))
     46#define xpLR(x) (*((pc*)(&(UC_MCONTEXT(x)->__ss.__lr))))
     47#define xpCTR(x) (*(pc*)(&(UC_MCONTEXT(x)->__ss.__ctr)))
     48#define xpXER(x) (UC_MCONTEXT(x)->__ss.__xer)
     49#define xpCCR(x) (UC_MCONTEXT(x)->__ss.__cr)
     50#define xpMSR(x) (UC_MCONTEXT(x)->__ss.__srr1)
     51#define xpDSISR(x) (UC_MCONTEXT(x)->__es.__dsisr)
     52#define xpDAR(x) (UC_MCONTEXT(x)->__es.__dar)
     53#define xpTRAP(x) (UC_MCONTEXT(x)->__es.__exception)
     54#define xpFPSCR(x) (UC_MCONTEXT(x)->__fs.__fpscr)
     55#define xpFPRvector(x) (UC_MCONTEXT(x)->__fs.__fpregs)
     56#define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
     57
     58/* Late versions of OSX 10.2 had a bug in 32-bit exception handling;
     59   machine context wasn't restored correctly if it wasn't modified
     60   by the exception handler.  DarwinSigReturn() was a macro that
     61   tried to work around this.
     62*/
     63#define DarwinSigReturn(x)
     64
     65/* On some platforms, we may need to do something more than returning
     66   from a signal handler in order to return to the kernel and let it
     67   restore context.  On DarwinPPC, that's not a factor.
     68*/
     69#define SIGRETURN(context)
  • trunk/source/lisp-kernel/platform-linuxppc.h

    r13627 r13637  
    3131#include "lisptypes.h"
    3232#include "ppc-constants32.h"
     33
     34/* xp accessors.  Logically identical on linuxppc32/64. */
     35#define XP_PTREGS(x) ((x)->uc_mcontext.regs)
     36#define xpGPRvector(x) ((natural *)(XP_PTREGS(x)))
     37#define XP_PTREGS(x) ((x)->uc_mcontext.regs)
     38#define xpGPRvector(x) ((natural *)(XP_PTREGS(x)))
     39#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
     40#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
     41#define xpPC(x) (*((pc*)(&(XP_PTREGS(x)->nip))))
     42#define set_xpPC(x,new) (xpPC(x) = (pc)(new))
     43#define xpLR(x) (*((pc*)(&(XP_PTREGS(x)->link))))
     44#define xpCTR(x) (*(pc*)(&(XP_PTREGS(x)->ctr)))
     45#define xpXER(x) (XP_PTREGS(x)->xer)
     46#define xpCCR(x) (XP_PTREGS(x)->ccr)
     47#define xpMSR(x) (XP_PTREGS(x)->msr)
     48#define xpDSISR(x) (XP_PTREGS(x)->dsisr)
     49#define xpDAR(x) (XP_PTREGS(x)->dar)
     50#define xpTRAP(x) (XP_PTREGS(x)->trap)
     51#define xpFPSCR(x) (XP_PTREGS(x)->gpr[PT_FPSCR])
     52#define xpFPRvector(x) ((double *)(&(XP_PTREGS(x)->gpr[PT_FPR0])))
     53#define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
     54
     55/*
     56   Work around a Darwin G5 bug (present in OSX 10.2.7, 10.2.8, and later
     57   versions.  See platform-darwinppc*.h for details
     58*/
     59#define DarwinSigReturn(context)
     60#define SIGRETURN(context)
  • trunk/source/lisp-kernel/platform-linuxppc64.h

    r13627 r13637  
    3030#include "lisptypes.h"
    3131#include "ppc-constants64.h"
     32
     33/* xp accessors.  Logically identical on linuxppc32/64. */
     34#define XP_PTREGS(x) ((x)->uc_mcontext.regs)
     35#define xpGPRvector(x) ((natural *)(XP_PTREGS(x)))
     36#define XP_PTREGS(x) ((x)->uc_mcontext.regs)
     37#define xpGPRvector(x) ((natural *)(XP_PTREGS(x)))
     38#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
     39#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
     40#define xpPC(x) (*((pc*)(&(XP_PTREGS(x)->nip))))
     41#define set_xpPC(x,new) (xpPC(x) = (pc)(new))
     42#define xpLR(x) (*((pc*)(&(XP_PTREGS(x)->link))))
     43#define xpCTR(x) (*(pc*)(&(XP_PTREGS(x)->ctr)))
     44#define xpXER(x) (XP_PTREGS(x)->xer)
     45#define xpCCR(x) (XP_PTREGS(x)->ccr)
     46#define xpMSR(x) (XP_PTREGS(x)->msr)
     47#define xpDSISR(x) (XP_PTREGS(x)->dsisr)
     48#define xpDAR(x) (XP_PTREGS(x)->dar)
     49#define xpTRAP(x) (XP_PTREGS(x)->trap)
     50#define xpFPSCR(x) (XP_PTREGS(x)->gpr[PT_FPSCR])
     51#define xpFPRvector(x) ((double *)(&(XP_PTREGS(x)->gpr[PT_FPR0])))
     52#define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
     53
     54/*
     55   Work around a Darwin G5 bug (present in OSX 10.2.7, 10.2.8, and later
     56   versions.  See platform-darwinppc*.h for details
     57*/
     58#define DarwinSigReturn(context)
     59#define SIGRETURN(context)
  • trunk/source/lisp-kernel/ppc-exceptions.h

    r13207 r13637  
    2525OSStatus
    2626handle_uuo(ExceptionInformation *, opcode, pc);
    27 
    28 
    29 
    30 #ifdef LINUX
    31 /*
    32   Different (recent) versions of glibc disagree about how
    33   a ucontext is laid out (and about what an mcontext is.)
    34   There's something like a pointer to a pt_regs structure
    35   in the 12th word in both cases.  (Yes, this is an extremely
    36   ugly hack; it would be better to conditionalize on the values
    37   of GLIBC_VERSION/GLIBC_MINOR , but the discrepancy exists
    38   in various flavors of glibc 2.3.)
    39 */
    40 #ifdef PPC64
    41 #define XP_PTREGS(x) ((x)->uc_mcontext.regs)
    42 #define xpGPRvector(x) ((natural *)(XP_PTREGS(x)))
    43 #else
    44 #define XP_PTREGS(x) (((struct pt_regs **)(x))[12])
    45 #define xpGPRvector(x) (XP_PTREGS(x)->gpr)
    46 #endif
    47 #define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
    48 #define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
    49 #define xpPC(x) (*((pc*)(&(XP_PTREGS(x)->nip))))
    50 #define set_xpPC(x,new) (xpPC(x) = (pc)(new))
    51 #define xpLR(x) (*((pc*)(&(XP_PTREGS(x)->link))))
    52 #define xpCTR(x) (*(pc*)(&(XP_PTREGS(x)->ctr)))
    53 #define xpXER(x) (XP_PTREGS(x)->xer)
    54 #define xpCCR(x) (XP_PTREGS(x)->ccr)
    55 #define xpMSR(x) (XP_PTREGS(x)->msr)
    56 #define xpDSISR(x) (XP_PTREGS(x)->dsisr)
    57 #define xpDAR(x) (XP_PTREGS(x)->dar)
    58 #define xpTRAP(x) (XP_PTREGS(x)->trap)
    59 #define xpFPSCR(x) (XP_PTREGS(x)->gpr[PT_FPSCR])
    60 #define xpFPRvector(x) ((double *)(&(XP_PTREGS(x)->gpr[PT_FPR0])))
    61 #define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
    62 
    63 /*
    64    Work around a Darwin G5 bug (present in OSX 10.2.7, 10.2.8, and later
    65    versions.  See below for details.
    66 */
    67 #define DarwinSigReturn(context)
    68 #define SIGRETURN(context)
    69 #endif
    70 
    71 #ifdef DARWIN
    72 #define xpGPRvector(x) (&(UC_MCONTEXT(x)->__ss.__r0))
    73 #define xpGPR(x,gprno) ((xpGPRvector(x))[gprno])
    74 #define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (UInt32)(new)
    75 #define xpPC(x) (*((pc*) &(UC_MCONTEXT(x)->__ss.__srr0)))
    76 #define set_xpPC(x,new) (xpPC(x) = (pc)(new))
    77 #define xpLR(x) (*((pc*)(&(UC_MCONTEXT(x)->__ss.__lr))))
    78 #define xpCTR(x) (*(pc*)(&(UC_MCONTEXT(x)->__ss.__ctr)))
    79 #define xpXER(x) (UC_MCONTEXT(x)->__ss.__xer)
    80 #define xpCCR(x) (UC_MCONTEXT(x)->__ss.__cr)
    81 #define xpMSR(x) (UC_MCONTEXT(x)->__ss.__srr1)
    82 #define xpDSISR(x) (UC_MCONTEXT(x)->__es.__dsisr)
    83 #define xpDAR(x) (UC_MCONTEXT(x)->__es.__dar)
    84 #define xpTRAP(x) (UC_MCONTEXT(x)->__es.__exception)
    85 #define xpFPSCR(x) (UC_MCONTEXT(x)->__fs.__fpscr)
    86 #define xpFPRvector(x) (UC_MCONTEXT(x)->__fs.__fpregs)
    87 #define xpFPR(x,fprno) (xpFPRvector(x)[fprno])
    88 /* There's a bug in some versions of Darwin on G5 processors: FP context
    89    isn't restored correctly on exit from a signal handler if the integer
    90    context appears to be unmodified (the 64-bit context isn't set up
    91    correctly by the kernel: only the first N bytes are copied out of
    92    the kernel, where N = size of 32-bit context.
    93 
    94    If the kernel pushed both a 32-bit and 64-bit context, the C
    95    runtime "signal trampoline" code tries to determine if the 32-bit
    96    GPRs and user-visible SPRs in the 32-bit context contain the same
    97    values as their 64-bit counterparts on exit; if so, it tries to
    98    call sigreturn with an extra argument that indicates that the
    99    thread's state should be restored from the 64-bit context.
    100    (Apparently that's more efficient; it'd be surprising if it'd be
    101    more efficent when the cost of comparing values in the two contexts
    102    is factored in ...).  On some OS releases, the 64-bit context can't
    103    be reliably restored (FPRs get trashed.)
    104 
    105    One way to work around this is to use a deprecated, 32-bit-context-only
    106    version of the sigreturn syscall.  There seems to be reason to be
    107    reason to believe that the old sigreturn syscall will disappear
    108    on OS releases >10.3.
    109 
    110    Another way to work around this is to make a "harmless" change to
    111    an SPR or GPR value in the 32-bit context.  There are lots of
    112    "reserved" bits in the XER that make good candidates: 1's written
    113    to reserved XER bits can't be reliably read anyway, so this may
    114    or may not actually change the value in the XER in a way that
    115    can be reliably detected.
    116 
    117    Note that both the old, deprecated version of sigreturn and the
    118    new version take a first argument of type "struct ucontext *",
    119    not "struct sigcontext *" as the man page and header files claim.
    120    The new version takes a second argument, which is a small integer
    121    which defines what "flavor" of context should be restored from.
    122    The meaningful values that can be used here aren't defined in
    123    a header file; the kernel (and the libc _sigtramp() function)
    124    have (hopefully) matching, redundant hardwired definitions in
    125    the source.
    126 */
    127 #ifdef PPC64
    128 #define DarwinSigReturn(x)
    129 #else
    130 #define DarwinSigReturn(x) (UC_MCONTEXT(x)->__ss.__xer)^=0x80
    131 #endif
    132 #define SIGRETURN(context) DarwinSigReturn(context)
    133 #endif
    134 
    135 
    136 
    13727
    13828
Note: See TracChangeset for help on using the changeset viewer.