Skip to content
Snippets Groups Projects
Commit 3e4590e7 authored by cshapiro's avatar cshapiro
Browse files

Make SC_REG expand out to an lvalue on the x86 and AMD64. Define a

reg_NARGS macro on these targets and use SC_REG to replace open-coded
assignments to platform specific sigcontext members in interrupt.c and
os-common.c.  This code could be simplified further by merging the x86
and AMD64 cases into the general case.
parent 3a2ba9da
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Much hacked by Paul Werkowski * Much hacked by Paul Werkowski
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.12 2006/05/30 22:42:05 fgilham Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.13 2006/11/07 11:24:12 cshapiro Exp $
* *
*/ */
...@@ -52,29 +52,29 @@ os_init(void) ...@@ -52,29 +52,29 @@ os_init(void)
os_vm_page_size = getpagesize(); os_vm_page_size = getpagesize();
} }
int int *
sc_reg(struct sigcontext *c, int offset) sc_reg(struct sigcontext *c, int offset)
{ {
switch (offset) { switch (offset) {
case 0: case 0:
return c->sc_eax; return &c->sc_eax;
case 2: case 2:
return c->sc_ecx; return &c->sc_ecx;
case 4: case 4:
return c->sc_edx; return &c->sc_edx;
case 6: case 6:
return c->sc_ebx; return &c->sc_ebx;
case 8: case 8:
return c->sc_esp; return &c->sc_esp;
case 10: case 10:
return c->sc_ebp; return &c->sc_ebp;
case 12: case 12:
return c->sc_esi; return &c->sc_esi;
case 14: case 14:
return c->sc_edi; return &c->sc_edi;
} }
return 0; return (int *) 0;
} }
void void
......
/* /*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.h,v 1.9 2006/05/30 22:42:14 fgilham Exp $ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.h,v 1.10 2006/11/07 11:24:12 cshapiro Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -35,7 +35,7 @@ typedef int os_vm_prot_t; ...@@ -35,7 +35,7 @@ typedef int os_vm_prot_t;
#define OS_VM_DEFAULT_PAGESIZE 4096 #define OS_VM_DEFAULT_PAGESIZE 4096
int sc_reg(struct sigcontext *, int); int *sc_reg(struct sigcontext *, int);
void os_save_context(void); void os_save_context(void);
/* I *think* this is when things became incompatible with old /* I *think* this is when things became incompatible with old
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* Alpha support by Julian Dolby, 1999. * Alpha support by Julian Dolby, 1999.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.26 2006/03/17 02:56:45 rtoy Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.27 2006/11/07 11:24:12 cshapiro Exp $
* *
*/ */
...@@ -100,75 +100,74 @@ os_init(void) ...@@ -100,75 +100,74 @@ os_init(void)
} }
#ifdef i386 #ifdef i386
int *
#if (LINUX_VERSION_CODE >= linuxversion(2,1,0)) || (__GNU_LIBRARY__ >= 6) #if (LINUX_VERSION_CODE >= linuxversion(2,1,0)) || (__GNU_LIBRARY__ >= 6)
int
sc_reg(struct sigcontext *c, int offset) sc_reg(struct sigcontext *c, int offset)
#else #else
int
sc_reg(struct sigcontext_struct *c, int offset) sc_reg(struct sigcontext_struct *c, int offset)
#endif #endif
{ {
switch (offset) { switch (offset) {
case 0: case 0:
return c->eax; return &c->eax;
case 2: case 2:
return c->ecx; return &c->ecx;
case 4: case 4:
return c->edx; return &c->edx;
case 6: case 6:
return c->ebx; return &c->ebx;
case 8: case 8:
return c->esp; return &c->esp;
case 10: case 10:
return c->ebp; return &c->ebp;
case 12: case 12:
return c->esi; return &c->esi;
case 14: case 14:
return c->edi; return &c->edi;
} }
return 0; return (int *) 0;
} }
#endif #endif
#ifdef __x86_64 #ifdef __x86_64
int int *
sc_reg(struct sigcontext *c, int offset) sc_reg(struct sigcontext *c, int offset)
{ {
switch (offset) { switch (offset) {
case 0: case 0:
return c->rax; return &c->rax;
case 2: case 2:
return c->rcx; return &c->rcx;
case 4: case 4:
return c->rdx; return &c->rdx;
case 6: case 6:
return c->rbx; return &c->rbx;
case 8: case 8:
return c->rsp; return &c->rsp;
case 10: case 10:
return c->rbp; return &c->rbp;
case 12: case 12:
return c->rsi; return &c->rsi;
case 14: case 14:
return c->rdi; return &c->rdi;
case 16: case 16:
return c->r8; return &c->r8;
case 18: case 18:
return c->r9; return &c->r9;
case 20: case 20:
return c->r10; return &c->r10;
case 22: case 22:
return c->r11; return &c->r11;
case 24: case 24:
return c->r12; return &c->r12;
case 26: case 26:
return c->r13; return &c->r13;
case 28: case 28:
return c->r14; return &c->r14;
case 30: case 30:
return c->r15; return &c->r15;
} }
return 0; return (int *) 0;
} }
#endif #endif
......
/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.h,v 1.18 2005/10/05 17:23:56 rtoy Exp $ /* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.h,v 1.19 2006/11/07 11:24:12 cshapiro Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -45,9 +45,9 @@ typedef int os_vm_prot_t; /* like hpux */ ...@@ -45,9 +45,9 @@ typedef int os_vm_prot_t; /* like hpux */
#endif #endif
#if (LINUX_VERSION_CODE >= linuxversion(2,1,0)) || (__GNU_LIBRARY__ >= 6) #if (LINUX_VERSION_CODE >= linuxversion(2,1,0)) || (__GNU_LIBRARY__ >= 6)
int sc_reg(struct sigcontext *, int); int *sc_reg(struct sigcontext *, int);
#else #else
int sc_reg(struct sigcontext_struct *, int); int *sc_reg(struct sigcontext_struct *, int);
#endif #endif
void os_save_context(void); void os_save_context(void);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Frobbed for OpenBSD by Pierre R. Mai, 2001. * Frobbed for OpenBSD by Pierre R. Mai, 2001.
* Frobbed for NetBSD by Pierre R. Mai, 2002. * Frobbed for NetBSD by Pierre R. Mai, 2002.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.3 2005/09/15 18:26:50 rtoy Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.4 2006/11/07 11:24:12 cshapiro Exp $
* *
*/ */
...@@ -53,51 +53,51 @@ os_init(void) ...@@ -53,51 +53,51 @@ os_init(void)
os_vm_page_size = OS_VM_DEFAULT_PAGESIZE; os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
} }
int int *
sc_reg(os_context_t * c, int offset) sc_reg(os_context_t * c, int offset)
{ {
#ifdef i386 #ifdef i386
#if USE_SA_SIGINFO #if USE_SA_SIGINFO
switch (offset) { switch (offset) {
case 0: case 0:
return c->uc_mcontext.__gregs[_REG_EAX]; return &c->uc_mcontext.__gregs[_REG_EAX];
case 2: case 2:
return c->uc_mcontext.__gregs[_REG_ECX]; return &c->uc_mcontext.__gregs[_REG_ECX];
case 4: case 4:
return c->uc_mcontext.__gregs[_REG_EDX]; return &c->uc_mcontext.__gregs[_REG_EDX];
case 6: case 6:
return c->uc_mcontext.__gregs[_REG_EBX]; return &c->uc_mcontext.__gregs[_REG_EBX];
case 8: case 8:
return c->uc_mcontext.__gregs[_REG_ESP]; return &c->uc_mcontext.__gregs[_REG_ESP];
case 10: case 10:
return c->uc_mcontext.__gregs[_REG_EBP]; return &c->uc_mcontext.__gregs[_REG_EBP];
case 12: case 12:
return c->uc_mcontext.__gregs[_REG_ESI]; return &c->uc_mcontext.__gregs[_REG_ESI];
case 14: case 14:
return c->uc_mcontext.__gregs[_REG_EDI]; return &c->uc_mcontext.__gregs[_REG_EDI];
} }
#else #else
switch (offset) { switch (offset) {
case 0: case 0:
return c->sc_eax; return &c->sc_eax;
case 2: case 2:
return c->sc_ecx; return &c->sc_ecx;
case 4: case 4:
return c->sc_edx; return &c->sc_edx;
case 6: case 6:
return c->sc_ebx; return &c->sc_ebx;
case 8: case 8:
return c->sc_esp; return &c->sc_esp;
case 10: case 10:
return c->sc_ebp; return &c->sc_ebp;
case 12: case 12:
return c->sc_esi; return &c->sc_esi;
case 14: case 14:
return c->sc_edi; return &c->sc_edi;
} }
#endif #endif
#endif #endif
return 0; return (int *) 0;
} }
void void
......
/* /*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.h,v 1.4 2005/09/15 18:26:50 rtoy Exp $ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.h,v 1.5 2006/11/07 11:24:12 cshapiro Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -34,7 +34,7 @@ typedef int os_vm_prot_t; ...@@ -34,7 +34,7 @@ typedef int os_vm_prot_t;
#define CODE(code) ((code) ? code->si_code : 0) #define CODE(code) ((code) ? code->si_code : 0)
#define os_context_t ucontext_t #define os_context_t ucontext_t
int sc_reg(ucontext_t *, int); int *sc_reg(ucontext_t *, int);
#define PROTECTION_VIOLATION_SIGNAL SIGSEGV #define PROTECTION_VIOLATION_SIGNAL SIGSEGV
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* Frobbed for OpenBSD by Pierre R. Mai, 2001. * Frobbed for OpenBSD by Pierre R. Mai, 2001.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.c,v 1.2 2005/09/15 18:26:50 rtoy Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.c,v 1.3 2006/11/07 11:24:12 cshapiro Exp $
* *
*/ */
...@@ -49,28 +49,28 @@ os_init(void) ...@@ -49,28 +49,28 @@ os_init(void)
os_vm_page_size = OS_VM_DEFAULT_PAGESIZE; os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
} }
int int *
sc_reg(struct sigcontext *c, int offset) sc_reg(struct sigcontext *c, int offset)
{ {
switch (offset) { switch (offset) {
case 0: case 0:
return c->sc_eax; return &c->sc_eax;
case 2: case 2:
return c->sc_ecx; return &c->sc_ecx;
case 4: case 4:
return c->sc_edx; return &c->sc_edx;
case 6: case 6:
return c->sc_ebx; return &c->sc_ebx;
case 8: case 8:
return c->sc_esp; return &c->sc_esp;
case 10: case 10:
return c->sc_ebp; return &c->sc_ebp;
case 12: case 12:
return c->sc_esi; return &c->sc_esi;
case 14: case 14:
return c->sc_edi; return &c->sc_edi;
} }
return 0; return (int *) 0;
} }
void void
......
/* /*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.h,v 1.3 2005/09/15 18:26:50 rtoy Exp $ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.h,v 1.4 2006/11/07 11:24:12 cshapiro Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -34,6 +34,6 @@ typedef int os_vm_prot_t; ...@@ -34,6 +34,6 @@ typedef int os_vm_prot_t;
#define CODE(code) ((code) ? code->si_code : 0) #define CODE(code) ((code) ? code->si_code : 0)
#define uc_sigmask sc_mask #define uc_sigmask sc_mask
int sc_reg(struct sigcontext *, int); int *sc_reg(struct sigcontext *, int);
#endif /* _OPENBSD_OS_H_ */ #endif /* _OPENBSD_OS_H_ */
/* x86-lispregs.h -*- Mode: C; -*- /* x86-lispregs.h -*- Mode: C; -*-
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/amd64-lispregs.h,v 1.3 2005/01/13 19:55:00 fgilham Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/amd64-lispregs.h,v 1.4 2006/11/07 11:24:12 cshapiro Rel $
*/ */
/* These register names and offsets correspond to definitions /* These register names and offsets correspond to definitions
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define reg_SP reg_RSP #define reg_SP reg_RSP
#define reg_FP reg_RBP #define reg_FP reg_RBP
#define reg_NARGS reg_RCX
#define REGNAMES "RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15" #define REGNAMES "RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15"
...@@ -51,7 +52,7 @@ ...@@ -51,7 +52,7 @@
* xxx-os.c handle it. * xxx-os.c handle it.
*/ */
#define SC_REG(sc, n) sc_reg(sc,n) #define SC_REG(sc, n) (*sc_reg(sc,n))
#define SC_PC(sc) ((sc)->sc_pc) #define SC_PC(sc) ((sc)->sc_pc)
#endif /* _AMD64_LISPREGS_H_ */ #endif /* _AMD64_LISPREGS_H_ */
/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/interrupt.c,v 1.43 2005/09/15 18:26:51 rtoy Exp $ */ /* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/interrupt.c,v 1.44 2006/11/07 11:24:12 cshapiro Exp $ */
/* Interrupt handling magic. */ /* Interrupt handling magic. */
...@@ -680,23 +680,10 @@ install_handler(int signal, void handler(HANDLER_ARGS)) ...@@ -680,23 +680,10 @@ install_handler(int signal, void handler(HANDLER_ARGS))
void void
interrupt_handle_space_overflow(lispobj error, os_context_t * context) interrupt_handle_space_overflow(lispobj error, os_context_t * context)
{ {
#ifdef i386 #if defined(i386) || defined(__x86_64)
/* ECX is the argument count. */
#if USE_SA_SIGINFO
context->uc_mcontext.__gregs[_REG_EIP] ==
(int) ((struct function *) PTR(error))->code;
context->uc_mcontext.__gregs[_REG_ECX] == 0;
#else
SC_PC(context) = (int) ((struct function *) PTR(error))->code; SC_PC(context) = (int) ((struct function *) PTR(error))->code;
context->sc_ecx = 0; SC_REG(context, reg_NARGS) = 0;
#endif #elif defined(sparc)
#else
#ifdef __x86_64
/* RCX is the argument count. */
context->sc_rip = (unsigned long) ((struct function *) PTR(error))->code;
context->sc_rcx = 0;
#else
#ifdef sparc
build_fake_control_stack_frame(context); build_fake_control_stack_frame(context);
/* This part should be common to all non-x86 ports */ /* This part should be common to all non-x86 ports */
SC_PC(context) = (long) ((struct function *) PTR(error))->code; SC_PC(context) = (long) ((struct function *) PTR(error))->code;
...@@ -709,8 +696,6 @@ interrupt_handle_space_overflow(lispobj error, os_context_t * context) ...@@ -709,8 +696,6 @@ interrupt_handle_space_overflow(lispobj error, os_context_t * context)
#else #else
#error interrupt_handle_space_overflow not implemented for this system #error interrupt_handle_space_overflow not implemented for this system
#endif #endif
#endif
#endif
} }
#endif /* FEATURE_HEAP_OVERFLOW_CHECK */ #endif /* FEATURE_HEAP_OVERFLOW_CHECK */
......
/* /*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os-common.c,v 1.20 2005/09/15 18:26:52 rtoy Exp $ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os-common.c,v 1.21 2006/11/07 11:24:12 cshapiro Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -449,22 +449,10 @@ os_control_stack_overflow(void *fault_addr, os_context_t * context) ...@@ -449,22 +449,10 @@ os_control_stack_overflow(void *fault_addr, os_context_t * context)
else else
error = SymbolFunction(YELLOW_ZONE_HIT); error = SymbolFunction(YELLOW_ZONE_HIT);
#ifdef i386 #if defined(i386) || defined(__x86_64)
/* ECX is the argument count. */
SC_PC(context) = (int) ((struct function *) PTR(error))->code; SC_PC(context) = (int) ((struct function *) PTR(error))->code;
#if USE_SA_SIGINFO SC_REG(context, reg_NARGS) = 0;
context->uc_mcontext.__gregs[_REG_ECX] == 0; #elif defined(sparc)
#else
context->sc_ecx = 0;
#endif
#else
#ifdef __x86_64
/* RCX is the argument count. */
context->sc_rip =
(unsigned long) ((struct function *) PTR(error))->code;
context->sc_rcx = 0;
#else
#ifdef sparc
/* This part should be common to all non-x86 ports */ /* This part should be common to all non-x86 ports */
SC_PC(context) = (long) ((struct function *) PTR(error))->code; SC_PC(context) = (long) ((struct function *) PTR(error))->code;
SC_NPC(context) = SC_PC(context) + 4; SC_NPC(context) = SC_PC(context) + 4;
...@@ -476,8 +464,6 @@ os_control_stack_overflow(void *fault_addr, os_context_t * context) ...@@ -476,8 +464,6 @@ os_control_stack_overflow(void *fault_addr, os_context_t * context)
SC_REG(context, reg_CODE) = ((long) PTR(error)) + type_FunctionPointer; SC_REG(context, reg_CODE) = ((long) PTR(error)) + type_FunctionPointer;
#else #else
#error os_control_stack_overflow not implemented for this system #error os_control_stack_overflow not implemented for this system
#endif
#endif
#endif #endif
return 1; return 1;
} }
......
/* x86-lispregs.h -*- Mode: C; -*- /* x86-lispregs.h -*- Mode: C; -*-
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-lispregs.h,v 1.4 2005/01/13 19:55:01 fgilham Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-lispregs.h,v 1.5 2006/11/07 11:24:12 cshapiro Exp $
*/ */
#ifndef _X86_LISPREGS_H_ #ifndef _X86_LISPREGS_H_
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#define reg_SP reg_ESP #define reg_SP reg_ESP
#define reg_FP reg_EBP #define reg_FP reg_EBP
#define reg_NARGS reg_ECX
#define REGNAMES "EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI" #define REGNAMES "EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI"
...@@ -43,7 +44,7 @@ ...@@ -43,7 +44,7 @@
* xxx-os.c handle it. * xxx-os.c handle it.
*/ */
#define SC_REG(sc, n) sc_reg(sc,n) #define SC_REG(sc, n) (*sc_reg(sc,n))
#ifdef __NetBSD__ #ifdef __NetBSD__
#define SC_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EIP]) #define SC_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EIP])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment