1#ifndef GEMU_H
2#define GEMU_H
3
4#include <signal.h>
5#include <string.h>
6
7#include "cpu.h"
8
9#include "thunk.h"
10
11#include "gdbstub.h"
12
13typedef siginfo_t target_siginfo_t;
14#define target_sigaction sigaction
15#ifdef TARGET_I386
16struct target_pt_regs {
17 long ebx;
18 long ecx;
19 long edx;
20 long esi;
21 long edi;
22 long ebp;
23 long eax;
24 int xds;
25 int xes;
26 long orig_eax;
27 long eip;
28 int xcs;
29 long eflags;
30 long esp;
31 int xss;
32};
33struct target_sigcontext {
34 int sc_onstack;
35 int sc_mask;
36 int sc_eax;
37 int sc_ebx;
38 int sc_ecx;
39 int sc_edx;
40 int sc_edi;
41 int sc_esi;
42 int sc_ebp;
43 int sc_esp;
44 int sc_ss;
45 int sc_eflags;
46 int sc_eip;
47 int sc_cs;
48 int sc_ds;
49 int sc_es;
50 int sc_fs;
51 int sc_gs;
52};
53
54#define __USER_CS (0x17)
55#define __USER_DS (0x1F)
56
57#elif defined(TARGET_PPC)
58struct target_pt_regs {
59 unsigned long gpr[32];
60 unsigned long nip;
61 unsigned long msr;
62 unsigned long orig_gpr3;
63 unsigned long ctr;
64 unsigned long link;
65 unsigned long xer;
66 unsigned long ccr;
67 unsigned long mq;
68
69 unsigned long trap;
70 unsigned long dar;
71 unsigned long dsisr;
72 unsigned long result;
73};
74
75struct target_sigcontext {
76 int sc_onstack;
77 int sc_mask;
78 int sc_ir;
79 int sc_psw;
80 int sc_sp;
81 void *sc_regs;
82};
83
84#endif
85
86typedef struct TaskState {
87 struct TaskState *next;
88 int used;
89 uint8_t stack[0];
90} __attribute__((aligned(16))) TaskState;
91
92void syscall_init(void);
93long do_mach_syscall(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3,
94 uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, uint32_t arg8);
95long do_thread_syscall(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3,
96 uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, uint32_t arg8);
97long do_unix_syscall(void *cpu_env, int num);
98int do_sigaction(int sig, const struct sigaction *act,
99 struct sigaction *oact);
100int do_sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss);
101
102void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
103void qerror(const char *fmt, ...);
104
105void write_dt(void *ptr, unsigned long addr, unsigned long limit, int flags);
106
107extern CPUState *global_env;
108void cpu_loop(CPUState *env);
109void init_paths(const char *prefix);
110const char *path(const char *pathname);
111
112#include "qemu-log.h"
113
114
115void commpage_init(void);
116void do_commpage(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3,
117 uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, uint32_t arg8);
118
119
120void process_pending_signals(void *cpu_env);
121void signal_init(void);
122int queue_signal(int sig, target_siginfo_t *info);
123void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
124void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
125long do_sigreturn(CPUState *env, int num);
126
127
128int mach_exec(const char * filename, char ** argv, char ** envp,
129 struct target_pt_regs * regs);
130
131
132int target_mprotect(unsigned long start, unsigned long len, int prot);
133long target_mmap(unsigned long start, unsigned long len, int prot,
134 int flags, int fd, unsigned long offset);
135int target_munmap(unsigned long start, unsigned long len);
136long target_mremap(unsigned long old_addr, unsigned long old_size,
137 unsigned long new_size, unsigned long flags,
138 unsigned long new_addr);
139int target_msync(unsigned long start, unsigned long len, int flags);
140
141
142
143
144#define lock_user(x,y,z) (void*)(x)
145#define unlock_user(x,y,z)
146
147
148#ifdef TARGET_I386
149static inline uint32_t get_int_arg(int *i, CPUX86State *cpu_env)
150{
151 uint32_t *args = (uint32_t*)(cpu_env->regs[R_ESP] + 4 + *i);
152 *i+=4;
153 return tswap32(*args);
154}
155static inline uint64_t get_int64_arg(int *i, CPUX86State *cpu_env)
156{
157 uint64_t *args = (uint64_t*)(cpu_env->regs[R_ESP] + 4 + *i);
158 *i+=8;
159 return tswap64(*args);
160}
161#elif defined(TARGET_PPC)
162static inline uint32_t get_int_arg(int *i, CPUPPCState *cpu_env)
163{
164
165 uint32_t args = (uint32_t)(cpu_env->gpr[3+(*i & 0xff)/4]);
166 *i+=4;
167 return tswap32(args);
168}
169static inline uint64_t get_int64_arg(int *i, CPUPPCState *cpu_env)
170{
171
172 uint64_t args = (uint64_t)(cpu_env->fpr[1+(*i >> 8)/8]);
173 *i+=(8 << 8) + 8;
174 return tswap64(args);
175}
176#endif
177
178#endif
179