mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-14 23:46:14 +00:00
Introduce functions to convert between lisp addresses and native pointers
Instead of using a single macro that converts from a lisp pointer to a native pointer to a 2-byte aligned item then perhaps casting to objects that require 4-byte alignment... use separate functions for 2-byte and 4-byte aligned pointer results. The clients should be explicit about which alignment they require, and the conversion functions can check (perhaps in DEBUG mode) that the resulting pointer is on an appropriate boundary. This commit defines the functions but does not introduce any uses.
This commit is contained in:
parent
5202c71a95
commit
215a22ea9f
52
inc/adr68k.h
52
inc/adr68k.h
@ -9,8 +9,6 @@
|
||||
* Hiroshi Hayata
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* Copyright 1989, 1990 Venue, Fuji Xerox Co., Ltd, Xerox Corp. */
|
||||
@ -20,8 +18,6 @@
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
Func name : adr68k.h
|
||||
@ -32,7 +28,51 @@
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
#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(DLword *SAddr)
|
||||
{
|
||||
/* Stack offsets are expressed as an offset in DLwords from the stack base */
|
||||
ptrdiff_t hoffset = 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;
|
||||
}
|
||||
|
||||
/* translate 68k ptr to Lisp DLword address */
|
||||
#define LADDR_from_68k(ptr68k) ((LispPTR)(((UNSIGNED)(ptr68k) - (UNSIGNED)Lisp_world) >>1))
|
||||
@ -49,10 +89,6 @@
|
||||
|
||||
/* 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)\
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user