Pristine Ack-5.5
[Ack-5.5.git] / mach / m68020 / libem / libem_s.a
1 eÿfp68881.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ÿ\ f.define .adf4, .adf8, .sbf4, .sbf8, .mlf4, .mlf8, .dvf4, .dvf8
2 .define .ngf4, .ngf8, .fif4, .fif8, .fef4, .fef8
3 .define .cif4, .cif8, .cuf4, .cuf8, .cfi, .cfu, .cff4, .cff8
4 .define .cmf4, .cmf8
5 .sect .text
6 .sect .rom
7 .sect .data
8 .sect .bss
9
10 !       $Id: fp68881.s,v 1.6 1994/06/24 13:06:44 ceriel Exp $
11
12 !       Implement interface to floating point package for M68881
13
14         .sect .text
15 .adf4:
16         move.l  (sp)+,a0
17         fmove.s (sp),fp0
18         fadd.s  (4,sp),fp0
19         fmove.s fp0,(4,sp)
20         jmp     (a0)
21
22 .adf8:
23         move.l  (sp)+,a0
24         fmove.d (sp),fp0
25         fadd.d  (8,sp),fp0
26         fmove.d fp0,(8,sp)
27         jmp     (a0)
28
29 .sbf4:
30         move.l  (sp)+,a0
31         fmove.s (sp),fp0
32         fmove.s (4,sp),fp1
33         fsub    fp0,fp1
34         fmove.s fp1,(4,sp)
35         jmp     (a0)
36
37 .sbf8:
38         move.l  (sp)+,a0
39         fmove.d (sp),fp0
40         fmove.d (8,sp),fp1
41         fsub    fp0,fp1
42         fmove.d fp1,(8,sp)
43         jmp     (a0)
44
45 .mlf4:
46         move.l  (sp)+,a0
47         fmove.s (sp),fp0
48         fmul.s  (4,sp),fp0
49         fmove.s fp0,(4,sp)
50         jmp     (a0)
51
52 .mlf8:
53         move.l  (sp)+,a0
54         fmove.d (sp),fp0
55         fmul.d  (8,sp),fp0
56         fmove.d fp0,(8,sp)
57         jmp     (a0)
58
59 .dvf4:
60         move.l  (sp)+,a0
61         fmove.s (sp),fp0
62         fmove.s (4,sp),fp1
63         fdiv    fp0,fp1
64         fmove.s fp1,(4,sp)
65         jmp     (a0)
66
67 .dvf8:
68         move.l  (sp)+,a0
69         fmove.d (sp),fp0
70         fmove.d (8,sp),fp1
71         fdiv    fp0,fp1
72         fmove.d fp1,(8,sp)
73         jmp     (a0)
74
75 .ngf4:
76         fmove.s (4,sp),fp0
77         fneg    fp0
78         fmove.s fp0,(4,sp)
79         rts
80
81 .ngf8:
82         fmove.d (4,sp),fp0
83         fneg    fp0
84         fmove.d fp0,(4,sp)
85         rts
86
87 .fif4:
88         move.l  (sp)+,a0
89         move.l  (sp),a1
90         fmove.s (4,sp),fp0
91         fmove.s (8,sp),fp1
92         fmul    fp0,fp1
93         fintrz  fp1,fp0
94         fsub    fp0,fp1
95         fmove.s fp1,(4,a1)
96         fmove.s fp0,(a1)
97         jmp     (a0)
98
99 .fif8:
100         move.l  (sp)+,a0
101         move.l  (sp),a1
102         fmove.d (4,sp),fp0
103         fmove.d (12,sp),fp1
104         fmul    fp0,fp1
105         fintrz  fp1,fp0
106         fsub    fp0,fp1
107         fmove.d fp1,(8,a1)
108         fmove.d fp0,(a1)
109         jmp     (a0)
110
111 .fef4:
112         move.l  (sp)+,a0
113         move.l  (sp),a1
114         fmove.s (4,sp),fp0
115         fgetexp fp0,fp1
116         fmove.l fpsr,d0
117         and.l   #0x2000,d0      ! set if Infinity
118         beq     1f
119         move.l  #129,(a1)
120         fmove.s (4,sp),fp0
121         fblt    2f
122         move.l  #0x3f000000,(4,a1)
123         jmp     (a0)
124 2:
125         move.l  #0xbf000000,(4,a1)
126         jmp     (a0)
127 1:
128         fmove.l fp1,d0
129         add.l   #1,d0
130         fgetman fp0
131         fbne    1f
132         clr.l   d0
133         bra     2f
134 1:
135         fmove.l #2,fp1
136         fdiv    fp1,fp0
137 2:
138         fmove.s fp0,(4,a1)
139         move.l  d0,(a1)
140         jmp     (a0)
141
142 .fef8:
143         move.l  (sp)+,a0
144         move.l  (sp),a1
145         fmove.d (4,sp),fp0
146         fgetexp fp0,fp1
147         fmove.l fpsr,d0
148         and.l   #0x2000,d0      ! set if Infinity
149         beq     1f
150         move.l  #1025,(a1)
151         fmove.d (4,sp),fp0
152         fblt    2f
153         move.l  #0x3fe00000,(4,a1)
154         clr.l   (8,a1)
155         jmp     (a0)
156 2:
157         move.l  #0xbfe00000,(4,a1)
158         clr.l   (8,a1)
159         jmp     (a0)
160 1:
161         fmove.l fp1,d0
162         add.l   #1,d0
163         fgetman fp0
164         fbne    1f
165         clr.l   d0
166         bra     2f
167 1:
168         fmove.l #2,fp1
169         fdiv    fp1,fp0
170 2:
171         fmove.d fp0,(4,a1)
172         move.l  d0,(a1)
173         jmp     (a0)
174
175 .cif4:
176         move.l  (sp)+,a0
177         fmove.l (4,sp),fp0
178         fmove.s fp0,(4,sp)
179         jmp     (a0)
180
181 .cif8:
182         move.l  (sp)+,a0
183         fmove.l (4,sp),fp0
184         fmove.d fp0,(sp)
185         jmp     (a0)
186
187 .cuf4:
188         move.l  (sp)+,a0
189         fmove.l (4,sp),fp0
190         tst.l   (4,sp)
191         bge     1f
192         fsub.l  #-2147483648,fp0
193         fsub.l  #-2147483648,fp0
194 1:
195         fmove.s fp0,(4,sp)
196         jmp     (a0)
197
198 .cuf8:
199         move.l  (sp)+,a0
200         fmove.l (4,sp),fp0
201         tst.l   (4,sp)
202         bge     1f
203         fsub.l  #-2147483648,fp0
204         fsub.l  #-2147483648,fp0
205 1:
206         fmove.d fp0,(sp)
207         jmp     (a0)
208
209 .cfi:
210         move.l  (sp)+,a0
211         move.l  (4,sp),d0
212         cmp.l   #4,d0
213         bne     1f
214         fmove.s (8,sp),fp0
215         fintrz  fp0,fp0
216         fmove.l fp0,(8,sp)
217         jmp     (a0)
218 1:
219         fmove.d (8,sp),fp0
220         fintrz  fp0,fp0
221         fmove.l fp0,(12,sp)
222         jmp     (a0)
223
224 .cfu:
225         move.l  (sp)+,a0
226         move.l  (4,sp),d0
227         cmp.l   #4,d0
228         bne     1f
229         fmove.s (8,sp),fp0
230         fabs    fp0
231         cmp.l   #0x4f000000,(8,sp)
232         bge     2f
233         fintrz  fp0,fp0
234         fmove.l fp0,(8,sp)
235         jmp     (a0)
236 2:
237         fadd.l  #-2147483648,fp0
238         fintrz  fp0,fp0
239         fmove.l fp0,d0
240         bchg    #31,d0
241         move.l  d0,(8,sp)
242         jmp     (a0)
243 1:
244         fmove.d (8,sp),fp0
245         fabs    fp0
246         cmp.l   #0x41e00000,(8,sp)
247         bge     1f
248         fintrz  fp0,fp0
249         fmove.l fp0,(12,sp)
250         jmp     (a0)
251 1:
252         fadd.l  #-2147483648,fp0
253         fintrz  fp0,fp0
254         fmove.l fp0,d0
255         bchg    #31,d0
256         move.l  d0,(12,sp)
257         jmp     (a0)
258
259 .cff4:
260         move.l  (sp)+,a0
261         fmove.d (sp),fp0
262         fmove.s fp0,(4,sp)
263         jmp     (a0)
264
265 .cff8:
266         move.l  (sp)+,a0
267         fmove.s (sp),fp0
268         fmove.d fp0,(sp)
269         jmp     (a0)
270
271 .cmf4:
272         move.l  (sp)+,a0
273         clr.l   d0
274         fmove.s (sp),fp0
275         fmove.s (4,sp),fp1
276         fcmp    fp0,fp1
277         fbeq    2f
278         fblt    1f
279         add.l   #1,d0
280         jmp     (a0)
281 1:
282         sub.l   #1,d0
283 2:
284         jmp     (a0)
285
286 .cmf8:
287         move.l  (sp)+,a0
288         clr.l   d0
289         fmove.d (sp),fp0
290         fmove.d (8,sp),fp1
291         fcmp    fp0,fp1
292         fbeq    2f
293         fblt    1f
294         add.l   #1,d0
295         jmp     (a0)
296 1:
297         sub.l   #1,d0
298 2:
299         jmp     (a0)
300 \0aar.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Þ\ 2.define      .aar
301 .sect .text
302 .sect .rom
303 .sect .data
304 .sect .bss
305 .sect .text
306 EILLINS = 18
307
308 .aar:   ! (on entry d0 contains the integer size in the descriptor)
309
310         cmp.l   #4, d0
311         beq     9f
312         move.l  #EILLINS, -(sp)
313         jmp     (.fatal)
314 9:
315         ! register usage:
316         ! a0: descriptor address
317         ! a1: return address
318         ! d0: index
319
320         ! The address is calculated by taking the relative index
321         ! (index - lower bound), multiplying that with the element
322         ! size and adding the result to the array base address.
323
324         move.l  (sp)+, a1       ! return address
325         move.l  (sp)+, a0       ! descriptor address
326         move.l  (sp)+, d0       ! index
327         sub.l   (a0), d0        ! relative index
328         muls.l  (8,a0), d0
329         move.l  (sp)+, a0       ! array base address
330         add.l   d0, a0          ! address of array element
331         jmp     (a1)            ! return
332 .align 2
333 lar.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ô\ 3.define       .lar
334 .sect .text
335 .sect .rom
336 .sect .data
337 .sect .bss
338 .sect .text
339 EILLINS=18
340         ! (on entry d0 contains the integer size in the descriptor)
341 .lar:
342         cmp.l   #4, d0
343         beq     9f
344         move.l  #EILLINS, -(sp)
345         jmp     (.fatal)
346 9:
347         ! register usage:
348         ! a0: descriptor address
349         ! a1: base address
350         ! d0: index
351         ! d1: # bytes / element
352
353         ! For address calculation; see comment in 'aar.s'.
354
355         move.l  (sp)+, d1       ! return address
356         move.l  (sp)+, a0       ! descriptor address
357         move.l  (sp)+, d0       ! index
358         move.l  (sp)+, a1       ! array base address
359         sub.l   (a0), d0        ! relative index
360         move.l  d1,-(sp)
361         move.l  (8,a0), d1      ! # bytes / element
362         cmp.l   #1, d1
363         bne     2f
364         move.l  (sp),a0
365         clr.l   (sp)
366         move.b  (a1,d0.l), (3,sp) ! one byte element
367         jmp     (a0)
368 2:
369         cmp.l   #2, d1
370         bne     4f
371         move.l  (sp),a0
372         clr.l   (sp)
373         move.w  (a1,d0.l*2), (2,sp) ! two byte element
374         jmp     (a0)
375 4:      
376         muls.l  d1, d0
377         add.l   d0, a1          ! address of 4n byte element
378         add.l   d1, a1          ! because of predecrement
379         asr.l   #2, d1
380         move.l  (sp)+,a0
381 1:
382         move.l  -(a1), -(sp)
383         sub.l   #1, d1
384         bne     1b
385         jmp     (a0)
386 .align 2
387 sar.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0#\ 4.define       .sar
388 .sect .text
389 .sect .rom
390 .sect .data
391 .sect .bss
392 EILLINS=18
393
394 .sect .text
395         ! (on entry d0 contains the integer size in the descriptor)
396 .sar:
397         cmp.l   #4, d0
398         beq     9f
399         move.l  #EILLINS, -(sp)
400         jmp     (.fatal)
401 9:
402         ! register usage:
403         ! a0: descriptor address
404         ! a1: base address
405         ! d0: index
406         ! d1: # bytes / element
407
408         ! For address calculation; see comment in 'aar.s'.
409         ! If the element size is a fraction of EM_WSIZE (4)
410         ! the calculation is done by adding.
411
412         move.l  (sp)+, d1       ! return address
413         move.l  (sp)+, a0
414         move.l  (sp)+, d0
415         move.l  (sp)+, a1
416         move.l  d1,-(sp)        ! return address
417         sub.l   (a0), d0
418         move.l  (8,a0), d1      ! # bytes / element
419         cmp.l   #1, d1
420         bne     2f
421         move.l  (sp)+,a0
422         move.l  (sp)+, d1
423         move.b  d1, (a1,d0.l)   ! store one byte element
424         jmp     (a0)
425 2:
426         cmp.l   #2, d1
427         bne     4f
428         move.l  (sp)+,a0
429         move.l  (sp)+, d1
430         move.w  d1, (a1,d0.l*2) ! store two byte element
431         jmp     (a0)
432 4:                              ! here: 4n byte element
433         muls.l  d1, d0
434         add.l   d0, a1          ! address of 4n byte element
435         asr.l   #2, d1
436         move.l  (sp)+,a0
437 1:
438         move.l  (sp)+, (a1)+
439         sub.l   #1, d1
440         bne     1b
441         jmp     (a0)
442 .align 2
443
444 csa.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0á\ 1.define       .csa4
445 .define .csa
446 .sect .text
447 .sect .rom
448 .sect .data
449 .sect .bss
450 ECASE=20
451
452 .sect .text
453
454 .csa4:
455 .csa:
456                 ! jump table address in a0
457                 ! index in d0
458
459         move.l  (a0)+, a1       ! default address
460         sub.l   (a0)+, d0       ! index - lower bound
461         blt     1f
462         cmp.l   (a0)+, d0       ! rel. index, upper - lower bound
463         bgt     1f
464         move.l  (a0,d0.l*4), d1 ! jump address
465         beq     1f
466         move.l  d1,a1
467         jmp     (a1)
468 1:
469         move.l  a1, d0
470         beq     2f
471         jmp     (a1)            ! jump to specified address
472 2:
473         move.l  #ECASE, -(sp)
474         jmp     (.fatal)
475 .align 2
476 rcsb.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0¡\ 1.define      .csb4
477 .define .csb
478 .sect .text
479 .sect .rom
480 .sect .data
481 .sect .bss
482 ECASE=20
483
484 .sect .text
485
486 .csb4:
487 .csb:
488                 ! case descriptor in a0
489                 ! index in d0
490
491         move.l  (a0)+, a1       ! default jump address
492         move.l  (a0)+, d1       ! # entries
493         beq     3f
494         sub.l   #1, d1
495 1:
496         cmp.l   (a0,d1.w*8), d0
497         dbeq    d1, 1b
498         bne     3f
499         move.l  (4,a0,d1.w*8), a1 ! jump address
500 3:
501         move.l  a1, d0
502         beq     4f
503         jmp     (a1)
504 4:
505         move.l  #ECASE, -(sp)
506         jmp     (.fatal)
507 .align 2
508 eshp.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0
509 \ 2.define        .strhp
510 .sect .text
511 .sect .rom
512 .sect .data
513 .sect .bss
514 EHEAP=17
515
516         .sect .text
517 .strhp:
518         move.l  (sp)+, a0
519         move.l  (sp), d1        ! new heap pointer
520         cmp.l   (.limhp), d1    ! compare new heap pointer with limit
521         blt     1f
522         add.l   #0x400, d1
523         and.l   #~0x3ff, d1
524         move.l  a0,-(sp)
525         move.l  d1, -(sp)
526         move.l  d1,(.limhp)
527         jsr     (BRK)           ! allocate 1K bytes of extra storage
528         add.l   #4,sp
529         move.l  (sp)+,a0
530         tst.l   d0
531         bne     2f
532 1:
533         move.l  (sp)+, (.reghp) ! store new value
534         jmp     (a0)            ! return
535 2:
536         move.l  #EHEAP, -(sp)
537         jsr     (.trp)
538         jmp     (a0)
539 .align 2
540 set.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0%\ 2.define       .set
541 .sect .text
542 .sect .rom
543 .sect .data
544 .sect .bss
545 .sect   .text
546 ESET=2
547
548 .set:   ! d0 bitnumber
549         ! d1 setsize in bytes
550         ! a1 saved d2
551         ! a0 return address
552
553         move.l  (sp)+, a0
554         move.l  d2, a1
555         move.l  d1, d2
556         asr.l   #2, d2
557 1:
558         clr.l   -(sp)
559         sub.l   #1, d2
560         bne     1b
561
562         move.l  d0, d2
563         asr.l   #3, d2          ! offset from sp in bytes
564         eor.l   #3, d2          ! longs are stored in high-to-low order
565         cmp.l   d1, d2
566         blt     2f
567         move.l  #ESET, -(sp)    ! bitnumber too large
568         move.l  a1, d2
569         move.l  a0, -(sp)
570         jmp     (.trp)
571 2:
572         bset    d0, (sp, d2.l)
573         move.l  a1, d2
574         jmp     (a0)    ! return
575 .align 2
576
577 inn.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\e\ 2.define       .inn
578 .sect .text
579 .sect .rom
580 .sect .data
581 .sect .bss
582 .sect .text
583
584 ESET=2
585
586 .inn:   ! d0 bitnumber
587         ! d1 setsize in bytes
588         ! on exit: 0 or 1 in d0
589
590         move.l  d2, -(sp)
591         move.l  d0, d2
592         asr.l   #3, d2          ! offset from sp in bytes
593         eor.l   #3, d2          ! longs are stored in high-to-low order
594         cmp.l   d1, d2
595         bge     1f              ! bitnumber too large
596         btst    d0, (8,sp,d2.l)
597         beq     2f
598         move.l  #1, d0
599         bra     3f
600 1:
601         move.l  #ESET, -(sp)
602         jsr     (.trp)
603 2:
604         clr.l   d0
605 3:
606         move.l  (sp)+, d2
607         move.l  (sp)+, a0       ! return address
608         add.l   d1, sp          ! pop bitset
609         jmp     (a0)            ! return
610 .align 2
611
612 fat.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0t\0.define       .fatal
613 .sect .text
614 .sect .rom
615 .sect .data
616 .sect .bss
617
618         .sect .text
619 .fatal:
620         jsr     (.trp)
621         jmp     (EXIT)
622 .align 2
623 trp.s\01.s\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ó\ 2#
624 .define .trp
625 .sect .text
626 .sect .rom
627 .sect .data
628 fmt:    .asciz "%s\n"
629 .sect .bss
630
631         .sect .text
632 .trp:
633         movem.l d0/d1/a0, -(sp)
634         move.l  (12, sp), a0    ! return address
635         move.l  (16, sp), d0    ! error number
636         move.l  a0, (16, sp)
637         move.l  d0, (12, sp)
638         cmp.l   #16, d0
639         bcc     1f
640         move.l  (.trpim), d1
641         btst    d0, d1
642         bne     3f
643 1:
644         move.l  (.trppc), a0
645         move.l  a0, d1
646         beq     9f
647         clr.l   (.trppc)
648         movem.l d2-d7/a1-a5,-(sp)
649 #if _M68881
650         fmovem.x fp0-fp7,-(sp)
651 #endif
652         move.l  d0,-(sp)
653         jsr     (a0)
654         add.l   #4, sp
655 #if _M68881
656         fmovem.x (sp)+,fp0-fp7
657 #endif
658         movem.l (sp)+,d2-d7/a1-a5
659 3:
660         movem.l (sp)+, d0/d1/a0
661         add.l   #4, sp
662         rts
663 9:
664         move.l  d0,-(sp)
665         jsr     (__trpstr)
666         move.l  d0,(sp)
667         pea     (fmt)
668         jsr     (.diagnos)
669         lea     (4, sp), sp
670         illegal
671         jmp     (EXIT)
672 .align 2
673 otrpstr.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ý\ 3#include <em_abs.h>
674 char *
675 _trpstr(d)
676 {
677         switch(d)
678         {
679         case EARRAY: return "array bound error";
680         case ERANGE: return "range bound error";
681         case ESET: return "set bound error";
682         case EIOVFL: return "integer overflow";
683         case EFOVFL: return "floating overflow";
684         case EFUNFL: return "floating underflow";
685         case EIDIVZ: return "divide by 0";
686         case EFDIVZ: return "divide by 0.0";
687         case EIUND: return "undefined integer";
688         case EFUND: return "undefined real";
689         case ECONV: return "conversion error";
690         case ESTACK: return "stack overflow";
691         case EHEAP: return "heap overflow";
692         case EILLINS: return "illegal instruction";
693         case EODDZ: return "illegal size argument";
694         case ECASE: return "case error";
695         case EMEMFLT: return "addressing non-existent memory";
696         case EBADPTR: return "bad pointer used";
697         case EBADPC: return "program counter out of range";
698         case EBADMON: return "bad monitor call";
699         case EBADLIN:
700         case EBADGTO:
701         case EBADLAE:
702         default:
703                 return "strange trap";
704         }
705         /*NOTREACHED*/
706 }
707 +mon.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ù\0.define .mon
708 .sect .text
709 .sect .rom
710 .sect .data
711 .sect .bss
712
713 .sect .text
714 .mon:
715         move.l  (sp)+,a0
716         pea     (fmt)
717         jsr     (.diagnos)
718         add.l   #8, sp
719         jmp     (EXIT)
720
721 .sect .data
722 fmt:    .asciz "system call %d not implemented\n"
723 .align 2
724         nop.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0$\ 1.define .nop
725 .sect .text
726 .sect .rom
727 .sect .data
728 .sect .bss
729
730 .sect .text
731 .nop:
732         move.l  (.limhp),-(sp)
733         move.l  (.reghp),-(sp)
734         pea     (12, sp)
735         move.l  (.lino),-(sp)
736         pea     (fmt)
737         jsr     (.diagnos)
738         lea     (20, sp), sp
739         rts
740
741 .sect .data
742 fmt:    .asciz "test %d, sp 0x%x, .reghp 0x%x, .limhp 0x%x.\n"
743 .align 2
744 dia.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0D\b.define       .diagnos
745 .sect .text
746 .sect .rom
747 .sect .data
748 .sect .bss
749
750 space   = 040
751 del     = 0177
752
753 .sect .data
754 .range: .data1 space, del-1
755 .align  2
756
757 .sect .text
758 .diagnos:
759         movem.l d0/d1/d2/a0, -(sp)
760         move.l  (.lino), -(sp)
761         move.l  (.filn), d2
762         beq     1f
763         move.l  d2, a0
764         move.l  #40, d0
765 3:
766         move.b  (a0)+, d1
767         beq     2f
768         cmp2.b  (.range), d1
769         bcs     1f
770         dbf     d0, 3b
771 2:
772         move.l  d2, -(sp)
773         pea     (fmt)
774         jsr     (printf)
775         lea     (12, sp), sp
776         movem.l (sp)+, d0/d1/d2/a0
777         jmp     (printf)
778         rts
779
780 1:
781         move.l  #unknwn, d2
782         bra     2b
783
784 .sect .bss
785 getal:
786         .space  12
787 char:
788         .space  1
789         .align  4
790 .sect .data
791 hexs:
792         .ascii  "0123456789abcdef"
793         .align  4
794 .sect .text
795 printf:
796         movem.l d0/d1/d2/a0/a1/a2/a3/a4/a5/a6, -(sp)
797         lea     (44, sp), a6    ! a6 <- address of arguments
798         move.l  (a6)+, a5       ! a5 <- address of format
799 next:   move.b  (a5)+, d0
800         beq     out
801         cmp.b   #'%', d0
802         beq     procnt
803 put:    move.l  d0, -(sp)
804         jsr     (putchar)       ! long argument on stack
805         tst.l   (sp)+
806         bra     next
807
808 procnt: move.b  (a5)+, d0
809         cmp.b   #'d', d0        ! NOTE: %d means unsigned.
810         beq     digit
811         cmp.b   #'x', d0
812         beq     hex
813         cmp.b   #'s', d0
814         beq     string
815         cmp.b   #'%', d0        ! second % has to be printed.
816         beq     put
817         tst.b   -(a5)           ! normal char should be printed
818         bra     next
819
820 string: move.l  (a6)+, a2       ! a2 <- address of string
821 sloop:  move.b  (a2)+, d0
822         beq     next
823         move.l  d0, -(sp)
824         jsr     (putchar)       ! long argument on stack
825         tst.l   (sp)+
826         bra     sloop
827
828 digit:  move.l  (a6)+, d1       ! d1 <- integer
829         move.l  #getal+12, a2   ! a2 <- ptr to last part of buf
830         clr.b   -(a2)           ! stringterminator
831 1:      divul.l #10, d2:d1      ! d1 <- qotient; d2 <- remainder
832         add.l   #'0', d2
833         move.b  d2, -(a2)
834         tst.l   d1              ! if quotient = 0 then ready
835         bne     1b
836         bra     sloop           ! print digitstring.
837
838 hex:    move.l  (a6)+, d1       ! d1 <- integer
839         move.l  #getal+12, a2   ! a2 <- ptr to last part of buf
840         clr.b   -(a2)           ! stringterminator
841         move.l  #7, d2          ! loop control
842 1:      move.l  d1, d0
843         and.l   #15, d0
844         move.b  (hexs,d0.w), -(a2) ! hex digit
845         asr.l   #4, d1
846         dbf     d2, 1b
847         bra     sloop
848
849 out:
850         movem.l (sp)+, d0/d1/d2/a0/a1/a2/a3/a4/a5/a6
851         rts
852
853
854 putchar:
855         move.l  #1, -(sp)
856         pea     (11,sp)
857         move.l  #1, -(sp)
858         jsr     (WRITE)
859         lea     (12, sp), sp
860         rts
861 .align 2
862
863 .sect .data
864 fmt:            .asciz "%s, line %d: "
865 unknwn:         .asciz "unknown file"
866 .align 2
867 cii.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\92\ 1.define       .cii
868 .sect .text
869 .sect .rom
870 .sect .data
871 .sect .bss
872
873 .sect .text
874 .cii:
875         move.l  (sp)+, a0       ! return address
876         move.l  (sp)+, d0       ! destination size
877         sub.l   (sp)+, d0       ! destination - source size
878         bgt     1f
879         sub.l   d0, sp          ! pop extra bytes
880         jmp     (a0)
881 1:
882         clr.l   d1
883         tst.l   (sp)
884         bne     4f
885         not.l   d1              ! d1 contains sign of source
886 4:
887         asr.l   #2, d0
888         sub.l   #1, d0
889 2:
890         move.l  d1, -(sp)
891         dbf     d0, 2b
892         jmp     (a0)
893 .align 2
894 cuu.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0a\ 1.define       .ciu, .cui, .cuu
895 .sect .text
896 .sect .rom
897 .sect .data
898 .sect .bss
899
900 .sect .text
901         ! only converts between sizes of multiples of four
902 .ciu:
903 .cui:
904 .cuu:
905         move.l  (sp)+, a0       ! return address
906         move.l  (sp)+, d0       ! destination size
907         sub.l   (sp)+, d0
908         bgt     1f
909         sub.l   d0, sp
910         jmp     (a0)
911 1:
912         asr.l   #2, d0
913         sub.l   #1, d0
914 2:
915         clr.l   -(sp)
916         dbf     d0, 2b
917         jmp     (a0)
918 .align 2
919         cmi.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ß\ 1.define       .cmi
920 .sect .text
921 .sect .rom
922 .sect .data
923 .sect .bss
924
925 .sect .text
926         ! on entry d0: # bytes in 1 block
927         ! on exit d0: result
928 .cmi:
929         move.l  (sp)+, d1       ! return address
930         move.l  sp, a0          ! address of top block
931         lea     (sp,d0.l), a1   ! address of lower block
932         move.l  d1,-(sp)
933         move.l  d0, d1
934         asr.l   #2, d0
935 1:
936         cmp.l   (a0)+, (a1)+
937         bne     2f
938         sub.l   #1, d0
939         bne     1b
940 2:
941         bge     3f
942         neg.l   d0              ! less
943 3:
944         move.l  (sp)+,a0
945         lea     (sp,d1.l*2), sp ! new sp; two blocks popped
946         jmp     (a0)            ! return
947 .align 2
948         cms.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ï\ 1.define       .cms
949 .sect .text
950 .sect .rom
951 .sect .data
952 .sect .bss
953
954 .sect .text
955         ! d0 contains set size
956         ! on exit d0 is zero for equal, non-zero for not equal
957 .cms:
958         move.l  (sp)+, d1       ! return address
959         move.l  sp, a0          ! address of top block
960         lea     (sp,d0.l), a1   ! address of lower block
961         move.l  d1,-(sp)
962         move.l  d0, d1
963         asr.l   #2, d0
964 1:
965         cmp.l   (a0)+, (a1)+
966         bne     2f
967         sub.l   #1, d0
968         bne     1b
969 2:
970         move.l  (sp)+,a0
971         lea     (sp,d1.l*2), sp ! new sp; two blocks popped
972         jmp     (a0)
973 .align 2
974 rcmu.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ô\ 1.define      .cmu
975 .sect .text
976 .sect .rom
977 .sect .data
978 .sect .bss
979
980 .sect .text
981         ! on entry d0: # bytes in 1 block
982         ! on exit d0: result
983 .cmu:
984         move.l  (sp)+, d1       ! return address
985         move.l  sp, a0          ! address of top block
986         lea     (sp,d0.l), a1   ! address of lower block
987         move.l  d1,-(sp)
988         move.l  d0, d1
989         asr.l   #2, d0
990 1:
991         cmp.l   (a0)+, (a1)+
992         bne     2f
993         sub.l   #1, d0
994         bne     1b              ! note: on equal carry is set
995 2:
996         bcc     3f
997         neg.l   d0              ! less
998 3:
999         move.l  (sp)+,a0
1000         lea     (sp,d1.l*2), sp ! new sp; two blocks popped
1001         jmp     (a0)
1002 .align 2
1003 cvf.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\04\ 1.define       .cfi, .cif,.cfu,.cuf,.cff
1004 .sect .text
1005 .sect .rom
1006 .sect .data
1007 .sect .bss
1008
1009         .sect .text
1010
1011         ! this is a dummy float conversion routine
1012 .cfi:
1013 .cif:
1014 .cfu:
1015 .cuf:
1016 .cff:
1017         move.l  (sp)+, a0       ! return address
1018         move.l  (sp)+, d0       ! destination size
1019         sub.l   (sp)+, d0       ! diff. in sizes
1020         sub.l   d0, sp
1021         jmp     (a0)
1022 .align 2
1023 exg.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0-\ 1.define       .exg
1024 .sect .text
1025 .sect .rom
1026 .sect .data
1027 .sect .bss
1028
1029 .sect .text
1030         ! d0 : exchange size in bytes
1031 .exg:
1032         lea     (4,sp,d0), a0   ! address of bottom block
1033         lea     (4,sp), a1      ! address of top block
1034         asr.l   #2, d0
1035 1:
1036         move.l  (a1), d1
1037         move.l  (a0), (a1)+
1038         move.l  d1, (a0)+
1039         sub.l   #1, d0
1040         bne     1b
1041         rts
1042 .align 2
1043 llos.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0È\ 1.define .los
1044 .sect .text
1045 .sect .rom
1046 .sect .data
1047 .sect .bss
1048
1049         ! d0 : # bytes
1050         ! a0 : source address
1051         ! a1 : return address
1052 .sect .text
1053 .los:
1054         move.l  (sp)+, a1
1055         move.l  (sp)+, d0
1056         move.l  (sp)+, a0
1057         cmp.l   #1, d0
1058         bne     1f
1059         clr.l   -(sp)
1060         move.b  (a0), (3,sp)    !1 byte
1061         bra     3f
1062 1:
1063         cmp.l   #2, d0
1064         bne     2f
1065         clr.l   -(sp)
1066         move.w  (a0), (2,sp)    !2 bytes
1067         bra     3f
1068 2:
1069         add.l   d0, a0          !>=4 bytes
1070         asr.l   #2, d0
1071
1072 4:      move.l  -(a0), -(sp)    
1073         sub.l   #1, d0
1074         bne     4b
1075 3:
1076         jmp     (a1)
1077 .align 2
1078 sts.s\0.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0«\ 1.define .sts
1079 .sect .text
1080 .sect .rom
1081 .sect .data
1082 .sect .bss
1083
1084         ! d0 : # bytes
1085         ! a0 : destination address
1086         ! a1 : return address
1087 .sect .text
1088 .sts:
1089         move.l  (sp)+, a1
1090         move.l  (sp)+, d0
1091         move.l  (sp)+, a0
1092         cmp.l   #1, d0
1093         bne     1f
1094         move.l  (sp)+, d0
1095         move.b  d0, (a0)
1096         bra     4f
1097
1098 1:      cmp.l   #2, d0
1099         bne     2f
1100         move.l  (sp)+, d0
1101         move.w  d0, (a0)
1102         bra     4f
1103 2:
1104         asr.l   #2, d0
1105 3:
1106         move.l  (sp)+, (a0)+
1107         sub.l   #1, d0
1108         bne     3b
1109 4:
1110         jmp     (a1)            ! return
1111 .align 2
1112 b