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