1 |
cebix |
1.1 |
/* |
2 |
cebix |
1.2 |
* asm_support.s - Utility functions in assemmbly language (for native 68k support) |
3 |
cebix |
1.1 |
* |
4 |
|
|
* Basilisk II (C) 1997-1999 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 |
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 _Scod060Patch1 |
31 |
|
|
.globl _Scod060Patch2 |
32 |
|
|
.globl _ThInitFPUPatch |
33 |
|
|
.globl _EmulOpTrampoline |
34 |
|
|
|
35 |
|
|
.globl _RAMBaseHost |
36 |
|
|
.globl _ROMBaseHost |
37 |
|
|
.globl _EmulOp__FUsP13M68kRegisters |
38 |
|
|
.globl _EmulatedSR |
39 |
|
|
.globl _InterruptFlags |
40 |
|
|
.globl _TriggerInterrupt__Fv |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
/* |
44 |
|
|
* Call m68k_sync_icache() (NetBSD, the version in libm68k is broken) |
45 |
|
|
*/ |
46 |
|
|
|
47 |
|
|
.type _m68k_sync_icache,@function |
48 |
|
|
_m68k_sync_icache: |
49 |
|
|
movl sp@(8),d1 |
50 |
|
|
movl sp@(4),a1 |
51 |
|
|
movl #0x80000004,d0 |
52 |
|
|
trap #12 |
53 |
|
|
rts |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/* |
57 |
|
|
* Jump to Mac ROM, start emulation |
58 |
|
|
*/ |
59 |
|
|
|
60 |
|
|
.type _Start680x0__Fv,@function |
61 |
|
|
_Start680x0__Fv: |
62 |
|
|
movl _RAMBaseHost,a0 |
63 |
|
|
addl #0x8000,a0 |
64 |
|
|
movl a0,sp |
65 |
|
|
movl _ROMBaseHost,a0 |
66 |
|
|
lea a0@(0x2a),a0 |
67 |
|
|
jmp a0@ |
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/* |
71 |
|
|
* Set/clear interrupt flag (atomically) |
72 |
|
|
*/ |
73 |
|
|
|
74 |
|
|
.type _SetInterruptFlag__FUi,@function |
75 |
|
|
_SetInterruptFlag__FUi: |
76 |
|
|
movl sp@(4),d0 |
77 |
|
|
orl d0,_InterruptFlags |
78 |
|
|
rts |
79 |
|
|
|
80 |
|
|
.type _ClearInterruptFlag__FUi,@function |
81 |
|
|
_ClearInterruptFlag__FUi: |
82 |
|
|
movl sp@(4),d0 |
83 |
|
|
notl d0 |
84 |
|
|
andl d0,_InterruptFlags |
85 |
|
|
rts |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
/* |
89 |
|
|
* Execute 68k subroutine (must be ended with rts) |
90 |
|
|
* r->a[7] and r->sr are unused! |
91 |
|
|
*/ |
92 |
|
|
|
93 |
|
|
/* void Execute68k(uint32 addr, M68kRegisters *r); */ |
94 |
|
|
.type _Execute68k,@function |
95 |
|
|
_Execute68k: movl sp@(4),d0 |Get arguments |
96 |
|
|
movl sp@(8),a0 |
97 |
|
|
|
98 |
|
|
movml d2-d7/a2-a6,sp@- |Save registers |
99 |
|
|
|
100 |
|
|
movl a0,sp@- |Push pointer to M68kRegisters on stack |
101 |
|
|
pea exec68kret |Push return address on stack |
102 |
|
|
movl d0,sp@- |Push pointer to 68k routine on stack |
103 |
|
|
movml a0@,d0-d7/a0-a6 |Load registers from M68kRegisters |
104 |
|
|
|
105 |
|
|
rts |Jump into 68k routine |
106 |
|
|
|
107 |
|
|
exec68kret: movl a6,sp@- |Save a6 |
108 |
|
|
movl sp@(4),a6 |Get pointer to M68kRegisters |
109 |
|
|
movml d0-d7/a0-a5,a6@ |Save d0-d7/a0-a5 to M68kRegisters |
110 |
|
|
movl sp@+,a6@(56) |Save a6 to M68kRegisters |
111 |
|
|
addql #4,sp |Remove pointer from stack |
112 |
|
|
|
113 |
|
|
movml sp@+,d2-d7/a2-a6 |Restore registers |
114 |
|
|
rts |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
/* |
118 |
|
|
* Execute MacOS 68k trap |
119 |
|
|
* r->a[7] and r->sr are unused! |
120 |
|
|
*/ |
121 |
|
|
|
122 |
|
|
/* void Execute68kTrap(uint16 trap, M68kRegisters *r); */ |
123 |
|
|
.type _Execute68kTrap,@function |
124 |
|
|
_Execute68kTrap: |
125 |
|
|
movl sp@(4),d0 |Get arguments |
126 |
|
|
movl sp@(8),a0 |
127 |
|
|
|
128 |
|
|
movml d2-d7/a2-a6,sp@- |Save registers |
129 |
|
|
|
130 |
|
|
movl a0,sp@- |Push pointer to M68kRegisters on stack |
131 |
|
|
movw d0,sp@- |Push trap word on stack |
132 |
|
|
subql #8,sp |Create fake A-Line exception frame |
133 |
|
|
movml a0@,d0-d7/a0-a6 |Load registers from M68kRegisters |
134 |
|
|
|
135 |
|
|
movl a2,sp@- |Save a2 and d2 |
136 |
|
|
movl d2,sp@- |
137 |
|
|
lea exectrapret,a2 |a2 points to return address |
138 |
|
|
movw sp@(16),d2 |Load trap word into d2 |
139 |
|
|
|
140 |
|
|
jmp zpc@(0x28:w)@(10) |Jump into MacOS A-Line handler |
141 |
|
|
|
142 |
|
|
exectrapret: movl a6,sp@- |Save a6 |
143 |
|
|
movl sp@(6),a6 |Get pointer to M68kRegisters |
144 |
|
|
movml d0-d7/a0-a5,a6@ |Save d0-d7/a0-a5 to M68kRegisters |
145 |
|
|
movl sp@+,a6@(56) |Save a6 to M68kRegisters |
146 |
|
|
addql #6,sp |Remove pointer and trap word from stack |
147 |
|
|
|
148 |
|
|
movml sp@+,d2-d7/a2-a6 |Restore registers |
149 |
|
|
rts |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
/* |
153 |
|
|
* Call EmulOp() after return from SIGILL handler, registers are pushed on stack |
154 |
|
|
*/ |
155 |
|
|
|
156 |
|
|
.type _EmulOpTrampoline,@function |
157 |
|
|
_EmulOpTrampoline: |
158 |
|
|
movl sp,a0 |Get pointer to registers |
159 |
|
|
|
160 |
|
|
movw _EmulatedSR,d0 |Save EmulatedSR, disable interrupts |
161 |
|
|
movw d0,sp@- |
162 |
|
|
oriw #0x0700,d0 |
163 |
|
|
movw d0,_EmulatedSR |
164 |
|
|
|
165 |
|
|
movl a0,sp@- |Push pointer to registers |
166 |
|
|
movl a0@(66),a1 |Get saved PC |
167 |
|
|
addql #2,a0@(66) |Skip EMUL_OP opcode |
168 |
|
|
movw a1@,sp@- |Push opcode word |
169 |
|
|
clrw sp@- |
170 |
|
|
jbsr _EmulOp__FUsP13M68kRegisters |
171 |
|
|
addql #8,sp |
172 |
|
|
|
173 |
|
|
movw sp@+,d0 |Restore interrupts, trigger pending interrupt |
174 |
|
|
movw d0,_EmulatedSR |
175 |
|
|
andiw #0x0700,d0 |
176 |
|
|
bne eot1 |
177 |
|
|
tstl _InterruptFlags |
178 |
|
|
beq eot1 |
179 |
|
|
jbsr _TriggerInterrupt__Fv |
180 |
|
|
|
181 |
|
|
eot1: moveml sp@+,d0-d7/a0-a6 |Restore registers |
182 |
|
|
addql #4,sp |Skip saved SP |
183 |
|
|
rtr |
184 |
|
|
|
185 |
|
|
|
186 |
|
|
/* |
187 |
|
|
* Process Manager 68060 FPU patches |
188 |
|
|
*/ |
189 |
|
|
|
190 |
|
|
.type _Scod060Patch1,@function |
191 |
|
|
_Scod060Patch1: fsave sp@- |Save FPU state |
192 |
|
|
tstb sp@(2) |Null? |
193 |
|
|
beqs sc1 |
194 |
|
|
fmovemx fp0-fp7,sp@- |No, save FPU registers |
195 |
|
|
fmovel fpi,sp@- |
196 |
|
|
fmovel fpsr,sp@- |
197 |
|
|
fmovel fpcr,sp@- |
198 |
|
|
pea -1 |Push "FPU state saved" flag |
199 |
|
|
sc1: movl d1,sp@- |
200 |
|
|
movl d0,sp@- |
201 |
|
|
bsrs sc3 |Switch integer registers and stack |
202 |
|
|
addql #8,sp |
203 |
|
|
tstb sp@(2) |New FPU state null or "FPU state saved" flag set? |
204 |
|
|
beqs sc2 |
205 |
|
|
addql #4,sp |Flag set, skip it |
206 |
|
|
fmovel sp@+,fpcr |Restore FPU registers and state |
207 |
|
|
fmovel sp@+,fpsr |
208 |
|
|
fmovel sp@+,fpi |
209 |
|
|
fmovemx sp@+,fp0-fp7 |
210 |
|
|
sc2: frestore sp@+ |
211 |
|
|
movml sp@+,d0-d1 |
212 |
|
|
rts |
213 |
|
|
|
214 |
|
|
sc3: movl sp@(4),a0 |Switch integer registers and stack |
215 |
|
|
movw sr,sp@- |
216 |
|
|
movml d2-d7/a2-a6,sp@- |
217 |
|
|
cmpw #0,a0 |
218 |
|
|
beqs sc4 |
219 |
|
|
movl sp,a0@ |
220 |
|
|
sc4: movl sp@(0x36),a0 |
221 |
|
|
movml a0@+,d2-d7/a2-a6 |
222 |
|
|
movw a0@+,sr |
223 |
|
|
movl a0,sp |
224 |
|
|
rts |
225 |
|
|
|
226 |
|
|
.type _Scod060Patch2,@function |
227 |
|
|
_Scod060Patch2: movl d0,sp@- |Create 68060 null frame on stack |
228 |
|
|
movl d0,sp@- |
229 |
|
|
movl d0,sp@- |
230 |
|
|
frestore sp@+ |and load it |
231 |
|
|
rts |
232 |
|
|
|
233 |
|
|
|
234 |
|
|
/* |
235 |
|
|
* Thread Manager 68060 FPU patches |
236 |
|
|
*/ |
237 |
|
|
|
238 |
|
|
.type _ThInitFPUPatch,@function |
239 |
|
|
_ThInitFPUPatch: |
240 |
|
|
tstb a4@(0x40) |
241 |
|
|
bnes th1 |
242 |
|
|
moveq #0,d0 |Create 68060 null frame on stack |
243 |
|
|
movl d0,a3@- |
244 |
|
|
movl d0,a3@- |
245 |
|
|
movl d0,a3@- |
246 |
|
|
th1: rts |