2005-02-07 15:35:39 +03:00
|
|
|
#ifndef QEMU_H
|
|
|
|
#define QEMU_H
|
2003-02-19 01:55:36 +03:00
|
|
|
|
|
|
|
#include "thunk.h"
|
|
|
|
|
2003-03-23 19:49:39 +03:00
|
|
|
#include <signal.h>
|
2004-02-22 16:40:13 +03:00
|
|
|
#include <string.h>
|
2003-03-23 19:49:39 +03:00
|
|
|
#include "syscall_defs.h"
|
2003-02-19 01:55:36 +03:00
|
|
|
|
2003-10-01 01:04:53 +04:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "syscall.h"
|
2005-04-17 23:16:13 +04:00
|
|
|
#include "gdbstub.h"
|
2003-03-23 04:06:05 +03:00
|
|
|
|
2003-02-19 01:55:36 +03:00
|
|
|
/* This struct is used to hold certain information about the image.
|
|
|
|
* Basically, it replicates in user space what would be certain
|
|
|
|
* task_struct fields in the kernel
|
|
|
|
*/
|
|
|
|
struct image_info {
|
|
|
|
unsigned long start_code;
|
|
|
|
unsigned long end_code;
|
|
|
|
unsigned long end_data;
|
|
|
|
unsigned long start_brk;
|
|
|
|
unsigned long brk;
|
|
|
|
unsigned long start_mmap;
|
|
|
|
unsigned long mmap;
|
|
|
|
unsigned long rss;
|
|
|
|
unsigned long start_stack;
|
|
|
|
unsigned long arg_start;
|
|
|
|
unsigned long arg_end;
|
|
|
|
unsigned long env_start;
|
|
|
|
unsigned long env_end;
|
|
|
|
unsigned long entry;
|
|
|
|
int personality;
|
|
|
|
};
|
|
|
|
|
2003-06-16 00:05:50 +04:00
|
|
|
#ifdef TARGET_I386
|
2003-03-29 19:53:14 +03:00
|
|
|
/* Information about the current linux thread */
|
|
|
|
struct vm86_saved_state {
|
|
|
|
uint32_t eax; /* return code */
|
|
|
|
uint32_t ebx;
|
|
|
|
uint32_t ecx;
|
|
|
|
uint32_t edx;
|
|
|
|
uint32_t esi;
|
|
|
|
uint32_t edi;
|
|
|
|
uint32_t ebp;
|
|
|
|
uint32_t esp;
|
|
|
|
uint32_t eflags;
|
|
|
|
uint32_t eip;
|
|
|
|
uint16_t cs, ss, ds, es, fs, gs;
|
|
|
|
};
|
2003-06-16 00:05:50 +04:00
|
|
|
#endif
|
2003-03-29 19:53:14 +03:00
|
|
|
|
2004-02-17 00:47:43 +03:00
|
|
|
#ifdef TARGET_ARM
|
|
|
|
/* FPU emulator */
|
|
|
|
#include "nwfpe/fpa11.h"
|
|
|
|
#endif
|
|
|
|
|
2003-03-29 19:53:14 +03:00
|
|
|
/* NOTE: we force a big alignment so that the stack stored after is
|
|
|
|
aligned too */
|
|
|
|
typedef struct TaskState {
|
|
|
|
struct TaskState *next;
|
2004-02-17 00:47:43 +03:00
|
|
|
#ifdef TARGET_ARM
|
|
|
|
/* FPA state */
|
|
|
|
FPA11 fpa;
|
2005-04-23 22:25:41 +04:00
|
|
|
/* Extra fields for semihosted binaries. */
|
|
|
|
uint32_t stack_base;
|
|
|
|
uint32_t heap_base;
|
|
|
|
uint32_t heap_limit;
|
|
|
|
int swi_errno;
|
2004-02-17 00:47:43 +03:00
|
|
|
#endif
|
2003-06-16 00:05:50 +04:00
|
|
|
#ifdef TARGET_I386
|
2003-03-29 19:53:14 +03:00
|
|
|
struct target_vm86plus_struct *target_v86;
|
|
|
|
struct vm86_saved_state vm86_saved_regs;
|
2003-05-15 01:48:51 +04:00
|
|
|
struct target_vm86plus_struct vm86plus;
|
2003-05-10 17:14:52 +04:00
|
|
|
uint32_t v86flags;
|
|
|
|
uint32_t v86mask;
|
2003-06-16 00:05:50 +04:00
|
|
|
#endif
|
2003-03-29 19:53:14 +03:00
|
|
|
int used; /* non zero if used */
|
|
|
|
uint8_t stack[0];
|
|
|
|
} __attribute__((aligned(16))) TaskState;
|
|
|
|
|
|
|
|
extern TaskState *first_task_state;
|
|
|
|
|
2003-04-11 04:16:16 +04:00
|
|
|
int elf_exec(const char * filename, char ** argv, char ** envp,
|
2003-02-19 02:00:51 +03:00
|
|
|
struct target_pt_regs * regs, struct image_info *infop);
|
2003-02-19 01:55:36 +03:00
|
|
|
|
|
|
|
void target_set_brk(char *new_brk);
|
2005-04-23 22:25:41 +04:00
|
|
|
long do_brk(char *new_brk);
|
2003-02-19 01:55:36 +03:00
|
|
|
void syscall_init(void);
|
2003-03-16 21:05:05 +03:00
|
|
|
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
2003-02-19 01:55:36 +03:00
|
|
|
long arg4, long arg5, long arg6);
|
|
|
|
void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
|
2003-06-16 00:05:50 +04:00
|
|
|
extern CPUState *global_env;
|
|
|
|
void cpu_loop(CPUState *env);
|
2003-04-11 04:16:16 +04:00
|
|
|
void init_paths(const char *prefix);
|
|
|
|
const char *path(const char *pathname);
|
2003-04-30 00:39:23 +04:00
|
|
|
|
|
|
|
extern int loglevel;
|
2003-05-10 17:14:52 +04:00
|
|
|
extern FILE *logfile;
|
|
|
|
|
2003-06-16 00:05:50 +04:00
|
|
|
/* signal.c */
|
|
|
|
void process_pending_signals(void *cpu_env);
|
|
|
|
void signal_init(void);
|
|
|
|
int queue_signal(int sig, target_siginfo_t *info);
|
|
|
|
void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
|
|
|
|
void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
|
|
|
|
long do_sigreturn(CPUState *env);
|
|
|
|
long do_rt_sigreturn(CPUState *env);
|
|
|
|
|
|
|
|
#ifdef TARGET_I386
|
2003-05-10 17:14:52 +04:00
|
|
|
/* vm86.c */
|
|
|
|
void save_v86_state(CPUX86State *env);
|
2003-05-10 19:10:36 +04:00
|
|
|
void handle_vm86_trap(CPUX86State *env, int trapno);
|
2003-05-10 17:14:52 +04:00
|
|
|
void handle_vm86_fault(CPUX86State *env);
|
|
|
|
int do_vm86(CPUX86State *env, long subfunction,
|
|
|
|
struct target_vm86plus_struct * target_v86);
|
2003-06-16 00:05:50 +04:00
|
|
|
#endif
|
2003-05-10 17:14:52 +04:00
|
|
|
|
2003-05-13 04:25:15 +04:00
|
|
|
/* mmap.c */
|
|
|
|
int target_mprotect(unsigned long start, unsigned long len, int prot);
|
|
|
|
long target_mmap(unsigned long start, unsigned long len, int prot,
|
|
|
|
int flags, int fd, unsigned long offset);
|
|
|
|
int target_munmap(unsigned long start, unsigned long len);
|
|
|
|
long target_mremap(unsigned long old_addr, unsigned long old_size,
|
|
|
|
unsigned long new_size, unsigned long flags,
|
|
|
|
unsigned long new_addr);
|
|
|
|
int target_msync(unsigned long start, unsigned long len, int flags);
|
|
|
|
|
2004-02-22 16:40:13 +03:00
|
|
|
/* user access */
|
|
|
|
|
|
|
|
#define VERIFY_READ 0
|
|
|
|
#define VERIFY_WRITE 1
|
|
|
|
|
|
|
|
#define access_ok(type,addr,size) (1)
|
|
|
|
|
|
|
|
#define __put_user(x,ptr)\
|
|
|
|
({\
|
|
|
|
int size = sizeof(*ptr);\
|
|
|
|
switch(size) {\
|
|
|
|
case 1:\
|
|
|
|
stb(ptr, (typeof(*ptr))(x));\
|
|
|
|
break;\
|
|
|
|
case 2:\
|
|
|
|
stw(ptr, (typeof(*ptr))(x));\
|
|
|
|
break;\
|
|
|
|
case 4:\
|
|
|
|
stl(ptr, (typeof(*ptr))(x));\
|
|
|
|
break;\
|
|
|
|
case 8:\
|
|
|
|
stq(ptr, (typeof(*ptr))(x));\
|
|
|
|
break;\
|
|
|
|
default:\
|
|
|
|
abort();\
|
|
|
|
}\
|
|
|
|
0;\
|
|
|
|
})
|
|
|
|
|
|
|
|
#define __get_user(x, ptr) \
|
|
|
|
({\
|
|
|
|
int size = sizeof(*ptr);\
|
|
|
|
switch(size) {\
|
|
|
|
case 1:\
|
2004-06-19 20:57:17 +04:00
|
|
|
x = (typeof(*ptr))ldub((void *)ptr);\
|
2004-02-22 16:40:13 +03:00
|
|
|
break;\
|
|
|
|
case 2:\
|
2004-06-19 20:57:17 +04:00
|
|
|
x = (typeof(*ptr))lduw((void *)ptr);\
|
2004-02-22 16:40:13 +03:00
|
|
|
break;\
|
|
|
|
case 4:\
|
2004-06-19 20:57:17 +04:00
|
|
|
x = (typeof(*ptr))ldl((void *)ptr);\
|
2004-02-22 16:40:13 +03:00
|
|
|
break;\
|
|
|
|
case 8:\
|
2004-06-19 20:57:17 +04:00
|
|
|
x = (typeof(*ptr))ldq((void *)ptr);\
|
2004-02-22 16:40:13 +03:00
|
|
|
break;\
|
|
|
|
default:\
|
|
|
|
abort();\
|
|
|
|
}\
|
|
|
|
0;\
|
|
|
|
})
|
|
|
|
|
|
|
|
static inline unsigned long __copy_to_user(void *dst, const void *src,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long __copy_from_user(void *dst, const void *src,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long __clear_user(void *dst, unsigned long size)
|
|
|
|
{
|
|
|
|
memset(dst, 0, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define put_user(x,ptr)\
|
|
|
|
({\
|
|
|
|
int __ret;\
|
|
|
|
if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\
|
|
|
|
__ret = __put_user(x, ptr);\
|
|
|
|
else\
|
|
|
|
__ret = -EFAULT;\
|
|
|
|
__ret;\
|
|
|
|
})
|
|
|
|
|
|
|
|
#define get_user(x,ptr)\
|
|
|
|
({\
|
|
|
|
int __ret;\
|
|
|
|
if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\
|
|
|
|
__ret = __get_user(x, ptr);\
|
|
|
|
else\
|
|
|
|
__ret = -EFAULT;\
|
|
|
|
__ret;\
|
|
|
|
})
|
|
|
|
|
|
|
|
static inline unsigned long copy_to_user(void *dst, const void *src,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
if (access_ok(VERIFY_WRITE, dst, size))
|
|
|
|
return __copy_to_user(dst, src, size);
|
|
|
|
else
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long copy_from_user(void *dst, const void *src,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
if (access_ok(VERIFY_READ, src, size))
|
|
|
|
return __copy_from_user(dst, src, size);
|
|
|
|
else
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long clear_user(void *dst, unsigned long size)
|
|
|
|
{
|
|
|
|
if (access_ok(VERIFY_WRITE, dst, size))
|
|
|
|
return __clear_user(dst, size);
|
|
|
|
else
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2005-02-07 15:35:39 +03:00
|
|
|
#endif /* QEMU_H */
|