---
-BasedOnStyle: WebKit
-AllowShortLoopsOnASingleLine: 'false'
+AlignAfterOpenBracket: AlwaysBreak
+AllowShortFunctionsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: false
+BasedOnStyle: WebKit
+BinPackArguments: true
+BinPackParameters: false
BreakBeforeBraces: Allman
+ColumnLimit: 100
IndentCaseLabels: 'true'
PointerAlignment: Left
+SortIncludes: false
TabWidth: '4'
UseTab: ForIndentation
-SortIncludes: false
...
--- /dev/null
+#ifndef LIBM2_H
+#define LIBM2_H
+
+#include <stdint.h>
+
+struct array_descr
+{
+ int lbound;
+ int n_elts_min_one;
+ unsigned size;
+};
+
+struct int_range_descr
+{
+ int low, high;
+};
+
+struct uint_range_descr
+{
+ unsigned int low, high;
+};
+
+struct long_range_descr
+{
+ long low, high;
+};
+
+struct ulong_range_descr
+{
+ unsigned long low, high;
+};
+
+struct stack_descr
+{
+ char* addr;
+ int low;
+ unsigned int highminlow;
+ unsigned int size;
+};
+
+struct proc
+{
+ unsigned size; /* size of saved stackframe(s) */
+ int (*proc)(void); /* address of coroutine procedure */
+ char* brk; /* stack break of this coroutine */
+};
+
+extern void (*handler)(int);
+extern char** argv;
+extern int argc;
+extern char* MainLB;
+
+extern double absd(double i);
+extern int CallAtEnd(void (*p)(void));
+extern int absi(int i);
+extern int dvi(int j, int i);
+extern int rmi(int j, int i);
+extern int sigtrp(int trapno, int signo);
+extern int stackprio(unsigned n);
+extern int topsave(void* brkpos, struct proc* proc);
+extern long absl(long i);
+extern long dvil(long j, long i);
+extern long rmil(long j, long i);
+extern size_t new_stackptr(struct stack_descr* pdscr, int a);
+extern unsigned int topsize(void* brkpos);
+extern void SIG(void (*)(int));
+extern void StringAssign(int dstsiz, int srcsiz, register char* dstaddr, register char* srcaddr);
+extern void TRP(int trapno);
+extern void _Arguments_(void);
+extern void _SYSTEM__NEWPROCESS(int (*p)(void), struct proc* a, unsigned n, struct proc** p1);
+extern void _SYSTEM__TRANSFER(struct proc** a, struct proc** b);
+extern void _cleanup(void);
+extern void adduchk(unsigned a, unsigned b);
+extern void blockmove(size_t siz, char* dst, char* src);
+extern void cap(unsigned u);
+extern void catch (int trapno);
+extern void copy_array(char* pp, int a);
+extern void halt(void);
+extern void init(void);
+extern void killbss(void);
+extern void load(size_t siz, register char* addr, int p);
+extern void muluchk(unsigned a, unsigned b);
+extern void rcka(struct array_descr* descr, int indx);
+extern void rcki(struct int_range_descr* descr, int val);
+extern void rckil(struct long_range_descr* descr, long val);
+extern void rcku(struct uint_range_descr* descr, unsigned val);
+extern void rckul(struct ulong_range_descr* descr, unsigned long val);
+extern void store(size_t siz, register char* addr, int p);
+extern void subuchk(unsigned a, unsigned b);
+extern void topload(struct proc* proc);
+extern void unstackprio(unsigned n);
+
+/* PROCEDURE Argv(argnum: CARDINAL; VAR argument: ARRAY OF CHAR): CARDINAL; */
+extern unsigned _Arguments__Argv(int n, char* argument, int l, unsigned int u, int s);
+
+/* PROCEDURE GetEnv(name: ARRAY OF CHAR; VAR value: ARRAY OF CHAR): CARDINAL; */
+extern unsigned _Arguments__GetEnv(
+ char* name, int nn, unsigned int nu, int ns, char* value, int l, unsigned int u, int s);
+
+/* PROCEDURE Message(str: ARRAY OF CHAR); */
+extern void _Traps__Message(char* str, int nn, unsigned int nu, int ns);
+
+#endif
/* Modula-2 runtime errors */
-#define M2_TOOLARGE 64 /* stack of process too large */
-#define M2_TOOMANY 65 /* too many nested traps & handlers */
-#define M2_NORESULT 66 /* no RETURN from procedure function */
-#define M2_UOVFL 67 /* cardinal overflow */
-#define M2_FORCH 68 /* FOR-loop control variable changed */
-#define M2_UUVFL 69 /* cardinal underflow */
-#define M2_INTERNAL 70 /* internal error, should not happen */
-#define M2_UNIXSIG 71 /* unix signal */
+#define M2_TOOLARGE 64 /* stack of process too large */
+#define M2_TOOMANY 65 /* too many nested traps & handlers */
+#define M2_NORESULT 66 /* no RETURN from procedure function */
+#define M2_UOVFL 67 /* cardinal overflow */
+#define M2_FORCH 68 /* FOR-loop control variable changed */
+#define M2_UUVFL 69 /* cardinal underflow */
+#define M2_INTERNAL 70 /* internal error, should not happen */
+#define M2_UNIXSIG 71 /* unix signal */
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
extern char **argv, **environ;
extern int argc;
unsigned int _Arguments__Argc;
-static char *
-findname(s1, s2)
-register char *s1, *s2;
+static char* findname(char* s1, char* s2)
{
- while (*s1 == *s2++) s1++;
- if (*s1 == '\0' && *(s2-1) == '=') return s2;
+ while (*s1 == *s2++)
+ s1++;
+ if (*s1 == '\0' && *(s2 - 1) == '=')
+ return s2;
return 0;
}
-static unsigned int
-scopy(src, dst, max)
- register char *src, *dst;
- unsigned int max;
+static unsigned int scopy(char* src, char* dst, unsigned int max)
{
register unsigned int i = 0;
- while (*src && i <= max) {
+ while (*src && i <= max)
+ {
i++;
*dst++ = *src++;
}
- if (i <= max) {
+ if (i <= max)
+ {
*dst = '\0';
- return i+1;
+ return i + 1;
}
- while (*src++) i++;
+ while (*src++)
+ i++;
return i + 1;
}
-_Arguments_()
+void _Arguments_(void)
{
_Arguments__Argc = argc;
}
-unsigned
-_Arguments__Argv(n, argument, l, u, s)
- unsigned int u;
- char *argument;
+unsigned int _Arguments__Argv(int n, char* argument, int l, unsigned int u, int s)
{
- if (n >= argc) return 0;
+ if (n >= argc)
+ return 0;
return scopy(argv[n], argument, u);
}
-unsigned
-_Arguments__GetEnv(name, nn, nu, ns, value, l, u, s)
- char *name, *value;
- unsigned int nu, u;
+unsigned int _Arguments__GetEnv(
+ char* name, int nn, unsigned int nu, int ns, char* value, int l, unsigned int u, int s)
{
- register char **p = environ;
- register char *v = 0;
+ register char** p = environ;
+ register char* v = 0;
- while (*p && !(v = findname(name, *p++))) {
+ while (*p && !(v = findname(name, *p++)))
+ {
/* nothing */
}
- if (!v) return 0;
+ if (!v)
+ return 0;
return scopy(v, value, u);
}
*/
/*
- An implementation of the Modula-2 NEWPROCESS and TRANSFER facilities
- using the topsize, topsave, and topload facilities.
- For each coroutine, a proc structure is built. For the main routine,
- a static space is declared to save its stack. For the other coroutines,
- the user specifies this space.
+ An implementation of the Modula-2 NEWPROCESS and TRANSFER facilities
+ using the topsize, topsave, and topload facilities.
+ For each coroutine, a proc structure is built. For the main routine,
+ a static space is declared to save its stack. For the other coroutines,
+ the user specifies this space.
*/
+#include <unistd.h>
+#include "libm2.h"
#include <m2_traps.h>
-#define MAXMAIN 2048
+#define MAXMAIN 2048
-struct proc {
- unsigned size; /* size of saved stackframe(s) */
- int (*proc)(); /* address of coroutine procedure */
- char *brk; /* stack break of this coroutine */
-};
+static struct proc mainproc[MAXMAIN / sizeof(struct proc) + 1];
-extern unsigned topsize();
+static struct proc* curproc = 0; /* current coroutine */
+extern char* MainLB; /* stack break of main routine */
-static struct proc mainproc[MAXMAIN/sizeof(struct proc) + 1];
-
-static struct proc *curproc = 0;/* current coroutine */
-extern char *MainLB; /* stack break of main routine */
-
-_SYSTEM__NEWPROCESS(p, a, n, p1)
- int (*p)(); /* coroutine procedure */
- struct proc *a; /* pointer to area for saved stack-frame */
- unsigned n; /* size of this area */
- struct proc **p1; /* where to leave coroutine descriptor,
- in this implementation the address of
- the area for saved stack-frame(s) */
+void _SYSTEM__NEWPROCESS(
+ int (*p)(void) /* coroutine procedure */,
+ struct proc* a /* pointer to area for saved stack-frame */,
+ unsigned int n /* size of this area */,
+ struct proc** p1 /* where to leave coroutine descriptor,
+ in this implementation the address of
+ the area for saved stack-frame(s) */
+ )
{
/* This procedure creates a new coroutine, but does not
- transfer control to it. The routine "topsize" will compute the
- stack break, which will be the local base of this routine.
- Notice that we can do this because we do not need the stack
- above this point for this coroutine. In Modula-2, coroutines
- must be level 0 procedures without parameters.
+ transfer control to it. The routine "topsize" will compute the
+ stack break, which will be the local base of this routine.
+ Notice that we can do this because we do not need the stack
+ above this point for this coroutine. In Modula-2, coroutines
+ must be level 0 procedures without parameters.
*/
- char *brk = 0;
+ char* brk = 0;
unsigned sz = topsize(&brk);
- if (sz + sizeof(struct proc) > n) {
+ if (sz + sizeof(struct proc) > n)
+ {
/* not enough space */
TRP(M2_TOOLARGE);
}
a->proc = p;
a->brk = brk;
*p1 = a;
- if (topsave(brk, a+1))
+ if (topsave(brk, a + 1))
/* stack frame saved; now just return */
;
- else {
+ else
+ {
/* We get here through the first transfer to the coroutine
created above.
This also means that curproc is now set to this coroutine.
}
}
-_SYSTEM__TRANSFER(a, b)
- struct proc **a, **b;
+void _SYSTEM__TRANSFER(struct proc** a, struct proc** b)
{
/* transfer from one coroutine to another, saving the current
- descriptor in the space indicated by "a", and transfering to
- the coroutine in descriptor "b".
+ descriptor in the space indicated by "a", and transfering to
+ the coroutine in descriptor "b".
*/
unsigned size;
- if (! curproc) {
+ if (!curproc)
+ {
/* the current coroutine is the main process;
initialize a coroutine descriptor for it ...
*/
mainproc[0].size = sizeof(mainproc);
curproc = &mainproc[0];
}
- *a = curproc; /* save current descriptor in "a" */
- if (*b == curproc) {
+ *a = curproc; /* save current descriptor in "a" */
+ if (*b == curproc)
+ {
/* transfer to itself is a no-op */
return;
}
size = topsize(&(curproc->brk));
- if (size + sizeof(struct proc) > curproc->size) {
+ if (size + sizeof(struct proc) > curproc->size)
+ {
TRP(M2_TOOLARGE);
}
- if (topsave(curproc->brk, curproc+1)) {
+ if (topsave(curproc->brk, curproc + 1))
+ {
/* stack top saved. Now restore context of target
coroutine
*/
curproc = *b;
- topload(curproc+1);
+ topload(curproc + 1);
/* we never get here ... */
}
/* but we do get here, when a transfer is done to the coroutine in "a".
/*
Module: assign string to character array, with possible 0-byte
- extension
+ extension
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
-StringAssign(dstsiz, srcsiz, dstaddr, srcaddr)
- register char *dstaddr, *srcaddr;
+#include "libm2.h"
+
+void StringAssign(int dstsiz, int srcsiz, char* dstaddr, char* srcaddr)
{
- while (srcsiz > 0) {
+ while (srcsiz > 0)
+ {
*dstaddr++ = *srcaddr++;
srcsiz--;
dstsiz--;
}
- if (dstsiz > 0) {
+ if (dstsiz > 0)
+ {
*dstaddr = 0;
}
}
*)
FROM SYSTEM IMPORT ADR;
#ifdef __USG
- FROM Unix IMPORT read, write, open, fcntl;
+ FROM Unix IMPORT read, write, fcntl;
#else
- FROM Unix IMPORT read, write, open, ioctl;
+ FROM Unix IMPORT read, write, ioctl;
#endif
VAR fildes, fdout: INTEGER;
unreadch: CHAR;
unread: BOOLEAN;
- tty: ARRAY[0..8] OF CHAR;
+ (* tty: ARRAY[0..8] OF CHAR; *)
PROCEDURE Read(VAR ch: CHAR);
BEGIN
*)
(* dtrg: changed so that instead of opening /dev/tty, fd 0 is always used. *)
(* kernigh: sent output to fd 1 *)
- tty := "stdio";
+ (* tty := "stdio"; *)
fildes := 0;
fdout := 1;
unread := FALSE;
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
+
#ifndef NOFLOAT
-double
-absd(i)
- double i;
+double absd(double i)
{
return i >= 0 ? i : -i;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
-absi(i)
+int absi(int i)
{
return i >= 0 ? i : -i;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
-long
-absl(i)
- long i;
+#include "libm2.h"
+
+long absl(long i)
{
return i >= 0 ? i : -i;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include <stdint.h>
+#include "libm2.h"
-#if _EM_WSIZE==_EM_PSIZE
-typedef unsigned pcnt;
-#else
-typedef unsigned long pcnt;
-#endif
-
-blockmove(siz, dst, src)
- pcnt siz;
- register char *dst, *src;
+void blockmove(size_t siz, char* dst, char* src)
{
- while (siz--) *dst++ = *src++;
+ while (siz--)
+ *dst++ = *src++;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
-cap(u)
- unsigned u;
+void cap(unsigned int u)
{
- register unsigned *p = &u;
+ register unsigned* p = &u;
- if (*p >= 'a' && *p <= 'z') *p += 'A'-'a';
+ if (*p >= 'a' && *p <= 'z')
+ *p += 'A' - 'a';
}
#include <em_abs.h>
#include <m2_traps.h>
#include <signal.h>
+#include "libm2.h"
-static struct errm {
+static struct errm
+{
int errno;
- char *errmes;
-} errors[] = {
- { EARRAY, "array bound error"},
- { ERANGE, "range bound error"},
- { ESET, "set bound error"},
- { EIOVFL, "integer overflow"},
- { EFOVFL, "real overflow"},
- { EFUNFL, "real underflow"},
- { EIDIVZ, "divide by 0"},
- { EFDIVZ, "divide by 0.0"},
- { EIUND, "undefined integer"},
- { EFUND, "undefined real"},
- { ECONV, "conversion error"},
+ char* errmes;
+} errors[] = { { EARRAY, "array bound error" },
+ { ERANGE, "range bound error" },
+ { ESET, "set bound error" },
+ { EIOVFL, "integer overflow" },
+ { EFOVFL, "real overflow" },
+ { EFUNFL, "real underflow" },
+ { EIDIVZ, "divide by 0" },
+ { EFDIVZ, "divide by 0.0" },
+ { EIUND, "undefined integer" },
+ { EFUND, "undefined real" },
+ { ECONV, "conversion error" },
- { ESTACK, "stack overflow"},
- { EHEAP, "heap overflow"},
- { EILLINS, "illegal instruction"},
- { EODDZ, "illegal size argument"},
- { ECASE, "case error"},
- { EMEMFLT, "addressing non existent memory"},
- { EBADPTR, "bad pointer used"},
- { EBADPC, "program counter out of range"},
- { EBADLAE, "bad argument of lae"},
- { EBADMON, "bad monitor call"},
- { EBADLIN, "argument if LIN too high"},
- { EBADGTO, "GTO descriptor error"},
+ { ESTACK, "stack overflow" },
+ { EHEAP, "heap overflow" },
+ { EILLINS, "illegal instruction" },
+ { EODDZ, "illegal size argument" },
+ { ECASE, "case error" },
+ { EMEMFLT, "addressing non existent memory" },
+ { EBADPTR, "bad pointer used" },
+ { EBADPC, "program counter out of range" },
+ { EBADLAE, "bad argument of lae" },
+ { EBADMON, "bad monitor call" },
+ { EBADLIN, "argument if LIN too high" },
+ { EBADGTO, "GTO descriptor error" },
- { M2_TOOLARGE, "stack size of process too large"},
- { M2_TOOMANY, "too many nested traps + handlers"},
- { M2_NORESULT, "no RETURN from function procedure"},
- { M2_UOVFL, "cardinal overflow"},
- { M2_FORCH, "(warning) FOR-loop control variable was changed in the body"},
- { M2_UUVFL, "cardinal underflow"},
- { M2_INTERNAL, "internal error; ask an expert for help"},
- { M2_UNIXSIG, "got a unix signal"},
- { -1, 0}
-};
+ { M2_TOOLARGE, "stack size of process too large" },
+ { M2_TOOMANY, "too many nested traps + handlers" },
+ { M2_NORESULT, "no RETURN from function procedure" },
+ { M2_UOVFL, "cardinal overflow" },
+ { M2_FORCH, "(warning) FOR-loop control variable was changed in the body" },
+ { M2_UUVFL, "cardinal underflow" },
+ { M2_INTERNAL, "internal error; ask an expert for help" },
+ { M2_UNIXSIG, "got a unix signal" },
+ { -1, 0 } };
-catch(trapno)
- int trapno;
+void catch (int trapno)
{
- register struct errm *ep = &errors[0];
- char *errmessage;
+ register struct errm* ep = &errors[0];
+ char* errmessage;
char buf[20];
register char *p, *s;
- while (ep->errno != trapno && ep->errmes != 0) ep++;
- if (p = ep->errmes) {
- while (*p) p++;
- _Traps__Message(ep->errmes, 0, (int) (p - ep->errmes), 1);
+ while (ep->errno != trapno && ep->errmes != 0)
+ ep++;
+ if (p = ep->errmes)
+ {
+ while (*p)
+ p++;
+ _Traps__Message(ep->errmes, 0, (int)(p - ep->errmes), 1);
}
- else {
+ else
+ {
int i = trapno;
static char q[] = "error number xxxxxxxxxxxxx";
p = &q[13];
s = buf;
- if (i < 0) {
+ if (i < 0)
+ {
i = -i;
*p++ = '-';
}
do
*s++ = i % 10 + '0';
while (i /= 10);
- while (s > buf) *p++ = *--s;
+ while (s > buf)
+ *p++ = *--s;
*p = 0;
- _Traps__Message(q, 0, (int) (p - q), 1);
+ _Traps__Message(q, 0, (int)(p - q), 1);
}
#if !defined(__em24) && !defined(__em44) && !defined(__em22)
- if (trapno == M2_UNIXSIG) {
+ if (trapno == M2_UNIXSIG)
+ {
extern int __signo;
signal(__signo, SIG_DFL);
_cleanup();
kill(getpid(), __signo);
- _exit(trapno+1);
+ _exit(trapno + 1);
}
#endif
- if (trapno != M2_FORCH) {
+ if (trapno != M2_FORCH)
+ {
_cleanup();
- _exit(trapno+1);
+ _exit(trapno + 1);
}
SIG(catch);
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
#include <m2_traps.h>
#ifndef EM_WSIZE
#define EM_PSIZE _EM_PSIZE
#endif
-#if EM_WSIZE==EM_PSIZE
-typedef unsigned pcnt;
-#else
-typedef unsigned long pcnt;
-#endif
-
-struct descr {
- char *addr;
- int low;
- unsigned int highminlow;
- unsigned int size;
-};
+static struct stack_descr* descrs[10];
+static struct stack_descr** ppdescr = descrs;
-static struct descr *descrs[10];
-static struct descr **ppdescr = descrs;
-
-pcnt
-new_stackptr(pdscr, a)
- struct descr *pdscr;
+size_t new_stackptr(struct stack_descr* pdescr, int a)
{
- register struct descr *pdescr = pdscr;
- pcnt size = (((pdescr->highminlow + 1) * pdescr->size +
- (EM_WSIZE - 1)) & ~(EM_WSIZE - 1));
+ size_t size = (((pdescr->highminlow + 1) * pdescr->size + (EM_WSIZE - 1)) & ~(EM_WSIZE - 1));
- if (ppdescr >= &descrs[10]) {
+ if (ppdescr >= &descrs[10])
+ {
/* to many nested traps + handlers ! */
TRP(M2_TOOMANY);
}
*ppdescr++ = pdescr;
- if ((char *) &a - (char *) &pdscr > 0) {
+ if ((char*)&a - (char*)&pdescr > 0)
+ {
/* stack grows downwards */
- return - size;
+ return -size;
}
return size;
}
-copy_array(pp, a)
- char *pp;
+void copy_array(char* p, int a)
{
- register char *p = pp;
- register char *q;
- register pcnt sz;
+ char* q;
+ size_t sz;
char dummy;
ppdescr--;
sz = ((*ppdescr)->highminlow + 1) * (*ppdescr)->size;
-
- if ((char *) &a - (char *) &pp > 0) {
- (*ppdescr)->addr = q = (char *) &a;
+
+ if ((char*)&a - (char*)&p > 0)
+ {
+ (*ppdescr)->addr = q = (char*)&a;
}
- else (*ppdescr)->addr = q = (char *) &a -
- ((sz + (EM_WSIZE - 1)) & ~ (EM_WSIZE - 1));
+ else
+ (*ppdescr)->addr = q = (char*)&a - ((sz + (EM_WSIZE - 1)) & ~(EM_WSIZE - 1));
- while (sz--) *q++ = *p++;
+ while (sz--)
+ *q++ = *p++;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
Reason: We cannot use DVI and RMI, because DVI rounds towards 0
- and Modula-2 requires truncation
+ and Modula-2 requires truncation
*/
+#include "libm2.h"
#include <em_abs.h>
-int
-dvi(j,i)
- int j,i;
+int dvi(int j, int i)
{
- if (j == 0) TRP(EIDIVZ);
- if ((i < 0) != (j < 0)) {
- if (i < 0) i = -i;
- else j = -j;
- return -((i+j-1)/j);
+ if (j == 0)
+ TRP(EIDIVZ);
+ if ((i < 0) != (j < 0))
+ {
+ if (i < 0)
+ i = -i;
+ else
+ j = -j;
+ return -((i + j - 1) / j);
}
- else return i/j;
+ else
+ return i / j;
}
-long
-dvil(j,i)
- long j,i;
+long dvil(long j, long i)
{
- if (j == 0) TRP(EIDIVZ);
- if ((i < 0) != (j < 0)) {
- if (i < 0) i = -i;
- else j = -j;
- return -((i+j-1)/j);
+ if (j == 0)
+ TRP(EIDIVZ);
+ if ((i < 0) != (j < 0))
+ {
+ if (i < 0)
+ i = -i;
+ else
+ j = -j;
+ return -((i + j - 1) / j);
}
- else return i/j;
+ else
+ return i / j;
}
-int
-rmi(j,i)
- int j,i;
+int rmi(int j, int i)
{
int m;
- if (j == 0) TRP(EIDIVZ);
- if (i == 0) return 0;
+ if (j == 0)
+ TRP(EIDIVZ);
+ if (i == 0)
+ return 0;
m = i % j;
if (m != 0 && (i < 0) != (j < 0))
return m;
}
-long
-rmil(j,i)
- long j,i;
+long rmil(long j, long i)
{
long m;
- if (j == 0) TRP(EIDIVZ);
- if (i == 0) return 0L;
+ if (j == 0)
+ TRP(EIDIVZ);
+ if (i == 0)
+ return 0L;
m = i % j;
if (m != 0 && (i < 0) != (j < 0))
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+
+#include <unistd.h>
+#include "libm2.h"
#define MAXPROCS 32
static int callindex = 0;
-static int (*proclist[MAXPROCS])();
+static void (*proclist[MAXPROCS])(void);
-_cleanup()
+void _cleanup(void)
{
while (--callindex >= 0)
(*proclist[callindex])();
callindex = 0;
}
-CallAtEnd(p)
- int (*p)();
+int CallAtEnd(void (*p)(void))
{
- if (callindex >= MAXPROCS) {
+ if (callindex >= MAXPROCS)
+ {
return 0;
}
proclist[callindex++] = p;
return 1;
}
-halt()
+void halt(void)
{
_cleanup();
_exit(0);
#include <signal.h>
#include <em_abs.h>
#include <m2_traps.h>
+#include "libm2.h"
static const char signals_list[] = {
#ifdef SIGHUP
void init(void)
{
const char* p = signals_list;
- do {
+ do
+ {
int i = *p++;
if (i == -1)
break;
#endif
}
#if defined(__em22) || defined(__em24) || defined(__em44)
-killbss()
+void killbss(void)
{
}
#else
-static int blablabla; /* We cannot use end, because then also
- bss allocated for the systemcall lib
- would be overwritten. Lets hope that
- this helps ...
- */
+static int blablabla; /* We cannot use end, because then also
+ bss allocated for the systemcall lib
+ would be overwritten. Lets hope that
+ this helps ...
+ */
-killbss()
+void killbss(void)
{
- extern char *bkillbss;
- register char *p = (char *) &bkillbss;
+ extern char* bkillbss;
+ register char* p = (char*)&bkillbss;
- while (p < (char *) &blablabla) *p++ = 0x66;
+ while (p < (char*)&blablabla)
+ *p++ = 0x66;
}
#endif
-extern int catch();
-
-int (*handler)() = catch;
-char **argv = 0;
+void (*handler)(int) = catch;
+char** argv = 0;
int argc = 0;
-char *MainLB = 0;
+char* MainLB = 0;
Version: $Id$
*/
+#include "libm2.h"
#include <m2_traps.h>
#ifndef EM_WSIZE
#define EM_PSIZE _EM_PSIZE
#endif
-#if EM_WSIZE==EM_PSIZE
-typedef unsigned pcnt;
-#else
-typedef long pcnt;
-#endif
-
-load(siz, addr, p)
- register char *addr;
- register pcnt siz;
+void load(size_t siz, char* addr, int p)
{
/* Make sure, that a value with a size that could have been
- handled by the LOI instruction ends up at the same place,
- where it would, were the LOI instruction used.
+ handled by the LOI instruction ends up at the same place,
+ where it would, were the LOI instruction used.
*/
- register char *q = (char *) &p;
+ register char* q = (char*)&p;
char t[4];
- if (siz < EM_WSIZE && EM_WSIZE % siz == 0) {
+ if (siz < EM_WSIZE && EM_WSIZE % siz == 0)
+ {
/* as long as EM_WSIZE <= 4 ... */
- if (siz != 2) TRP(M2_INTERNAL); /* internal error */
+ if (siz != 2)
+ TRP(M2_INTERNAL); /* internal error */
q = &t[0];
}
- while (siz--) *q++ = *addr++;
- if (q - t == 2) {
- *((unsigned *)(&p)) = *((unsigned short *) (&t[0]));
+ while (siz--)
+ *q++ = *addr++;
+ if (q - t == 2)
+ {
+ *((unsigned*)(&p)) = *((unsigned short*)(&t[0]));
}
}
* Version: $Id$
*/
+#include "libm2.h"
#include <em_abs.h>
-extern TRP();
-
-struct array_descr {
- int lbound;
- int n_elts_min_one;
- unsigned size;
-};
-
-rcka(descr, indx)
- struct array_descr *descr;
+void rcka(struct array_descr* descr, int indx)
{
- if (indx < 0 || indx > descr->n_elts_min_one) TRP(EARRAY);
+ if (indx < 0 || indx > descr->n_elts_min_one)
+ TRP(EARRAY);
}
* Version: $Id$
*/
+#include "libm2.h"
#include <em_abs.h>
-extern TRP();
-
-struct range_descr {
- int low, high;
-};
-
-rcki(descr, val)
- struct range_descr *descr;
+void rcki(struct int_range_descr* descr, int val)
{
- if (val < descr->low || val > descr->high) TRP(ERANGE);
+ if (val < descr->low || val > descr->high)
+ TRP(ERANGE);
}
* Version: $Id$
*/
+#include "libm2.h"
#include <em_abs.h>
-extern TRP();
-
-struct range_descr {
- long low, high;
-};
-
-rckil(descr, val)
- struct range_descr *descr;
- long val;
+void rckil(struct long_range_descr* descr, long val)
{
- if (val < descr->low || val > descr->high) TRP(ERANGE);
+ if (val < descr->low || val > descr->high)
+ TRP(ERANGE);
}
* Version: $Id$
*/
+#include "libm2.h"
#include <em_abs.h>
-extern TRP();
-
-struct range_descr {
- unsigned low, high;
-};
-
-rcku(descr, val)
- struct range_descr *descr;
- unsigned val;
+void rcku(struct uint_range_descr* descr, unsigned int val)
{
- if (val < descr->low || val > descr->high) TRP(ERANGE);
+ if (val < descr->low || val > descr->high)
+ TRP(ERANGE);
}
* Version: $Id$
*/
+#include "libm2.h"
#include <em_abs.h>
-extern TRP();
-
-struct range_descr {
- unsigned long low, high;
-};
-
-rckul(descr, val)
- struct range_descr *descr;
- unsigned long val;
+void rckul(struct ulong_range_descr* descr, unsigned long val)
{
- if (val < descr->low || val > descr->high) TRP(ERANGE);
+ if (val < descr->low || val > descr->high)
+ TRP(ERANGE);
}
/*
Module: Mapping of Unix signals to EM traps
- (only when not using the MON instruction)
+ (only when not using the MON instruction)
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
#if !defined(__em22) && !defined(__em24) && !defined(__em44)
-#define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
+#define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
+#include "libm2.h"
#include <signal.h>
#include <errno.h>
int __signo;
static int __traps[] = {
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
+ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
+ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
};
-static void
-__ctchsig(signo)
+static void __ctchsig(int signo)
{
- signal(signo,__ctchsig);
+ signal(signo, __ctchsig);
#ifdef __BSD4_2
- sigsetmask(sigblock(0) & ~(1<<(signo - 1)));
+ sigsetmask(sigblock(0) & ~(1 << (signo - 1)));
#endif
__signo = signo;
EM_trap(__traps[signo]);
}
-int
-sigtrp(trapno, signo)
+int sigtrp(int trapno, int signo)
{
/* Let Unix signal signo cause EM trap trapno to occur.
- If trapno = -2, restore default,
- If trapno = -3, ignore.
- Return old trapnumber.
- Careful, this could be -2 or -3; But return value of -1
- indicates failure, with error number in errno.
+ If trapno = -2, restore default,
+ If trapno = -3, ignore.
+ Return old trapnumber.
+ Careful, this could be -2 or -3; But return value of -1
+ indicates failure, with error number in errno.
*/
extern int errno;
- void (*ctch)() = __ctchsig;
- void (*oldctch)();
+ void (*ctch)(int) = __ctchsig;
+ void (*oldctch)(int);
int oldtrap;
- if (signo <= 0 || signo >= sizeof(__traps)/sizeof(__traps[0])) {
+ if (signo <= 0 || signo >= sizeof(__traps) / sizeof(__traps[0]))
+ {
errno = EINVAL;
return -1;
}
ctch = SIG_DFL;
else if (trapno >= 0 && trapno <= 252)
;
- else {
+ else
+ {
errno = EINVAL;
return -1;
}
oldtrap = __traps[signo];
- if ((oldctch = signal(signo, ctch)) == (void (*)())-1) /* errno set by signal */
+ if ((oldctch = signal(signo, ctch)) == (void (*)()) - 1) /* errno set by signal */
return -1;
-
- else if (oldctch == SIG_IGN) {
+
+ else if (oldctch == SIG_IGN)
+ {
signal(signo, SIG_IGN);
}
- else __traps[signo] = trapno;
+ else
+ __traps[signo] = trapno;
return oldtrap;
}
Author: Ceriel J.H. Jacobs
Version: $Id$
*/
+#include "libm2.h"
static unsigned prio = 0;
-stackprio(n)
- unsigned n;
+int stackprio(unsigned int n)
{
unsigned old = prio;
- if (n > prio) prio = n;
+ if (n > prio)
+ prio = n;
return old;
}
-unstackprio(n)
- unsigned n;
+void unstackprio(unsigned int n)
{
prio = n;
}
Version: $Id$
*/
+#include "libm2.h"
#include <m2_traps.h>
#ifndef EM_WSIZE
#define EM_PSIZE _EM_PSIZE
#endif
-#if EM_WSIZE==EM_PSIZE
-typedef unsigned pcnt;
-#else
-typedef long pcnt;
-#endif
-
-store(siz, addr, p)
- register char *addr;
- register pcnt siz;
+void store(size_t siz, char* addr, int p)
{
/* Make sure, that a value with a size that could have been
- handled by the LOI instruction is handled as if it was
- loaded with the LOI instruction.
+ handled by the LOI instruction is handled as if it was
+ loaded with the LOI instruction.
*/
- register char *q = (char *) &p;
+ register char* q = (char*)&p;
char t[4];
- if (siz < EM_WSIZE && EM_WSIZE % siz == 0) {
+ if (siz < EM_WSIZE && EM_WSIZE % siz == 0)
+ {
/* as long as EM_WSIZE <= 4 ... */
- if (siz != 2) TRP(M2_INTERNAL); /* internal error */
- *((unsigned short *) (&t[0])) = *((unsigned *) q);
+ if (siz != 2)
+ TRP(M2_INTERNAL); /* internal error */
+ *((unsigned short*)(&t[0])) = *((unsigned*)q);
q = &t[0];
}
- while (siz--) *addr++ = *q++;
+ while (siz--)
+ *addr++ = *q++;
}
#define EM_LSIZE _EM_LSIZE
#endif
+#include "libm2.h"
#include <m2_traps.h>
-#define MAXCARD ((unsigned)-1)
+#define MAXCARD ((unsigned)-1)
#if EM_WSIZE < EM_LSIZE
-#define MAXLONGCARD ((unsigned long) -1L)
+#define MAXLONGCARD ((unsigned long)-1L)
#endif
-adduchk(a,b)
- unsigned a,b;
+void adduchk(unsigned int a, unsigned int b)
{
- if (MAXCARD - a < b) TRP(M2_UOVFL);
+ if (MAXCARD - a < b)
+ TRP(M2_UOVFL);
}
#if EM_WSIZE < EM_LSIZE
-addulchk(a,b)
- unsigned long a,b;
+void addulchk(unsigned long a, unsigned long b)
{
- if (MAXLONGCARD - a < b) TRP(M2_UOVFL);
+ if (MAXLONGCARD - a < b)
+ TRP(M2_UOVFL);
}
#endif
-muluchk(a,b)
- unsigned a,b;
+void muluchk(unsigned int a, unsigned int b)
{
- if (a != 0 && MAXCARD/a < b) TRP(M2_UOVFL);
+ if (a != 0 && MAXCARD / a < b)
+ TRP(M2_UOVFL);
}
#if EM_WSIZE < EM_LSIZE
-mululchk(a,b)
- unsigned long a,b;
+void mululchk(unsigned long a, unsigned long b)
{
- if (a != 0 && MAXLONGCARD/a < b) TRP(M2_UOVFL);
+ if (a != 0 && MAXLONGCARD / a < b)
+ TRP(M2_UOVFL);
}
#endif
-subuchk(a,b)
- unsigned a,b;
+void subuchk(unsigned int a, unsigned int b)
{
- if (b < a) TRP(M2_UUVFL);
+ if (b < a)
+ TRP(M2_UUVFL);
}
#if EM_WSIZE < EM_LSIZE
-subulchk(a,b)
- unsigned long a,b;
+void subulchk(unsigned long a, unsigned long b)
{
- if (b < a) TRP(M2_UUVFL);
+ if (b < a)
+ TRP(M2_UUVFL);
}
#endif