root / linux-user / qemu.h @ 3d177870
History | View | Annotate | Download (9 kB)
1 | e88de099 | bellard | #ifndef QEMU_H
|
---|---|---|---|
2 | e88de099 | bellard | #define QEMU_H
|
3 | 31e31b8a | bellard | |
4 | 31e31b8a | bellard | #include "thunk.h" |
5 | 31e31b8a | bellard | |
6 | 9de5e440 | bellard | #include <signal.h> |
7 | edf779ff | bellard | #include <string.h> |
8 | 9de5e440 | bellard | #include "syscall_defs.h" |
9 | 31e31b8a | bellard | |
10 | 6180a181 | bellard | #include "cpu.h" |
11 | 6180a181 | bellard | #include "syscall.h" |
12 | a04e134a | ths | #include "target_signal.h" |
13 | 1fddef4b | bellard | #include "gdbstub.h" |
14 | 66fb9763 | bellard | |
15 | 31e31b8a | bellard | /* This struct is used to hold certain information about the image.
|
16 | 31e31b8a | bellard | * Basically, it replicates in user space what would be certain
|
17 | 31e31b8a | bellard | * task_struct fields in the kernel
|
18 | 31e31b8a | bellard | */
|
19 | 31e31b8a | bellard | struct image_info {
|
20 | 3d177870 | j_mayer | target_ulong load_addr; |
21 | 3d177870 | j_mayer | target_ulong start_code; |
22 | 3d177870 | j_mayer | target_ulong end_code; |
23 | 3d177870 | j_mayer | target_ulong start_data; |
24 | 3d177870 | j_mayer | target_ulong end_data; |
25 | 3d177870 | j_mayer | target_ulong start_brk; |
26 | 3d177870 | j_mayer | target_ulong brk; |
27 | 3d177870 | j_mayer | target_ulong start_mmap; |
28 | 3d177870 | j_mayer | target_ulong mmap; |
29 | 3d177870 | j_mayer | target_ulong rss; |
30 | 3d177870 | j_mayer | target_ulong start_stack; |
31 | 3d177870 | j_mayer | target_ulong entry; |
32 | 978efd6a | pbrook | target_ulong code_offset; |
33 | 978efd6a | pbrook | target_ulong data_offset; |
34 | 38d0662a | pbrook | char **host_argv;
|
35 | 31e31b8a | bellard | int personality;
|
36 | 31e31b8a | bellard | }; |
37 | 31e31b8a | bellard | |
38 | b346ff46 | bellard | #ifdef TARGET_I386
|
39 | 851e67a1 | bellard | /* Information about the current linux thread */
|
40 | 851e67a1 | bellard | struct vm86_saved_state {
|
41 | 851e67a1 | bellard | uint32_t eax; /* return code */
|
42 | 851e67a1 | bellard | uint32_t ebx; |
43 | 851e67a1 | bellard | uint32_t ecx; |
44 | 851e67a1 | bellard | uint32_t edx; |
45 | 851e67a1 | bellard | uint32_t esi; |
46 | 851e67a1 | bellard | uint32_t edi; |
47 | 851e67a1 | bellard | uint32_t ebp; |
48 | 851e67a1 | bellard | uint32_t esp; |
49 | 851e67a1 | bellard | uint32_t eflags; |
50 | 851e67a1 | bellard | uint32_t eip; |
51 | 851e67a1 | bellard | uint16_t cs, ss, ds, es, fs, gs; |
52 | 851e67a1 | bellard | }; |
53 | b346ff46 | bellard | #endif
|
54 | 851e67a1 | bellard | |
55 | 28c4f361 | bellard | #ifdef TARGET_ARM
|
56 | 28c4f361 | bellard | /* FPU emulator */
|
57 | 28c4f361 | bellard | #include "nwfpe/fpa11.h" |
58 | 28c4f361 | bellard | #endif
|
59 | 28c4f361 | bellard | |
60 | 851e67a1 | bellard | /* NOTE: we force a big alignment so that the stack stored after is
|
61 | 851e67a1 | bellard | aligned too */
|
62 | 851e67a1 | bellard | typedef struct TaskState { |
63 | 851e67a1 | bellard | struct TaskState *next;
|
64 | 28c4f361 | bellard | #ifdef TARGET_ARM
|
65 | 28c4f361 | bellard | /* FPA state */
|
66 | 28c4f361 | bellard | FPA11 fpa; |
67 | a4f81979 | bellard | int swi_errno;
|
68 | 28c4f361 | bellard | #endif
|
69 | 84409ddb | j_mayer | #if defined(TARGET_I386) && !defined(TARGET_X86_64)
|
70 | 53a5960a | pbrook | target_ulong target_v86; |
71 | 851e67a1 | bellard | struct vm86_saved_state vm86_saved_regs;
|
72 | b333af06 | bellard | struct target_vm86plus_struct vm86plus;
|
73 | 631271d7 | bellard | uint32_t v86flags; |
74 | 631271d7 | bellard | uint32_t v86mask; |
75 | b346ff46 | bellard | #endif
|
76 | e6e5906b | pbrook | #ifdef TARGET_M68K
|
77 | e6e5906b | pbrook | int sim_syscalls;
|
78 | e6e5906b | pbrook | #endif
|
79 | a87295e8 | pbrook | #if defined(TARGET_ARM) || defined(TARGET_M68K)
|
80 | a87295e8 | pbrook | /* Extra fields for semihosted binaries. */
|
81 | a87295e8 | pbrook | uint32_t stack_base; |
82 | a87295e8 | pbrook | uint32_t heap_base; |
83 | a87295e8 | pbrook | uint32_t heap_limit; |
84 | a87295e8 | pbrook | #endif
|
85 | 851e67a1 | bellard | int used; /* non zero if used */ |
86 | 978efd6a | pbrook | struct image_info *info;
|
87 | 851e67a1 | bellard | uint8_t stack[0];
|
88 | 851e67a1 | bellard | } __attribute__((aligned(16))) TaskState;
|
89 | 851e67a1 | bellard | |
90 | 851e67a1 | bellard | extern TaskState *first_task_state;
|
91 | c5937220 | pbrook | extern const char *qemu_uname_release; |
92 | 851e67a1 | bellard | |
93 | e5fe0c52 | pbrook | /* ??? See if we can avoid exposing so much of the loader internals. */
|
94 | e5fe0c52 | pbrook | /*
|
95 | e5fe0c52 | pbrook | * MAX_ARG_PAGES defines the number of pages allocated for arguments
|
96 | e5fe0c52 | pbrook | * and envelope for the new program. 32 should suffice, this gives
|
97 | e5fe0c52 | pbrook | * a maximum env+arg of 128kB w/4KB pages!
|
98 | e5fe0c52 | pbrook | */
|
99 | e5fe0c52 | pbrook | #define MAX_ARG_PAGES 32 |
100 | e5fe0c52 | pbrook | |
101 | e5fe0c52 | pbrook | /*
|
102 | 5fafdf24 | ths | * This structure is used to hold the arguments that are
|
103 | e5fe0c52 | pbrook | * used when loading binaries.
|
104 | e5fe0c52 | pbrook | */
|
105 | e5fe0c52 | pbrook | struct linux_binprm {
|
106 | e5fe0c52 | pbrook | char buf[128]; |
107 | e5fe0c52 | pbrook | void *page[MAX_ARG_PAGES];
|
108 | 3d177870 | j_mayer | target_ulong p; |
109 | e5fe0c52 | pbrook | int fd;
|
110 | e5fe0c52 | pbrook | int e_uid, e_gid;
|
111 | e5fe0c52 | pbrook | int argc, envc;
|
112 | e5fe0c52 | pbrook | char **argv;
|
113 | e5fe0c52 | pbrook | char **envp;
|
114 | e5fe0c52 | pbrook | char * filename; /* Name of binary */ |
115 | e5fe0c52 | pbrook | }; |
116 | e5fe0c52 | pbrook | |
117 | e5fe0c52 | pbrook | void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); |
118 | e5fe0c52 | pbrook | target_ulong loader_build_argptr(int envc, int argc, target_ulong sp, |
119 | e5fe0c52 | pbrook | target_ulong stringp, int push_ptr);
|
120 | 5fafdf24 | ths | int loader_exec(const char * filename, char ** argv, char ** envp, |
121 | 01ffc75b | bellard | struct target_pt_regs * regs, struct image_info *infop); |
122 | 31e31b8a | bellard | |
123 | e5fe0c52 | pbrook | int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, |
124 | e5fe0c52 | pbrook | struct image_info * info);
|
125 | e5fe0c52 | pbrook | int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, |
126 | e5fe0c52 | pbrook | struct image_info * info);
|
127 | e5fe0c52 | pbrook | |
128 | e5fe0c52 | pbrook | void memcpy_to_target(target_ulong dest, const void *src, |
129 | e5fe0c52 | pbrook | unsigned long len); |
130 | 53a5960a | pbrook | void target_set_brk(target_ulong new_brk);
|
131 | 32407103 | j_mayer | target_long do_brk(target_ulong new_brk); |
132 | 31e31b8a | bellard | void syscall_init(void); |
133 | 32407103 | j_mayer | target_long do_syscall(void *cpu_env, int num, target_long arg1, |
134 | 32407103 | j_mayer | target_long arg2, target_long arg3, target_long arg4, |
135 | 32407103 | j_mayer | target_long arg5, target_long arg6); |
136 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2))); |
137 | b346ff46 | bellard | extern CPUState *global_env;
|
138 | b346ff46 | bellard | void cpu_loop(CPUState *env);
|
139 | 32ce6337 | bellard | void init_paths(const char *prefix); |
140 | 32ce6337 | bellard | const char *path(const char *pathname); |
141 | 6977fbfd | bellard | |
142 | 6977fbfd | bellard | extern int loglevel; |
143 | 631271d7 | bellard | extern FILE *logfile;
|
144 | 631271d7 | bellard | |
145 | b346ff46 | bellard | /* signal.c */
|
146 | b346ff46 | bellard | void process_pending_signals(void *cpu_env); |
147 | b346ff46 | bellard | void signal_init(void); |
148 | b346ff46 | bellard | int queue_signal(int sig, target_siginfo_t *info); |
149 | b346ff46 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); |
150 | b346ff46 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); |
151 | b346ff46 | bellard | long do_sigreturn(CPUState *env);
|
152 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env);
|
153 | a04e134a | ths | int do_sigaltstack(const struct target_sigaltstack *uss, |
154 | a04e134a | ths | struct target_sigaltstack *uoss,
|
155 | a04e134a | ths | target_ulong sp); |
156 | b346ff46 | bellard | |
157 | b346ff46 | bellard | #ifdef TARGET_I386
|
158 | 631271d7 | bellard | /* vm86.c */
|
159 | 631271d7 | bellard | void save_v86_state(CPUX86State *env);
|
160 | 447db213 | bellard | void handle_vm86_trap(CPUX86State *env, int trapno); |
161 | 631271d7 | bellard | void handle_vm86_fault(CPUX86State *env);
|
162 | 53a5960a | pbrook | int do_vm86(CPUX86State *env, long subfunction, target_ulong v86_addr); |
163 | 5bfb56b2 | blueswir1 | #elif defined(TARGET_SPARC64)
|
164 | 5bfb56b2 | blueswir1 | void sparc64_set_context(CPUSPARCState *env);
|
165 | 5bfb56b2 | blueswir1 | void sparc64_get_context(CPUSPARCState *env);
|
166 | b346ff46 | bellard | #endif
|
167 | 631271d7 | bellard | |
168 | 54936004 | bellard | /* mmap.c */
|
169 | 53a5960a | pbrook | int target_mprotect(target_ulong start, target_ulong len, int prot); |
170 | a5b85f79 | ths | target_long target_mmap(target_ulong start, target_ulong len, int prot,
|
171 | 53a5960a | pbrook | int flags, int fd, target_ulong offset); |
172 | 53a5960a | pbrook | int target_munmap(target_ulong start, target_ulong len);
|
173 | a5b85f79 | ths | target_long target_mremap(target_ulong old_addr, target_ulong old_size, |
174 | 53a5960a | pbrook | target_ulong new_size, unsigned long flags, |
175 | 53a5960a | pbrook | target_ulong new_addr); |
176 | 53a5960a | pbrook | int target_msync(target_ulong start, target_ulong len, int flags); |
177 | 54936004 | bellard | |
178 | edf779ff | bellard | /* user access */
|
179 | edf779ff | bellard | |
180 | edf779ff | bellard | #define VERIFY_READ 0 |
181 | edf779ff | bellard | #define VERIFY_WRITE 1 |
182 | edf779ff | bellard | |
183 | edf779ff | bellard | #define access_ok(type,addr,size) (1) |
184 | edf779ff | bellard | |
185 | 53a5960a | pbrook | /* NOTE get_user and put_user use host addresses. */
|
186 | edf779ff | bellard | #define __put_user(x,ptr)\
|
187 | edf779ff | bellard | ({\ |
188 | edf779ff | bellard | int size = sizeof(*ptr);\ |
189 | edf779ff | bellard | switch(size) {\
|
190 | edf779ff | bellard | case 1:\ |
191 | 53a5960a | pbrook | *(uint8_t *)(ptr) = (typeof(*ptr))(x);\ |
192 | edf779ff | bellard | break;\
|
193 | edf779ff | bellard | case 2:\ |
194 | 53a5960a | pbrook | *(uint16_t *)(ptr) = tswap16((typeof(*ptr))(x));\ |
195 | edf779ff | bellard | break;\
|
196 | edf779ff | bellard | case 4:\ |
197 | 53a5960a | pbrook | *(uint32_t *)(ptr) = tswap32((typeof(*ptr))(x));\ |
198 | edf779ff | bellard | break;\
|
199 | edf779ff | bellard | case 8:\ |
200 | 53a5960a | pbrook | *(uint64_t *)(ptr) = tswap64((typeof(*ptr))(x));\ |
201 | edf779ff | bellard | break;\
|
202 | edf779ff | bellard | default:\
|
203 | edf779ff | bellard | abort();\ |
204 | edf779ff | bellard | }\ |
205 | edf779ff | bellard | 0;\
|
206 | edf779ff | bellard | }) |
207 | edf779ff | bellard | |
208 | edf779ff | bellard | #define __get_user(x, ptr) \
|
209 | edf779ff | bellard | ({\ |
210 | edf779ff | bellard | int size = sizeof(*ptr);\ |
211 | edf779ff | bellard | switch(size) {\
|
212 | edf779ff | bellard | case 1:\ |
213 | 53a5960a | pbrook | x = (typeof(*ptr))*(uint8_t *)(ptr);\ |
214 | edf779ff | bellard | break;\
|
215 | edf779ff | bellard | case 2:\ |
216 | 53a5960a | pbrook | x = (typeof(*ptr))tswap16(*(uint16_t *)(ptr));\ |
217 | edf779ff | bellard | break;\
|
218 | edf779ff | bellard | case 4:\ |
219 | 53a5960a | pbrook | x = (typeof(*ptr))tswap32(*(uint32_t *)(ptr));\ |
220 | edf779ff | bellard | break;\
|
221 | edf779ff | bellard | case 8:\ |
222 | 53a5960a | pbrook | x = (typeof(*ptr))tswap64(*(uint64_t *)(ptr));\ |
223 | edf779ff | bellard | break;\
|
224 | edf779ff | bellard | default:\
|
225 | edf779ff | bellard | abort();\ |
226 | edf779ff | bellard | }\ |
227 | edf779ff | bellard | 0;\
|
228 | edf779ff | bellard | }) |
229 | edf779ff | bellard | |
230 | edf779ff | bellard | #define put_user(x,ptr)\
|
231 | edf779ff | bellard | ({\ |
232 | edf779ff | bellard | int __ret;\
|
233 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\ |
234 | edf779ff | bellard | __ret = __put_user(x, ptr);\ |
235 | edf779ff | bellard | else\
|
236 | edf779ff | bellard | __ret = -EFAULT;\ |
237 | edf779ff | bellard | __ret;\ |
238 | edf779ff | bellard | }) |
239 | edf779ff | bellard | |
240 | edf779ff | bellard | #define get_user(x,ptr)\
|
241 | edf779ff | bellard | ({\ |
242 | edf779ff | bellard | int __ret;\
|
243 | edf779ff | bellard | if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\ |
244 | edf779ff | bellard | __ret = __get_user(x, ptr);\ |
245 | edf779ff | bellard | else\
|
246 | edf779ff | bellard | __ret = -EFAULT;\ |
247 | edf779ff | bellard | __ret;\ |
248 | edf779ff | bellard | }) |
249 | edf779ff | bellard | |
250 | 53a5960a | pbrook | /* Functions for accessing guest memory. The tget and tput functions
|
251 | 53a5960a | pbrook | read/write single values, byteswapping as neccessary. The lock_user
|
252 | 53a5960a | pbrook | gets a pointer to a contiguous area of guest memory, but does not perform
|
253 | 53a5960a | pbrook | and byteswapping. lock_user may return either a pointer to the guest
|
254 | 53a5960a | pbrook | memory, or a temporary buffer. */
|
255 | 53a5960a | pbrook | |
256 | 53a5960a | pbrook | /* Lock an area of guest memory into the host. If copy is true then the
|
257 | 53a5960a | pbrook | host area will have the same contents as the guest. */
|
258 | 53a5960a | pbrook | static inline void *lock_user(target_ulong guest_addr, long len, int copy) |
259 | edf779ff | bellard | { |
260 | 53a5960a | pbrook | #ifdef DEBUG_REMAP
|
261 | 53a5960a | pbrook | void *addr;
|
262 | 53a5960a | pbrook | addr = malloc(len); |
263 | 53a5960a | pbrook | if (copy)
|
264 | 53a5960a | pbrook | memcpy(addr, g2h(guest_addr), len); |
265 | edf779ff | bellard | else
|
266 | 53a5960a | pbrook | memset(addr, 0, len);
|
267 | 53a5960a | pbrook | return addr;
|
268 | 53a5960a | pbrook | #else
|
269 | 53a5960a | pbrook | return g2h(guest_addr);
|
270 | 53a5960a | pbrook | #endif
|
271 | edf779ff | bellard | } |
272 | edf779ff | bellard | |
273 | 53a5960a | pbrook | /* Unlock an area of guest memory. The first LEN bytes must be flushed back
|
274 | 53a5960a | pbrook | to guest memory. */
|
275 | 53a5960a | pbrook | static inline void unlock_user(void *host_addr, target_ulong guest_addr, |
276 | 53a5960a | pbrook | long len)
|
277 | edf779ff | bellard | { |
278 | 53a5960a | pbrook | #ifdef DEBUG_REMAP
|
279 | 53a5960a | pbrook | if (host_addr == g2h(guest_addr))
|
280 | 53a5960a | pbrook | return;
|
281 | 53a5960a | pbrook | if (len > 0) |
282 | 53a5960a | pbrook | memcpy(g2h(guest_addr), host_addr, len); |
283 | 53a5960a | pbrook | free(host_addr); |
284 | 53a5960a | pbrook | #endif
|
285 | edf779ff | bellard | } |
286 | edf779ff | bellard | |
287 | 53a5960a | pbrook | /* Return the length of a string in target memory. */
|
288 | 53a5960a | pbrook | static inline int target_strlen(target_ulong ptr) |
289 | edf779ff | bellard | { |
290 | 53a5960a | pbrook | return strlen(g2h(ptr));
|
291 | 53a5960a | pbrook | } |
292 | 53a5960a | pbrook | |
293 | 53a5960a | pbrook | /* Like lock_user but for null terminated strings. */
|
294 | 53a5960a | pbrook | static inline void *lock_user_string(target_ulong guest_addr) |
295 | 53a5960a | pbrook | { |
296 | 53a5960a | pbrook | long len;
|
297 | 53a5960a | pbrook | len = target_strlen(guest_addr) + 1;
|
298 | 53a5960a | pbrook | return lock_user(guest_addr, len, 1); |
299 | edf779ff | bellard | } |
300 | edf779ff | bellard | |
301 | 53a5960a | pbrook | /* Helper macros for locking/ulocking a target struct. */
|
302 | 53a5960a | pbrook | #define lock_user_struct(host_ptr, guest_addr, copy) \
|
303 | 53a5960a | pbrook | host_ptr = lock_user(guest_addr, sizeof(*host_ptr), copy)
|
304 | 53a5960a | pbrook | #define unlock_user_struct(host_ptr, guest_addr, copy) \
|
305 | 53a5960a | pbrook | unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) |
306 | 53a5960a | pbrook | |
307 | 53a5960a | pbrook | #define tget8(addr) ldub(addr)
|
308 | 53a5960a | pbrook | #define tput8(addr, val) stb(addr, val)
|
309 | 53a5960a | pbrook | #define tget16(addr) lduw(addr)
|
310 | 53a5960a | pbrook | #define tput16(addr, val) stw(addr, val)
|
311 | 53a5960a | pbrook | #define tget32(addr) ldl(addr)
|
312 | 53a5960a | pbrook | #define tput32(addr, val) stl(addr, val)
|
313 | 53a5960a | pbrook | #define tget64(addr) ldq(addr)
|
314 | 53a5960a | pbrook | #define tput64(addr, val) stq(addr, val)
|
315 | 53a5960a | pbrook | #if TARGET_LONG_BITS == 64 |
316 | 53a5960a | pbrook | #define tgetl(addr) ldq(addr)
|
317 | 53a5960a | pbrook | #define tputl(addr, val) stq(addr, val)
|
318 | 53a5960a | pbrook | #else
|
319 | 53a5960a | pbrook | #define tgetl(addr) ldl(addr)
|
320 | 53a5960a | pbrook | #define tputl(addr, val) stl(addr, val)
|
321 | 53a5960a | pbrook | #endif
|
322 | 53a5960a | pbrook | |
323 | e88de099 | bellard | #endif /* QEMU_H */ |