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