1 |
cebix |
1.1 |
/* |
2 |
cebix |
1.4 |
* asm_support.s - Utility functions in assembly language (for native 68k support) |
3 |
cebix |
1.1 |
* |
4 |
cebix |
1.5 |
* Basilisk II (C) 1997-2002 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
.file "asm_support.s" |
22 |
|
|
.text |
23 |
|
|
|
24 |
|
|
.globl _m68k_sync_icache |
25 |
|
|
.globl _Start680x0__Fv |
26 |
|
|
.globl _SetInterruptFlag__FUi |
27 |
|
|
.globl _ClearInterruptFlag__FUi |
28 |
|
|
.globl _Execute68k |
29 |
|
|
.globl _Execute68kTrap |
30 |
|
|
.globl _EmulOpTrampoline |
31 |
|
|
|
32 |
|
|
.globl _RAMBaseHost |
33 |
|
|
.globl _ROMBaseHost |
34 |
|
|
.globl _EmulOp__FUsP13M68kRegisters |
35 |
|
|
.globl _EmulatedSR |
36 |
|
|
.globl _InterruptFlags |
37 |
|
|
.globl _TriggerInterrupt__Fv |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/* |
41 |
|
|
* Call m68k_sync_icache() (NetBSD, the version in libm68k is broken) |
42 |
|
|
*/ |
43 |
|
|
|
44 |
|
|
.type _m68k_sync_icache,@function |
45 |
|
|
_m68k_sync_icache: |
46 |
|
|
movl sp@(8),d1 |
47 |
|
|
movl sp@(4),a1 |
48 |
|
|
movl #0x80000004,d0 |
49 |
|
|
trap #12 |
50 |
|
|
rts |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
/* |
54 |
|
|
* Jump to Mac ROM, start emulation |
55 |
|
|
*/ |
56 |
|
|
|
57 |
|
|
.type _Start680x0__Fv,@function |
58 |
|
|
_Start680x0__Fv: |
59 |
|
|
movl _RAMBaseHost,a0 |
60 |
|
|
addl #0x8000,a0 |
61 |
|
|
movl a0,sp |
62 |
|
|
movl _ROMBaseHost,a0 |
63 |
|
|
lea a0@(0x2a),a0 |
64 |
|
|
jmp a0@ |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
/* |
68 |
|
|
* Set/clear interrupt flag (atomically) |
69 |
|
|
*/ |
70 |
|
|
|
71 |
|
|
.type _SetInterruptFlag__FUi,@function |
72 |
|
|
_SetInterruptFlag__FUi: |
73 |
|
|
movl sp@(4),d0 |
74 |
|
|
orl d0,_InterruptFlags |
75 |
|
|
rts |
76 |
|
|
|
77 |
|
|
.type _ClearInterruptFlag__FUi,@function |
78 |
|
|
_ClearInterruptFlag__FUi: |
79 |
|
|
movl sp@(4),d0 |
80 |
|
|
notl d0 |
81 |
|
|
andl d0,_InterruptFlags |
82 |
|
|
rts |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
/* |
86 |
|
|
* Execute 68k subroutine (must be ended with rts) |
87 |
|
|
* r->a[7] and r->sr are unused! |
88 |
|
|
*/ |
89 |
|
|
|
90 |
|
|
/* void Execute68k(uint32 addr, M68kRegisters *r); */ |
91 |
|
|
.type _Execute68k,@function |
92 |
|
|
_Execute68k: movl sp@(4),d0 |Get arguments |
93 |
|
|
movl sp@(8),a0 |
94 |
|
|
|
95 |
|
|
movml d2-d7/a2-a6,sp@- |Save registers |
96 |
|
|
|
97 |
|
|
movl a0,sp@- |Push pointer to M68kRegisters on stack |
98 |
|
|
pea exec68kret |Push return address on stack |
99 |
|
|
movl d0,sp@- |Push pointer to 68k routine on stack |
100 |
|
|
movml a0@,d0-d7/a0-a6 |Load registers from M68kRegisters |
101 |
|
|
|
102 |
|
|
rts |Jump into 68k routine |
103 |
|
|
|
104 |
|
|
exec68kret: movl a6,sp@- |Save a6 |
105 |
|
|
movl sp@(4),a6 |Get pointer to M68kRegisters |
106 |
|
|
movml d0-d7/a0-a5,a6@ |Save d0-d7/a0-a5 to M68kRegisters |
107 |
|
|
movl sp@+,a6@(56) |Save a6 to M68kRegisters |
108 |
|
|
addql #4,sp |Remove pointer from stack |
109 |
|
|
|
110 |
|
|
movml sp@+,d2-d7/a2-a6 |Restore registers |
111 |
|
|
rts |
112 |
|
|
|
113 |
|
|
|
114 |
|
|
/* |
115 |
|
|
* Execute MacOS 68k trap |
116 |
|
|
* r->a[7] and r->sr are unused! |
117 |
|
|
*/ |
118 |
|
|
|
119 |
|
|
/* void Execute68kTrap(uint16 trap, M68kRegisters *r); */ |
120 |
|
|
.type _Execute68kTrap,@function |
121 |
|
|
_Execute68kTrap: |
122 |
|
|
movl sp@(4),d0 |Get arguments |
123 |
|
|
movl sp@(8),a0 |
124 |
|
|
|
125 |
|
|
movml d2-d7/a2-a6,sp@- |Save registers |
126 |
|
|
|
127 |
|
|
movl a0,sp@- |Push pointer to M68kRegisters on stack |
128 |
|
|
movw d0,sp@- |Push trap word on stack |
129 |
|
|
subql #8,sp |Create fake A-Line exception frame |
130 |
|
|
movml a0@,d0-d7/a0-a6 |Load registers from M68kRegisters |
131 |
|
|
|
132 |
|
|
movl a2,sp@- |Save a2 and d2 |
133 |
|
|
movl d2,sp@- |
134 |
|
|
lea exectrapret,a2 |a2 points to return address |
135 |
|
|
movw sp@(16),d2 |Load trap word into d2 |
136 |
|
|
|
137 |
|
|
jmp zpc@(0x28:w)@(10) |Jump into MacOS A-Line handler |
138 |
|
|
|
139 |
|
|
exectrapret: movl a6,sp@- |Save a6 |
140 |
|
|
movl sp@(6),a6 |Get pointer to M68kRegisters |
141 |
|
|
movml d0-d7/a0-a5,a6@ |Save d0-d7/a0-a5 to M68kRegisters |
142 |
|
|
movl sp@+,a6@(56) |Save a6 to M68kRegisters |
143 |
|
|
addql #6,sp |Remove pointer and trap word from stack |
144 |
|
|
|
145 |
|
|
movml sp@+,d2-d7/a2-a6 |Restore registers |
146 |
|
|
rts |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
/* |
150 |
|
|
* Call EmulOp() after return from SIGILL handler, registers are pushed on stack |
151 |
|
|
*/ |
152 |
|
|
|
153 |
|
|
.type _EmulOpTrampoline,@function |
154 |
|
|
_EmulOpTrampoline: |
155 |
|
|
movl sp,a0 |Get pointer to registers |
156 |
|
|
|
157 |
|
|
movw _EmulatedSR,d0 |Save EmulatedSR, disable interrupts |
158 |
|
|
movw d0,sp@- |
159 |
|
|
oriw #0x0700,d0 |
160 |
|
|
movw d0,_EmulatedSR |
161 |
|
|
|
162 |
|
|
movl a0,sp@- |Push pointer to registers |
163 |
|
|
movl a0@(66),a1 |Get saved PC |
164 |
|
|
addql #2,a0@(66) |Skip EMUL_OP opcode |
165 |
|
|
movw a1@,sp@- |Push opcode word |
166 |
|
|
clrw sp@- |
167 |
|
|
jbsr _EmulOp__FUsP13M68kRegisters |
168 |
|
|
addql #8,sp |
169 |
|
|
|
170 |
|
|
movw sp@+,d0 |Restore interrupts, trigger pending interrupt |
171 |
|
|
movw d0,_EmulatedSR |
172 |
|
|
andiw #0x0700,d0 |
173 |
|
|
bne eot1 |
174 |
|
|
tstl _InterruptFlags |
175 |
|
|
beq eot1 |
176 |
|
|
jbsr _TriggerInterrupt__Fv |
177 |
|
|
|
178 |
|
|
eot1: moveml sp@+,d0-d7/a0-a6 |Restore registers |
179 |
|
|
addql #4,sp |Skip saved SP |
180 |
|
|
rtr |