1 /* Loglan82 Compiler&Interpreter
\r
2 Copyright (C) 1993 Institute of Informatics, University of Warsaw
\r
3 Copyright (C) 1993, 1994 LITA, Pau
\r
5 This program is free software; you can redistribute it and/or modify
\r
6 it under the terms of the GNU General Public License as published by
\r
7 the Free Software Foundation; either version 2 of the License, or
\r
8 (at your option) any later version.
\r
10 This program is distributed in the hope that it will be useful,
\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 GNU General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License
\r
16 along with this program; if not, write to the Free Software
\r
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
19 contacts: Andrzej.Salwicki@univ-pau.fr
\r
22 LITA Departement d'Informatique
\r
24 Avenue de l'Universite
\r
26 tel. ++33 59923154 fax. ++33 59841696
\r
28 =======================================================================
\r
34 #include "process.h"
\r
35 #include "intproto.h"
\r
44 /* IIUW LOGLAN-82 Executor */
\r
45 /* Written in PASCAL by P.Gburzynski and A.Litwiniuk. */
\r
46 /* Modified by J.Findeisen, T.Przytycka, D.Szczepanska, B.Ciesielski. */
\r
47 /* Hand translated to C by B. Ciesielski. */
\r
51 static void load(char *);
52 static void initiate(int,char **);
53 int main(int,char **);
56 static void initiate();
61 /* Macro to decode addressing modes : */
\r
62 #define getargument(a, argnr) \
\r
63 switch (eop->args[ argnr ]) \
\r
65 case GLOBAL : a = M[ ic++ ]; break; \
\r
66 case LOCAL : a = c1+M[ ic++ ]; break; \
\r
67 case TEMPLOCAL : a = c2+M[ ic++ ]; break; \
\r
68 case REMOTE : a = M[ M[ ic+1 ] ]+M[ ic ]; ic+=2; break;\
\r
69 case INDIRECT : a = M[ M[ ic++ ] ]; break;\
\r
70 case IMMEDIATE : a = ic++; break;\
\r
71 case CONSTANT : a = M[ ic++ ]; break;\
\r
72 case DOTACCESS : a = M[ display+M[ ic+1 ] ]+M[ ic ]; ic += 2; break;\
\r
73 case NOARGUMENT : return; \
\r
77 static void load(_filename) /* Load code and prototypes from file */
\r
83 char filename[100]; /* should suffice on all systems */
\r
85 strcpy( filename, _filename );
\r
87 M = mallocate(memorysize+1); /* allocate main memory array */
\r
88 if (M == NULL) abend("Memory size too large (use /m option)\n");
\r
90 addext(filename, ".ccd");
\r
91 if ((fp = fopen(filename, BINARYREAD)) == NULL)
\r
92 abend("Cannot open .ccd file\n");
\r
94 ic = 0; /* read static data and code */
\r
95 left = memorysize+1; /* from .ccd file */
\r
98 if (left == 0) abend("Memory size too small (use /m option)\n");
\r
99 n = min(IOBLOCK/sizeof(word), left);
\r
100 n = fread((char *) &M[ ic ], sizeof(word), (int) n, fp);
\r
103 } while (n != 0); /* now ic = number of words read */
\r
106 /* Get various addresses passed by GENERATOR */
\r
107 ipradr = M[ ic-5 ]; /* primitive type desctriptions */
\r
108 temporary = M[ ic-4 ]; /* global temporary variables */
\r
109 strings = M[ ic-3 ]; /* string constants */
\r
110 lastprot = M[ ic-2 ]; /* last prototype number */
\r
111 freem = M[ ic-1 ]; /* first free word in memory */
\r
113 /* Read prototypes from .pcd file */
\r
114 addext(filename, ".pcd");
\r
115 if ((fp = fopen(filename, BINARYREAD)) == NULL)
\r
116 abend("Cannot open .pcd file\n");
\r
117 for (n = MAINBLOCK; n <= lastprot; n++ )
\r
119 cp = ballocate(sizeof(protdescr));
\r
120 if (cp == NULL) abend("Memory size too large (use /m option)\n");
\r
121 prototype[ n ] = (protdescr *) cp;
\r
122 if (fread(cp, sizeof(protdescr), 1, fp) != 1)
\r
123 abend("Cannot read .pcd file\n");
\r
127 /* Open trace file */
\r
130 addext(filename, ".trd");
\r
131 if ((tracefile = fopen(filename, "w")) == NULL)
\r
132 abend("Cannot open .trd file\n");
\r
137 static void initiate(argc, argv) /* Establish configuration parameters */
\r
143 char *filename=NULL;
\r
145 fprintf(stderr,"\n LOGLAN-82 Concurrent Executor Version 4.51\n");
\r
146 fprintf(stderr," January 21, 1993\n");
\r
148 " (C) Copyright Institute of Informatics University of Warsaw\n");
\r
149 fprintf(stderr," (C) Copyleft LITA Universite de Pau\n");
\r
151 fprintf(stderr," D-LINK version 3.21\n\n");
\r
153 fprintf(stderr," TCPIP version 0.9\n\n");
\r
155 fprintf(stderr,"\n");
\r
160 ournode = net_logon(msginterrupt);
\r
161 if (ournode >= 0) /* network driver installed */
\r
163 else /* network driver not installed */
\r
166 ournode = 0; /* only node 0 is available */
\r
174 for( ; argc>0; argc--,argv++ ){
\r
175 if( filename != NULL ) usage();
\r
176 if( (*argv)[0]=='-' )
\r
177 switch( (*argv)[1] ){
\r
190 abend("D-Link Network Driver Version 3.21 must be installed\n");
\r
192 if( argc==0 ) usage();
\r
193 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
\r
194 if( c < 0 || c >= 255 || c == ournode )
\r
195 abend("Invalid console node number\n");
\r
200 if( argc==0 ) usage();
\r
201 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
\r
202 if( c < 0 || c >= 255 )
\r
203 abend("Invalid my console node number\n");
\r
204 ournode = console = c;
\r
206 if( argc==0 ) usage();
\r
207 /* here we test if we are remote */
\r
208 /* master will have number of slaves to wait for */
\r
209 /* slave - internet full address of master */
\r
210 if( strchr(*argv,':') ){
\r
211 /* internet address of master nn.nn.nn.nn:port */
\r
213 tcpip_connect_to_master( *argv );
\r
215 /* # of slaves to wait for */
\r
216 if( sscanf( *argv, "%d", &c ) != 1 ) usage();
\r
217 if( c < 0 || c >= 254 ) usage();
\r
218 tcpip_wait_for_slaves( c );
\r
230 if( argc==0 ) usage();
\r
231 if (sscanf( *argv, "%ld", &m ) != 1) usage();
\r
232 if (m <= 0 || m > MAXMEMSIZE)
\r
233 abend("Invalid memory size specified\n");
\r
241 } /* end of switch */
\r
242 else{ /* this is not option */
\r
243 if( filename != NULL ) usage();
\r
248 if( filename!=NULL )
\r
249 load(filename); /* load code and prototypes */
\r
257 eop = (extopcode *)(M+ic); /* pointer to extended opcode in M */
\r
258 lastic = ic; /* save ic for possible redecoding */
\r
260 opcode = ((int) eop->opcode ) & 0xFF ;
\r
261 getargument(a1, 0);
\r
262 getargument(a2, 1);
\r
263 getargument(a3, 2);
\r
267 int main(argc, argv)
\r
271 initiate(argc, argv); /* initialize executor */
\r
272 runsys(); /* initialize running system */
\r
274 setjmp(contenv); /* set label for continue long jump */
\r
275 while (TRUE) /* repeat until exit() is called */
\r
277 schedule(); /* reschedule current process */
\r
278 decode(); /* fetch instruction */
\r
279 execute(); /* and execute it */
\r