Pristine Ack-5.5
[Ack-5.5.git] / mach / pdp / int / em_int.s
1 /
2 /  (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 / See the copyright notice in the ACK home directory, in the file "Copyright".
4 /------------------------------------------------------------------------------
5 /\f
6 /       This is an interpreter for EM programs with no virtual memory
7 /       which is adapted from an EM1 interpreter by Hans van Staveren
8 /       by      Evert Wattel
9 /               Vrije Universiteit
10 /               Amsterdam
11 /
12 /       Memory layout:
13 /
14 /        interpreter  em-text  pd  global  tables  heap  unused stack
15 /       __________________________________________________________________
16 /       |            |       |    |       |       |     |      |      |  |
17 /       |            |       |    |       |       |     |      |      |  |
18 /       |      1     |   2   |  3 |   4   |   5   |  6  |      |  7   | 8|
19 /       |            |       |    |       |       |     |      |      |  |
20 /       |____________|_______|____|_______|_______|_____|______|______|__|
21 /
22 /       1:      Interpreter text+data+bss
23 /       2:      EM text
24 /       3:      EM procedure descriptors
25 /       4:      EM global data area
26 /       5:      flow, count and profile tables
27 /       6:      EM heap area
28 /       7:      EM local data and stack
29 /       8:      Arguments to interpreter
30 /
31 /       Assembly time flags:
32 /       .test  : controls checking for undefined variables,nil pointers,
33 /                array indices, etc....
34 /       .prof  : controls generation of a runtime profile
35 /       .opfreq: controls runtime frequency count per opcode
36 /       .flow  : controls generation of a flow bitmap
37 /       .count : controls generation of a flow count
38 /       .last  : controls generation of file with last 16
39 /                consecutive blocks of lines executed
40 /
41 /       Register layout:
42 /       pcx = EM programcounter
43 /       lb  = EM base-address
44 /       nxt = address of start of interpreter loop
45 /
46 /       The general structure of this interpreter is as follows:
47 /       The opcode byte of the instruction is placed in r0
48 /       with sign-extension and multiplied by 2.
49 /       If .opfreq is nonzero each occurence of each opcode is counted.
50 /       Then, if .prof is nonzero an estimation of the time required
51 /       to execute the instruction is added to a counter associated
52 /       with the source-line number. This estimation is roughly the
53 /       number of memory-cycles needed. At the end of this accounting
54 /       loprof points to the loword of the double precision counter.
55 /       This can be used by individual execution routines to add some
56 /       more to the counter depending on their operand.
57 /
58 /       NOTE: This interpreter can be loaded in separate I and D space
59 /
60 /\f
61 /------------------------------------------------------------------------------
62 /       Declaring of some constants
63 /------------------------------------------------------------------------------
64
65         nxt     = r4
66         pcx     = r3
67         lb      = r2
68
69         statd   = -8.
70
71         unixextra= 1280.        / extra memory asked by heap overflow
72         und     = 100000        / undefined memory pattern
73         signext = 177400        / high bits for signextension
74         EINVAL  = 22.           / UNIX error code for bad signal
75
76 / Interpreter options
77         .float   = 1
78         .opfreq = 0
79         .last   = 1
80         V7      = 1
81         V6      = 0
82         VPLUS   = 0
83         HARDWARE_FP     = 1
84 /------------------------------------------------------------------------------
85 /       EM1 machine errors (in the range 0-63)
86 /------------------------------------------------------------------------------
87
88         EARRAY  = 0.
89         ERANGE  = 1.
90         ESET    = 2.
91         EIOVFL  = 3.
92         EFOVFL  = 4.
93         EFUNFL  = 5.
94         EIDIVZ  = 6.
95         EFDIVZ  = 7.
96         EIUND   = 8.
97         EFUND   = 9.
98         ECONV   = 10.
99         ESTACK  = 16.
100         EHEAP   = 17.
101         EILLINS = 18.
102         EODDZ   = 19.
103         ECASE   = 20.
104         EMEMFLT = 21.
105         EBADPTR = 22.
106         EBADPC  = 23.
107         EBADLAE = 24.
108         EBADMON = 25.
109         EBADLIN = 26.
110         EBADGTO = 27.
111
112 /------------------------------------------------------------------------------
113 /       Declaring of some instructions unknown to the assembler
114 /------------------------------------------------------------------------------
115
116         next    = 10407         / = mov nxt,pc; jump to decode loop
117         rti     = 2             / return from interrupt
118         iot     = 4             / force core dump
119         stst    = 170300^tst    / store floating point status
120         indir   = 0             / for sys indir
121         exit    = 1
122         fork    = 2
123         read    = 3
124         write   = 4
125         open    = 5
126         close   = 6
127         creat   = 8.
128         break   = 17.
129         alarm   = 27.
130         pause   = 29.
131         sleep   = 35.
132         signal  = 48.
133
134 /------------------------------------------------------------------------------
135 /       External references
136 /------------------------------------------------------------------------------
137
138         .globl  _end
139
140 /\f
141 /------------------------------------------------------------------------------
142 /       Now the real program starts
143 /------------------------------------------------------------------------------
144
145 startoff:
146         mov     sp,r0
147         mov     sp,ml
148         mov     sp,filb
149         add     $2,filb         / pointer to argv in filb for error message
150         dec     (r0)
151         mov     (r0)+,argc      / pass to userprogram later
152         bgt     0f              / go for argument
153         mov     $emfile,forward+2    / e.out is load file default
154         mov     $forward+2,argv
155         br      1f
156 0:
157         tst     (r0)+           / skip interpreter name
158         mov     r0,argv         / pass to userprogram later
159         mov     (r0),forward+2       / argv filename to open call
160 1:
161 .if V7
162         tst     (r0)+           / increment r0 look for last arg
163         bne     1b
164         mov     r0,environ
165 .endif
166         sys     indir;forward
167         .data
168 forward:      sys     open;0;0
169 emfile: <e.out\0>
170 .even
171         .text
172         jes     badarg
173         mov     r0,saver0       / save filedescriptor
174         mov     r0,r5           / duplicate filedescriptor
175         sys     read;header;16. / skip first header
176         jes     badarg          / failed
177         mov     r5,r0           / recall fildes
178         sys     read;header;16. / read second header
179         jes     badarg          / failed
180         cmp     r0,$16.         / long enough ?
181         jne     badarg          / no.
182         mov     $_end,r0        / Bottom em-text
183         mov     r0,pb           / program base
184         add     txtsiz,r0       / reserve space for text
185         mov     r0,pd           / set up proc.descr base
186         mov     nprocs, r3      / number of procs
187         ash     $2,r3           / proc. descr is 4 bytes
188 .if .count +.prof + .flow
189         mul     $3,r3           / or 12 bytes
190 .endif
191         add     r3,r0           / reserve space
192         mov     r0,hp           / top of pd space, temporarily in hp
193         mov     r0,r3           / base for data fill
194
195         mov     $retsize,eb     / address of value containing 0, temporarily
196         add     szdata,r0       / size of external data
197         jcs     toolarge        / too much text and data
198         mov     r0,globmax      / maximum global
199         add     $1280.,r0       / bit extra core for setup
200         mov     r0,sybreak+2    / set up for core claim
201         sys     indir;sybreak   / ask for the core
202         jes     toolarge        / too much, sorry
203
204         mov     hp,eb           / top of pd space
205         mov     txtsiz,leescal+4     / set up for text read
206         mov     pb,leescal+2         / start address text read
207         mov     r5,r0           / file descriptor input
208         sys     indir;leescal        / read!!
209         .data
210 leescal:
211 1:      sys     read;0;0        / read call
212         .text
213 lblread:
214
215
216 / hier is nu dus de tekst ingelezen. De sybreak voor de
217 / tabellen  en de data moet opnieuw gebeuren.
218
219
220 .if .last
221         mov     $47.,r0
222         mov     $lasttab,r5
223 3:      clr     (r5)+
224         sob     r0,3b
225         mov     $-1,(r5)
226         sub     $96.,r5
227         mov     r5,linused
228 .endif
229 lblfloat:
230 .if .float
231         sys     signal;8.;sig8  / catch floating exception
232         ldfps   $7600
233         movf    $50200,fr3      / load 2^32 in fr3 for conversion
234                                 / unsigned to float
235 .endif
236
237
238         sys     signal;11.;sig11        / catch segmentation violation
239         sys     signal;12.;sig12        / catch bad system calls
240
241                         / We make a 1024 buffer for reading in
242                         / data descriptors. When the number of
243                         / bytes in the buffer is less than 512
244                         / we read another block. Descriptors of
245                         / more than 512 bytes are not allowed.
246                         / This is no restriction since they do
247                         / not fit in the descriptor format.
248 lblbuf:
249
250         sub     $02000,sp       / new buffer bottom
251         tst     (sp)            / ask for core
252         mov     sp,r4           / pointer in descriptor
253         mov     saver0,r0       / recall fildes
254         clr     r1              / clear registers for byte
255         clr     r2              / format instruction and data
256         mov     sp,r5           / copy
257         mov     r5,leescal+2    / set up for read
258         mov     $02000,leescal+4     / idem
259         sys     indir;leescal        / read
260         jes     badarg          / read failed
261         cmp     $02000,r0       / not yet eof?
262         bgt     0f              / eof encountered
263
264         add     $01000,r5       / buffer middle
265         mov     r5,saver1       / save buffermiddle to compare
266         br      datloop         / start data initialization
267 0:      add     r0,r5           / now pointer at top of file
268         mov     r5,saver1       / still set up for compare
269
270
271
272
273 datloop:
274         cmp     r4,saver1       / descriptor over middle?
275         blt     9f              / no? go ahead
276         jsr     pc,blshift      / yes? shift block down, read next
277
278 9:      dec     ndatad          / still data to initialize?
279         blt     finito          / no? go on
280         movb    (r4)+,r1        / opcode descriptor
281         beq     0f              / if 0 then go there
282         mov     r3,r5           / copy data pointer
283         clr     r2              / unsigned integer byte
284         bisb    (r4)+,r2        / "ored" in for data size
285         asl     r1              / make opcode even
286         mov     datswi(r1),pc  / main data swich
287
288 .data
289 datswi: 0;      dat1;   dat2;   dat3;   dat4;   dat5;   dat6;   dat6;   dofloat
290 .text
291 dat3:   asl     r2              / multiply with 2
292 dat2: 2: movb   (r4)+,(r3)+     / copy byte from buffer to data
293         sob     r2,2b           / until r2 is 0
294         br      datloop         / next datadescriptor
295
296
297 dat4:   mov     eb,r0           / external base should be added
298         br      2f              / for data pointers
299
300 dat5:   mov     pb,r0           / and program base for procedures
301
302 2:      movb    (r4)+,(r3)      / move in first byte of pointer
303         movb    (r4)+,1(r3)     / move in second byte of pointer
304         add     r0,(r3)+        / add pointer base
305         sob     r2,2b           / jump back if there is more
306         br      datloop         / next data descriptor
307
308 dat1:   mov     $und,(r3)+      / reserve words with undefineds
309         sob     r2,dat1         / jump back if more
310         br      datloop         / next data descriptor
311
312 0:      mov     r3,r1           / copy data pointer (odd register)
313         sub     r5,r1           / subtract previous pointer
314         movb    (r4)+,(r3)      / copy first byte of operand
315         movb    (r4)+,1(r3)     / copy second byte
316         mul     (r3),r1         / the number of bytes to copy
317 1:      movb    (r5)+,(r3)+     / is the product of the operand
318         sob     r1,1b           / and the number of bytes in the
319         br      datloop         / previous operation
320
321 dat6:   add     r2,r3           / new data pointer, the old is
322         mov     r3,r0           / still in r5
323         asr     r2              / divide by 2
324         beq     6f              / case 1 byte is special
325         sub     $2,r0           / this is the least significant
326                                 / byte in PDP11-standard
327 2:      movb    (r4)+,(r0)+     / copy low byte
328         movb    (r4)+,(r0)      / copy high byte
329         sub     $3,r0           / next lowest byte
330         sob     r2,2b           / jump if not ready
331         br      datloop         / next descriptor
332 6:      movb    (r4)+,(r5)      / copy one byte
333         br      datloop         / next descriptor
334
335 blshift:
336         mov     saver1,r1       / bottom of top half
337         mov     r1,r2           / set up bottom
338         sub     $01000,r2
339         mov     $1000,r0        / number to copy
340         mov     r0,leescal+4         / amount to read
341         sub     r0,r4           / decrease pointer
342         asr     r0              / 512 bytes is 256 words
343 3:      mov     (r1)+,(r2)+     / copy top half in bottom half
344         sob     r0,3b
345         mov     saver1,leescal+2     / set up for read
346 blockr:
347         mov     saver0,r0               / filedescriptor
348         sys     indir;leescal
349         jes     badarg
350         clr     r1              / clear registers which contain
351         clr     r2              / descriptor bytes later
352         cmp     $01000,r0       / look if eof is encountered
353         beq     3f              / yes? go on
354         add     r0,saver1       / no extra read necessary
355 3:      rts     pc
356
357 finito:
358        cmp     globmax,r3           / test if data size ok
359        jne     badarg          / load file error
360         mov     eb,filb
361         add     $4,filb
362
363
364         mov     nprocs,r5       / set up for procdesc read
365         mov     pd,r3           / proc descriptor base
366         asl     r5              / multiply with 4 because
367         asl     r5              / procdes is 4 bytes
368 1:      mov     saver1,r1       / look what is available
369         sub     r4,r1           / in buffer to be read
370         add     $3,r1           / let it be a multiple
371         bic     $3,r1           / of four
372         sub     r1,r5           / subtract what can be read
373         asr     r1;   asr  r1;  / divide by four
374 0:
375         movb    (r4)+,(r3)+     / copy byte
376         movb    (r4)+,(r3)+     / copy byte
377         movb    (r4)+,(r3)+     / copy byte
378         movb    (r4)+,(r3)+     / copy byte
379         add     pb,-2(r3)       / change em-address in pdp-address
380 .if .count + .prof + .flow
381         clr     (r3)+
382         clr     (r3)+
383         clr     (r3)+
384         clr     (r3)+
385 .endif
386         sob     r1,0b           / look if there is more
387         tst     r5              / is there still a descriptor
388         ble     2f;             / no? go on
389         jsr     pc,blshift      / yes? read again
390         br      1b
391
392 2:
393         cmp     eb,r3        / test if procdes is ok
394         jne     badarg          / load file error
395         mov     saver0,r0       / fildes in r0
396         sys     close           / close input load file
397         mov     ml,sp           / fresh stack
398         mov     2(sp),*filb
399 .if .flow + .count + .prof
400 /                                          |==================|
401 / Here we fill the fields in the procedure | bytes for locals |
402 / descriptor with table information. The   |------------------|
403 / procedure descriptor has six fields,     |  start address   |
404 / like described in this picture. We       |------------------|
405 / construct a linked list of the proc.     |  count pointer   |
406 / descriptors, such that the defined       |------------------|
407 / order of procedures is compatible        |   first line nr  |
408 / with the text order. Thereafter we       |------------------|
409 / scan the text for line information to    |  link next proc  |
410 / fill the countpointer and startline      |------------------|
411 / field. The link to the first proc.       | current file name|
412 / is in firstp, links are descriptor       |==================|
413 / start addresses. The last procedure
414 / links to the external base. All lines in the text get a count
415 / number, lines of a procedure get consecutive count numbers,
416 / the procedure count pointer gives the number of the first line.
417 / Count pointer zero is reserved for the case that no line number
418 / is yet defined.
419
420 makelink:
421         mov     pd,r0           / first descriptor
422         mov     r0,r3           / points to first proc
423         mov     r0,r4           / pd in register
424         mov     eb,r5           / eb in register
425
426 0:      mov     r0,r1           / copy old descriptor bottom
427         add     $12.,r0         / next descriptor
428         cmp     r0,r5           / top of descriptor space
429         bhis    4f              / ready? continue
430 1:      cmp     2(r0),2(r1)     / compare start addresses
431         bhis    2f              / 2(r0) large? follow link
432         sub     $12.,r1         / 2(r0) small? previous descriptor
433         cmp     r1,r4           / is r1 smaller than pd?
434         bhis    1b              / no? try again
435         mov     r3,8.(r0)       / yes? then r0 has small text address
436         mov     r0,r3           / now r3 again points to first proc
437         br      0b              / next descriptor
438
439 2:      mov     8.(r1),r2       / follow link to compare with 2(r0)
440         beq     3f              / if 0 then no link defined
441         cmp     2(r0),2(r2)     / compare start addresses
442         blo     3f              / r0 between r1 and r2
443         mov     r2,r1           / r0 above r2,
444         br      2b              / look again.
445
446 3:      mov     r0,8.(r1)       / link of r1 points to r0
447         mov     r2,8.(r0)       / link of r0 points to r2
448         br      0b              / next descriptor
449
450 4:      mov     r3,firstp       / firstp links to first procedure
451
452 procinf:
453         mov     $1,maxcount     / countptr for first proc
454         mov     r3,r4           / points to first proc
455
456 0:      mov     r3,-(sp)        / stack current procedure
457         mov     $-1,r1          / minimal line number 0177777
458         clr     r5              / maximum line number on 0
459         mov     8.(r3),r4       / bottom address next descriptor
460         beq     6f              / if 0 last procedure
461         mov     2(r4),r4        / top of current procedure
462         br      2f              / start looking for lines
463 6:      mov     pd,r4           / top of last procedure
464 2:
465         mov     2(r3),r3        / start text address procedure
466 8:      movb    (r3)+,r2        / first opcode for scanning
467         cmp     $-2,r2          / case escape
468         beq     1f              / escape treated at label 1
469         cmp     $-106.,r2       / case lni
470         blt     7f              / ordinary skip at label 7
471         beq     2f              / lni treated at label 2
472         cmp     $-108.,r2       / case lin.l
473         bgt     7f              / ordinary skip at label 7
474         beq     3f              / lin.l at label 3
475         clr     r0              / lin.s0 treated here
476         bisb    (r3)+,r0        / line number in r0
477         br      4f              / compares at label 4
478 2:      inc     r0              / lni increases line number
479         br      4f              / compares at label 4
480 3:      jsr     pc,wrdoff       / get 2 byte number
481 4:
482         cmp     r1,r0           / look if r0 less than minimum
483         blo     5f              / nothing to declare
484         mov     r0,r1           / r0 new minimum
485 5:      cmp     r0,r5           / look if r0 more than maximum
486         blo     9f              / nothing spectacular
487         mov     r0,r5           / r0 new maximum
488         br      9f              / line processed
489
490 1:      clr     r2
491         bisb    (r3)+,r2        / escaped instruction opcode
492         add     $128.,r2        / ready for table entry
493 7:      movb    skipdisp(r2),r2 / skip the required number of bytes
494         add     r2,r3
495
496 9:      cmp     r3,r4           / still more text in this proc?
497         blt     8b              / yes? again
498 filpd:
499         mov     (sp)+,r3        / get bottom descriptor back
500         sub     r1,r5           / number of lines encountered
501         bcs     9f              / no lines then no file information
502         mov     maxcount,4(r3)  / this is the count pointer
503         mov     r1,6(r3)        / minimum line in descriptor
504         inc     r5
505         add     r5,maxcount     / this is the new maximum
506 9:      mov     8.(r3),r3       / follow link to next procedure
507         bne     0b              / restart
508 .data
509 .byte 2; .byte 2; .byte 0; .byte 0; .byte 1; .byte 1; .byte 1; .byte 0;
510 .byte 0; .byte 2; .byte 1; .byte 0; .byte 1; .byte 0; .byte 0; .byte 1;
511 .byte 1; .byte 1; .byte 0; .byte 0; .byte 2; .byte 1; .byte 0; .byte 2;
512 .byte 0; .byte 1; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
513 .byte 1; .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 2;
514 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 2; .byte 2;
515 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
516 .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 1; .byte 0; .byte 0;
517
518 .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1;
519 .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 1; .byte 1; .byte 1;
520 .byte 1; .byte 0; .byte 2; .byte 1; .byte 1; .byte 1; .byte 2; .byte 0;
521 .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1;
522 .byte 2; .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
523 .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 2; .byte 1;
524 .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1;
525 .byte 2; .byte 1; .byte 0; .byte 0; .byte 1; .byte 2; .byte 7; .byte 5;
526
527 skipdisp:
528 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
529 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
530 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
531 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
532 .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 2; .byte 0;
533 .byte 0; .byte 1; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
534 .byte 0; .byte 0; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
535 .byte 1; .byte 1; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
536
537 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
538 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
539 .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
540 .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0;
541 .byte 1; .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0;
542 .byte 1; .byte 1; .byte 0; .byte 1; .byte 0; .byte 2; .byte 0; .byte 2;
543 .byte 1; .byte 0; .byte 0; .byte 0; .byte 1; .byte 1; .byte 0; .byte 1;
544 .byte 2; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1;
545
546 /escaped opcodes
547
548 .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
549 .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 0; .byte 2;
550 .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 2; .byte 0;
551 .byte 2; .byte 0; .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
552 .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
553 .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 2; .byte 2; .byte 2;
554 .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
555 .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
556
557 .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
558 .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 1;
559 .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
560 .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 0; .byte 2;
561 .byte 0; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
562 .byte 2; .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
563 .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
564 .byte 2; .byte 2; .byte 0; .byte 0; .byte 2; .byte 2; .byte 0; .byte 2;
565
566 .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
567 .byte 2; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 2; .byte 0;
568 .byte 2; .byte 0; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2;
569 .byte 0; .byte 2; .byte 0; .byte 1; .byte 2; .byte 0; .byte 0; .byte 2;
570 .text
571         mov     globmax,r3      / bottom of table space
572         mov     r3,r5           / copy
573 .if .prof
574         mov     r3,ltime        / set up pointer to base
575 mov     r3,hiprof
576 mov     r3,loprof
577 add     $2,loprof
578         mov     maxcount,r0     / number of lines
579         inc     r0
580         asl     r0              / four byter per prof count
581         asl     r0
582         add     r0,r3
583         mov     r0,profsiz
584 .endif
585 .if .flow
586         mov     r3,lflow        / set up pointer to base
587         mov     maxcount,r0
588         ash     $-3,r0          / divide by 8
589         add     $2,r0
590         bic     $1,r0           / Rounded up to an integral number of words
591         add     r0,r3
592         mov     r0,flowsiz
593 .endif
594 .if .count
595         mov     r3,lcount       / set up pointer
596         mov     maxcount,r0
597         inc     r0
598         ash     $2,r0           / multiply by 4
599         add     r0,r3
600         mov     r0,countsiz
601 .endif
602         mov     r3,tblmax
603         cmp     r3,sybreak+2    / core available for tables?
604         blos    2f
605         mov     r3,sybreak+2
606         sys     indir;sybreak   / ask for core
607 2:      sub     r5,r3           / this amount of space required
608         asr     r3
609 2:      clr     (r5)+           / clear table space
610         sob     r3,2b
611 .endif
612 .if  [1 - .count] * [1 - .flow] * [1 - .prof]
613         mov     globmax,tblmax
614 .endif
615
616                      / start calling sequence here
617 calseq:
618         mov     tblmax,hp
619         mov     pd,r3           / top of em-text and top of stack
620         clr     r2              / are dummy return values
621         mov     environ,-(sp)   / setup environment pointer
622         mov     argv,-(sp)      / setup argument pointer
623         mov     *argv,*filb     / setup first file message
624         mov     argc,-(sp)      / setup argument count
625         mov     entry.,-(sp)    / start procedure to call
626 precal:
627         mov     $loop,r4        / main loop address in r4
628         jbr     cai.z           / according to the cai
629
630 noarg:  mov     r0,argv
631         mov     $0f,r0;         jbr     rude_error
632 badarg: mov     $1f,r0;         jbr     rude_error
633 toolarge:mov    $2f,r0;         jbr     rude_error
634
635
636         .data
637 0:      <no load file\0>
638 1:      <load file error\0>
639 2:      <program too large\0>
640         .even
641         .text
642
643
644 dofloat:
645         jsr     pc,atof
646         mov     r5,r3           / restore r3
647                                 / Assumed that the result is 8
648                                 / bytes Recall r2 and move the
649                                 / amount of bytes asked for
650         clr     r1              / restore for opcode
651         sub     $8.,r2          / 8 bytes?
652         beq     1f              / yes! later, 4 bytes next
653         movfo   fr0,-(sp)       / push result
654         mov     (sp)+,(r3)+     / write result in data
655         mov     (sp)+,(r3)+     / idem
656         jbr     datloop         / next loop
657 1:      movf    fr0,-(sp)       / push result
658         mov     (sp)+,(r3)+     / write result in data
659         mov     (sp)+,(r3)+     / write result in data
660         mov     (sp)+,(r3)+     / write result in data
661         mov     (sp)+,(r3)+     / write result in data
662         jbr     datloop
663 atof:
664         mov     r2,-(sp)                / save byte count
665         clr     -(sp)
666         clrf    fr0
667         clr     r2
668 1:
669         movb    (r4)+,r0                / get byte
670         cmp     $' ,r0
671         bge     1b
672         cmpb    r0,$'+
673         beq     1f
674         cmpb    r0,$'-
675         bne     2f
676         inc     (sp)
677 1:
678         movb    (r4)+,r0                / get next byte
679 2:
680         sub     $'0,r0
681         cmp     r0,$9.
682         bhi     2f
683         jsr     pc,digit
684                 br 1b
685         inc     r2
686         br      1b
687 2:
688         cmpb    r0,$'.-'0
689         bne     2f
690 1:
691         movb    (r4)+,r0                / get next byte
692         sub     $'0,r0
693         cmp     r0,$9.
694         bhi     2f
695         jsr     pc,digit
696                 dec r2
697         br      1b
698 2:
699         cmpb    r0,$'E-'0
700         beq     3f
701         cmpb    r0,$'e-'0
702         bne     1f
703 3:
704         clr     r3
705         clr     r1
706         movb    (r4)+,r0                / get next byte
707         cmpb    r0,$'+
708         beq     3f
709         cmpb    r0,$'-
710         bne     5f
711         inc     r3
712 3:
713         movb    (r4)+,r0                / get next byte
714 5:
715         sub     $'0,r0
716         cmp     r0,$9.
717         bhi     3f
718         mul     $10.,r1
719         add     r0,r1
720         br      3b
721 3:
722         tst     r3
723         bne     3f
724         neg     r1
725 3:
726         sub     r1,r2
727 1:
728         movf    $one,fr1
729         movf    $one,fr2
730         mov     r2,-(sp)
731         beq     2f
732         bgt     1f
733         neg     r2
734 1:
735         mulf    $twohalf,fr1
736         mulf    $four,fr2
737         sob     r2,1b
738 2:
739         tst     (sp)+
740         bge     1f
741         divf    fr1,fr0
742         divf    fr2,fr0
743         br      2f
744 1:
745         mulf    fr1,fr0
746         mulf    fr2,fr0
747 2:
748         tst     (sp)+
749         beq     1f
750         negf    fr0
751 1:      mov     (sp)+,r2
752         rts     pc
753
754
755 digit:
756         cmpf    $big,fr0
757         cfcc
758         blt     1f
759         mulf    $ten,fr0
760         movif   r0,fr1
761         addf    fr1,fr0
762         rts     pc
763 1:
764         add     $2,(sp)
765         rts     pc
766 /
767 /
768 one     = 40200
769 twohalf = 40440
770 four    = 40600
771 ten     = 41040
772 big     = 56200
773 huge    = 77777
774
775
776 /------------------------------------------------------------------------------
777 /------------------------------------------------------------------------------
778 /       Main loop of interpreter starts here
779 /------------------------------------------------------------------------------
780
781 loop:
782         movb    (pcx)+,r0               / pickup opcode + sign extend
783 9:      asl     r0                      / opcode now -256 .. 254 & even
784
785 .if .opfreq
786         mov     r0,r1
787         asl     r1                      / multiply by two again
788         add     $1,counttab+514.(r1)    / cannot be inc
789         adc     counttab+512.(r1)       / double precision counters
790 .endif
791 .if .prof
792         add     timeinf(r0),*loprof
793         adc     *hiprof                    / double precision
794 .endif
795         mov     dispat(r0),pc           / fast dispatch
796
797 /------------------------------------------------------------------------------
798 /       Two byte opcodes come here for decoding of second byte
799 /------------------------------------------------------------------------------
800
801 escape1:
802         clr     r0
803         bisb    (pcx)+,r0               / fetch second byte no sign extend
804         asl     r0                      / 0 to 512 & even
805         cmp     $0500,r0                / look for righ range
806         jlt     e.illins
807
808 .if .opfreq
809         mov     r0,r1
810         asl     r1                      / multiply by two again
811         add     $1,counttab+1026.(r1)   / cannot be inc
812         adc     counttab+1024.(r1)      / double precision counters
813 .endif
814 .if .prof
815         add     time2inf(r0),*loprof
816         adc     *hiprof                    / double precision
817 .endif
818         mov     dispae1(r0),pc            / fast dispatch
819
820 /----------------------------------------------------------------------------
821 escape2:
822         movb    (pcx)+,r0               / fetch second byte and sign extend
823         jne     e.illins
824
825 .if .opfreq
826         add     $1,counttab+1666.       / cannot be inc
827         adc     counttab+1664.          / double precision counters
828 .endif
829         jbr     loc.f                   / fast dispatch
830 /------------------------------------------------------------------------------
831 /       dispatch tables, first the unescaped opcodes
832 /
833 /       name convention is as follows:
834 /       each execution routine has as a name the name of the instruction
835 /       followed by a dot and a suffix.
836 /       suffix can be an integer (sometimes followed by a W),
837 /       an 's'or a 'w', followed by an integer, an 'l' ,a 'p' ,
838 /       a 'n', sometimes followed by a 'w',  or a 'z'.
839 /       loc.1           routine to execute loc 1
840 /       zge.s0          routine to execute zge 0 thru 255
841 /       lae.w1          routine to execute lae 1024 thru lae 2046
842 /       lof.2W          routine to execute lof 2*the word size
843 /       lol.pw          routine to execute positive lol instructions
844 /       loe.l           routine to execute all loe instructions
845 /       add.z           routine to execute instruction without operand
846 /                       or with operand on the stack.
847 /------------------------------------------------------------------------------
848         .data
849
850
851
852 lal.p;   lal.n;   lal.0;   lal._1;  lal.w0;  lal.w_1; lal.w_2; lar.1W
853 ldc.0;   lde.lw;  lde.w0;  ldl.0;   ldl.w_1; lfr.1W;  lfr.2W;  lfr.s0
854 lil.w_1; lil.w0;  lil.0;   lil.1W;  lin.l;   lin.s0;  lni.z;   loc.l
855 loc._1;  loc.s0;  loc.s_1; loe.lw;  loe.w0;  loe.w1;  loe.w2;  loe.w3
856 loe.w4;  lof.l;   lof.1W;  lof.2W;  lof.3W;  lof.4W;  lof.s0;  loi.l
857 loi.1;   loi.1W;  loi.2W;  loi.3W;  loi.4W;  loi.s0;  lol.pw;  lol.nw
858 lol.0;   lol.1W;  lol.2W;  lol.3W;  lol._1W; lol._2W; lol._3W; lol._4W
859 lol._5W; lol._6W; lol._7W; lol._8W; lol.w0;  lol.w_1; lxa.1;   lxl.1
860 lxl.2;   mlf.s0;  mli.1W;  mli.2W;  rck.1W;  ret.0;   ret.1W;  ret.s0
861 rmi.1W;  sar.1W;  sbf.s0;  sbi.1W;  sbi.2W;  sdl.w_1; set.s0;  sil.w_1
862 sil.w0;  sli.1W;  ste.lw;  ste.w0;  ste.w1;  ste.w2;  stf.l;   stf.1W
863 stf.2W;  stf.s0;  sti.1;   sti.1W;  sti.2W;  sti.3W;  sti.4W;  sti.s0
864 stl.pw;  stl.nw;  stl.0;   stl.1W;  stl._1W; stl._2W; stl._3W; stl._4W
865 stl._5W; stl.w_1; teq.z;   tgt.z;   tlt.z;   tne.z;   zeq.l;   zeq.s0
866 zeq.s1;  zer.s0;  zge.s0;  zgt.s0;  zle.s0;  zlt.s0;  zne.s0;  zne.s_1
867 zre.lw;  zre.w0;  zrl._1W; zrl._2W; zrl.w_1; zrl.nw;  escape1; escape2
868
869
870 dispat:               / dispatch table for unescaped opcodes
871
872
873 loc.0;   loc.1;   loc.2;   loc.3;   loc.4;   loc.5;   loc.6;   loc.7
874 loc.8;   loc.9;   loc.10;  loc.11;  loc.12;  loc.13;  loc.14;  loc.15
875 loc.16;  loc.17;  loc.18;  loc.19;  loc.20;  loc.21;  loc.22;  loc.23
876 loc.24;  loc.25;  loc.26;  loc.27;  loc.28;  loc.29;  loc.30;  loc.31
877 loc.32;  loc.33;  aar.1W;  adf.s0;  adi.1W;  adi.2W;  adp.l ;  adp.1
878 adp.2;   adp.s0;  adp.s_1; ads.1W;  and.1W;  asp.1W;  asp.2W;  asp.3W
879 asp.4W;  asp.5W;  asp.w0;  beq.l;   beq.s0;  bge.s0;  bgt.s0;  ble.s0
880 blm.s0;  blt.s0;  bne.s0;  bra.l;   bra.s_1; bra.s_2; bra.s0;  bra.s1
881 cal.1;   cal.2;   cal.3;   cal.4;   cal.5;   cal.6;   cal.7;   cal.8
882 cal.9;   cal.10;  cal.11;  cal.12;  cal.13;  cal.14;  cal.15;  cal.16
883 cal.17;  cal.18;  cal.19;  cal.20;  cal.21;  cal.22;  cal.23;  cal.24
884 cal.25;  cal.26;  cal.27;  cal.28;  cal.s0;  cff.z;   cif.z;   cii.z
885 cmf.s0;  cmi.1W;  cmi.2W;  cmp.z;   cms.s0;  csa.1W;  csb.1W;  dec.z
886 dee.w0;  del.w_1; dup.1W;  dvf.s0;  dvi.1W;  fil.l;   inc.z;   ine.lw
887 ine.w0;  inl._1W; inl._2W; inl._3W; inl.w_1; inn.s0;  ior.1W;  ior.s0
888 lae.l;   lae.w0;  lae.w1;  lae.w2;  lae.w3;  lae.w4;  lae.w5;  lae.w6
889
890
891
892 /------------------------------------------------------------------------------
893 /       now dispatch table for escaped opcodes
894 /------------------------------------------------------------------------------
895
896 dispae1:      /dispatch escaped opcodes 1
897
898 aar.l;   aar.z;   adf.l;   adf.z;   adi.l;   adi.z;   ads.l;   ads.z
899 adu.l;   adu.z;   and.l;   and.z;   asp.lw;  ass.l;   ass.z;   bge.l
900 bgt.l;   ble.l;   blm.l;   bls.l;   bls.z;   blt.l;   bne.l;   cai.z
901 cal.l;   cfi.z;   cfu.z;   ciu.z;   cmf.l;   cmf.z;   cmi.l;   cmi.z
902 cms.l;   cms.z;   cmu.l;   cmu.z;   com.l;   com.z;   csa.l;   csa.z
903 csb.l;   csb.z;   cuf.z;   cui.z;   cuu.z;   dee.lw;  del.pw;  del.nw
904 dup.l;   dus.l;   dus.z;   dvf.l;   dvf.z;   dvi.l;   dvi.z;   dvu.l
905 dvu.z;   fef.l;   fef.z;   fif.l;   fif.z;   inl.pw;  inl.nw;  inn.l
906 inn.z;   ior.l;   ior.z;   lar.l;   lar.z;   ldc.l;   ldf.l;   ldl.pw
907 ldl.nw;  lfr.l;   lil.pw;  lil.nw;  lim.z;   los.l;   los.z;   lor.s0
908 lpi.l;   lxa.l;   lxl.l;   mlf.l;   mlf.z;   mli.l;   mli.z;   mlu.l
909 mlu.z;   mon.z;   ngf.l;   ngf.z;   ngi.l;   ngi.z;   nop.z;   rck.l
910 rck.z;   ret.l;   rmi.l;   rmi.z;   rmu.l;   rmu.z;   rol.l;   rol.z
911 ror.l;   ror.z;   rtt.z;   sar.l;   sar.z;   sbf.l;   sbf.z;   sbi.l
912 sbi.z;   sbs.l;   sbs.z;   sbu.l;   sbu.z;   sde.l;   sdf.l;   sdl.pw
913 sdl.nw;  set.l;   set.z;   sig.z;   sil.pw;  sil.nw;  sim.z;   sli.l
914
915
916
917
918
919
920 sli.z;   slu.l;   slu.z;   sri.l;   sri.z;   sru.l;   sru.z;   sti.l
921 sts.l;   sts.z;   str.s0;  tge.z;   tle.z;   trp.z;   xor.l;   xor.z
922 zer.l;   zer.z;   zge.l;   zgt.l;   zle.l;   zlt.l;   zne.l;   zrf.l
923 zrf.z;   zrl.pw;  dch.z;   exg.s0;  exg.l;   exg.z;   lpb.z;   gto.l
924
925 /------------------------------------------------------------------------------
926 /       timeinf tables, first the unescaped opcodes
927 /       these tables are parallel to the tables dispat and dispae1
928 /       Each entry contains a reasonable estimate of
929 /       the number of memory-cycles needed to
930 /       execute that instruction. The exact amount cannot be
931 /       supplied, since this can depend rather heavily on the
932 /       size of the object in set, array case instructions etc.
933 /       The table timeinf also contains, added to each entry,
934 /       the number of memory-cycles needed to decode the instruction.
935 /       This number is currently 6. The number is computed for
936 /       the case that all check and runinf options are off.
937 /------------------------------------------------------------------------------
938 .if .prof
939 23.;    23.;    12.;    12.;    18.;    17.;    19.;    61.
940 11.;    31.;    21.;    15.;    20.;    30.;    30.;    31.
941 20.;    18.;    18.;    19.;    29.;    18.;    13.;    20.
942 10.;    14.;    13.;    27.;    20.;    20.;    20.;    20.
943 20.;    23.;    16.;    16.;    16.;    16.;    17.;    38.
944 14.;    26.;    26.;    26.;    26.;    28.;    26.;    25.
945 11.;    11.;    11.;    11.;    11.;    11.;    11.;    11.
946 11.;    11.;    11.;    11.;    16.;    16.;    26.;    24.
947
948 24.;    53.;    25.;    25.;    18.;    27.;    44.;    54.
949 30.;    59.;    53.;    21.;    28.;    19.;    51.;    18.
950 18.;    21.;    27.;    19.;    20.;    18.;    25.;    16.
951 16.;    15.;    12.;    24.;    24.;    24.;    24.;    25.
952 26.;    25.;    15.;    13.;    11.;    11.;    11.;    11.
953 11.;    16.;    14.;    14.;    14.;    14.;    20.;    16.
954 16.;    21.;    16.;    16.;    16.;    16.;    16.;    16.
955 26.;    16.;    10.;    10.;    15.;    24.;    10.;    40.
956
957 timeinf:
958
959  9.;    10.;    10.;    10.;    10.;    10.;    10.;    10.
960 10.;    10.;    10.;    10.;    10.;    10.;    10.;    10.
961 10.;    10.;    10.;    10.;    10.;    10.;    10.;    10.
962 10.;    10.;    10.;    10.;    10.;    10.;    10.;    10.
963 10.;    10.;    48.;    53.;    21.;    28.;    20.;    10.
964 10.;    12.;    13.;    11.;    44.;    11.;    11.;    11.
965 11.;    11.;    27.;    21.;    17.;    17.;    17.;    17.
966 81.;    17.;    17.;    21.;    12.;    12.;    11.;    12.
967
968 54.;    54.;    54.;    54.;    54.;    54.;    54.;    54.
969 54.;    54.;    54.;    54.;    54.;    54.;    54.;    54.
970 54.;    54.;    54.;    54.;    54.;    54.;    54.;    54.
971 54.;    54.;    54.;    54.;    54.;    41.;    49.;    37.
972 40.;    53.;    53.;    51.;    60.;    24.;    41.;    11.
973 20.;    19.;    10.;    53.;    30.;    29.;    11.;    30.
974 20.;    15.;    15.;    15.;    19.;    44.;    37.;    36.
975 25.;    19.;    19.;    19.;    19.;    19.;    19.;    19.
976
977 /------------------------------------------------------------------------------
978 /       time2inf table for escaped opcodes
979 /       cycles necessary for decoding is already accounted for in timeinf
980 /------------------------------------------------------------------------------
981
982 time2inf:
983
984 57.;    46.;    61.;    50.;    37.;    26.;    30.;    19.
985 45.;    34.;    52.;    41.;    37.;    42.;    31.;    21.
986 21.;    21.;    91.;   108.;    97.;    21.;    21.;    53.
987 60.;    56.;    55.;    26.;    53.;    42.;    62.;    51.
988 72.;    61.;    72.;    61.;    38.;    27.;    40.;    29.
989 53.;    46.;    54.;    38.;    23.;    30.;    30.;    28.
990 36.;    45.;    34.;    61.;    50.;    39.;    28.;    44.
991 33.;    68.;    57.;    68.;    57.;    30.;    28.;    54.
992
993 45.;    44.;    33.;    70.;    59.;    22.;    27.;    28.
994 29.;    37.;    28.;    27.;    11.;    47.;    40.;    21.
995 20.;    35.;    33.;    61.;    50.;    34.;    23.;    39.
996 28.;   500.;    47.;    36.;    41.;    30.;   100.;    38.
997 27.;    62.;    39.;    28.;    44.;    33.;    88.;    77.
998 92.;    81.;    32.;    68.;    57.;    61.;    50.;    37.
999 26.;    33.;    22.;    45.;    34.;    29.;    28.;    30.
1000 28.;    61.;    52.;    16.;    28.;    27.;    11.;    30.
1001
1002 19.;    36.;    25.;    32.;    21.;    36.;    25.;    31.
1003 39.;    32.;    32.;    14.;    14.;   117.;    45.;    34.
1004 31.;    22.;    20.;    20.;    20.;    20.;    20.;    27.
1005 16.;    26.;    17.;    39.;    47.;    36.;    10.;    29.
1006 .endif
1007              .text
1008 /------------------------------------------------------------------------------
1009 /       LOAD CONSTANT, LOAD LOCAL, STORE LOCAL
1010 /------------------------------------------------------------------------------
1011
1012 loc.0:  clr     -(sp)
1013         next
1014 loc.1:  loc.2:  loc.3:  loc.4:  loc.5:  loc.6:  loc.7:  loc.8:
1015 loc.9:  loc.10: loc.11: loc.12: loc.13: loc.14: loc.15: loc.16:
1016 loc.17: loc.18: loc.19: loc.20: loc.21: loc.22: loc.23: loc.24:
1017 loc.25: loc.26: loc.27: loc.28: loc.29: loc.30: loc.31: loc.32:
1018 loc.33:
1019         asr     r0              / make multiplication undone
1020         mov     r0,-(sp)
1021         next
1022 loc._1:
1023         mov     $-1,-(sp)
1024         next
1025 loc.s0:
1026         clr     r0
1027         br      2f
1028 loc.s_1:
1029         mov     $-400,r0
1030 2:      bisb    (pcx)+,r0
1031         mov     r0,-(sp)
1032         next
1033 lpi.l:                          / let op, dit is een pointer
1034                                 / zonder offset op het moment!
1035 loc.l:
1036         jsr     pc,wrdoff
1037         mov     r0,-(sp)
1038         next
1039 ldc.0:
1040         clr     -(sp)
1041         clr     -(sp)
1042         next
1043 ldc.l:
1044         jsr     pc,wrdoff
1045         mov     r0,-(sp)
1046         sxt    -(sp)
1047         next
1048
1049 loc.f:  jsr     pc,wrdoff;      mov     r0,r1
1050         jsr     pc,wrdoff;      mov     r0,-(sp)
1051         mov     r1,-(sp);       next
1052
1053 /__________________________________________________________________________
1054
1055 lol.0:          mov     010(r2),-(sp);  next
1056 lol.1W:         mov     012(r2),-(sp);  next
1057 lol.2W:         mov     014(r2),-(sp);  next
1058 lol.3W:         mov     016(r2),-(sp);  next
1059 lol._1W:        mov     -02(r2),-(sp);  next
1060 lol._2W:        mov     -04(r2),-(sp);  next
1061 lol._3W:        mov     -06(r2),-(sp);  next
1062 lol._4W:        mov     -010(r2),-(sp); next
1063 lol._5W:        mov     -012(r2),-(sp); next
1064 lol._6W:        mov     -014(r2),-(sp); next
1065 lol._7W:        mov     -016(r2),-(sp); next
1066 lol._8W:        mov     -020(r2),-(sp); next
1067
1068 lol.w0:         clr     r0;             bisb    (pcx)+,r0
1069 5:              asl     r0;             add     r2,r0
1070                 mov     010(r0),-(sp);  next
1071 lol.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1072 2:              asl     r0;             add     r2,r0
1073                 mov     (r0),-(sp);     next
1074 lol.pw:         jsr     pc,wrdoff;      br      5b
1075 lol.nw:         jsr     pc,wrdoff;      br      2b
1076
1077 /------------------------------------------------------------------------------
1078
1079 ldl.0:          mov     10.(r2),-(sp);  mov     8.(r2),-(sp);    next
1080 ldl.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1081 2:              asl     r0;             add     r2,r0
1082                 mov     2(r0),-(sp);    mov     (r0),-(sp);    next
1083 ldl.pw:         jsr     pc,wrdoff;      asl     r0
1084                 add     r2,r0;          mov     10.(r0),-(sp)
1085                 mov     8.(r0),-(sp);   next
1086 ldl.nw:         jsr     pc,wrdoff;      br      2b
1087
1088 /------------------------------------------------------------------------------
1089 loe.lw:         jsr     pc,wrdoff;      br      2f
1090 loe.w0:         loe.w1:         loe.w2:         loe.w3:         loe.w4:
1091                 asr     r0;             add     $0144,r0
1092                 swab    r0;             bisb    (pcx)+,r0
1093 2:              asl     r0;             add     eb,r0
1094                 mov     (r0),-(sp);     next
1095 lde.lw:         jsr     pc,wrdoff;      br      2f
1096 lde.w0:         clr     r0;             bisb    (pcx)+,r0
1097 2:              asl     r0;             add     eb,r0
1098                 mov     2(r0),-(sp);    mov     (r0),-(sp);    next
1099
1100
1101 /------------------------------------------------------------------------------
1102 lil.0:          clr     r0;             br      1f
1103 lil.1W:         mov     $1,r0;          br      1f
1104 lil.pw:         jsr     pc,wrdoff;      br      1f
1105 lil.w0:         clr     r0;             bisb    (pcx)+,r0
1106 1:              add     $04,r0
1107 2:              asl     r0;             add     r2,r0
1108                 mov     (r0),-(sp);     jsr     pc,chckptr
1109                 mov     *(sp),(sp);     next
1110 lil.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0;    br      2b
1111 lil.nw:         jsr     pc,wrdoff;      br     2b
1112 /------------------------------------------------------------------------------
1113 lof.l:          jsr     pc,wrdoff
1114 1:              jsr     pc,chckptr;     add     (sp)+,r0;
1115                 mov     (r0),-(sp);    next
1116
1117 lof.1W:         lof.2W:         lof.3W:         lof.4W:
1118                 add     $0276,r0;
1119                 br      1b
1120 lof.s0:         clr     r0;             bisb    (pcx)+,r0;      br      1b
1121 ldf.l:          jsr     pc,wrdoff;      add     (sp)+,r0
1122                 mov     2(r0),-(sp);    mov     (r0),-(sp);     next
1123 /------------------------------------------------------------------------------
1124 lal.p:          jsr     pc,wrdoff
1125 5:              add     r2,r0;          add     $8.,r0
1126                 mov     r0,-(sp);       next
1127 lal.0:          mov     r2,-(sp);       add     $8.,(sp);       next
1128 lal.w0:         clr     r0;             bisb    (pcx)+,r0
1129                 asl     r0;             br      5b
1130 lal.n:          jsr     pc,wrdoff;      br      2f
1131 lal._1:         mov     $-1,r0
1132 2:              add     r2,r0;          mov     r0,-(sp);       next
1133 lal.w_1:        mov     $-400,r0
1134 3:              bisb    (pcx)+,r0;      asl     r0;             br      2b
1135 lal.w_2:        mov     $-1000,r0;      br      3b
1136
1137 lae.l:          jsr     pc,wrdoff;      br      1f
1138 lae.w0: lae.w1: lae.w2: lae.w3: lae.w4: lae.w5: lae.w6:
1139                 asr     r0
1140                 sub     $0171,r0;       swab    r0
1141                 bisb    (pcx)+,r0;      asl     r0
1142 1:              add     eb,r0;
1143 .if .test
1144                 cmp     globmax,r0;
1145                 bhi     1f;             jsr     pc,e.badlae;
1146 .endif
1147 1:              mov     r0,-(sp);      next
1148 /------------------------------------------------------------------------------
1149 lxl.1:          mov     $1,r0;          br      1f
1150 lxl.2:          mov     $2,r0;          br      1f
1151 lxl.l:          jsr     pc,wrdoff
1152                 bgt     1f;             jlt     e.oddz
1153                 mov     r2,-(sp);       next
1154 1:              mov     r2,r1
1155 2:              mov     8(r1),r1;       sob     r0,2b
1156                 mov     r1,-(sp);       next
1157
1158 lxa.1:          mov     $1,r0;          br      1f
1159 lxa.l:          jsr     pc,wrdoff;      bgt     1f
1160                 jlt     e.oddz;         mov     r2,-(sp)
1161                 add     $10,(sp);       next
1162 1:              mov     r2,r1
1163 2:              mov     8(r1),r1;       sob     r0,2b
1164                 add     $10,r1;         mov      r1,-(sp);       next
1165
1166 /------------------------------------------------------------------------------
1167 loi.l:          jsr     pc,wrdoff;      br      2f
1168 loi.1W: loi.2W: loi.3W: loi.4W:
1169                 add     $260,r0;        br      1f
1170 loi.s0:         clr     r0;             bisb    (pcx)+,r0
1171 2:              cmp     $1,r0;          beq     loi.1
1172 1:              jsr     pc,chckptr;     mov     (sp)+,r1;       add     r0,r1
1173                 asr     r0;             jcs     e.oddz
1174 1:              mov     -(r1),-(sp);    sob     r0,1b;          next
1175 loi.1:          jsr     pc,chckptb;     mov     (sp),r1;        clr     r0
1176                 bisb    (r1),r0;        mov     r0,(sp);        next
1177 los.z:
1178                 mov     (sp)+,r0
1179                 br      0f
1180 los.l:
1181                 jsr     pc,wrdoff
1182 0:
1183                 cmp     $04,r0
1184                 beq     4f
1185
1186                 cmp     $02,r0;         beq     3f
1187                 jbr     e.oddz
1188 4:              mov     (sp)+,r0
1189 3:              mov     (sp)+,r0;       br      2b
1190
1191 /------------------------------------------------------------------------------
1192                         /Store group
1193 /------------------------------------------------------------------------------
1194 stl.pw:         jsr     pc,wrdoff;      asl     r0;     br    0f
1195 stl.0:          clr     r0;             br      0f
1196 stl.1W:         mov     $2,r0
1197 0:              add     r2,r0;          mov(sp)+,8.(r0);        next
1198
1199 stl.nw:         jsr     pc,wrdoff;      br      0f
1200 stl.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1201 0:              asl     r0;             add     r2,r0
1202                 mov     (sp)+,(r0);     next
1203 stl._1W:        mov     (sp)+,-2(r2);   next
1204 stl._2W:        mov     (sp)+,-4(r2);   next
1205 stl._3W:        mov     (sp)+,-6(r2);   next
1206 stl._4W:        mov     (sp)+,-10(r2);  next
1207 stl._5W:        mov     (sp)+,-12(r2);  next
1208
1209 sdl.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1210 0:              asl     r0;             add     r2,r0
1211 2:              mov     (sp)+,(r0)+;    mov     (sp)+,(r0);     next
1212 sdl.nw:         jsr     pc,wrdoff;      br      0b
1213 sdl.pw:         jsr     pc,wrdoff;      asl     r0
1214                 add     r2,r0;          add     $8.,r0;         br      2b
1215
1216 /------------------------------------------------------------------------------
1217
1218 sde.l:          jsr     pc,wrdoff;      add     eb,r0
1219                 br      2b
1220 ste.lw:         jsr     pc,wrdoff;      br      1f
1221 ste.w0:         clr     r0;             br      0f
1222 ste.w1:         mov     $400,r0;        br      0f
1223 ste.w2:         mov     $1000,r0
1224 0:              bisb    (pcx)+,r0
1225 1:              asl     r0;             add     eb,r0
1226                 mov     (sp)+,(r0);     next
1227
1228
1229 /------------------------------------------------------------------------------
1230
1231 stf.l:          jsr     pc,wrdoff;      br      6f
1232 stf.1W:         mov     $2,r0;          br      6f
1233 stf.2W:         mov     $4,r0;          br      6f
1234 stf.s0:         clr     r0;             bisb    (pcx)+,r0
1235 6:              add     (sp)+,r0;       br      7f
1236 sdf.l:          jsr     pc,wrdoff;      add     (sp)+,r0
1237                 jbr      2b
1238
1239
1240 /------------------------------------------------------------------------------
1241 sil.w0:         clr     r0;             bisb    (pcx)+,r0
1242 5:              asl     r0;             add     r2,r0
1243                 mov     8.(r0),r0;      br      7f
1244 sil.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1245 2:              asl     r0;             add     r2,r0
1246                 mov     (r0),r0;
1247 7:              mov     (sp),r1;        mov     r0,(sp);
1248                 jsr     pc,chckptr;     mov     r1,*(sp)+;    next
1249 sil.pw:         jsr     pc,wrdoff;      br      5b
1250 sil.nw:         jsr     pc,wrdoff;      br      2b
1251 /------------------------------------------------------------------------------
1252 sti.1:          jsr     pc,chckptb;     mov     (sp)+,r1;
1253                 movb    (sp)+,(r1);     next
1254 sti.1W:         sti.2W:         sti.3W:         sti.4W:
1255                 add     $114,r0;        br      1f
1256 sti.s0:         clr     r0;             bisb    (pcx)+,r0;      br     1f
1257 sti.l:          jsr     pc,wrdoff
1258 1:              asr     r0;             beq     3f
1259                 jcs     e.oddz;         jsr     pc,chckptr;
1260                 mov     (sp)+,r1
1261 2:              mov     (sp)+,(r1)+;    sob     r0,2b;          next
1262 3:              jcs     sti.1;          jbr     e.oddz
1263 sts.l:          jsr     pc,wrdoff
1264 0:              cmp     $2,r0;          beq     2f
1265                 cmp     $4,r0;          beq     4f;             jbr   e.oddz
1266 4:              mov     (sp)+,r0
1267 2:              mov     (sp)+,r0;       br      1b
1268 sts.z:          mov     (sp)+,r0;       br      0b
1269
1270 /------------------------------------------------------------------------------
1271 /                POINTER ARITHMETIC
1272 /------------------------------------------------------------------------------
1273 adp.l:          jsr     pc,wrdoff;      add     r0,(sp);    next
1274 adp.1:          add     $1,(sp);        next
1275 adp.2:          add     $2,(sp);        next
1276 adp.s0:         clr     r0;             bisb    (pcx)+,r0
1277                 add     r0,(sp);        next
1278 adp.s_1:        mov     $-400,r0;       bisb    (pcx)+,r0
1279                 add     r0,(sp);        next
1280 ads.l:          jsr     pc,wrdoff;      br      0f
1281 ads.z:          mov     (sp)+,r0
1282 0:              cmp     $1,r0;          beq     1f
1283                 asr     r0;             jcs     e.oddz
1284 2:              mov     (sp)+,r1;       sob     r0,2b
1285                 add     r1,(sp);        next
1286 ads.1W:         mov     (sp)+,r1;       add     r1,(sp);    next
1287 1:              movb    (sp)+,r1
1288                 add     r1,(sp);        next
1289 sbs.l:          jsr     pc,wrdoff;      br      0f
1290 sbs.z:          mov     (sp)+,r0
1291 0:              mov     (sp)+,r1;       sub     r1,(sp)
1292                 beq     0f;             mov     $-1,r1
1293                 br      1f
1294 0:              clr     r1
1295 1:              dec     r0;             beq     3f
1296                 dec     r0;             beq     2f
1297                 asr     r0
1298 4:              mov     r1,-(sp);       sob     r0,4b
1299 2:              next
1300 3:              clrb    1(sp);  next
1301
1302
1303 /------------------------------------------------------------------------------
1304 /------------------------------------------------------------------------------
1305 /       Clears, increments and decrements
1306 /------------------------------------------------------------------------------
1307 inc.z:          mov     sp,r1;
1308 4:
1309 .if .test
1310                 cmp     (r1),$und;      jne     3f;
1311                 jsr     pc,e.iund;                      3:
1312 .endif
1313                 inc     (r1);           bvs     9f;     next
1314 inl._1W:        mov     r2,r1;          sub     $2,r1;          br 4b
1315 inl._2W:        mov     r2,r1;          sub     $4,r1;          br 4b
1316 inl._3W:        mov     r2,r1;          sub     $6,r1;          br 4b
1317 inl.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0;
1318 1:              asl     r0;             mov     r2,r1;
1319                 add     r0,r1;          br      4b
1320 inl.pw:         jsr     pc,wrdoff;      add     $4,r0;
1321                 br      1b;             /      !! proc frame 4  words
1322 inl.nw:         jsr     pc,wrdoff;      br      1b
1323 ine.lw:         jsr     pc,wrdoff;      br      1f
1324 ine.w0:         clr     r0;             bisb    (pcx)+,r0;
1325 1:              asl     r0;             add     eb,r0;
1326                 mov     r0,r1;          br      4b
1327 dec.z:          mov     sp,r1;
1328 4:
1329 .if .test
1330                 cmp     (r1),$und;      jne     3f;
1331                 jsr     pc,e.iund;                      3:
1332 .endif
1333                 dec     (r1);           bvs     9f;     next
1334 del.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0;
1335 1:              asl     r0;             mov     r0,r1;
1336                 add     r2,r1;          br      4b
1337 del.pw:         jsr     pc,wrdoff;      add     $4,r0;
1338                 br      1b;             /       !proc frame 4 words
1339 del.nw:         jsr     pc,wrdoff;      br      1b
1340 dee.w0:         clr     r0;             bisb    (pcx)+,r0;
1341 1:              asl     r0;             add     eb,r0;
1342                 mov     r0,r1;          br      4b
1343 dee.lw:         jsr     pc,wrdoff;      br      1b;
1344 9:              jsr     pc,e.iovfl;     next
1345                 / jump to an error routine for integer overflow
1346 zrl._1W:        clr     -2(r2);         next
1347 zrl._2W:        clr     -4(r2);         next
1348 zrl.w_1:        mov     $-400,r0;       bisb    (pcx)+,r0;
1349 1:              asl     r0;             add     r2,r0;
1350                 clr     (r0);           next
1351 zrl.nw:         jsr     pc,wrdoff;      br      1b
1352 zrl.pw:         jsr     pc,wrdoff;      add     $4,r0;
1353                 br      1b
1354 zre.lw:         jsr     pc,wrdoff;      br      1f
1355 zre.w0:         clr     r0;             bisb    (pcx)+,r0;
1356 1:              asl     r0;             add     eb,r0;
1357                 clr     (r0);           next
1358 zrf.l:          jsr     pc,wrdoff;      br      1f
1359 zrf.z:          mov     (sp)+,r0;
1360 1:              asr     r0;
1361 2:              clr     -(sp);          sob     r0,2b;          next
1362 zer.s0:         clr     r0;             bisb    (pcx)+,r0;
1363 3:              bit     $1,r0;          jne     e.illins
1364                 / test if number of bytes is even
1365                 br      1b
1366 zer.l:          jsr     pc,wrdoff;      br      3b
1367 zer.z:          mov     (sp)+,r0;       br      3b
1368 /------------------------------------------------------------------------------
1369 /               LOGICAL GROUP
1370 /------------------------------------------------------------------------------
1371
1372 and.1W:         mov     $1,r1;          mov     $2,r0;
1373                 br      lbland;
1374 and.l:          jsr     pc,wrdoff;      br      0f
1375 and.z:          mov     (sp)+,r0;
1376 0:              ble     9f;             mov     r0,r1;
1377                 asr     r1;             bcs     9f;
1378 lbland:         add     sp,r0;
1379 1:              mov     (sp)+,r5;       com     r5;
1380                 bic     r5,(r0)+;       sob     r1,1b;
1381                 next
1382 ior.1W:         mov     $1,r1;          mov     $2,r0;
1383                 br      0f
1384 ior.s0:         clr     r0;             bisb    (pcx)+,r0;
1385                 br      0f
1386 ior.l:          jsr     pc,wrdoff;      br      0f
1387 ior.z:          mov     (sp)+,r0;
1388 lblior:
1389
1390 0:              ble     9f;             bit     $1,r0;
1391                 bne     9f;             mov     r0,r1;
1392                 mov     sp,r5;  add     r0,r5;  asr     r1;
1393 1:              bis     (sp)+,(r5)+;    sob     r1,1b;             next
1394 xor.l:          jsr     pc,wrdoff;      br      0f;
1395 xor.z:          mov     (sp)+,r0;
1396 0:              ble     9f;             bit     $1,r0;
1397                 bne     9f;             mov     r0,r1;
1398                 mov     sp,r5;  add     r0,r5;  asr     r1
1399 1:              mov     (sp)+,r0;
1400                 xor     r0,(r5)+;    sob     r1,1b;             next
1401 com.l:          jsr     pc,wrdoff;      br      1f
1402 com.z:          mov     (sp)+,r0;
1403 1:              bit     $1,r0;          bne     9f
1404                 mov     r0,r1;          asr     r1
1405                 add     sp,r0;
1406 2:              com     -(r0);          sob     r1,2b
1407                 next
1408 rol.l:          jsr     pc,wrdoff;      br      3f
1409 rol.z:          mov     (sp)+,r0;
1410 3:              clr     r4;
1411                 mov     (sp)+,r5;       ash     $3,r0;
1412                 div     r0,r4;          mov     r5,r4;
1413                 bge     1f;             add     r0,r4;
1414 1:              ash     $-3,r0;         mov     sp,r1;
1415                 cmp     r0,$1;          beq     1f;
1416                 add     r0,r1;          mov     r1,r5;
1417                 asr     r0;             jcs     9f
1418                 mov     r3,saver0;      mov     r0,r3;
1419 4:              mov     r3,r0;          mov     r5,r1;
1420 2:              rol     -(r1);          sob     r0,2b;
1421                 adc     -2(r5);         sob     r4,4b;
1422                 mov     saver0,r3;      mov     $loop,r4;       next
1423 1:              rolb    (r1)+;          adc     (r1);
1424                 sob     r4,1b;          mov     saver1,r4;      next
1425 ror.l:          jsr     pc,wrdoff;      neg     (sp);   br 3b
1426 ror.z:          mov     (sp)+,r0;       neg     (sp);   br 3b
1427 9:              jsr      pc,e.oddz  /error codes for odd or
1428                                     /negative number of bytes
1429
1430 /------------------------------------------------------------------------------
1431 /               SET GROUP
1432 /------------------------------------------------------------------------------
1433
1434 set.s0:         clr     r0;             bisb    (pcx)+,r0
1435 1:
1436 .if .test
1437                 bgt     9f;             jsr     pc,e.set
1438 9:
1439 .endif
1440                 mov     (sp)+,r1
1441                 jsr     pc,settest;     inc     r0
1442                 asr     r0;           / if r0 odd choose next even
1443 2:              clr     -(sp);          sob     r0,2b; / empty set
1444                 mov     r1,r0;          ash     $-3,r0;
1445                 add     sp,r0;          bic     $177770,r1;
1446                 bisb    bits(r1),(r0);  next
1447 set.l:          jsr     pc,wrdoff;      br      1b
1448 set.z:          mov     (sp)+,r0;       br      1b
1449 inn.s0:         clr     r0;             bisb    (pcx)+,r0
1450 1:
1451 .if .test
1452                 bgt     9f;             jsr     pc,e.set
1453 9:
1454 .endif
1455                 mov     sp,r5;
1456                 add     r0,r5;          mov     (sp)+,r1;
1457                 jsr     pc,settest;     mov     r1,r0
1458                 ash     $-3,r0;         add     sp,r0;
1459                 clr     -(sp);
1460                 bic     $177770,r1;        bitb    bits(r1),(r0)
1461                 beq     2f;             mov     r5,sp;
1462                 mov     $1,(sp);        next
1463 2:              mov     r5,sp;          clr     (sp);    next
1464 inn.l:          jsr     pc,wrdoff;      br      1b
1465 inn.z:          mov     (sp)+,r0;       br      1b
1466         .data
1467 bits:   .byte   1
1468         .byte   2
1469         .byte   4
1470         .byte   10
1471         .byte   20
1472         .byte   40
1473         .byte   100
1474         .byte   200
1475         .even
1476         .text
1477 settest:        mov     r0,-(sp);       clc
1478                 ash     $3,r0;          sub     r1,r0;
1479 .if .test
1480                 bgt     3f;             jsr     pc,e.set
1481 .endif
1482 3:              mov     (sp)+,r0;       rts     pc
1483 /------------------------------------------------------------------------------
1484 /               ARRAY   GROUP
1485 /------------------------------------------------------------------------------
1486
1487
1488
1489 lar.1W:         mov     $2,r0;          br      1f
1490 lar.l:          jsr     pc,wrdoff;      br      1f
1491 lar.z:          mov     (sp)+,r0;
1492 1:              jsr     pc,calcarr;     clr     -2(sp);
1493                 sub     r5,sp;          bic     $1,sp;
1494                 mov     sp,r0;
1495 2:              movb    (r1)+,(r0)+;    sob     r5,2b;  next
1496 sar.1W:         mov     $2,r0;          br      1f
1497 sar.l:          jsr     pc,wrdoff;      br      1f
1498 sar.z:          mov     (sp)+,r0;
1499 1:              jsr     pc,calcarr;     mov     sp,r0;
1500                 add     r5,sp;          inc     sp;
1501                 bic     $1,sp;
1502 2:              movb    (r0)+,(r1)+;    sob     r5,2b;  next
1503 aar.1W:         mov     $2,r0;          br      1f
1504 aar.l:          jsr     pc,wrdoff;      br      1f
1505 aar.z:          mov     (sp)+,r0;
1506 1:              jsr     pc,calcarr;     mov     r1,-(sp);       next
1507
1508 calcarr:        sub     $02,r0;         beq     0f;
1509                 jsr     pc,e.oddz;
1510 0:              tst     (sp)+;
1511                 mov     (sp)+,r0;       mov     (sp)+,r1;
1512                 sub     (r0)+,r1;       bge     9f
1513                 jsr     pc,e.array
1514 9:
1515                 cmp     (r0)+,r1;       bge     9f
1516                 jsr     pc,e.array
1517 9:
1518                 mov     (r0),r5;
1519                 mul     r5,r1;          add     (sp)+,r1;
1520                 mov     -010(sp),-(sp); rts     pc;
1521
1522
1523
1524 /------------------------------------------------------------------------------
1525 /--------------------------------------------------------------
1526 /               CONVERT GROUP
1527 /--------------------------------------------------------------
1528
1529 cii.z:
1530                 / convert int to int
1531                 / 1 byte -> ? : sign extension
1532         mov     (sp)+,r0
1533         inc     r0              / dest 1 byte = dest 1 word
1534         bic     $1,r0
1535 .if .test
1536         cmp     (sp),$2         / if size 2 then trap for undefined
1537         bne     7f
1538         cmp     2(sp),$und
1539         bne     7f
1540         jsr     pc,e.iund          / this is the trap
1541 7:
1542 .endif
1543         sub     (sp)+,r0
1544 0:      blt     1f
1545         asr     r0
1546         bcc     2f
1547         movb    (sp),r1
1548         mov     r1,(sp)
1549 2:      tst     r0
1550         beq     3f
1551         tst     (sp)
1552 4:      sxt     -(sp)
1553         sob     r0,4b
1554 3:      next
1555 1:      sub     r0,sp
1556 .if .test
1557         mov     sp,r1
1558         neg     r0
1559         asr     r0
1560         tst     (sp)
1561         blt     3f
1562 5:      tst     -(r1)
1563         bne     9f
1564         sob     r0,5b
1565         next
1566 3:      cmp     -(r1),$-1
1567         bne     9f
1568         sob     r0,3b
1569 .endif
1570         next
1571 /-------
1572 cui.z:  mov     (sp)+,r0
1573         sub     (sp)+,r0
1574         clr     -(sp)
1575         add     $-2,r0
1576         br      0b
1577 cif.z:
1578         mov     (sp)+,r0
1579         jsr     pc,setfloat
1580         mov     (sp)+,r0
1581 .if .test
1582         cmp     r0,$2           / trap if size 2 undefined integer
1583         bne     7f
1584         cmp     (sp),$und
1585         bne     7f
1586         jsr     pc,e.iund          / trap for undefined integer
1587 7:
1588 .endif
1589         jsr     pc,setint
1590         movif   (sp)+,fr0
1591         movf    fr0,-(sp)
1592         next
1593 cuf.z:
1594         mov     (sp)+,r0
1595         jsr     pc,setfloat
1596         mov     (sp)+,r0
1597         cmp     r0,$02
1598         bne     1b
1599         clr     -(sp)
1600         mov     $04,r0
1601         jsr     pc,setint
1602         movif   (sp)+,fr0
1603         cfcc
1604         bge     1f
1605         addf    fr3,fr0
1606 1:      movf    fr0,-(sp)
1607         next
1608 /-------
1609 cff.z:
1610         mov     (sp)+,r0
1611         cmp     (sp)+,r0
1612         beq     1f
1613         jsr     pc,setfloat
1614         movof   (sp)+,fr0
1615         movf    fr0,-(sp)
1616 1:      next
1617 /-------
1618 ciu.z:  mov     (sp)+,r0
1619 .if .test
1620         cmp     (sp),$2         / trap undefined of size 2
1621         bne     7f
1622         cmp     2(sp),$und
1623         bne     7f
1624         jsr     pc,e.iund          / this is the trap
1625 7:
1626 .endif
1627         sub     (sp)+,r0
1628         asr     r0
1629         bcc     2f
1630         clrb    1(sp)
1631 2:
1632 6:      tst     r0
1633         beq     3f
1634         blt     5f
1635 4:      clr     -(sp)
1636         sob     r0,4b
1637 3:      next
1638 9:      jsr     pc,e.conv;      next
1639 5:      neg     r0
1640 4:      tst     (sp)+
1641         sob     r0,4b
1642         next
1643 cuu.z:
1644         mov     (sp)+,r0
1645         sub     (sp)+,r0
1646         asr     r0
1647         jbr     6b
1648 /-------
1649 cfu.z:
1650         mov     (sp)+,r1
1651         mov     $4,r0
1652         jsr     pc,setint
1653         mov     (sp)+,r0
1654         jsr     pc,setfloat
1655         movf    (sp)+,fr0
1656         movfi   fr0,-(sp)
1657 / unfortunately, this does not work for numbers >= 2^31
1658 .if .test
1659         jcs     9b
1660         jlt     9b
1661 .endif
1662         mov     $4,-(sp)
1663         mov     r1,-(sp)
1664         jbr     cuu.z
1665 /-------
1666 cfi.z:
1667         mov     (sp)+,r0
1668         jsr     pc,setint
1669         mov     (sp)+,r0
1670         jsr     pc,setfloat
1671         movf    (sp)+,fr0
1672         movfi   fr0,-(sp)
1673         jcs     e.conv
1674         next
1675 /--------------------------------------------------------------
1676 /               INTEGER ARITHMETIC
1677 /--------------------------------------------------------------
1678
1679 adi.l:  jsr     pc,wrdoff;      br      0f
1680 adi.z:  mov     (sp)+,r0
1681 0:      cmp     r0,$04
1682         bgt     1f
1683         cmp     r0,$02
1684         bgt     2f
1685         bne     1f
1686 adi.1W:
1687 .if .test
1688         cmp     (sp),$und       / trap undefineds of size 2
1689         beq     6f
1690         cmp     2(sp),$und
1691         bne     7f
1692 6:      jsr     pc,e.iund          / this is the trap
1693 7:
1694 .endif
1695         add     (sp)+,(sp)
1696 .if .test
1697         bvs     9f
1698 .endif
1699         next
1700 adi.2W: 2:      add     (sp)+,02(sp)
1701 .if .test
1702         bvc     2f
1703         jsr     pc,e.iovfl
1704 2:
1705 .endif
1706         add     (sp)+,02(sp)
1707         adc     (sp)
1708 .if .test
1709         bvs     9f
1710 .endif
1711
1712         next
1713 1:
1714         jsr    pc,e.oddz ;      next
1715 /-------
1716 sbi.l:  jsr     pc,wrdoff;      br      0f
1717 sbi.z:  mov     (sp)+,r0
1718 0:      cmp     r0,$04
1719         bgt     1b
1720         cmp     r0,$02
1721         bgt     2f
1722         bne     1b
1723 sbi.1W:
1724 .if .test
1725         cmp     (sp),$und       / trap for size 2 undefineds
1726         beq     6f
1727         cmp     2(sp),$und
1728         bne     7f
1729 6:      jsr     pc,e.iund          / this is the trap
1730 7:
1731 .endif
1732         sub     (sp)+,(sp)
1733 .if .test
1734         bvs     9f
1735 .endif
1736         next
1737 sbi.2W: 2:              sub     (sp)+,02(sp)
1738 .if .test
1739         bvc     2f
1740         jsr     pc,e.iovfl
1741 2:
1742 .endif
1743         sub     (sp)+,02(sp)
1744         sbc     (sp)
1745 .if .test
1746         bvs     9f
1747         next
1748 9:      jsr     pc,e.iovfl
1749 .endif
1750         next
1751 /------
1752 mli.l:   jsr    pc,wrdoff;      br      0f
1753 mli.z:   mov    (sp)+,r0
1754 0:
1755         cmp     r0,$04
1756         bgt     1f
1757         beq     mli4
1758         cmp     r0,$02
1759         bne     1f
1760 mli.1W: mov     (sp)+,r1
1761 .if .test
1762         cmp     r1,$und         / trap for undefineds of size 2
1763         beq     6f
1764         cmp     (sp),$und
1765         bne     7f
1766 6:      jsr     pc,e.iund          / this is the trap
1767 7:
1768 .endif
1769         mul     (sp)+,r1
1770 .if .test
1771
1772         bcc     9f              / overflow
1773         jsr     pc,e.iovfl
1774 9:
1775 .endif
1776         mov     r1,-(sp)
1777         next
1778 1:      jmp     e.oddz
1779 /------
1780 mli.2W:         mli4:
1781 .if .prof
1782         add     $91.,*loprof
1783         adc     *hiprof
1784 .endif
1785         jsr     pc,regsave
1786         tst     02(sp)
1787         sxt     r0
1788         sub     (sp),r0
1789         tst     06(sp)
1790         sxt     r2
1791         sub     04(sp),r2
1792         mov     r0,r4
1793         mul     r2,r4
1794         mul     06(sp),r0
1795 .if .test
1796         bge     2f
1797         inc     r4
1798 2:
1799 .endif
1800         mul     02(sp),r2
1801 .if .test
1802         bge     2f
1803         inc     r4
1804 2:      sub     r2,r5
1805         sbc     r4
1806         sub     r0,r5
1807         sbc     r4
1808         add     r1,r3
1809         sbc     r5
1810         sbc     r4
1811 .endif
1812         mov     02(sp),r0
1813         mul     06(sp),r0
1814 .if .test
1815         bge     2f
1816         sub     $1,r5
1817         sbc     r4
1818 .endif
1819 2:      sub     r3,r0
1820 .if .test
1821         sxt     r2
1822         sbc     r5
1823         sbc     r4
1824         cmp     r2,r4
1825         bne     2f
1826         cmp     r2,r5
1827         beq     9f
1828 2:      jsr     pc,e.iovfl
1829 9:
1830 .endif
1831         add     $010,sp
1832         mov     r1,-(sp);
1833         mov     r0,-(sp);
1834         jsr     pc,regretu;          next
1835
1836
1837 /-------
1838 dvi.l:  jsr    pc,wrdoff;      br      0f
1839 dvi.z:  mov    (sp)+,r0
1840 0:      cmp     r0,$04
1841         bgt     1f
1842         beq     dvi4
1843         cmp     r0,$02
1844         bne     1f
1845 dvi.1W: mov     02(sp),r1
1846         sxt     r0
1847 .if .test
1848         cmp     r1,$und         / trap for undifined of size 2
1849         beq     6f
1850         cmp     (sp),$und
1851         bne     7f
1852 6:      jsr     pc,e.iund          / this is the trap
1853 7:
1854 .endif
1855         div     (sp)+,r0
1856         jcs     9f
1857         mov     r0,(sp)
1858         next
1859 1:      jmp     e.oddz
1860 /-------
1861 dvi4:
1862 .if .prof
1863         add     $100.,*loprof
1864         adc     *hiprof
1865 .endif
1866         jsr     pc,regsave
1867         mov     02(sp),r3
1868         bne     1f
1869         tst     (sp)
1870         bne     1f
1871 9:      jsr     pc,e.idivz
1872 1:      sxt     r4
1873         bpl     1f
1874         neg     r3
1875 1:      cmp     r4,(sp)
1876         bne     hardldiv
1877         mov     06(sp),r2
1878         mov     04(sp),r1
1879         bge     2f
1880         neg     r1
1881         neg     r2
1882         sbc     r1
1883         com     r4
1884 2:      mov     r4,-(sp)
1885         clr     r0
1886         div     r3,r0
1887         mov     r0,-(sp)
1888         mov     r1,r0
1889         mov     r1,r4
1890         mov     r2,r1
1891         div     r3,r0
1892         bvc     3f
1893         mov     r2,r1
1894         mov     r4,r0
1895         sub     r3,r0
1896         div     r3,r0
1897         tst     r1
1898         sxt     r1
1899         add     r1,r0
1900 3:      mov     r0,r1
1901         mov     (sp)+,r0
1902         br      4f
1903 hardldiv:
1904 .if .prof
1905         add     $75.,*loprof
1906         adc     *hiprof
1907 .endif
1908         clr     -(sp)
1909         mov     010(sp),r2
1910         mov     06(sp),r1
1911         bpl     5f
1912         com     (sp)
1913         neg     r1
1914         neg     r2
1915         sbc     r1
1916 5:      clr     r0
1917         mov     02(sp),r3
1918         bge     6f
1919         neg     r3
1920         neg     04(sp)
1921         sbc     r3
1922         com     (sp)
1923 6:      mov     $16.,r4
1924 9:      clc
1925         rol     r2
1926         rol     r1
1927         rol     r0
1928         cmp     r3,r0
1929         bhi     7f
1930         bcs     8f
1931         cmp     04(sp),r1
1932         blos    8f
1933 7:      sob     r4,9b
1934         br      1f
1935 8:      sub     04(sp),r1
1936         sbc     r0
1937         sub     r3,r0
1938         inc     r2
1939         sob     r4,9b
1940 1:
1941         mov     r2,r1
1942         clr     r0
1943 4:      tst     (sp)+
1944         beq     1f
1945         neg     r0
1946         neg     r1
1947         sbc     r0
1948 1:      add     $010,sp
1949         mov     r1,-(sp);
1950         mov     r0,-(sp);
1951         jsr     pc,regretu;          next
1952 /-------
1953 rmi.l:  jsr     pc,wrdoff;      br      0f
1954 rmi.z:  mov     (sp)+,r0
1955 0:      cmp     r0,$04
1956         bgt     1f
1957         beq     rmi4
1958         cmp     r0,$02
1959         bne     1f
1960 rmi.1W: mov     02(sp),r1
1961         sxt     r0
1962 .if .test
1963         cmp     r1,$und         / trap for undefineds of size 2
1964         beq     6f
1965         cmp     (sp),$und
1966         bne     7f
1967 6:      jsr     pc,e.iund          / this is the trap
1968 7:
1969 .endif
1970         div     (sp)+,r0
1971         bcs     9f
1972         mov     r1,(sp)
1973         next
1974 1:      jmp     e.oddz
1975 /-------
1976 rmi4:
1977 .if .prof
1978         add     $100.,*loprof
1979         adc     *hiprof
1980 .endif
1981         jsr     pc,regsave
1982         mov     02(sp),r3
1983         bne     1f
1984         tst     (sp)
1985         bne     1f
1986 9:      jsr     pc,e.idivz
1987 1:      tst     r3
1988         sxt     r4
1989         bpl     1f
1990         neg     r3
1991 1:      cmp     r4,(sp)
1992         bne     hardrmi4
1993         mov     06(sp),r2
1994         mov     04(sp),r1
1995         mov     r1,r4
1996         bge     2f
1997         neg     r1
1998         neg     r2
1999         sbc     r1
2000 2:      mov     r4,-(sp)
2001         clr     r0
2002         div     r3,r0
2003         mov     r1,r0
2004         mov     r1,r4
2005         mov     r2,r1
2006         div     r3,r0
2007         bvc     3f
2008         mov     r2,r1
2009         mov     r4,r0
2010         sub     r3,r0
2011         div     r3,r0
2012         tst     r1
2013         beq     3f
2014         add     r3,r1
2015 3:      tst     (sp)+
2016         bpl     4f
2017         neg     r1
2018 4:      sxt     r0
2019         br      9f
2020 hardrmi4:
2021 .if .prof
2022         add     $75.,*loprof
2023         adc     *hiprof
2024 .endif
2025         mov     06(sp),r2
2026         mov     04(sp),r1
2027         bpl     5f
2028         neg     r1
2029         neg     r2
2030         sbc     r1
2031 5:      clr     r0
2032         mov     (sp),r3
2033         bge     6f
2034         neg     r3
2035         neg     02(sp)
2036         sbc     r3
2037 6:      mov     $16.,r4
2038 1:      clc
2039         rol     r2
2040         rol     r1
2041         rol     r0
2042         cmp     r3,r0
2043         bhi     7f
2044         bcs     8f
2045         cmp     02(sp),r1
2046         blos    8f
2047 7:      sob     r4,1b
2048         br      2f
2049 8:      sub     02(sp),r1
2050         sbc     r0
2051         sub     r3,r0
2052         sob     r4,1b
2053 2:      tst     04(sp)
2054         bge     9f
2055         neg     r0
2056         neg     r1
2057         sbc     r0
2058 9:      add     $010,sp
2059         mov     r1,-(sp)
2060         mov     r0,-(sp)
2061         jsr     pc,regretu;          next
2062 /-------
2063 ngi.l:  jsr     pc,wrdoff;      br      1f
2064 ngi.z:  mov     (sp)+,r0
2065 1:
2066 lblngi:
2067         cmp     r0,$02
2068         bgt     1f
2069 .if .test
2070         cmp     (sp),$und       / trap for undefineds of size 2
2071         bne     7f
2072         jsr     pc,e.iund
2073 7:
2074 .endif
2075         neg     (sp)
2076 3:      next
2077 1:      cmp     r0,$04
2078         bgt     2f
2079         mov     (sp),r0
2080         neg     (sp)
2081         mov     02(sp),r1
2082         neg     02(sp)
2083         sbc     (sp)
2084         cmp     r0,(sp)
2085 .if .test
2086         bne     3b
2087         cmp     r1,02(sp)
2088         bne     3b
2089 2:      jsr     pc,e.iovfl
2090 .endif
2091         next
2092 /-------
2093 sli.l:  jsr     pc,wrdoff;      br      0f
2094 sli.z:  mov     (sp)+,r0
2095 0:      cmp     r0,$02
2096         bgt     1f
2097 sli.1W: mov     (sp)+,r1
2098         mov     (sp)+,r0
2099 .if .test
2100         cmp     r0,$und         / trap for undefined size 2
2101         bne     7f
2102         jsr     pc,e.iund
2103 7:
2104 .endif
2105         ash     r1,r0
2106 .if .test
2107         bvc     7f
2108         jsr     pc,e.iovfl
2109 7:
2110 .endif
2111         mov     r0,-(sp)
2112         next
2113 1:      cmp     r0,$04
2114         bgt     2f
2115         mov     02(sp),r0
2116         mov     04(sp),r1
2117         ashc    (sp)+,r0
2118 .if .test
2119         bvc     7f
2120         jsr     pc,e.iovfl
2121 7:
2122 .endif
2123         mov     r0,(sp)
2124         mov     r1,02(sp)
2125         next
2126 2:      jmp     e.oddz
2127 /-------
2128 sri.l:  jsr     pc,wrdoff;      br      0f
2129 sri.z:  mov     (sp)+,r0
2130 0:      cmp     r0,$02
2131         bgt     1f
2132         mov     (sp)+,r1
2133         mov     (sp)+,r0
2134 .if .test
2135         cmp     r0,$und         / trap for undefined size 2
2136         bne     7f
2137         jsr     pc,e.iund
2138 7:
2139 .endif
2140         neg     r1
2141         ash     r1,r0
2142         mov     r0,-(sp)
2143         next
2144 1:      cmp     r0,$04
2145         bgt     2f
2146         mov     02(sp),r0
2147         mov     04(sp),r1
2148         neg     (sp)
2149         ashc    (sp)+,r0
2150         mov     r0,(sp)
2151         mov     r1,02(sp)
2152         next
2153 2:      jmp     e.oddz
2154 /--------------------------------------------------------------
2155 adu.l:  jsr     pc,wrdoff;      br      0f
2156 adu.z:  mov     (sp)+,r0
2157 0:      jsr     pc,tstr0;       add     r0,sp
2158         mov     sp,r1;          add     r0,sp;          asr     r0
2159 2:      adc     -(sp);          add     -(r1),(sp);     sob r0,2b
2160         next
2161 sbu.l:  jsr     pc,wrdoff;      br      0f
2162 sbu.z:  mov     (sp)+,r0
2163 0:      jsr     pc,tstr0;       add     r0,sp
2164         mov     sp,r1;          add     r0,sp;          asr     r0;
2165 2:      sbc     -(sp);          sub     -(r1),(sp);     sob r0,2b
2166         next
2167 mlu.l:  jsr     pc,wrdoff;      br      0f
2168 mlu.z:  mov     (sp)+,r0
2169 0:      jsr     pc,tstr0
2170         cmp     r0,$04
2171         bgt     1f
2172         beq     mlu4
2173         mov     (sp)+,r1
2174         mul     (sp)+,r1
2175         mov     r1,-(sp)
2176         next
2177 1:      jmp     e.oddz
2178 mlu4:
2179 .if .prof
2180         add     $90.,*loprof
2181         adc     *hiprof
2182 .endif
2183         jsr     pc,regsave
2184         clr     r0
2185         mov     02(sp),r1
2186         mov     06(sp),r3
2187         mul     r3,r0
2188         tst     r3
2189         bge     1f
2190         ashc    $15.,r0
2191 1:      mov     02(sp),r3
2192         clr     r2
2193         mul     04(sp),r2
2194         add     r3,r0
2195         mov     06(sp),r3
2196         clr     r2
2197         mul     (sp),r2
2198         add     r3,r0
2199         add     $010,sp
2200         mov     r1,-(sp)
2201         mov     r0,-(sp)
2202         jsr     pc,regretu;          next
2203 9:      jmp     e.oddz
2204 /-------
2205 dvu.l:  jsr     pc,wrdoff;      br      0f
2206 dvu.z:  mov     (sp)+,r0
2207 0:
2208         clr     saver0;
2209         cmp     r0,$04
2210         bgt     9b
2211         beq     dvu4
2212         clr     r0
2213         mov     02(sp),r1
2214         tst     (sp)
2215         blt     1f
2216         div     (sp)+,r0
2217         mov     r0,(sp);        next
2218 1:      mov     (sp),-(sp);
2219         clr     02(sp);
2220         clr     -(sp);
2221         mov     $1,saver0;
2222 dvu4:
2223 .if .prof
2224         add     $95.,*loprof
2225         adc     *hiprof
2226 .endif
2227         jsr     pc,regsave
2228         clr     r0
2229         tst     (sp)
2230         bne     harddvu4
2231         tst     02(sp)
2232         blt     harddvu4
2233         mov     06(sp),r2
2234         mov     04(sp),r1
2235         mov     02(sp),r3
2236         div     r3,r0
2237         mov     r0,-(sp)
2238         mov     r1,r0
2239         mov     r1,r4
2240         mov     r2,r1
2241         div     r3,r0
2242         bvc     1f
2243         mov     r2,r1
2244         mov     r4,r0
2245         sub     r3,r0
2246         div     r3,r0
2247         tst     r1
2248         sxt     r1
2249         add     r1,r0
2250 1:      mov     r0,r1
2251         mov     (sp)+,r0
2252         br      2f
2253 harddvu4:
2254 .if .prof
2255         add     $75.,*loprof
2256         adc     *hiprof
2257 .endif
2258         mov     06(sp),r2
2259         mov     04(sp),r1
2260         mov     (sp),r3
2261         mov     $17.,r4
2262         br      3f
2263 6:      rol     r2
2264         rol     r1
2265         rol     r0
2266 3:      cmp     r3,r0
2267         bhi     4f
2268         blo     5f
2269         cmp     02(sp),r1
2270         blos    5f
2271 4:      clc
2272         sob     r4,6b
2273         br      7f
2274 5:      sub     02(sp),r1
2275         sbc     r0
2276         sub     r3,r0
2277         sec
2278         sob     r4,6b
2279 7:      rol     r2
2280         bcc     8f
2281         mov     $01,r0
2282         br      9f
2283 8:      clr     r0
2284 9:      mov     r2,r1
2285 2:      add     $010,sp
2286         mov     r1,-(sp)
2287         mov     r0,-(sp)
2288         jsr     pc,regretu
2289         tst     saver0;
2290         beq     2f;
2291         tst     (sp)+
2292 2:
2293           next
2294 /-------
2295 9:      jbr     e.oddz
2296 rmu.l:  jsr     pc,wrdoff;      br      0f
2297 rmu.z:  mov     (sp)+,r0
2298 0:      clr     saver0;
2299         cmp     r0,$04
2300         bgt     9b
2301         beq     rmu4
2302         cmp     r0,$02
2303         bne     9b
2304         mov     $1,saver0;
2305         mov     02(sp),r1
2306         tst     (sp)
2307         blt     1f
2308         clr     r0
2309         div     (sp)+,r0
2310         mov     r1,(sp);                next
2311 1:      mov     (sp),-(sp)
2312         clr     02(sp)
2313         clr     -(sp)
2314 rmu4:
2315 .if .prof
2316         add     $95.,*loprof
2317         adc     *hiprof
2318 .endif
2319         jsr     pc,regsave
2320         clr     r0
2321         tst     (sp)
2322         bne     hardrmu4
2323         tst     02(sp)
2324         blt     hardrmu4
2325         mov     06(sp),r2
2326         mov     04(sp),r1
2327         mov     02(sp),r3
2328         div     r3,r0
2329         mov     r1,r0
2330         mov     r1,r4
2331         mov     r2,r1
2332         div     r3,r0
2333         bvc     1f
2334         mov     r2,r1
2335         mov     r4,r0
2336         sub     r3,r0
2337         div     r3,r0
2338         tst     r1
2339         beq     1f
2340         add     r3,r1
2341 1:      clr     r0
2342         br      2f
2343 hardrmu4:
2344 .if .prof
2345         add     $75.,*loprof
2346         adc     *hiprof
2347 .endif
2348         mov     06(sp),r2
2349         mov     04(sp),r1
2350         mov     (sp),r3
2351         mov     $17.,r4
2352         br      3f
2353 6:      clc
2354         rol     r2
2355         rol     r1
2356         rol     r0
2357 3:      cmp     r3,r0
2358         bhi     4f
2359         bcs     5f
2360         cmp     02(sp),r1
2361         blos    5f
2362 4:      sob     r4,6b
2363         br      2f
2364 5:      sub     02(sp),r1
2365         sbc     r0
2366         sub     r3,r0
2367         sob     r4,6b
2368 2:      add     $010,sp
2369         mov     r1,-(sp)
2370         mov     r0,-(sp)
2371         jsr     pc,regretu
2372         tst     saver0
2373         beq     2f;
2374         tst     (sp)+;
2375 2:        next
2376 /-------
2377 slu.l:  jsr     pc,wrdoff;      br      0f
2378 slu.z:  mov     (sp)+,r0
2379 0:
2380         cmp     r0,$02
2381         bgt     1f
2382         mov     (sp)+,r1
2383         mov     (sp)+,r0
2384         ash     r1,r0
2385         mov     r0,-(sp)
2386         next
2387 1:      cmp     r0,$04
2388         bgt     2f
2389         mov     02(sp),r0
2390         mov     04(sp),r1
2391         ashc    (sp)+,r0
2392         mov     r0,(sp)
2393         mov     r1,02(sp)
2394         next
2395 2:      jmp     e.oddz
2396 /-------
2397 sru.l:  jsr     pc,wrdoff;      br      0f
2398 sru.z:  mov     (sp)+,r0
2399 0:
2400         cmp     r0,$02
2401         bgt     1f
2402         mov     2(sp),r1
2403         neg     (sp)
2404         clr     r0
2405         ashc    (sp)+,r0
2406 2:      mov     r1,-(sp)
2407         next
2408 1:      cmp     r0,$04
2409         bgt     3f
2410         mov     02(sp),r0
2411         mov     04(sp),r1
2412         neg     (sp)
2413         beq     4f
2414         ashc    $-1,r0
2415         bic     $0100000,r0
2416         inc     (sp)
2417         beq     4f
2418         ashc    (sp)+,r0
2419 4:      mov     r0,(sp)
2420         mov     r1,02(sp)
2421         next
2422 3:      jmp     e.oddz
2423 /-------
2424
2425 /--------------------------------------------------------------
2426                 / FLOATING POINT INSTRUCTIONS
2427 /--------------------------------------------------------------
2428
2429 adf.s0: clr     r0;             bisb    (pcx)+,r0; br      0f
2430 adf.l:  jsr     pc,wrdoff;      br      0f
2431 adf.z:  mov     (sp)+,r0
2432 0:
2433         jsr     pc,setfloat
2434         movf    (sp)+,fr0
2435         addf    (sp)+,fr0
2436         movf    fr0,-(sp)
2437         next
2438 /-------
2439
2440 sbf.s0: clr     r0;             bisb    (pcx)+,r0; br      0f
2441 sbf.l:  jsr     pc,wrdoff;      br      0f
2442 sbf.z:  mov     (sp)+,r0
2443 0:
2444         jsr     pc,setfloat
2445         movf    (sp)+,fr0
2446         subf    (sp)+,fr0
2447         negf    fr0
2448         movf    fr0,-(sp)
2449         next
2450 /-------
2451
2452 mlf.s0: clr     r0;             bisb    (pcx)+,r0; br      0f
2453 mlf.l:  jsr     pc,wrdoff;      br      0f
2454 mlf.z:  mov     (sp)+,r0
2455 0:
2456         jsr     pc,setfloat
2457         movf    (sp)+,fr0
2458         mulf    (sp)+,fr0
2459         movf    fr0,-(sp)
2460         next
2461 /-------
2462
2463 dvf.s0: clr     r0;             bisb    (pcx)+,r0; br      0f
2464 dvf.l:  jsr     pc,wrdoff;      br      0f
2465 dvf.z:  mov     (sp)+,r0
2466 0:
2467         jsr     pc,setfloat
2468         movf    (sp)+,fr0
2469         movf    (sp)+,fr1
2470         divf    fr0,r1
2471         movf    fr1,-(sp)
2472         next
2473 /-------
2474
2475 ngf.l:  jsr     pc,wrdoff;      br      0f
2476 ngf.z:  mov     (sp)+,r0
2477 0:
2478         jsr     pc,setfloat
2479         negf    (sp)
2480         next
2481 /-------
2482
2483 fif.l:  jsr     pc,wrdoff;      br      0f
2484 fif.z:  mov     (sp)+,r0
2485 0:
2486         jsr     pc,setfloat
2487         movf    (sp)+,fr0
2488         modf    (sp)+,fr0
2489         movf    fr0,-(sp)
2490         movf    fr1,-(sp)
2491         next
2492 /-------
2493
2494 fef.l:  jsr     pc,wrdoff;      br      0f
2495 fef.z:  mov     (sp)+,r0
2496 0:
2497         jsr     pc,setfloat
2498         movf    (sp),fr0
2499         movei   fr0,-(sp)
2500         movie   $0,fr0
2501         movf    fr0,02(sp)
2502         next
2503 /----------------------------------------------------------------------------
2504 /       TEST AND BRANCH GROUP
2505 /----------------------------------------------------------------------------
2506 tlt.z:  tst     (sp)+; blt     true;   clr     -(sp); next
2507 tle.z:  tst     (sp)+; ble     true;   clr     -(sp); next
2508 teq.z:  tst     (sp)+; beq     true;   clr     -(sp); next
2509 tne.z:  tst     (sp)+; bne     true;   clr     -(sp); next
2510 tge.z:  tst     (sp)+; bge     true;   clr     -(sp); next
2511 tgt.z:  tst     (sp)+; bgt     true;   clr     -(sp); next
2512 /----------------------------------------------------------------------------
2513 zlt.s0:         tst     (sp)+; blt     yesbr2; br      nobr2
2514 zlt.l:          tst     (sp)+; blt     yesbr3; br      nobr3
2515 zle.s0:         tst     (sp)+; ble     yesbr2; br      nobr2
2516 zle.l:          tst     (sp)+; ble     yesbr3; br      nobr3
2517 zeq.s0:         tst     (sp)+; beq     yesbr2; br      nobr2
2518 zeq.s1:         tst     (sp)+; beq     yesbr4; br      nobr2
2519 zeq.l:          tst     (sp)+; beq     yesbr3; br      nobr3
2520 zne.s0:         tst     (sp)+; bne     yesbr2; br      nobr2
2521 zne.l:          tst     (sp)+; bne     yesbr3; br      nobr3
2522 zne.s_1:        tst     (sp)+; bne     yesbr5; br      nobr2
2523 zge.s0:         tst     (sp)+; bge     yesbr2; br      nobr2
2524 zge.l:          tst     (sp)+; bge     yesbr3; br      nobr3
2525 zgt.s0:         tst     (sp)+; bgt     yesbr2; br      nobr2
2526 zgt.l:          tst     (sp)+; bgt     yesbr3; br      nobr3
2527 great:
2528 true:   mov     $1,-(sp)
2529         next
2530
2531 /------------------------------------------------------------------------------
2532
2533 blt.s0: cmp     (sp)+,(sp)+;  bgt     yesbr2; br      nobr2
2534 blt.l:  cmp     (sp)+,(sp)+;  bgt     yesbr3; br      nobr3
2535 ble.s0: cmp     (sp)+,(sp)+;  bge     yesbr2; br      nobr2
2536 ble.l:  cmp     (sp)+,(sp)+;  bge     yesbr3; br      nobr3
2537 beq.l:  cmp     (sp)+,(sp)+;  beq     yesbr3; br      nobr3
2538 beq.s0: cmp     (sp)+,(sp)+;  beq     yesbr2; br      nobr2
2539 bne.s0: cmp     (sp)+,(sp)+;  bne     yesbr2; br      nobr2
2540 bne.l:  cmp     (sp)+,(sp)+;  bne     yesbr3; br      nobr3
2541 bge.s0: cmp     (sp)+,(sp)+;  ble     yesbr2; br      nobr2
2542 bge.l:  cmp     (sp)+,(sp)+;  ble     yesbr3; br      nobr3
2543 bgt.s0: cmp     (sp)+,(sp)+;  blt     yesbr2; br      nobr2
2544 bgt.l:  cmp     (sp)+,(sp)+;  blt     yesbr3; br      nobr3
2545
2546 bra.s0: yesbr2:
2547         clr     r0;
2548 5:      bisb    (pcx)+,r0
2549 1:      add     r0,pcx
2550         next
2551 bra.l:  yesbr3:
2552         jsr     pc,wrdoff
2553         br      1b
2554 bra.s1:         yesbr4:         mov     $400,r0;        br 5b
2555 bra.s_1:        yesbr5:         mov     $-400,r0;       br 5b
2556 bra.s_2:        mov     $-800,r0;       br 5b
2557 nobr2:  tstb    (pcx)+
2558         next
2559 nobr3:  cmpb    (pcx)+,(pcx)+
2560         next
2561 /\f
2562 /------------------------------------------------------------------------------
2563 /       Compare group
2564 /------------------------------------------------------------------------------
2565
2566 calccomp:       mov     (sp)+,saver1;           / old pc
2567                 mov     sp,r1;
2568                 add     r0,r1;          mov     r1,r5;
2569                 add     r0,r1;          mov     r1,saver0;   / new sp
2570                 mov     r0,r1;          asr     r1;
2571 2:              cmp     (r5)+,(sp)+;    blt     3f;
2572                 bgt     4f;             dec     r1;
2573                 beq     5f
2574 2:              cmp     (r5)+,(sp)+;    blo     3f;
2575                 bhi     4f;             sob     r1,2b;
2576 5:              mov     saver0,sp;      clr    -(sp);
2577                 br      5f
2578 4:              mov     saver0,sp;      mov     $1,-(sp);
2579                 br      5f
2580 3:              mov     saver0,sp;      mov     $-1,-(sp);
2581                 br      5f
2582 5:              mov     saver1,-(sp);   rts  pc
2583
2584 cmi.1W:         mov     $2,r0;          br      1f
2585 cmi.2W:         mov     $4,r0;          br      1f
2586 cmi.l:          jsr     pc,wrdoff;      br      1f
2587 cmi.z:          mov     (sp)+,r0;
2588 1:              jsr     pc,calccomp;    next
2589 cms.s0:         clr     r0;             bisb    (pcx)+,r0
2590 1:              jsr     pc,calccomp;    tst     (sp)+;
2591                 bne     great;          clr     -(sp);          next
2592 cms.l:          jsr     pc,wrdoff;      br      1b
2593 cms.z:          mov     (sp)+,r0;       br      1b
2594 cmu.l:          jsr     pc,wrdoff;      br      1f
2595 cmu.z:          mov     (sp)+,r0;       br      1f
2596 cmp.z:          mov     $2,r0;
2597 1:              jsr     pc,calccomp;    mov     (sp)+,r1;
2598                 jlo     less;           jhi     great;
2599                 clr     -(sp);          next
2600 cmf.s0:         clr     r0;             bisb    (pcx)+,r0;
2601 1:              cmp     $4,r0;          beq     3f
2602                 cmp     $8,r0;          beq     3f
2603                 jsr     pc,e.oddz;
2604 3:              jsr     pc,setfloat
2605                 movf    (sp)+,fr0;      cmpf    (sp)+,fr0;
2606 4:              cfcc;   jlt     less;   jgt     great;
2607                 clr     -(sp);          next
2608 cmf.l:          jsr     pc,wrdoff;      br      1b
2609 cmf.z:          mov     (sp)+,r0;       br      1b
2610 less:           mov     $-1,-(sp);      next
2611
2612 /------------------------------------------------------------------------------
2613 /------------------------------------------------------------------------------
2614 /------------------------------------------------------------------------------
2615 /       call and return group
2616 /------------------------------------------------------------------------------
2617 /
2618 /       Frame format on the stack is:
2619 /
2620 /       | Parameter 1             |
2621 /       | - - - - - - - - - - - - |
2622 /       | Static link = param 0   | < AB
2623 /       |_________________________|      ____
2624 /       |-------------------------|          |  P
2625 /       | Saved line number       |          |  R
2626 /       |-------------------------|          |  O
2627 /       | Saved file address      |          |  C
2628 /       |-------------------------|          |  F
2629 /       | Return address          |          |  R
2630 /       |-------------------------|          |  A
2631 /       | Dynamic link            | < LB     |  M
2632 /       |_________________________|      ____|  E
2633 /       |-------------------------|
2634 /       |                         |
2635 /       | local variable -1       |
2636 /       |-------------------------|
2637 /       |                         |
2638 /
2639 /
2640 /       The static link and the parameters are set by the
2641 /       calling procedure; the frame is set by cal which reserves
2642 /       also the space for local variables.
2643 /------------------------------------------------------------------------------
2644
2645 cal.1:  cal.2:  cal.3:  cal.4:  cal.5:  cal.6:  cal.7:  cal.8:
2646 cal.9:  cal.10: cal.11: cal.12: cal.13: cal.14: cal.15: cal.16:
2647 cal.17: cal.18: cal.19: cal.20: cal.21: cal.22: cal.23: cal.24:
2648 cal.25: cal.26: cal.27: cal.28:
2649
2650         asr     r0;             sub     $077,r0;        br  1f
2651 cal.s0: clr     r0;             bisb    (pcx)+,r0;      br  1f
2652 cai.z:  mov     (sp)+,r0;       br      1f
2653 cal.l:  jsr     pc,wrdoff
2654 lblcal:
2655 1:
2656         cmp     nprocs,r0
2657         jlos    e.badpc
2658 1:      asl     r0;             asl     r0;
2659 .if .flow + .count + .prof
2660         mov     r0,r5;
2661         asl     r5
2662         add     r5,r0           / procdes 12 bytes in this case
2663 .endif
2664         add     pd,r0;          / now r0 points to the bottom
2665                                 / of the proc descriptor
2666         mov     *eb,-(sp)       / save line number
2667         mov     *filb,-(sp)     / save file address
2668
2669 .if .prof + .count + .flow
2670         tst     10.(r0)         / yet a filename defined in this proc?
2671         bne     4f              / yes? continue
2672         mov     (sp),10.(r0)    / no? Then take the old filename
2673 4:      mov     curproc,(sp)    / save old procdescriptor
2674         mov     r0,curproc      / continue with the new one
2675         mov     4(r0),countfld  / count pointer minus line number
2676         sub     6(r0),countfld  / to add at line numbers
2677 .endif
2678         mov     pcx,-(sp)       / return address
2679         mov     r2,-(sp)        / old local base
2680         mov     sp,r2           / new local base
2681         mov     (r0)+,r1        / number of bytes for locals
2682         beq     3f              / no locals
2683         inc     r1;     asr  r1 / make even
2684 2:      mov     $und,-(sp)      / make undefined
2685         sob     r1,2b           / for r1 words local
2686 3:      mov     (r0),pcx        / em start address
2687         next                    / ready
2688 /------------------------------------------------------------------------------
2689
2690 ret.l:  jsr     pc,wrdoff;      br      1f
2691 ret.1W: mov     $2,r0;          br      1f
2692 ret.s0: clr     r0;             bisb    (pcx)+,r0;
2693         jlt     e.oddz          / bad   result size
2694         beq     ret.0           / no result
2695         cmp     $32.,r0;        bge     1f;     jsr     pc,e.badlfr
2696 1:      inc     r0;     asr r0  / make even
2697         mov     r0,retsize      / result size
2698         mov     $retarea,r1     / must point to retarea
2699 2:      mov     (sp)+,(r1)+     / load result
2700         sob     r0,2b           / continue when there is more
2701         br      3f
2702 retcount:
2703 ret.0:  clr     retsize         / no function result
2704 3:      mov     r2,sp           / set sp to bottom frame
2705         mov     (sp)+,r2        / restore (dynamic) local base
2706         jeq     lblhalt;        / if zero then main procedure returns
2707         mov     (sp)+,pcx       / return address in program counter
2708         mov     eb,r1           / must point to external base
2709         mov     (sp)+,r0        / file or procdesbase in r0
2710 .if .count + .flow + .prof
2711         mov     r0,curproc      / save procdesbase current proc
2712         mov     4(r0),countfld  / restore pointer to
2713         beq     5f              / countfield 0 non interesting
2714         sub     6(r0),countfld  / table entries
2715         mov     countfld,countptr
2716         add     (sp),countptr
2717 .if .prof
2718         tst     (sp)
2719         beq     5f
2720         mov     countptr,r5
2721         asl     r5
2722         asl     r5
2723         add     ltime,r5
2724         mov     r5,hiprof
2725         add     $2,r5
2726         mov     r5,loprof
2727 .endif
2728 5:
2729         mov     10.(r0),r0      / pointer to file name in r0
2730 .endif
2731 retlast:
2732 .if .last
2733         tst     4(r1)           / file 0 not stacked
2734         beq     4f
2735         cmp     r0,4(r1)        / same file name?
2736         beq     4f              / yes continue
2737         jsr     pc,nexttab      / next line table entry in r5
2738         clr     (r5)            / 0 indicates file pointer follows
2739         jsr     pc,nexttab      / next entry in r5
2740         mov     4(r1),(r5)      / store pointer to file name
2741 5:      mov     (sp),(r1)       / restored line number in *eb
2742         beq     4f              / do not put 0 in last table
2743         jsr     pc,nexttab      / next entry in r5
2744         mov     (sp),(r5)       / line number in table
2745 4:      cmp     (sp),(r1)       / line number different?
2746         bne     5b              / yes? put it in table
2747 .endif
2748         mov     r0,4(r1)        / old file address
2749         mov     (sp)+,(r1)      / reset line number
2750         next                    / main loop again
2751
2752 lfr.l:  jsr     pc,wrdoff;
2753 8:      bit     $1,r0;          jne     e.illins
2754         cmp     r0,retsize;     jeq     7f;     jsr     pc,e.badlfr
2755 7:      asr     r0;                              / number of words
2756         tst     r0;             beq     0f;
2757         mov     $retarea,r1;    / must point to retarea
2758         add     r0,r1;
2759         add     r0,r1;          / top of result
2760 2:      mov     -(r1),-(sp);    / move word of result
2761         sob     r0,2b;          / look for more
2762 0:      next
2763 lfr.1W: mov     $2,r0;          br      8b
2764 lfr.2W: mov     $4,r0;          br      8b
2765 lfr.s0: clr     r0;             bisb    (pcx)+,r0;      br      8b
2766 /\f
2767 /------------------------------------------------------------------------------
2768
2769 /       miscellaneous
2770 /------------------------------------------------------------------------------
2771 exg.s0: clr     r0;             bisb    (pcx)+,r0;      br      1f
2772 exg.l:  jsr     pc,wrdoff;      br      1f
2773 exg.z:  mov     (sp)+,r0;
2774 1:      cmp     r0,$1;          beq     0f;
2775         blt     9f;             bit     $1,r0;
2776         bne     9f;
2777         add     r0,sp;
2778         mov     r0,r1;          asr     r1;
2779         add     sp,r0;
2780 2:      mov     -(sp),r5;       mov     -(r0),(sp);
2781         mov     r5,(r0);        sob     r1,2b;
2782         next
2783 0:      swab    (sp);           next
2784 9:      jsr     pc,e.oddz;      next
2785
2786
2787
2788
2789 /------------------------------------------------------------------------------
2790
2791 dup.1W:         mov     (sp),-(sp);     next
2792 dup.l:          jsr     pc,wrdoff;      br      1f;
2793 dus.l:          jsr     pc,wrdoff;      br      0f;
2794 dus.z:          mov     (sp)+,r0;
2795 0:              ble     9b;             bit     $1,r0;
2796                 bne     9b;             add     r0,sp;
2797                 tst     -(sp);          mov     (sp)+,r0;
2798 1:              ble     9b;             inc     r0;
2799                 bic     $1,r0;          mov     r0,r1;
2800                 mov     sp,r5;          add     r0,r5;
2801                 asr     r1;
2802 2:              mov     -(r5),-(sp);    sob     r1,2b;       next
2803
2804 nop.z:
2805         next
2806
2807 /------------------------------------------------------------------------------
2808 fil.l:  jsr     pc,wrdoff;      add     eb,r0
2809         cmp     r0,*filb;       beq     1f;
2810 .if .last
2811         clr     *eb                     / new file asks for new line
2812         jsr     pc,nexttab;     clr     (r5);
2813         jsr     pc,nexttab;     mov     *filb,(r5);
2814 .endif
2815 .if .flow + .count + .prof
2816         mov     curproc,r1      / current proc descriptor
2817         mov     4(r1),countfld
2818         sub     6(r1),countfld    / start countptr for this proc
2819         mov     r0,10.(r1)      / file pointer in procdes
2820 .endif
2821         mov     r0,*filb
2822 1:      next
2823 lni.z:  inc     *eb;
2824 .if .count + .flow + .prof
2825         inc     countptr
2826 .if .prof
2827         add     $4,hiprof
2828         add     $4,loprof
2829 .endif
2830 .endif
2831         br      8f
2832 lin.l:  jsr     pc,wrdoff;      br      1f
2833 lin.s0: clr     r0;             bisb    (pcx)+,r0
2834 1:      cmp    *eb,r0;         beq     9f;
2835         mov    r0,*eb
2836 .if .count + .flow + .prof
2837         mov     countfld,r5
2838         add     r0,r5           / this is the right countptr
2839         mov     r5,countptr
2840 .if .prof
2841         asl     r5
2842         asl     r5
2843         add     ltime,r5
2844         mov     r5,hiprof
2845         add     $2,r5
2846         mov     r5,loprof
2847 .endif
2848 .endif
2849 8:
2850 .if .last
2851         jsr     pc,nexttab      / next entry in lasttab
2852         mov     *eb,(r5)        / set endline
2853 .endif
2854 .if .count
2855         mov     countptr,r1          / line number in r1
2856         asl     r1
2857         asl     r1              / multiply by 4
2858         add     lcount,r1       / r1 is pointer to long integer now
2859         add     $1,2(r1)        / cannot be inc
2860         adc     (r1)            / that was all
2861 .endif
2862 .if .flow
2863         mov     countptr,r1          / line number in r1
2864         clr     r0              / get ready for divide
2865         div     $8.,r0          / r0 = byte offset; r1 = bit offset
2866         add     lflow,r0        / r0 is byte pointer now
2867         bisb    bits(r1),(r0)   / set bit
2868 .endif
2869 9:      next
2870
2871 /------------------------------------------------------------------------------
2872
2873 bls.l:  jsr     pc,wrdoff;      br      0f;
2874 bls.z:  mov     (sp)+,r0;
2875 0:      asr     r0
2876         bhi     1f
2877         jbr     e.oddz
2878 1:      mov     (sp)+,r1;       sob     r0,1b;
2879         mov     r1,r0;          br      1f;
2880 blm.l:  jsr     pc,wrdoff
2881         tst     r0
2882         br      1f
2883 blm.s0: clr     r0;             bisb    (pcx)+,r0
2884 1:      jsr     pc,regsave;     jsr     pc,chckptr
2885         mov     (sp)+,r2;       jsr     pc,chckptr
2886         mov     (sp)+,r3
2887         mov     r0,r1
2888         asr     r0
2889         beq     2f      / Now avoid wrong copy. The pieces may overlap !
2890         cmp     r3,r2
2891         beq     2f
2892         blt     3f
2893 1:      mov     (r3)+,(r2)+
2894         sob     r0,1b
2895 2:      jsr     pc,regretu;             next
2896 3:      add     r1,r3;          add     r1,r2;
2897 1:      mov     -(r3),-(r2);    sob     r0,1b;          br    2b
2898 /------------------------------------------------------------------------------
2899 /       Range check and case instructions
2900 /------------------------------------------------------------------------------
2901 csa.l:  jsr     pc,wrdoff;      br      1f;
2902 csa.z:  mov     (sp)+,r0;
2903 1:      sub     $2,r0;          jne     e.illins;
2904 csa.1W: mov     (sp)+,r0;
2905         mov     (sp)+,r1;       sub     2(r0),r1;
2906         blt     6f;             cmp     4(r0),r1;
2907         blo     6f;             asl     r1;
2908         add     $6,r1;          add     r0,r1;
2909 5:      mov     (r1),pcx;
2910         jeq     e.case;         next
2911 6:      mov     r0,r1;          br      5b;
2912
2913 csb.z:  mov     (sp)+,r0;       br      1f;
2914 csb.l:  jsr     pc,wrdoff;
2915 1:      sub     $2,r0;          jne     e.illins;
2916 csb.1W: mov     (sp)+,r0;       mov     (sp)+,r1;
2917         mov     r0,pcx;         mov     2(r0),r5
2918                                         /use pcx as ordinary register
2919         ble     3f
2920 2:      add     $4,r0;          cmp     (r0),r1;
2921         beq     4f;             sob     r5,2b;
2922 3:      mov     (pcx),pcx;      jeq     e.case;         next
2923 4:      mov     2(r0),pcx;      jeq     e.case;         next
2924
2925 rck.l:  jsr     pc,wrdoff;      br      1f;
2926 rck.z:  mov     (sp)+,r0;
2927 1:      sub     $2,r0;          beq     rck.1W;
2928         sub     $2,r0;          jne     e.oddz;
2929         mov     (sp)+,r1;       cmp     (sp),(r1);
2930         blt     9f;             cmp     (sp),4(r1);
2931         bgt     9f;             next
2932 rck.1W: mov     (sp)+,r1;       cmp     (sp),(r1);
2933         blt     9f;             cmp     (sp),2(r1);
2934         bgt     9f;             next
2935 9:      mov     $ERANGE,-(sp);  jmp     trp.z;
2936
2937 /------------------------------------------------------------------------------
2938 /       Load and store register
2939 /------------------------------------------------------------------------------
2940 lbllor:
2941 lor.s0: clr     r0;             bisb    (pcx)+,r0
2942         cmp     r0,$2;          jhi     e.illins
2943         asl     r0;             jmp     1f(r0)
2944 1:      br      2f;     br      3f;     br      4f
2945 2:      mov     lb,-(sp);       next
2946 3:      mov     sp,r1;          mov     r1,-(sp);       next
2947 4:      mov     hp,-(sp);       next
2948 lblstr:
2949 str.s0: clr     r0;             bisb    (pcx)+,r0
2950         cmp     r0,$2;          jhi     e.illins
2951         asl     r0;             jmp     1f(r0)
2952 1:      br      2f;     br      3f;     br      4f
2953 2:      mov     (sp)+,lb;       next
2954 3:      mov     (sp)+,r1;       mov     r1,sp;  next
2955 4:      mov     (sp)+,r1;
2956 5:      cmp     r1,sybreak+2;
2957         blos    5f;             add     $unixextra,sybreak+2;
2958         sys     indir;sybreak           / ask for more core
2959         jec     5b;
2960 1:
2961         jsr     pc,e.heap;                 / core claim failed
2962         next
2963 5:      cmp     r1,globmax;     jlo     1b
2964         mov     r1,hp;          next
2965
2966 /------------------------------------------------------------------------------
2967
2968 ass.l:  jsr     pc,wrdoff;      br      1f
2969 ass.z:  mov     (sp)+,r0;
2970 1:      cmp     $2,r0;          beq     2f
2971         cmp     $4,r0;          jne     e.oddz
2972         mov     (sp)+,r0;
2973 2:      mov     (sp)+,r0;       br      3f
2974 asp.lw: jsr     pc,wrdoff;      br      2f
2975 asp.w0: clr     r0;             bisb    (pcx)+,r0;
2976 2:      asl     r0;             br      3f
2977 asp.1W:         asp.2W:         asp.3W:         asp.4W:         asp.5W:
2978         sub     $88.,r0;
2979 3:      blt     4f;             add     r0,sp;  next
2980 4:      neg     r0;             asr     r0;
2981 2:      mov     $und,-(sp);     sob     r0,2b;  next
2982
2983
2984 /------------------------------------------------------------------------------
2985
2986 dch.z:  mov     (sp)+,r1;       mov     (r1),-(sp);
2987         cmp     (sp),ml;        jge     e.badptr;
2988         next                    / dch adjusts local base to
2989                                 / dynamically previous local base
2990
2991 lpb.z:  add     $8.,(sp);        next    / static link 8 bytes from lb
2992
2993 /------------------------------------------------------------------------------
2994
2995 gto.l:  jsr     pc,wrdoff;      / get descriptor address
2996         add     eb,r0           / descriptor is in external address space
2997         mov     4(r0),r2;       / new local base after jump
2998         mov     2(r0),sp;       / new stack pointer after jump
2999         mov     (r0),pcx;       / new program counter
3000 .if .prof + .flow + .count
3001         mov     firstp,r0
3002 1:      mov     8.(r0),r1
3003         cmp     r3,2(r1)
3004         blos    2f
3005         mov     r1,r0
3006         br      1b
3007 2:      mov     r0,curproc      / procdesbase current proc
3008         mov     4(r0),countfld  / restore pointer to
3009         sub     6(r0),countfld  / table entries
3010         mov     10.(r0),*filb   / file name restored
3011 .endif
3012         next
3013 /------------------------------------------------------------------------------
3014 /       Ignore mask
3015 /------------------------------------------------------------------------------
3016
3017 lim.z:  mov     ignmask,-(sp);  next    / load ignore mask
3018 sim.z:  mov     (sp)+,ignmask;  next    / store ignore mask
3019                                         / for trap routines
3020
3021 sig.z:  mov     (sp),r1;                / exchange previous
3022         mov     uerrorp,(sp);           / and stacked error
3023         mov     r1,uerrorp;             / procedure pointer
3024         next
3025 /------------------------------------------------------------------------------
3026 /       Signals generated by UNIX
3027 /------------------------------------------------------------------------------
3028
3029 sig1:
3030         mov     $sig.trp+0.,-(sp);      br      1f
3031 sig2:
3032         mov     $sig.trp+2.,-(sp);      br      1f
3033 sig3:
3034         mov     $sig.trp+4.,-(sp);      br      1f
3035 sig13:
3036         mov     $sig.trp+24.,-(sp);     br      1f
3037 sig14:
3038         mov     $sig.trp+26.,-(sp);     br      1f
3039 sig15:
3040         mov     $sig.trp+28.,-(sp);     br      1f
3041 sig16:
3042         mov     $sig.trp+30.,-(sp)      / push address trap number
3043 1:      mov     *(sp),-2(sp);           / save trap number
3044         mov     $-2,*(sp)               / set defold trap number
3045         mov     $retutrap,(sp)          / set return address to rti
3046         tst     -(sp)                   / trap number position on stack
3047         jbr     error
3048
3049 sig12:  mov     r0,-(sp)
3050         mov     $2,r0;                  / fildes standard error
3051         sys     0;      9b              / call write message
3052         sys     signal;12.;sig12        / this is a mon-error
3053         jsr     pc,e.badmon
3054         mov     (sp)+,r0
3055         rti
3056
3057 sig11:  mov     r0,saver1        /save r0
3058         mov     sybreak+2,r0
3059         sub     sp,r0
3060         jgt     e.memflt        /real trap
3061         mov     $7f,r0
3062         mov     argv,sp         /setup a new stack
3063         jbr     rude_error
3064
3065         .data
3066 7:      <stack overflow\n\0>
3067         .even
3068 sybreak:sys     break;_end      /For indirect calling of break
3069         .text
3070 sig8:   mov     r0,saver1;
3071         sys     signal;8.;sig8
3072         mov     $ECONV,fpperr+6
3073         stfps   r0
3074         bit     $100,r0
3075         beq     1f
3076         mov     $ECONV,fpperr+6
3077 1:      stst    r0
3078         mov     $retutrap,-(sp)
3079         mov     fpperr(r0),-(sp)
3080         mov     saver1,r0
3081         jbr     error
3082 retutrap:        rti
3083         .data
3084 fpperr: EILLINS; EILLINS; EFDIVZ; ECONV; EFOVFL; EFUNFL; EFUND; EILLINS
3085         .text
3086 /------------------------------------------------------------------------------
3087 /       Errors,traps and all their friends
3088
3089 /------------------------------------------------------------------------------
3090
3091 savereg:        mov     r1,-(sp)        / stack r1 so r1 scratch register
3092                 mov     2(sp),r1        / now r1 contains return address
3093                 mov     r0,2(sp)        / save r0
3094                 mov     r2,-(sp)        / save r2
3095                 mov     r3,-(sp)        / save r3
3096                 mov     r4,-(sp)        / save r4
3097                 mov     r5,-(sp)        / save r5
3098                 mov     12.(sp),r0      / copy error number or param 0
3099                 movf    fr0,-(sp)       / save float registers
3100                 movf    fr1,-(sp)       / fr0 and fr1
3101                 stfps   -(sp)           / and status
3102                 mov     $retsize+26.,r5
3103                 mov     $13.,r2
3104 8:              mov     -(r5),-(sp);    sob     r2,8b
3105                 mov     r0,-(sp)        / extra errno (param 0) on stack
3106                 mov     r1,-(sp)        / set return address
3107                 rts     pc
3108
3109 restoreg:       mov     (sp)+,r1        / return address in r1
3110                 add     $2,sp           / skip error number (param 0)
3111                 mov     $13.,r2;
3112                 mov     $retsize,r5;
3113 8:              mov     (sp)+,(r5)+;    sob     r2,8b
3114                 ldfps   (sp)+           / restore floating point status
3115                 movf    (sp)+,fr1       / restore float registers
3116                 movf    (sp)+,fr0       / fr0 and fr1
3117                 mov     (sp)+,r5        / restore r5
3118                 mov     (sp)+,r4        / restore r4
3119                 mov     (sp)+,r3        / restore r3
3120                 mov     (sp)+,r2        / restore r2
3121                 mov     2(sp),r0        / restore r0
3122                 mov     r1,2(sp)        / reset return address
3123                 mov     (sp)+,r1        / restore r1
3124                 rts     pc
3125
3126 /------------------------------------------------------------------------------
3127 /       Various error entries
3128 /------------------------------------------------------------------------------
3129
3130 e.badlfr:       mov     r0,r5;  mov     $2,r0;  mov     $blfr,9f+2
3131                 sys     0;9f;
3132                 mov     r5,r0;  rts     pc
3133 .data
3134 9:              sys     write;7;0;
3135 blfr:           <badlfr\n\0>
3136 .even
3137 .text
3138
3139 e.iund:         mov     $EIUND,-(sp);          br      error
3140 e.iovfl:        mov     $EIOVFL,-(sp);         br      error
3141 e.idivz:        mov     $EIDIVZ,-(sp);         br      error
3142 e.range:        mov     $ERANGE,-(sp);         br      error
3143 e.set:          mov     $ESET,-(sp);           br      error
3144 e.badptr:       mov     $EBADPTR,-(sp);        br      fatal
3145 e.fovfl:        mov     $EFOVFL,-(sp);         br      error
3146 e.funfl:        mov     $EFUNFL,-(sp);         br      error
3147 e.fdivz:        mov     $EFDIVZ,-(sp);         br      error
3148 e.fund:         mov     $EFUND,-(sp);          br      error
3149 e.conv:         mov     $ECONV,-(sp);          br      error
3150 e.stack:        mov     $ESTACK,-(sp);         br      fatal
3151 e.badpc:        mov     $EBADPC,-(sp);         br      fatal
3152 e.badlin:       mov     $EBADLIN,-(sp);        br      error
3153 e.badlae:       mov     $EBADLAE,-(sp);        br      error
3154 e.array:        mov     $EARRAY,-(sp);         br      error
3155 e.badmon:       mov     $EBADMON,-(sp);        br      error
3156 e.case:         mov     $ECASE,-(sp);          br      fatal
3157 e.oddz:         mov     $EODDZ,-(sp);          br      fatal
3158 e.illins:       mov     $EILLINS,-(sp);        br      fatal
3159 e.heap:         mov     $EHEAP,-(sp);          br      error
3160 e.memflt:       mov     $EMEMFLT,-(sp);        br      fatal
3161 e.badgto:       mov     $EBADGTO,-(sp);         br      error
3162 /------------------------------------------------------------------------------
3163
3164 fatal:  mov     $hlt.z,-(sp)    / return from fatal halts
3165         mov     2(sp),-(sp)     / dup error number
3166 error:
3167         jsr     pc,savereg      / save old register contents
3168         cmp     $16.,r0;
3169         ble     9f;
3170         mov     $1,r1
3171         ash     r0,r1
3172         bic     ignmask,r1
3173         bne     9f
3174         jsr     pc,restoreg
3175         add     $2,sp           / remove error number from stack
3176         rts     pc
3177 9:
3178         cmp     uerrorp,$-1     / has the user defined a trapprocedure ?
3179         beq     notrap          / if not kill it off fast
3180         mov     uerrorp,-(sp)   / go for cal
3181         mov     $-1,uerrorp     / user must set trap again
3182         jbr     precal          / call trap routine
3183
3184 /------------------------------------------------------------------------------
3185
3186 rtt.z:  mov     r2,sp           / sp to bottom frame
3187         add     $8,sp           / set to top frame
3188         jsr     pc,restoreg     / restore status and registers
3189         add     $2,sp           / skip error number
3190         rts     pc
3191 /------------------------------------------------------------------------------
3192 trp.z:  mov     (sp),-(sp);     / error number one down
3193         mov     r4,2(sp);       / set return address to main loop
3194         jbr     error           / call error routine
3195
3196 /------------------------------------------------------------------------------
3197
3198 notrap: mov     (sp),r1         / error number
3199         mov     $num+9.,r0
3200         mov     r1,retarea      / set error number for exit status
3201         jsr     pc,itoa         / make string
3202         mov     $num,r0
3203 rude_error:
3204         mov     r0,8f+4
3205         mov     *filb,8f        / pointer to file name
3206         mov     *eb,r1          / line number
3207         mov     $line,8f+6      / line message
3208         mov     $line+21.,r0
3209         jsr     pc,itoa         / convert to string
3210 1:      mov     $8f,r4
3211 2:      mov     (r4)+,r0        / next string
3212         beq     5f
3213 3:      mov     r0,9f+2
3214 4:      tstb    (r0)+           / find zero byte
3215         bne     4b
3216         dec     r0
3217         sub     9f+2,r0         / string length
3218         mov     r0,9f+4
3219         mov     $2,r0           / diagnostic output
3220         sys     0; 9f
3221         jbr     2b
3222 5:                              / no file
3223         mov     $-1,argc
3224         jbr     hlt.z
3225
3226 itoa:   mov     r5,-(sp)
3227         mov     r0,r5
3228 1:      clr     r0
3229         div     $10.,r0
3230         add     $'0,r1
3231         movb    r1,-(r5)
3232         mov     r0,r1
3233         bne     1b
3234         mov     r5,r0
3235         mov     (sp)+,r5
3236         rts     pc
3237
3238         .data
3239 uerrorp:        -1              / undefined trap procedure
3240 sep:    <: \0>
3241 line:   < on source line      \n\0>
3242 num:    <error    \0>
3243         .even
3244 8:      0                       / name of text file
3245         sep                     / separator
3246         0                       / error
3247         line+21.                / line number if present
3248         0                       / end of list
3249 lblwri:
3250 9:      sys     write;0;0
3251         .text
3252 /------------------------------------------------------------------------------
3253 /       Exit instruction, with all it's crud
3254 /------------------------------------------------------------------------------
3255
3256 hlt.z:
3257         mov     (sp)+,retarea
3258 .if .count + .flow + .prof
3259         br      9f
3260 .endif
3261         bne     9f
3262         clr     r0
3263         sys     exit
3264 9:
3265 lblhalt:
3266         sys     creat;1f;666
3267 .data
3268 1:      <em_runinf\0>
3269 2:      <runinf file failed\n\0>
3270 .even
3271 .text
3272         bec     2f
3273 3:      mov     $2b,lblwri+2
3274         mov     $19.,lblwri+4
3275         mov     $2.,r0
3276         sys     indir;lblwri
3277         br      9f
3278 2:      mov     r0,saver0
3279         mov     $hp,r1
3280         mov     r1,ndatad
3281         mov     $txtsiz,r5
3282         mov     r5,txtsiz
3283         sub     r5,r1
3284         mov     r5,lblwri+2
3285         mov     r1,lblwri+4
3286         clr     r1
3287 .if .last
3288         add     $1,r1
3289 .endif
3290 .if .opfreq
3291         add     $2,r1
3292 .endif
3293 .if .count
3294         add     $4,r1
3295 .endif
3296 .if .flow
3297         add     $8.,r1
3298 .endif
3299 .if .prof
3300         add     $16.,r1
3301 .endif
3302         mov     r1,entry.
3303         sys     indir;lblwri
3304         bes     3b
3305         mov     pd,lblwri+2
3306         mov     tblmax,lblwri+4
3307         sub     pd,lblwri+4
3308         mov     saver0,r0
3309         sys     indir;lblwri
3310         bes     3b
3311         mov     ml,lblwri+2
3312         mov     ml,lblwri+4
3313         neg     lblwri+4
3314         mov     saver0,r0
3315         sys     indir;lblwri
3316         bes     3b
3317 9:
3318         mov     retarea,r0      / set exit status
3319 2:      sys     exit
3320
3321 /------------------------------------------------------------------------------
3322 /       System call interface routine
3323 /------------------------------------------------------------------------------
3324 R0_IN   =       0200
3325 R1_IN   =       0100
3326 R0_OUT  =       040
3327 R1_OUT  =       020
3328 CBIT    =       010
3329
3330 lblmon:
3331 mon.z:
3332         mov     (sp)+,r0;       / call number from stack
3333         cmp     r0,$1           / sys exit ?
3334         jeq     hlt.z           / go there
3335         bit     $177700,r0;     / range 0-63?
3336         bne     mon.bad;        / no? bad call
3337         movb    r0,call;        / move call number in system call
3338         movb    tab(r0),r5;     / table lookup call conditions
3339         cmp     r5,$-1;         / compare for special context
3340         beq     mon.special;    / yes? jump to special context
3341 monmon: mov     r5,r4;          / save call conditions
3342         rolb    r5              / R0_IN
3343         bcc     1f              / check if bit 7 is on
3344         mov     (sp)+,r0;       / call argument in r0
3345 1:      rolb    r5              / R1_IN
3346         bcc     1f              / check if bit 6 is on
3347         mov     (sp)+,r1;       / argument in r1
3348 1:      bic     $177770,r4      / clear all exept bits  2,1,0
3349         beq     2f              / if 0 forget about args
3350         mov     r3,saver1       / save r3
3351         mov     $call+2,r3      / base of args for call
3352 1:      mov     (sp)+,(r3)+     / move argument
3353         sob     r4,1b           / look for more
3354         mov     saver1,r3       / restore r3
3355 2:      sys     indir;call      / this is it folks
3356         bcc     1f              / no error set? forward
3357         mov     r0,r4           / copy error in r4
3358 1:      rolb    r5              / R0_OUT
3359         bcc     1f              / check original bit 5
3360         mov     r0,-(sp)        / stack r0 from errno
3361 1:      rolb    r5              / R1_OUT
3362         bcc     1f              / check original bit 4
3363         mov     r1,-(sp)        / stack r1
3364 1:      rolb    r5              / CBIT
3365         bcc     mon.end         / no c-bit then ready
3366 mon.cbit:
3367         mov     r4,-(sp)        / stack errno
3368         beq     mon.end         / only once if no error
3369         mov     r4,-(sp)        / stack errno twice when  error
3370 mon.end:
3371         mov     $loop,r4        / restore r4
3372         next                    / ready
3373
3374 mon.special:                    / special calls decoded here
3375         cmp     r0,$fork        / fork?
3376         beq     mon.fork
3377         cmp     r0,$signal      / signal?
3378         beq     mon.signal
3379 mon.bad:                        / otherwise undecodable
3380         mov     saver0,r4       / restore r4
3381         jsr     pc,e.badmon     / mon call error routine
3382         next
3383
3384 mon.fork:
3385         clr     r5
3386         clr     r4
3387         sys     fork
3388         inc     r5
3389         bcc     1f
3390         mov     r0,r4
3391 1:      mov     r0,-(sp)
3392         mov     r5,-(sp)
3393         br      mon.cbit
3394 mon.signal:
3395 msign:
3396         mov     (sp)+,r1                / trap number
3397         mov     (sp)+,r0                / signal number
3398         cmp     r0,$16.                 / only 1 - 16 legal
3399         bhi     sig.bad
3400         mov     r0,call+2               / move signal number into call
3401         beq     sig.bad                 / 0 illegal
3402         asl     r0                      / make 2-32 and even
3403         mov     sig.trp-2(r0),r5        / previous trap number
3404         cmp     r1,$256.                / values -1 and -2 special
3405         bhis    1f
3406         mov     sig.adr-2(r0),r4        / zero label means illegal signal
3407         bne     2f
3408 sig.bad:
3409         mov     $EINVAL,r4              / bad signal
3410         jbr     mon.cbit                / and continue
3411 1:      cmp     r1,$-3                  / -2: reset default, -3: ignore
3412         blo     sig.bad
3413         mov     r1,r4                   / trap number in r4
3414         inc     r4
3415         inc     r4                      / -2 -> 0, -3 -> -1
3416 2:      mov     r1,sig.trp-2(r0)        / new trap number
3417                                         / -3 if ignored; -2 if default action
3418         mov     r4,call+4               / translated trap number in call
3419         clr     r4
3420         sys     indir;call
3421         bcs     sig.bad                 / unlikely to happen
3422         asr     r0                      / special if old label odd
3423         bcc     1f
3424         mov     $-3,r5                  / set ignore signal
3425 1:      mov     r5,-(sp)                / push trap number
3426         jbr     mon.cbit
3427
3428
3429         .data
3430
3431 call:   sys 0;  0;      0;      0;      0
3432 sig.trp:
3433         -2;     -2;     -2;     -2;     -2;     -2;     -2;     -2
3434         -2;     -2;     21.;    25.;     -2;     -2;     -2;     -2
3435 sig.adr:
3436         sig1;   sig2;   sig3;   0;      0;      0;      0;      sig8
3437         0;      0;      sig11;  sig12;  sig13;  sig14;  sig15;  sig16
3438
3439 tab:
3440 .if V6
3441 .byte -1                                        /  0 = indir
3442 .byte -1                                        /  1 = exit
3443 .byte -1                                        /  2 = fork
3444 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  3 = read
3445 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  4 = write
3446 .byte 2                 +R0_OUT         +CBIT   /  5 = open
3447 .byte 0         +R0_IN                  +CBIT   /  6 = close
3448 .byte 0                 +R0_OUT +R1_OUT +CBIT   /  7 = wait
3449 .byte 2                 +R0_OUT         +CBIT   /  8 = creat
3450 .byte 2                                 +CBIT   /  9 = link
3451 .byte 1                                 +CBIT   / 10 = unlink
3452 .byte 2                                 +CBIT   / 11 = exec
3453 .byte 1                                 +CBIT   / 12 = chdir
3454 .byte 0                 +R0_OUT +R1_OUT         / 13 = time
3455 .byte 3                                 +CBIT   / 14 = mknod
3456 .byte 2                                 +CBIT   / 15 = chmod
3457 .byte 2                                 +CBIT   / 16 = chown
3458 .byte -1                                        / 17 = break
3459 .byte 2                                 +CBIT   / 18 = stat
3460 .byte 2         +R0_IN                  +CBIT   / 19 = seek
3461 .byte 0                 +R0_OUT                 / 20 = getpid
3462 .byte 3                                 +CBIT   / 21 = mount
3463 .byte 1                                 +CBIT   / 22 = umount
3464 .byte 0         +R0_IN                  +CBIT   / 23 = setuid
3465 .byte 0                 +R0_OUT                 / 24 = getuid
3466 .byte 0 +R1_IN  +R0_IN                  +CBIT   / 25 = stime
3467 .byte 3         +R0_IN  +R0_OUT         +CBIT   / 26 = ptrace
3468 .byte -1                                        / 27 = x
3469 .byte 1         +R0_IN                  +CBIT   / 28 = fstat
3470 .byte -1                                        / 29 = x
3471 .byte -1                                        / 30 = x
3472 .byte 1         +R0_IN                  +CBIT   / 31 = stty
3473 .byte 1         +R0_IN                  +CBIT   / 32 = gtty
3474 .byte -1                                        / 33 = x
3475 .byte 0         +R0_IN                  +CBIT   / 34 = nice
3476 .byte 0         +R0_IN                          / 35 = sleep
3477 .byte 0                                         / 36 = sync
3478 .byte 1         +R0_IN                  +CBIT   / 37 = kill
3479 .byte 0                 +R0_OUT                 / 38 = csw
3480 .byte -1                                        / 39 = x
3481 .byte -1                                        / 40 = x
3482 .byte 0         +R0_IN  +R0_OUT         +CBIT   / 41 = dup
3483 .byte 0                 +R0_OUT +R1_OUT +CBIT   / 42 = pipe
3484 .byte 1                                         / 43 = times
3485 .byte 4                                         / 44 = prof
3486 .byte -1                                        / 45 = x
3487 .byte 0         +R0_IN                  +CBIT   / 46 = setgid
3488 .byte 0                 +R0_OUT                 / 47 = getgid
3489 .byte -1                                        / 48 = signal
3490 .byte -1                                        / 49 = reserved for USG
3491 .byte -1                                        / 50 = reserved for USG
3492 .byte -1                                        / 51 = x
3493 .byte -1                                        / 52 = x
3494 .byte -1                                        / 53 = x
3495 .byte -1                                        / 54 = x
3496 .byte -1                                        / 55 = x
3497 .byte -1                                        / 56 = x
3498 .byte -1                                        / 57 = x
3499 .byte -1                                        / 58 = x
3500 .byte -1                                        / 59 = x
3501 .byte -1                                        / 60 = x
3502 .byte -1                                        / 61 = x
3503 .byte -1                                        / 62 = x
3504 .byte -1                                        / 63 = x
3505 .endif
3506
3507 .if VPLUS
3508 .byte -1                                        /  0 = indir
3509 .byte -1                                        /  1 = exit
3510 .byte -1                                        /  2 = fork
3511 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  3 = read
3512 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  4 = write
3513 .byte 2                 +R0_OUT         +CBIT   /  5 = open
3514 .byte 0         +R0_IN                  +CBIT   /  6 = close
3515 .byte 0                 +R0_OUT +R1_OUT +CBIT   /  7 = wait
3516 .byte 2                 +R0_OUT         +CBIT   /  8 = creat
3517 .byte 2                                 +CBIT   /  9 = link
3518 .byte 1                                 +CBIT   / 10 = unlink
3519 .byte 2                                 +CBIT   / 11 = exec
3520 .byte 1                                 +CBIT   / 12 = chdir
3521 .byte 0                 +R0_OUT +R1_OUT         / 13 = time
3522 .byte 3                                 +CBIT   / 14 = mknod
3523 .byte 2                                 +CBIT   / 15 = chmod
3524 .byte 2                                 +CBIT   / 16 = chown
3525 .byte -1                                        / 17 = break
3526 .byte 2                                 +CBIT   / 18 = stat
3527 .byte 2         +R0_IN                  +CBIT   / 19 = seek
3528 .byte 0                 +R0_OUT                 / 20 = getpid
3529 .byte 3                                 +CBIT   / 21 = mount
3530 .byte 1                                 +CBIT   / 22 = umount
3531 .byte 0         +R0_IN                  +CBIT   / 23 = setuid
3532 .byte 0                 +R0_OUT                 / 24 = getuid
3533 .byte 0 +R1_IN  +R0_IN                  +CBIT   / 25 = stime
3534 .byte 3         +R0_IN  +R0_OUT         +CBIT   / 26 = ptrace
3535 .byte 0         +R0_IN  +R0_OUT                 / 27 = alarm
3536 .byte 1         +R0_IN                  +CBIT   / 28 = fstat
3537 .byte 0                                         / 29 = pause
3538 .byte -1                                        / 30 = x
3539 .byte 1         +R0_IN                  +CBIT   / 31 = stty
3540 .byte 1         +R0_IN                  +CBIT   / 32 = gtty
3541 .byte 2                                 +CBIT   / 33 = access
3542 .byte 0         +R0_IN                  +CBIT   / 34 = nice
3543 .byte 0         +R0_IN                          / 35 = sleep
3544 .byte 0                                         / 36 = sync
3545 .byte 1         +R0_IN                  +CBIT   / 37 = kill
3546 .byte 0                 +R0_OUT                 / 38 = csw
3547 .byte -1                                        / 39 = x
3548 .byte 0         +R0_IN  +R0_OUT +R1_OUT +CBIT   / 40 = tell
3549 .byte 0         +R0_IN  +R0_OUT         +CBIT   / 41 = dup
3550 .byte 0                 +R0_OUT +R1_OUT +CBIT   / 42 = pipe
3551 .byte 1                                         / 43 = times
3552 .byte 4                                         / 44 = prof
3553 .byte -1                                        / 45 = x
3554 .byte 0         +R0_IN                  +CBIT   / 46 = setgid
3555 .byte 0                 +R0_OUT                 / 47 = getgid
3556 .byte -1                                        / 48 = signal
3557 .byte -1                                        / 49 = reserved for USG
3558 .byte -1                                        / 50 = reserved for USG
3559 .byte 1                                 +CBIT   / 51 = acct
3560 .byte -1                                        / 52 = x
3561 .byte -1                                        / 53 = x
3562 .byte -1                                        / 54 = x
3563 .byte -1                                        / 55 = x
3564 .byte -1                                        / 56 = x
3565 .byte -1                                        / 57 = x
3566 .byte -1                                        / 58 = x
3567 .byte -1                                        / 59 = x
3568 .byte -1                                        / 60 = x
3569 .byte -1                                        / 61 = x
3570 .byte -1                                        / 62 = x
3571 .byte -1                                        / 63 = x
3572 .endif
3573
3574 .if V7
3575 .byte -1                                        /  0 = indir
3576 .byte 0                                         /  1 = exit
3577 .byte -1                                        /  2 = fork
3578 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  3 = read
3579 .byte 2         +R0_IN  +R0_OUT         +CBIT   /  4 = write
3580 .byte 2                 +R0_OUT         +CBIT   /  5 = open
3581 .byte 0         +R0_IN                  +CBIT   /  6 = close
3582 .byte 0                 +R0_OUT +R1_OUT +CBIT   /  7 = wait
3583 .byte 2                 +R0_OUT         +CBIT   /  8 = creat
3584 .byte 2                                 +CBIT   /  9 = link
3585 .byte 1                                 +CBIT   / 10 = unlink
3586 .byte -1                                        / 11 = x no exec in em code
3587 .byte 1                                 +CBIT   / 12 = chdir
3588 .byte -1                                        / 13 = x time is obsolete
3589 .byte 3                                 +CBIT   / 14 = mknod
3590 .byte 2                                 +CBIT   / 15 = chmod
3591 .byte 3                                 +CBIT   / 16 = chown
3592 .byte -1                                        / 17 = break
3593 .byte 2                                 +CBIT   / 18 = stat
3594 .byte 3         +R0_IN  +R0_OUT +R1_OUT +CBIT   / 19 = lseek
3595 .byte 0                 +R0_OUT                 / 20 = getpid
3596 .byte 3                                 +CBIT   / 21 = mount
3597 .byte 1                                 +CBIT   / 22 = umount
3598 .byte 0         +R0_IN                  +CBIT   / 23 = setuid
3599 .byte 0                 +R0_OUT +R1_OUT         / 24 = getuid
3600 .byte 0 +R1_IN  +R0_IN                  +CBIT   / 25 = stime
3601 .byte 3         +R0_IN  +R0_OUT         +CBIT   / 26 = ptrace
3602 .byte 0         +R0_IN  +R0_OUT                 / 27 = alarm
3603 .byte 1         +R0_IN                  +CBIT   / 28 = fstat
3604 .byte 0                                         / 29 = pause
3605 .byte 2                                 +CBIT   / 30 = utime
3606 .byte -1                                        / 31 = x
3607 .byte -1                                        / 32 = x
3608 .byte 2                                 +CBIT   / 33 = access
3609 .byte 0         +R0_IN                  +CBIT   / 34 = nice
3610 .byte 1                                         / 35 = ftime
3611 .byte 0                                         / 36 = sync
3612 .byte 1         +R0_IN                  +CBIT   / 37 = kill
3613 .byte -1                                        / 38 = x
3614 .byte -1                                        / 39 = x
3615 .byte -1                                        / 40 = x
3616 .byte 0 +R1_IN  +R0_IN  +R0_OUT         +CBIT   / 41 = dup
3617 .byte 0                 +R0_OUT +R1_OUT +CBIT   / 42 = pipe
3618 .byte 1                                         / 43 = times
3619 .byte 4                                         / 44 = prof
3620 .byte -1                                        / 45 = x
3621 .byte 0         +R0_IN                  +CBIT   / 46 = setgid
3622 .byte 0                 +R0_OUT +R1_OUT         / 47 = getgid
3623 .byte -1                                        / 48 = signal
3624 .byte -1                                        / 49 = reserved for USG
3625 .byte -1                                        / 50 = reserved for USG
3626 .byte 1                                 +CBIT   / 51 = acct
3627 .byte 3                                 +CBIT   / 52 = phys
3628 .byte 1                                 +CBIT   / 53 = lock
3629 .byte 3                                 +CBIT   / 54 = ioctl
3630 .byte -1                                        / 55 = x
3631 .byte 2                                 +CBIT   / 56 = mpxcall
3632 .byte -1                                        / 57 = x
3633 .byte -1                                        / 58 = x
3634 .byte 3                                 +CBIT   / 59 = exece
3635 .byte 1                                 +CBIT   / 60 = umask
3636 .byte 1                                 +CBIT   / 61 = chroot
3637 .byte -1                                        / 62 = x
3638 .byte -1                                        / 63 = x
3639 .endif
3640
3641         .text
3642 /------------------------------------------------------------------------------
3643 /       General subroutines
3644 /------------------------------------------------------------------------------
3645
3646 wrdoff: movb    (pcx)+,r0       /get first byte
3647         swab    r0              /put it in high byte
3648         clrb    r0              /clear low byte of r0
3649         bisb    (pcx)+,r0       /"or" second byte in
3650         rts     pc              /done
3651
3652 /------------------------------------------------------------------------------
3653
3654 tstr0:  cmp     r0,$04;         jgt     e.oddz;
3655         cmp     r0,$02;         jne     e.oddz;         rts pc
3656
3657 chckptr:                        / this routine traps a pointer outside
3658                                 / the globals, the stack or the heap
3659         bit     $1,2(sp);       bne     8f
3660 chckptb:
3661         mov     2(sp),r5;
3662         cmp     r5,sp;          bhis    9f
3663         cmp     r5,hp;          bhis    8f
3664 .if  .count + .prof + .flow
3665         cmp     r5,tblmax;      bhis    9f
3666         cmp     r5,globmax;     bhis    8f
3667 .endif
3668         cmp     r5,eb;          bhis    9f
3669 8:      jsr     pc,e.badptr
3670 9:      rts     pc
3671
3672 .if .last
3673 nexttab: mov    linused,r5;
3674         add     $2,r5           / increment lasttab
3675         cmp     r5,$linused     / top of table reached?
3676         blo     1f
3677         sub     $96.,r5
3678 1:      mov     r5,linused
3679         rts     pc
3680 .endif
3681 regsave:
3682         mov     r5,savearea
3683         mov     $[savearea+2],r5
3684         mov     r4,(r5)+
3685         mov     r3,(r5)+
3686         mov     r2,(r5)
3687         rts     pc
3688 regretu:
3689         mov     $[savearea+6],r5
3690         mov     (r5),r2
3691         mov     -(r5),r3
3692         mov     -(r5),r4
3693         mov     -(r5),r5
3694         rts     pc
3695
3696 setfloat:
3697         cmp     r0,$8.
3698         bne     1f
3699         setd
3700         rts     pc
3701 1:      cmp     r0,$04
3702         bne     3f
3703         setf
3704 2:      rts     pc
3705 3:      jmp     e.oddz
3706 setint:
3707         cmp     r0,$04
3708         bne     4f
3709         setl
3710         rts     pc
3711 4:      cmp     r0,$02
3712         bne     3b
3713         seti
3714 5:      rts     pc
3715
3716
3717
3718 /------------------------------------------------------------------------------
3719 /       Leftover data
3720 /------------------------------------------------------------------------------
3721
3722
3723
3724
3725         .bss
3726 filb:   .=.+2
3727 curproc:.=.+2
3728 linmax: .=.+2
3729 countptr:.=.+2
3730 countfld:.=.+2
3731 hiprof: .=.+2
3732 loprof: .=.+2
3733 ignmask:.=.+2           / ignore mask for trap
3734 retsize:.=.+2           / size of return value of function
3735 retarea:.=.+8           / return area for function value
3736 savearea:       .=.+8   / save register area
3737 saver0: .=.+2
3738 saver1: .=.+2
3739 header:
3740         txtsiz: .=.+2   / program textsize in bytes
3741         ndatad: .=.+2   / number of loadfile descriptors
3742         nprocs: .=.+2   / number of entries in procedure descriptors
3743 option: entry.: .=.+2   / procedure number to start
3744         nlines: .=.+2   / maximum sorceline number
3745         szdata: .=.+2   / address of lowest uninitialized byte
3746         firstp: .=.+2   / descriptor address first basic block of text
3747         maxcount: .=.+2 / total number of processable source lines
3748 argc:   .=.+2
3749 argv:   .=.+2
3750 environ:
3751         .=.+2
3752 pb:     .=.+2
3753 pd:     .=.+2
3754 eb:     .=.+2
3755 globmax:
3756         .=.+2
3757 tblmax: .=.+2
3758 ml:     .=.+2
3759 .if .last
3760 lasttab:.=.+96.        / 16 descriptors of integers + index at the end
3761 linused:.=.+2
3762 .endif
3763
3764 .if .opfreq
3765 counttab:
3766         .=.+1664.
3767 .endif
3768
3769 .if .count
3770 lcount: .=.+2
3771 countsiz:.=.+2
3772 .endif
3773
3774 .if .flow
3775 lflow:  .=.+2
3776 flowsiz:.=.+2
3777 .endif
3778
3779 .if .prof
3780 ltime:  .=.+2
3781 profsiz:.=.+2
3782 .endif
3783
3784 hp:     .=.+2