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