2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
8 #include "ptrace_user.h"
9 #include "uml-config.h"
10 #include "skas_ptregs.h"
11 #include "registers.h"
15 /* These are set once at boot time and not changed thereafter */
17 static unsigned long exec_regs
[MAX_REG_NR
];
18 static unsigned long exec_fp_regs
[HOST_FP_SIZE
];
20 void init_thread_registers(union uml_pt_regs
*to
)
22 memcpy(to
->skas
.regs
, exec_regs
, sizeof(to
->skas
.regs
));
23 memcpy(to
->skas
.fp
, exec_fp_regs
, sizeof(to
->skas
.fp
));
26 static int move_registers(int pid
, int int_op
, int fp_op
,
27 union uml_pt_regs
*regs
)
29 if(ptrace(int_op
, pid
, 0, regs
->skas
.regs
) < 0)
32 if(ptrace(fp_op
, pid
, 0, regs
->skas
.fp
) < 0)
38 void save_registers(int pid
, union uml_pt_regs
*regs
)
42 err
= move_registers(pid
, PTRACE_GETREGS
, PTRACE_GETFPREGS
, regs
);
44 panic("save_registers - saving registers failed, errno = %d\n",
48 void restore_registers(int pid
, union uml_pt_regs
*regs
)
52 err
= move_registers(pid
, PTRACE_SETREGS
, PTRACE_SETFPREGS
, regs
);
54 panic("restore_registers - saving registers failed, "
55 "errno = %d\n", -err
);
58 void init_registers(int pid
)
62 err
= ptrace(PTRACE_GETREGS
, pid
, 0, exec_regs
);
64 panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
67 err
= ptrace(PTRACE_GETFPREGS
, pid
, 0, exec_fp_regs
);
69 panic("check_ptrace : PTRACE_GETFPREGS failed, errno = %d",
73 void get_safe_registers(unsigned long *regs
, unsigned long *fp_regs
)
75 memcpy(regs
, exec_regs
, sizeof(exec_regs
));
77 memcpy(fp_regs
, exec_fp_regs
,
78 HOST_FP_SIZE
* sizeof(unsigned long));
81 unsigned long get_thread_reg(int reg
, jmp_buf *buf
)
84 case RIP
: return buf
[0]->__rip
;
85 case RSP
: return buf
[0]->__rsp
;
86 case RBP
: return buf
[0]->__rbp
;
88 printk("get_thread_regs - unknown register %d\n", reg
);