2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
9 #include <linux/stddef.h>
10 #include "ptrace_user.h"
11 /* Grr, asm/user.h includes asm/ptrace.h, so has to follow ptrace_user.h */
13 #include "kern_util.h"
14 #include "sysdep/thread.h"
17 #include "uml-config.h"
19 int ptrace_getregs(long pid
, unsigned long *regs_out
)
21 if (ptrace(PTRACE_GETREGS
, pid
, 0, regs_out
) < 0)
26 int ptrace_setregs(long pid
, unsigned long *regs
)
28 if (ptrace(PTRACE_SETREGS
, pid
, 0, regs
) < 0)
33 int ptrace_getfpregs(long pid
, unsigned long *regs
)
35 if (ptrace(PTRACE_GETFPREGS
, pid
, 0, regs
) < 0)
40 int ptrace_setfpregs(long pid
, unsigned long *regs
)
42 if (ptrace(PTRACE_SETFPREGS
, pid
, 0, regs
) < 0)
47 /* All the below stuff is of interest for TT mode only */
48 static void write_debugregs(int pid
, unsigned long *regs
)
54 nregs
= sizeof(dummy
->u_debugreg
)/sizeof(dummy
->u_debugreg
[0]);
55 for(i
= 0; i
< nregs
; i
++){
56 if((i
== 4) || (i
== 5)) continue;
57 if(ptrace(PTRACE_POKEUSR
, pid
, &dummy
->u_debugreg
[i
],
59 printk("write_debugregs - ptrace failed on "
60 "register %d, value = 0x%lx, errno = %d\n", i
,
65 static void read_debugregs(int pid
, unsigned long *regs
)
71 nregs
= sizeof(dummy
->u_debugreg
)/sizeof(dummy
->u_debugreg
[0]);
72 for(i
= 0; i
< nregs
; i
++){
73 regs
[i
] = ptrace(PTRACE_PEEKUSR
, pid
,
74 &dummy
->u_debugreg
[i
], 0);
78 /* Accessed only by the tracing thread */
79 static unsigned long kernel_debugregs
[8] = { [ 0 ... 7 ] = 0 };
81 void arch_enter_kernel(void *task
, int pid
)
83 read_debugregs(pid
, TASK_DEBUGREGS(task
));
84 write_debugregs(pid
, kernel_debugregs
);
87 void arch_leave_kernel(void *task
, int pid
)
89 read_debugregs(pid
, kernel_debugregs
);
90 write_debugregs(pid
, TASK_DEBUGREGS(task
));
93 #ifdef UML_CONFIG_PT_PROXY
94 /* Accessed only by the tracing thread */
95 static int debugregs_seq
;
97 /* Only called by the ptrace proxy */
98 void ptrace_pokeuser(unsigned long addr
, unsigned long data
)
100 if((addr
< offsetof(struct user
, u_debugreg
[0])) ||
101 (addr
> offsetof(struct user
, u_debugreg
[7])))
103 addr
-= offsetof(struct user
, u_debugreg
[0]);
105 if(kernel_debugregs
[addr
] == data
) return;
107 kernel_debugregs
[addr
] = data
;
111 static void update_debugregs_cb(void *arg
)
113 int pid
= *((int *) arg
);
115 write_debugregs(pid
, kernel_debugregs
);
118 /* Optimized out in its header when not defined */
119 void update_debugregs(int seq
)
123 if(seq
== debugregs_seq
) return;
126 initial_thread_cb(update_debugregs_cb
, &me
);
131 * Overrides for Emacs so that we follow Linus's tabbing style.
132 * Emacs will notice this stuff at the end of the file and automatically
133 * adjust the settings for this buffer only. This must remain at the end
135 * ---------------------------------------------------------------------------
137 * c-file-style: "linux"