Skip to content

Commit

Permalink
cpu: Move opaque field from CPU_COMMON to CPUState
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Färber <[email protected]>
  • Loading branch information
afaerber committed Mar 13, 2014
1 parent 2710342 commit 0429a97
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bsd-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ int main(int argc, char **argv)
memset(ts, 0, sizeof(TaskState));
init_task_state(ts);
ts->info = info;
env->opaque = ts;
cpu->opaque = ts;

#if defined(TARGET_I386)
cpu_x86_set_cpl(env, 3);
Expand Down
3 changes: 1 addition & 2 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
}
#ifdef CONFIG_USER_ONLY
else if (strncmp(p, "Offsets", 7) == 0) {
CPUArchState *env = s->c_cpu->env_ptr;
TaskState *ts = env->opaque;
TaskState *ts = s->c_cpu->opaque;

snprintf(buf, sizeof(buf),
"Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx
Expand Down
3 changes: 0 additions & 3 deletions include/exec/cpu-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,5 @@ typedef struct CPUWatchpoint {
\
QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \
CPUWatchpoint *watchpoint_hit; \
\
/* user data */ \
void *opaque; \

#endif
3 changes: 3 additions & 0 deletions include/qom/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct kvm_run;
* @gdb_num_regs: Number of total registers accessible to GDB.
* @gdb_num_g_regs: Number of registers in GDB 'g' packets.
* @next_cpu: Next CPU sharing TB cache.
* @opaque: User data.
* @mem_io_pc: Host Program Counter at which the memory was accessed.
* @mem_io_vaddr: Target virtual address at which the memory was accessed.
* @kvm_fd: vCPU file descriptor for KVM.
Expand Down Expand Up @@ -230,6 +231,8 @@ struct CPUState {
int gdb_num_g_regs;
QTAILQ_ENTRY(CPUState) node;

void *opaque;

/* In order to avoid passing too many arguments to the MMIO helpers,
* we store some rarely used information in the CPU context.
*/
Expand Down
10 changes: 6 additions & 4 deletions linux-user/elfload.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,8 @@ static int write_note(struct memelfnote *men, int fd)

static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env)
{
TaskState *ts = (TaskState *)env->opaque;
CPUState *cpu = ENV_GET_CPU((CPUArchState *)env);
TaskState *ts = (TaskState *)cpu->opaque;
struct elf_thread_status *ets;

ets = g_malloc0(sizeof (*ets));
Expand Down Expand Up @@ -2650,8 +2651,8 @@ static int fill_note_info(struct elf_note_info *info,
long signr, const CPUArchState *env)
{
#define NUMNOTES 3
CPUState *cpu = NULL;
TaskState *ts = (TaskState *)env->opaque;
CPUState *cpu = ENV_GET_CPU((CPUArchState *)env);
TaskState *ts = (TaskState *)cpu->opaque;
int i;

info->notes = g_malloc0(NUMNOTES * sizeof (struct memelfnote));
Expand Down Expand Up @@ -2775,7 +2776,8 @@ static int write_note_info(struct elf_note_info *info, int fd)
*/
static int elf_core_dump(int signr, const CPUArchState *env)
{
const TaskState *ts = (const TaskState *)env->opaque;
const CPUState *cpu = ENV_GET_CPU((CPUArchState *)env);
const TaskState *ts = (const TaskState *)cpu->opaque;
struct vm_area_struct *vma = NULL;
char corefile[PATH_MAX];
struct elf_note_info info;
Expand Down
3 changes: 1 addition & 2 deletions linux-user/linuxload.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
abi_ulong stringp, int push_ptr)
{
CPUArchState *env = thread_cpu->env_ptr;
TaskState *ts = (TaskState *)env->opaque;
TaskState *ts = (TaskState *)thread_cpu->opaque;
int n = sizeof(abi_ulong);
abi_ulong envp;
abi_ulong argv;
Expand Down
4 changes: 3 additions & 1 deletion linux-user/m68k/target_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static inline void cpu_clone_regs(CPUM68KState *env, target_ulong newsp)

static inline void cpu_set_tls(CPUM68KState *env, target_ulong newtls)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(m68k_env_get_cpu(env));
TaskState *ts = cs->opaque;

ts->tp_value = newtls;
}

Expand Down
6 changes: 3 additions & 3 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void cpu_loop(CPUARMState *env)
switch(trapnr) {
case EXCP_UDEF:
{
TaskState *ts = env->opaque;
TaskState *ts = cs->opaque;
uint32_t opcode;
int rc;

Expand Down Expand Up @@ -2965,7 +2965,7 @@ void cpu_loop(CPUM68KState *env)
int trapnr;
unsigned int n;
target_siginfo_t info;
TaskState *ts = env->opaque;
TaskState *ts = cs->opaque;

for(;;) {
trapnr = cpu_m68k_exec(env);
Expand Down Expand Up @@ -4001,7 +4001,7 @@ int main(int argc, char **argv, char **envp)
/* build Task State */
ts->info = info;
ts->bprm = &bprm;
env->opaque = ts;
cpu->opaque = ts;
task_settid(ts);

execfd = qemu_getauxval(AT_EXECFD);
Expand Down
17 changes: 11 additions & 6 deletions linux-user/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ void signal_init(void)

static inline struct sigqueue *alloc_sigqueue(CPUArchState *env)
{
TaskState *ts = env->opaque;
CPUState *cpu = ENV_GET_CPU(env);
TaskState *ts = cpu->opaque;
struct sigqueue *q = ts->first_free;
if (!q)
return NULL;
Expand All @@ -380,16 +381,19 @@ static inline struct sigqueue *alloc_sigqueue(CPUArchState *env)

static inline void free_sigqueue(CPUArchState *env, struct sigqueue *q)
{
TaskState *ts = env->opaque;
CPUState *cpu = ENV_GET_CPU(env);
TaskState *ts = cpu->opaque;

q->next = ts->first_free;
ts->first_free = q;
}

/* abort execution with signal */
static void QEMU_NORETURN force_sig(int target_sig)
{
CPUArchState *env = thread_cpu->env_ptr;
TaskState *ts = (TaskState *)env->opaque;
CPUState *cpu = thread_cpu;
CPUArchState *env = cpu->env_ptr;
TaskState *ts = (TaskState *)cpu->opaque;
int host_sig, core_dumped = 0;
struct sigaction act;
host_sig = target_to_host_signal(target_sig);
Expand Down Expand Up @@ -440,7 +444,8 @@ static void QEMU_NORETURN force_sig(int target_sig)
as possible */
int queue_signal(CPUArchState *env, int sig, target_siginfo_t *info)
{
TaskState *ts = env->opaque;
CPUState *cpu = ENV_GET_CPU(env);
TaskState *ts = cpu->opaque;
struct emulated_sigtable *k;
struct sigqueue *q, **pq;
abi_ulong handler;
Expand Down Expand Up @@ -5676,7 +5681,7 @@ void process_pending_signals(CPUArchState *cpu_env)
struct emulated_sigtable *k;
struct target_sigaction *sa;
struct sigqueue *q;
TaskState *ts = cpu_env->opaque;
TaskState *ts = cpu->opaque;

if (!ts->signal_pending)
return;
Expand Down
30 changes: 18 additions & 12 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -4243,7 +4243,7 @@ static void *clone_func(void *arg)
env = info->env;
cpu = ENV_GET_CPU(env);
thread_cpu = cpu;
ts = (TaskState *)env->opaque;
ts = (TaskState *)cpu->opaque;
info->tid = gettid();
cpu->host_tid = info->tid;
task_settid(ts);
Expand Down Expand Up @@ -4271,8 +4271,10 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
abi_ulong parent_tidptr, target_ulong newtls,
abi_ulong child_tidptr)
{
CPUState *cpu = ENV_GET_CPU(env);
int ret;
TaskState *ts;
CPUState *new_cpu;
CPUArchState *new_env;
unsigned int nptl_flags;
sigset_t sigmask;
Expand All @@ -4282,7 +4284,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
flags &= ~(CLONE_VFORK | CLONE_VM);

if (flags & CLONE_VM) {
TaskState *parent_ts = (TaskState *)env->opaque;
TaskState *parent_ts = (TaskState *)cpu->opaque;
new_thread_info info;
pthread_attr_t attr;

Expand All @@ -4292,7 +4294,8 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
new_env = cpu_copy(env);
/* Init regs that differ from the parent. */
cpu_clone_regs(new_env, newsp);
new_env->opaque = ts;
new_cpu = ENV_GET_CPU(new_env);
new_cpu->opaque = ts;
ts->bprm = parent_ts->bprm;
ts->info = parent_ts->info;
nptl_flags = flags;
Expand Down Expand Up @@ -4364,7 +4367,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
put_user_u32(gettid(), child_tidptr);
if (flags & CLONE_PARENT_SETTID)
put_user_u32(gettid(), parent_tidptr);
ts = (TaskState *)env->opaque;
ts = (TaskState *)cpu->opaque;
if (flags & CLONE_SETTLS)
cpu_set_tls (env, newtls);
if (flags & CLONE_CHILD_CLEARTID)
Expand Down Expand Up @@ -4974,7 +4977,8 @@ void init_qemu_uname_release(void)
static int open_self_maps(void *cpu_env, int fd)
{
#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
TaskState *ts = cpu->opaque;
#endif
FILE *fp;
char *line = NULL;
Expand Down Expand Up @@ -5026,7 +5030,8 @@ static int open_self_maps(void *cpu_env, int fd)

static int open_self_stat(void *cpu_env, int fd)
{
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
TaskState *ts = cpu->opaque;
abi_ulong start_stack = ts->info->start_stack;
int i;

Expand Down Expand Up @@ -5062,7 +5067,8 @@ static int open_self_stat(void *cpu_env, int fd)

static int open_self_auxv(void *cpu_env, int fd)
{
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
TaskState *ts = cpu->opaque;
abi_ulong auxv = ts->info->saved_auxv;
abi_ulong len = ts->info->auxv_len;
char *ptr;
Expand Down Expand Up @@ -5244,14 +5250,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
/* Remove the CPU from the list. */
QTAILQ_REMOVE(&cpus, cpu, node);
cpu_list_unlock();
ts = ((CPUArchState *)cpu_env)->opaque;
ts = cpu->opaque;
if (ts->child_tidptr) {
put_user_u32(0, ts->child_tidptr);
sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
NULL, NULL, 0);
}
thread_cpu = NULL;
object_unref(OBJECT(ENV_GET_CPU(cpu_env)));
object_unref(OBJECT(cpu));
g_free(ts);
pthread_exit(NULL);
}
Expand Down Expand Up @@ -6555,7 +6561,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
case TARGET_NR_mprotect:
{
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
TaskState *ts = cpu->opaque;
/* Special hack to detect libc making the stack executable. */
if ((arg3 & PROT_GROWSDOWN)
&& arg1 >= ts->info->stack_limit
Expand Down Expand Up @@ -8647,7 +8653,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
#elif defined(TARGET_M68K)
{
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
TaskState *ts = cpu->opaque;
ts->tp_value = arg1;
ret = 0;
break;
Expand All @@ -8663,7 +8669,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
#elif defined(TARGET_M68K)
{
TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
TaskState *ts = cpu->opaque;
ret = ts->tp_value;
break;
}
Expand Down
27 changes: 18 additions & 9 deletions linux-user/vm86.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static inline unsigned int vm_getl(uint32_t segptr, unsigned int reg16)

void save_v86_state(CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;
struct target_vm86plus_struct * target_v86;

if (!lock_user_struct(VERIFY_WRITE, target_v86, ts->target_v86, 0))
Expand Down Expand Up @@ -131,7 +132,8 @@ static inline void return_to_32bit(CPUX86State *env, int retval)

static inline int set_IF(CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;

ts->v86flags |= VIF_MASK;
if (ts->v86flags & VIP_MASK) {
Expand All @@ -143,7 +145,8 @@ static inline int set_IF(CPUX86State *env)

static inline void clear_IF(CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;

ts->v86flags &= ~VIF_MASK;
}
Expand All @@ -160,7 +163,8 @@ static inline void clear_AC(CPUX86State *env)

static inline int set_vflags_long(unsigned long eflags, CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;

set_flags(ts->v86flags, eflags, ts->v86mask);
set_flags(env->eflags, eflags, SAFE_MASK);
Expand All @@ -173,7 +177,8 @@ static inline int set_vflags_long(unsigned long eflags, CPUX86State *env)

static inline int set_vflags_short(unsigned short flags, CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;

set_flags(ts->v86flags, flags, ts->v86mask & 0xffff);
set_flags(env->eflags, flags, SAFE_MASK);
Expand All @@ -186,7 +191,8 @@ static inline int set_vflags_short(unsigned short flags, CPUX86State *env)

static inline unsigned int get_vflags(CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;
unsigned int flags;

flags = env->eflags & RETURN_MASK;
Expand All @@ -202,7 +208,8 @@ static inline unsigned int get_vflags(CPUX86State *env)
support TSS interrupt revectoring, so this code is always executed) */
static void do_int(CPUX86State *env, int intno)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;
uint32_t int_addr, segoffs, ssp;
unsigned int sp;

Expand Down Expand Up @@ -260,7 +267,8 @@ void handle_vm86_trap(CPUX86State *env, int trapno)

void handle_vm86_fault(CPUX86State *env)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;
uint32_t csp, ssp;
unsigned int ip, sp, newflags, newip, newcs, opcode, intno;
int data32, pref_done;
Expand Down Expand Up @@ -384,7 +392,8 @@ void handle_vm86_fault(CPUX86State *env)

int do_vm86(CPUX86State *env, long subfunction, abi_ulong vm86_addr)
{
TaskState *ts = env->opaque;
CPUState *cs = CPU(x86_env_get_cpu(env));
TaskState *ts = cs->opaque;
struct target_vm86plus_struct * target_v86;
int ret;

Expand Down
Loading

0 comments on commit 0429a97

Please sign in to comment.