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