Skip to content

Commit 4859bfc

Browse files
committed
csky: System Call
This patch adds files related to syscall. Signed-off-by: Guo Ren <ren_guo@c-sky.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 081860b commit 4859bfc

5 files changed

Lines changed: 153 additions & 0 deletions

File tree

‎arch/csky/include/asm/syscall.h‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_SYSCALL_H
4+
#define __ASM_SYSCALL_H
5+
6+
#include <linux/sched.h>
7+
#include <linux/err.h>
8+
#include <abi/regdef.h>
9+
10+
static inline int
11+
syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
12+
{
13+
return regs_syscallid(regs);
14+
}
15+
16+
static inline void
17+
syscall_rollback(struct task_struct *task, struct pt_regs *regs)
18+
{
19+
regs->a0 = regs->orig_a0;
20+
}
21+
22+
static inline long
23+
syscall_get_error(struct task_struct *task, struct pt_regs *regs)
24+
{
25+
unsigned long error = regs->a0;
26+
27+
return IS_ERR_VALUE(error) ? error : 0;
28+
}
29+
30+
static inline long
31+
syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
32+
{
33+
return regs->a0;
34+
}
35+
36+
static inline void
37+
syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
38+
int error, long val)
39+
{
40+
regs->a0 = (long) error ?: val;
41+
}
42+
43+
static inline void
44+
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
45+
unsigned int i, unsigned int n, unsigned long *args)
46+
{
47+
BUG_ON(i + n > 6);
48+
if (i == 0) {
49+
args[0] = regs->orig_a0;
50+
args++;
51+
i++;
52+
n--;
53+
}
54+
memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
55+
}
56+
57+
static inline void
58+
syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
59+
unsigned int i, unsigned int n, const unsigned long *args)
60+
{
61+
BUG_ON(i + n > 6);
62+
if (i == 0) {
63+
regs->orig_a0 = args[0];
64+
args++;
65+
i++;
66+
n--;
67+
}
68+
memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
69+
}
70+
71+
#endif /* __ASM_SYSCALL_H */

‎arch/csky/include/asm/syscalls.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#ifndef __ASM_CSKY_SYSCALLS_H
5+
#define __ASM_CSKY_SYSCALLS_H
6+
7+
#include <asm-generic/syscalls.h>
8+
9+
long sys_cacheflush(void __user *, unsigned long, int);
10+
11+
long sys_set_thread_area(unsigned long addr);
12+
13+
long sys_csky_fadvise64_64(int fd, int advice, loff_t offset, loff_t len);
14+
15+
#endif /* __ASM_CSKY_SYSCALLS_H */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#define __ARCH_WANT_SYS_CLONE
5+
#include <asm-generic/unistd.h>
6+
7+
#define __NR_set_thread_area (__NR_arch_specific_syscall + 0)
8+
__SYSCALL(__NR_set_thread_area, sys_set_thread_area)
9+
#define __NR_cacheflush (__NR_arch_specific_syscall + 1)
10+
__SYSCALL(__NR_cacheflush, sys_cacheflush)

‎arch/csky/kernel/syscall.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#include <linux/syscalls.h>
5+
6+
SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
7+
{
8+
struct thread_info *ti = task_thread_info(current);
9+
struct pt_regs *reg = current_pt_regs();
10+
11+
reg->tls = addr;
12+
ti->tp_value = addr;
13+
14+
return 0;
15+
}
16+
17+
SYSCALL_DEFINE6(mmap2,
18+
unsigned long, addr,
19+
unsigned long, len,
20+
unsigned long, prot,
21+
unsigned long, flags,
22+
unsigned long, fd,
23+
off_t, offset)
24+
{
25+
if (unlikely(offset & (~PAGE_MASK >> 12)))
26+
return -EINVAL;
27+
28+
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
29+
offset >> (PAGE_SHIFT - 12));
30+
}
31+
32+
/*
33+
* for abiv1 the 64bits args should be even th, So we need mov the advice
34+
* forward.
35+
*/
36+
SYSCALL_DEFINE4(csky_fadvise64_64,
37+
int, fd,
38+
int, advice,
39+
loff_t, offset,
40+
loff_t, len)
41+
{
42+
return ksys_fadvise64_64(fd, offset, len, advice);
43+
}

‎arch/csky/kernel/syscall_table.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#include <linux/syscalls.h>
5+
#include <asm/syscalls.h>
6+
7+
#undef __SYSCALL
8+
#define __SYSCALL(nr, call)[nr] = (call),
9+
10+
#define sys_fadvise64_64 sys_csky_fadvise64_64
11+
void * const sys_call_table[__NR_syscalls] __page_aligned_data = {
12+
[0 ... __NR_syscalls - 1] = sys_ni_syscall,
13+
#include <asm/unistd.h>
14+
};

0 commit comments

Comments
 (0)