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-2002 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 |
|
|
319 |
< |
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 |
319 |
> |
and.w #$d8ff,_EmulatedSR ;enable interrupts in EmulatedSR |
320 |
|
|
321 |
|
move.l $28.w,-(sp) ;Jump to MacOS exception handler |
322 |
|
rts |
323 |
|
|
372 |
– |
afmt: dc.b 'a0=%08lx d0=%08lx\n',0 |
373 |
– |
cnop 0,4 |
374 |
– |
|
324 |
|
* |
325 |
|
* Illegal address handler |
326 |
|
* |
327 |
|
|
328 |
< |
doilladdr: move.l a0,(sp) ;Save a0 |
328 |
> |
doilladdr move.l a0,(sp) ;Save a0 |
329 |
|
|
330 |
|
move.l usp,a0 ;Get user stack pointer |
331 |
|
move.l 3*4(sp),-(a0) ;Copy 6-word stack frame to user stack |
346 |
|
* to execute extended opcodes (see emul_op.h) |
347 |
|
* |
348 |
|
|
349 |
< |
doillinstr |
401 |
< |
movem.l a0/d0,-(sp) |
349 |
> |
doillinstr movem.l a0/d0,-(sp) |
350 |
|
move.w ([6+2*4,sp]),d0 |
351 |
|
and.w #$ff00,d0 |
352 |
|
cmp.w #$7100,d0 |
366 |
|
move.l $10.w,-(sp) ;Jump to MacOS exception handler |
367 |
|
rts |
368 |
|
|
369 |
< |
1$: |
422 |
< |
move.l a6,(sp) ;Save a6 |
369 |
> |
1$ move.l a6,(sp) ;Save a6 |
370 |
|
move.l usp,a6 ;Get user stack pointer |
371 |
|
|
372 |
|
move.l a6,-10(a6) ;Push USP (a7) |
637 |
|
fsavepush move.l (sp),d0 ;Restore d0 |
638 |
|
move.l a0,(sp) ;Save a0 |
639 |
|
move.l usp,a0 ;Get user stack pointer |
640 |
< |
fsave -(a0) ;Push FP state |
640 |
> |
move.l #$41000000,-(a0) ;Push idle frame |
641 |
|
move.l a0,usp ;Update USP |
642 |
|
move.l (sp)+,a0 ;Restore a0 |
643 |
|
addq.l #2,2(sp) ;Skip instruction |
644 |
|
rte |
645 |
|
|
646 |
+ |
; fsave xxx(a5) |
647 |
+ |
fsavea5 move.l (sp),d0 ;Restore d0 |
648 |
+ |
move.l a0,(sp) ;Save a0 |
649 |
+ |
move.l a5,a0 ;Get base register |
650 |
+ |
add.w ([6,sp],2),a0 ;Add offset to base register |
651 |
+ |
move.l #$41000000,(a0) ;Push idle frame |
652 |
+ |
move.l (sp)+,a0 ;Restore a0 |
653 |
+ |
addq.l #4,2(sp) ;Skip instruction |
654 |
+ |
rte |
655 |
+ |
|
656 |
|
; frestore (sp)+ |
657 |
|
frestorepop move.l (sp),d0 ;Restore d0 |
658 |
|
move.l a0,(sp) ;Save a0 |
659 |
|
move.l usp,a0 ;Get user stack pointer |
660 |
< |
frestore (a0)+ ;Restore FP state |
660 |
> |
addq.l #4,a0 ;Nothing to do... |
661 |
|
move.l a0,usp ;Update USP |
662 |
|
move.l (sp)+,a0 ;Restore a0 |
663 |
|
addq.l #2,2(sp) ;Skip instruction |
664 |
|
rte |
665 |
|
|
666 |
< |
; frestore xxx(a5) +jl+ |
666 |
> |
; frestore xxx(a5) |
667 |
|
frestorea5 move.l (sp),d0 ;Restore d0 |
668 |
|
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) |
669 |
|
move.l (sp)+,a0 ;Restore a0 |
670 |
|
addq.l #4,2(sp) ;Skip instruction |
671 |
|
rte |
690 |
|
lea 16+4(sp),a1 ; destination address (in supervisor stack) |
691 |
|
bra 1$ |
692 |
|
|
693 |
< |
2$: move.w (a0)+,(a1)+ ; copy additional stack words back to supervisor stack |
694 |
< |
1$: dbf d0,2$ |
693 |
> |
2$ move.w (a0)+,(a1)+ ; copy additional stack words back to supervisor stack |
694 |
> |
1$ dbf d0,2$ |
695 |
|
|
696 |
|
move.l a0,usp ;Update USP |
697 |
|
movem.l (sp)+,a0/a1 ;Restore a0 and a1 |
895 |
|
rte |
896 |
|
|
897 |
|
; movec sfc,d1 +jl+ |
898 |
< |
movecsfcd1: move.l (sp)+,d0 ;Restore d0 |
898 |
> |
movecsfcd1 move.l (sp)+,d0 ;Restore d0 |
899 |
|
moveq #0,d1 |
900 |
|
addq.l #4,2(sp) |
901 |
|
rte |
902 |
|
|
903 |
|
; movec dfc,d1 +jl+ |
904 |
< |
movecdfcd1: move.l (sp)+,d0 ;Restore d0 |
904 |
> |
movecdfcd1 move.l (sp)+,d0 ;Restore d0 |
905 |
|
moveq #0,d1 |
906 |
|
addq.l #4,2(sp) |
907 |
|
rte |
908 |
|
|
909 |
< |
movecurpd0: ; movec urp,d0 +jl+ |
910 |
< |
movecsrpd0: ; movec srp,d0 |
911 |
< |
movecitt0d0: ; movec itt0,d0 |
912 |
< |
movecitt1d0: ; movec itt1,d0 |
913 |
< |
movecdtt0d0: ; movec dtt0,d0 |
914 |
< |
movecdtt1d0: ; movec dtt1,d0 |
909 |
> |
movecurpd0 ; movec urp,d0 +jl+ |
910 |
> |
movecsrpd0 ; movec srp,d0 |
911 |
> |
movecitt0d0 ; movec itt0,d0 |
912 |
> |
movecitt1d0 ; movec itt1,d0 |
913 |
> |
movecdtt0d0 ; movec dtt0,d0 |
914 |
> |
movecdtt1d0 ; movec dtt1,d0 |
915 |
|
addq.l #4,sp |
916 |
|
moveq.l #0,d0 ;MMU is always off |
917 |
|
addq.l #4,2(sp) ;skip instruction |
966 |
|
rte |
967 |
|
|
968 |
|
; move usp,a1 +jl+ |
969 |
< |
moveuspa1: move.l (sp)+,d0 |
969 |
> |
moveuspa1 move.l (sp)+,d0 |
970 |
|
move usp,a1 |
971 |
|
addq.l #2,2(sp) |
972 |
|
rte |
973 |
|
|
974 |
|
; move usp,a0 +jl+ |
975 |
< |
moveuspa0: move.l (sp)+,d0 |
975 |
> |
moveuspa0 move.l (sp)+,d0 |
976 |
|
move usp,a0 |
977 |
|
addq.l #2,2(sp) |
978 |
|
rte |
979 |
|
|
980 |
|
; move a1,usp +jl+ |
981 |
< |
moved1usp: move.l (sp)+,d0 |
981 |
> |
moved1usp move.l (sp)+,d0 |
982 |
|
move a1,usp |
983 |
|
addq.l #2,2(sp) |
984 |
|
rte |
987 |
|
; Trigger NMI (Pop up debugger) |
988 |
|
; |
989 |
|
|
990 |
< |
_AsmTriggerNMI: |
1047 |
< |
move.l d0,-(sp) ;Save d0 |
990 |
> |
_AsmTriggerNMI move.l d0,-(sp) ;Save d0 |
991 |
|
move.w #$007c,-(sp) ;Yes, fake NMI stack frame |
992 |
|
pea 1$ |
993 |
|
move.w _EmulatedSR,d0 |