xref: /openbmc/linux/arch/um/os-Linux/registers.c (revision 18badddaa84e13e126f4ca5df47ac55b97a2635a)
1 /*
2  * Copyright (C) 2004 PathScale, Inc
3  * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4  * Licensed under the GPL
5  */
6 
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/ptrace.h>
10 #include "sysdep/ptrace.h"
11 #include "user.h"
12 
13 /* This is set once at boot time and not changed thereafter */
14 
15 static unsigned long exec_regs[MAX_REG_NR];
16 
17 void init_thread_registers(struct uml_pt_regs *to)
18 {
19 	memcpy(to->gp, exec_regs, sizeof(to->gp));
20 }
21 
22 void save_registers(int pid, struct uml_pt_regs *regs)
23 {
24 	int err;
25 
26 	err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp);
27 	if (err < 0)
28 		panic("save_registers - saving registers failed, errno = %d\n",
29 		      errno);
30 }
31 
32 void restore_registers(int pid, struct uml_pt_regs *regs)
33 {
34 	int err;
35 
36 	err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp);
37 	if (err < 0)
38 		panic("restore_registers - saving registers failed, "
39 		      "errno = %d\n", errno);
40 }
41 
42 void init_registers(int pid)
43 {
44 	int err;
45 
46 	err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
47 	if (err)
48 		panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
49 		      errno);
50 }
51 
52 void get_safe_registers(unsigned long *regs)
53 {
54 	memcpy(regs, exec_regs, sizeof(exec_regs));
55 }
56