10 typedef uint32_t abi_ulong
;
11 typedef int32_t abi_long
;
12 #define TARGET_ABI_BITS 32
14 typedef target_ulong abi_ulong
;
15 typedef target_long abi_long
;
16 #define TARGET_ABI_BITS TARGET_LONG_BITS
20 #include "syscall_defs.h"
22 #include "target_signal.h"
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
40 abi_ulong start_stack
;
42 abi_ulong code_offset
;
43 abi_ulong data_offset
;
49 /* Information about the current linux thread */
50 struct vm86_saved_state
{
51 uint32_t eax
; /* return code */
61 uint16_t cs
, ss
, ds
, es
, fs
, gs
;
67 #include "nwfpe/fpa11.h"
70 /* NOTE: we force a big alignment so that the stack stored after is
72 typedef struct TaskState
{
73 struct TaskState
*next
;
79 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
81 struct vm86_saved_state vm86_saved_regs
;
82 struct target_vm86plus_struct vm86plus
;
89 #if defined(TARGET_ARM) || defined(TARGET_M68K)
90 /* Extra fields for semihosted binaries. */
95 int used
; /* non zero if used */
96 struct image_info
*info
;
98 } __attribute__((aligned(16))) TaskState
;
100 extern TaskState
*first_task_state
;
101 extern const char *qemu_uname_release
;
103 /* ??? See if we can avoid exposing so much of the loader internals. */
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!
109 #define MAX_ARG_PAGES 32
112 * This structure is used to hold the arguments that are
113 * used when loading binaries.
115 struct linux_binprm
{
117 void *page
[MAX_ARG_PAGES
];
124 char * filename
; /* Name of binary */
127 void do_init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
);
128 abi_ulong
loader_build_argptr(int envc
, int argc
, abi_ulong sp
,
129 abi_ulong stringp
, int push_ptr
);
130 int loader_exec(const char * filename
, char ** argv
, char ** envp
,
131 struct target_pt_regs
* regs
, struct image_info
*infop
);
133 int load_elf_binary(struct linux_binprm
* bprm
, struct target_pt_regs
* regs
,
134 struct image_info
* info
);
135 int load_flt_binary(struct linux_binprm
* bprm
, struct target_pt_regs
* regs
,
136 struct image_info
* info
);
137 #ifdef TARGET_HAS_ELFLOAD32
138 int load_elf_binary_multi(struct linux_binprm
*bprm
,
139 struct target_pt_regs
*regs
,
140 struct image_info
*info
);
143 void memcpy_to_target(abi_ulong dest
, const void *src
,
145 void target_set_brk(abi_ulong new_brk
);
146 abi_long
do_brk(abi_ulong new_brk
);
147 void syscall_init(void);
148 abi_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
);
151 void gemu_log(const char *fmt
, ...) __attribute__((format(printf
,1,2)));
152 extern CPUState
*global_env
;
153 void cpu_loop(CPUState
*env
);
154 void init_paths(const char *prefix
);
155 const char *path(const char *pathname
);
158 extern FILE *logfile
;
161 void process_pending_signals(void *cpu_env
);
162 void signal_init(void);
163 int queue_signal(int sig
, target_siginfo_t
*info
);
164 void host_to_target_siginfo(target_siginfo_t
*tinfo
, const siginfo_t
*info
);
165 void target_to_host_siginfo(siginfo_t
*info
, const target_siginfo_t
*tinfo
);
166 long do_sigreturn(CPUState
*env
);
167 long do_rt_sigreturn(CPUState
*env
);
168 int do_sigaltstack(const struct target_sigaltstack
*uss
,
169 struct target_sigaltstack
*uoss
,
174 void save_v86_state(CPUX86State
*env
);
175 void handle_vm86_trap(CPUX86State
*env
, int trapno
);
176 void handle_vm86_fault(CPUX86State
*env
);
177 int do_vm86(CPUX86State
*env
, long subfunction
, abi_ulong v86_addr
);
178 #elif defined(TARGET_SPARC64)
179 void sparc64_set_context(CPUSPARCState
*env
);
180 void sparc64_get_context(CPUSPARCState
*env
);
184 int target_mprotect(abi_ulong start
, abi_ulong len
, int prot
);
185 abi_long
target_mmap(abi_ulong start
, abi_ulong len
, int prot
,
186 int flags
, int fd
, abi_ulong offset
);
187 int target_munmap(abi_ulong start
, abi_ulong len
);
188 abi_long
target_mremap(abi_ulong old_addr
, abi_ulong old_size
,
189 abi_ulong new_size
, unsigned long flags
,
191 int target_msync(abi_ulong start
, abi_ulong len
, int flags
);
195 #define VERIFY_READ 0
196 #define VERIFY_WRITE 1
198 #define access_ok(type,addr,size) (1)
200 /* NOTE get_user and put_user use host addresses. */
201 #define __put_user(x,ptr)\
203 int size = sizeof(*ptr);\
206 *(uint8_t *)(ptr) = (typeof(*ptr))(x);\
209 *(uint16_t *)(ptr) = tswap16((typeof(*ptr))(x));\
212 *(uint32_t *)(ptr) = tswap32((typeof(*ptr))(x));\
215 *(uint64_t *)(ptr) = tswap64((typeof(*ptr))(x));\
223 #define __get_user(x, ptr) \
225 int size = sizeof(*ptr);\
228 x = (typeof(*ptr))*(uint8_t *)(ptr);\
231 x = (typeof(*ptr))tswap16(*(uint16_t *)(ptr));\
234 x = (typeof(*ptr))tswap32(*(uint32_t *)(ptr));\
237 x = (typeof(*ptr))tswap64(*(uint64_t *)(ptr));\
245 #define put_user(x,ptr)\
248 if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\
249 __ret = __put_user(x, ptr);\
255 #define get_user(x,ptr)\
258 if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\
259 __ret = __get_user(x, ptr);\
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. */
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. */
273 static inline void *lock_user(abi_ulong guest_addr
, long len
, int copy
)
279 memcpy(addr
, g2h(guest_addr
), len
);
281 memset(addr
, 0, len
);
284 return g2h(guest_addr
);
288 /* Unlock an area of guest memory. The first LEN bytes must be flushed back
290 static inline void unlock_user(void *host_addr
, abi_ulong guest_addr
,
294 if (host_addr
== g2h(guest_addr
))
297 memcpy(g2h(guest_addr
), host_addr
, len
);
302 /* Return the length of a string in target memory. */
303 static inline int target_strlen(abi_ulong ptr
)
305 return strlen(g2h(ptr
));
308 /* Like lock_user but for null terminated strings. */
309 static inline void *lock_user_string(abi_ulong guest_addr
)
312 len
= target_strlen(guest_addr
) + 1;
313 return lock_user(guest_addr
, len
, 1);
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)
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)
330 #if TARGET_ABI_BITS == 64
331 #define tgetl(addr) ldq(addr)
332 #define tputl(addr, val) stq(addr, val)
334 #define tgetl(addr) ldl(addr)
335 #define tputl(addr, val) stl(addr, val)