Skip to content

Commit

Permalink
Merge pull request #443 from Interlisp/cast-align
Browse files Browse the repository at this point in the history
Replace Addr68k and stack offset related macros with NativeAligned inline functions
  • Loading branch information
nbriggs authored Sep 29, 2022
2 parents 5202c71 + c2070d9 commit f5b17b0
Show file tree
Hide file tree
Showing 89 changed files with 1,022 additions and 1,005 deletions.
90 changes: 58 additions & 32 deletions inc/adr68k.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* Hiroshi Hayata
*/



/************************************************************************/
/* */
/* Copyright 1989, 1990 Venue, Fuji Xerox Co., Ltd, Xerox Corp. */
Expand All @@ -20,8 +18,6 @@
/* */
/************************************************************************/



/**********************************************************************/
/*
Func name : adr68k.h
Expand All @@ -32,32 +28,62 @@
*/
/**********************************************************************/



/* translate 68k ptr to Lisp DLword address */
#define LADDR_from_68k(ptr68k) ((LispPTR)(((UNSIGNED)(ptr68k) - (UNSIGNED)Lisp_world) >>1))


/* translate 68k ptr to Lisp Page number */
#define LPAGE_from_68k(ptr68k) (LADDR_from_68k(ptr68k) >> 8)


/* Translate Lisp_address to 68K address */
/* Lisp_addr: word offset */
#define Addr68k_from_LADDR(Lisp_addr) (Lisp_world + (Lisp_addr))


/* translate LispPage to 68k address */
#define Addr68k_from_LPAGE(Lisp_page) (Addr68k_from_LADDR(((Lisp_page) << 8) ))




/* Stack Offset Macros */

#define StkOffset_from_68K(ptr68k)\
((LispPTR)(((UNSIGNED)(ptr68k) - (UNSIGNED)Stackspace) >>1))

#define Addr68k_from_StkOffset(stkoffset)\
(Stackspace + (stkoffset))
#include <stddef.h>
#include <stdio.h>
#include "lispemul.h"
#include "lspglob.h"

static inline LispPTR LAddrFromNative(void *NAddr)
{
if ((uintptr_t)NAddr & 1) {
printf("Misaligned pointer in LAddrFromNative %p\n", NAddr);
}
return ((DLword *)NAddr) - Lisp_world;
}

static inline DLword *NativeAligned2FromLAddr(LispPTR LAddr)
{
return (Lisp_world + LAddr);
}

static inline LispPTR *NativeAligned4FromLAddr(LispPTR LAddr)
{
if (LAddr & 1) {
printf("Misaligned pointer in NativeAligned4FromLAddr 0x%x\n", LAddr);
}
return (LispPTR *)(Lisp_world + LAddr);
}

static inline LispPTR *NativeAligned4FromLPage(LispPTR LPage)
{
return (LispPTR *)(Lisp_world + (LPage << 8));
}

static inline DLword StackOffsetFromNative(void *SAddr)
{
/* Stack offsets are expressed as an offset in DLwords from the stack base */
ptrdiff_t hoffset = (DLword *)SAddr - Stackspace;
if (hoffset > 0xffff) {
printf("Stack offset is too large: 0x%tx\n", hoffset);
}
return (DLword)hoffset;
}

static inline DLword *NativeAligned2FromStackOffset(DLword StackOffset)
{
return Stackspace + StackOffset;
}

static inline LispPTR *NativeAligned4FromStackOffset(DLword StackOffset)
{
return (LispPTR *)(Stackspace + StackOffset);
}

static inline LispPTR LPageFromNative(void *NAddr)
{
if ((uintptr_t)NAddr & 1) {
printf("Misaligned pointer in LPageFromNative %p\n", NAddr);
}
return (((DLword *)NAddr) - Lisp_world) >> 8;
}
#endif /* ADR68K_H */
10 changes: 5 additions & 5 deletions inc/arith.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* */
/************************************************************************/

#include "adr68k.h" // for Addr68k_from_LADDR, LADDR_from_68k
#include "adr68k.h" // for NativeAligned4FromLAddr, LAddrFromNative
#include "commondefs.h" // for error
#include "lispemul.h" // for SEGMASK, ERROR_EXIT
#include "lispmap.h" // for S_NEGATIVE, S_POSITIVE
Expand Down Expand Up @@ -55,9 +55,9 @@ static inline LispPTR GetPosSmallp(unsigned long x) {
return (S_POSITIVE | 0);
}

#define FIXP_VALUE(dest) *((int *)Addr68k_from_LADDR(dest))
#define FIXP_VALUE(dest) *((int *)NativeAligned4FromLAddr(dest))

#define FLOATP_VALUE(dest) *((float *)Addr68k_from_LADDR(dest))
#define FLOATP_VALUE(dest) *((float *)NativeAligned4FromLAddr(dest))

