2019-03-17 14:42:00 +00:00
|
|
|
/** @file
|
|
|
|
* Sources of the "PROCEDURE CALL" group instructions
|
1988-06-22 16:57:09 +00:00
|
|
|
*/
|
|
|
|
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
#include "em_abs.h"
|
1988-06-22 16:57:09 +00:00
|
|
|
#include "logging.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "mem.h"
|
|
|
|
#include "shadow.h"
|
|
|
|
#include "memdirect.h"
|
2019-03-17 14:42:00 +00:00
|
|
|
#include "segment.h"
|
1988-06-22 16:57:09 +00:00
|
|
|
#include "trap.h"
|
|
|
|
#include "warn.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "proctab.h"
|
|
|
|
#include "fra.h"
|
|
|
|
#include "rsb.h"
|
|
|
|
#include "linfil.h"
|
2019-10-23 23:13:51 +00:00
|
|
|
#include "switch.h"
|
Cut down some clang warnings
Edit C code to reduce warnings from clang. Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().
Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c. Such changes don't silence warnings; I make
such changes while I silence warnings in the same file. In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.
Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning. I wrongly added the `const` in d347207.
For warnings about implicit declarations of functions, the fix is to
declare the function before calling it. For example, my OpenBSD
system needs <sys/wait.h> to declare wait().
In util/int, add "whatever.h" to declare more functions. Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-23 20:06:36 +00:00
|
|
|
#include "whatever.h"
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
extern int running; /* from main.c */
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/* Forward declarations */
|
|
|
|
PRIVATE void lfr(size), ret(size);
|
1988-06-22 16:57:09 +00:00
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/** CAI -: Call procedure (procedure identifier on stack) */
|
|
|
|
void DoCAI(void) /* proc identifier on top of stack */
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
register long pi = spop(psize);
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@P6 DoCAI(%lu)", pi));
|
1988-06-22 16:57:09 +00:00
|
|
|
call(arg_p(pi), RSB_CAL);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/** CAL p: Call procedure (with identifier p) */
|
|
|
|
void DoCAL(register long pi)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@P6 DoCAL(%lu)", pi));
|
1988-06-22 16:57:09 +00:00
|
|
|
call(arg_p(pi), RSB_CAL);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/** LFR s: Load function result */
|
|
|
|
void DoLFR(register size l)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@P6 DoLFR(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
lfr(arg_s(l));
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/** RET z: Return (function result consists of top z bytes) */
|
|
|
|
void DoRET(register size l)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@P6 DoRET(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
ret(arg_z(l));
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2019-03-17 14:42:00 +00:00
|
|
|
* Calling a new procedure. *
|
1988-06-22 16:57:09 +00:00
|
|
|
************************************************************************/
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
void call(long new_PI, int rsbcode)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* legality of new_PI has already been checked */
|
|
|
|
register size nloc = proctab[new_PI].pr_nloc;
|
|
|
|
register ptr ep = proctab[new_PI].pr_ep;
|
|
|
|
|
|
|
|
push_frame(SP); /* remember AB */
|
|
|
|
pushrsb(rsbcode);
|
|
|
|
|
|
|
|
/* do the call */
|
|
|
|
PI = new_PI;
|
|
|
|
st_inc(nloc);
|
|
|
|
newPC(ep);
|
|
|
|
spoilFRA();
|
|
|
|
LOG(("@p5 call: new_PI = %lu, nloc = %lu, ep = %lu",
|
|
|
|
new_PI, nloc, ep));
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2019-03-17 14:42:00 +00:00
|
|
|
* Loading a function result. *
|
1988-06-22 16:57:09 +00:00
|
|
|
************************************************************************/
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE void lfr(size sz)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
if (sz > FRALimit) {
|
|
|
|
wtrap(WILLLFR, EILLINS);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("@p5 lfr: size = %ld", sz));
|
|
|
|
|
|
|
|
#ifdef LOGGING
|
|
|
|
if (!FRA_def) {
|
|
|
|
warning(WRFUNGAR);
|
|
|
|
}
|
|
|
|
if (sz != FRASize) {
|
|
|
|
warning(FRASize < sz ? WRFUNSML : WRFUNLAR);
|
|
|
|
}
|
1991-12-17 15:28:58 +00:00
|
|
|
#endif /* LOGGING */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
pushFRA(sz);
|
|
|
|
spoilFRA();
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Returning from a procedure. *
|
|
|
|
************************************************************************/
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE void ret(size sz)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
if (sz > FRALimit) {
|
|
|
|
wtrap(WILLRET, EILLINS);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("@p5 ret: size = %ld", sz));
|
|
|
|
|
|
|
|
/* retrieve return value from stack */
|
|
|
|
FRA_def = DEFINED;
|
|
|
|
FRASize = sz;
|
|
|
|
popFRA(FRASize);
|
|
|
|
|
|
|
|
switch (poprsb(0)) {
|
|
|
|
case RSB_STP:
|
|
|
|
if (sz == wsize) {
|
|
|
|
ES_def = DEFINED;
|
|
|
|
ES = btol(FRA[sz-1]);
|
|
|
|
/* one byte only */
|
|
|
|
}
|
|
|
|
running = 0; /* stop the machine */
|
|
|
|
return;
|
|
|
|
case RSB_CAL:
|
|
|
|
/* OK */
|
|
|
|
break;
|
|
|
|
case RSB_RTT:
|
|
|
|
case RSB_NRT:
|
|
|
|
warning(WRETTRAP);
|
|
|
|
running = 0; /* stop the machine */
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
warning(WRETBAD);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|