ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/basilisk_glue.cpp
Revision: 1.10
Committed: 2001-06-26T22:35:42Z (23 years, 5 months ago) by gbeauche
Branch: MAIN
Changes since 1.9: +4 -1 lines
Log Message:
- added SIGSEGV support for Linux/Alpha (to be checked), Darwin/PPC
- added uniform virtual memory allocation
  (supports mmap(), vm_allocate(), or fallbacks to malloc()/free())
- cleaned up memory allocation in main_unix.cpp

File Contents

# Content
1 /*
2 * basilisk_glue.cpp - Glue UAE CPU to Basilisk II CPU engine interface
3 *
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
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 #include "sysdeps.h"
22
23 #include "cpu_emulation.h"
24 #include "main.h"
25 #include "emul_op.h"
26 #include "rom_patches.h"
27 #include "m68k.h"
28 #include "memory.h"
29 #include "readcpu.h"
30 #include "newcpu.h"
31
32
33 // RAM and ROM pointers
34 uint32 RAMBaseMac = 0; // RAM base (Mac address space) gb-- init is important
35 uint8 *RAMBaseHost; // RAM base (host address space)
36 uint32 RAMSize; // Size of RAM
37 uint32 ROMBaseMac; // ROM base (Mac address space)
38 uint8 *ROMBaseHost; // ROM base (host address space)
39 uint32 ROMSize; // Size of ROM
40
41 #if !REAL_ADDRESSING
42 // Mac frame buffer
43 uint8 *MacFrameBaseHost; // Frame buffer base (host address space)
44 uint32 MacFrameSize; // Size of frame buffer
45 int MacFrameLayout; // Frame buffer layout
46 #endif
47
48 #if DIRECT_ADDRESSING
49 uintptr MEMBaseDiff; // Global offset between a Mac address and its Host equivalent
50 #endif
51
52 // From newcpu.cpp
53 extern int quit_program;
54
55
56 /*
57 * Initialize 680x0 emulation, CheckROM() must have been called first
58 */
59
60 bool Init680x0(void)
61 {
62 #if REAL_ADDRESSING
63 // Mac address space = host address space
64 RAMBaseMac = (uint32)RAMBaseHost;
65 ROMBaseMac = (uint32)ROMBaseHost;
66 #elif DIRECT_ADDRESSING
67 // Mac address space = host address space minus constant offset (MEMBaseDiff)
68 // NOTE: MEMBaseDiff is set in main_unix.cpp/main()
69 RAMBaseMac = 0;
70 ROMBaseMac = Host2MacAddr(ROMBaseHost);
71 #else
72 // Initialize UAE memory banks
73 RAMBaseMac = 0;
74 switch (ROMVersion) {
75 case ROM_VERSION_64K:
76 case ROM_VERSION_PLUS:
77 case ROM_VERSION_CLASSIC:
78 ROMBaseMac = 0x00400000;
79 break;
80 case ROM_VERSION_II:
81 ROMBaseMac = 0x00a00000;
82 break;
83 case ROM_VERSION_32:
84 ROMBaseMac = 0x40800000;
85 break;
86 default:
87 return false;
88 }
89 memory_init();
90 #endif
91
92 init_m68k();
93 return true;
94 }
95
96
97 /*
98 * Deinitialize 680x0 emulation
99 */
100
101 void Exit680x0(void)
102 {
103 exit_m68k();
104 }
105
106
107 /*
108 * Reset and start 680x0 emulation (doesn't return)
109 */
110
111 void Start680x0(void)
112 {
113 m68k_reset();
114 m68k_go(true);
115 }
116
117
118 /*
119 * Trigger interrupt
120 */
121
122 void TriggerInterrupt(void)
123 {
124 regs.spcflags |= SPCFLAG_INT;
125 }
126
127 void TriggerNMI(void)
128 {
129 //!! not implemented yet
130 }
131
132
133 /*
134 * Get 68k interrupt level
135 */
136
137 int intlev(void)
138 {
139 return InterruptFlags ? 1 : 0;
140 }
141
142
143 /*
144 * Execute MacOS 68k trap
145 * r->a[7] and r->sr are unused!
146 */
147
148 void Execute68kTrap(uint16 trap, struct M68kRegisters *r)
149 {
150 int i;
151
152 // Save old PC
153 uaecptr oldpc = m68k_getpc();
154
155 // Set registers
156 for (i=0; i<8; i++)
157 m68k_dreg(regs, i) = r->d[i];
158 for (i=0; i<7; i++)
159 m68k_areg(regs, i) = r->a[i];
160
161 // Push trap and EXEC_RETURN on stack
162 m68k_areg(regs, 7) -= 2;
163 put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN);
164 m68k_areg(regs, 7) -= 2;
165 put_word(m68k_areg(regs, 7), trap);
166
167 // Execute trap
168 m68k_setpc(m68k_areg(regs, 7));
169 fill_prefetch_0();
170 quit_program = 0;
171 m68k_go(true);
172
173 // Clean up stack
174 m68k_areg(regs, 7) += 4;
175
176 // Restore old PC
177 m68k_setpc(oldpc);
178 fill_prefetch_0();
179
180 // Get registers
181 for (i=0; i<8; i++)
182 r->d[i] = m68k_dreg(regs, i);
183 for (i=0; i<7; i++)
184 r->a[i] = m68k_areg(regs, i);
185 quit_program = 0;
186 }
187
188
189 /*
190 * Execute 68k subroutine
191 * The executed routine must reside in UAE memory!
192 * r->a[7] and r->sr are unused!
193 */
194
195 void Execute68k(uint32 addr, struct M68kRegisters *r)
196 {
197 int i;
198
199 // Save old PC
200 uaecptr oldpc = m68k_getpc();
201
202 // Set registers
203 for (i=0; i<8; i++)
204 m68k_dreg(regs, i) = r->d[i];
205 for (i=0; i<7; i++)
206 m68k_areg(regs, i) = r->a[i];
207
208 // Push EXEC_RETURN and faked return address (points to EXEC_RETURN) on stack
209 m68k_areg(regs, 7) -= 2;
210 put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN);
211 m68k_areg(regs, 7) -= 4;
212 put_long(m68k_areg(regs, 7), m68k_areg(regs, 7) + 4);
213
214 // Execute routine
215 m68k_setpc(addr);
216 fill_prefetch_0();
217 quit_program = 0;
218 m68k_go(true);
219
220 // Clean up stack
221 m68k_areg(regs, 7) += 2;
222
223 // Restore old PC
224 m68k_setpc(oldpc);
225 fill_prefetch_0();
226
227 // Get registers
228 for (i=0; i<8; i++)
229 r->d[i] = m68k_dreg(regs, i);
230 for (i=0; i<7; i++)
231 r->a[i] = m68k_areg(regs, i);
232 quit_program = 0;
233 }