+ ANSI C conversion

This commit is contained in:
carl 2019-03-17 22:42:00 +08:00
parent 75909230c9
commit 5a18b85b3f
46 changed files with 1824 additions and 1742 deletions

View file

@ -1,12 +1,19 @@
/* $Id$ */ /** @file
* Memory allocation routines that will cause
* fatal error if allocation fails.
*/
#include <stdlib.h>
#include "debug.h" #include "debug.h"
#include "global.h" #include "global.h"
#include "alloc.h" #include "alloc.h"
#include "io.h"
char *Malloc(sz, descr) /** Allocate "sz" bytes on the heap with description
size sz; * "descr", raise a fatal error if it cannot be
char *descr; * allocated. Returns a pointer to the newly allocated
* block.
*/
char *Malloc(size sz, char *descr)
{ {
register char *new = malloc((unsigned int) (sz)); register char *new = malloc((unsigned int) (sz));
@ -31,10 +38,12 @@ char *Malloc(sz, descr)
return new; return new;
} }
char *Realloc(old, sz, descr) /** Reallocates an "old" memory block with new size
char *old; * "sz" in bytes. Raise a fatal error if the block
size sz; * cannot be reallocated.
char *descr; *
*/
char *Realloc(char *old, size sz, char *descr)
{ {
register char *new = realloc(old, (unsigned int) (sz)); register char *new = realloc(old, (unsigned int) (sz));

View file

@ -3,12 +3,17 @@
afterwards, we use a version that will either succeed or call afterwards, we use a version that will either succeed or call
fatal(). fatal().
*/ */
#ifndef ALLOC_H_
#define ALLOC_H_
/* $Id$ */ #include "global.h"
char *Malloc(size sz, char *descr);
char *Realloc(char *old, size sz, char *descr);
extern char *Realloc(), *Malloc();
/* reallocation factor */ /* reallocation factor */
#define allocfrac(s) ((s) * 3 / 2) #define allocfrac(s) ((s) * 3 / 2)
#endif /* ALLOC_H_ */

View file

@ -1,17 +1,16 @@
/* /** @file
Core dumping routines Core dumping routines
*/ */
/* $Id$ */
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "warn.h"
#include "shadow.h" #include "shadow.h"
#include "fra.h" #include "fra.h"
#include <stdio.h> #include <stdio.h>
core_dump() void core_dump(void)
{ {
FILE *core_file; FILE *core_file;

View file

@ -1,10 +1,10 @@
/* /** @file
Data access Data access routines
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
@ -16,18 +16,20 @@
#include "mem.h" #include "mem.h"
#include "shadow.h" #include "shadow.h"
#define HEAPSIZE 1000L /* initial heap size */ /** Initial heap size in bytes. */
#define HEAPSIZE 1000L
extern size maxheap; /* from main.c */ extern size maxheap; /* from main.c */
#ifdef LOGGING #ifdef LOGGING
char *data_sh; /* shadowbytes */ char *data_sh; /* shadowbytes */
PRIVATE void warn_dtbits(ptr, size);
PRIVATE void dt_clear_area(ptr, ptr );
#endif /* LOGGING */ #endif /* LOGGING */
PRIVATE warn_dtbits();
init_data(hb) /** Initialize the heap with "hb" address. */
ptr hb; void init_data(ptr hb)
{ {
HB = hb; /* set Heap Base */ HB = hb; /* set Heap Base */
HP = HB; /* initialize Heap Pointer */ HP = HB; /* initialize Heap Pointer */
@ -49,8 +51,8 @@ init_data(hb)
* * * *
********************************************************/ ********************************************************/
newHP(ap) /** Grows the heap space with the new heap pointer. */
ptr ap; void newHP(ptr ap)
{ {
register ptr p = ap; register ptr p = ap;
@ -99,9 +101,8 @@ newHP(ap)
* * * *
************************************************************************/ ************************************************************************/
dt_stdp(addr, ap) /** Store data pointer "ap" at address "addr". */
register ptr addr; void dt_stdp(register ptr addr, ptr ap)
ptr ap;
{ {
register int i; register int i;
register long p = (long) ap; register long p = (long) ap;
@ -117,9 +118,7 @@ dt_stdp(addr, ap)
} }
} }
dt_stip(addr, ap) void dt_stip(register ptr addr, ptr ap)
register ptr addr;
ptr ap;
{ {
register int i; register int i;
register long p = (long) ap; register long p = (long) ap;
@ -135,10 +134,8 @@ dt_stip(addr, ap)
} }
} }
dt_stn(addr, al, n) /** Store "n" byte integer "al" at address "addr". */
register ptr addr; void dt_stn(register ptr addr, long al, size n)
long al;
size n;
{ {
register int i; register int i;
register long l = al; register long l = al;
@ -160,9 +157,8 @@ dt_stn(addr, al, n)
} }
} }
dt_stw(addr, al) /** Store word sized integer "al" at address. */
register ptr addr; void dt_stw(register ptr addr, long al)
long al;
{ {
register int i; register int i;
register long l = al; register long l = al;
@ -185,10 +181,8 @@ dt_stw(addr, al)
} }
#ifndef NOFLOAT #ifndef NOFLOAT
dt_stf(addr, f, n) /** Store a real value "f" or size "n" bytes at address "addr". */
register ptr addr; void dt_stf(register ptr addr, double f, register size n)
double f;
register size n;
{ {
register char *cp = (char *) &f; register char *cp = (char *) &f;
register int i; register int i;
@ -222,8 +216,8 @@ dt_stf(addr, f, n)
* * * *
************************************************************************/ ************************************************************************/
ptr dt_lddp(addr) /** Load a data segment pointer located at address "addr". */
register ptr addr; ptr dt_lddp(register ptr addr)
{ {
register ptr p; register ptr p;
@ -243,8 +237,7 @@ ptr dt_lddp(addr)
return (p); return (p);
} }
ptr dt_ldip(addr) ptr dt_ldip(register ptr addr)
register ptr addr;
{ {
register ptr p; register ptr p;
@ -264,9 +257,8 @@ ptr dt_ldip(addr)
return (p); return (p);
} }
unsigned long dt_ldu(addr, n) /** Load an unsigned integer of "n" bytes from address "addr". */
register ptr addr; unsigned long dt_ldu(register ptr addr, size n)
size n;
{ {
register int i; register int i;
register unsigned long u = 0; register unsigned long u = 0;
@ -290,8 +282,8 @@ unsigned long dt_ldu(addr, n)
return (u); return (u);
} }
unsigned long dt_lduw(addr) /** Load an unsigned integer of word size from address "addr". */
register ptr addr; unsigned long dt_lduw(register ptr addr)
{ {
register int i; register int i;
register unsigned long u = 0; register unsigned long u = 0;
@ -315,9 +307,8 @@ unsigned long dt_lduw(addr)
return (u); return (u);
} }
long dt_lds(addr, n) /** Load an integer of size "n" bytes from address "addr". */
register ptr addr; long dt_lds(register ptr addr, size n)
size n;
{ {
register int i; register int i;
register long l; register long l;
@ -342,8 +333,8 @@ long dt_lds(addr, n)
return (l); return (l);
} }
long dt_ldsw(addr) /** Load a word size integer from address "addr". */
register ptr addr; long dt_ldsw(register ptr addr)
{ {
register int i; register int i;
register long l; register long l;
@ -379,9 +370,8 @@ long dt_ldsw(addr)
* * * *
************************************************************************/ ************************************************************************/
dt_mvd(d2, d1, n) /* d1 -> d2 */ /** Move "n" bytes from "d1" to "d2". */
register ptr d2, d1; void dt_mvd(ptr d2, ptr d1, size n)
size n;
{ {
register int i; register int i;
@ -399,9 +389,8 @@ dt_mvd(d2, d1, n) /* d1 -> d2 */
} }
} }
dt_mvs(d, s, n) /* s -> d */ /** Move "n" bytes from stack address "s" to data address "d". */
register ptr d, s; void dt_mvs(ptr d, ptr s, size n) /* s -> d */
size n;
{ {
register int i; register int i;
@ -422,9 +411,7 @@ dt_mvs(d, s, n) /* s -> d */
#ifdef LOGGING #ifdef LOGGING
PRIVATE warn_dtbits(addr, n) PRIVATE void warn_dtbits(ptr addr, size n)
register ptr addr;
register size n;
{ {
register int or_bits = 0; register int or_bits = 0;
register int and_bits = 0xff; register int and_bits = 0xff;
@ -452,5 +439,15 @@ PRIVATE warn_dtbits(addr, n)
warningcont(WWASINSP); warningcont(WWASINSP);
} }
void dt_clear_area(ptr from, ptr to)
{
/* includes *from but excludes *to */
register ptr a;
for (a = from; a < to; a++) {
dt_undef(a);
}
}
#endif /* LOGGING */ #endif /* LOGGING */

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "ARRAY" group instructions * Sources of the "ARRAY" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "trap.h" #include "trap.h"
@ -16,26 +16,24 @@
#define SAR 2 #define SAR 2
#define AAR 3 #define AAR 3
PRIVATE arr(); PRIVATE void arr(int, size);
DoLAR(arg)
size arg; void DoLAR(size arg)
{ {
/* LAR w: Load array element, descriptor contains integers of size w */ /* LAR w: Load array element, descriptor contains integers of size w */
LOG(("@A6 DoLAR(%ld)", arg)); LOG(("@A6 DoLAR(%ld)", arg));
arr(LAR, arg_wi(arg)); arr(LAR, arg_wi(arg));
} }
DoSAR(arg) void DoSAR(size arg)
size arg;
{ {
/* SAR w: Store array element */ /* SAR w: Store array element */
LOG(("@A6 DoSAR(%ld)", arg)); LOG(("@A6 DoSAR(%ld)", arg));
arr(SAR, arg_wi(arg)); arr(SAR, arg_wi(arg));
} }
DoAAR(arg) void DoAAR(size arg)
size arg;
{ {
/* AAR w: Load address of array element */ /* AAR w: Load address of array element */
LOG(("@A6 DoAAR(%ld)", arg)); LOG(("@A6 DoAAR(%ld)", arg));
@ -54,9 +52,9 @@ DoAAR(arg)
* 6. Perform the correct function. * * 6. Perform the correct function. *
*********************************************************/ *********************************************************/
PRIVATE arr(type, elm_size) PRIVATE void arr(int type, /* operation TYPE */
int type; /* operation TYPE */ size elm_size /* ELeMent SIZE */
size elm_size; /* ELeMent SIZE */ )
{ {
register ptr desc = dppop(); /* array DESCriptor */ register ptr desc = dppop(); /* array DESCriptor */
register size obj_size; /* OBJect SIZE */ register size obj_size; /* OBJect SIZE */

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "BRANCH" group instructions * Sources of the "BRANCH" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "mem.h" #include "mem.h"
@ -21,8 +21,7 @@
#define do_jump(j) { newPC(PC + (j)); } #define do_jump(j) { newPC(PC + (j)); }
DoBRA(jump) void DoBRA(register long jump)
register long jump;
{ {
/* BRA b: Branch unconditionally to label b */ /* BRA b: Branch unconditionally to label b */
@ -30,8 +29,7 @@ DoBRA(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBLT(jump) void DoBLT(register long jump)
register long jump;
{ {
/* BLT b: Branch less (pop 2 words, branch if top > second) */ /* BLT b: Branch less (pop 2 words, branch if top > second) */
register long t = wpop(); register long t = wpop();
@ -42,8 +40,7 @@ DoBLT(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBLE(jump) void DoBLE(register long jump)
register long jump;
{ {
/* BLE b: Branch less or equal */ /* BLE b: Branch less or equal */
register long t = wpop(); register long t = wpop();
@ -54,8 +51,7 @@ DoBLE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBEQ(jump) void DoBEQ(register long jump)
register long jump;
{ {
/* BEQ b: Branch equal */ /* BEQ b: Branch equal */
register long t = wpop(); register long t = wpop();
@ -66,8 +62,7 @@ DoBEQ(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBNE(jump) void DoBNE(register long jump)
register long jump;
{ {
/* BNE b: Branch not equal */ /* BNE b: Branch not equal */
register long t = wpop(); register long t = wpop();
@ -78,8 +73,7 @@ DoBNE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBGE(jump) void DoBGE(register long jump)
register long jump;
{ {
/* BGE b: Branch greater or equal */ /* BGE b: Branch greater or equal */
register long t = wpop(); register long t = wpop();
@ -90,8 +84,7 @@ DoBGE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoBGT(jump) void DoBGT(register long jump)
register long jump;
{ {
/* BGT b: Branch greater */ /* BGT b: Branch greater */
register long t = wpop(); register long t = wpop();
@ -102,8 +95,7 @@ DoBGT(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZLT(jump) void DoZLT(register long jump)
register long jump;
{ {
/* ZLT b: Branch less than zero (pop 1 word, branch negative) */ /* ZLT b: Branch less than zero (pop 1 word, branch negative) */
@ -113,8 +105,7 @@ DoZLT(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZLE(jump) void DoZLE(register long jump)
register long jump;
{ {
/* ZLE b: Branch less or equal to zero */ /* ZLE b: Branch less or equal to zero */
@ -124,8 +115,7 @@ DoZLE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZEQ(jump) void DoZEQ(register long jump)
register long jump;
{ {
/* ZEQ b: Branch equal zero */ /* ZEQ b: Branch equal zero */
@ -135,8 +125,7 @@ DoZEQ(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZNE(jump) void DoZNE(register long jump)
register long jump;
{ {
/* ZNE b: Branch not zero */ /* ZNE b: Branch not zero */
@ -146,8 +135,7 @@ DoZNE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZGE(jump) void DoZGE(register long jump)
register long jump;
{ {
/* ZGE b: Branch greater or equal zero */ /* ZGE b: Branch greater or equal zero */
@ -157,8 +145,7 @@ DoZGE(jump)
do_jump(arg_c(jump)); do_jump(arg_c(jump));
} }
DoZGT(jump) void DoZGT(register long jump)
register long jump;
{ {
/* ZGT b: Branch greater than zero */ /* ZGT b: Branch greater than zero */

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "COMPARE" group instructions * Sources of the "COMPARE" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
@ -15,15 +15,12 @@
#include "trap.h" #include "trap.h"
#include "text.h" #include "text.h"
#include "fra.h" #include "fra.h"
#include "stack.h"
#ifndef NOFLOAT
extern double fpop();
#endif /* NOFLOAT */
PRIVATE compare_obj(); PRIVATE void compare_obj(size);
DoCMI(l) void DoCMI(register size l)
register size l;
{ {
/* CMI w: Compare w byte integers, Push negative, zero, positive for <, = or > */ /* CMI w: Compare w byte integers, Push negative, zero, positive for <, = or > */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
@ -34,8 +31,7 @@ DoCMI(l)
wpush((long)(t < s ? 1 : t > s ? -1 : 0)); wpush((long)(t < s ? 1 : t > s ? -1 : 0));
} }
DoCMF(l) void DoCMF(register size l)
register size l;
{ {
/* CMF w: Compare w byte reals */ /* CMF w: Compare w byte reals */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -50,8 +46,7 @@ DoCMF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoCMU(l) void DoCMU(register size l)
register size l;
{ {
/* CMU w: Compare w byte unsigneds */ /* CMU w: Compare w byte unsigneds */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
@ -62,8 +57,7 @@ DoCMU(l)
wpush((long)(t < s ? 1 : t > s ? -1 : 0)); wpush((long)(t < s ? 1 : t > s ? -1 : 0));
} }
DoCMS(l) void DoCMS(register size l)
register size l;
{ {
/* CMS w: Compare w byte values, can only be used for bit for bit equality test */ /* CMS w: Compare w byte values, can only be used for bit for bit equality test */
@ -72,7 +66,7 @@ DoCMS(l)
compare_obj(arg_w(l)); compare_obj(arg_w(l));
} }
DoCMP() void DoCMP(void)
{ {
/* CMP -: Compare pointers */ /* CMP -: Compare pointers */
register ptr t, s; register ptr t, s;
@ -84,7 +78,7 @@ DoCMP()
wpush((long)(t < s ? 1 : t > s ? -1 : 0)); wpush((long)(t < s ? 1 : t > s ? -1 : 0));
} }
DoTLT() void DoTLT(void)
{ {
/* TLT -: True if less, i.e. iff top of stack < 0 */ /* TLT -: True if less, i.e. iff top of stack < 0 */
LOG(("@T6 DoTLT()")); LOG(("@T6 DoTLT()"));
@ -92,7 +86,7 @@ DoTLT()
wpush((long)(wpop() < 0 ? 1 : 0)); wpush((long)(wpop() < 0 ? 1 : 0));
} }
DoTLE() void DoTLE(void)
{ {
/* TLE -: True if less or equal, i.e. iff top of stack <= 0 */ /* TLE -: True if less or equal, i.e. iff top of stack <= 0 */
LOG(("@T6 DoTLE()")); LOG(("@T6 DoTLE()"));
@ -100,7 +94,7 @@ DoTLE()
wpush((long)(wpop() <= 0 ? 1 : 0)); wpush((long)(wpop() <= 0 ? 1 : 0));
} }
DoTEQ() void DoTEQ(void)
{ {
/* TEQ -: True if equal, i.e. iff top of stack = 0 */ /* TEQ -: True if equal, i.e. iff top of stack = 0 */
LOG(("@T6 DoTEQ()")); LOG(("@T6 DoTEQ()"));
@ -108,7 +102,7 @@ DoTEQ()
wpush((long)(wpop() == 0 ? 1 : 0)); wpush((long)(wpop() == 0 ? 1 : 0));
} }
DoTNE() void DoTNE(void)
{ {
/* TNE -: True if not equal, i.e. iff top of stack non zero */ /* TNE -: True if not equal, i.e. iff top of stack non zero */
LOG(("@T6 DoTNE()")); LOG(("@T6 DoTNE()"));
@ -116,7 +110,7 @@ DoTNE()
wpush((long)(wpop() != 0 ? 1 : 0)); wpush((long)(wpop() != 0 ? 1 : 0));
} }
DoTGE() void DoTGE(void)
{ {
/* TGE -: True if greater or equal, i.e. iff top of stack >= 0 */ /* TGE -: True if greater or equal, i.e. iff top of stack >= 0 */
LOG(("@T6 DoTGE()")); LOG(("@T6 DoTGE()"));
@ -124,7 +118,7 @@ DoTGE()
wpush((long)(wpop() >= 0 ? 1 : 0)); wpush((long)(wpop() >= 0 ? 1 : 0));
} }
DoTGT() void DoTGT(void)
{ {
/* TGT -: True if greater, i.e. iff top of stack > 0 */ /* TGT -: True if greater, i.e. iff top of stack > 0 */
LOG(("@T6 DoTGT()")); LOG(("@T6 DoTGT()"));
@ -133,17 +127,15 @@ DoTGT()
} }
/******************************************************** /********************************************************
* Compare objects * * Compare objects.
* * *
* Two 'obj_size' sized objects are bytewise * * Two 'obj_size' sized objects are bytewise
* compared; as soon as one byte is different * * compared; as soon as one byte is different
* 1 is returned, otherwise 0. No type checking * * 1 is returned, otherwise 0. No type checking
* is performed. Checking for undefined bytes * * is performed. Checking for undefined bytes
* is done when LOGGING is defined. * * is done when LOGGING is defined.
********************************************************/ ********************************************************/
PRIVATE void compare_obj(size obj_size)
PRIVATE compare_obj(obj_size)
size obj_size;
{ {
register ptr addr1; /* ADDRess in object highest on st. */ register ptr addr1; /* ADDRess in object highest on st. */
register ptr addr2; /* ADDRess in object deeper in st. */ register ptr addr2; /* ADDRess in object deeper in st. */

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "CONVERT" group instructions * Sources of the "CONVERT" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -13,12 +13,9 @@
#include "text.h" #include "text.h"
#include "fra.h" #include "fra.h"
#include "warn.h" #include "warn.h"
#include "stack.h"
#ifndef NOFLOAT void DoCII(void)
extern double fpop();
#endif /* NOFLOAT */
DoCII()
{ {
/* CII -: Convert integer to integer (*) */ /* CII -: Convert integer to integer (*) */
register int newsize = swpop(); register int newsize = swpop();
@ -62,7 +59,7 @@ DoCII()
} }
} }
DoCUI() void DoCUI(void)
{ {
/* CUI -: Convert unsigned to integer (*) */ /* CUI -: Convert unsigned to integer (*) */
register int newsize = swpop(); register int newsize = swpop();
@ -112,7 +109,7 @@ DoCUI()
} }
} }
DoCFI() void DoCFI(void)
{ {
/* CFI -: Convert floating to integer (*) */ /* CFI -: Convert floating to integer (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -168,7 +165,7 @@ DoCFI()
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoCIF() void DoCIF(void)
{ {
/* CIF -: Convert integer to floating (*) */ /* CIF -: Convert integer to floating (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -203,7 +200,7 @@ DoCIF()
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoCUF() void DoCUF(void)
{ {
/* CUF -: Convert unsigned to floating (*) */ /* CUF -: Convert unsigned to floating (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -249,7 +246,7 @@ DoCUF()
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoCFF() void DoCFF(void)
{ {
/* CFF -: Convert floating to floating (*) */ /* CFF -: Convert floating to floating (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -276,7 +273,7 @@ DoCFF()
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoCIU() void DoCIU(void)
{ {
/* CIU -: Convert integer to unsigned */ /* CIU -: Convert integer to unsigned */
register int newsize = swpop(); register int newsize = swpop();
@ -310,7 +307,7 @@ DoCIU()
} }
} }
DoCUU() void DoCUU(void)
{ {
/* CUU -: Convert unsigned to unsigned */ /* CUU -: Convert unsigned to unsigned */
register int newsize = swpop(); register int newsize = swpop();
@ -342,7 +339,7 @@ DoCUU()
} }
} }
DoCFU() void DoCFU(void)
{ {
/* CFU -: Convert floating to unsigned */ /* CFU -: Convert floating to unsigned */
#ifndef NOFLOAT #ifndef NOFLOAT

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "FLOATING POINT ARITHMETIC" group instructions * Sources of the "FLOATING POINT ARITHMETIC" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -12,6 +12,7 @@
#include "trap.h" #include "trap.h"
#include "text.h" #include "text.h"
#include "fra.h" #include "fra.h"
#include "io.h"
#include "warn.h" #include "warn.h"
#ifndef NOFLOAT #ifndef NOFLOAT
@ -30,15 +31,14 @@ extern double fpop();
#endif /* not __STDC__ */ #endif /* not __STDC__ */
#define SMALL (1.0/MAXDOUBLE) #define SMALL (1.0/MAXDOUBLE)
PRIVATE double adf(), sbf(), mlf(), dvf(); PRIVATE double adf(double, double), sbf(double, double), mlf(double, double), dvf(double, double);
PRIVATE double ttttp(); PRIVATE double ttttp(double, int);
PRIVATE double floor(), fabs(); PRIVATE double floor(double), fabs(double);
PRIVATE fef(), fif(); PRIVATE void fef(double, size), fif(double, double, size);
#endif /* NOFLOAT */ #endif /* NOFLOAT */
DoADF(l) void DoADF(register size l)
register size l;
{ {
/* ADF w: Floating add (*) */ /* ADF w: Floating add (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -52,8 +52,7 @@ DoADF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoSBF(l) void DoSBF(register size l)
register size l;
{ {
/* SBF w: Floating subtract (*) */ /* SBF w: Floating subtract (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -67,8 +66,7 @@ DoSBF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoMLF(l) void DoMLF(register size l)
register size l;
{ {
/* MLF w: Floating multiply (*) */ /* MLF w: Floating multiply (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -82,8 +80,7 @@ DoMLF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoDVF(l) void DoDVF(register size l)
register size l;
{ {
/* DVF w: Floating divide (*) */ /* DVF w: Floating divide (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -97,10 +94,9 @@ DoDVF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoNGF(l) void DoNGF(register size l)
register size l;
{ {
/* NGF w: Floating negate (*) */ /** NGF w: Floating negate (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
double t = fpop(arg_wf(l)); double t = fpop(arg_wf(l));
@ -112,8 +108,7 @@ DoNGF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoFIF(l) void DoFIF(register size l)
register size l;
{ {
/* FIF w: Floating multiply and split integer and fraction part (*) */ /* FIF w: Floating multiply and split integer and fraction part (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -127,8 +122,7 @@ DoFIF(l)
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
DoFEF(l) void DoFEF(register size l)
register size l;
{ {
/* FEF w: Split floating number in exponent and fraction part (*) */ /* FEF w: Split floating number in exponent and fraction part (*) */
#ifndef NOFLOAT #ifndef NOFLOAT
@ -144,8 +138,8 @@ DoFEF(l)
/* Service routines */ /* Service routines */
PRIVATE double adf(f1, f2) /* returns f1 + f2 */ /** Returns "f1" + "f2" */
double f1, f2; PRIVATE double adf(double f1, double f2)
{ {
if (must_test && !(IgnMask&BIT(EFOVFL))) { if (must_test && !(IgnMask&BIT(EFOVFL))) {
if (f1 > 0.0 && f2 > 0.0) { if (f1 > 0.0 && f2 > 0.0) {
@ -164,8 +158,8 @@ PRIVATE double adf(f1, f2) /* returns f1 + f2 */
return (f1 + f2); return (f1 + f2);
} }
PRIVATE double sbf(f1, f2) /* returns f1 - f2 */ /** Returns "f1" - "f2" */
double f1, f2; PRIVATE double sbf(double f1, double f2)
{ {
if (must_test && !(IgnMask&BIT(EFOVFL))) { if (must_test && !(IgnMask&BIT(EFOVFL))) {
if (f2 < 0.0 && f1 > 0.0) { if (f2 < 0.0 && f1 > 0.0) {
@ -184,8 +178,8 @@ PRIVATE double sbf(f1, f2) /* returns f1 - f2 */
return (f1 - f2); return (f1 - f2);
} }
PRIVATE double mlf(f1, f2) /* returns f1 * f2 */ /** Returns "f1" * "f2" */
double f1, f2; PRIVATE double mlf(double f1, double f2)
{ {
double ff1 = fabs(f1), ff2 = fabs(f2); double ff1 = fabs(f1), ff2 = fabs(f2);
@ -214,8 +208,8 @@ PRIVATE double mlf(f1, f2) /* returns f1 * f2 */
return (f1 * f2); return (f1 * f2);
} }
PRIVATE double dvf(f1, f2) /* returns f1 / f2 */ /** Returns "f1" / "f2" */
double f1, f2; PRIVATE double dvf(double f1, double f2)
{ {
double ff1 = fabs(f1), ff2 = fabs(f2); double ff1 = fabs(f1), ff2 = fabs(f2);
@ -251,9 +245,7 @@ PRIVATE double dvf(f1, f2) /* returns f1 / f2 */
return (f1 / f2); return (f1 / f2);
} }
PRIVATE fif(f1, f2, n) PRIVATE void fif(double f1, double f2, size n)
double f1, f2;
size n;
{ {
double f = mlf(f1, f2); double f = mlf(f1, f2);
double fl = floor(fabs(f)); double fl = floor(fabs(f));
@ -262,9 +254,7 @@ PRIVATE fif(f1, f2, n)
fpush((f < 0.0) ? -fl : fl, n); /* push integer-part */ fpush((f < 0.0) ? -fl : fl, n); /* push integer-part */
} }
PRIVATE fef(f, n) PRIVATE void fef(double f, size n)
double f;
size n;
{ {
register long exponent, sign = (long) (f < 0.0); register long exponent, sign = (long) (f < 0.0);
@ -286,14 +276,12 @@ PRIVATE fef(f, n)
/* floating point service routines, to avoid having to use -lm */ /* floating point service routines, to avoid having to use -lm */
PRIVATE double fabs(f) PRIVATE double fabs(double f)
double f;
{ {
return (f < 0.0 ? -f : f); return (f < 0.0 ? -f : f);
} }
PRIVATE double floor(f) PRIVATE double floor(double f)
double f;
{ {
double res, d; double res, d;
register int sign = 1; register int sign = 1;
@ -327,8 +315,8 @@ PRIVATE double floor(f)
return res; return res;
} }
PRIVATE double ttttp(f, n) /* times ten to the power */ /** Times ten to the power. */
double f; PRIVATE double ttttp(double f, int n)
{ {
while (n > 0) { while (n > 0) {
f = mlf(f, 10.0); f = mlf(f, 10.0);
@ -341,13 +329,11 @@ PRIVATE double ttttp(f, n) /* times ten to the power */
return f; return f;
} }
/* Str2double is used to initialize the global data area with floats; /** Str2double is used to initialize the global data area with floats;
we do not use, e.g., sscanf(), to be able to check the grammar of we do not use, e.g., sscanf(), to be able to check the grammar of
the string and to give warnings. the string and to give warnings.
*/ */
double str2double(char *str)
double str2double(str)
char *str;
{ {
register char b; register char b;
register int sign = 1; /* either +1 or -1 */ register int sign = 1; /* either +1 or -1 */
@ -451,7 +437,8 @@ BadFloat:
#else /* NOFLOAT */ #else /* NOFLOAT */
nofloat() { void nofloat(void)
{
fatal("attempt to execute a floating point instruction on an EM machine without FP"); fatal("attempt to execute a floating point instruction on an EM machine without FP");
} }

View file

@ -1,33 +1,34 @@
/* /** @file
* Sources of the "INCREMENT/DECREMENT/ZERO" group instructions * Sources of the "INCREMENT/DECREMENT/ZERO" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "nofloat.h" #include "nofloat.h"
#include "trap.h" #include "trap.h"
#include "mem.h" #include "mem.h"
#include "data.h"
#include "text.h" #include "text.h"
#include "stack.h"
#include "fra.h" #include "fra.h"
#include "warn.h" #include "warn.h"
PRIVATE long inc(), dec(); PRIVATE long inc(long), dec(long);
DoINC() /** INC -: Increment word on top of stack by 1 (*) */
void DoINC(void)
{ {
/* INC -: Increment word on top of stack by 1 (*) */
LOG(("@Z6 DoINC()")); LOG(("@Z6 DoINC()"));
spoilFRA(); spoilFRA();
wpush(inc(swpop())); wpush(inc(swpop()));
} }
DoINL(l) /** INL l: Increment local or parameter (*) */
register long l; void DoINL(register long l)
{ {
/* INL l: Increment local or parameter (*) */
register ptr p; register ptr p;
LOG(("@Z6 DoINL(%ld)", l)); LOG(("@Z6 DoINL(%ld)", l));
@ -36,10 +37,10 @@ DoINL(l)
st_stw(p, inc(st_ldsw(p))); st_stw(p, inc(st_ldsw(p)));
} }
DoINE(arg) /** INE g: Increment external (*) */
register long arg; void DoINE(register long arg)
{ {
/* INE g: Increment external (*) */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@Z6 DoINE(%lu)", p)); LOG(("@Z6 DoINE(%lu)", p));
@ -48,18 +49,19 @@ DoINE(arg)
dt_stw(p, inc(dt_ldsw(p))); dt_stw(p, inc(dt_ldsw(p)));
} }
DoDEC() /** DEC -: Decrement word on top of stack by 1 (*) */
void DoDEC(void)
{ {
/* DEC -: Decrement word on top of stack by 1 (*) */
LOG(("@Z6 DoDEC()")); LOG(("@Z6 DoDEC()"));
spoilFRA(); spoilFRA();
wpush(dec(swpop())); wpush(dec(swpop()));
} }
DoDEL(l) /** DEL l: Decrement local or parameter (*) */
register long l; void DoDEL(register long l)
{ {
/* DEL l: Decrement local or parameter (*) */
register ptr p; register ptr p;
LOG(("@Z6 DoDEL(%ld)", l)); LOG(("@Z6 DoDEL(%ld)", l));
@ -69,10 +71,10 @@ DoDEL(l)
st_stw(p, dec(st_ldsw(p))); st_stw(p, dec(st_ldsw(p)));
} }
DoDEE(arg) /** DEE g: Decrement external (*) */
register long arg; void DoDEE(register long arg)
{ {
/* DEE g: Decrement external (*) */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@Z6 DoDEE(%lu)", p)); LOG(("@Z6 DoDEE(%lu)", p));
@ -81,10 +83,10 @@ DoDEE(arg)
dt_stw(p, dec(dt_ldsw(p))); dt_stw(p, dec(dt_ldsw(p)));
} }
DoZRL(l) /** ZRL l: Zero local or parameter */
register long l; void DoZRL(register long l)
{ {
/* ZRL l: Zero local or parameter */
LOG(("@Z6 DoZRL(%ld)", l)); LOG(("@Z6 DoZRL(%ld)", l));
spoilFRA(); spoilFRA();
@ -92,10 +94,10 @@ DoZRL(l)
st_stw(loc_addr(l), 0L); st_stw(loc_addr(l), 0L);
} }
DoZRE(arg) /** ZRE g: Zero external */
register long arg; void DoZRE(register long arg)
{ {
/* ZRE g: Zero external */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@Z6 DoZRE(%lu)", p)); LOG(("@Z6 DoZRE(%lu)", p));
@ -103,10 +105,10 @@ DoZRE(arg)
dt_stw(arg_g(p), 0L); dt_stw(arg_g(p), 0L);
} }
DoZRF(l) /** ZRF w: Load a floating zero of size w */
register size l; void DoZRF(register size l)
{ {
/* ZRF w: Load a floating zero of size w */
#ifndef NOFLOAT #ifndef NOFLOAT
LOG(("@Z6 DoZRF(%ld)", l)); LOG(("@Z6 DoZRF(%ld)", l));
spoilFRA(); spoilFRA();
@ -116,13 +118,9 @@ DoZRF(l)
nofloat(); nofloat();
#endif /* NOFLOAT */ #endif /* NOFLOAT */
} }
/** ZER w: Load w zero bytes */
DoZER(l) void DoZER(register size l)
register size l;
{ {
/* ZER w: Load w zero bytes */
register size i;
LOG(("@Z6 DoZER(%ld)", l)); LOG(("@Z6 DoZER(%ld)", l));
spoilFRA(); spoilFRA();
npush(0L, arg_w(l)); npush(0L, arg_w(l));
@ -133,8 +131,7 @@ DoZER(l)
*/ */
} }
PRIVATE long inc(l) PRIVATE long inc(long l)
long l;
{ {
if (must_test && !(IgnMask&BIT(EIOVFL))) { if (must_test && !(IgnMask&BIT(EIOVFL))) {
if (l == i_maxsw) if (l == i_maxsw)
@ -143,8 +140,7 @@ PRIVATE long inc(l)
return (l + 1); return (l + 1);
} }
PRIVATE long dec(l) PRIVATE long dec(long l)
long l;
{ {
if (must_test && !(IgnMask&BIT(EIOVFL))) { if (must_test && !(IgnMask&BIT(EIOVFL))) {
if (l == i_minsw) if (l == i_minsw)

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "INTEGER ARITHMETIC" group instructions * Sources of the "INTEGER ARITHMETIC" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -14,12 +14,13 @@
#include "text.h" #include "text.h"
#include "fra.h" #include "fra.h"
PRIVATE long adi(), sbi(), dvi(), mli(), rmi(), ngi(), sli(), sri(); PRIVATE long adi(long, long, size), sbi(long, long, size), dvi(long, long);
PRIVATE long mli(long, long, size), rmi(long, long), ngi(long, size);
PRIVATE long sli(long, long, size), sri(long, long, size);
DoADI(l) /** ADI w: Addition (*) */
register size l; void DoADI(register size l)
{ {
/* ADI w: Addition (*) */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
LOG(("@I6 DoADI(%ld)", l)); LOG(("@I6 DoADI(%ld)", l));
@ -27,10 +28,9 @@ DoADI(l)
npush(adi(spop(l), t, l), l); npush(adi(spop(l), t, l), l);
} }
DoSBI(l) /** SBI w: Subtraction (*) */
register size l; void DoSBI(register size l)
{ {
/* SBI w: Subtraction (*) */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
LOG(("@I6 DoSBI(%ld)", l)); LOG(("@I6 DoSBI(%ld)", l));
@ -38,10 +38,9 @@ DoSBI(l)
npush(sbi(spop(l), t, l), l); npush(sbi(spop(l), t, l), l);
} }
DoMLI(l) /** MLI w: Multiplication (*) */
register size l; void DoMLI(register size l)
{ {
/* MLI w: Multiplication (*) */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
LOG(("@I6 DoMLI(%ld)", l)); LOG(("@I6 DoMLI(%ld)", l));
@ -49,10 +48,9 @@ DoMLI(l)
npush(mli(spop(l), t, l), l); npush(mli(spop(l), t, l), l);
} }
DoDVI(l) /** DVI w: Division (*) */
register size l; void DoDVI(register size l)
{ {
/* DVI w: Division (*) */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
LOG(("@I6 DoDVI(%ld)", l)); LOG(("@I6 DoDVI(%ld)", l));
@ -60,10 +58,9 @@ DoDVI(l)
npush(dvi(spop(l), t), l); npush(dvi(spop(l), t), l);
} }
DoRMI(l) /** RMI w: Remainder (*) */
register size l; void DoRMI(register size l)
{ {
/* RMI w: Remainder (*) */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
LOG(("@I6 DoRMI(%ld)", l)); LOG(("@I6 DoRMI(%ld)", l));
@ -71,21 +68,18 @@ DoRMI(l)
npush(rmi(spop(l), t), l); npush(rmi(spop(l), t), l);
} }
DoNGI(l) /** NGI w: Negate (two's complement) (*) */
register size l; void DoNGI(register size l)
{ {
/* NGI w: Negate (two's complement) (*) */
LOG(("@I6 DoNGI(%ld)", l)); LOG(("@I6 DoNGI(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_wi(l); l = arg_wi(l);
npush(ngi(spop(l), l), l); npush(ngi(spop(l), l), l);
} }
DoSLI(l) /** SLI w: Shift left (*) */
register size l; void DoSLI(register size l)
{ {
/* SLI w: Shift left (*) */
register long t = swpop(); register long t = swpop();
LOG(("@I6 DoSLI(%ld)", l)); LOG(("@I6 DoSLI(%ld)", l));
@ -94,10 +88,9 @@ DoSLI(l)
npush(sli(spop(l), t, l), l); npush(sli(spop(l), t, l), l);
} }
DoSRI(l) /** SRI w: Shift right (*) */
register size l; void DoSRI(register size l)
{ {
/* SRI w: Shift right (*) */
register long t = swpop(); register long t = swpop();
LOG(("@I6 DoSRI(%ld)", l)); LOG(("@I6 DoSRI(%ld)", l));
@ -109,9 +102,8 @@ DoSRI(l)
#define i_maxs(n) ((n == 2) ? I_MAXS2 : I_MAXS4) #define i_maxs(n) ((n == 2) ? I_MAXS2 : I_MAXS4)
#define i_mins(n) ((n == 2) ? I_MINS2 : I_MINS4) #define i_mins(n) ((n == 2) ? I_MINS2 : I_MINS4)
PRIVATE long adi(w1, w2, nbytes) /* returns w1 + w2 */ /** Returns "w1" + "w2". */
long w1, w2; PRIVATE long adi(long w1, long w2, size nbytes)
size nbytes;
{ {
if (must_test && !(IgnMask&BIT(EIOVFL))) { if (must_test && !(IgnMask&BIT(EIOVFL))) {
if (w1 > 0 && w2 > 0) { if (w1 > 0 && w2 > 0) {
@ -126,9 +118,8 @@ PRIVATE long adi(w1, w2, nbytes) /* returns w1 + w2 */
return (w1 + w2); return (w1 + w2);
} }
PRIVATE long sbi(w1, w2, nbytes) /* returns w1 - w2 */ /** Returns "w1" - "w2" */
long w1, w2; PRIVATE long sbi(long w1, long w2, size nbytes)
size nbytes;
{ {
if (must_test && !(IgnMask&BIT(EIOVFL))) { if (must_test && !(IgnMask&BIT(EIOVFL))) {
if (w2 < 0 && w1 > 0) { if (w2 < 0 && w1 > 0) {
@ -146,9 +137,8 @@ PRIVATE long sbi(w1, w2, nbytes) /* returns w1 - w2 */
#define labs(w) ((w < 0) ? (-w) : w) #define labs(w) ((w < 0) ? (-w) : w)
PRIVATE long mli(w1, w2, nbytes) /* returns w1 * w2 */ /** Returns "w1" * "w2" */
long w1, w2; PRIVATE long mli(long w1, long w2, size nbytes)
size nbytes;
{ {
if (w1 == 0 || w2 == 0) if (w1 == 0 || w2 == 0)
return (0L); return (0L);
@ -172,8 +162,7 @@ PRIVATE long mli(w1, w2, nbytes) /* returns w1 * w2 */
return (w1 * w2); return (w1 * w2);
} }
PRIVATE long dvi(w1, w2) PRIVATE long dvi(long w1, long w2)
long w1, w2;
{ {
if (w2 == 0) { if (w2 == 0) {
if (!(IgnMask&BIT(EIDIVZ))) { if (!(IgnMask&BIT(EIDIVZ))) {
@ -184,8 +173,7 @@ PRIVATE long dvi(w1, w2)
return (w1 / w2); return (w1 / w2);
} }
PRIVATE long rmi(w1, w2) PRIVATE long rmi(long w1, long w2)
long w1, w2;
{ {
if (w2 == 0) { if (w2 == 0) {
if (!(IgnMask&BIT(EIDIVZ))) { if (!(IgnMask&BIT(EIDIVZ))) {
@ -196,9 +184,7 @@ PRIVATE long rmi(w1, w2)
return (w1 % w2); return (w1 % w2);
} }
PRIVATE long ngi(w1, nbytes) PRIVATE long ngi(long w1, size nbytes)
long w1;
size nbytes;
{ {
if (must_test && !(IgnMask&BIT(EIOVFL))) { if (must_test && !(IgnMask&BIT(EIOVFL))) {
if (w1 == i_mins(nbytes)) { if (w1 == i_mins(nbytes)) {
@ -208,9 +194,8 @@ PRIVATE long ngi(w1, nbytes)
return (-w1); return (-w1);
} }
PRIVATE long sli(w1, w2, nbytes) /* w1 << w2 */ /** "w1" << "w2" */
long w1, w2; PRIVATE long sli(long w1, long w2, size nbytes)
size nbytes;
{ {
if (must_test) { if (must_test) {
#ifdef LOGGING #ifdef LOGGING
@ -240,9 +225,7 @@ PRIVATE long sli(w1, w2, nbytes) /* w1 << w2 */
} }
/*ARGSUSED*/ /*ARGSUSED*/
PRIVATE long sri(w1, w2, nbytes) /* w1 >> w2 */ PRIVATE long sri(long w1, long w2, size nbytes) /* w1 >> w2 */
long w1, w2;
size nbytes;
{ {
#ifdef LOGGING #ifdef LOGGING
if (must_test) { if (must_test) {

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "LOAD" group instructions * Sources of the "LOAD" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "mem.h" #include "mem.h"
@ -14,44 +14,37 @@
#include "rsb.h" #include "rsb.h"
#include "warn.h" #include "warn.h"
PRIVATE ptr lexback_LB(); PRIVATE ptr lexback_LB(unsigned long);
DoLOC(l) /** LOC c: Load constant (i.e. push one word onto the stack) */
register long l; void DoLOC(register long l)
{ {
/* LOC c: Load constant (i.e. push one word onto the stack) */
LOG(("@L6 DoLOC(%ld)", l)); LOG(("@L6 DoLOC(%ld)", l));
spoilFRA(); spoilFRA();
wpush(arg_c(l)); wpush(arg_c(l));
} }
DoLDC(l) /** LDC d: Load double constant ( push two words ) */
register long l; void DoLDC(register long l)
{ {
/* LDC d: Load double constant ( push two words ) */
LOG(("@L6 DoLDC(%ld)", l)); LOG(("@L6 DoLDC(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_d(l); l = arg_d(l);
npush(l, dwsize); npush(l, dwsize);
} }
DoLOL(l) /** LOL l: Load word at l-th local (l<0) or parameter (l>=0) */
register long l; void DoLOL(register long l)
{ {
/* LOL l: Load word at l-th local (l<0) or parameter (l>=0) */
LOG(("@L6 DoLOL(%ld)", l)); LOG(("@L6 DoLOL(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_l(l); l = arg_l(l);
pushw_st(loc_addr(l)); pushw_st(loc_addr(l));
} }
DoLOE(arg) /** LOE g: Load external word g */
register long arg; void DoLOE(register long arg)
{ {
/* LOE g: Load external word g */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@L6 DoLOE(%lu)", p)); LOG(("@L6 DoLOE(%lu)", p));
@ -59,21 +52,18 @@ DoLOE(arg)
pushw_m(arg_g(p)); pushw_m(arg_g(p));
} }
DoLIL(l) /** LIL l: Load word pointed to by l-th local or parameter */
register long l; void DoLIL(register long l)
{ {
/* LIL l: Load word pointed to by l-th local or parameter */
LOG(("@L6 DoLIL(%ld)", l)); LOG(("@L6 DoLIL(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_l(l); l = arg_l(l);
pushw_m(st_lddp(loc_addr(l))); pushw_m(st_lddp(loc_addr(l)));
} }
DoLOF(l) /** LOF f: Load offsetted (top of stack + f yield address) */
register long l; void DoLOF(register long l)
{ {
/* LOF f: Load offsetted (top of stack + f yield address) */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@L6 DoLOF(%ld)", l)); LOG(("@L6 DoLOF(%ld)", l));
@ -81,10 +71,10 @@ DoLOF(l)
pushw_m(p + arg_f(l)); pushw_m(p + arg_f(l));
} }
DoLAL(l) /** LAL l: Load address of local or parameter */
register long l; void DoLAL(register long l)
{ {
/* LAL l: Load address of local or parameter */
LOG(("@L6 DoLAL(%ld)", l)); LOG(("@L6 DoLAL(%ld)", l));
spoilFRA(); spoilFRA();
@ -92,10 +82,10 @@ DoLAL(l)
dppush(loc_addr(l)); dppush(loc_addr(l));
} }
DoLAE(arg) /** LAE g: Load address of external */
register unsigned long arg; void DoLAE(register unsigned long arg)
{ {
/* LAE g: Load address of external */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@L6 DoLAE(%lu)", p)); LOG(("@L6 DoLAE(%lu)", p));
@ -103,10 +93,9 @@ DoLAE(arg)
dppush(arg_lae(p)); dppush(arg_lae(p));
} }
DoLXL(l) /** LXL n: Load lexical (address of LB n static levels back) */
register unsigned long l; void DoLXL(register unsigned long l)
{ {
/* LXL n: Load lexical (address of LB n static levels back) */
register ptr p; register ptr p;
LOG(("@L6 DoLXL(%lu)", l)); LOG(("@L6 DoLXL(%lu)", l));
@ -116,10 +105,9 @@ DoLXL(l)
dppush(p); dppush(p);
} }
DoLXA(l) /** LXA n: Load lexical (address of AB n static levels back) */
register unsigned long l; void DoLXA(register unsigned long l)
{ {
/* LXA n: Load lexical (address of AB n static levels back) */
register ptr p; register ptr p;
LOG(("@L6 DoLXA(%lu)", l)); LOG(("@L6 DoLXA(%lu)", l));
@ -129,10 +117,9 @@ DoLXA(l)
dppush(p + rsbsize); dppush(p + rsbsize);
} }
DoLOI(l) /** LOI o: Load indirect o bytes (address is popped from the stack) */
register size l; void DoLOI(register size l)
{ {
/* LOI o: Load indirect o bytes (address is popped from the stack) */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@L6 DoLOI(%ld)", l)); LOG(("@L6 DoLOI(%ld)", l));
@ -141,10 +128,10 @@ DoLOI(l)
push_m(p, l); push_m(p, l);
} }
DoLOS(l) /** LOS w: Load indirect, w-byte integer on top of stack gives
register size l; * object size */
void DoLOS(register size l)
{ {
/* LOS w: Load indirect, w-byte integer on top of stack gives object size */
register ptr p; register ptr p;
LOG(("@L6 DoLOS(%ld)", l)); LOG(("@L6 DoLOS(%ld)", l));
@ -155,21 +142,18 @@ DoLOS(l)
push_m(p, arg_o(l)); push_m(p, arg_o(l));
} }
DoLDL(l) /** LDL l: Load double local or parameter (two consecutive words are stacked) */
register long l; void DoLDL(register long l)
{ {
/* LDL l: Load double local or parameter (two consecutive words are stacked) */
LOG(("@L6 DoLDL(%ld)", l)); LOG(("@L6 DoLDL(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_l(l); l = arg_l(l);
push_st(loc_addr(l), dwsize); push_st(loc_addr(l), dwsize);
} }
DoLDE(arg) /** LDE g: Load double external (two consecutive externals are stacked) */
register long arg; void DoLDE(register long arg)
{ {
/* LDE g: Load double external (two consecutive externals are stacked) */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@L6 DoLDE(%lu)", p)); LOG(("@L6 DoLDE(%lu)", p));
@ -177,10 +161,9 @@ DoLDE(arg)
push_m(arg_g(p), dwsize); push_m(arg_g(p), dwsize);
} }
DoLDF(l) /** LDF f: Load double offsetted (top of stack + f yield address) */
register long l; void DoLDF(register long l)
{ {
/* LDF f: Load double offsetted (top of stack + f yield address) */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@L6 DoLDF(%ld)", l)); LOG(("@L6 DoLDF(%ld)", l));
@ -188,18 +171,15 @@ DoLDF(l)
push_m(p + arg_f(l), dwsize); push_m(p + arg_f(l), dwsize);
} }
DoLPI(pi) /** LPI p: Load procedure identifier */
register long pi; void DoLPI(register long pi)
{ {
/* LPI p: Load procedure identifier */
LOG(("@L6 DoLPI(%ld)", pi)); LOG(("@L6 DoLPI(%ld)", pi));
spoilFRA(); spoilFRA();
npush(arg_p(pi), psize); npush(arg_p(pi), psize);
} }
PRIVATE ptr lexback_LB(n) PRIVATE ptr lexback_LB(unsigned long n)
unsigned long n;
{ {
/* LB n static levels back */ /* LB n static levels back */
register ptr lb = LB; register ptr lb = LB;

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "LOGICAL" group instructions * Sources of the "LOGICAL" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -25,11 +25,11 @@ extern int must_test;
#define check_def(p,l) #define check_def(p,l)
#endif /* LOGGING */ #endif /* LOGGING */
DoAND(l) /** AND w: Boolean and on two groups of w bytes. Size of objects to be compared
register size l; * (in bytes) on top of stack
*/
void DoAND(register size l)
{ {
/* AND w: Boolean and on two groups of w bytes */
/* size of objects to be compared (in bytes) on top of stack */
register ptr p; register ptr p;
LOG(("@X6 DoAND(%ld)", l)); LOG(("@X6 DoAND(%ld)", l));
@ -42,10 +42,9 @@ DoAND(l)
st_dec(l); st_dec(l);
} }
DoIOR(l) /** IOR w: Boolean inclusive or on two groups of w bytes */
register size l; void DoIOR(register size l)
{ {
/* IOR w: Boolean inclusive or on two groups of w bytes */
register ptr p; register ptr p;
LOG(("@X6 DoIOR(%ld)", l)); LOG(("@X6 DoIOR(%ld)", l));
@ -58,10 +57,9 @@ DoIOR(l)
st_dec(l); st_dec(l);
} }
DoXOR(l) /** XOR w: Boolean exclusive or on two groups of w bytes */
register size l; void DoXOR(register size l)
{ {
/* XOR w: Boolean exclusive or on two groups of w bytes */
register ptr p; register ptr p;
LOG(("@X6 DoXOR(%ld)", l)); LOG(("@X6 DoXOR(%ld)", l));
@ -74,10 +72,9 @@ DoXOR(l)
st_dec(l); st_dec(l);
} }
DoCOM(l) /** COM w: Complement (one's complement of top w bytes) */
register size l; void DoCOM(register size l)
{ {
/* COM w: Complement (one's complement of top w bytes) */
register ptr p; register ptr p;
LOG(("@X6 DoCOM(%ld)", l)); LOG(("@X6 DoCOM(%ld)", l));
@ -89,10 +86,9 @@ DoCOM(l)
} }
} }
DoROL(l) /** ROL w: Rotate left a group of w bytes */
register size l; void DoROL(register size l)
{ {
/* ROL w: Rotate left a group of w bytes */
register long s, t = uwpop(); register long s, t = uwpop();
register long signbit; register long signbit;
@ -122,10 +118,9 @@ DoROL(l)
npush(s, l); npush(s, l);
} }
DoROR(l) /** ROR w: Rotate right a group of w bytes */
register size l; void DoROR(register size l)
{ {
/* ROR w: Rotate right a group of w bytes */
register long s, t = uwpop(); register long s, t = uwpop();
register long signbit; register long signbit;

View file

@ -1,4 +1,4 @@
/* /** @file
* Sources of the "MISCELLANEOUS" group instructions * Sources of the "MISCELLANEOUS" group instructions
*/ */
@ -12,38 +12,43 @@
#include "warn.h" #include "warn.h"
#include "mem.h" #include "mem.h"
#include "memdirect.h" #include "memdirect.h"
#include "segment.h"
#include "shadow.h" #include "shadow.h"
#include "data.h"
#include "text.h" #include "text.h"
#include "stack.h"
#include "read.h" #include "read.h"
#include "fra.h" #include "fra.h"
#include "rsb.h" #include "rsb.h"
#include "io.h"
#include "linfil.h" #include "linfil.h"
extern int running; /* from main.c */ extern int running; /* from main.c */
/* Two useful but unofficial registers */ /** Current line number */
long LIN; long LIN;
/** Pointer to the filename. */
ptr FIL; ptr FIL;
PRIVATE index_jump(), range_check(), search_jump(); PRIVATE void index_jump(size), range_check(size), search_jump(size);
PRIVATE gto(); PRIVATE void gto(ptr);
void putLIN(long);
void putFIL(ptr);
#define asp(l) newSP(SP + arg_f(l)) #define asp(l) newSP(SP + arg_f(l))
DoASP(l) extern void moncall(void);
register long l;
{
/* ASP f: Adjust the stack pointer by f */
/** ASP f: Adjust the stack pointer by f */
void DoASP(register long l)
{
LOG(("@M6 DoASP(%ld)", l)); LOG(("@M6 DoASP(%ld)", l));
asp(l); asp(l);
} }
DoASS(l) /** ASS w: Adjust the stack pointer by w-byte integer */
register size l; void DoASS(register size l)
{ {
/* ASS w: Adjust the stack pointer by w-byte integer */
LOG(("@M6 DoASS(%ld)", l)); LOG(("@M6 DoASS(%ld)", l));
spoilFRA(); spoilFRA();
l = spop(arg_wi(l)); l = spop(arg_wi(l));
@ -57,10 +62,9 @@ DoASS(l)
else { if (in_stack(a2)) dt_mvs(a1, a2, n); \ else { if (in_stack(a2)) dt_mvs(a1, a2, n); \
else dt_mvd(a1, a2, n); } else dt_mvd(a1, a2, n); }
DoBLM(l) /** BLM z: Block move z bytes; first pop destination addr, then source addr */
register size l; void DoBLM(register size l)
{ {
/* BLM z: Block move z bytes; first pop destination addr, then source addr */
register ptr dp1, dp2; /* Destination Pointers */ register ptr dp1, dp2; /* Destination Pointers */
LOG(("@M6 DoBLM(%ld)", l)); LOG(("@M6 DoBLM(%ld)", l));
@ -70,10 +74,9 @@ DoBLM(l)
block_move(dp1, dp2, arg_z(l)); block_move(dp1, dp2, arg_z(l));
} }
DoBLS(l) /** BLS w: Block move, size is in w-byte integer on top of stack */
register size l; void DoBLS(register size l)
{ {
/* BLS w: Block move, size is in w-byte integer on top of stack */
register ptr dp1, dp2; register ptr dp1, dp2;
LOG(("@M6 DoBLS(%ld)", l)); LOG(("@M6 DoBLS(%ld)", l));
@ -84,29 +87,25 @@ DoBLS(l)
block_move(dp1, dp2, arg_z(l)); block_move(dp1, dp2, arg_z(l));
} }
DoCSA(l) /** CSA w: Case jump; address of jump table at top of stack */
register size l; void DoCSA(register size l)
{ {
/* CSA w: Case jump; address of jump table at top of stack */
LOG(("@M6 DoCSA(%ld)", l)); LOG(("@M6 DoCSA(%ld)", l));
spoilFRA(); spoilFRA();
index_jump(arg_wi(l)); index_jump(arg_wi(l));
} }
DoCSB(l) /** CSB w: Table lookup jump; address of jump table at top of stack */
register size l; void DoCSB(register size l)
{ {
/* CSB w: Table lookup jump; address of jump table at top of stack */
LOG(("@M6 DoCSB(%ld)", l)); LOG(("@M6 DoCSB(%ld)", l));
spoilFRA(); spoilFRA();
search_jump(arg_wi(l)); search_jump(arg_wi(l));
} }
DoDCH() /** DCH -: Follow dynamic chain, convert LB to LB of caller */
void DoDCH(void)
{ {
/* DCH -: Follow dynamic chain, convert LB to LB of caller */
register ptr lb; register ptr lb;
LOG(("@M6 DoDCH()")); LOG(("@M6 DoDCH()"));
@ -118,10 +117,9 @@ DoDCH()
dppush(st_lddp(lb + rsb_LB)); dppush(st_lddp(lb + rsb_LB));
} }
DoDUP(arg) /** DUP s: Duplicate top s bytes */
size arg; void DoDUP(size arg)
{ {
/* DUP s: Duplicate top s bytes */
register ptr oldSP = SP; register ptr oldSP = SP;
LOG(("@M6 DoDUP(%ld)", arg)); LOG(("@M6 DoDUP(%ld)", arg));
@ -130,10 +128,9 @@ DoDUP(arg)
st_mvs(SP, oldSP, arg); st_mvs(SP, oldSP, arg);
} }
DoDUS(l) /** DUS w: Duplicate top w bytes */
register size l; void DoDUS(register size l)
{ {
/* DUS w: Duplicate top w bytes */
register ptr oldSP; register ptr oldSP;
LOG(("@M6 DoDUS(%ld)", l)); LOG(("@M6 DoDUS(%ld)", l));
@ -144,10 +141,9 @@ DoDUS(l)
st_mvs(SP, oldSP, l); st_mvs(SP, oldSP, l);
} }
DoEXG(l) /** EXG w: Exchange top w bytes */
register size l; void DoEXG(register size l)
{ {
/* EXG w: Exchange top w bytes */
register ptr oldSP = SP; register ptr oldSP = SP;
LOG(("@M6 DoEXG(%ld)", l)); LOG(("@M6 DoEXG(%ld)", l));
@ -159,10 +155,9 @@ DoEXG(l)
st_dec(l); st_dec(l);
} }
DoFIL(arg) /** FIL g: File name (external 4 := g) */
register unsigned long arg; void DoFIL(register unsigned long arg)
{ {
/* FIL g: File name (external 4 := g) */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@M6 DoFIL(%lu)", p)); LOG(("@M6 DoFIL(%lu)", p));
@ -173,47 +168,42 @@ DoFIL(arg)
putFIL(arg_g(p)); putFIL(arg_g(p));
} }
DoGTO(arg) /** GTO g: Non-local goto, descriptor at g */
register unsigned long arg; void DoGTO(register unsigned long arg)
{ {
/* GTO g: Non-local goto, descriptor at g */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@M6 DoGTO(%lu)", p)); LOG(("@M6 DoGTO(%lu)", p));
gto(arg_gto(p)); gto(arg_gto(p));
} }
DoLIM() /** LIM -: Load 16 bit ignore mask */
void DoLIM(void)
{ {
/* LIM -: Load 16 bit ignore mask */
LOG(("@M6 DoLIM()")); LOG(("@M6 DoLIM()"));
spoilFRA(); spoilFRA();
wpush(IgnMask); wpush(IgnMask);
} }
DoLIN(l) /** LIN n: Line number (external 0 := n) */
register unsigned long l; void DoLIN(register unsigned long l)
{ {
/* LIN n: Line number (external 0 := n) */
LOG(("@M6 DoLIN(%lu)", l)); LOG(("@M6 DoLIN(%lu)", l));
spoilFRA(); spoilFRA();
putLIN((long) arg_lin(l)); putLIN((long) arg_lin(l));
} }
DoLNI() /** LNI -: Line number increment */
void DoLNI(void)
{ {
/* LNI -: Line number increment */
LOG(("@M6 DoLNI()")); LOG(("@M6 DoLNI()"));
spoilFRA(); spoilFRA();
putLIN((long)getLIN() + 1); putLIN((long)getLIN() + 1);
} }
DoLOR(l) /** LOR r: Load register (0=LB, 1=SP, 2=HP) */
register long l; void DoLOR(register long l)
{ {
/* LOR r: Load register (0=LB, 1=SP, 2=HP) */
LOG(("@M6 DoLOR(%ld)", l)); LOG(("@M6 DoLOR(%ld)", l));
spoilFRA(); spoilFRA();
switch ((int) arg_r(l)) { switch ((int) arg_r(l)) {
@ -229,9 +219,9 @@ DoLOR(l)
} }
} }
DoLPB() /** LPB -: Convert local base to argument base */
void DoLPB(void)
{ {
/* LPB -: Convert local base to argument base */
register ptr lb; register ptr lb;
LOG(("@M6 DoLPB()")); LOG(("@M6 DoLPB()"));
@ -243,35 +233,33 @@ DoLPB()
dppush(lb + rsbsize); dppush(lb + rsbsize);
} }
DoMON() /** MON -: Monitor call */
void DoMON(void)
{ {
/* MON -: Monitor call */
LOG(("@M6 DoMON()")); LOG(("@M6 DoMON()"));
spoilFRA(); spoilFRA();
moncall(); moncall();
} }
DoNOP() /** NOP -: No operation */
void DoNOP(void)
{ {
/* NOP -: No operation */
LOG(("@M6 DoNOP()")); LOG(("@M6 DoNOP()"));
spoilFRA(); spoilFRA();
message("NOP instruction"); message("NOP instruction");
} }
DoRCK(l) /** RCK w: Range check; trap on error */
register size l; void DoRCK(register size l)
{ {
/* RCK w: Range check; trap on error */
LOG(("@M6 DoRCK(%ld)", l)); LOG(("@M6 DoRCK(%ld)", l));
spoilFRA(); spoilFRA();
range_check(arg_wi(l)); range_check(arg_wi(l));
} }
DoRTT() /** RTT -: Return from trap */
void DoRTT(void)
{ {
/* RTT -: Return from trap */
LOG(("@M6 DoRTT()")); LOG(("@M6 DoRTT()"));
switch (poprsb(1)) { switch (poprsb(1)) {
@ -303,9 +291,9 @@ DoRTT()
popFRA(FRASize); popFRA(FRASize);
} }
DoSIG() /** SIG -: Trap errors to proc identifier on top of stack, \-2 resets default */
void DoSIG(void)
{ {
/* SIG -: Trap errors to proc identifier on top of stack, \-2 resets default */
register long tpi = spop(psize); register long tpi = spop(psize);
LOG(("@M6 DoSIG()")); LOG(("@M6 DoSIG()"));
@ -325,19 +313,17 @@ DoSIG()
} }
} }
DoSIM() /** SIM -: Store 16 bit ignore mask */
void DoSIM(void)
{ {
/* SIM -: Store 16 bit ignore mask */
LOG(("@M6 DoSIM()")); LOG(("@M6 DoSIM()"));
spoilFRA(); spoilFRA();
IgnMask = (uwpop() | PreIgnMask) & MASK2; IgnMask = (uwpop() | PreIgnMask) & MASK2;
} }
DoSTR(l) /** STR r: Store register (0=LB, 1=SP, 2=HP) */
register long l; void DoSTR(register long l)
{ {
/* STR r: Store register (0=LB, 1=SP, 2=HP) */
LOG(("@M6 DoSTR(%ld)", l)); LOG(("@M6 DoSTR(%ld)", l));
spoilFRA(); spoilFRA();
switch ((int) arg_r(l)) { switch ((int) arg_r(l)) {
@ -354,9 +340,9 @@ DoSTR(l)
} }
} }
DoTRP() /** TRP -: Cause trap to occur (Error number on stack) */
void DoTRP(void)
{ {
/* TRP -: Cause trap to occur (Error number on stack) */
register unsigned int tr = (unsigned int)uwpop(); register unsigned int tr = (unsigned int)uwpop();
LOG(("@M6 DoTRP()")); LOG(("@M6 DoTRP()"));
@ -369,8 +355,7 @@ DoTRP()
/* Service routines */ /* Service routines */
PRIVATE gto(p) PRIVATE void gto(ptr p)
ptr p;
{ {
register ptr old_LB = LB; register ptr old_LB = LB;
register ptr new_PC = dt_ldip(p); register ptr new_PC = dt_ldip(p);
@ -397,8 +382,7 @@ PRIVATE gto(p)
(variables LIN and FIL) and in the data space. (variables LIN and FIL) and in the data space.
*/ */
putLIN(lin) void putLIN(long lin)
long lin;
{ {
dt_unprot(i2p(LINO_AD), (long)LINSIZE); dt_unprot(i2p(LINO_AD), (long)LINSIZE);
dt_stn(i2p(LINO_AD), lin, (long)LINSIZE); dt_stn(i2p(LINO_AD), lin, (long)LINSIZE);
@ -406,8 +390,7 @@ putLIN(lin)
dt_prot(i2p(LINO_AD), (long)LINSIZE); dt_prot(i2p(LINO_AD), (long)LINSIZE);
} }
putFIL(fil) void putFIL(ptr fil)
ptr fil;
{ {
dt_unprot(i2p(FILN_AD), psize); dt_unprot(i2p(FILN_AD), psize);
dt_stdp(i2p(FILN_AD), fil); dt_stdp(i2p(FILN_AD), fil);
@ -426,8 +409,7 @@ putFIL(fil)
* 6. Else: load default value. * * 6. Else: load default value. *
********************************************************/ ********************************************************/
PRIVATE index_jump(nbytes) PRIVATE void index_jump(size nbytes)
size nbytes;
{ {
register ptr cdp = dppop(); /* Case Descriptor Pointer */ register ptr cdp = dppop(); /* Case Descriptor Pointer */
register long t_index = /* Table INDEX */ register long t_index = /* Table INDEX */
@ -454,8 +436,7 @@ PRIVATE index_jump(nbytes)
* 6. Else: load default value. * * 6. Else: load default value. *
********************************************************/ ********************************************************/
PRIVATE search_jump(nbytes) PRIVATE void search_jump(size nbytes)
size nbytes;
{ {
register ptr cdp = dppop(); /* Case Descriptor Pointer */ register ptr cdp = dppop(); /* Case Descriptor Pointer */
register long sv = spop(nbytes);/* Search Value */ register long sv = spop(nbytes);/* Search Value */
@ -486,9 +467,7 @@ PRIVATE search_jump(nbytes)
* 3. Generate trap if necessary. * * 3. Generate trap if necessary. *
* 4. DON'T remove integer. * * 4. DON'T remove integer. *
********************************************************/ ********************************************************/
PRIVATE void range_check(size nbytes)
PRIVATE range_check(nbytes)
size nbytes;
{ {
register ptr rdp = dppop(); /* Range check Descriptor Pointer */ register ptr rdp = dppop(); /* Range check Descriptor Pointer */
register long cv = /* Check Value */ register long cv = /* Check Value */

View file

@ -1,16 +1,17 @@
/* /** @file
* Sources of the "PROCEDURE CALL" group instructions * Sources of the "PROCEDURE CALL" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "mem.h" #include "mem.h"
#include "shadow.h" #include "shadow.h"
#include "memdirect.h" #include "memdirect.h"
#include "segment.h"
#include "trap.h" #include "trap.h"
#include "warn.h" #include "warn.h"
#include "text.h" #include "text.h"
@ -21,40 +22,36 @@
extern int running; /* from main.c */ extern int running; /* from main.c */
PRIVATE lfr(), ret(); /* Forward declarations */
PRIVATE void lfr(size), ret(size);
void call(long, int);
DoCAI() /* proc identifier on top of stack */ /** CAI -: Call procedure (procedure identifier on stack) */
void DoCAI(void) /* proc identifier on top of stack */
{ {
/* CAI -: Call procedure (procedure identifier on stack) */
register long pi = spop(psize); register long pi = spop(psize);
LOG(("@P6 DoCAI(%lu)", pi)); LOG(("@P6 DoCAI(%lu)", pi));
call(arg_p(pi), RSB_CAL); call(arg_p(pi), RSB_CAL);
} }
DoCAL(pi) /** CAL p: Call procedure (with identifier p) */
register long pi; void DoCAL(register long pi)
{ {
/* CAL p: Call procedure (with identifier p) */
LOG(("@P6 DoCAL(%lu)", pi)); LOG(("@P6 DoCAL(%lu)", pi));
call(arg_p(pi), RSB_CAL); call(arg_p(pi), RSB_CAL);
} }
DoLFR(l) /** LFR s: Load function result */
register size l; void DoLFR(register size l)
{ {
/* LFR s: Load function result */
LOG(("@P6 DoLFR(%ld)", l)); LOG(("@P6 DoLFR(%ld)", l));
lfr(arg_s(l)); lfr(arg_s(l));
} }
DoRET(l) /** RET z: Return (function result consists of top z bytes) */
register size l; void DoRET(register size l)
{ {
/* RET z: Return (function result consists of top z bytes) */
LOG(("@P6 DoRET(%ld)", l)); LOG(("@P6 DoRET(%ld)", l));
ret(arg_z(l)); ret(arg_z(l));
} }
@ -63,9 +60,7 @@ DoRET(l)
* Calling a new procedure. * * Calling a new procedure. *
************************************************************************/ ************************************************************************/
call(new_PI, rsbcode) void call(long new_PI, int rsbcode)
long new_PI;
int rsbcode;
{ {
/* legality of new_PI has already been checked */ /* legality of new_PI has already been checked */
register size nloc = proctab[new_PI].pr_nloc; register size nloc = proctab[new_PI].pr_nloc;
@ -87,8 +82,7 @@ call(new_PI, rsbcode)
* Loading a function result. * * Loading a function result. *
************************************************************************/ ************************************************************************/
PRIVATE lfr(sz) PRIVATE void lfr(size sz)
size sz;
{ {
if (sz > FRALimit) { if (sz > FRALimit) {
wtrap(WILLLFR, EILLINS); wtrap(WILLLFR, EILLINS);
@ -113,8 +107,7 @@ PRIVATE lfr(sz)
* Returning from a procedure. * * Returning from a procedure. *
************************************************************************/ ************************************************************************/
PRIVATE ret(sz) PRIVATE void ret(size sz)
size sz;
{ {
if (sz > FRALimit) { if (sz > FRALimit) {
wtrap(WILLRET, EILLINS); wtrap(WILLRET, EILLINS);

View file

@ -1,12 +1,13 @@
/* /** @file
* Sources of the "POINTER ARITHMETIC" group instructions * Sources of the "POINTER ARITHMETIC" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "segcheck.h" #include "segcheck.h"
#include "global.h" #include "global.h"
#include "segment.h"
#include "log.h" #include "log.h"
#include "mem.h" #include "mem.h"
#include "trap.h" #include "trap.h"
@ -27,10 +28,10 @@
#endif /* SEGCHECK */ #endif /* SEGCHECK */
DoADP(l) /** ADP f: Add f to pointer on top of stack */
register long l; void DoADP(register long l)
{ {
/* ADP f: Add f to pointer on top of stack */
register ptr p, t = st_lddp(SP); register ptr p, t = st_lddp(SP);
LOG(("@R6 DoADP(%ld)", l)); LOG(("@R6 DoADP(%ld)", l));
@ -44,10 +45,9 @@ DoADP(l)
st_stdp(SP, p); st_stdp(SP, p);
} }
DoADS(l) /** ADS w: Add w-byte value and pointer */
register size l; void DoADS(register size l)
{ {
/* ADS w: Add w-byte value and pointer */
register long t = spop(arg_wi(l)); register long t = spop(arg_wi(l));
register ptr p, s = st_lddp(SP); register ptr p, s = st_lddp(SP);
@ -62,10 +62,9 @@ DoADS(l)
st_stdp(SP, p); st_stdp(SP, p);
} }
DoSBS(l) /** SBS w: Subtract pointers in same fragment and push diff as size w integer */
register size l; void DoSBS(register size l)
{ {
/* SBS w: Subtract pointers in same fragment and push diff as size w integer */
register ptr t = st_lddp(SP); register ptr t = st_lddp(SP);
register ptr s = st_lddp(SP + psize); register ptr s = st_lddp(SP + psize);
register long w; register long w;

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "SETS" group instructions * Sources of the "SETS" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "trap.h" #include "trap.h"
@ -12,39 +12,30 @@
#include "text.h" #include "text.h"
#include "fra.h" #include "fra.h"
PRIVATE bit_test(), create_set(); PRIVATE void bit_test(size), create_set(size);
DoINN(l) /** INN w: Bit test on w byte set (bit number on top of stack) */
register size l; void DoINN(register size l)
{ {
/* INN w: Bit test on w byte set (bit number on top of stack) */
LOG(("@Y6 DoINN(%ld)", l)); LOG(("@Y6 DoINN(%ld)", l));
spoilFRA(); spoilFRA();
bit_test(arg_w(l)); bit_test(arg_w(l));
} }
DoSET(l) /** SET w: Create singleton w byte set with bit n on (n is top of stack) */
register size l; void DoSET(register size l)
{ {
/* SET w: Create singleton w byte set with bit n on (n is top of stack) */
LOG(("@Y6 DoSET(%ld)", l)); LOG(("@Y6 DoSET(%ld)", l));
spoilFRA(); spoilFRA();
create_set(arg_w(l)); create_set(arg_w(l));
} }
/******************************************************** /** Bit testing. Tests whether the bit with number to be found
* bit testing * * on TOS is on in 'w'-byte set.
* * * ON --> push 1 on stack.
* Tests whether the bit with number to be found * * OFF -> push 0 on stack.
* on TOS is on in 'w'-byte set. * **/
* ON --> push 1 on stack. * PRIVATE void bit_test(size w)
* OFF -> push 0 on stack. *
********************************************************/
PRIVATE bit_test(w)
size w;
{ {
register int bitno = register int bitno =
(int) swpop(); /* bitno on TOS */ (int) swpop(); /* bitno on TOS */
@ -65,17 +56,12 @@ PRIVATE bit_test(w)
wpush((long)((test_byte & BIT(bitoff)) ? 1 : 0)); wpush((long)((test_byte & BIT(bitoff)) ? 1 : 0));
} }
/******************************************************** /** Set creation. Creates a singleton 'w'-byte set with as
* set creation * * singleton member, the bit with number on TOS.
* * * The w bytes constituting the set are
* Creates a singleton 'w'-byte set with as * * pushed on the stack.
* singleton member, the bit with number on * **/
* TOS. The w bytes constituting the set are * PRIVATE void create_set(size w)
* pushed on the stack. *
********************************************************/
PRIVATE create_set(w)
size w;
{ {
register int bitno = (int) swpop(); register int bitno = (int) swpop();
register size nbytes = w; register size nbytes = w;

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "STORE" group instructions * Sources of the "STORE" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "mem.h" #include "mem.h"
@ -13,21 +13,18 @@
#include "fra.h" #include "fra.h"
#include "warn.h" #include "warn.h"
DoSTL(l) /** STL l: Store local or parameter */
register long l; void DoSTL(register long l)
{ {
/* STL l: Store local or parameter */
LOG(("@S6 DoSTL(%ld)", l)); LOG(("@S6 DoSTL(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_l(l); l = arg_l(l);
popw_st(loc_addr(l)); popw_st(loc_addr(l));
} }
DoSTE(arg) /** STE g: Store external */
register unsigned long arg; void DoSTE(register unsigned long arg)
{ {
/* STE g: Store external */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@S6 DoSTE(%lu)", p)); LOG(("@S6 DoSTE(%lu)", p));
@ -35,21 +32,18 @@ DoSTE(arg)
popw_m(arg_g(p)); popw_m(arg_g(p));
} }
DoSIL(l) /** SIL l: Store into word pointed to by l-th local or parameter */
register long l; void DoSIL(register long l)
{ {
/* SIL l: Store into word pointed to by l-th local or parameter */
LOG(("@S6 DoSIL(%ld)", l)); LOG(("@S6 DoSIL(%ld)", l));
spoilFRA(); spoilFRA();
l = arg_l(l); l = arg_l(l);
popw_m(st_lddp(loc_addr(l))); popw_m(st_lddp(loc_addr(l)));
} }
DoSTF(l) /** STF f: Store offsetted */
register long l; void DoSTF(register long l)
{ {
/* STF f: Store offsetted */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@S6 DoSTF(%ld)", l)); LOG(("@S6 DoSTF(%ld)", l));
@ -57,10 +51,9 @@ DoSTF(l)
popw_m(p + arg_f(l)); popw_m(p + arg_f(l));
} }
DoSTI(l) /** STI o: Store indirect o bytes (pop address, then data) */
register size l; void DoSTI(register size l)
{ {
/* STI o: Store indirect o bytes (pop address, then data) */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@S6 DoSTI(%ld)", l)); LOG(("@S6 DoSTI(%ld)", l));
@ -68,10 +61,9 @@ DoSTI(l)
pop_m(p, arg_o(l)); pop_m(p, arg_o(l));
} }
DoSTS(l) /** STS w: Store indirect, w-byte integer on top of stack gives object size */
register size l; void DoSTS(register size l)
{ {
/* STS w: Store indirect, w-byte integer on top of stack gives object size */
register ptr p; register ptr p;
LOG(("@S6 DoSTS(%ld)", l)); LOG(("@S6 DoSTS(%ld)", l));
@ -81,10 +73,9 @@ DoSTS(l)
pop_m(p, arg_o(l)); pop_m(p, arg_o(l));
} }
DoSDL(l) /** SDL l: Store double local or parameter */
register long l; void DoSDL(register long l)
{ {
/* SDL l: Store double local or parameter */
LOG(("@S6 DoSDL(%ld)", l)); LOG(("@S6 DoSDL(%ld)", l));
spoilFRA(); spoilFRA();
@ -92,10 +83,9 @@ DoSDL(l)
pop_st(loc_addr(l), dwsize); pop_st(loc_addr(l), dwsize);
} }
DoSDE(arg) /** SDE g: Store double external */
register unsigned long arg; void DoSDE(register unsigned long arg)
{ {
/* SDE g: Store double external */
register ptr p = i2p(arg); register ptr p = i2p(arg);
LOG(("@S6 DoSDE(%lu)", p)); LOG(("@S6 DoSDE(%lu)", p));
@ -103,10 +93,9 @@ DoSDE(arg)
pop_m(arg_g(p), dwsize); pop_m(arg_g(p), dwsize);
} }
DoSDF(l) /** SDF f: Store double offsetted */
register long l; void DoSDF(register long l)
{ {
/* SDF f: Store double offsetted */
register ptr p = dppop(); register ptr p = dppop();
LOG(("@S6 DoSDF(%ld)", l)); LOG(("@S6 DoSDF(%ld)", l));

View file

@ -1,10 +1,10 @@
/* /** @file
* Sources of the "UNSIGNED ARITHMETIC" group instructions * Sources of the "UNSIGNED ARITHMETIC" group instructions
*/ */
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -33,10 +33,9 @@ extern int must_test;
PRIVATE unsigned long dvu(), rmu(), slu(), sru(); PRIVATE unsigned long dvu(), rmu(), slu(), sru();
DoADU(l) /** ADU w: Addition */
register size l; void DoADU(register size l)
{ {
/* ADU w: Addition */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
LOG(("@U6 DoADU(%ld)", l)); LOG(("@U6 DoADU(%ld)", l));
@ -44,10 +43,9 @@ DoADU(l)
npush((long) adu(upop(l), t), l); npush((long) adu(upop(l), t), l);
} }
DoSBU(l) /** SBU w: Subtraction */
register size l; void DoSBU(register size l)
{ {
/* SBU w: Subtraction */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
LOG(("@U6 DoSBU(%ld)", l)); LOG(("@U6 DoSBU(%ld)", l));
@ -55,10 +53,9 @@ DoSBU(l)
npush((long) sbu(upop(l), t), l); npush((long) sbu(upop(l), t), l);
} }
DoMLU(l) /** MLU w: Multiplication */
register size l; void DoMLU(register size l)
{ {
/* MLU w: Multiplication */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
LOG(("@U6 DoMLU(%ld)", l)); LOG(("@U6 DoMLU(%ld)", l));
@ -66,10 +63,9 @@ DoMLU(l)
npush((long) mlu(upop(l), t), l); npush((long) mlu(upop(l), t), l);
} }
DoDVU(l) /** DVU w: Division */
register size l; void DoDVU(register size l)
{ {
/* DVU w: Division */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
LOG(("@U6 DoDVU(%ld)", l)); LOG(("@U6 DoDVU(%ld)", l));
@ -77,10 +73,9 @@ DoDVU(l)
npush((long) dvu(upop(l), t), l); npush((long) dvu(upop(l), t), l);
} }
DoRMU(l) /** RMU w: Remainder */
register size l; void DoRMU(register size l)
{ {
/* RMU w: Remainder */
register unsigned long t = upop(arg_wi(l)); register unsigned long t = upop(arg_wi(l));
LOG(("@U6 DoRMU(%ld)", l)); LOG(("@U6 DoRMU(%ld)", l));
@ -88,10 +83,9 @@ DoRMU(l)
npush((long) rmu(upop(l), t), l); npush((long) rmu(upop(l), t), l);
} }
DoSLU(l) /** SLU w: Shift left */
register size l; void DoSLU(register size l)
{ {
/* SLU w: Shift left */
register unsigned long t = uwpop(); register unsigned long t = uwpop();
LOG(("@U6 DoSLU(%ld)", l)); LOG(("@U6 DoSLU(%ld)", l));
@ -100,10 +94,9 @@ DoSLU(l)
npush((long) slu(upop(l), t, l), l); npush((long) slu(upop(l), t, l), l);
} }
DoSRU(l) /** SRU w: Shift right */
register size l; void DoSRU(register size l)
{ {
/* SRU w: Shift right */
register unsigned long t = uwpop(); register unsigned long t = uwpop();
LOG(("@U6 DoSRU(%ld)", l)); LOG(("@U6 DoSRU(%ld)", l));
@ -112,8 +105,9 @@ DoSRU(l)
npush((long) sru(upop(l), t, l), l); npush((long) sru(upop(l), t, l), l);
} }
PRIVATE unsigned long dvu(w1, w2) PRIVATE unsigned long dvu(
unsigned long w1, w2; unsigned long w1,
unsigned long w2)
{ {
if (w2 == 0) { if (w2 == 0) {
if (!(IgnMask&BIT(EIDIVZ))) { if (!(IgnMask&BIT(EIDIVZ))) {
@ -124,8 +118,9 @@ PRIVATE unsigned long dvu(w1, w2)
return (w1 / w2); return (w1 / w2);
} }
PRIVATE unsigned long rmu(w1, w2) PRIVATE unsigned long rmu(
unsigned long w1, w2; unsigned long w1,
unsigned long w2)
{ {
if (w2 == 0) { if (w2 == 0) {
if (!(IgnMask&BIT(EIDIVZ))) { if (!(IgnMask&BIT(EIDIVZ))) {
@ -137,10 +132,12 @@ PRIVATE unsigned long rmu(w1, w2)
} }
/*ARGSUSED*/ /*ARGSUSED*/
PRIVATE unsigned long slu(w1, w2, nbytes) /* w1 << w2 */ PRIVATE unsigned long slu(
unsigned long w1, w2; unsigned long w1,
size nbytes; unsigned long w2,
size nbytes)
{ {
/* w1 << w2 */
#ifdef LOGGING #ifdef LOGGING
if (must_test) { if (must_test) {
/* check shift distance */ /* check shift distance */
@ -156,10 +153,12 @@ PRIVATE unsigned long slu(w1, w2, nbytes) /* w1 << w2 */
} }
/*ARGSUSED*/ /*ARGSUSED*/
PRIVATE unsigned long sru(w1, w2, nbytes) /* w1 >> w2 */ PRIVATE unsigned long sru(
unsigned long w1, w2; unsigned long w1,
size nbytes; unsigned long w2,
size nbytes)
{ {
/* w1 >> w2 */
#ifdef LOGGING #ifdef LOGGING
if (must_test) { if (must_test) {
/* check shift distance */ /* check shift distance */

View file

@ -1,4 +1,4 @@
/* /** @file
For dumping the stack, GDA, heap and text segment. For dumping the stack, GDA, heap and text segment.
*/ */
@ -6,7 +6,8 @@
#include <ctype.h> #include <ctype.h>
#include <em_abs.h> #include "em_abs.h"
#include "dump.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
@ -31,19 +32,18 @@ extern long inr; /* from log.c */
although it is not directly evident how. although it is not directly evident how.
*/ */
PRIVATE char *displ_undefs(), *displ_fil(), *displ_sh(), *displ_code(); /* Forward declarations */
PRIVATE ptr std_raw(), std_rsb(); PRIVATE char *displ_undefs(int, ptr), *displ_fil(ptr), *displ_sh(char, int), *displ_code(int);
PRIVATE int std_bytes(), dtd_bytes(), FRAd_bytes(); PRIVATE ptr std_raw(ptr, int), std_rsb(ptr);
PRIVATE std_item(), std_left_undefs(); PRIVATE int std_bytes(ptr, ptr, int), dtd_bytes(ptr, ptr, int), FRAd_bytes(int, int, int);
PRIVATE gdad_item(), gdad_left_undefs(); PRIVATE void std_item(ptr), std_left_undefs(int, ptr);
PRIVATE hpd_item(), hpd_left_undefs(); PRIVATE void gdad_item(ptr), gdad_left_undefs(int, ptr);
PRIVATE FRA_dump(), FRA_item(); PRIVATE void hpd_item(ptr), hpd_left_undefs(int, ptr);
PRIVATE void FRA_dump(void), FRA_item(int);
/******** Stack Dump ********/ /******** Stack Dump ********/
std_all(sz, rawfl) void std_all(long sz, int rawfl)
long sz;
int rawfl;
{ {
register ptr addr; register ptr addr;
@ -79,11 +79,9 @@ std_all(sz, rawfl)
LOG((" d2 ")); LOG((" d2 "));
} }
PRIVATE ptr PRIVATE ptr std_raw(ptr addr, int rawfl)
std_raw(addr, rawfl) {
ptr addr; /* Produces a formatted dump of the stack segment starting
int rawfl;
{ /* Produces a formatted dump of the stack segment starting
at addr, up to the Return Status Block (identified at addr, up to the Return Status Block (identified
by protection bits) by protection bits)
*/ */
@ -112,8 +110,7 @@ std_raw(addr, rawfl)
return addr; return addr;
} }
PRIVATE std_item(addr) PRIVATE void std_item(ptr addr)
ptr addr;
{ {
if ( is_wordaligned(addr) if ( is_wordaligned(addr)
&& is_in_stack(addr, psize) && is_in_stack(addr, psize)
@ -147,10 +144,9 @@ PRIVATE std_item(addr)
} }
} }
PRIVATE ptr /** Dumps the Return Status Block. */
std_rsb(addr) PRIVATE ptr std_rsb(ptr addr)
ptr addr; {
{ /* Dumps the Return Status Block */
ptr dmp_lb; ptr dmp_lb;
int code; int code;
long pi; long pi;
@ -194,8 +190,7 @@ std_rsb(addr)
return addr - rsbsize; return addr - rsbsize;
} }
PRIVATE char *displ_code(rsbcode) PRIVATE char *displ_code(int rsbcode)
int rsbcode;
{ {
switch (rsbcode) { switch (rsbcode) {
case RSB_STP: return "STP"; case RSB_STP: return "STP";
@ -207,9 +202,7 @@ PRIVATE char *displ_code(rsbcode)
/*NOTREACHED*/ /*NOTREACHED*/
} }
PRIVATE std_left_undefs(nundef, addr) PRIVATE void std_left_undefs(int nundef, ptr addr)
int nundef;
ptr addr;
{ {
/* handle pending undefineds */ /* handle pending undefineds */
switch (nundef) { switch (nundef) {
@ -226,7 +219,7 @@ PRIVATE std_left_undefs(nundef, addr)
} }
} }
PRIVATE FRA_dump() PRIVATE void FRA_dump(void)
{ {
register int addr; register int addr;
@ -238,8 +231,7 @@ PRIVATE FRA_dump()
} }
} }
PRIVATE FRA_item(addr) PRIVATE void FRA_item(int addr)
int addr;
{ {
if ( is_wordaligned(addr) if ( is_wordaligned(addr)
&& is_in_FRA(addr, psize) && is_in_FRA(addr, psize)
@ -276,8 +268,7 @@ PRIVATE FRA_item(addr)
/******** Global Data Area Dump ********/ /******** Global Data Area Dump ********/
gdad_all(low, high) void gdad_all(ptr low, ptr high)
ptr low, high;
{ {
register ptr addr; register ptr addr;
register int nundef = 0; register int nundef = 0;
@ -316,8 +307,7 @@ gdad_all(low, high)
LOG((" +1 ")); LOG((" +1 "));
} }
PRIVATE gdad_item(addr) PRIVATE void gdad_item(ptr addr)
ptr addr;
{ {
if ( is_wordaligned(addr) if ( is_wordaligned(addr)
&& is_in_data(addr, psize) && is_in_data(addr, psize)
@ -351,9 +341,7 @@ PRIVATE gdad_item(addr)
} }
} }
PRIVATE gdad_left_undefs(nundef, addr) PRIVATE void gdad_left_undefs(int nundef, ptr addr)
int nundef;
ptr addr;
{ {
/* handle pending undefineds */ /* handle pending undefineds */
switch (nundef) { switch (nundef) {
@ -372,7 +360,7 @@ PRIVATE gdad_left_undefs(nundef, addr)
/******** Heap Area Dump ********/ /******** Heap Area Dump ********/
hpd_all() void hpd_all(void)
{ {
register ptr addr; register ptr addr;
register int nundef = 0; register int nundef = 0;
@ -406,8 +394,7 @@ hpd_all()
LOG((" *1 ")); LOG((" *1 "));
} }
PRIVATE hpd_item(addr) PRIVATE void hpd_item(ptr addr)
ptr addr;
{ {
if ( is_wordaligned(addr) if ( is_wordaligned(addr)
&& is_in_data(addr, psize) && is_in_data(addr, psize)
@ -441,9 +428,7 @@ PRIVATE hpd_item(addr)
} }
} }
PRIVATE hpd_left_undefs(nundef, addr) PRIVATE void hpd_left_undefs(int nundef, ptr addr)
int nundef;
ptr addr;
{ {
/* handle pending undefineds */ /* handle pending undefineds */
switch (nundef) { switch (nundef) {
@ -463,9 +448,7 @@ PRIVATE hpd_left_undefs(nundef, addr)
/* Service routines */ /* Service routines */
PRIVATE int std_bytes(low, high, bits) PRIVATE int std_bytes(ptr low, ptr high, int bits)
ptr low, high;
int bits;
{ {
/* True if all stack bytes from low to high-1 have one of the /* True if all stack bytes from low to high-1 have one of the
bits in bits on. bits in bits on.
@ -480,9 +463,7 @@ PRIVATE int std_bytes(low, high, bits)
return byte & bits; return byte & bits;
} }
PRIVATE int dtd_bytes(low, high, bits) PRIVATE int dtd_bytes(ptr low, ptr high, int bits)
ptr low, high;
int bits;
{ {
/* True if all data bytes from low to high-1 have one of the /* True if all data bytes from low to high-1 have one of the
bits in bits on. bits in bits on.
@ -497,9 +478,7 @@ PRIVATE int dtd_bytes(low, high, bits)
return byte & bits; return byte & bits;
} }
PRIVATE int FRAd_bytes(low, high, bits) PRIVATE int FRAd_bytes(int low, int high, int bits)
int low, high;
int bits;
{ {
/* True if all data bytes from low to high-1 have one of the /* True if all data bytes from low to high-1 have one of the
bits in bits on. bits in bits on.
@ -514,10 +493,7 @@ PRIVATE int FRAd_bytes(low, high, bits)
return byte & bits; return byte & bits;
} }
PRIVATE char * /* transient */ PRIVATE char *displ_undefs(int nundef, ptr addr)
displ_undefs(nundef, addr)
int nundef;
ptr addr;
{ {
/* Given the number of undefineds, we want to report the number /* Given the number of undefineds, we want to report the number
of words with the left-over numbers of bytes on both sides: of words with the left-over numbers of bytes on both sides:
@ -562,9 +538,7 @@ displ_undefs(nundef, addr)
return buf; return buf;
} }
PRIVATE char * PRIVATE char *displ_fil(ptr fil)
displ_fil(fil) /* transient */
ptr fil;
{ /* Returns a buffer containing a representation of the { /* Returns a buffer containing a representation of the
filename derived from FIL-value fil. filename derived from FIL-value fil.
*/ */
@ -590,10 +564,7 @@ displ_fil(fil) /* transient */
return &buf[0]; return &buf[0];
} }
PRIVATE char * PRIVATE char *displ_sh(char shadow, int byte)
displ_sh(shadow, byte) /* transient */
char shadow;
int byte;
{ /* Returns a buffer containing a description of the { /* Returns a buffer containing a description of the
shadow byte. shadow byte.
*/ */

View file

@ -11,7 +11,8 @@
char *FRA_sh; /* shadowbytes */ char *FRA_sh; /* shadowbytes */
#endif /* LOGGING */ #endif /* LOGGING */
init_FRA() { void init_FRA(void)
{
FRA = Malloc(FRALimit, "Function Return Area"); FRA = Malloc(FRALimit, "Function Return Area");
#ifdef LOGGING #ifdef LOGGING
FRA_sh = Malloc(FRALimit, "shadowspace for Function Return Area"); FRA_sh = Malloc(FRALimit, "shadowspace for Function Return Area");
@ -19,8 +20,7 @@ init_FRA() {
FRA_def = UNDEFINED; /* set FRA illegal */ FRA_def = UNDEFINED; /* set FRA illegal */
} }
pushFRA(sz) void pushFRA(size sz)
size sz;
{ {
register int i; register int i;
@ -28,7 +28,8 @@ pushFRA(sz)
return; return;
st_inc(max(sz, wsize)); st_inc(max(sz, wsize));
for (i = 0; i < sz; i++) { for (i = 0; i < sz; i++)
{
stack_loc(SP + i) = FRA[i]; stack_loc(SP + i) = FRA[i];
#ifdef LOGGING #ifdef LOGGING
st_sh(SP + i) = (i < FRASize ? FRA_sh[i] : UNDEFINED); st_sh(SP + i) = (i < FRASize ? FRA_sh[i] : UNDEFINED);
@ -36,15 +37,15 @@ pushFRA(sz)
} }
} }
popFRA(sz) void popFRA(size sz)
size sz;
{ {
register int i; register int i;
if (sz == 0) if (sz == 0)
return; return;
for (i = 0; i < sz; i++) { for (i = 0; i < sz; i++)
{
FRA[i] = stack_loc(SP + i); FRA[i] = stack_loc(SP + i);
#ifdef LOGGING #ifdef LOGGING
FRA_sh[i] = st_sh(SP + i); FRA_sh[i] = st_sh(SP + i);

View file

@ -6,6 +6,11 @@
#include "logging.h" #include "logging.h"
void init_FRA(void);
void pushFRA(size);
void popFRA(size);
#ifdef LOGGING #ifdef LOGGING
extern char *FRA_sh; /* shadowbytes of Function Return Area */ extern char *FRA_sh; /* shadowbytes of Function Return Area */

View file

@ -1,18 +1,27 @@
/* /** @file
Startup routines Startup routines.
*/ */
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "segment.h"
#include "log.h" #include "log.h"
#include "rsb.h"
#include "fra.h"
#include "read.h"
#include "stack.h"
#include "text.h"
#include "data.h"
#include "alloc.h" #include "alloc.h"
#include "warn.h" #include "warn.h"
#include "mem.h" #include "mem.h"
#include "io.h"
#include "shadow.h" #include "shadow.h"
#include "trap.h" #include "trap.h"
#include "read.h" #include "read.h"
@ -41,9 +50,7 @@ PRIVATE size alignedstrlen();
char *load_name; char *load_name;
init(ac, av) void init(int ac, char **av)
int ac;
char **av;
{ {
register char **p; register char **p;
register size env_vec_size; /* size of environ vector */ register size env_vec_size; /* size of environ vector */
@ -137,17 +144,14 @@ init(ac, av)
wpush((long) ac); /* push argc */ wpush((long) ac); /* push argc */
} }
PRIVATE size alignedstrlen(s) PRIVATE size alignedstrlen(char *s)
char *s;
{ {
register size len = strlen(s) + 1; register size len = strlen(s) + 1;
return (len + wsize - 1) / wsize * wsize; return (len + wsize - 1) / wsize * wsize;
} }
PRIVATE ptr storestring(addr, s) PRIVATE ptr storestring(ptr addr, char *s)
ptr addr;
char *s;
{ {
/* Store string, aligned to a fit multiple of wsize bytes. /* Store string, aligned to a fit multiple of wsize bytes.
Return first address on a wordsize boundary after string. Return first address on a wordsize boundary after string.
@ -174,29 +178,7 @@ PRIVATE ptr storestring(addr, s)
return (addr + i); return (addr + i);
} }
#ifdef LOGGING
dt_clear_area(from, to)
ptr from;
register ptr to;
{
/* includes *from but excludes *to */
register ptr a;
for (a = from; a < to; a++) {
dt_undef(a);
}
}
st_clear_area(from, to)
ptr from;
register ptr to;
{
/* includes both *from and *to (since ML+1 is unexpressible) */
register ptr a;
for (a = from; a >= to; a--) {
st_undef(a);
}
}
#endif /* LOGGING */

View file

@ -1,35 +1,35 @@
/* /** @file
In and output, error messages, etc. In and output, error messages, etc.
*/ */
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#if __STDC__
#include <stdarg.h> #include <stdarg.h>
extern fatal(char *, ...);
#else
#include <varargs.h>
#endif
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "mem.h" #include "mem.h"
#include "io.h"
#include "warn.h"
#include "log.h"
#include "linfil.h" #include "linfil.h"
extern int running; /* from main.c */ extern int running; /* from main.c */
extern char *prog_name; /* from main.c */ extern char *prog_name; /* from main.c */
extern char *load_name; /* from init.c */ extern char *load_name; /* from init.c */
extern void core_dump(void);
/******** The message file ********/ /******** The message file ********/
extern char mess_file[64]; /* from main.c */ extern char mess_file[64]; /* from main.c */
long mess_id; /* Id, to determine unique mess file */ long mess_id; /* Id, to determine unique mess file */
FILE *mess_fp; /* Filepointer of message file */ FILE *mess_fp; /* Filepointer of message file */
PRIVATE do_fatal(); PRIVATE void do_fatal(FILE *, char *, va_list);
incr_mess_id() void incr_mess_id(void)
{ /* for a new child */ { /* for a new child */
mess_id++; mess_id++;
} }
@ -44,12 +44,11 @@ PRIVATE int highestfd();
int fd_limit = 100; /* first non-available file descriptor */ int fd_limit = 100; /* first non-available file descriptor */
FILE *fcreat_high(fn) /** Creates an unbuffered FILE with name "fn" on the highest
char *fn; * possible file descriptor.
{
/* Creates an unbuffered FILE with name fn on the highest
possible file descriptor.
*/ */
FILE *fcreat_high(char *fn)
{
register int fd; register int fd;
register FILE *fp; register FILE *fp;
@ -63,13 +62,13 @@ FILE *fcreat_high(fn)
return fp; return fp;
} }
PRIVATE int highestfd(fd) /** Moves the (open) file descriptor "fd" to the highest available
int fd; * position and returns the new "fd". Does this without knowing
{ * how many fd-s are available.
/* Moves the (open) file descriptor fd to the highest available
position and returns the new fd. Does this without knowing
how many fd-s are available.
*/ */
PRIVATE int highestfd(int fd)
{
register int newfd, higherfd; register int newfd, higherfd;
/* try to get a better fd */ /* try to get a better fd */
@ -89,8 +88,7 @@ PRIVATE int highestfd(fd)
return higherfd; /* this is a deep one */ return higherfd; /* this is a deep one */
} }
init_ofiles(firsttime) void init_ofiles(int firsttime)
int firsttime;
{ {
if (!firsttime) { if (!firsttime) {
fclose(mess_fp); /* old message file */ fclose(mess_fp); /* old message file */
@ -110,9 +108,8 @@ init_ofiles(firsttime)
#endif /* LOGGING */ #endif /* LOGGING */
} }
#if __STDC__
/*VARARGS0*/ /*VARARGS0*/
fatal(char *fmt, ...) void fatal(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -137,40 +134,8 @@ fatal(char *fmt, ...)
close_down(1); close_down(1);
} }
#else
/*VARARGS0*/
fatal(va_alist)
va_dcl
{
va_list ap;
fprintf(stderr, "%s: ", prog_name); void close_down(int rc)
va_start(ap);
{
register char *fmt = va_arg(ap, char *);
do_fatal(stderr, fmt, ap);
}
va_end(ap);
if (mess_fp) {
va_start(ap);
{
register char *fmt = va_arg(ap, char *);
do_fatal(mess_fp, fmt, ap);
}
va_end(ap);
}
if (running)
core_dump();
close_down(1);
}
#endif
close_down(rc)
int rc;
{ {
/* all exits should go through here */ /* all exits should go through here */
if (mess_fp) { if (mess_fp) {
@ -185,10 +150,7 @@ close_down(rc)
exit(rc); exit(rc);
} }
PRIVATE do_fatal(fp, fmt, ap) PRIVATE void do_fatal(FILE *fp, char *fmt, va_list ap)
FILE *fp;
char *fmt;
va_list ap;
{ {
fprintf(fp, "(Fatal error) "); fprintf(fp, "(Fatal error) ");
if (load_name) if (load_name)
@ -197,9 +159,8 @@ PRIVATE do_fatal(fp, fmt, ap)
fputc('\n', fp); fputc('\n', fp);
} }
#if __STDC__
/*VARARGS0*/ /*VARARGS0*/
message(char *fmt, ...) void message(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -213,27 +174,8 @@ message(char *fmt, ...)
fprintf(mess_fp, " at %s\n", position()); fprintf(mess_fp, " at %s\n", position());
} }
#else
/*VARARGS0*/
message(va_alist)
va_dcl
{
va_list ap;
fprintf(mess_fp, "(Message): "); char *position(void) /* transient */
va_start(ap);
{
register char *fmt = va_arg(ap, char *);
vfprintf(mess_fp, fmt, ap);
}
va_end(ap);
fprintf(mess_fp, " at %s\n", position());
}
#endif
char *position() /* transient */
{ {
static char buff[300]; static char buff[300];
register char *fn = dt_fname(getFIL()); register char *fn = dt_fname(getFIL());

View file

@ -14,7 +14,9 @@
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "dump.h"
#include "linfil.h" #include "linfil.h"
#include "io.h"
#ifdef LOGGING #ifdef LOGGING
@ -49,12 +51,11 @@ PRIVATE FILE *log_fp; /* Filepointer of log file */
PRIVATE int argcount; PRIVATE int argcount;
PRIVATE char *arglist[20]; /* arbitrary size */ PRIVATE char *arglist[20]; /* arbitrary size */
PRIVATE char *getpar(); PRIVATE void set_lmask(char *mask);
PRIVATE long longpar(); PRIVATE char *getpar(char *);
PRIVATE set_lmask(); PRIVATE long longpar(char *, long);
int logarg(str) int logarg(char *str)
char *str;
{ {
/* If the string might be an interesting argument for the /* If the string might be an interesting argument for the
logging machine, it is stored in the arglist, and logarg logging machine, it is stored in the arglist, and logarg
@ -65,10 +66,12 @@ int logarg(str)
register char *arg = str; register char *arg = str;
register char ch; register char ch;
while ((ch = *arg) && (ch != '=')) { while ((ch = *arg) && (ch != '='))
{
arg++; arg++;
} }
if (ch == '=') { if (ch == '=')
{
if (argcount == (sizeof arglist / sizeof arglist[0])) if (argcount == (sizeof arglist / sizeof arglist[0]))
fatal("too many logging arguments on command line"); fatal("too many logging arguments on command line");
arglist[argcount++] = str; arglist[argcount++] = str;
@ -77,29 +80,33 @@ int logarg(str)
return 0; return 0;
} }
init_log() void init_log(void)
{ {
/* setting the logging machine */ /* setting the logging machine */
stop = longpar("STOP", 0L); stop = longpar("STOP", 0L);
gdump = longpar("GDA", 0L); gdump = longpar("GDA", 0L);
if (gdump) { if (gdump)
{
gmin = i2p(longpar("GMIN", 0L)); gmin = i2p(longpar("GMIN", 0L));
gmax = i2p(longpar("GMAX", 0L)); gmax = i2p(longpar("GMAX", 0L));
set_lmask("+1"); set_lmask("+1");
} }
hdump = longpar("HEAP", 0L); hdump = longpar("HEAP", 0L);
if (hdump) { if (hdump)
{
set_lmask("*1"); set_lmask("*1");
} }
stdsize = longpar("STDSIZE", 0L); stdsize = longpar("STDSIZE", 0L);
stdrawflag = longpar("RAWSTACK", 0L); stdrawflag = longpar("RAWSTACK", 0L);
if (getpar("LOGFILE")) { if (getpar("LOGFILE"))
{
strcpy(log_file, getpar("LOGFILE")); strcpy(log_file, getpar("LOGFILE"));
} }
if ((at = longpar("AT", 0L))) { if ((at = longpar("AT", 0L)))
{
/* abbreviation for: */ /* abbreviation for: */
stop = at + 1; /* stop AFTER at + 1 */ stop = at + 1; /* stop AFTER at + 1 */
/* Note: the setting of log_start is deferred to /* Note: the setting of log_start is deferred to
@ -109,7 +116,8 @@ init_log()
*/ */
} }
if ((lmask = getpar("L"))) { if ((lmask = getpar("L")))
{
/* abbreviation for: */ /* abbreviation for: */
log_start = 0; log_start = 0;
must_log = 1; must_log = 1;
@ -118,119 +126,128 @@ init_log()
inr = 0; inr = 0;
} }
/******** The log file ********/ /******** The log file ********/
open_log(firsttime) void open_log(int firsttime)
int firsttime; {
if (!firsttime)
{ {
if (!firsttime) {
sprintf(logvar, "%s%ld", logvar, mess_id); sprintf(logvar, "%s%ld", logvar, mess_id);
if (log_fp) { if (log_fp)
{
fclose(log_fp); fclose(log_fp);
log_fp = 0; log_fp = 0;
} }
logging = 0; logging = 0;
if ((must_log = getpar(logvar) != 0)) { if ((must_log = getpar(logvar) != 0))
{
sprintf(log_file, "%s%ld", log_file, mess_id); sprintf(log_file, "%s%ld", log_file, mess_id);
log_start = atol(getpar(logvar)); log_start = atol(getpar(logvar));
} }
} }
else { else
{
/* first time, top level */ /* first time, top level */
logvar = "LOG\0 "; logvar = "LOG\0 ";
if (at) { /* patch */ if (at)
{ /* patch */
must_log = 1; must_log = 1;
log_start = at - 1; log_start = at - 1;
} }
else else if (!must_log && (must_log = getpar(logvar) != 0))
if (!must_log && (must_log = getpar(logvar) != 0)) { {
log_start = atoi(getpar(logvar)); log_start = atoi(getpar(logvar));
} }
set_lmask(lmask ? lmask : set_lmask(
getpar("LOGMASK") ? getpar("LOGMASK") : lmask ? lmask :
"A-Z9d2twx9"); getpar("LOGMASK") ? getpar("LOGMASK") : "A-Z9d2twx9");
} }
/* Create logfile if needed */ /* Create logfile if needed */
if (must_log) { if (must_log)
{
if ((log_fp = fcreat_high(log_file)) == NULL) if ((log_fp = fcreat_high(log_file)) == NULL)
fatal("Cannot create logfile '%s'", log_file); fatal("Cannot create logfile '%s'", log_file);
} }
if (must_log && inr >= log_start) { if (must_log && inr >= log_start)
{
logging = 1; logging = 1;
} }
} }
close_log() { void close_log(void)
if (log_fp) { {
if (log_fp)
{
fclose(log_fp); fclose(log_fp);
log_fp = 0; log_fp = 0;
} }
} }
/******** The logmask ********/ /******** The logmask ********/
#define inrange(c,l,h) (l <= c && c <= h) #define inrange(c,l,h) (l <= c && c <= h)
#define layout(c) (c == ' ' || c == '\t' || c == ',') #define layout(c) (c == ' ' || c == '\t' || c == ',')
PRIVATE set_lmask(mask) PRIVATE void set_lmask(char *mask)
char *mask;
{ {
register char *mp = mask; register char *mp = mask;
while (*mp != 0) { while (*mp != 0)
{
register char *lvp; register char *lvp;
register int lev; register int lev;
while (layout(*mp)) { while (layout(*mp))
{
mp++; mp++;
} }
/* find level */ /* find level */
lvp = mp; lvp = mp;
while (*lvp != 0 && !inrange(*lvp, '0', '9')) { while (*lvp != 0 && !inrange(*lvp, '0', '9'))
{
lvp++; lvp++;
} }
lev = *lvp - '0'; lev = *lvp - '0';
/* find classes */ /* find classes */
while (mp != lvp) { while (mp != lvp)
register mc = *mp; {
register int mc = *mp;
if ( inrange(mc, 'a', 'z') if ( inrange(mc, 'a', 'z') || inrange(mc, 'A', 'Z') || mc == '+'
|| inrange(mc, 'A', 'Z') || mc == '*')
|| mc == '+' {
|| mc == '*'
) {
log_level[mc] = lev; log_level[mc] = lev;
mp++; mp++;
} }
else if (mc == '-') { else if (mc == '-')
{
register char c; register char c;
for (c = *(mp-1) + 1; c <= *(mp + 1); c++) { for (c = *(mp - 1) + 1; c <= *(mp + 1); c++)
log_level[c] = lev; {
log_level[(unsigned char)c] = lev;
} }
mp += 2; mp += 2;
} }
else if (layout(mc)) { else if (layout(mc))
{
mp++; mp++;
} }
else fatal("Bad logmask initialization string"); else
fatal("Bad logmask initialization string");
} }
mp = lvp + 1; mp = lvp + 1;
} }
} }
/******** The logging ********/ /******** The logging ********/
int check_log(mark) int check_log(char mark[])
char mark[];
{ {
/* mark must be of the form ".CL...", C is class letter, /* mark must be of the form ".CL...", C is class letter,
L is level digit. L is level digit.
@ -238,12 +255,12 @@ int check_log(mark)
if (!logging) if (!logging)
return 0; return 0;
return ((mark[2] - '0') <= log_level[mark[1]]); return ((mark[2] - '0') <= log_level[(unsigned char)mark[1]]);
} }
#if __STDC__ #if __STDC__
/*VARARGS*/ /*VARARGS*/
do_log(char *fmt, ...) void do_log(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -265,12 +282,14 @@ do_log(va_alist)
if (!check_log(fmt)) if (!check_log(fmt))
return; return;
if (fmt[0] == '@') { if (fmt[0] == '@')
{
/* include position */ /* include position */
fprintf(log_fp, "%.4s%s, ", fmt, position()); fprintf(log_fp, "%.4s%s, ", fmt, position());
vfprintf(log_fp, &fmt[4], ap); vfprintf(log_fp, &fmt[4], ap);
} }
else { else
{
vfprintf(log_fp, &fmt[0], ap); vfprintf(log_fp, &fmt[0], ap);
} }
} }
@ -279,10 +298,11 @@ do_log(va_alist)
putc('\n', log_fp); putc('\n', log_fp);
} }
log_eoi() void log_eoi(void)
{ {
/* Logging to be done at end of instruction */ /* Logging to be done at end of instruction */
if (logging) { if (logging)
{
if (inr == gdump) if (inr == gdump)
gdad_all(gmin, gmax); gdad_all(gmin, gmax);
if (inr == hdump) if (inr == hdump)
@ -290,27 +310,28 @@ log_eoi()
std_all(stdsize, stdrawflag); std_all(stdsize, stdrawflag);
} }
if (inr == stop) { if (inr == stop)
{
message("program stopped on request"); message("program stopped on request");
close_down(0); close_down(0);
} }
} }
/******** Service routines ********/ /******** Service routines ********/
PRIVATE char *getpar(var) PRIVATE char *getpar(char *var)
char *var;
{ {
/* Looks up the name in the argument list. /* Looks up the name in the argument list.
*/ */
register int count; register int count;
register int ln = strlen(var); register int ln = strlen(var);
for (count = 0; count < argcount; count++) { for (count = 0; count < argcount; count++)
{
register char *arg = arglist[count]; register char *arg = arglist[count];
if (strncmp(var, arg, ln) == 0 && arg[ln] == '=') { if (strncmp(var, arg, ln) == 0 && arg[ln] == '=')
{
return &arg[ln + 1]; return &arg[ln + 1];
} }
} }
@ -318,9 +339,10 @@ PRIVATE char *getpar(var)
return 0; return 0;
} }
PRIVATE long longpar(var, def) PRIVATE long longpar(
char *var; /* name of the variable */ char *var, /* name of the variable */
long def; /* default value */ long def /* default value */
)
{ {
register char *res = getpar(var); register char *res = getpar(var);

View file

@ -16,6 +16,19 @@ extern int logging; /* set if logging in progress */
#define LOG(a) { if (logging) do_log a; } #define LOG(a) { if (logging) do_log a; }
/* Initalize logging system. */
void init_log(void);
int logarg(char *str);
/* Open the log file. */
void open_log(int firsttime);
/* Close the log file. */
void close_log(void);
int check_log(char mark[]);
/* Log an entry into the logfile. */
void do_log(char *fmt, ...);
void log_eoi(void);
#else #else
#define LOG(a) #define LOG(a)

View file

@ -1,5 +1,5 @@
/* /** @file
Dedicated treatment of the sigtrp system call, MON 48. * Dedicated treatment of the sigtrp system call, MON 48.
*/ */
/* $Id$ */ /* $Id$ */
@ -10,6 +10,8 @@
#include "log.h" #include "log.h"
#include "warn.h" #include "warn.h"
#include "trap.h" #include "trap.h"
#include "m_sigtrp.h"
#include "io.h"
/*************************** SIGTRP ************************************* /*************************** SIGTRP *************************************
* The monitor call "sigtrp()" is handled by "do_sigtrp()". The first * * The monitor call "sigtrp()" is handled by "do_sigtrp()". The first *
@ -28,29 +30,37 @@
#endif #endif
PRIVATE int sig_map[NSIG + 1]; /* maps signals onto trap numbers */ PRIVATE int sig_map[NSIG + 1]; /* maps signals onto trap numbers */
PRIVATE void HndlIntSig(); /* handle signal to interpreter */ PRIVATE void HndlIntSig(int); /* handle signal to interpreter */
PRIVATE void HndlEmSig(); /* handle signal to user program */ PRIVATE void HndlEmSig(int); /* handle signal to user program */
init_signals() { void init_signals(void)
{
int sn; int sn;
for (sn = 0; sn < NSIG+1; sn++) { for (sn = 0; sn < NSIG + 1; sn++)
{
sig_map[sn] = -2; /* Default EM trap number */ sig_map[sn] = -2; /* Default EM trap number */
} }
for (sn = 0; sn < NSIG+1; sn++) { for (sn = 0; sn < NSIG + 1; sn++)
{
/* for all signals that would cause termination */ /* for all signals that would cause termination */
if (!UNIX_trap(sn)) { if (!UNIX_trap(sn))
{
#ifdef SIGCHLD #ifdef SIGCHLD
if (sn == SIGCHLD) continue; if (sn == SIGCHLD)
continue;
#endif #endif
#ifdef SIGIO #ifdef SIGIO
if (sn == SIGIO) continue; if (sn == SIGIO)
continue;
#endif #endif
#ifdef SIGWINCH #ifdef SIGWINCH
if (sn == SIGWINCH) continue; if (sn == SIGWINCH)
continue;
#endif #endif
if (signal(sn, SIG_IGN) != SIG_IGN) { if (signal(sn, SIG_IGN) != SIG_IGN)
{
/* we take our fate in our own hand */ /* we take our fate in our own hand */
signal(sn, HndlIntSig); signal(sn, HndlIntSig);
} }
@ -58,37 +68,45 @@ init_signals() {
} }
} }
int do_sigtrp(tn, sn) int do_sigtrp(
int tn; /* EM trap number */ int tn, /* EM trap number */
int sn; /* UNIX signal number */ int sn /* UNIX signal number */
)
{ {
register int old_tn; register int old_tn;
if (sn <= 0 || sn > NSIG) { if (sn <= 0 || sn > NSIG)
{
einval(WILLSN); einval(WILLSN);
return (-1); return (-1);
} }
if (UNIX_trap(sn)) { if (UNIX_trap(sn))
{
einval(WUNIXTR); einval(WUNIXTR);
return (-1); return (-1);
} }
old_tn = sig_map[sn]; old_tn = sig_map[sn];
sig_map[sn] = tn; sig_map[sn] = tn;
if (tn == -2) { /* reset default for signal sn */ if (tn == -2)
{ /* reset default for signal sn */
signal(sn, SIG_DFL); signal(sn, SIG_DFL);
} }
else if (tn == -3) { /* ignore signal sn */ else if (tn == -3)
{ /* ignore signal sn */
signal(sn, SIG_IGN); signal(sn, SIG_IGN);
} }
else if (tn >= 0 && tn <= 252) {/* legal tn */ else if (tn >= 0 && tn <= 252)
if ((int)signal(sn, HndlEmSig) == -1) { {/* legal tn */
if ((int) signal(sn, HndlEmSig) == -1)
{
sig_map[sn] = old_tn; sig_map[sn] = old_tn;
return (-1); return (-1);
} }
} }
else { else
{
/* illegal trap number */ /* illegal trap number */
einval(WILLTN); einval(WILLTN);
sig_map[sn] = old_tn; /* restore sig_map */ sig_map[sn] = old_tn; /* restore sig_map */
@ -97,32 +115,29 @@ int do_sigtrp(tn, sn)
return (old_tn); return (old_tn);
} }
trap_signal() /** Execute the trap belonging to the signal that came in during
{ * the last instruction
/* execute the trap belonging to the signal that came in during
the last instruction
*/ */
void trap_signal(void)
{
register int old_sig = signalled; register int old_sig = signalled;
signalled = 0; signalled = 0;
trap(sig_map[old_sig]); trap(sig_map[old_sig]);
} }
/* The handling functions for the UNIX signals */ PRIVATE void HndlIntSig(int sn)
PRIVATE void HndlIntSig(sn)
int sn;
{ {
/* The interpreter got the signal */ /* The interpreter got the signal */
signal(sn, SIG_IGN); /* peace and quiet for close_down() */ signal(sn, SIG_IGN); /* peace and quiet for close_down() */
LOG(("@t1 signal %d caught by interpreter", sn)); LOG(("@t1 signal %d caught by interpreter", sn));
message("interpreter received signal %d, which was not caught by the interpreted program", message(
"interpreter received signal %d, which was not caught by the interpreted program",
sn); sn);
close_down(1); close_down(1);
} }
PRIVATE void HndlEmSig(sn) PRIVATE void HndlEmSig(int sn)
int sn;
{ {
/* The EM machine got the signal */ /* The EM machine got the signal */
signal(sn, HndlIntSig); /* Revert to old situation */ signal(sn, HndlIntSig); /* Revert to old situation */

View file

@ -15,11 +15,13 @@
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "io.h"
#include "trap.h" #include "trap.h"
#include "warn.h" #include "warn.h"
#include "text.h" #include "text.h"
#include "read.h" #include "read.h"
#include "opcode.h" #include "opcode.h"
#include "m_sigtrp.h"
#include "rsb.h" #include "rsb.h"
char mess_file[64] = "int.mess"; /* name of message file */ char mess_file[64] = "int.mess"; /* name of message file */
@ -37,9 +39,13 @@ extern long inr; /* from log.c */
PRIVATE char *dflt_av[] = {"e.out", 0}; /* default arguments */ PRIVATE char *dflt_av[] = {"e.out", 0}; /* default arguments */
main(argc, argv) /* External definitions - too lazy to create a header file for each. */
int argc; extern void init(int , char **);
char *argv[]; extern void disassemble(void);
extern void tally(void);
extern void out_tally(void);
int main(int argc, char *argv[])
{ {
register int i; register int i;
register int nosetjmp = 1; register int nosetjmp = 1;

View file

@ -4,6 +4,7 @@
/* $Id$ */ /* $Id$ */
#include "stack.h"
/******** Memory address & location defines ********/ /******** Memory address & location defines ********/

View file

@ -123,13 +123,13 @@ PRIVATE check_buf();
PRIVATE int savestr(); PRIVATE int savestr();
PRIVATE int vec(); PRIVATE int vec();
moncall() void moncall(void)
{ {
int n; /* number actually read/written */ int n; /* number actually read/written */
int status; /* status for wait-call */ int status; /* status for wait-call */
int flag; /* various flag parameters */ int flag; /* various flag parameters */
int mode; /* various mode parameters */ int mode; /* various mode parameters */
int oldmask; /* for umask call */ mode_t oldmask; /* for umask call */
int whence; /* parameter for lseek */ int whence; /* parameter for lseek */
int address; /* address parameter typed int2 */ int address; /* address parameter typed int2 */
int owner; /* owner parameter typed int2 */ int owner; /* owner parameter typed int2 */
@ -987,7 +987,7 @@ moncall()
case 60: /* Umask */ case 60: /* Umask */
mode = pop_int2(); mode = pop_int2();
oldmask = umask(mode); oldmask = umask((mode_t)mode);
push_int(oldmask); push_int(oldmask);
LOG(("@m9 Umask: succeeded, mode = %d, oldmask = %d", LOG(("@m9 Umask: succeeded, mode = %d, oldmask = %d",
mode, oldmask)); mode, oldmask));

View file

@ -1,5 +1,5 @@
/* /** @file
Handling the proctable proctable management routines.
*/ */
/* $Id$ */ /* $Id$ */
@ -7,22 +7,27 @@
#include "logging.h" #include "logging.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "io.h"
#include "alloc.h" #include "alloc.h"
#include "proctab.h" #include "proctab.h"
/** Procedure table */
struct proc *proctab; struct proc *proctab;
PRIVATE long pr_cnt; PRIVATE long pr_cnt;
init_proctab() /** Allocates and initializes the procedure table. */
void init_proctab(void)
{ {
proctab = (struct proc *) proctab = (struct proc *)
Malloc(NProc * sizeof (struct proc), "proctable"); Malloc(NProc * sizeof (struct proc), "proctable");
pr_cnt = 0; pr_cnt = 0;
} }
add_proc(nloc, ep) /** Add a procedure to the procedure entry table.
size nloc; * "ep" is the pointer to the entry point of the
ptr ep; * procedure to add.
*/
void add_proc(size nloc, ptr ep)
{ {
register struct proc *pr = &proctab[pr_cnt++]; register struct proc *pr = &proctab[pr_cnt++];
register struct proc *p; register struct proc *p;
@ -55,7 +60,7 @@ add_proc(nloc, ep)
pr->pr_ff = ff; pr->pr_ff = ff;
} }
end_init_proctab() void end_init_proctab(void)
{ {
#ifdef LOGGING #ifdef LOGGING
register long p; register long p;

View file

@ -1,9 +1,13 @@
/* /*
Handling the proctable Handling the proctable
*/ */
#ifndef PROCTAB_H_
#define PROCTAB_H_
/* $Id$ */ /* $Id$ */
#include "global.h"
struct proc { struct proc {
size pr_nloc; size pr_nloc;
ptr pr_ep; ptr pr_ep;
@ -11,3 +15,9 @@ struct proc {
}; };
extern struct proc *proctab; extern struct proc *proctab;
void init_proctab(void);
void add_proc(size, ptr);
void end_init_proctab(void);
#endif /* PROCTAB_H_ */

View file

@ -1,18 +1,21 @@
/* /** @file
Reading the EM object file * Reading the EM object file
*/ */
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#include <local.h> /* for VERSION */ #include "local.h" /* for VERSION */
#include <em_spec.h> #include "em_spec.h"
#include <as_spec.h> /* for as_magic */ #include "as_spec.h" /* for as_magic */
#include "logging.h" #include "logging.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "io.h"
#include "data.h"
#include "proctab.h"
#include "warn.h" #include "warn.h"
#include "mem.h" #include "mem.h"
#include "shadow.h" #include "shadow.h"
@ -51,20 +54,20 @@ size SZDATA;
PRIVATE FILE *load_fp; /* Filepointer of load file */ PRIVATE FILE *load_fp; /* Filepointer of load file */
PRIVATE ptr rd_repeat(); PRIVATE ptr rd_repeat(ptr, size, ptr);
PRIVATE ptr rd_descr(); PRIVATE ptr rd_descr(int, size, ptr);
PRIVATE int rd_byte(); PRIVATE int rd_byte(void);
PRIVATE long rd_int(); PRIVATE long rd_int(size);
rd_open(fname) void rd_open(char *fname)
char *fname;
{ /* Open loadfile */ { /* Open loadfile */
if ((load_fp = fopen(fname, "r")) == NULL) { if ((load_fp = fopen(fname, "r")) == NULL)
{
fatal("Cannot open loadfile '%s'", fname); fatal("Cannot open loadfile '%s'", fname);
} }
} }
rd_header() void rd_header(void)
{ {
/* Part 1 */ /* Part 1 */
if (rd_int(2L) != as_magic) if (rd_int(2L) != as_magic)
@ -106,7 +109,8 @@ rd_header()
if (ENTRY < 0 || ENTRY >= NPROC) if (ENTRY < 0 || ENTRY >= NPROC)
fatal("Bad entry point"); fatal("Bad entry point");
NLINE = rd_int(psize); NLINE = rd_int(psize);
if (NLINE == 0) { if (NLINE == 0)
{
warning(WNLINEZR); warning(WNLINEZR);
NLINE = I_MAXS4; NLINE = I_MAXS4;
} }
@ -116,12 +120,12 @@ rd_header()
rd_int(psize); /* entry 8 is unused */ rd_int(psize); /* entry 8 is unused */
} }
rd_text() void rd_text(void)
{ {
fread(text, 1, (int) DB, load_fp); fread(text, 1, (int) DB, load_fp);
} }
rd_gda() void rd_gda(void)
{ {
register int type, prev_type; register int type, prev_type;
register ptr pos, prev_pos; /* prev_pos invalid if prev_type==0 */ register ptr pos, prev_pos; /* prev_pos invalid if prev_type==0 */
@ -129,26 +133,29 @@ rd_gda()
type = prev_type = 0; type = prev_type = 0;
pos = prev_pos = i2p(0); pos = prev_pos = i2p(0);
for (i = 1; i <= NDATA; i++) { for (i = 1; i <= NDATA; i++)
{
type = btol(rd_byte()); type = btol(rd_byte());
LOG((" r6 rd_gda(), i = %ld, pos = %u", i, pos)); LOG((" r6 rd_gda(), i = %ld, pos = %u", i, pos));
if (type == 0) { if (type == 0)
{
/* repetition descriptor */ /* repetition descriptor */
register size count = rd_int(psize); register size count = rd_int(psize);
LOG((" r6 rd_gda(), case 0: count = %lu", count)); LOG((" r6 rd_gda(), case 0: count = %lu", count));
if (prev_type == 0) { if (prev_type == 0)
{
fatal("Type 0 initialisation on type 0"); fatal("Type 0 initialisation on type 0");
} }
pos = rd_repeat(pos, count, prev_pos); pos = rd_repeat(pos, count, prev_pos);
prev_type = 0; prev_type = 0;
} }
else { else
{
/* filling descriptor */ /* filling descriptor */
register size count = btol(rd_byte()); register size count = btol(rd_byte());
LOG((" r6 rd_gda(), case %d: count = %lu", LOG((" r6 rd_gda(), case %d: count = %lu", type, count));
type, count));
prev_pos = pos; prev_pos = pos;
pos = rd_descr(type, count, prev_pos); pos = rd_descr(type, count, prev_pos);
prev_type = type; prev_type = type;
@ -160,12 +167,13 @@ rd_gda()
dt_prot(i2p(4), psize); dt_prot(i2p(4), psize);
} }
rd_proctab() void rd_proctab(void)
{ {
register long p; register long p;
init_proctab(); init_proctab();
for (p = 0; p < NPROC; p++) { for (p = 0; p < NPROC; p++)
{
register long nloc = rd_int(psize); register long nloc = rd_int(psize);
register ptr ep = i2p(rd_int(psize)); register ptr ep = i2p(rd_int(psize));
@ -174,7 +182,7 @@ rd_proctab()
end_init_proctab(); end_init_proctab();
} }
rd_close() void rd_close(void)
{ {
fclose(load_fp); fclose(load_fp);
load_fp = 0; load_fp = 0;
@ -199,17 +207,17 @@ rd_close()
* number is also stored in a double. * * number is also stored in a double. *
************************************************************************/ ************************************************************************/
PRIVATE ptr rd_repeat(pos, count, prev_pos) PRIVATE ptr rd_repeat(ptr pos, size count, ptr prev_pos)
ptr pos, prev_pos;
size count;
{ {
register size diff = pos - prev_pos; register size diff = pos - prev_pos;
register size j; register size j;
for (j = 0; j < count; j++) { for (j = 0; j < count; j++)
{
register long i; register long i;
for (i = 0; i < diff; i++) { for (i = 0; i < diff; i++)
{
data_loc(pos) = data_loc(pos - diff); data_loc(pos) = data_loc(pos - diff);
#ifdef LOGGING #ifdef LOGGING
/* copy shadow byte, including protection bit */ /* copy shadow byte, including protection bit */
@ -221,43 +229,46 @@ PRIVATE ptr rd_repeat(pos, count, prev_pos)
return pos; return pos;
} }
PRIVATE ptr rd_descr(type, count, pos) PRIVATE ptr rd_descr(int type, size count, ptr pos)
int type;
size count;
ptr pos;
{ {
register size j; register size j;
char fl_rep[128]; /* fp number representation */ char fl_rep[128]; /* fp number representation */
register int fl_cnt; register int fl_cnt;
switch (type) { switch (type)
{
case 1: /* m uninitialized words */ case 1: /* m uninitialized words */
j = count; j = count;
while (j--) { while (j--)
{
dt_stw(pos, 0L); dt_stw(pos, 0L);
pos += wsize; pos += wsize;
} }
break; break;
case 2: /* m initialized bytes */ case 2: /* m initialized bytes */
j = count; j = count;
while (j--) { while (j--)
{
dt_stn(pos++, btol(rd_byte()), 1L); dt_stn(pos++, btol(rd_byte()), 1L);
} }
break; break;
case 3: /* m initialized wordsize integers */ case 3: /* m initialized wordsize integers */
for (j = 0; j < count; j++) { for (j = 0; j < count; j++)
{
dt_stw(pos, rd_int(wsize)); dt_stw(pos, rd_int(wsize));
pos += wsize; pos += wsize;
} }
break; break;
case 4: /* m initialized data pointers */ case 4: /* m initialized data pointers */
for (j = 0; j < count; j++) { for (j = 0; j < count; j++)
{
dt_stdp(pos, i2p(rd_int(psize))); dt_stdp(pos, i2p(rd_int(psize)));
pos += psize; pos += psize;
} }
break; break;
case 5: /* m initialized instruction pointers */ case 5: /* m initialized instruction pointers */
for (j = 0; j < count; j++) { for (j = 0; j < count; j++)
{
dt_stip(pos, i2p(rd_int(psize))); dt_stip(pos, i2p(rd_int(psize)));
pos += psize; pos += psize;
} }
@ -274,11 +285,12 @@ PRIVATE ptr rd_descr(type, count, pos)
fatal("Bad floatsize during initialisation"); fatal("Bad floatsize during initialisation");
/* get fp representation */ /* get fp representation */
fl_cnt = 0; fl_cnt = 0;
while (fl_rep[fl_cnt] = rd_byte()) { while ( (fl_rep[fl_cnt] = rd_byte()) )
{
fl_cnt++; fl_cnt++;
if (fl_cnt >= sizeof (fl_rep)) { if (fl_cnt >= sizeof(fl_rep))
fatal("Initialized float longer than %d chars", {
sizeof (fl_rep)); fatal("Initialized float longer than %d chars", sizeof(fl_rep));
} }
} }
#ifndef NOFLOAT #ifndef NOFLOAT
@ -297,7 +309,7 @@ PRIVATE ptr rd_descr(type, count, pos)
return pos; return pos;
} }
PRIVATE int rd_byte() PRIVATE int rd_byte(void)
{ {
register int i; register int i;
@ -306,14 +318,14 @@ PRIVATE int rd_byte()
return (i); return (i);
} }
PRIVATE long rd_int(n) PRIVATE long rd_int(size n)
size n;
{ {
register long l; register long l;
register int i; register int i;
l = btol(rd_byte()); l = btol(rd_byte());
for (i = 1; i < n; i++) { for (i = 1; i < n; i++)
{
l |= (btol(rd_byte()) << (i * 8)); l |= (btol(rd_byte()) << (i * 8));
} }
return (l); return (l);

View file

@ -16,3 +16,30 @@ extern long NPROC; /* number of procedure descriptors */
extern long ENTRY; /* procedure identifier of start procedure */ extern long ENTRY; /* procedure identifier of start procedure */
extern long NLINE; /* the maximum source line number */ extern long NLINE; /* the maximum source line number */
extern size SZDATA; /* number of gda bytes after initialization */ extern size SZDATA; /* number of gda bytes after initialization */
/* Open e.out file with "fname". Raise a fatal error if
it cannot be opened. */
void rd_open(char *fname);
/* Read the header of the load file and populates
* the "FLAGS", "NTEXT", "NDATA", "NPROC", "ENTRY", "NLINE"
* and "SZDATA" variables. A fatail error is raised
* if there is an error reading the load file.
*/
void rd_header(void);
/* Read the text segment from the load file into the
* the address pointed to by the "text" variable.
*/
void rd_text(void);
/* Read and populate the data segment from the load file
* into the address pointed to by the "data" variable.
*/
void rd_gda(void);
/* Read the procedure table from the load file. */
void rd_proctab(void);
/* Close the load file. */
void rd_close(void);

View file

@ -11,6 +11,8 @@
#include "proctab.h" #include "proctab.h"
#include "linfil.h" #include "linfil.h"
#include "shadow.h" #include "shadow.h"
#include "segment.h"
#include "text.h"
#include "warn.h" #include "warn.h"
/* offsets to be added to a local base */ /* offsets to be added to a local base */
@ -22,7 +24,7 @@ int rsb_LIN;
int rsb_FIL; int rsb_FIL;
int rsbsize; int rsbsize;
init_rsb() void init_rsb(void)
{ {
rsb_rsbcode = 0; rsb_rsbcode = 0;
rsb_PI = wsize; rsb_PI = wsize;
@ -33,8 +35,7 @@ init_rsb()
rsbsize = rsb_FIL + psize; rsbsize = rsb_FIL + psize;
} }
pushrsb(rsbcode) void pushrsb(int rsbcode)
int rsbcode;
{ {
/* fill Return Status Block */ /* fill Return Status Block */
incSP((size)rsbsize); incSP((size)rsbsize);
@ -61,8 +62,7 @@ pushrsb(rsbcode)
} }
/*ARGSUSED*/ /*ARGSUSED*/
int poprsb(rtt) int poprsb(int rtt) /* set to 1 if working for RTT */
int rtt; /* set to 1 if working for RTT */
{ {
/* pops the RSB and returns the rsbcode, for further testing */ /* pops the RSB and returns the rsbcode, for further testing */
register int rsbcode; register int rsbcode;

View file

@ -29,3 +29,6 @@ extern int rsbsize;
#define is_LB(p) ((st_lds(p+rsb_rsbcode, wsize) & RSBMASK) == RSBCODE) #define is_LB(p) ((st_lds(p+rsb_rsbcode, wsize) & RSBMASK) == RSBCODE)
void init_rsb(void);
void pushrsb(int rsbcode);
int poprsb(int rtt);

View file

@ -11,6 +11,7 @@
/* $Id$ */ /* $Id$ */
#include "segcheck.h" #include "segcheck.h"
#include "segment.h"
#include "global.h" #include "global.h"
#include "mem.h" #include "mem.h"
#include "alloc.h" #include "alloc.h"
@ -26,17 +27,16 @@ PRIVATE ptr *AB_list;
PRIVATE size frame_limit; PRIVATE size frame_limit;
PRIVATE size curr_frame; PRIVATE size curr_frame;
init_AB_list() { /** Allocate space for AB_list & initialize frame variables */
/* Allocate space for AB_list & initialize frame variables */ void init_AB_list(void)
{
frame_limit = ABLISTSIZE; frame_limit = ABLISTSIZE;
curr_frame = 0L; curr_frame = 0L;
AB_list = (ptr *) Malloc(frame_limit * sizeof (ptr), "AB_list"); AB_list = (ptr *) Malloc(frame_limit * sizeof (ptr), "AB_list");
AB_list[curr_frame] = AB; AB_list[curr_frame] = AB;
} }
push_frame(p) void push_frame(ptr p)
ptr p;
{ {
if (++curr_frame == frame_limit) { if (++curr_frame == frame_limit) {
frame_limit = allocfrac(frame_limit); frame_limit = allocfrac(frame_limit);
@ -46,14 +46,14 @@ push_frame(p)
AB_list[curr_frame] = p; AB_list[curr_frame] = p;
} }
pop_frames() { void pop_frames(void)
{
while (AB_list[curr_frame] < AB) { while (AB_list[curr_frame] < AB) {
curr_frame--; curr_frame--;
} }
} }
int ptr2seg(p) int ptr2seg(ptr p)
ptr p;
{ {
register int s; register int s;
@ -74,11 +74,11 @@ int ptr2seg(p)
#else /* SEGCHECK */ #else /* SEGCHECK */
init_AB_list() {} void init_AB_list(void) {}
push_frame() {} void push_frame(ptr) {}
pop_frames() {} void pop_frames(void) {}
#endif /* SEGCHECK */ #endif /* SEGCHECK */

View file

@ -1,12 +1,12 @@
/* /** \file
Stack manipulation Stack manipulation routines.
*/ */
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#include <em_abs.h> #include "em_abs.h"
#include "logging.h" #include "logging.h"
#include "nofloat.h" #include "nofloat.h"
#include "global.h" #include "global.h"
@ -17,20 +17,26 @@
#include "memdirect.h" #include "memdirect.h"
#include "mem.h" #include "mem.h"
#include "shadow.h" #include "shadow.h"
#include "stack.h"
#include "data.h"
#include "rsb.h" #include "rsb.h"
#define STACKSIZE 1000L /* initial stack size */ /** initial stack size in bytes */
#define STACKSIZE 1000L
extern size maxstack; /* from main.c */ extern size maxstack; /* from main.c */
#ifdef LOGGING #ifdef LOGGING
char *stack_sh; /* stadowbytes */ char *stack_sh; /* stadowbytes */
char *stackML_sh; /* speed up access of stadowbytes */ char *stackML_sh; /* speed up access of stadowbytes */
PRIVATE void st_clear_area(ptr, ptr);
#endif /* LOGGING */ #endif /* LOGGING */
PRIVATE warn_stbits(); PRIVATE void warn_stbits(ptr, size);
init_stack() { /** Initialize and allocate the operand stack space "stack". */
void init_stack(void)
{
ML = max_addr; /* set Memory Limit */ ML = max_addr; /* set Memory Limit */
SP = ML + 1; /* initialize Stack Pointer */ SP = ML + 1; /* initialize Stack Pointer */
SL = ML + 1; /* initialize Stack Limit */ SL = ML + 1; /* initialize Stack Limit */
@ -47,7 +53,6 @@ init_stack() {
#endif /* LOGGING */ #endif /* LOGGING */
} }
/************************************************************************ /************************************************************************
* EM-register division. * * EM-register division. *
************************************************************************ ************************************************************************
@ -59,30 +64,39 @@ init_stack() {
* * * *
************************************************************************/ ************************************************************************/
newSP(ap) /** Set the value of the stack pointer "SP" to the value "ap".
ptr ap; * Full validation of the new value is done beforehand.
*/
void newSP(ptr ap)
{ {
register ptr p = ap; register ptr p = ap;
LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP)); LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP));
if (LB < p) { if (LB < p)
{
wtrap(WSPGTLB, ESTACK); wtrap(WSPGTLB, ESTACK);
} }
if (!is_wordaligned(p)) { if (!is_wordaligned(p))
{
wtrap(WSPODD, ESTACK); wtrap(WSPODD, ESTACK);
} }
if (p < SP) { if (p < SP)
if (p < HP) { {
if (p < HP)
{
wtrap(WSPINHEAP, ESTACK); wtrap(WSPINHEAP, ESTACK);
} }
if (maxstack) { if (maxstack)
{
/* more than allowed on command line */ /* more than allowed on command line */
if (ML - p > maxstack) { if (ML - p > maxstack)
{
warning(WESTACK); warning(WESTACK);
trap(ESTACK); trap(ESTACK);
} }
} }
if (p < SL) { if (p < SL)
{
/* extend stack space */ /* extend stack space */
register size stacksize = ML + 1 - p; register size stacksize = ML + 1 - p;
@ -104,23 +118,25 @@ newSP(ap)
SP = p; SP = p;
} }
incSP(n) /** Increment stack pointer "SP" by "n" bytes.
#ifdef LOGGING * Full validation on stack alignment and address is done.
register */
#endif void incSP(size n)
size n;
{ {
register ptr p = SP - n; register ptr p = SP - n;
if (p < HP || maxstack || p < SL) newSP(p); if (p < HP || maxstack || p < SL)
else { newSP(p);
else
{
LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP)); LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP));
#ifdef LOGGING #ifdef LOGGING
/* inline version of st_clear_area. /* inline version of st_clear_area.
*/ */
SP = p; SP = p;
{ {
while (n--) { while (n--)
{
st_undef(p); st_undef(p);
p++; p++;
} }
@ -129,35 +145,40 @@ incSP(n)
} }
} }
decSP(n) /** Decrement stack pointer "SP" by "n" bytes.
size n; * Full validation on stack alignment and address is done.
*/
void decSP(size n)
{ {
register ptr p = SP + n; register ptr p = SP + n;
if (LB < p) newSP(p); if (LB < p)
else { newSP(p);
else
{
LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP)); LOG(("@s6 newSP(%lu), ML = %lu, SP = %lu", p, ML, SP));
SP = p; SP = p;
} }
} }
newLB(p) void newLB(ptr p)
ptr p; {
if (!in_stack(p))
{ {
if (!in_stack(p)) {
wtrap(WLBOUT, ESTACK); wtrap(WLBOUT, ESTACK);
} }
if (!is_wordaligned(p)) { if (!is_wordaligned(p))
{
wtrap(WLBODD, ESTACK); wtrap(WLBODD, ESTACK);
} }
if (!is_LB(p)) { if (!is_LB(p))
{
wtrap(WLBRSB, ESTACK); wtrap(WLBRSB, ESTACK);
} }
LB = p; LB = p;
AB = LB + rsbsize; AB = LB + rsbsize;
} }
/************************************************************************ /************************************************************************
* Stack store division. * * Stack store division. *
************************************************************************ ************************************************************************
@ -170,9 +191,10 @@ newLB(p)
* * * *
************************************************************************/ ************************************************************************/
st_stdp(addr, ap) /** Store data pointer "ap" in stack at address "addr".
register ptr addr; * Full validation is done on "addr" before storing into it.
ptr ap; */
void st_stdp(register ptr addr, ptr ap)
{ {
register int i; register int i;
register long p = (long) ap; register long p = (long) ap;
@ -180,7 +202,8 @@ st_stdp(addr, ap)
LOG(("@s6 st_stdp(%lu, %lu)", addr, p)); LOG(("@s6 st_stdp(%lu, %lu)", addr, p));
ch_in_stack(addr, psize); ch_in_stack(addr, psize);
ch_wordaligned(addr); ch_wordaligned(addr);
for (i = (int) psize; i > 0; i--, addr++) { for (i = (int) psize; i > 0; i--, addr++)
{
ch_st_prot(addr); ch_st_prot(addr);
stack_loc(addr) = (char) (p); stack_loc(addr) = (char) (p);
st_dp(addr); st_dp(addr);
@ -189,9 +212,10 @@ st_stdp(addr, ap)
} }
st_stip(addr, ap) /** Store code pointer "ap" in stack address "addr".
register ptr addr; * Full validation is done on "addr" before storing into it.
ptr ap; */
void st_stip(register ptr addr, ptr ap)
{ {
register int i; register int i;
register long p = (long) ap; register long p = (long) ap;
@ -199,7 +223,8 @@ st_stip(addr, ap)
LOG(("@s6 st_stip(%lu, %lu)", addr, p)); LOG(("@s6 st_stip(%lu, %lu)", addr, p));
ch_in_stack(addr, psize); ch_in_stack(addr, psize);
ch_wordaligned(addr); ch_wordaligned(addr);
for (i = (int) psize; i > 0; i--, addr++) { for (i = (int) psize; i > 0; i--, addr++)
{
ch_st_prot(addr); ch_st_prot(addr);
stack_loc(addr) = (char) (p); stack_loc(addr) = (char) (p);
st_ip(addr); st_ip(addr);
@ -207,10 +232,10 @@ st_stip(addr, ap)
} }
} }
st_stn(addr, al, n) /** Store an integer value "al" of "n" bytes in size in stack at address "addr".
register ptr addr; * Full validation is done on "addr" before storing into it.
long al; */
size n; void st_stn(register ptr addr, long al, size n)
{ {
register int i; register int i;
register long l = al; register long l = al;
@ -224,7 +249,8 @@ st_stn(addr, al, n)
ch_aligned(addr, n); ch_aligned(addr, n);
/* store the bytes */ /* store the bytes */
for (i = (int) n; i > 0; i--, addr++) { for (i = (int) n; i > 0; i--, addr++)
{
ch_st_prot(addr); ch_st_prot(addr);
stack_loc(addr) = (char) l; stack_loc(addr) = (char) l;
#ifdef LOGGING #ifdef LOGGING
@ -234,9 +260,10 @@ st_stn(addr, al, n)
} }
} }
st_stw(addr, al) /** Store an integer value "al" of word size bytes in stack at address "addr".
register ptr addr; * Full validation is done on "addr" before storing into it.
long al; */
void st_stw(register ptr addr, long al)
{ {
register int i; register int i;
register long l = al; register long l = al;
@ -250,7 +277,8 @@ st_stw(addr, al)
ch_wordaligned(addr); ch_wordaligned(addr);
/* store the bytes */ /* store the bytes */
for (i = (int) wsize; i > 0; i--, addr++) { for (i = (int) wsize; i > 0; i--, addr++)
{
ch_st_prot(addr); ch_st_prot(addr);
stack_loc(addr) = (char) l; stack_loc(addr) = (char) l;
#ifdef LOGGING #ifdef LOGGING
@ -261,10 +289,10 @@ st_stw(addr, al)
} }
#ifndef NOFLOAT #ifndef NOFLOAT
st_stf(addr, f, n) /** Store a real value "f" of "n" bytes in size in stack at address "addr".
register ptr addr; * Full validation is done on "addr" before storing into it.
double f; */
size n; void st_stf(register ptr addr, double f, size n)
{ {
register char *cp = (char *) &f; register char *cp = (char *) &f;
float fl; float fl;
@ -273,11 +301,13 @@ st_stf(addr, f, n)
LOG(("@s6 st_stf(%lu, %g, %lu)", addr, f, n)); LOG(("@s6 st_stf(%lu, %g, %lu)", addr, f, n));
ch_in_stack(addr, n); ch_in_stack(addr, n);
ch_wordaligned(addr); ch_wordaligned(addr);
if ((int) n == 4) { if ((int) n == 4)
{
fl = f; fl = f;
cp = (char *) &fl; cp = (char *) &fl;
} }
for (i = (int) n; i > 0; i--, addr++) { for (i = (int) n; i > 0; i--, addr++)
{
ch_st_prot(addr); ch_st_prot(addr);
stack_loc(addr) = *(cp++); stack_loc(addr) = *(cp++);
st_fl(addr); st_fl(addr);
@ -299,8 +329,10 @@ st_stf(addr, f, n)
* * * *
************************************************************************/ ************************************************************************/
ptr st_lddp(addr) /** Loads and returns a data pointer stored on the stack
register ptr addr; * at address "addr".
*/
ptr st_lddp(register ptr addr)
{ {
register ptr p; register ptr p;
@ -309,7 +341,8 @@ ptr st_lddp(addr)
ch_in_stack(addr, psize); ch_in_stack(addr, psize);
ch_wordaligned(addr); ch_wordaligned(addr);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, psize, SH_DATAP)) { if (!is_st_set(addr, psize, SH_DATAP))
{
warning(WLDPEXP); warning(WLDPEXP);
warn_stbits(addr, psize); warn_stbits(addr, psize);
} }
@ -320,8 +353,10 @@ ptr st_lddp(addr)
return (p); return (p);
} }
ptr st_ldip(addr) /** Loads and returns a core pointer stored on the stack
register ptr addr; * at address "addr".
*/
ptr st_ldip(register ptr addr)
{ {
register ptr p; register ptr p;
@ -330,7 +365,8 @@ ptr st_ldip(addr)
ch_in_stack(addr, psize); ch_in_stack(addr, psize);
ch_wordaligned(addr); ch_wordaligned(addr);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, psize, SH_INSP)) { if (!is_st_set(addr, psize, SH_INSP))
{
warning(WLIPEXP); warning(WLIPEXP);
warn_stbits(addr, psize); warn_stbits(addr, psize);
} }
@ -341,9 +377,11 @@ ptr st_ldip(addr)
return (p); return (p);
} }
unsigned long st_ldu(addr, n) /** Loads and returns an unsigned integer value of
register ptr addr; * "n" bytes in size stored in the stack at address
size n; * "addr".
*/
unsigned long st_ldu(register ptr addr, size n)
{ {
register int i; register int i;
register unsigned long u = 0; register unsigned long u = 0;
@ -353,22 +391,27 @@ unsigned long st_ldu(addr, n)
ch_in_stack(addr, n); ch_in_stack(addr, n);
ch_aligned(addr, n); ch_aligned(addr, n);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, n, SH_INT)) { if (!is_st_set(addr, n, SH_INT))
{
warning(n == 1 ? WLCEXP : WLIEXP); warning(n == 1 ? WLCEXP : WLIEXP);
warn_stbits(addr, n); warn_stbits(addr, n);
} }
#endif /* LOGGING */ #endif /* LOGGING */
addr += n - 1; addr += n - 1;
for (i = (int) n-1; i >= 0; i--, addr--) { for (i = (int) n - 1; i >= 0; i--, addr--)
{
u = (u << 8) | (btou(stack_loc(addr))); u = (u << 8) | (btou(stack_loc(addr)));
} }
LOG(("@s6 st_ldu() returns %ld", u)); LOG(("@s6 st_ldu() returns %ld", u));
return (u); return (u);
} }
unsigned long st_lduw(addr) /** Loads and returns an unsigned integer value of
register ptr addr; * word size bytes stored in the stack at address
* "addr".
*/
unsigned long st_lduw(register ptr addr)
{ {
register int i; register int i;
register unsigned long u = 0; register unsigned long u = 0;
@ -378,23 +421,27 @@ unsigned long st_lduw(addr)
ch_w_in_stack(addr); ch_w_in_stack(addr);
ch_wordaligned(addr); ch_wordaligned(addr);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, wsize, SH_INT)) { if (!is_st_set(addr, wsize, SH_INT))
{
warning(WLIEXP); warning(WLIEXP);
warn_stbits(addr, wsize); warn_stbits(addr, wsize);
} }
#endif /* LOGGING */ #endif /* LOGGING */
addr += wsize - 1; addr += wsize - 1;
for (i = (int) wsize-1; i >= 0; i--, addr--) { for (i = (int) wsize - 1; i >= 0; i--, addr--)
{
u = (u << 8) | (btou(stack_loc(addr))); u = (u << 8) | (btou(stack_loc(addr)));
} }
LOG(("@s6 st_lduw() returns %ld", u)); LOG(("@s6 st_lduw() returns %ld", u));
return (u); return (u);
} }
long st_lds(addr, n) /** Loads and returns a signed integer value of
register ptr addr; * "n" bytes in size stored in the stack at address
size n; * "addr".
*/
long st_lds(register ptr addr, size n)
{ {
register int i; register int i;
register long l; register long l;
@ -404,7 +451,8 @@ long st_lds(addr, n)
ch_in_stack(addr, n); ch_in_stack(addr, n);
ch_aligned(addr, n); ch_aligned(addr, n);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, n, SH_INT)) { if (!is_st_set(addr, n, SH_INT))
{
warning(n == 1 ? WLCEXP : WLIEXP); warning(n == 1 ? WLCEXP : WLIEXP);
warn_stbits(addr, n); warn_stbits(addr, n);
} }
@ -412,15 +460,19 @@ long st_lds(addr, n)
addr += n - 2; addr += n - 2;
l = btos(stack_loc(addr + 1)); l = btos(stack_loc(addr + 1));
for (i = n - 2; i >= 0; i--, addr--) { for (i = n - 2; i >= 0; i--, addr--)
{
l = (l << 8) | btol(stack_loc(addr)); l = (l << 8) | btol(stack_loc(addr));
} }
LOG(("@s6 st_lds() returns %ld", l)); LOG(("@s6 st_lds() returns %ld", l));
return (l); return (l);
} }
long st_ldsw(addr) /** Loads and returns a signed integer value of
register ptr addr; * word size bytes stored in the stack at address
* "addr".
*/
long st_ldsw(register ptr addr)
{ {
register int i; register int i;
register long l; register long l;
@ -430,7 +482,8 @@ long st_ldsw(addr)
ch_w_in_stack(addr); ch_w_in_stack(addr);
ch_wordaligned(addr); ch_wordaligned(addr);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, wsize, SH_INT)) { if (!is_st_set(addr, wsize, SH_INT))
{
warning(WLIEXP); warning(WLIEXP);
warn_stbits(addr, wsize); warn_stbits(addr, wsize);
} }
@ -438,7 +491,8 @@ long st_ldsw(addr)
addr += wsize - 2; addr += wsize - 2;
l = btos(stack_loc(addr+1)); l = btos(stack_loc(addr+1));
for (i = wsize - 2; i >= 0; i--, addr--) { for (i = wsize - 2; i >= 0; i--, addr--)
{
l = (l << 8) | btol(stack_loc(addr)); l = (l << 8) | btol(stack_loc(addr));
} }
LOG(("@s6 st_ldsw() returns %ld", l)); LOG(("@s6 st_ldsw() returns %ld", l));
@ -446,9 +500,10 @@ long st_ldsw(addr)
} }
#ifndef NOFLOAT #ifndef NOFLOAT
double st_ldf(addr, n) /** Loads and returns a real value of "n" bytes
register ptr addr; * stored in the stack at address "addr".
size n; */
double st_ldf(register ptr addr, size n)
{ {
double f; double f;
float fl; float fl;
@ -457,25 +512,30 @@ double st_ldf(addr, n)
LOG(("@s6 st_ldf(%lu, %lu)", addr, n)); LOG(("@s6 st_ldf(%lu, %lu)", addr, n));
if ((int)n == 4) { if ((int) n == 4)
{
cp = (char *) &fl; cp = (char *) &fl;
} }
else { else
{
cp = (char *) &f; cp = (char *) &f;
} }
ch_in_stack(addr, n); ch_in_stack(addr, n);
ch_wordaligned(addr); ch_wordaligned(addr);
#ifdef LOGGING #ifdef LOGGING
if (!is_st_set(addr, n, SH_FLOAT)) { if (!is_st_set(addr, n, SH_FLOAT))
{
warning(WLFEXP); warning(WLFEXP);
warn_stbits(addr, n); warn_stbits(addr, n);
} }
#endif /* LOGGING */ #endif /* LOGGING */
for (i = (int) n; i > 0; i--, addr++) { for (i = (int) n; i > 0; i--, addr++)
{
*(cp++) = stack_loc(addr); *(cp++) = stack_loc(addr);
} }
if ((int)n == 4) { if ((int) n == 4)
{
f = fl; f = fl;
} }
return (f); return (f);
@ -499,9 +559,11 @@ double st_ldf(addr, n)
* * * *
************************************************************************/ ************************************************************************/
st_mvs(s2, s1, n) /* s1 -> s2 */ /** Moves "n" bytes from stack address "s1" to
register ptr s2, s1; * stack address "s2".
size n; */
void st_mvs(register ptr s2, register ptr s1, size n)
/* s1 -> s2 */
{ {
register int i; register int i;
@ -510,7 +572,8 @@ st_mvs(s2, s1, n) /* s1 -> s2 */
ch_in_stack(s2, n); ch_in_stack(s2, n);
ch_wordaligned(s2); ch_wordaligned(s2);
for (i = (int) n; i > 0; i--, s1++, s2++) { for (i = (int) n; i > 0; i--, s1++, s2++)
{
ch_st_prot(s2); ch_st_prot(s2);
ch_st_prot(s1); ch_st_prot(s1);
stack_loc(s2) = stack_loc(s1); stack_loc(s2) = stack_loc(s1);
@ -520,9 +583,11 @@ st_mvs(s2, s1, n) /* s1 -> s2 */
} }
} }
st_mvd(s, d, n) /* d -> s */ /** Move "n" bytes from data pointer "d" to
register ptr s, d; * stack address "s".
size n; */
void st_mvd(ptr s, ptr d, size n)
/* d -> s */
{ {
register int i; register int i;
@ -531,7 +596,8 @@ st_mvd(s, d, n) /* d -> s */
ch_in_stack(s, n); ch_in_stack(s, n);
ch_wordaligned(s); ch_wordaligned(s);
for (i = (int) n; i > 0; i--, s++, d++) { for (i = (int) n; i > 0; i--, s++, d++)
{
ch_st_prot(s); ch_st_prot(s);
stack_loc(s) = data_loc(d); stack_loc(s) = data_loc(d);
#ifdef LOGGING #ifdef LOGGING
@ -558,7 +624,8 @@ st_mvd(s, d, n) /* d -> s */
* * * *
************************************************************************/ ************************************************************************/
ptr dppop() /** Pop and return as a data pointer from the stack. */
ptr dppop(void)
{ {
register ptr p; register ptr p;
@ -568,8 +635,8 @@ ptr dppop()
return (p); return (p);
} }
unsigned long upop(n) /** Pop and return as an unsigned integer "n" bytes from the stack. */
size n; unsigned long upop(size n)
{ {
register unsigned long l; register unsigned long l;
@ -579,7 +646,8 @@ unsigned long upop(n)
return (l); return (l);
} }
unsigned long uwpop() /** Pop and return a word size unsigned integer from the stack. */
unsigned long uwpop(void)
{ {
register unsigned long l; register unsigned long l;
@ -589,8 +657,8 @@ unsigned long uwpop()
return (l); return (l);
} }
long spop(n) /** Pop and return as an integer "n" bytes from the stack. */
size n; long spop(size n)
{ {
register long l; register long l;
@ -600,7 +668,8 @@ long spop(n)
return (l); return (l);
} }
long swpop() /** Pop and return a word size signed integer from the stack. */
long swpop(void)
{ {
register long l; register long l;
@ -610,47 +679,53 @@ long swpop()
return (l); return (l);
} }
pop_dt(d, n) /** Pop "n" bytes from the stack and store them at data pointer
ptr d; * address "d".
size n; */
void pop_dt(ptr d, size n)
{ {
if (n < wsize) if (n < wsize)
dt_stn(d, (long) upop(n), n); dt_stn(d, (long) upop(n), n);
else { else
{
dt_mvs(d, SP, n); dt_mvs(d, SP, n);
decSP(n); decSP(n);
} }
} }
popw_dt(d) /** Pop word size bytes from the stack and store them at data pointer
ptr d; * address "d".
*/
void popw_dt(ptr d)
{ {
dt_mvs(d, SP, wsize); dt_mvs(d, SP, wsize);
decSP(wsize); decSP(wsize);
} }
pop_st(s, n) /** Pop "n" bytes from the stack and store them at stack address "s". */
ptr s; void pop_st(ptr s, size n)
size n;
{ {
if (n < wsize) if (n < wsize)
st_stn(s, (long) upop(n), n); st_stn(s, (long) upop(n), n);
else { else
{
st_mvs(s, SP, n); st_mvs(s, SP, n);
decSP(n); decSP(n);
} }
} }
popw_st(s) /** Pop word size bytes from the stack and store them at stack
ptr s; * address "s".
*/
void popw_st(ptr s)
{ {
st_mvs(s, SP, wsize); st_mvs(s, SP, wsize);
decSP(wsize); decSP(wsize);
} }
#ifndef NOFLOAT #ifndef NOFLOAT
double fpop(n) /** Pop a real value of "n" bytes from the stack. */
size n; double fpop(size n)
{ {
double d; double d;
@ -660,7 +735,8 @@ double fpop(n)
} }
#endif /* NOFLOAT */ #endif /* NOFLOAT */
long wpop() /** Pop a word size value, independently of its type. */
long wpop(void)
{ {
register long l; register long l;
@ -684,80 +760,92 @@ long wpop()
* * * *
************************************************************************/ ************************************************************************/
dppush(p) /** Push a data pointer "p" unto the stack. */
ptr p; void dppush(ptr p)
{ {
incSP(psize); incSP(psize);
st_stdp(SP, p); st_stdp(SP, p);
} }
wpush(l) /** Push a word size integer "l" unto the stack. */
long l; void wpush(long l)
{ {
incSP(wsize); incSP(wsize);
st_stw(SP, l); st_stw(SP, l);
} }
npush(l, n) /** Push "n" bytes from value "l" unto the stack. */
register long l; void npush(register long l, register size n)
register size n; {
if (n <= wsize)
{ {
if (n <= wsize) {
incSP(wsize); incSP(wsize);
if (n == 1) l &= MASK1; if (n == 1)
else if (n == 2) l &= MASK2; l &= MASK1;
else if (n == 2)
l &= MASK2;
st_stw(SP, l); st_stw(SP, l);
} }
else { else
{
incSP(n); incSP(n);
st_stn(SP, l, n); st_stn(SP, l, n);
} }
} }
push_dt(d, n) /** Push "n" bytes of data pointed to by the
ptr d; * data pointer "d" unto the stack.
size n; */
void push_dt(ptr d, size n)
{
if (n < wsize)
{ {
if (n < wsize) {
npush((long) dt_ldu(d, n), n); npush((long) dt_ldu(d, n), n);
} }
else { else
{
incSP(n); incSP(n);
st_mvd(SP, d, n); st_mvd(SP, d, n);
} }
} }
pushw_dt(d) /** Push word size bytes of data pointed to by
ptr d; * the data pointer "d" unto the stack.
*/
void pushw_dt(ptr d)
{ {
incSP(wsize); incSP(wsize);
st_mvd(SP, d, wsize); st_mvd(SP, d, wsize);
} }
push_st(s, n) /** Push "n" bytes of data pointed to by the
ptr s; * stack pointer "s" unto the stack.
size n; */
void push_st(ptr s, size n)
{
if (n < wsize)
{ {
if (n < wsize) {
npush((long) st_ldu(s, n), n); npush((long) st_ldu(s, n), n);
} }
else { else
{
incSP(n); incSP(n);
st_mvs(SP, s, n); st_mvs(SP, s, n);
} }
} }
pushw_st(s) /** Push word size bytes of data pointed to by
ptr s; * the stack pointer "s" unto the stack.
*/
void pushw_st(ptr s)
{ {
incSP(wsize); incSP(wsize);
st_mvs(SP, s, wsize); st_mvs(SP, s, wsize);
} }
#ifndef NOFLOAT #ifndef NOFLOAT
fpush(f, n) /** Push a real value of "n" bytes unto the stack. */
double f; void fpush(double f, size n)
size n;
{ {
incSP(n); incSP(n);
st_stf(SP, f, n); st_stf(SP, f, n);
@ -766,20 +854,20 @@ fpush(f, n)
#ifdef LOGGING #ifdef LOGGING
PRIVATE warn_stbits(addr, n) PRIVATE void warn_stbits(ptr addr, size n)
register ptr addr;
register size n;
{ {
register int or_bits = 0; register int or_bits = 0;
register int and_bits = 0xff; register int and_bits = 0xff;
while (n--) { while (n--)
{
or_bits |= st_sh(addr); or_bits |= st_sh(addr);
and_bits &= st_sh(addr); and_bits &= st_sh(addr);
addr++; addr++;
} }
if (or_bits != and_bits) { if (or_bits != and_bits)
{
/* no use trying to diagnose */ /* no use trying to diagnose */
warningcont(WWASMISC); warningcont(WWASMISC);
return; return;
@ -796,5 +884,16 @@ PRIVATE warn_stbits(addr, n)
warningcont(WWASINSP); warningcont(WWASINSP);
} }
PRIVATE void st_clear_area(ptr from, ptr to)
{
/* includes both *from and *to (since ML+1 is unexpressible) */
register ptr a;
for (a = from; a >= to; a--) {
st_undef(a);
}
}
#endif /* LOGGING */ #endif /* LOGGING */

View file

@ -11,8 +11,7 @@
#include "trap.h" #include "trap.h"
#include "warn.h" #include "warn.h"
do_instr(opcode) void do_instr(unsigned int opcode)
unsigned int opcode;
{ {
switch (opcode) { switch (opcode) {
#include "DoCases" /* for the muscle */ #include "DoCases" /* for the muscle */

View file

@ -10,12 +10,14 @@
#include "linfil.h" #include "linfil.h"
#include "alloc.h" #include "alloc.h"
struct line_tally { /* one for each line */ struct line_tally
{ /* one for each line */
long lt_cnt; /* counts entrances */ long lt_cnt; /* counts entrances */
long lt_instr; /* counts instructions */ long lt_instr; /* counts instructions */
}; };
struct file_tally { /* one for each file */ struct file_tally
{ /* one for each file */
struct file_tally *next; struct file_tally *next;
ptr ft_fil; /* file name */ ptr ft_fil; /* file name */
long ft_limit; /* size of line array */ long ft_limit; /* size of line array */
@ -27,21 +29,27 @@ PRIVATE struct file_tally *file; /* present file */
PRIVATE long lastLIN; PRIVATE long lastLIN;
PRIVATE tally_newFIL(); PRIVATE FILE *tally_fp;
PRIVATE enlarge();
tally() /* Forward declarations. */
PRIVATE void tally_newFIL(ptr);
PRIVATE void enlarge(struct file_tally *, long);
void tally(void)
{ {
if (!FIL) if (!FIL)
return; return;
if (!file || FIL != file->ft_fil) { if (!file || FIL != file->ft_fil)
{
tally_newFIL(FIL); tally_newFIL(FIL);
file->ft_fil = FIL; file->ft_fil = FIL;
lastLIN = -1; lastLIN = -1;
} }
if (LIN != lastLIN) { if (LIN != lastLIN)
if (LIN >= file->ft_limit) { {
if (LIN >= file->ft_limit)
{
enlarge(file, LIN); enlarge(file, LIN);
} }
file->ft_line[LIN].lt_cnt++; file->ft_line[LIN].lt_cnt++;
@ -50,28 +58,28 @@ tally()
file->ft_line[LIN].lt_instr++; file->ft_line[LIN].lt_instr++;
} }
PRIVATE tally_newFIL(f) PRIVATE void tally_newFIL(ptr f)
ptr f;
{ {
struct file_tally **hook = &first_tally; struct file_tally **hook = &first_tally;
while (*hook) { while (*hook)
{
if ((*hook)->ft_fil == f) if ((*hook)->ft_fil == f)
break; break;
hook = &(*hook)->next; hook = &(*hook)->next;
} }
if (!*hook) { if (!*hook)
{
/* first time we see this file */ /* first time we see this file */
/* construct a new entry */ /* construct a new entry */
struct file_tally *nt = (struct file_tally *) struct file_tally *nt = (struct file_tally *) Malloc(
Malloc((size) sizeof (struct file_tally), "file_tally"); (size) sizeof(struct file_tally), "file_tally");
nt->next = (struct file_tally *) 0; nt->next = (struct file_tally *) 0;
nt->ft_fil = f; nt->ft_fil = f;
nt->ft_limit = 1; /* provisional length */ nt->ft_limit = 1; /* provisional length */
nt->ft_line = (struct line_tally *) nt->ft_line = (struct line_tally *) Malloc(
Malloc((size) sizeof (struct line_tally), (size) sizeof(struct line_tally), "struct line_tally");
"struct line_tally");
nt->ft_line[0].lt_cnt = 0; nt->ft_line[0].lt_cnt = 0;
nt->ft_line[0].lt_instr = 0; nt->ft_line[0].lt_instr = 0;
@ -81,28 +89,25 @@ PRIVATE tally_newFIL(f)
file = *hook; file = *hook;
} }
PRIVATE enlarge(ft, l) PRIVATE void enlarge(struct file_tally *ft, long l)
struct file_tally *ft;
long l;
{ {
long limit = allocfrac(l < 100 ? 100 : l); long limit = allocfrac(l < 100 ? 100 : l);
if (limit <= ft->ft_limit) if (limit <= ft->ft_limit)
return; return;
ft->ft_line = (struct line_tally *) ft->ft_line = (struct line_tally *) Realloc((char *) ft->ft_line,
Realloc((char *)ft->ft_line, (size) (limit * sizeof(struct line_tally)), "array line_tally");
(size)(limit*sizeof (struct line_tally)), while (ft->ft_limit < limit)
"array line_tally"); {
while (ft->ft_limit < limit) {
ft->ft_line[ft->ft_limit].lt_cnt = 0; ft->ft_line[ft->ft_limit].lt_cnt = 0;
ft->ft_line[ft->ft_limit].lt_instr = 0; ft->ft_line[ft->ft_limit].lt_instr = 0;
ft->ft_limit++; ft->ft_limit++;
} }
} }
PRIVATE FILE *tally_fp;
out_tally()
void out_tally(void)
{ {
struct file_tally **hook = &first_tally; struct file_tally **hook = &first_tally;
@ -113,18 +118,21 @@ out_tally()
if (!tally_fp) if (!tally_fp)
return; return;
while (*hook) { while (*hook)
{
struct file_tally *ft = *hook; struct file_tally *ft = *hook;
register long i; register long i;
fprintf(tally_fp, "%s:\n", dt_fname(ft->ft_fil)); fprintf(tally_fp, "%s:\n", dt_fname(ft->ft_fil));
for (i = 0; i < ft->ft_limit; i++) { for (i = 0; i < ft->ft_limit; i++)
{
struct line_tally *lt = &ft->ft_line[i]; struct line_tally *lt = &ft->ft_line[i];
if (lt->lt_cnt) { if (lt->lt_cnt)
{
/* we visited this line */ /* we visited this line */
fprintf(tally_fp, "\t%ld\t%ld\t%ld\n", fprintf(tally_fp, "\t%ld\t%ld\t%ld\n", i, lt->lt_cnt,
i, lt->lt_cnt, lt->lt_instr); lt->lt_instr);
} }
} }
fprintf(tally_fp, "\n"); fprintf(tally_fp, "\n");

View file

@ -1,10 +1,9 @@
/* /** @file
Manipulating the Program Counter * Program counter manipulation routines */
*/
/* $Id$ */ /* $Id$ */
#include <em_abs.h> #include "em_abs.h"
#include "global.h" #include "global.h"
#include "alloc.h" #include "alloc.h"
#include "trap.h" #include "trap.h"
@ -13,7 +12,8 @@
#include "proctab.h" #include "proctab.h"
#include "warn.h" #include "warn.h"
init_text() { void init_text(void)
{
DB = i2p(NTEXT); /* set Descriptor Base */ DB = i2p(NTEXT); /* set Descriptor Base */
NProc = NPROC; /* set Number of Proc. Descriptors */ NProc = NPROC; /* set Number of Proc. Descriptors */
PI = -1; /* initialize Procedure Identifier */ PI = -1; /* initialize Procedure Identifier */
@ -31,8 +31,7 @@ init_text() {
* * * *
************************************************************************/ ************************************************************************/
newPC(p) void newPC(register ptr p)
register ptr p;
{ {
register struct proc *pr = &proctab[PI]; register struct proc *pr = &proctab[PI];

View file

@ -112,3 +112,11 @@
#define arg_lin(u) ((u > NLINE) ? (trap(EBADLIN), u) : u) #define arg_lin(u) ((u > NLINE) ? (trap(EBADLIN), u) : u)
/* Allocates the "text" variable that will hold the text
* segment.
*/
void init_text(void);
/* Sets the new value of the PC register to the specified
* value "p".
*/
void newPC(register ptr p);

View file

@ -1,5 +1,5 @@
/* /** @file
Trap handling * Trap handling and management routines.
*/ */
/* $Id$ */ /* $Id$ */
@ -11,6 +11,7 @@
#include "global.h" #include "global.h"
#include "log.h" #include "log.h"
#include "trap.h" #include "trap.h"
#include "io.h"
#include "warn.h" #include "warn.h"
#include "mem.h" #include "mem.h"
#include "shadow.h" #include "shadow.h"
@ -25,22 +26,21 @@ int signalled;
PRIVATE int nonreturnable(); PRIVATE int nonreturnable();
PRIVATE char *trap_msg[] = { PRIVATE char *trap_msg[] =
{
#include "trap_msg" /* generated from $(EM)/etc/traps */ #include "trap_msg" /* generated from $(EM)/etc/traps */
"" "" };
};
char *trap2text(nr) /* transient */ char *trap2text(int nr)
int nr;
{ {
if ( /* trap number in predefined range */ if ( /* trap number in predefined range */
nr < sizeof (trap_msg) / sizeof (trap_msg[0]) nr < sizeof(trap_msg) / sizeof(trap_msg[0]) && /* trap message not the empty string */
&& /* trap message not the empty string */ trap_msg[nr][0])
trap_msg[nr][0] {
) {
return trap_msg[nr]; return trap_msg[nr];
} }
else { else
{
static char buf[50]; static char buf[50];
sprintf(buf, "TRAP %d", nr); sprintf(buf, "TRAP %d", nr);
@ -49,10 +49,7 @@ char *trap2text(nr) /* transient */
} }
/*ARGSUSED*/ /*ARGSUSED*/
do_trap(nr, L, F) void do_trap(int nr, int L, char *F)
int nr;
int L;
char *F;
{ {
/* /*
1. The trap has not been masked. 1. The trap has not been masked.
@ -67,19 +64,20 @@ do_trap(nr, L, F)
LOG(("@t1 trap(%d) [%s: %d]", nr, F, L)); LOG(("@t1 trap(%d) [%s: %d]", nr, F, L));
warning(WMSG + nr); warning(WMSG + nr);
switch (OnTrap) { switch (OnTrap)
{
case TR_ABORT: case TR_ABORT:
fatal("trap \"%s\" before program started", trap2text(nr)); fatal("trap \"%s\" before program started", trap2text(nr));
/*NOTREACHED*/ /*NOTREACHED*/
case TR_HALT: case TR_HALT:
fatal("trap \"%s\" not caught at %s", fatal("trap \"%s\" not caught at %s", trap2text(nr), position());
trap2text(nr), position());
/*NOTREACHED*/ /*NOTREACHED*/
case TR_TRAP: case TR_TRAP:
/* execute the trap */ /* execute the trap */
if (rec_trap) { if (rec_trap)
{
fatal("recursive trap; first trap number was \"%s\"", fatal("recursive trap; first trap number was \"%s\"",
trap2text(rec_nr)); trap2text(rec_nr));
} }
@ -104,10 +102,10 @@ do_trap(nr, L, F)
} }
} }
PRIVATE int nonreturnable(nr) PRIVATE int nonreturnable(int nr)
int nr; {
switch (nr)
{ {
switch (nr) {
case ESTACK: case ESTACK:
case EILLINS: case EILLINS:
case EODDZ: case EODDZ:

View file

@ -1,6 +1,10 @@
/* /*
Trap handling Trap handling
*/ */
#ifndef TRAP_H_
#define TRAP_H_
#include "warn.h"
/* $Id$ */ /* $Id$ */
@ -12,3 +16,12 @@ extern int signalled; /* signal nr if trap was due to sig */
extern int must_test; /* must trap on overfl./out of range*/ extern int must_test; /* must trap on overfl./out of range*/
/* TEST-bit on in EM header word 2 */ /* TEST-bit on in EM header word 2 */
/* Execute the specified trap. "nr" represents the signal
* number, "L" is the line number and "F" is the filename
* where the trap occurred.
*/
void do_trap(int nr, int L, char *F);
#endif /* TRAP_H_ */

View file

@ -1,5 +1,5 @@
/* /** @file
Warnings. * Warning management.
*/ */
/* $Id$ */ /* $Id$ */
@ -32,7 +32,7 @@ PRIVATE struct warn_msg warn_msg[] = {
PRIVATE char *warn_text[WMSG+1]; PRIVATE char *warn_text[WMSG+1];
init_wmsg() void init_wmsg(void)
{ {
register int i; register int i;
register struct warn_msg *wmsg; register struct warn_msg *wmsg;
@ -58,8 +58,7 @@ struct warn_cnt {
PRIVATE struct warn_cnt *warn_cnt[WMSG]; PRIVATE struct warn_cnt *warn_cnt[WMSG];
PRIVATE char warnmask[WMSG]; PRIVATE char warnmask[WMSG];
PRIVATE long count_wrn(nr) PRIVATE long count_wrn(int nr)
int nr;
{ /* returns the occurrence counter for the warning with number { /* returns the occurrence counter for the warning with number
nr; keeps track of the warnings, sorted by warning number, nr; keeps track of the warnings, sorted by warning number,
file name and line number. file name and line number.
@ -67,7 +66,7 @@ PRIVATE long count_wrn(nr)
register struct warn_cnt **warn_hook = &warn_cnt[nr]; register struct warn_cnt **warn_hook = &warn_cnt[nr];
register struct warn_cnt *wrn; register struct warn_cnt *wrn;
while (wrn = *warn_hook) { while ( (wrn = *warn_hook) ) {
if (wrn->wc_fil == FIL && wrn->wc_lin == LIN) { if (wrn->wc_fil == FIL && wrn->wc_lin == LIN) {
return ++wrn->wc_cnt; return ++wrn->wc_cnt;
} }
@ -95,10 +94,7 @@ PRIVATE long count_wrn(nr)
PRIVATE int latest_warning_printed; /* set if ... */ PRIVATE int latest_warning_printed; /* set if ... */
/*ARGSUSED*/ /*ARGSUSED*/
do_warn(nr, L, F) void do_warn(int nr, int L, char *F)
int nr;
int L;
char *F;
{ {
latest_warning_printed = 0; latest_warning_printed = 0;
if (nr < WMSG) { if (nr < WMSG) {
@ -130,8 +126,7 @@ do_warn(nr, L, F)
#ifdef LOGGING #ifdef LOGGING
warningcont(nr) void warningcont(int nr)
int nr;
{ {
/* continued warning */ /* continued warning */
if (latest_warning_printed) { if (latest_warning_printed) {
@ -148,8 +143,7 @@ warningcont(nr)
#endif /* LOGGING */ #endif /* LOGGING */
set_wmask(i) void set_wmask(int i)
int i;
{ {
if (i < WMSG) { if (i < WMSG) {
warnmask[i] = 1; warnmask[i] = 1;