root / linux-user / qemu.h @ 89344d5a
History | View | Annotate | Download (5.8 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 | 31e31b8a | bellard | unsigned long end_data; |
22 | 31e31b8a | bellard | unsigned long start_brk; |
23 | 31e31b8a | bellard | unsigned long brk; |
24 | 31e31b8a | bellard | unsigned long start_mmap; |
25 | 31e31b8a | bellard | unsigned long mmap; |
26 | 31e31b8a | bellard | unsigned long rss; |
27 | 31e31b8a | bellard | unsigned long start_stack; |
28 | 31e31b8a | bellard | unsigned long arg_start; |
29 | 31e31b8a | bellard | unsigned long arg_end; |
30 | 31e31b8a | bellard | unsigned long env_start; |
31 | 31e31b8a | bellard | unsigned long env_end; |
32 | 31e31b8a | bellard | unsigned long entry; |
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 | 28c4f361 | bellard | #endif
|
66 | b346ff46 | bellard | #ifdef TARGET_I386
|
67 | 851e67a1 | bellard | struct target_vm86plus_struct *target_v86;
|
68 | 851e67a1 | bellard | struct vm86_saved_state vm86_saved_regs;
|
69 | b333af06 | bellard | struct target_vm86plus_struct vm86plus;
|
70 | 631271d7 | bellard | uint32_t v86flags; |
71 | 631271d7 | bellard | uint32_t v86mask; |
72 | b346ff46 | bellard | #endif
|
73 | 851e67a1 | bellard | int used; /* non zero if used */ |
74 | 851e67a1 | bellard | uint8_t stack[0];
|
75 | 851e67a1 | bellard | } __attribute__((aligned(16))) TaskState;
|
76 | 851e67a1 | bellard | |
77 | 851e67a1 | bellard | extern TaskState *first_task_state;
|
78 | 851e67a1 | bellard | |
79 | 32ce6337 | bellard | int elf_exec(const char * filename, char ** argv, char ** envp, |
80 | 01ffc75b | bellard | struct target_pt_regs * regs, struct image_info *infop); |
81 | 31e31b8a | bellard | |
82 | 31e31b8a | bellard | void target_set_brk(char *new_brk); |
83 | 31e31b8a | bellard | void syscall_init(void); |
84 | 6dbad63e | bellard | long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
85 | 31e31b8a | bellard | long arg4, long arg5, long arg6); |
86 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2))); |
87 | b346ff46 | bellard | extern CPUState *global_env;
|
88 | b346ff46 | bellard | void cpu_loop(CPUState *env);
|
89 | 32ce6337 | bellard | void init_paths(const char *prefix); |
90 | 32ce6337 | bellard | const char *path(const char *pathname); |
91 | 6977fbfd | bellard | |
92 | 6977fbfd | bellard | extern int loglevel; |
93 | 631271d7 | bellard | extern FILE *logfile;
|
94 | 631271d7 | bellard | |
95 | b346ff46 | bellard | /* signal.c */
|
96 | b346ff46 | bellard | void process_pending_signals(void *cpu_env); |
97 | b346ff46 | bellard | void signal_init(void); |
98 | b346ff46 | bellard | int queue_signal(int sig, target_siginfo_t *info); |
99 | b346ff46 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); |
100 | b346ff46 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); |
101 | b346ff46 | bellard | long do_sigreturn(CPUState *env);
|
102 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env);
|
103 | b346ff46 | bellard | |
104 | b346ff46 | bellard | #ifdef TARGET_I386
|
105 | 631271d7 | bellard | /* vm86.c */
|
106 | 631271d7 | bellard | void save_v86_state(CPUX86State *env);
|
107 | 447db213 | bellard | void handle_vm86_trap(CPUX86State *env, int trapno); |
108 | 631271d7 | bellard | void handle_vm86_fault(CPUX86State *env);
|
109 | 631271d7 | bellard | int do_vm86(CPUX86State *env, long subfunction, |
110 | 631271d7 | bellard | struct target_vm86plus_struct * target_v86);
|
111 | b346ff46 | bellard | #endif
|
112 | 631271d7 | bellard | |
113 | 54936004 | bellard | /* mmap.c */
|
114 | 54936004 | bellard | int target_mprotect(unsigned long start, unsigned long len, int prot); |
115 | 54936004 | bellard | long target_mmap(unsigned long start, unsigned long len, int prot, |
116 | 54936004 | bellard | int flags, int fd, unsigned long offset); |
117 | 54936004 | bellard | int target_munmap(unsigned long start, unsigned long len); |
118 | 54936004 | bellard | long target_mremap(unsigned long old_addr, unsigned long old_size, |
119 | 54936004 | bellard | unsigned long new_size, unsigned long flags, |
120 | 54936004 | bellard | unsigned long new_addr); |
121 | 54936004 | bellard | int target_msync(unsigned long start, unsigned long len, int flags); |
122 | 54936004 | bellard | |
123 | edf779ff | bellard | /* user access */
|
124 | edf779ff | bellard | |
125 | edf779ff | bellard | #define VERIFY_READ 0 |
126 | edf779ff | bellard | #define VERIFY_WRITE 1 |
127 | edf779ff | bellard | |
128 | edf779ff | bellard | #define access_ok(type,addr,size) (1) |
129 | edf779ff | bellard | |
130 | edf779ff | bellard | #define __put_user(x,ptr)\
|
131 | edf779ff | bellard | ({\ |
132 | edf779ff | bellard | int size = sizeof(*ptr);\ |
133 | edf779ff | bellard | switch(size) {\
|
134 | edf779ff | bellard | case 1:\ |
135 | edf779ff | bellard | stb(ptr, (typeof(*ptr))(x));\ |
136 | edf779ff | bellard | break;\
|
137 | edf779ff | bellard | case 2:\ |
138 | edf779ff | bellard | stw(ptr, (typeof(*ptr))(x));\ |
139 | edf779ff | bellard | break;\
|
140 | edf779ff | bellard | case 4:\ |
141 | edf779ff | bellard | stl(ptr, (typeof(*ptr))(x));\ |
142 | edf779ff | bellard | break;\
|
143 | edf779ff | bellard | case 8:\ |
144 | edf779ff | bellard | stq(ptr, (typeof(*ptr))(x));\ |
145 | edf779ff | bellard | break;\
|
146 | edf779ff | bellard | default:\
|
147 | edf779ff | bellard | abort();\ |
148 | edf779ff | bellard | }\ |
149 | edf779ff | bellard | 0;\
|
150 | edf779ff | bellard | }) |
151 | edf779ff | bellard | |
152 | edf779ff | bellard | #define __get_user(x, ptr) \
|
153 | edf779ff | bellard | ({\ |
154 | edf779ff | bellard | int size = sizeof(*ptr);\ |
155 | edf779ff | bellard | switch(size) {\
|
156 | edf779ff | bellard | case 1:\ |
157 | d69d1fa0 | bellard | x = (typeof(*ptr))ldub((void *)ptr);\
|
158 | edf779ff | bellard | break;\
|
159 | edf779ff | bellard | case 2:\ |
160 | d69d1fa0 | bellard | x = (typeof(*ptr))lduw((void *)ptr);\
|
161 | edf779ff | bellard | break;\
|
162 | edf779ff | bellard | case 4:\ |
163 | d69d1fa0 | bellard | x = (typeof(*ptr))ldl((void *)ptr);\
|
164 | edf779ff | bellard | break;\
|
165 | edf779ff | bellard | case 8:\ |
166 | d69d1fa0 | bellard | x = (typeof(*ptr))ldq((void *)ptr);\
|
167 | edf779ff | bellard | break;\
|
168 | edf779ff | bellard | default:\
|
169 | edf779ff | bellard | abort();\ |
170 | edf779ff | bellard | }\ |
171 | edf779ff | bellard | 0;\
|
172 | edf779ff | bellard | }) |
173 | edf779ff | bellard | |
174 | edf779ff | bellard | static inline unsigned long __copy_to_user(void *dst, const void *src, |
175 | edf779ff | bellard | unsigned long size) |
176 | edf779ff | bellard | { |
177 | edf779ff | bellard | memcpy(dst, src, size); |
178 | edf779ff | bellard | return 0; |
179 | edf779ff | bellard | } |
180 | edf779ff | bellard | |
181 | edf779ff | bellard | static inline unsigned long __copy_from_user(void *dst, const void *src, |
182 | edf779ff | bellard | unsigned long size) |
183 | edf779ff | bellard | { |
184 | edf779ff | bellard | memcpy(dst, src, size); |
185 | edf779ff | bellard | return 0; |
186 | edf779ff | bellard | } |
187 | edf779ff | bellard | |
188 | edf779ff | bellard | static inline unsigned long __clear_user(void *dst, unsigned long size) |
189 | edf779ff | bellard | { |
190 | edf779ff | bellard | memset(dst, 0, size);
|
191 | edf779ff | bellard | return 0; |
192 | edf779ff | bellard | } |
193 | edf779ff | bellard | |
194 | edf779ff | bellard | #define put_user(x,ptr)\
|
195 | edf779ff | bellard | ({\ |
196 | edf779ff | bellard | int __ret;\
|
197 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\ |
198 | edf779ff | bellard | __ret = __put_user(x, ptr);\ |
199 | edf779ff | bellard | else\
|
200 | edf779ff | bellard | __ret = -EFAULT;\ |
201 | edf779ff | bellard | __ret;\ |
202 | edf779ff | bellard | }) |
203 | edf779ff | bellard | |
204 | edf779ff | bellard | #define get_user(x,ptr)\
|
205 | edf779ff | bellard | ({\ |
206 | edf779ff | bellard | int __ret;\
|
207 | edf779ff | bellard | if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\ |
208 | edf779ff | bellard | __ret = __get_user(x, ptr);\ |
209 | edf779ff | bellard | else\
|
210 | edf779ff | bellard | __ret = -EFAULT;\ |
211 | edf779ff | bellard | __ret;\ |
212 | edf779ff | bellard | }) |
213 | edf779ff | bellard | |
214 | edf779ff | bellard | static inline unsigned long copy_to_user(void *dst, const void *src, |
215 | edf779ff | bellard | unsigned long size) |
216 | edf779ff | bellard | { |
217 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, dst, size))
|
218 | edf779ff | bellard | return __copy_to_user(dst, src, size);
|
219 | edf779ff | bellard | else
|
220 | edf779ff | bellard | return size;
|
221 | edf779ff | bellard | } |
222 | edf779ff | bellard | |
223 | edf779ff | bellard | static inline unsigned long copy_from_user(void *dst, const void *src, |
224 | edf779ff | bellard | unsigned long size) |
225 | edf779ff | bellard | { |
226 | edf779ff | bellard | if (access_ok(VERIFY_READ, src, size))
|
227 | edf779ff | bellard | return __copy_from_user(dst, src, size);
|
228 | edf779ff | bellard | else
|
229 | edf779ff | bellard | return size;
|
230 | edf779ff | bellard | } |
231 | edf779ff | bellard | |
232 | edf779ff | bellard | static inline unsigned long clear_user(void *dst, unsigned long size) |
233 | edf779ff | bellard | { |
234 | edf779ff | bellard | if (access_ok(VERIFY_WRITE, dst, size))
|
235 | edf779ff | bellard | return __clear_user(dst, size);
|
236 | edf779ff | bellard | else
|
237 | edf779ff | bellard | return size;
|
238 | edf779ff | bellard | } |
239 | edf779ff | bellard | |
240 | e88de099 | bellard | #endif /* QEMU_H */ |