Skip to content

Commit

Permalink
csky: support regset for ptrace.
Browse files Browse the repository at this point in the history
move usp into pt_regs.

Signed-off-by: Guo Ren <ren_guo@c-sky.com>
  • Loading branch information
guoren83 committed Apr 9, 2018
1 parent a098d4c commit b167422
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 73 deletions.
1 change: 1 addition & 0 deletions arch/csky/Kconfig
Expand Up @@ -15,6 +15,7 @@ config CSKY
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_SCHED_CLOCK
select HAVE_ARCH_TRACEHOOK
select HAVE_GENERIC_DMA_COHERENT
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_LZO
Expand Down
7 changes: 7 additions & 0 deletions arch/csky/abiv1/inc/abi/entry.h
Expand Up @@ -68,6 +68,7 @@
bt 1f
USPTOKSP
1:
subi sp, 8
subi sp, 32
subi sp, 32
stw r13, (sp, 0)
Expand All @@ -88,6 +89,11 @@
stw r1, (sp, 56)
stw r15, (sp, 60)

addi sp, 32
mfcr r13, ss0
stw r13, (sp, 32)
subi sp, 32

subi sp, 8
stw a0, (sp, 4)
mfcr r13, epc
Expand Down Expand Up @@ -126,6 +132,7 @@
ldw r15, (sp, 56)
addi sp, 32
addi sp, 28
addi sp, 8

bt 1f
KSPTOUSP
Expand Down
2 changes: 2 additions & 0 deletions arch/csky/abiv1/inc/abi/regdef.h
Expand Up @@ -6,6 +6,8 @@
#define syscallid r1
#define r11_sig r11

#define regs_syscallid(regs) regs->regs[9]

#define DEFAULT_PSR_VALUE 0x8f000000

#define PTRACE_REGOFF_ABI \
Expand Down
17 changes: 10 additions & 7 deletions arch/csky/abiv2/inc/abi/entry.h
Expand Up @@ -27,7 +27,7 @@
.endm

.macro SAVE_ALL
subi sp, 144
subi sp, 152
stw a0, (sp, 4)
stw a0, (sp, 12)
stw a1, (sp, 16)
Expand All @@ -48,17 +48,20 @@
stm r16-r31,(sp)
#ifdef CONFIG_CPU_HAS_HILO
mfhi r22
mflo r23
stw r22, (sp, 64)
stw r23, (sp, 68)
mflo r22
stw r22, (sp, 68)
#endif
subi sp, 72
mfcr r22, cr<14, 1>
stw r22, (sp, 72)

subi sp, 72
mfcr r22, epsr
stw r22, (sp, 8)
mfcr r22, epc
stw r22, (sp)
.endm

.macro SAVE_ALL_TRAP
SAVE_ALL
INCTRAP r22
Expand All @@ -74,9 +77,9 @@
addi sp, 12
#ifdef CONFIG_CPU_HAS_HILO
ldw a0, (sp, 124)
ldw a1, (sp, 128)
mthi a0
mtlo a1
ldw a0, (sp, 128)
mtlo a0
#endif
ldw a0, (sp, 0)
ldw a1, (sp, 4)
Expand All @@ -95,7 +98,7 @@
ldw r15, (sp, 56)
addi sp, 60
ldm r16-r31,(sp)
addi sp, 72
addi sp, 80
1:
rte
.endm
Expand Down
2 changes: 2 additions & 0 deletions arch/csky/abiv2/inc/abi/regdef.h
Expand Up @@ -6,6 +6,8 @@
#define syscallid r7
#define r11_sig r11

#define regs_syscallid(regs) regs->regs[3]

#define DEFAULT_PSR_VALUE 0x8f000200

#define PTRACE_REGOFF_ABI \
Expand Down
1 change: 1 addition & 0 deletions arch/csky/include/asm/page.h
Expand Up @@ -12,6 +12,7 @@
#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE - 1))
#define THREAD_SIZE (PAGE_SIZE * 2)
#define THREAD_MASK (~(THREAD_SIZE -1))
#define THREAD_SHIFT (PAGE_SHIFT + 1)

/*
Expand Down
69 changes: 69 additions & 0 deletions arch/csky/include/asm/syscall.h
@@ -0,0 +1,69 @@
#ifndef __ASM_SYSCALL_H
#define __ASM_SYSCALL_H

#include <linux/sched.h>
#include <linux/err.h>
#include <abi/regdef.h>

static inline int
syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
{
return regs_syscallid(regs);
}

static inline void
syscall_rollback(struct task_struct *task, struct pt_regs *regs)
{
regs->a0 = regs->orig_a0;
}

static inline long
syscall_get_error(struct task_struct *task, struct pt_regs *regs)
{
unsigned long error = regs->a0;

return IS_ERR_VALUE(error) ? error : 0;
}

static inline long
syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
{
return regs->a0;
}

static inline void
syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
int error, long val)
{
regs->a0 = (long) error ?: val;
}

static inline void
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
unsigned int i, unsigned int n, unsigned long *args)
{
BUG_ON(i + n > 6);
if (i == 0) {
args[0] = regs->orig_a0;
args++;
i++;
n--;
}
memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
}

static inline void
syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
unsigned int i, unsigned int n, const unsigned long *args)
{
BUG_ON(i + n > 6);
if (i == 0) {
regs->orig_a0 = args[0];
args++;
i++;
n--;
}
memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
}

#endif /* __ASM_SYSCALL_H */
6 changes: 5 additions & 1 deletion arch/csky/include/uapi/asm/ptrace.h
Expand Up @@ -10,7 +10,7 @@

/* this struct defines the way the registers are stored on the
stack during a system call. */
struct pt_regs {
struct pt_regs {
unsigned long pc;
long orig_a0;
unsigned long sr;
Expand All @@ -27,6 +27,8 @@ struct pt_regs {
long rhi;
long rlo;
#endif
unsigned long usp;
unsigned long pad; /* make pt_regs 8 bytes aligned */
};

/*
Expand Down Expand Up @@ -84,7 +86,9 @@ struct switch_stack {
#define arch_has_single_step() (1)
#define current_pt_regs() \
(struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1

#define current_user_stack_pointer() rdusp()
#define user_stack_pointer(regs) ((regs)->usp)

#define user_mode(regs) (!((regs)->sr & PS_S))
#define instruction_pointer(regs) ((regs)->pc)
Expand Down

0 comments on commit b167422

Please sign in to comment.