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