2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
9 #include "sysdep/ptrace_user.h"
10 #include "sysdep/ptrace.h"
11 #include "uml-config.h"
12 #include "skas_ptregs.h"
13 #include "registers.h"
16 /* These are set once at boot time and not changed thereafter */
18 static unsigned long exec_regs[HOST_FRAME_SIZE];
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 err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
106 panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
110 err = ptrace(PTRACE_GETFPXREGS, pid, 0, exec_fpx_regs);
114 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
119 err = ptrace(PTRACE_GETFPREGS, pid, 0, exec_fp_regs);
121 panic("check_ptrace : PTRACE_GETFPREGS failed, errno = %d",
125 void get_safe_registers(unsigned long *regs)
127 memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long));
130 void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer)
132 struct __jmp_buf_tag *jmpbuf = buffer;
134 UPT_SET(uml_regs, EIP, jmpbuf->__jmpbuf[JB_PC]);
135 UPT_SET(uml_regs, UESP, jmpbuf->__jmpbuf[JB_SP]);
136 UPT_SET(uml_regs, EBP, jmpbuf->__jmpbuf[JB_BP]);