1988-02-19 15:54:01 +00:00
|
|
|
/*
|
|
|
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Module: default modula-2 trap handler
|
|
|
|
Author: Ceriel J.H. Jacobs
|
1994-06-24 14:02:31 +00:00
|
|
|
Version: $Id$
|
1988-02-19 15:54:01 +00:00
|
|
|
*/
|
1987-05-13 14:36:45 +00:00
|
|
|
#include <em_abs.h>
|
1987-07-09 15:15:22 +00:00
|
|
|
#include <m2_traps.h>
|
1988-04-29 14:38:36 +00:00
|
|
|
#include <signal.h>
|
2018-06-25 20:22:37 +00:00
|
|
|
#include "libm2.h"
|
1987-05-13 14:36:45 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
static struct errm
|
|
|
|
{
|
1987-05-13 14:36:45 +00:00
|
|
|
int errno;
|
2018-06-25 20:22:37 +00:00
|
|
|
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" },
|
1987-05-13 14:36:45 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
{ 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" },
|
1987-06-23 17:12:42 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
{ 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 } };
|
1987-05-13 14:36:45 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
void catch (int trapno)
|
1987-05-13 14:36:45 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
register struct errm* ep = &errors[0];
|
|
|
|
char* errmessage;
|
1987-06-26 15:59:52 +00:00
|
|
|
char buf[20];
|
|
|
|
register char *p, *s;
|
1987-05-13 14:36:45 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
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);
|
1987-06-26 15:59:52 +00:00
|
|
|
}
|
2018-06-25 20:22:37 +00:00
|
|
|
else
|
|
|
|
{
|
1987-06-26 15:59:52 +00:00
|
|
|
int i = trapno;
|
1991-03-19 11:14:39 +00:00
|
|
|
static char q[] = "error number xxxxxxxxxxxxx";
|
1987-06-26 15:59:52 +00:00
|
|
|
|
|
|
|
p = &q[13];
|
|
|
|
s = buf;
|
2018-06-25 20:22:37 +00:00
|
|
|
if (i < 0)
|
|
|
|
{
|
1987-05-13 14:36:45 +00:00
|
|
|
i = -i;
|
1987-06-26 15:59:52 +00:00
|
|
|
*p++ = '-';
|
1987-05-13 14:36:45 +00:00
|
|
|
}
|
|
|
|
do
|
1987-06-26 15:59:52 +00:00
|
|
|
*s++ = i % 10 + '0';
|
1987-05-13 14:36:45 +00:00
|
|
|
while (i /= 10);
|
2018-06-25 20:22:37 +00:00
|
|
|
while (s > buf)
|
|
|
|
*p++ = *--s;
|
1987-06-29 19:33:01 +00:00
|
|
|
*p = 0;
|
2018-06-25 20:22:37 +00:00
|
|
|
_Traps__Message(q, 0, (int)(p - q), 1);
|
1987-05-13 14:36:45 +00:00
|
|
|
}
|
1991-09-04 15:49:34 +00:00
|
|
|
#if !defined(__em24) && !defined(__em44) && !defined(__em22)
|
2018-06-25 20:22:37 +00:00
|
|
|
if (trapno == M2_UNIXSIG)
|
|
|
|
{
|
1988-04-29 14:38:36 +00:00
|
|
|
extern int __signo;
|
|
|
|
signal(__signo, SIG_DFL);
|
|
|
|
_cleanup();
|
|
|
|
kill(getpid(), __signo);
|
2018-06-25 20:22:37 +00:00
|
|
|
_exit(trapno + 1);
|
1988-04-29 14:38:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-06-25 20:22:37 +00:00
|
|
|
if (trapno != M2_FORCH)
|
|
|
|
{
|
1991-03-15 09:24:03 +00:00
|
|
|
_cleanup();
|
2018-06-25 20:22:37 +00:00
|
|
|
_exit(trapno + 1);
|
1991-03-15 09:24:03 +00:00
|
|
|
}
|
1988-03-23 17:55:57 +00:00
|
|
|
SIG(catch);
|
1987-05-13 14:36:45 +00:00
|
|
|
}
|