#define N_GETNUMBER(sour, dest, label) \
do { \
Expand Down Expand Up @@ -102,7 +102,7 @@ static inline LispPTR GetPosSmallp(unsigned long x) {
/* arg is FIXP, call createcell */ \
fixpp = (int *)createcell68k(TYPE_FIXP); \
*((int *)fixpp) = (int)(arg); \
(result) = (LADDR_from_68k(fixpp)); \
(result) = (LAddrFromNative(fixpp)); \
break; \
} \
} \
Expand All @@ -118,7 +118,7 @@ static inline LispPTR GetPosSmallp(unsigned long x) {
/* arg is FIXP, call createcell */ \
fixpp = (int *)createcell68k(TYPE_FIXP); \
*fixpp = arg; \
return (LADDR_from_68k(fixpp)); \
return (LAddrFromNative(fixpp)); \
} \
} \
} while (0)
Expand Down
28 changes: 14 additions & 14 deletions inc/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
/**********************************************************************/
#include "adr68k.h" /* for NativeAligned4FromLPage, NativeAligned4FromLAddr */
#include "lispemul.h" /* for LispPTR, DLword */

/* CONS CELL (LISTP) definitions moved to lispemulater.h */
Expand Down Expand Up @@ -101,13 +102,13 @@ struct conspage {
/* Following MACROs for Conspage */

/* lisp_ptr is LISP pointer, returns 68k ptr points struct conspage obj */
#define Get_ConsPageBase(lisp_ptr) (struct conspage *)Addr68k_from_LPAGE(POINTER_PAGEBASE(lisp_ptr))
#define Get_ConsPageBase(lisp_ptr) (struct conspage *)NativeAligned4FromLPage(POINTER_PAGEBASE(lisp_ptr))

#define GetNewCell_68k(conspage68k) \
(ConsCell *)(((DLword *)(conspage68k)) + (unsigned)((conspage68k)->next_cell))

/* page : LISP page */
#define GetCONSCount(page) (((struct conspage *)Addr68k_from_LPAGE(page))->count)
#define GetCONSCount(page) (((struct conspage *)NativeAligned4FromLPage(page))->count)

#ifndef BYTESWAP
/* For chaining together free cons cells on a page */
Expand Down Expand Up @@ -377,20 +378,16 @@ struct cadr_cell {
#else
/* Good for old LITATOMS and new NEW-ATOMs */
#define GetDEFCELL68k(index) \
((((index) & SEGMASK) != 0) ? (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_DEFN_OFFSET) \
: GetDEFCELLlitatom(index))
((((index) & SEGMASK) != 0) ? GetDEFCELLnew(index) : GetDEFCELLlitatom(index))

#define GetVALCELL68k(index) \
((((index) & SEGMASK) != 0) ? (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_VALUE_OFFSET) \
: GetVALCELLlitatom(index))
((((index) & SEGMASK) != 0) ? GetVALCELLnew(index) : GetVALCELLlitatom(index))

#define GetPnameCell(index) \
((((index) & SEGMASK) != 0) ? (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_PNAME_OFFSET) \
: GetPnameCelllitatom(index))
((((index) & SEGMASK) != 0) ? GetPnameCellnew(index) : GetPnameCelllitatom(index))

#define GetPropCell(index) \
((((index) & SEGMASK) != 0) ? (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_PLIST_OFFSET) \
: GetPropCelllitatom(index))
((((index) & SEGMASK) != 0) ? GetPropCellnew(index) : GetPropCelllitatom(index))

/* Good only for old-style LITATOMS */
#ifdef BIGVM
Expand All @@ -406,10 +403,13 @@ struct cadr_cell {
#endif

/* Good only for new-style NEW-ATOMs */
#define GetDEFCELLnew(index) (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_DEFN_OFFSET)
#define GetVALCELLnew(index) (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_VALUE_OFFSET)
#define GetPnameCellnew(index) (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_PNAME_OFFSET)
#define GetPropCellnew(index) (LispPTR *)(Addr68k_from_LADDR(index) + NEWATOM_PLIST_OFFSET)
/* Note: the _OFFSET values are in units of DLword so need to be adjusted before doing pointer
* arithmetic since we now have native pointers to cells not DLwords
*/
#define GetDEFCELLnew(index) (NativeAligned4FromLAddr(index) + (NEWATOM_DEFN_OFFSET / DLWORDSPER_CELL))
#define GetVALCELLnew(index) (NativeAligned4FromLAddr(index) + (NEWATOM_VALUE_OFFSET / DLWORDSPER_CELL))
#define GetPnameCellnew(index) (NativeAligned4FromLAddr(index) + (NEWATOM_PNAME_OFFSET / DLWORDSPER_CELL))
#define GetPropCellnew(index) (NativeAligned4FromLAddr(index) + (NEWATOM_PLIST_OFFSET / DLWORDSPER_CELL))

#endif /* BIGATOMS */

Expand Down
Loading

0 comments on commit f5b17b0

Please sign in to comment.