1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-13 15:18:14 +00:00

Use ...FromStackOffset functions where appropriate

Rather than adding/or-ing the STK_OFFSET constant into a stack offset
to convert it to a pointer in general Lisp memory and then converting
from that to a native address... use the functions specifically
present to do those conversions with embedded checks on stack offset
validity.
This commit is contained in:
Nick Briggs 2024-03-07 10:45:38 -08:00
parent 939c23c03b
commit 68baf6fb30
9 changed files with 21 additions and 21 deletions

View File

@ -37,7 +37,7 @@
#define FastRetCALL \
do { \
/* Get IVar from Returnee's IVAR offset slot(BF) */ \
IVar = NativeAligned2FromLAddr(STK_OFFSET | GETWORD((DLword *)CURRENTFX -1)); \
IVar = NativeAligned2FromStackOffset(GETWORD((DLword *)CURRENTFX - 1)); \
/* Get FuncObj from Returnee's FNHEAD slot in FX */ \
FuncObj = (struct fnhead *)NativeAligned4FromLAddr(FX_FNHEADER); \
/* Get PC from Returnee's pc slot in FX */ \
@ -47,7 +47,7 @@
#define FastRetCALL \
do { \
/* Get IVar from Returnee's IVAR offset slot(BF) */ \
IVar = NativeAligned2FromLAddr(STK_OFFSET | GETWORD((DLword *)CURRENTFX -1)); \
IVar = NativeAligned2FromStackOffset(GETWORD((DLword *)CURRENTFX - 1)); \
/* Get FuncObj from Returnee's FNHEAD slot in FX */ \
FuncObj = (struct fnhead *)NativeAligned4FromLAddr(FX_FNHEADER); \
/* Get PC from Returnee's pc slot in FX */ \

View File

@ -1664,7 +1664,7 @@ void ccfuncall(unsigned int atom_index, int argnum, int bytenum)
CURRENTFX->nextblock = (LAddrFromNative(CurrentStackPTR) & 0x0ffff) - (argnum << 1) + 4 /* +3 */;
/* Setup IVar */ /* XXX: is it really only 2-byte aligned? */
IVar = NativeAligned2FromLAddr((((LispPTR)(CURRENTFX->nextblock)) | STK_OFFSET));
IVar = NativeAligned2FromStackOffset(CURRENTFX->nextblock);
/* Set PC to the Next Instruction and save into FX */
CURRENTFX->pc = ((UNSIGNED)PC - (UNSIGNED)FuncObj) + bytenum;

View File

@ -303,14 +303,14 @@ int sf(struct frameex1 *fx_addr68k) {
if (((fx_addr68k)->alink & 1) == 0) { /* FAST */
bf = (Bframe *)(((DLword *)fx_addr68k) - 2);
} else { /* SLOW */
bf = (Bframe *)NativeAligned4FromLAddr(((fx_addr68k)->blink + STK_OFFSET));
bf = (Bframe *)NativeAligned4FromStackOffset((fx_addr68k)->blink);
}
/* Print IVARs */
printf("IVAR -------\n");
BT_morep;
ptr = NativeAligned2FromLAddr(STK_OFFSET + bf->ivar);
ptr = NativeAligned2FromStackOffset(bf->ivar);
i = 0;
while (ptr != (DLword *)bf) {
ptrlo = ptr + 1;
@ -475,7 +475,7 @@ int sf(struct frameex1 *fx_addr68k) {
i++;
}
if (fx_addr68k->alink == 11) /* for contextsw */
next68k = (DLword *)NativeAligned2FromLAddr((fx_addr68k->nextblock + STK_OFFSET));
next68k = NativeAligned2FromStackOffset(fx_addr68k->nextblock);
else
next68k = CurrentStackPTR;
@ -493,7 +493,7 @@ int sf(struct frameex1 *fx_addr68k) {
return (-1);
}
next68k = (DLword *)NativeAligned2FromLAddr((fx_addr68k->nextblock + STK_OFFSET));
next68k = NativeAligned2FromStackOffset(fx_addr68k->nextblock);
ptr = (DLword *)(fx_addr68k + 1);
i = 0;

View File

@ -45,7 +45,7 @@ LispPTR N_OP_findkey(LispPTR tos, int byte) {
#endif
if (CURRENTFX->alink & 1) { /* slow case */
find_end = (DLword *)NativeAligned2FromLAddr(STK_OFFSET | (CURRENTFX->blink - 4));
find_end = NativeAligned2FromStackOffset(CURRENTFX->blink - 4);
} else { /* Fast cae */
find_end = ((DLword *)CURRENTFX) - 2 - 4;
}

View File

@ -26,7 +26,7 @@
#include "gcarraydefs.h" // for get_package_atom
#include "gcdata.h" // for FRPLPTR
#include "lispemul.h" // for LispPTR, state, CurrentStackPTR, NIL_PTR, NIL
#include "lispmap.h" // for S_POSITIVE, STK_OFFSET
#include "lispmap.h" // for S_POSITIVE
#include "loopsopsdefs.h" // for lcfuncall, LCFetchMethod, LCFetchMethodOrHelp
#include "lspglob.h"
#include "lsptypes.h" // for GetDTD, GetTypeNumber, dtd, Listp, GETWORD
@ -358,7 +358,7 @@ LispPTR lcfuncall(unsigned int atom_index, int argnum, int bytenum)
CURRENTFX->nextblock = (LAddrFromNative(CurrentStackPTR) & 0x0ffff) - (argnum << 1) + 4 /* +3 */;
/* Setup IVar */
IVar = NativeAligned2FromLAddr((((LispPTR)(CURRENTFX->nextblock)) | STK_OFFSET));
IVar = NativeAligned2FromStackOffset(CURRENTFX->nextblock);
/* Set PC to the Next Instruction and save into FX */
CURRENTFX->pc = ((UNSIGNED)PC - (UNSIGNED)FuncObj) + bytenum;

View File

@ -727,9 +727,9 @@ void start_lisp(void) {
TopOfStack = 0;
Error_Exit = 0;
PVar = (DLword *)NativeAligned2FromLAddr(STK_OFFSET | InterfacePage->currentfxp) + FRAMESIZE;
PVar = NativeAligned2FromStackOffset(InterfacePage->currentfxp) + FRAMESIZE;
freeptr = next68k = NativeAligned2FromLAddr(STK_OFFSET | CURRENTFX->nextblock);
freeptr = next68k = NativeAligned2FromStackOffset(CURRENTFX->nextblock);
if (GETWORD(next68k) != STK_FSB_WORD) error("Starting Lisp: Next stack block isn't free!");

View File

@ -129,7 +129,7 @@ void contextsw(DLword fxnum, DLword bytenum, DLword flags)
Midpunt(fxnum); /* exchanging FX */
next68k = (DLword *)NativeAligned2FromLAddr(STK_OFFSET | CURRENTFX->nextblock);
next68k = NativeAligned2FromStackOffset(CURRENTFX->nextblock);
if (GETWORD(next68k) != STK_FSB_WORD) error("contextsw(): MP9316");
freeptr = next68k;

View File

@ -57,7 +57,7 @@
#include "gcarraydefs.h" // for aref1
#include "kprintdefs.h" // for print, prindatum
#include "lispemul.h" // for DLword, LispPTR, DLbyte, state, T, ConsCell
#include "lispmap.h" // for STK_OFFSET, ATOMS_HI
#include "lispmap.h" // for ATOMS_HI
#include "lspglob.h" // for Package_from_Index_word, Stackspace
#include "lsptypes.h" // for GETWORD, dtd, GETBYTE, NEWSTRINGP, GetType...
#include "mkatomdefs.h" // for compare_chars, make_atom
@ -852,7 +852,7 @@ void dump_bf(Bframe *bf) {
if (BFRAMEPTR(bf)->residual) { goto printflags; }
ptr = NativeAligned2FromLAddr(STK_OFFSET + bf->ivar);
ptr = NativeAligned2FromStackOffset(bf->ivar);
if ((((DLword *)bf - ptr) > 512) || (((UNSIGNED)ptr & 1) != 0)) {
printf("\nInvalid basic frame");
return;
@ -910,7 +910,7 @@ void dump_fx(struct frameex1 *fx_addr68k) {
/* should pay attention to the name table like RAID does */
next68k = (DLword *)NativeAligned2FromLAddr((fx_addr68k->nextblock + STK_OFFSET));
next68k = NativeAligned2FromStackOffset(fx_addr68k->nextblock);
if (fx_addr68k == CURRENTFX) { next68k = CurrentStackPTR + 2; }
if ((next68k < ptr) || (((UNSIGNED)next68k & 1) != 0)) {
@ -937,7 +937,7 @@ void dump_stackframe(struct frameex1 *fx_addr68k) {
if ((fx_addr68k->alink & 1) == 0) { /* FAST */
bf = (Bframe *)(((DLword *)fx_addr68k) - 2);
} else { /* SLOW */
bf = (Bframe *)NativeAligned4FromLAddr((fx_addr68k->blink + STK_OFFSET));
bf = (Bframe *)NativeAligned4FromStackOffset(fx_addr68k->blink);
}
dump_bf(bf);
dump_fx((struct frameex1 *)fx_addr68k);
@ -1104,12 +1104,12 @@ void all_stack_dump(DLword start, DLword end, DLword silent)
if (start == 0)
start68k = Stackspace + InterfacePage->stackbase;
else
start68k = NativeAligned2FromLAddr(STK_OFFSET | start);
start68k = NativeAligned2FromStackOffset(start);
if (end == 0)
end68k = Stackspace + InterfacePage->endofstack;
else
end68k = NativeAligned2FromLAddr(STK_OFFSET | end);
end68k = NativeAligned2FromStackOffset(end);
stkptr = (STKH *)start68k;
@ -1156,7 +1156,7 @@ void all_stack_dump(DLword start, DLword end, DLword silent)
printf(" <-***current***");
size = EndSTKP - (DLword *)stkptr;
} else {
size = NativeAligned2FromLAddr(STK_OFFSET | ((FX *)stkptr)->nextblock) - (DLword *)stkptr;
size = NativeAligned2FromStackOffset(((FX *)stkptr)->nextblock) - (DLword *)stkptr;
}
goto checksize;
default:

View File

@ -107,7 +107,7 @@ void ufn(DLword bytecode)
(LAddrFromNative(CurrentStackPTR) & 0x0ffff) - (entry68k->arg_num << 1) + 2 /** +1 **/;
/* Setup IVar */
IVar = NativeAligned2FromLAddr((((LispPTR)(CURRENTFX->nextblock)) | STK_OFFSET));
IVar = NativeAligned2FromStackOffset(CURRENTFX->nextblock);
#ifdef LISPTRACE
print(entry68k->atom_name);