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