Skip to content

Commit e50e2f2

Browse files
committed
Blackfin: initial regset support
We don't support core dumps (yet?), but this should make things easier. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
1 parent f2ce480 commit e50e2f2

3 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎arch/blackfin/include/asm/elf.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
#define EF_BFIN_CODE_IN_L2 0x00000040 /* --code-in-l2 */
2323
#define EF_BFIN_DATA_IN_L2 0x00000080 /* --data-in-l2 */
2424

25+
#if 1 /* core dumps not supported, but linux/elfcore.h needs these */
2526
typedef unsigned long elf_greg_t;
2627

27-
#define ELF_NGREG 40 /* (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) */
28+
#define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
2829
typedef elf_greg_t elf_gregset_t[ELF_NGREG];
2930

3031
typedef struct { } elf_fpregset_t;
32+
#endif
33+
3134
/*
3235
* This is used to ensure we don't load something for the wrong architecture.
3336
*/
@@ -55,6 +58,9 @@ do { \
5558
_regs->p2 = _dynamic_addr; \
5659
} while(0)
5760

61+
#if 0
62+
#define CORE_DUMP_USE_REGSET
63+
#endif
5864
#define ELF_FDPIC_CORE_EFLAGS EF_BFIN_FDPIC
5965
#define ELF_EXEC_PAGESIZE 4096
6066

‎arch/blackfin/kernel/process.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ void cpu_idle(void)
9898
}
9999
}
100100

101-
/* Fill in the fpu structure for a core dump. */
102-
103-
int dump_fpu(struct pt_regs *regs, elf_fpregset_t * fpregs)
104-
{
105-
return 1;
106-
}
107-
108101
/*
109102
* This gets run with P1 containing the
110103
* function to call, and R1 containing

‎arch/blackfin/kernel/ptrace.c‎

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include <linux/sched.h>
1010
#include <linux/mm.h>
1111
#include <linux/smp.h>
12+
#include <linux/elf.h>
1213
#include <linux/errno.h>
1314
#include <linux/ptrace.h>
1415
#include <linux/user.h>
16+
#include <linux/regset.h>
1517
#include <linux/signal.h>
1618
#include <linux/uaccess.h>
1719

@@ -49,22 +51,6 @@ static inline struct pt_regs *task_pt_regs(struct task_struct *task)
4951
(THREAD_SIZE - sizeof(struct pt_regs)));
5052
}
5153

52-
/*
53-
* Get all user integer registers.
54-
*/
55-
static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
56-
{
57-
struct pt_regs regs;
58-
memcpy(&regs, task_pt_regs(tsk), sizeof(regs));
59-
regs.usp = tsk->thread.usp;
60-
return copy_to_user(uregs, &regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
61-
}
62-
63-
/* Mapping from PT_xxx to the stack offset at which the register is
64-
* saved. Notice that usp has no stack-slot and needs to be treated
65-
* specially (see get_reg/put_reg below).
66-
*/
67-
6854
/*
6955
* Get contents of register REGNO in task TASK.
7056
*/
@@ -170,6 +156,84 @@ static inline int is_user_addr_valid(struct task_struct *child,
170156
return -EIO;
171157
}
172158

159+
/*
160+
* retrieve the contents of Blackfin userspace general registers
161+
*/
162+
static int genregs_get(struct task_struct *target,
163+
const struct user_regset *regset,
164+
unsigned int pos, unsigned int count,
165+
void *kbuf, void __user *ubuf)
166+
{
167+
struct pt_regs *regs = task_pt_regs(target);
168+
int ret;
169+
170+
/* This sucks ... */
171+
regs->usp = target->thread.usp;
172+
173+
ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
174+
regs, 0, sizeof(*regs));
175+
if (ret < 0)
176+
return ret;
177+
178+
return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
179+
sizeof(*regs), -1);
180+
}
181+
182+
/*
183+
* update the contents of the Blackfin userspace general registers
184+
*/
185+
static int genregs_set(struct task_struct *target,
186+
const struct user_regset *regset,
187+
unsigned int pos, unsigned int count,
188+
const void *kbuf, const void __user *ubuf)
189+
{
190+
struct pt_regs *regs = task_pt_regs(target);
191+
int ret;
192+
193+
/* Don't let people set SYSCFG (it's at the end of pt_regs) */
194+
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
195+
regs, 0, PT_SYSCFG);
196+
if (ret < 0)
197+
return ret;
198+
199+
/* This sucks ... */
200+
target->thread.usp = regs->usp;
201+
/* regs->retx = regs->pc; */
202+
203+
return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
204+
PT_SYSCFG, -1);
205+
}
206+
207+
/*
208+
* Define the register sets available on the Blackfin under Linux
209+
*/
210+
enum bfin_regset {
211+
REGSET_GENERAL,
212+
};
213+
214+
static const struct user_regset bfin_regsets[] = {
215+
[REGSET_GENERAL] = {
216+
.core_note_type = NT_PRSTATUS,
217+
.n = sizeof(struct pt_regs) / sizeof(long),
218+
.size = sizeof(long),
219+
.align = sizeof(long),
220+
.get = genregs_get,
221+
.set = genregs_set,
222+
},
223+
};
224+
225+
static const struct user_regset_view user_bfin_native_view = {
226+
.name = "Blackfin",
227+
.e_machine = EM_BLACKFIN,
228+
.regsets = bfin_regsets,
229+
.n = ARRAY_SIZE(bfin_regsets),
230+
};
231+
232+
const struct user_regset_view *task_user_regset_view(struct task_struct *task)
233+
{
234+
return &user_bfin_native_view;
235+
}
236+
173237
void ptrace_enable(struct task_struct *child)
174238
{
175239
struct pt_regs *regs = task_pt_regs(child);
@@ -327,15 +391,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
327391
break;
328392

329393
case PTRACE_GETREGS:
330-
/* Get all gp regs from the child. */
331-
ret = ptrace_getregs(child, datap);
332-
break;
394+
pr_debug("ptrace: PTRACE_GETREGS\n");
395+
return copy_regset_to_user(child, &user_bfin_native_view,
396+
REGSET_GENERAL,
397+
0, sizeof(struct pt_regs),
398+
(void __user *)data);
333399

334400
case PTRACE_SETREGS:
335-
printk(KERN_WARNING "ptrace: SETREGS: **** NOT IMPLEMENTED ***\n");
336-
/* Set all gp regs in the child. */
337-
ret = 0;
338-
break;
401+
pr_debug("ptrace: PTRACE_SETREGS\n");
402+
return copy_regset_from_user(child, &user_bfin_native_view,
403+
REGSET_GENERAL,
404+
0, sizeof(struct pt_regs),
405+
(const void __user *)data);
339406

340407
default:
341408
ret = ptrace_request(child, request, addr, data);

0 commit comments

Comments
 (0)