1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-23 10:48:26 +00:00
Interlisp.maiko/inc/adr68k.h
Nick Briggs d4226c20f2 Replace Addr68k related macros with NativeAligned inline functions
Addr68k_from_LADDR always produced a 2-byte aligned pointer which
  was frequently cast to a type requiring 4-byte alignment.
  This commit changes Addr68k_from_LADDR uses to one of two new
  inline procedures, NativeAligned2FromLAddr or NativeAligned4FromLAddr,
  which produce a result with the appropriate alignment for the context.
  This permits checking for cases where the Lisp address is not
  appropriately aligned for the usage context, and localizes compiler
  warnings to these two procedures.

  Similarly, the Addr68k_from_StkOffset macros are replaced by
  NativeAligned2FromStackOffset and NativeAligned4FromStackOffset.

  NativeAligned4FromLPage replaces Addr68k_from_LPAGE as page address
  will always be at least 4-byte aligned.

  LAddrFromNative, LPageFromNative, and StackOffsetFromNative complete
  the set, replacing LADDR_from_68k, LPAGE_from_68k, and
  StkOffset_from_68K (note K not k) respectively.
2022-09-01 14:11:54 -07:00

112 lines
3.0 KiB
C

#ifndef ADR68K_H
#define ADR68K_H 1
/* $Id: adr68k.h,v 1.2 1999/01/03 02:05:52 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */
/*
* Copyright (C) 1987 by Fuji Xerox Co., Ltd. All rights reserved.
*
* Author : Takeshi Shimizu
* Hiroshi Hayata
*/
/************************************************************************/
/* */
/* Copyright 1989, 1990 Venue, Fuji Xerox Co., Ltd, Xerox Corp. */
/* */
/* This file is work-product resulting from the Xerox/Venue */
/* Agreement dated 18-August-1989 for support of Medley. */
/* */
/************************************************************************/
/**********************************************************************/
/*
Func name : adr68k.h
Translate 68k address to Lisp or Lisp to 68k
Date : January 16, 1987
Create : Takeshi Shimizu
*/
/**********************************************************************/
#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;
}
/* 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))
#endif /* ADR68K_H */