2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
9 #include "ptrace_user.h"
10 #include "uml-config.h"
11 #include "skas_ptregs.h"
12 #include "registers.h"
15 /* These are set once at boot time and not changed thereafter */
17 static unsigned long exec_regs
[HOST_FRAME_SIZE
];
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
, HOST_FRAME_SIZE
* sizeof(unsigned long));
77 memcpy(fp_regs
, exec_fp_regs
,
78 HOST_FP_SIZE
* sizeof(unsigned long));
81 void get_thread_regs(union uml_pt_regs
*uml_regs
, void *buffer
)
83 struct __jmp_buf_tag
*jmpbuf
= buffer
;
85 UPT_SET(uml_regs
, RIP
, jmpbuf
->__jmpbuf
[JB_PC
]);
86 UPT_SET(uml_regs
, RSP
, jmpbuf
->__jmpbuf
[JB_RSP
]);
87 UPT_SET(uml_regs
, RBP
, jmpbuf
->__jmpbuf
[JB_RBP
]);