ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/cpu_emulation.h
Revision: 1.1.1.1 (vendor branch)
Committed: 2002-02-04T16:58:13Z (22 years, 9 months ago) by cebix
Content type: text/plain
Branch: cebix
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
Imported sources

File Contents

# Content
1 /*
2 * cpu_emulation.h - Definitions for CPU emulation and Mac memory access
3 *
4 * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
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 #ifndef CPU_EMULATION_H
22 #define CPU_EMULATION_H
23
24
25 /*
26 * Memory system
27 */
28
29 // Constants
30 const uint32 ROM_BASE = 0x40800000; // Base address of ROM
31 const uint32 ROM_SIZE = 0x00400000; // Size of ROM file
32 const uint32 DR_CACHE_BASE = 0x69000000; // Address of DR cache
33 const uint32 DR_CACHE_SIZE = 0x80000; // Size of DR Cache
34
35 // RAM and ROM pointers (allocated and set by main_*.cpp)
36 extern uint32 RAMBase; // Base address of Mac RAM
37 extern uint32 RAMSize; // Size address of Mac RAM
38
39 // Mac memory access functions
40 static inline uint32 ReadMacInt8(uint32 addr) {return *(uint8 *)addr;}
41 static inline void WriteMacInt8(uint32 addr, uint32 b) {*(uint8 *)addr = b;}
42 #ifdef __i386__
43 static inline uint32 ReadMacInt16(uint32 addr) {uint32 retval; __asm__ ("movzwl %w1,%k0\n\tshll $16,%k0\n\tbswapl %k0\n" : "=&r" (retval) : "m" (*(uint16 *)addr) : "cc"); return retval;}
44 static inline uint32 ReadMacInt32(uint32 addr) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*(uint32 *)addr) : "cc"); return retval;}
45 static inline uint64 ReadMacInt64(uint32 addr) {return ((uint64)ReadMacInt32(addr) << 32) | ReadMacInt32(addr + 4);}
46 static inline void WriteMacInt16(uint32 addr, uint32 w) {__asm__ ("bswapl %0" : "=&r" (w) : "0" (w << 16) : "cc"); *(uint16 *)addr = w;}
47 static inline void WriteMacInt32(uint32 addr, uint32 l) {__asm__ ("bswap %0" : "=r" (l) : "0" (l) : "cc"); *(uint32 *)addr = l;}
48 static inline void WriteMacInt64(uint32 addr, uint64 ll) {WriteMacInt32(addr, ll >> 32); WriteMacInt32(addr, ll);}
49 #else
50 static inline uint32 ReadMacInt16(uint32 addr) {return *(uint16 *)addr;}
51 static inline uint32 ReadMacInt32(uint32 addr) {return *(uint32 *)addr;}
52 static inline uint64 ReadMacInt64(uint32 addr) {return *(uint64 *)addr;}
53 static inline void WriteMacInt16(uint32 addr, uint32 w) {*(uint16 *)addr = w;}
54 static inline void WriteMacInt32(uint32 addr, uint32 l) {*(uint32 *)addr = l;}
55 static inline void WriteMacInt64(uint32 addr, uint64 ll) {*(uint64 *)addr = ll;}
56 #endif
57 static inline uint8 *Mac2HostAddr(uint32 addr) {return (uint8 *)addr;}
58 static inline void *Mac_memset(uint32 addr, int c, size_t n) {return memset(Mac2HostAddr(addr), c, n);}
59 static inline void *Mac2Host_memcpy(void *dest, uint32 src, size_t n) {return memcpy(dest, Mac2HostAddr(src), n);}
60 static inline void *Host2Mac_memcpy(uint32 dest, const void *src, size_t n) {return memcpy(Mac2HostAddr(dest), src, n);}
61 static inline void *Mac2Mac_memcpy(uint32 dest, uint32 src, size_t n) {return memcpy(Mac2HostAddr(dest), Mac2HostAddr(src), n);}
62
63
64 /*
65 * 680x0 and PPC emulation
66 */
67
68 struct M68kRegisters;
69 extern void Execute68k(uint32, M68kRegisters *r); // Execute 68k subroutine from EMUL_OP routine, must be ended with RTS
70 extern void Execute68kTrap(uint16 trap, M68kRegisters *r); // Execute 68k A-Trap from EMUL_OP routine
71 extern void ExecutePPC(void (*func)()); // Execute PPC code from EMUL_OP routine (real mode switch)
72
73 #endif