2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
8 #include "sysdep/ptrace_user.h"
9 #include "sysdep/ptrace.h"
10 #include "uml-config.h"
11 #include "skas_ptregs.h"
12 #include "registers.h"
16 /* These are set once at boot time and not changed thereafter */
18 static unsigned long exec_regs
[MAX_REG_NR
];
19 static unsigned long exec_fp_regs
[HOST_FP_SIZE
];
20 static unsigned long exec_fpx_regs
[HOST_XFP_SIZE
];
21 static int have_fpx_regs
= 1;
23 void init_thread_registers(union uml_pt_regs
*to
)
25 memcpy(to
->skas
.regs
, exec_regs
, sizeof(to
->skas
.regs
));
26 memcpy(to
->skas
.fp
, exec_fp_regs
, sizeof(to
->skas
.fp
));
28 memcpy(to
->skas
.xfp
, exec_fpx_regs
, sizeof(to
->skas
.xfp
));
31 /* XXX These need to use [GS]ETFPXREGS and copy_sc_{to,from}_user_skas needs
32 * to pass in a sufficiently large buffer
34 int save_fp_registers(int pid
, unsigned long *fp_regs
)
36 if(ptrace(PTRACE_GETFPREGS
, pid
, 0, fp_regs
) < 0)
41 int restore_fp_registers(int pid
, unsigned long *fp_regs
)
43 if(ptrace(PTRACE_SETFPREGS
, pid
, 0, fp_regs
) < 0)
48 static int move_registers(int pid
, int int_op
, union uml_pt_regs
*regs
,
49 int fp_op
, unsigned long *fp_regs
)
51 if(ptrace(int_op
, pid
, 0, regs
->skas
.regs
) < 0)
54 if(ptrace(fp_op
, pid
, 0, fp_regs
) < 0)
60 void save_registers(int pid
, union uml_pt_regs
*regs
)
62 unsigned long *fp_regs
;
66 fp_op
= PTRACE_GETFPXREGS
;
67 fp_regs
= regs
->skas
.xfp
;
70 fp_op
= PTRACE_GETFPREGS
;
71 fp_regs
= regs
->skas
.fp
;
74 err
= move_registers(pid
, PTRACE_GETREGS
, regs
, fp_op
, fp_regs
);
76 panic("save_registers - saving registers failed, errno = %d\n",
80 void restore_registers(int pid
, union uml_pt_regs
*regs
)
82 unsigned long *fp_regs
;
86 fp_op
= PTRACE_SETFPXREGS
;
87 fp_regs
= regs
->skas
.xfp
;
90 fp_op
= PTRACE_SETFPREGS
;
91 fp_regs
= regs
->skas
.fp
;
94 err
= move_registers(pid
, PTRACE_SETREGS
, regs
, fp_op
, fp_regs
);
96 panic("restore_registers - saving registers failed, "
97 "errno = %d\n", -err
);
100 void init_registers(int pid
)
104 memset(exec_regs
, 0, sizeof(exec_regs
));
105 err
= ptrace(PTRACE_GETREGS
, pid
, 0, exec_regs
);
107 panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
111 err
= ptrace(PTRACE_GETFPXREGS
, pid
, 0, exec_fpx_regs
);
115 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
120 err
= ptrace(PTRACE_GETFPREGS
, pid
, 0, exec_fp_regs
);
122 panic("check_ptrace : PTRACE_GETFPREGS failed, errno = %d",
126 void get_safe_registers(unsigned long *regs
, unsigned long *fp_regs
)
128 memcpy(regs
, exec_regs
, sizeof(exec_regs
));
130 memcpy(fp_regs
, exec_fp_regs
,
131 HOST_FP_SIZE
* sizeof(unsigned long));
134 unsigned long get_thread_reg(int reg
, jmp_buf *buf
)
137 case EIP
: return buf
[0]->__eip
;
138 case UESP
: return buf
[0]->__esp
;
139 case EBP
: return buf
[0]->__ebp
;
141 printk("get_thread_regs - unknown register %d\n", reg
);