/* Copyright Per Bothner 1987. Read the file Q-INFO */
#include "types.h"
#include "frame.h"
#include "procs.h"
typedef struct
  {
    long _pcToStatLink;	/* always = _PCtoSTATLINK */
    u_short _jmp;	/* always = _JMP */
    Func code;		/* normally, = FixupFrame */
    long *retAddr;	/* save real return address here */
    long *saveSp;
  } FrameSaveInfo;
extern FixupFrame(), d1;
static _FixupFrame()/* this should be done properly in assembler! */
  {
asm("FixupFrame:")
#define pf ((FrameSaveInfo*)RgStatLink)
    asm(" movl d0,d1");
    sp = pf->saveSp;
    PreserveFrame(curFrame, pf->saveSp); /* preserve frame of dynamic Link */
    a1 = pf->retAddr;
    asm(" movl d1,d0");
    asm("jmp a1@");
#undef pf
  }
PreserveFrame(frame, saveSp) /* must save d1, because called from FixupFrame */
  { register FrameSaveInfo *pf; long save=d1;
    if (FrRetAddr(frame) == FixupFrame) return;
    pf = (FrameSaveInfo*)malloc(sizeof(FrameSaveInfo));
    pf->saveSp = saveSp;
    pf->_pcToStatLink = _PCtoSTATLINK;
    pf->_jmp = _JMP;
    pf->code = FixupFrame;
    pf->retAddr = FrRetAddr(frame);
    FrRetAddr(frame) = pf;
    d1 = save;
  }
