add missing FORCE_RET (Paul Brook)
[qemu/qemu_0_9_1_stable.git] / linux-user / qemu.h
blobc176a58aa46fe52ade5ad6523062446da1db7d86
1 #ifndef QEMU_H
2 #define QEMU_H
4 #include "thunk.h"
6 #include <signal.h>
7 #include <string.h>
8 #include "syscall_defs.h"
10 #include "cpu.h"
11 #include "syscall.h"
13 /* This struct is used to hold certain information about the image.
14 * Basically, it replicates in user space what would be certain
15 * task_struct fields in the kernel
17 struct image_info {
18 unsigned long start_code;
19 unsigned long end_code;
20 unsigned long end_data;
21 unsigned long start_brk;
22 unsigned long brk;
23 unsigned long start_mmap;
24 unsigned long mmap;
25 unsigned long rss;
26 unsigned long start_stack;
27 unsigned long arg_start;
28 unsigned long arg_end;
29 unsigned long env_start;
30 unsigned long env_end;
31 unsigned long entry;
32 int personality;
35 #ifdef TARGET_I386
36 /* Information about the current linux thread */
37 struct vm86_saved_state {
38 uint32_t eax; /* return code */
39 uint32_t ebx;
40 uint32_t ecx;
41 uint32_t edx;
42 uint32_t esi;
43 uint32_t edi;
44 uint32_t ebp;
45 uint32_t esp;
46 uint32_t eflags;
47 uint32_t eip;
48 uint16_t cs, ss, ds, es, fs, gs;
50 #endif
52 #ifdef TARGET_ARM
53 /* FPU emulator */
54 #include "nwfpe/fpa11.h"
55 #endif
57 /* NOTE: we force a big alignment so that the stack stored after is
58 aligned too */
59 typedef struct TaskState {
60 struct TaskState *next;
61 #ifdef TARGET_ARM
62 /* FPA state */
63 FPA11 fpa;
64 #endif
65 #ifdef TARGET_I386
66 struct target_vm86plus_struct *target_v86;
67 struct vm86_saved_state vm86_saved_regs;
68 struct target_vm86plus_struct vm86plus;
69 uint32_t v86flags;
70 uint32_t v86mask;
71 #endif
72 int used; /* non zero if used */
73 uint8_t stack[0];
74 } __attribute__((aligned(16))) TaskState;
76 extern TaskState *first_task_state;
78 int elf_exec(const char * filename, char ** argv, char ** envp,
79 struct target_pt_regs * regs, struct image_info *infop);
81 void target_set_brk(char *new_brk);
82 void syscall_init(void);
83 long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
84 long arg4, long arg5, long arg6);
85 void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
86 extern CPUState *global_env;
87 void cpu_loop(CPUState *env);
88 void init_paths(const char *prefix);
89 const char *path(const char *pathname);
91 extern int loglevel;
92 extern FILE *logfile;
94 /* signal.c */
95 void process_pending_signals(void *cpu_env);
96 void signal_init(void);
97 int queue_signal(int sig, target_siginfo_t *info);
98 void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
99 void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
100 long do_sigreturn(CPUState *env);
101 long do_rt_sigreturn(CPUState *env);
103 #ifdef TARGET_I386
104 /* vm86.c */
105 void save_v86_state(CPUX86State *env);
106 void handle_vm86_trap(CPUX86State *env, int trapno);
107 void handle_vm86_fault(CPUX86State *env);
108 int do_vm86(CPUX86State *env, long subfunction,
109 struct target_vm86plus_struct * target_v86);
110 #endif
112 /* mmap.c */
113 int target_mprotect(unsigned long start, unsigned long len, int prot);
114 long target_mmap(unsigned long start, unsigned long len, int prot,
115 int flags, int fd, unsigned long offset);
116 int target_munmap(unsigned long start, unsigned long len);
117 long target_mremap(unsigned long old_addr, unsigned long old_size,
118 unsigned long new_size, unsigned long flags,
119 unsigned long new_addr);
120 int target_msync(unsigned long start, unsigned long len, int flags);
122 /* user access */
124 #define VERIFY_READ 0
125 #define VERIFY_WRITE 1
127 #define access_ok(type,addr,size) (1)
129 #define __put_user(x,ptr)\
131 int size = sizeof(*ptr);\
132 switch(size) {\
133 case 1:\
134 stb(ptr, (typeof(*ptr))(x));\
135 break;\
136 case 2:\
137 stw(ptr, (typeof(*ptr))(x));\
138 break;\
139 case 4:\
140 stl(ptr, (typeof(*ptr))(x));\
141 break;\
142 case 8:\
143 stq(ptr, (typeof(*ptr))(x));\
144 break;\
145 default:\
146 abort();\
151 #define __get_user(x, ptr) \
153 int size = sizeof(*ptr);\
154 switch(size) {\
155 case 1:\
156 x = (typeof(*ptr))ldub((void *)ptr);\
157 break;\
158 case 2:\
159 x = (typeof(*ptr))lduw((void *)ptr);\
160 break;\
161 case 4:\
162 x = (typeof(*ptr))ldl((void *)ptr);\
163 break;\
164 case 8:\
165 x = (typeof(*ptr))ldq((void *)ptr);\
166 break;\
167 default:\
168 abort();\
173 static inline unsigned long __copy_to_user(void *dst, const void *src,
174 unsigned long size)
176 memcpy(dst, src, size);
177 return 0;
180 static inline unsigned long __copy_from_user(void *dst, const void *src,
181 unsigned long size)
183 memcpy(dst, src, size);
184 return 0;
187 static inline unsigned long __clear_user(void *dst, unsigned long size)
189 memset(dst, 0, size);
190 return 0;
193 #define put_user(x,ptr)\
195 int __ret;\
196 if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\
197 __ret = __put_user(x, ptr);\
198 else\
199 __ret = -EFAULT;\
200 __ret;\
203 #define get_user(x,ptr)\
205 int __ret;\
206 if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\
207 __ret = __get_user(x, ptr);\
208 else\
209 __ret = -EFAULT;\
210 __ret;\
213 static inline unsigned long copy_to_user(void *dst, const void *src,
214 unsigned long size)
216 if (access_ok(VERIFY_WRITE, dst, size))
217 return __copy_to_user(dst, src, size);
218 else
219 return size;
222 static inline unsigned long copy_from_user(void *dst, const void *src,
223 unsigned long size)
225 if (access_ok(VERIFY_READ, src, size))
226 return __copy_from_user(dst, src, size);
227 else
228 return size;
231 static inline unsigned long clear_user(void *dst, unsigned long size)
233 if (access_ok(VERIFY_WRITE, dst, size))
234 return __clear_user(dst, size);
235 else
236 return size;
239 #endif /* QEMU_H */