root / darwin-user / commpage.c @ 4870852c
History | View | Annotate | Download (12.9 kB)
1 | 831b7825 | ths | /*
|
---|---|---|---|
2 | 831b7825 | ths | * Commpage syscalls
|
3 | 831b7825 | ths | *
|
4 | 831b7825 | ths | * Copyright (c) 2006 Pierre d'Herbemont
|
5 | 831b7825 | ths | *
|
6 | 831b7825 | ths | * This program is free software; you can redistribute it and/or modify
|
7 | 831b7825 | ths | * it under the terms of the GNU General Public License as published by
|
8 | 831b7825 | ths | * the Free Software Foundation; either version 2 of the License, or
|
9 | 831b7825 | ths | * (at your option) any later version.
|
10 | 831b7825 | ths | *
|
11 | 831b7825 | ths | * This program is distributed in the hope that it will be useful,
|
12 | 831b7825 | ths | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 831b7825 | ths | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 831b7825 | ths | * GNU General Public License for more details.
|
15 | 831b7825 | ths | *
|
16 | 831b7825 | ths | * You should have received a copy of the GNU General Public License
|
17 | 831b7825 | ths | * along with this program; if not, write to the Free Software
|
18 | 530e7615 | blueswir1 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
19 | 530e7615 | blueswir1 | * MA 02110-1301, USA.
|
20 | 831b7825 | ths | */
|
21 | 831b7825 | ths | #include <fcntl.h> |
22 | 831b7825 | ths | #include <stdio.h> |
23 | 831b7825 | ths | #include <stdlib.h> |
24 | 831b7825 | ths | #include <errno.h> |
25 | 831b7825 | ths | |
26 | 831b7825 | ths | #include <mach/message.h> |
27 | 831b7825 | ths | #include <mach/mach.h> |
28 | 831b7825 | ths | #include <mach/mach_time.h> |
29 | 831b7825 | ths | #include <sys/time.h> |
30 | 831b7825 | ths | #include <sys/mman.h> |
31 | 831b7825 | ths | #include <libkern/OSAtomic.h> |
32 | 831b7825 | ths | |
33 | 831b7825 | ths | #include "qemu.h" |
34 | 831b7825 | ths | |
35 | 831b7825 | ths | //#define DEBUG_COMMPAGE
|
36 | 831b7825 | ths | |
37 | 831b7825 | ths | #ifdef DEBUG_COMMPAGE
|
38 | 93fcfe39 | aliguori | # define DPRINTF(...) do { qemu_log(__VA_ARGS__); printf(__VA_ARGS__); } while(0) |
39 | 831b7825 | ths | #else
|
40 | 93fcfe39 | aliguori | # define DPRINTF(...) do { qemu_log(__VA_ARGS__); } while(0) |
41 | 831b7825 | ths | #endif
|
42 | 831b7825 | ths | |
43 | 831b7825 | ths | /********************************************************************
|
44 | 831b7825 | ths | * Commpage definitions
|
45 | 831b7825 | ths | */
|
46 | 831b7825 | ths | #ifdef TARGET_I386
|
47 | 831b7825 | ths | /* Reserve space for the commpage see xnu/osfmk/i386/cpu_capabilities.h */
|
48 | 831b7825 | ths | # define COMMPAGE_START (-16 * 4096) /* base address is -20 * 4096 */ |
49 | 831b7825 | ths | # define COMMPAGE_SIZE (0x1240) /* _COMM_PAGE_AREA_LENGTH is 19 * 4096 */ |
50 | 831b7825 | ths | #elif defined(TARGET_PPC)
|
51 | 831b7825 | ths | /* Reserve space for the commpage see xnu/osfmk/ppc/cpu_capabilities.h */
|
52 | 831b7825 | ths | # define COMMPAGE_START (-8*4096) |
53 | 831b7825 | ths | # define COMMPAGE_SIZE (2*4096) /* its _COMM_PAGE_AREA_USED but _COMM_PAGE_AREA_LENGTH is 7*4096 */ |
54 | 831b7825 | ths | #endif
|
55 | 831b7825 | ths | |
56 | 831b7825 | ths | void do_compare_and_swap32(void *cpu_env, int num); |
57 | 831b7825 | ths | void do_compare_and_swap64(void *cpu_env, int num); |
58 | 831b7825 | ths | void do_add_atomic_word32(void *cpu_env, int num); |
59 | 831b7825 | ths | void do_cgettimeofday(void *cpu_env, int num, uint32_t arg1); |
60 | 831b7825 | ths | void do_nanotime(void *cpu_env, int num); |
61 | 831b7825 | ths | |
62 | 831b7825 | ths | void unimpl_commpage(void *cpu_env, int num); |
63 | 831b7825 | ths | |
64 | 831b7825 | ths | typedef void (*commpage_8args_function_t)(uint32_t arg1, uint32_t arg2, uint32_t arg3, |
65 | 831b7825 | ths | uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, |
66 | 831b7825 | ths | uint32_t arg8); |
67 | 831b7825 | ths | typedef void (*commpage_indirect_function_t)(void *cpu_env, int num, uint32_t arg1, |
68 | 831b7825 | ths | uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, |
69 | 831b7825 | ths | uint32_t arg6, uint32_t arg7, uint32_t arg8); |
70 | 831b7825 | ths | |
71 | 831b7825 | ths | #define HAS_PTR 0x10 |
72 | 831b7825 | ths | #define NO_PTR 0x20 |
73 | 831b7825 | ths | #define CALL_DIRECT 0x1 |
74 | 831b7825 | ths | #define CALL_INDIRECT 0x2 |
75 | 831b7825 | ths | |
76 | 831b7825 | ths | #define COMMPAGE_ENTRY(name, nargs, offset, func, options) \
|
77 | 831b7825 | ths | { #name, offset, nargs, options, (commpage_8args_function_t)func }
|
78 | 831b7825 | ths | |
79 | 831b7825 | ths | struct commpage_entry {
|
80 | 831b7825 | ths | char * name;
|
81 | 831b7825 | ths | int offset;
|
82 | 831b7825 | ths | int nargs;
|
83 | 831b7825 | ths | char options;
|
84 | 831b7825 | ths | commpage_8args_function_t function; |
85 | 831b7825 | ths | }; |
86 | 831b7825 | ths | |
87 | 831b7825 | ths | static inline int commpage_code_num(struct commpage_entry *entry) |
88 | 831b7825 | ths | { |
89 | 831b7825 | ths | if((entry->options & HAS_PTR))
|
90 | 831b7825 | ths | return entry->offset + 4; |
91 | 831b7825 | ths | else
|
92 | 831b7825 | ths | return entry->offset;
|
93 | 831b7825 | ths | } |
94 | 831b7825 | ths | |
95 | 831b7825 | ths | static inline int commpage_is_indirect(struct commpage_entry *entry) |
96 | 831b7825 | ths | { |
97 | 831b7825 | ths | return !(entry->options & CALL_DIRECT);
|
98 | 831b7825 | ths | } |
99 | 831b7825 | ths | |
100 | 831b7825 | ths | /********************************************************************
|
101 | 831b7825 | ths | * Commpage entry
|
102 | 831b7825 | ths | */
|
103 | 831b7825 | ths | static struct commpage_entry commpage_entries[] = |
104 | 831b7825 | ths | { |
105 | 831b7825 | ths | COMMPAGE_ENTRY(compare_and_swap32, 0, 0x080, do_compare_and_swap32, CALL_INDIRECT | HAS_PTR), |
106 | 831b7825 | ths | COMMPAGE_ENTRY(compare_and_swap64, 0, 0x0c0, do_compare_and_swap64, CALL_INDIRECT | HAS_PTR), |
107 | 831b7825 | ths | COMMPAGE_ENTRY(enqueue, 0, 0x100, unimpl_commpage, CALL_INDIRECT), |
108 | 831b7825 | ths | COMMPAGE_ENTRY(dequeue, 0, 0x140, unimpl_commpage, CALL_INDIRECT), |
109 | 831b7825 | ths | COMMPAGE_ENTRY(memory_barrier, 0, 0x180, unimpl_commpage, CALL_INDIRECT), |
110 | 831b7825 | ths | COMMPAGE_ENTRY(add_atomic_word32, 0, 0x1a0, do_add_atomic_word32, CALL_INDIRECT | HAS_PTR), |
111 | 831b7825 | ths | COMMPAGE_ENTRY(add_atomic_word64, 0, 0x1c0, unimpl_commpage, CALL_INDIRECT | HAS_PTR), |
112 | 831b7825 | ths | |
113 | 831b7825 | ths | COMMPAGE_ENTRY(mach_absolute_time, 0, 0x200, unimpl_commpage, CALL_INDIRECT), |
114 | 831b7825 | ths | COMMPAGE_ENTRY(spinlock_try, 1, 0x220, unimpl_commpage, CALL_INDIRECT), |
115 | 831b7825 | ths | COMMPAGE_ENTRY(spinlock_lock, 1, 0x260, OSSpinLockLock, CALL_DIRECT), |
116 | 831b7825 | ths | COMMPAGE_ENTRY(spinlock_unlock, 1, 0x2a0, OSSpinLockUnlock, CALL_DIRECT), |
117 | 831b7825 | ths | COMMPAGE_ENTRY(pthread_getspecific, 0, 0x2c0, unimpl_commpage, CALL_INDIRECT), |
118 | 2a252826 | bellard | COMMPAGE_ENTRY(gettimeofday, 1, 0x2e0, do_cgettimeofday, CALL_INDIRECT), |
119 | 2a252826 | bellard | COMMPAGE_ENTRY(sys_dcache_flush, 0, 0x4e0, unimpl_commpage, CALL_INDIRECT), |
120 | 2a252826 | bellard | COMMPAGE_ENTRY(sys_icache_invalidate, 0, 0x520, unimpl_commpage, CALL_INDIRECT), |
121 | 2a252826 | bellard | COMMPAGE_ENTRY(pthread_self, 0, 0x580, unimpl_commpage, CALL_INDIRECT), |
122 | 831b7825 | ths | |
123 | 831b7825 | ths | COMMPAGE_ENTRY(relinquish, 0, 0x5c0, unimpl_commpage, CALL_INDIRECT), |
124 | 831b7825 | ths | |
125 | 831b7825 | ths | #ifdef TARGET_I386
|
126 | 831b7825 | ths | COMMPAGE_ENTRY(bts, 0, 0x5e0, unimpl_commpage, CALL_INDIRECT), |
127 | 831b7825 | ths | COMMPAGE_ENTRY(btc, 0, 0x5f0, unimpl_commpage, CALL_INDIRECT), |
128 | 831b7825 | ths | #endif
|
129 | 831b7825 | ths | |
130 | 831b7825 | ths | COMMPAGE_ENTRY(bzero, 2, 0x600, bzero, CALL_DIRECT), |
131 | 831b7825 | ths | COMMPAGE_ENTRY(bcopy, 3, 0x780, bcopy, CALL_DIRECT), |
132 | 831b7825 | ths | COMMPAGE_ENTRY(memcpy, 3, 0x7a0, memcpy, CALL_DIRECT), |
133 | 831b7825 | ths | |
134 | 831b7825 | ths | #ifdef TARGET_I386
|
135 | 831b7825 | ths | COMMPAGE_ENTRY(old_nanotime, 0, 0xf80, do_nanotime, CALL_INDIRECT), |
136 | 831b7825 | ths | COMMPAGE_ENTRY(memset_pattern, 0, 0xf80, unimpl_commpage, CALL_INDIRECT), |
137 | 831b7825 | ths | COMMPAGE_ENTRY(long_copy, 0, 0x1200, unimpl_commpage, CALL_INDIRECT), |
138 | 831b7825 | ths | |
139 | 831b7825 | ths | COMMPAGE_ENTRY(sysintegrity, 0, 0x1600, unimpl_commpage, CALL_INDIRECT), |
140 | 831b7825 | ths | |
141 | 831b7825 | ths | COMMPAGE_ENTRY(nanotime, 0, 0x1700, do_nanotime, CALL_INDIRECT), |
142 | 831b7825 | ths | #elif TARGET_PPC
|
143 | 831b7825 | ths | COMMPAGE_ENTRY(compare_and_swap32b, 0, 0xf80, unimpl_commpage, CALL_INDIRECT), |
144 | 831b7825 | ths | COMMPAGE_ENTRY(compare_and_swap64b, 0, 0xfc0, unimpl_commpage, CALL_INDIRECT), |
145 | 831b7825 | ths | COMMPAGE_ENTRY(memset_pattern, 0, 0x1000, unimpl_commpage, CALL_INDIRECT), |
146 | 831b7825 | ths | COMMPAGE_ENTRY(bigcopy, 0, 0x1140, unimpl_commpage, CALL_INDIRECT), |
147 | 831b7825 | ths | #endif
|
148 | 831b7825 | ths | }; |
149 | 831b7825 | ths | |
150 | 831b7825 | ths | |
151 | 831b7825 | ths | /********************************************************************
|
152 | 831b7825 | ths | * Commpage backdoor
|
153 | 831b7825 | ths | */
|
154 | 831b7825 | ths | static inline void print_commpage_entry(struct commpage_entry entry) |
155 | 831b7825 | ths | { |
156 | 831b7825 | ths | printf("@0x%x %s\n", entry.offset, entry.name);
|
157 | 831b7825 | ths | } |
158 | 831b7825 | ths | |
159 | 831b7825 | ths | static inline void install_commpage_backdoor_for_entry(struct commpage_entry entry) |
160 | 831b7825 | ths | { |
161 | 831b7825 | ths | #ifdef TARGET_I386
|
162 | 831b7825 | ths | char * commpage = (char*)(COMMPAGE_START+entry.offset); |
163 | 831b7825 | ths | int c = 0; |
164 | 831b7825 | ths | if(entry.options & HAS_PTR)
|
165 | 831b7825 | ths | { |
166 | 831b7825 | ths | commpage[c++] = (COMMPAGE_START+entry.offset+4) & 0xff; |
167 | 831b7825 | ths | commpage[c++] = ((COMMPAGE_START+entry.offset+4) >> 8) & 0xff; |
168 | 831b7825 | ths | commpage[c++] = ((COMMPAGE_START+entry.offset+4) >> 16) & 0xff; |
169 | 831b7825 | ths | commpage[c++] = ((COMMPAGE_START+entry.offset+4) >> 24) & 0xff; |
170 | 831b7825 | ths | } |
171 | 831b7825 | ths | commpage[c++] = 0xcd;
|
172 | 831b7825 | ths | commpage[c++] = 0x79; /* int 0x79 */ |
173 | 831b7825 | ths | commpage[c++] = 0xc3; /* ret */ |
174 | 831b7825 | ths | #else
|
175 | 831b7825 | ths | qerror("can't install the commpage on this arch\n");
|
176 | 831b7825 | ths | #endif
|
177 | 831b7825 | ths | } |
178 | 831b7825 | ths | |
179 | 831b7825 | ths | /********************************************************************
|
180 | 831b7825 | ths | * Commpage initialization
|
181 | 831b7825 | ths | */
|
182 | 831b7825 | ths | void commpage_init(void) |
183 | 831b7825 | ths | { |
184 | e58ffeb3 | malc | #if (defined(__i386__) ^ defined(TARGET_I386)) || (defined(_ARCH_PPC) ^ defined(TARGET_PPC))
|
185 | 831b7825 | ths | int i;
|
186 | 831b7825 | ths | void * commpage = (void *)target_mmap( COMMPAGE_START, COMMPAGE_SIZE, |
187 | 831b7825 | ths | PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_FIXED, -1, 0); |
188 | 831b7825 | ths | if((int)commpage != COMMPAGE_START) |
189 | 831b7825 | ths | qerror("can't allocate the commpage\n");
|
190 | 831b7825 | ths | |
191 | 831b7825 | ths | bzero(commpage, COMMPAGE_SIZE); |
192 | 831b7825 | ths | |
193 | 831b7825 | ths | /* XXX: commpage data not handled */
|
194 | 831b7825 | ths | |
195 | b1503cda | malc | for(i = 0; i < ARRAY_SIZE(commpage_entries); i++) |
196 | 831b7825 | ths | install_commpage_backdoor_for_entry(commpage_entries[i]); |
197 | 831b7825 | ths | #else
|
198 | 831b7825 | ths | /* simply map our pages so they can be executed
|
199 | 831b7825 | ths | XXX: we don't really want to do that since in the ppc on ppc situation we may
|
200 | 831b7825 | ths | not able to run commpages host optimized instructions (like G5's on a G5),
|
201 | 831b7825 | ths | hence this is sometimes a broken fix. */
|
202 | 831b7825 | ths | page_set_flags(COMMPAGE_START, COMMPAGE_START+COMMPAGE_SIZE, PROT_EXEC | PROT_READ | PAGE_VALID); |
203 | 831b7825 | ths | #endif
|
204 | 831b7825 | ths | } |
205 | 831b7825 | ths | |
206 | 831b7825 | ths | /********************************************************************
|
207 | 831b7825 | ths | * Commpage implementation
|
208 | 831b7825 | ths | */
|
209 | 831b7825 | ths | void do_compare_and_swap32(void *cpu_env, int num) |
210 | 831b7825 | ths | { |
211 | 831b7825 | ths | #ifdef TARGET_I386
|
212 | 831b7825 | ths | uint32_t old = ((CPUX86State*)cpu_env)->regs[R_EAX]; |
213 | 831b7825 | ths | uint32_t *value = (uint32_t*)((CPUX86State*)cpu_env)->regs[R_ECX]; |
214 | 831b7825 | ths | DPRINTF("commpage: compare_and_swap32(%x,new,%p)\n", old, value);
|
215 | 831b7825 | ths | |
216 | 831b7825 | ths | if(value && old == tswap32(*value))
|
217 | 831b7825 | ths | { |
218 | 831b7825 | ths | uint32_t new = ((CPUX86State*)cpu_env)->regs[R_EDX]; |
219 | 831b7825 | ths | *value = tswap32(new); |
220 | 831b7825 | ths | /* set zf flag */
|
221 | 831b7825 | ths | ((CPUX86State*)cpu_env)->eflags |= 0x40;
|
222 | 831b7825 | ths | } |
223 | 831b7825 | ths | else
|
224 | 831b7825 | ths | { |
225 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = tswap32(*value); |
226 | 831b7825 | ths | /* unset zf flag */
|
227 | 831b7825 | ths | ((CPUX86State*)cpu_env)->eflags &= ~0x40;
|
228 | 831b7825 | ths | } |
229 | 831b7825 | ths | #else
|
230 | 831b7825 | ths | qerror("do_compare_and_swap32 unimplemented");
|
231 | 831b7825 | ths | #endif
|
232 | 831b7825 | ths | } |
233 | 831b7825 | ths | |
234 | 831b7825 | ths | void do_compare_and_swap64(void *cpu_env, int num) |
235 | 831b7825 | ths | { |
236 | 831b7825 | ths | #ifdef TARGET_I386
|
237 | 831b7825 | ths | /* OSAtomicCompareAndSwap64 is not available on non 64 bits ppc, here is a raw implementation */
|
238 | 831b7825 | ths | uint64_t old, new, swapped_val; |
239 | 831b7825 | ths | uint64_t *value = (uint64_t*)((CPUX86State*)cpu_env)->regs[R_ESI]; |
240 | 831b7825 | ths | old = (uint64_t)((uint64_t)((CPUX86State*)cpu_env)->regs[R_EDX]) << 32 | (uint64_t)((CPUX86State*)cpu_env)->regs[R_EAX];
|
241 | 831b7825 | ths | |
242 | 831b7825 | ths | DPRINTF("commpage: compare_and_swap64(%llx,new,%p)\n", old, value);
|
243 | 831b7825 | ths | swapped_val = tswap64(*value); |
244 | 831b7825 | ths | |
245 | 831b7825 | ths | if(old == swapped_val)
|
246 | 831b7825 | ths | { |
247 | 831b7825 | ths | new = (uint64_t)((uint64_t)((CPUX86State*)cpu_env)->regs[R_ECX]) << 32 | (uint64_t)((CPUX86State*)cpu_env)->regs[R_EBX];
|
248 | 831b7825 | ths | *value = tswap64(new); |
249 | 831b7825 | ths | /* set zf flag */
|
250 | 831b7825 | ths | ((CPUX86State*)cpu_env)->eflags |= 0x40;
|
251 | 831b7825 | ths | } |
252 | 831b7825 | ths | else
|
253 | 831b7825 | ths | { |
254 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = (uint32_t)(swapped_val); |
255 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EDX] = (uint32_t)(swapped_val >> 32);
|
256 | 831b7825 | ths | /* unset zf flag */
|
257 | 831b7825 | ths | ((CPUX86State*)cpu_env)->eflags &= ~0x40;
|
258 | 831b7825 | ths | } |
259 | 831b7825 | ths | #else
|
260 | 831b7825 | ths | qerror("do_compare_and_swap64 unimplemented");
|
261 | 831b7825 | ths | #endif
|
262 | 831b7825 | ths | } |
263 | 831b7825 | ths | |
264 | 831b7825 | ths | void do_add_atomic_word32(void *cpu_env, int num) |
265 | 831b7825 | ths | { |
266 | 831b7825 | ths | #ifdef TARGET_I386
|
267 | 831b7825 | ths | uint32_t amt = ((CPUX86State*)cpu_env)->regs[R_EAX]; |
268 | 831b7825 | ths | uint32_t *value = (uint32_t*)((CPUX86State*)cpu_env)->regs[R_EDX]; |
269 | 831b7825 | ths | uint32_t swapped_value = tswap32(*value); |
270 | 831b7825 | ths | |
271 | 831b7825 | ths | DPRINTF("commpage: add_atomic_word32(%x,%p)\n", amt, value);
|
272 | 831b7825 | ths | |
273 | 831b7825 | ths | /* old value in EAX */
|
274 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = swapped_value; |
275 | 831b7825 | ths | *value = tswap32(swapped_value + amt); |
276 | 831b7825 | ths | #else
|
277 | 831b7825 | ths | qerror("do_add_atomic_word32 unimplemented");
|
278 | 831b7825 | ths | #endif
|
279 | 831b7825 | ths | } |
280 | 831b7825 | ths | |
281 | 831b7825 | ths | void do_cgettimeofday(void *cpu_env, int num, uint32_t arg1) |
282 | 831b7825 | ths | { |
283 | 831b7825 | ths | #ifdef TARGET_I386
|
284 | 831b7825 | ths | extern int __commpage_gettimeofday(struct timeval *); |
285 | 831b7825 | ths | DPRINTF("commpage: gettimeofday(0x%x)\n", arg1);
|
286 | 831b7825 | ths | struct timeval *time = (struct timeval *)arg1; |
287 | 831b7825 | ths | int ret = __commpage_gettimeofday(time);
|
288 | 831b7825 | ths | tswap32s((uint32_t*)&time->tv_sec); |
289 | 831b7825 | ths | tswap32s((uint32_t*)&time->tv_usec); |
290 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = ret; /* Success */
|
291 | 831b7825 | ths | #else
|
292 | 831b7825 | ths | qerror("do_gettimeofday unimplemented");
|
293 | 831b7825 | ths | #endif
|
294 | 831b7825 | ths | } |
295 | 831b7825 | ths | |
296 | 831b7825 | ths | void do_nanotime(void *cpu_env, int num) |
297 | 831b7825 | ths | { |
298 | 831b7825 | ths | #ifdef TARGET_I386
|
299 | 831b7825 | ths | uint64_t t = mach_absolute_time(); |
300 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = (int)(t & 0xffffffff); |
301 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EDX] = (int)((t >> 32) & 0xffffffff); |
302 | 831b7825 | ths | #else
|
303 | 831b7825 | ths | qerror("do_nanotime unimplemented");
|
304 | 831b7825 | ths | #endif
|
305 | 831b7825 | ths | } |
306 | 831b7825 | ths | |
307 | 831b7825 | ths | void unimpl_commpage(void *cpu_env, int num) |
308 | 831b7825 | ths | { |
309 | 2a252826 | bellard | qerror("qemu: commpage function 0x%x not implemented\n", num);
|
310 | 831b7825 | ths | } |
311 | 831b7825 | ths | |
312 | 831b7825 | ths | /********************************************************************
|
313 | 831b7825 | ths | * do_commpage - called by the main cpu loop
|
314 | 831b7825 | ths | */
|
315 | 831b7825 | ths | void
|
316 | 831b7825 | ths | do_commpage(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3, |
317 | 831b7825 | ths | uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, |
318 | 831b7825 | ths | uint32_t arg8) |
319 | 831b7825 | ths | { |
320 | 831b7825 | ths | int i, found = 0; |
321 | 831b7825 | ths | |
322 | 831b7825 | ths | arg1 = tswap32(arg1); |
323 | 831b7825 | ths | arg2 = tswap32(arg2); |
324 | 831b7825 | ths | arg3 = tswap32(arg3); |
325 | 831b7825 | ths | arg4 = tswap32(arg4); |
326 | 831b7825 | ths | arg5 = tswap32(arg5); |
327 | 831b7825 | ths | arg6 = tswap32(arg6); |
328 | 831b7825 | ths | arg7 = tswap32(arg7); |
329 | 831b7825 | ths | arg8 = tswap32(arg8); |
330 | 831b7825 | ths | |
331 | 831b7825 | ths | num = num-COMMPAGE_START-2;
|
332 | 831b7825 | ths | |
333 | b1503cda | malc | for(i = 0; i < ARRAY_SIZE(commpage_entries); i++) { |
334 | 831b7825 | ths | if( num == commpage_code_num(&commpage_entries[i]) )
|
335 | 831b7825 | ths | { |
336 | 831b7825 | ths | DPRINTF("commpage: %s %s\n", commpage_entries[i].name, commpage_is_indirect(&commpage_entries[i]) ? "[indirect]" : "[direct]"); |
337 | 831b7825 | ths | found = 1;
|
338 | 831b7825 | ths | if(commpage_is_indirect(&commpage_entries[i]))
|
339 | 831b7825 | ths | { |
340 | 831b7825 | ths | commpage_indirect_function_t function = (commpage_indirect_function_t)commpage_entries[i].function; |
341 | 831b7825 | ths | function(cpu_env, num, arg1, arg2, arg3, |
342 | 831b7825 | ths | arg4, arg5, arg6, arg7, arg8); |
343 | 831b7825 | ths | } |
344 | 831b7825 | ths | else
|
345 | 831b7825 | ths | { |
346 | 831b7825 | ths | commpage_entries[i].function(arg1, arg2, arg3, |
347 | 831b7825 | ths | arg4, arg5, arg6, arg7, arg8); |
348 | 831b7825 | ths | } |
349 | 831b7825 | ths | break;
|
350 | 831b7825 | ths | } |
351 | 831b7825 | ths | } |
352 | 831b7825 | ths | |
353 | 831b7825 | ths | if(!found)
|
354 | 831b7825 | ths | { |
355 | 831b7825 | ths | gemu_log("qemu: commpage function 0x%x not defined\n", num);
|
356 | 831b7825 | ths | gdb_handlesig (cpu_env, SIGTRAP); |
357 | 831b7825 | ths | exit(-1);
|
358 | 831b7825 | ths | } |
359 | 831b7825 | ths | } |