10 typedef uint32_t abi_ulong
;
11 typedef int32_t abi_long
;
12 #define TARGET_ABI_FMT_lx "%08x"
13 #define TARGET_ABI_FMT_ld "%d"
14 #define TARGET_ABI_FMT_lu "%u"
15 #define TARGET_ABI_BITS 32
17 typedef target_ulong abi_ulong
;
18 typedef target_long abi_long
;
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
22 #define TARGET_ABI_BITS TARGET_LONG_BITS
26 #include "syscall_defs.h"
28 #include "target_signal.h"
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
46 abi_ulong start_stack
;
48 abi_ulong code_offset
;
49 abi_ulong data_offset
;
55 /* Information about the current linux thread */
56 struct vm86_saved_state
{
57 uint32_t eax
; /* return code */
67 uint16_t cs
, ss
, ds
, es
, fs
, gs
;
73 #include "nwfpe/fpa11.h"
76 /* NOTE: we force a big alignment so that the stack stored after is
78 typedef struct TaskState
{
79 struct TaskState
*next
;
85 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
87 struct vm86_saved_state vm86_saved_regs
;
88 struct target_vm86plus_struct vm86plus
;
95 #if defined(TARGET_ARM) || defined(TARGET_M68K)
96 /* Extra fields for semihosted binaries. */
101 int used
; /* non zero if used */
102 struct image_info
*info
;
104 } __attribute__((aligned(16))) TaskState
;
106 extern TaskState
*first_task_state
;
107 extern const char *qemu_uname_release
;
109 /* ??? See if we can avoid exposing so much of the loader internals. */
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!
115 #define MAX_ARG_PAGES 32
118 * This structure is used to hold the arguments that are
119 * used when loading binaries.
121 struct linux_binprm
{
123 void *page
[MAX_ARG_PAGES
];
130 char * filename
; /* Name of binary */
133 void do_init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
);
134 abi_ulong
loader_build_argptr(int envc
, int argc
, abi_ulong sp
,
135 abi_ulong stringp
, int push_ptr
);
136 int loader_exec(const char * filename
, char ** argv
, char ** envp
,
137 struct target_pt_regs
* regs
, struct image_info
*infop
);
139 int load_elf_binary(struct linux_binprm
* bprm
, struct target_pt_regs
* regs
,
140 struct image_info
* info
);
141 int load_flt_binary(struct linux_binprm
* bprm
, struct target_pt_regs
* regs
,
142 struct image_info
* info
);
143 #ifdef TARGET_HAS_ELFLOAD32
144 int load_elf_binary_multi(struct linux_binprm
*bprm
,
145 struct target_pt_regs
*regs
,
146 struct image_info
*info
);
149 void memcpy_to_target(abi_ulong dest
, const void *src
,
151 void target_set_brk(abi_ulong new_brk
);
152 abi_long
do_brk(abi_ulong new_brk
);
153 void syscall_init(void);
154 abi_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
);
157 void gemu_log(const char *fmt
, ...) __attribute__((format(printf
,1,2)));
158 extern CPUState
*global_env
;
159 void cpu_loop(CPUState
*env
);
160 void init_paths(const char *prefix
);
161 const char *path(const char *pathname
);
162 char *target_strerror(int err
);
165 extern FILE *logfile
;
168 void print_syscall(int num
,
169 target_long arg1
, target_long arg2
, target_long arg3
,
170 target_long arg4
, target_long arg5
, target_long arg6
);
171 void print_syscall_ret(int num
, target_long arg1
);
172 extern int do_strace
;
175 void process_pending_signals(void *cpu_env
);
176 void signal_init(void);
177 int queue_signal(int sig
, target_siginfo_t
*info
);
178 void host_to_target_siginfo(target_siginfo_t
*tinfo
, const siginfo_t
*info
);
179 void target_to_host_siginfo(siginfo_t
*info
, const target_siginfo_t
*tinfo
);
180 long do_sigreturn(CPUState
*env
);
181 long do_rt_sigreturn(CPUState
*env
);
182 int do_sigaltstack(const struct target_sigaltstack
*uss
,
183 struct target_sigaltstack
*uoss
,
188 void save_v86_state(CPUX86State
*env
);
189 void handle_vm86_trap(CPUX86State
*env
, int trapno
);
190 void handle_vm86_fault(CPUX86State
*env
);
191 int do_vm86(CPUX86State
*env
, long subfunction
, abi_ulong v86_addr
);
192 #elif defined(TARGET_SPARC64)
193 void sparc64_set_context(CPUSPARCState
*env
);
194 void sparc64_get_context(CPUSPARCState
*env
);
198 int target_mprotect(abi_ulong start
, abi_ulong len
, int prot
);
199 abi_long
target_mmap(abi_ulong start
, abi_ulong len
, int prot
,
200 int flags
, int fd
, abi_ulong offset
);
201 int target_munmap(abi_ulong start
, abi_ulong len
);
202 abi_long
target_mremap(abi_ulong old_addr
, abi_ulong old_size
,
203 abi_ulong new_size
, unsigned long flags
,
205 int target_msync(abi_ulong start
, abi_ulong len
, int flags
);
209 #define VERIFY_READ 0
210 #define VERIFY_WRITE 1
212 #define access_ok(type,addr,size) \
213 (page_check_range((target_ulong)addr,size,(type==VERIFY_READ)?PAGE_READ:PAGE_WRITE)==0)
215 /* NOTE __get_user and __put_user use host pointers and don't check access. */
216 #define __put_user(x, hptr)\
218 int size = sizeof(*hptr);\
221 *(uint8_t *)(hptr) = (typeof(*hptr))(x);\
224 *(uint16_t *)(hptr) = tswap16((typeof(*hptr))(x));\
227 *(uint32_t *)(hptr) = tswap32((typeof(*hptr))(x));\
230 *(uint64_t *)(hptr) = tswap64((typeof(*hptr))(x));\
238 #define __get_user(x, hptr) \
240 int size = sizeof(*hptr);\
243 x = (typeof(*hptr))*(uint8_t *)(hptr);\
246 x = (typeof(*hptr))tswap16(*(uint16_t *)(hptr));\
249 x = (typeof(*hptr))tswap32(*(uint32_t *)(hptr));\
252 x = (typeof(*hptr))tswap64(*(uint64_t *)(hptr));\
260 #define put_user(x,ptr)\
263 if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\
264 __ret = __put_user(x, ptr);\
270 #define get_user(x,ptr)\
273 if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\
274 __ret = __get_user(x, ptr);\
280 /* Functions for accessing guest memory. The tget and tput functions
281 read/write single values, byteswapping as neccessary. The lock_user
282 gets a pointer to a contiguous area of guest memory, but does not perform
283 and byteswapping. lock_user may return either a pointer to the guest
284 memory, or a temporary buffer. */
286 /* Lock an area of guest memory into the host. If copy is true then the
287 host area will have the same contents as the guest. */
288 static inline void *lock_user(abi_ulong guest_addr
, long len
, int copy
)
294 memcpy(addr
, g2h(guest_addr
), len
);
296 memset(addr
, 0, len
);
299 return g2h(guest_addr
);
303 /* Unlock an area of guest memory. The first LEN bytes must be flushed back
305 static inline void unlock_user(void *host_addr
, abi_ulong guest_addr
,
309 if (host_addr
== g2h(guest_addr
))
312 memcpy(g2h(guest_addr
), host_addr
, len
);
317 /* Return the length of a string in target memory. */
318 static inline int target_strlen(abi_ulong ptr
)
320 return strlen(g2h(ptr
));
323 /* Like lock_user but for null terminated strings. */
324 static inline void *lock_user_string(abi_ulong guest_addr
)
327 len
= target_strlen(guest_addr
) + 1;
328 return lock_user(guest_addr
, len
, 1);
331 /* Helper macros for locking/ulocking a target struct. */
332 #define lock_user_struct(host_ptr, guest_addr, copy) \
333 host_ptr = lock_user(guest_addr, sizeof(*host_ptr), copy)
334 #define unlock_user_struct(host_ptr, guest_addr, copy) \
335 unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0)
337 #define tget8(addr) ldub(addr)
338 #define tput8(addr, val) stb(addr, val)
339 #define tget16(addr) lduw(addr)
340 #define tput16(addr, val) stw(addr, val)
341 #define tget32(addr) ldl(addr)
342 #define tput32(addr, val) stl(addr, val)
343 #define tget64(addr) ldq(addr)
344 #define tput64(addr, val) stq(addr, val)
345 #if TARGET_ABI_BITS == 64
346 #define tgetl(addr) ldq(addr)
347 #define tputl(addr, val) stq(addr, val)
349 #define tgetl(addr) ldl(addr)
350 #define tputl(addr, val) stl(addr, val)