1 |
|
* |
2 |
|
* asm_support.asm - AmigaOS utility functions in assembly language |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
28 |
|
XDEF _AtomicAnd |
29 |
|
XDEF _AtomicOr |
30 |
|
XDEF _MoveVBR |
31 |
+ |
XDEF _DisableSuperBypass |
32 |
|
XDEF _Execute68k |
33 |
|
XDEF _Execute68kTrap |
34 |
|
XDEF _TrapHandlerAsm |
35 |
|
XDEF _ExceptionHandlerAsm |
35 |
– |
XDEF _Scod060Patch1 |
36 |
– |
XDEF _Scod060Patch2 |
37 |
– |
XDEF _ThInitFPUPatch |
36 |
|
XDEF _AsmTriggerNMI |
37 |
|
|
38 |
|
XREF _OldTrapHandler |
45 |
|
XREF _MainTask |
46 |
|
XREF _SysBase |
47 |
|
XREF _quit_emulator |
50 |
– |
XREF _kprintf |
48 |
|
|
49 |
|
SECTION text,CODE |
50 |
|
|
51 |
+ |
MACHINE 68020 |
52 |
+ |
|
53 |
|
* |
54 |
|
* Atomic bit operations (don't trust the compiler) |
55 |
|
* |
107 |
|
rte |
108 |
|
|
109 |
|
* |
110 |
+ |
* Disable 68060 Super Bypass mode |
111 |
+ |
* |
112 |
+ |
|
113 |
+ |
_DisableSuperBypass |
114 |
+ |
movem.l d0-d1/a0-a1/a5-a6,-(sp) |
115 |
+ |
move.l _SysBase,a6 |
116 |
+ |
|
117 |
+ |
lea dissb,a5 |
118 |
+ |
JSRLIB Supervisor |
119 |
+ |
|
120 |
+ |
movem.l (sp)+,d0-d1/a0-a1/a5-a6 |
121 |
+ |
rts |
122 |
+ |
|
123 |
+ |
MACHINE 68060 |
124 |
+ |
|
125 |
+ |
dissb movec pcr,d0 |
126 |
+ |
bset #5,d0 |
127 |
+ |
movec d0,pcr |
128 |
+ |
rte |
129 |
+ |
|
130 |
+ |
MACHINE 68020 |
131 |
+ |
|
132 |
+ |
* |
133 |
|
* Execute 68k subroutine (must be ended with rts) |
134 |
|
* r->a[7] and r->sr are unused! |
135 |
|
* |
241 |
|
rts |
242 |
|
|
243 |
|
* |
222 |
– |
* Process Manager 68060 FPU patches |
223 |
– |
* |
224 |
– |
|
225 |
– |
_Scod060Patch1 fsave -(sp) ;Save FPU state |
226 |
– |
tst.b 2(sp) ;Null? |
227 |
– |
beq.s 1$ |
228 |
– |
fmovem.x fp0-fp7,-(sp) ;No, save FPU registers |
229 |
– |
fmove.l fpiar,-(sp) |
230 |
– |
fmove.l fpsr,-(sp) |
231 |
– |
fmove.l fpcr,-(sp) |
232 |
– |
pea -1 ;Push "FPU state saved" flag |
233 |
– |
1$ move.l d1,-(sp) |
234 |
– |
move.l d0,-(sp) |
235 |
– |
bsr.s 3$ ;Switch integer registers and stack |
236 |
– |
addq.l #8,sp |
237 |
– |
tst.b 2(sp) ;New FPU state null or "FPU state saved" flag set? |
238 |
– |
beq.s 2$ |
239 |
– |
addq.l #4,sp ;Flag set, skip it |
240 |
– |
fmove.l (sp)+,fpcr ;Restore FPU registers and state |
241 |
– |
fmove.l (sp)+,fpsr |
242 |
– |
fmove.l (sp)+,fpiar |
243 |
– |
fmovem.x (sp)+,fp0-fp7 |
244 |
– |
2$ frestore (sp)+ |
245 |
– |
movem.l (sp)+,d0-d1 |
246 |
– |
rts |
247 |
– |
|
248 |
– |
3$ move.l 4(sp),a0 ;Switch integer registers and stack |
249 |
– |
move sr,-(sp) |
250 |
– |
movem.l d2-d7/a2-a6,-(sp) |
251 |
– |
cmp.w #0,a0 |
252 |
– |
beq.s 4$ |
253 |
– |
move.l sp,(a0) |
254 |
– |
4$ move.l $36(sp),a0 |
255 |
– |
movem.l (a0)+,d2-d7/a2-a6 |
256 |
– |
move (a0)+,sr |
257 |
– |
move.l a0,sp |
258 |
– |
rts |
259 |
– |
|
260 |
– |
_Scod060Patch2 move.l d0,-(sp) ;Create 68060 null frame on stack |
261 |
– |
move.l d0,-(sp) |
262 |
– |
move.l d0,-(sp) |
263 |
– |
frestore (sp)+ ;and load it |
264 |
– |
rts |
265 |
– |
|
266 |
– |
* |
267 |
– |
* Thread Manager 68060 FPU patches |
268 |
– |
* |
269 |
– |
|
270 |
– |
_ThInitFPUPatch tst.b $40(a4) |
271 |
– |
bne.s 1$ |
272 |
– |
moveq #0,d0 ;Create 68060 null frame on stack |
273 |
– |
move.l d0,-(a3) |
274 |
– |
move.l d0,-(a3) |
275 |
– |
move.l d0,-(a3) |
276 |
– |
1$ rts |
277 |
– |
|
278 |
– |
* |
244 |
|
* Trap handler of main task |
245 |
|
* |
246 |
|
|
261 |
|
cmp.l #47,(sp) |
262 |
|
ble doTrapXX ; Vector 32-47 : TRAP #0 - 15 Instruction Vectors |
263 |
|
|
264 |
< |
1$: move.l _OldTrapHandler,-(sp) ;No, jump to old trap handler |
264 |
> |
1$ move.l _OldTrapHandler,-(sp) ;No, jump to old trap handler |
265 |
|
rts |
266 |
|
|
267 |
|
* |
268 |
|
* TRAP #0 - 15 Instruction Vectors |
269 |
|
* |
270 |
|
|
271 |
< |
doTrapXX: move.l a0,(sp) ;Save a0 |
271 |
> |
doTrapXX move.l a0,(sp) ;Save a0 |
272 |
|
move.l usp,a0 ;Get user stack pointer |
273 |
|
move.l 2*4(sp),-(a0) ;Copy 4-word stack frame to user stack |
274 |
|
move.l 1*4(sp),-(a0) |
286 |
|
* trace Vector |
287 |
|
* |
288 |
|
|
289 |
< |
dotrace: move.l a0,(sp) ;Save a0 |
289 |
> |
dotrace move.l a0,(sp) ;Save a0 |
290 |
|
|
291 |
|
move.l usp,a0 ;Get user stack pointer |
292 |
|
move.l 3*4(sp),-(a0) ;Copy 6-word stack frame to user stack |
316 |
|
addq.l #8,sp ;Remove exception frame from supervisor stack |
317 |
|
andi #$d8ff,sr ;Switch to user mode, enable interrupts |
318 |
|
|
354 |
– |
IFNE 0 |
355 |
– |
|
356 |
– |
; move.w ([2,sp]),($3800) |
357 |
– |
|
358 |
– |
cmp.w #$a9c3,([2,sp]) |
359 |
– |
bne 1$ |
360 |
– |
|
361 |
– |
move.l d0,-(sp) |
362 |
– |
move.l a0,-(sp) |
363 |
– |
pea afmt(pc) |
364 |
– |
jsr _kprintf |
365 |
– |
lea 3*4(sp),sp |
366 |
– |
1$: |
367 |
– |
ENDC |
368 |
– |
|
319 |
|
move.l $28.w,-(sp) ;Jump to MacOS exception handler |
320 |
|
rts |
321 |
|
|
372 |
– |
afmt: dc.b 'a0=%08lx d0=%08lx\n',0 |
373 |
– |
cnop 0,4 |
374 |
– |
|
322 |
|
* |
323 |
|
* Illegal address handler |
324 |
|
* |
325 |
|
|
326 |
< |
doilladdr: move.l a0,(sp) ;Save a0 |
326 |
> |
doilladdr move.l a0,(sp) ;Save a0 |
327 |
|
|
328 |
|
move.l usp,a0 ;Get user stack pointer |
329 |
|
move.l 3*4(sp),-(a0) ;Copy 6-word stack frame to user stack |
344 |
|
* to execute extended opcodes (see emul_op.h) |
345 |
|
* |
346 |
|
|
347 |
< |
doillinstr |
401 |
< |
movem.l a0/d0,-(sp) |
347 |
> |
doillinstr movem.l a0/d0,-(sp) |
348 |
|
move.w ([6+2*4,sp]),d0 |
349 |
|
and.w #$ff00,d0 |
350 |
|
cmp.w #$7100,d0 |
364 |
|
move.l $10.w,-(sp) ;Jump to MacOS exception handler |
365 |
|
rts |
366 |
|
|
367 |
< |
1$: |
422 |
< |
move.l a6,(sp) ;Save a6 |
367 |
> |
1$ move.l a6,(sp) ;Save a6 |
368 |
|
move.l usp,a6 ;Get user stack pointer |
369 |
|
|
370 |
|
move.l a6,-10(a6) ;Push USP (a7) |
635 |
|
fsavepush move.l (sp),d0 ;Restore d0 |
636 |
|
move.l a0,(sp) ;Save a0 |
637 |
|
move.l usp,a0 ;Get user stack pointer |
638 |
< |
fsave -(a0) ;Push FP state |
638 |
> |
move.l #$41000000,-(a0) ;Push idle frame |
639 |
|
move.l a0,usp ;Update USP |
640 |
|
move.l (sp)+,a0 ;Restore a0 |
641 |
|
addq.l #2,2(sp) ;Skip instruction |
642 |
|
rte |
643 |
|
|
644 |
+ |
; fsave xxx(a5) |
645 |
+ |
fsavea5 move.l (sp),d0 ;Restore d0 |
646 |
+ |
move.l a0,(sp) ;Save a0 |
647 |
+ |
move.l a5,a0 ;Get base register |
648 |
+ |
add.w ([6,sp],2),a0 ;Add offset to base register |
649 |
+ |
move.l #$41000000,(a0) ;Push idle frame |
650 |
+ |
move.l (sp)+,a0 ;Restore a0 |
651 |
+ |
addq.l #4,2(sp) ;Skip instruction |
652 |
+ |
rte |
653 |
+ |
|
654 |
|
; frestore (sp)+ |
655 |
|
frestorepop move.l (sp),d0 ;Restore d0 |
656 |
|
move.l a0,(sp) ;Save a0 |
657 |
|
move.l usp,a0 ;Get user stack pointer |
658 |
< |
frestore (a0)+ ;Restore FP state |
658 |
> |
addq.l #4,a0 ;Nothing to do... |
659 |
|
move.l a0,usp ;Update USP |
660 |
|
move.l (sp)+,a0 ;Restore a0 |
661 |
|
addq.l #2,2(sp) ;Skip instruction |
662 |
|
rte |
663 |
|
|
664 |
< |
; frestore xxx(a5) +jl+ |
664 |
> |
; frestore xxx(a5) |
665 |
|
frestorea5 move.l (sp),d0 ;Restore d0 |
666 |
|
move.l a0,(sp) ;Save a0 |
712 |
– |
move.l a5,a0 ;Get base register |
713 |
– |
add.w ([6,sp],2),a0 ;Add offset to base register |
714 |
– |
frestore (a0) ;Restore FP state from (a0) |
715 |
– |
move.l (sp)+,a0 ;Restore a0 |
716 |
– |
addq.l #4,2(sp) ;Skip instruction |
717 |
– |
rte |
718 |
– |
|
719 |
– |
; fsave xxx(a5) +jl+ |
720 |
– |
fsavea5: move.l (sp),d0 ;Restore d0 |
721 |
– |
move.l a0,(sp) ;Save a0 |
722 |
– |
move.l a5,a0 ;Get base register |
723 |
– |
add.w ([6,sp],2),a0 ;Add offset to base register |
724 |
– |
fsave (a0) ;Push FP state to (a0) |
667 |
|
move.l (sp)+,a0 ;Restore a0 |
668 |
|
addq.l #4,2(sp) ;Skip instruction |
669 |
|
rte |
688 |
|
lea 16+4(sp),a1 ; destination address (in supervisor stack) |
689 |
|
bra 1$ |
690 |
|
|
691 |
< |
2$: move.w (a0)+,(a1)+ ; copy additional stack words back to supervisor stack |
692 |
< |
1$: dbf d0,2$ |
691 |
> |
2$ move.w (a0)+,(a1)+ ; copy additional stack words back to supervisor stack |
692 |
> |
1$ dbf d0,2$ |
693 |
|
|
694 |
|
move.l a0,usp ;Update USP |
695 |
|
movem.l (sp)+,a0/a1 ;Restore a0 and a1 |
893 |
|
rte |
894 |
|
|
895 |
|
; movec sfc,d1 +jl+ |
896 |
< |
movecsfcd1: move.l (sp)+,d0 ;Restore d0 |
896 |
> |
movecsfcd1 move.l (sp)+,d0 ;Restore d0 |
897 |
|
moveq #0,d1 |
898 |
|
addq.l #4,2(sp) |
899 |
|
rte |
900 |
|
|
901 |
|
; movec dfc,d1 +jl+ |
902 |
< |
movecdfcd1: move.l (sp)+,d0 ;Restore d0 |
902 |
> |
movecdfcd1 move.l (sp)+,d0 ;Restore d0 |
903 |
|
moveq #0,d1 |
904 |
|
addq.l #4,2(sp) |
905 |
|
rte |
906 |
|
|
907 |
< |
movecurpd0: ; movec urp,d0 +jl+ |
908 |
< |
movecsrpd0: ; movec srp,d0 |
909 |
< |
movecitt0d0: ; movec itt0,d0 |
910 |
< |
movecitt1d0: ; movec itt1,d0 |
911 |
< |
movecdtt0d0: ; movec dtt0,d0 |
912 |
< |
movecdtt1d0: ; movec dtt1,d0 |
907 |
> |
movecurpd0 ; movec urp,d0 +jl+ |
908 |
> |
movecsrpd0 ; movec srp,d0 |
909 |
> |
movecitt0d0 ; movec itt0,d0 |
910 |
> |
movecitt1d0 ; movec itt1,d0 |
911 |
> |
movecdtt0d0 ; movec dtt0,d0 |
912 |
> |
movecdtt1d0 ; movec dtt1,d0 |
913 |
|
addq.l #4,sp |
914 |
|
moveq.l #0,d0 ;MMU is always off |
915 |
|
addq.l #4,2(sp) ;skip instruction |
964 |
|
rte |
965 |
|
|
966 |
|
; move usp,a1 +jl+ |
967 |
< |
moveuspa1: move.l (sp)+,d0 |
967 |
> |
moveuspa1 move.l (sp)+,d0 |
968 |
|
move usp,a1 |
969 |
|
addq.l #2,2(sp) |
970 |
|
rte |
971 |
|
|
972 |
|
; move usp,a0 +jl+ |
973 |
< |
moveuspa0: move.l (sp)+,d0 |
973 |
> |
moveuspa0 move.l (sp)+,d0 |
974 |
|
move usp,a0 |
975 |
|
addq.l #2,2(sp) |
976 |
|
rte |
977 |
|
|
978 |
|
; move a1,usp +jl+ |
979 |
< |
moved1usp: move.l (sp)+,d0 |
979 |
> |
moved1usp move.l (sp)+,d0 |
980 |
|
move a1,usp |
981 |
|
addq.l #2,2(sp) |
982 |
|
rte |
985 |
|
; Trigger NMI (Pop up debugger) |
986 |
|
; |
987 |
|
|
988 |
< |
_AsmTriggerNMI: |
1047 |
< |
move.l d0,-(sp) ;Save d0 |
988 |
> |
_AsmTriggerNMI move.l d0,-(sp) ;Save d0 |
989 |
|
move.w #$007c,-(sp) ;Yes, fake NMI stack frame |
990 |
|
pea 1$ |
991 |
|
move.w _EmulatedSR,d0 |