ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/thunks.h
Revision: 1.9
Committed: 2004-11-13T14:09:16Z (19 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.8: +11 -16 lines
Log Message:
Implement Direct Addressing mode similarly to Basilisk II. This is to get
SheepShaver working on OSes that don't support maipping of Low Memory globals
at 0x00000000, e.g. Windows.

File Contents

# Content
1 /*
2 * thunks.h - Thunks to share data and code with MacOS
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 THUNKS_H
22 #define THUNKS_H
23
24 #include "cpu_emulation.h"
25
26 /*
27 * Native function invocation
28 */
29
30 enum {
31 NATIVE_PATCH_NAME_REGISTRY,
32 NATIVE_VIDEO_INSTALL_ACCEL,
33 NATIVE_VIDEO_VBL,
34 NATIVE_VIDEO_DO_DRIVER_IO,
35 NATIVE_ETHER_IRQ,
36 NATIVE_ETHER_INIT,
37 NATIVE_ETHER_TERM,
38 NATIVE_ETHER_OPEN,
39 NATIVE_ETHER_CLOSE,
40 NATIVE_ETHER_WPUT,
41 NATIVE_ETHER_RSRV,
42 NATIVE_SERIAL_NOTHING,
43 NATIVE_SERIAL_OPEN,
44 NATIVE_SERIAL_PRIME_IN,
45 NATIVE_SERIAL_PRIME_OUT,
46 NATIVE_SERIAL_CONTROL,
47 NATIVE_SERIAL_STATUS,
48 NATIVE_SERIAL_CLOSE,
49 NATIVE_GET_RESOURCE,
50 NATIVE_GET_1_RESOURCE,
51 NATIVE_GET_IND_RESOURCE,
52 NATIVE_GET_1_IND_RESOURCE,
53 NATIVE_R_GET_RESOURCE,
54 NATIVE_MAKE_EXECUTABLE,
55 NATIVE_CHECK_LOAD_INVOC,
56 NATIVE_SYNC_HOOK,
57 NATIVE_BITBLT_HOOK,
58 NATIVE_FILLRECT_HOOK,
59 NATIVE_BITBLT,
60 NATIVE_INVRECT,
61 NATIVE_FILLRECT,
62 NATIVE_OP_MAX
63 };
64
65 // Initialize the thunks system
66 extern bool ThunksInit(void);
67
68 // Exit the thunks system
69 extern void ThunksExit(void);
70
71 // Return the fake PowerPC opcode to handle specified native code
72 #if EMULATED_PPC
73 extern uint32 NativeOpcode(int selector);
74 #endif
75
76 // Return the native function descriptor (TVECT)
77 extern uint32 NativeTVECT(int selector);
78
79 // Return the native function address
80 extern uint32 NativeFunction(int selector);
81
82 // Return the routine descriptor address of the native function
83 extern uint32 NativeRoutineDescriptor(int selector);
84
85
86 /*
87 * Helpers to share 32-bit addressable data with MacOS
88 */
89
90 class SheepMem {
91 static uint32 align(uint32 size);
92 protected:
93 static uint32 page_size;
94 static uintptr zero_page;
95 static uintptr base;
96 static uintptr top;
97 static const uint32 size = 0x40000; // 256 KB
98 public:
99 static bool Init(void);
100 static void Exit(void);
101 static uint32 PageSize();
102 static uint32 ZeroPage();
103 static uint32 Reserve(uint32 size);
104 static void Release(uint32 size);
105 friend class SheepVar;
106 };
107
108 inline uint32 SheepMem::align(uint32 size)
109 {
110 // Align on 4 bytes boundaries
111 return (size + 3) & -4;
112 }
113
114 inline uint32 SheepMem::PageSize()
115 {
116 return page_size;
117 }
118
119 inline uint32 SheepMem::ZeroPage()
120 {
121 return zero_page;
122 }
123
124 inline uint32 SheepMem::Reserve(uint32 size)
125 {
126 top -= align(size);
127 assert(top >= base);
128 return top;
129 }
130
131 inline void SheepMem::Release(uint32 size)
132 {
133 top += align(size);
134 }
135
136 class SheepVar
137 {
138 uint32 m_base;
139 uint32 m_size;
140 public:
141 SheepVar(uint32 requested_size);
142 ~SheepVar() { SheepMem::Release(m_size); }
143 uint32 addr() const { return m_base; }
144 };
145
146 inline SheepVar::SheepVar(uint32 requested_size)
147 {
148 m_size = SheepMem::align(requested_size);
149 m_base = SheepMem::Reserve(m_size);
150 }
151
152 // TODO: optimize for 32-bit platforms
153
154 template< int requested_size >
155 struct SheepArray : public SheepVar
156 {
157 SheepArray() : SheepVar(requested_size) { }
158 };
159
160 struct SheepVar32 : public SheepVar
161 {
162 SheepVar32() : SheepVar(4) { }
163 SheepVar32(uint32 value) : SheepVar(4) { set_value(value); }
164 uint32 value() const { return ReadMacInt32(addr()); }
165 void set_value(uint32 v) { WriteMacInt32(addr(), v); }
166 };
167
168 struct SheepString : public SheepVar
169 {
170 SheepString(const char *str) : SheepVar(strlen(str) + 1)
171 { if (str) strcpy(value(), str); else WriteMacInt8(addr(), 0); }
172 char *value() const
173 { return (char *)Mac2HostAddr(addr()); }
174 };
175
176 #endif