root / linux-user / qemu.h @ 97eb5b14
History | View | Annotate | Download (5.8 kB)
1 | 31e31b8a | bellard | #ifndef GEMU_H
|
---|---|---|---|
2 | 31e31b8a | bellard | #define GEMU_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 | 66fb9763 | bellard | |
13 | 31e31b8a | bellard | /* This struct is used to hold certain information about the image.
|
14 | 31e31b8a | bellard | * Basically, it replicates in user space what would be certain
|
15 | 31e31b8a | bellard | * task_struct fields in the kernel
|
16 | 31e31b8a | bellard | */
|
17 | 31e31b8a | bellard | struct image_info {
|
18 | 31e31b8a | bellard | unsigned long start_code; |
19 | 31e31b8a | bellard | unsigned long end_code; |
20 | 31e31b8a | bellard | unsigned long end_data; |
21 | 31e31b8a | bellard | unsigned long start_brk; |
22 | 31e31b8a | bellard | unsigned long brk; |
23 | 31e31b8a | bellard | unsigned long start_mmap; |
24 | 31e31b8a | bellard | unsigned long mmap; |
25 | 31e31b8a | bellard | unsigned long rss; |
26 | 31e31b8a | bellard | unsigned long start_stack; |
27 | 31e31b8a | bellard | unsigned long arg_start; |
28 | 31e31b8a | bellard | unsigned long arg_end; |
29 | 31e31b8a | bellard | unsigned long env_start; |
30 | 31e31b8a | bellard | unsigned long env_end; |
31 | 31e31b8a | bellard | unsigned long entry; |
32 | 31e31b8a | bellard | int personality;
|
33 | 31e31b8a | bellard | }; |
34 | 31e31b8a | bellard | |
35 | b346ff46 | bellard | #ifdef TARGET_I386
|
36 | 851e67a1 | bellard | /* Information about the current linux thread */
|
37 | 851e67a1 | bellard | struct vm86_saved_state {
|
38 | 851e67a1 | bellard | uint32_t eax; /* return code */
|
39 | 851e67a1 | bellard | uint32_t ebx; |
40 | 851e67a1 | bellard | uint32_t ecx; |
41 | 851e67a1 | bellard | uint32_t edx; |
42 | 851e67a1 | bellard | uint32_t esi; |
43 | 851e67a1 | bellard | uint32_t edi; |
44 | 851e67a1 | bellard | uint32_t ebp; |
45 | 851e67a1 | bellard | uint32_t esp; |
46 | 851e67a1 | bellard | uint32_t eflags; |
47 | 851e67a1 | bellard | uint32_t eip; |
48 | 851e67a1 | bellard | uint16_t cs, ss, ds, es, fs, gs; |
49 | 851e67a1 | bellard | }; |
50 | b346ff46 | bellard | #endif
|
51 | 851e67a1 | bellard | |
52 | 28c4f361 | bellard | #ifdef TARGET_ARM
|
53 | 28c4f361 | bellard | /* FPU emulator */
|
54 | 28c4f361 | bellard | #include "nwfpe/fpa11.h" |
55 | 28c4f361 | bellard | #undef put_user
|
56 | 28c4f361 | bellard | #undef get_user
|
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 | 28c4f361 | bellard | #endif
|
67 | b346ff46 | bellard | #ifdef TARGET_I386
|
68 | 851e67a1 | bellard | struct target_vm86plus_struct *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 | 851e67a1 | bellard | int used; /* non zero if used */ |
75 | 851e67a1 | bellard | uint8_t stack[0];
|
76 | 851e67a1 | bellard | } __attribute__((aligned(16))) TaskState;
|
77 | 851e67a1 | bellard | |
78 | 851e67a1 | bellard | extern TaskState *first_task_state;
|
79 | 851e67a1 | bellard | |
80 | 32ce6337 | bellard | int elf_exec(const char * filename, char ** argv, char ** envp, |
81 | 01ffc75b | bellard | struct target_pt_regs * regs, struct image_info *infop); |
82 | 31e31b8a | bellard | |
83 | 31e31b8a | bellard | void target_set_brk(char *new_brk); |
84 | 31e31b8a | bellard | void syscall_init(void); |
85 | 6dbad63e | bellard | long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
86 | 31e31b8a | bellard | long arg4, long arg5, long arg6); |
87 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2))); |
88 | b346ff46 | bellard | extern CPUState *global_env;
|
89 | b346ff46 | bellard | void cpu_loop(CPUState *env);
|
90 | 32ce6337 | bellard | void init_paths(const char *prefix); |
91 | 32ce6337 | bellard | const char *path(const char *pathname); |
92 | 6977fbfd | bellard | |
93 | 6977fbfd | bellard | extern int loglevel; |
94 | 631271d7 | bellard | extern FILE *logfile;
|
95 | 631271d7 | bellard | |
96 | b346ff46 | bellard | /* signal.c */
|
97 | b346ff46 | bellard | void process_pending_signals(void *cpu_env); |
98 | b346ff46 | bellard | void signal_init(void); |
99 | b346ff46 | bellard | int queue_signal(int sig, target_siginfo_t *info); |
100 | b346ff46 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); |
101 | b346ff46 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); |
102 | b346ff46 | bellard | long do_sigreturn(CPUState *env);
|
103 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env);
|
104 | b346ff46 | bellard | |
105 | b346ff46 | bellard | #ifdef TARGET_I386
|
106 | 631271d7 | bellard | /* vm86.c */
|
107 | 631271d7 | bellard | void save_v86_state(CPUX86State *env);
|
108 | 447db213 | bellard | void handle_vm86_trap(CPUX86State *env, int trapno); |
109 | 631271d7 | bellard | void handle_vm86_fault(CPUX86State *env);
|
110 | 631271d7 | bellard | int do_vm86(CPUX86State *env, long subfunction, |
111 | 631271d7 | bellard | struct target_vm86plus_struct * target_v86);
|
112 | b346ff46 | bellard | #endif
|
113 | 631271d7 | bellard | |
114 | 54936004 | bellard | /* mmap.c */
|
115 | 54936004 | bellard | int target_mprotect(unsigned long start, unsigned long len, int prot); |
116 | 54936004 | bellard | long target_mmap(unsigned long start, unsigned long len, int prot, |
117 | 54936004 | bellard | int flags, int fd, unsigned long offset); |
118 | 54936004 | bellard | int target_munmap(unsigned long start, unsigned long len); |
119 | 54936004 | bellard | long target_mremap(unsigned long old_addr, unsigned long old_size, |
120 | 54936004 | bellard | unsigned long new_size, unsigned long flags, |
121 | 54936004 | bellard | unsigned long new_addr); |
122 | 54936004 | bellard | int target_msync(unsigned long start, unsigned long len, int flags); |
123 | 54936004 | bellard | |
124 | edf779ff | bellard | /* user access */
|
125 | edf779ff | bellard | |
126 | edf779ff | bellard | #define VERIFY_READ 0 |
127 | edf779ff | bellard | #define VERIFY_WRITE 1 |
128 | edf779ff | bellard | |
129 | edf779ff | bellard | #define access_ok(type,addr,size) (1) |
130 | edf779ff | bellard | |
131 | edf779ff | bellard | #define __put_user(x,ptr)\
|
132 | edf779ff | bellard | ({\ |
133 | edf779ff | bellard | int size = sizeof(*ptr);\ |
134 | edf779ff | bellard | switch(size) {\
|
135 | edf779ff | bellard | case 1:\ |
136 | edf779ff | bellard | stb(ptr, (typeof(*ptr))(x));\ |
137 | edf779ff | bellard | break;\
|
138 | edf779ff | bellard | case 2:\ |
139 | edf779ff | bellard | stw(ptr, (typeof(*ptr))(x));\ |
140 | edf779ff | bellard | break;\
|
141 | edf779ff | bellard | case 4:\ |
142 | edf779ff | bellard | stl(ptr, (typeof(*ptr))(x));\ |
143 | edf779ff | bellard | break;\
|
144 | edf779ff | bellard | case 8:\ |
145 | edf779ff | bellard | stq(ptr, (typeof(*ptr))(x));\ |
146 | edf779ff | bellard | break;\
|
147 | edf779ff | bellard | default:\
|
148 | edf779ff | bellard | abort();\ |
149 | edf779ff | bellard | }\ |
150 | edf779ff | bellard | 0;\
|
151 | edf779ff | bellard | }) |
152 | edf779ff | bellard | |
153 | edf779ff | bellard | #define __get_user(x, ptr) \
|
154 | edf779ff | bellard | ({\ |
155 | edf779ff | bellard | int size = sizeof(*ptr);\ |
156 | edf779ff | bellard | switch(size) {\
|
157 | edf779ff | bellard | case 1:\ |
158 | edf779ff | bellard | x = (typeof(*ptr))ldub(ptr);\ |
159 | edf779ff | bellard | break;\
|
160 | edf779ff | bellard | case 2:\ |
161 | edf779ff | bellard | x = (typeof(*ptr))lduw(ptr);\ |
162 | edf779ff | bellard | break;\
|
163 | edf779ff | bellard | case 4:\ |
164 | edf779ff | bellard | x = (typeof(*ptr))ldl(ptr);\ |
165 | edf779ff | bellard | break;\
|
166 | edf779ff | bellard | case 8:\ |
167 | edf779ff | bellard | x = (typeof(*ptr))ldq(ptr);\ |
168 | edf779ff | bellard | break;\
|
169 | edf779ff | bellard | default:\
|
170 | edf779ff | bellard | abort();\ |
171 | edf779ff | bellard | }\ |
172 | edf779ff | bellard | 0;\
|
173 | edf779ff | bellard | }) |
174 | edf779ff | bellard | |
175 | edf779ff | bellard | static inline unsigned long __copy_to_user(void *dst, const void *src, |
176 | edf779ff | bellard | unsigned long size) |
177 | edf779ff | bellard | { |
178 | edf779ff | bellard | memcpy(dst, src, size); |
179 | edf779ff | bellard | return 0; |
180 | edf779ff | bellard | } |
181 | edf779ff | bellard | |
182 | edf779ff | bellard | static inline unsigned long __copy_from_user(void *dst, const void *src, |
183 | edf779ff | bellard | unsigned long size) |
184 | edf779ff | bellard | { |
185 | edf779ff | bellard | memcpy(dst, src, size); |
186 | edf779ff | bellard | return 0; |
187 | edf779ff | bellard | } |
188 | edf779ff | bellard | |
189 | edf779ff | bellard | static inline unsigned long __clear_user(void *dst, unsigned long size) |
190 | edf779ff | bellard | { |
191 | edf779ff | bellard | memset(dst, 0, size);
|
192 | edf779ff | bellard | return 0; |
193 | edf779ff | bellard | } |
194 | edf779ff | bellard | |
195 | edf779ff | bellard | #define put_user(x,ptr)\
|
196 | edf779ff | bellard | ({\ |
197 | edf779ff | bellard | int __ret;\
|
198 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\ |
199 | edf779ff | bellard | __ret = __put_user(x, ptr);\ |
200 | edf779ff | bellard | else\
|
201 | edf779ff | bellard | __ret = -EFAULT;\ |
202 | edf779ff | bellard | __ret;\ |
203 | edf779ff | bellard | }) |
204 | edf779ff | bellard | |
205 | edf779ff | bellard | #define get_user(x,ptr)\
|
206 | edf779ff | bellard | ({\ |
207 | edf779ff | bellard | int __ret;\
|
208 | edf779ff | bellard | if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\ |
209 | edf779ff | bellard | __ret = __get_user(x, ptr);\ |
210 | edf779ff | bellard | else\
|
211 | edf779ff | bellard | __ret = -EFAULT;\ |
212 | edf779ff | bellard | __ret;\ |
213 | edf779ff | bellard | }) |
214 | edf779ff | bellard | |
215 | edf779ff | bellard | static inline unsigned long copy_to_user(void *dst, const void *src, |
216 | edf779ff | bellard | unsigned long size) |
217 | edf779ff | bellard | { |
218 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, dst, size))
|
219 | edf779ff | bellard | return __copy_to_user(dst, src, size);
|
220 | edf779ff | bellard | else
|
221 | edf779ff | bellard | return size;
|
222 | edf779ff | bellard | } |
223 | edf779ff | bellard | |
224 | edf779ff | bellard | static inline unsigned long copy_from_user(void *dst, const void *src, |
225 | edf779ff | bellard | unsigned long size) |
226 | edf779ff | bellard | { |
227 | edf779ff | bellard | if (access_ok(VERIFY_READ, src, size))
|
228 | edf779ff | bellard | return __copy_from_user(dst, src, size);
|
229 | edf779ff | bellard | else
|
230 | edf779ff | bellard | return size;
|
231 | edf779ff | bellard | } |
232 | edf779ff | bellard | |
233 | edf779ff | bellard | static inline unsigned long clear_user(void *dst, unsigned long size) |
234 | edf779ff | bellard | { |
235 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, dst, size))
|
236 | edf779ff | bellard | return __clear_user(dst, size);
|
237 | edf779ff | bellard | else
|
238 | edf779ff | bellard | return size;
|
239 | edf779ff | bellard | } |
240 | edf779ff | bellard | |
241 | 31e31b8a | bellard | #endif |