From 6bc9a3966f0395419b09b2ec90f89f7f00341b37 Mon Sep 17 00:00:00 2001 From: Chen Liqin Date: Fri, 12 Jun 2009 22:01:00 +0800 Subject: score: Add support for Sunplus S+core architecture This is the complete set of new arch Score's files for linux. Score instruction set support 16bits, 32bits and 64bits instruction, Score SOC had been used in game machine and LCD TV. Signed-off-by: Chen Liqin Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 147 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 arch/score/kernel/sys_score.c (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c new file mode 100644 index 00000000000..6a60d1ee533 --- /dev/null +++ b/arch/score/kernel/sys_score.c @@ -0,0 +1,147 @@ +/* + * arch/score/kernel/syscall.c + * + * Score Processor version. + * + * Copyright (C) 2009 Sunplus Core Technology Co., Ltd. + * Chen Liqin + * Lennox Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see the file COPYING, or write + * to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include + +unsigned long shm_align_mask = PAGE_SIZE - 1; +EXPORT_SYMBOL(shm_align_mask); + +asmlinkage unsigned long +sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, + unsigned long flags, unsigned long fd, unsigned long pgoff) +{ + int error = -EBADF; + struct file *file = NULL; + + if (pgoff & (~PAGE_MASK >> 12)) + return -EINVAL; + + flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + if (!(flags & MAP_ANONYMOUS)) { + file = fget(fd); + if (!file) + return error; + } + + down_write(¤t->mm->mmap_sem); + error = do_mmap_pgoff(file, addr, len, prot, flags, + pgoff >> (PAGE_SHIFT - 12)); + up_write(¤t->mm->mmap_sem); + + if (file) + fput(file); + + return error; +} + +/* + * Clone a task - this clones the calling program thread. + * This is called indirectly via a small wrapper + */ +asmlinkage int +score_clone(struct pt_regs *regs) +{ + unsigned long clone_flags; + unsigned long newsp; + int __user *parent_tidptr, *child_tidptr; + + clone_flags = regs->regs[4]; + newsp = regs->regs[5]; + if (!newsp) + newsp = regs->regs[0]; + parent_tidptr = (int __user *)regs->regs[6]; + + child_tidptr = NULL; + if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { + int __user *__user *usp = (int __user *__user *)regs->regs[0]; + + if (get_user(child_tidptr, &usp[4])) + return -EFAULT; + } + + return do_fork(clone_flags, newsp, regs, 0, + parent_tidptr, child_tidptr); +} + +/* + * sys_execve() executes a new program. + * This is called indirectly via a small wrapper + */ +asmlinkage int score_execve(struct pt_regs *regs) +{ + int error; + char *filename; + + filename = getname((char *) (long) regs->regs[4]); + error = PTR_ERR(filename); + if (IS_ERR(filename)) + return error; + + error = do_execve(filename, (char **) (long) regs->regs[5], + (char **) (long) regs->regs[6], regs); + + putname(filename); + return error; +} + +/* + * If we ever come here the user sp is bad. Zap the process right away. + * Due to the bad stack signaling wouldn't work. + */ +asmlinkage void bad_stack(void) +{ + do_exit(SIGSEGV); +} + +/* + * Do a system call from kernel instead of calling sys_execve so we + * end up with proper pt_regs. + */ +int kernel_execve(const char *filename, char *const argv[], char *const envp[]) +{ + register unsigned long __r4 asm("r4") = (unsigned long) filename; + register unsigned long __r5 asm("r5") = (unsigned long) argv; + register unsigned long __r6 asm("r6") = (unsigned long) envp; + register unsigned long __r7 asm("r7"); + + __asm__ __volatile__ (" \n" + "ldi r27, %5 \n" + "syscall \n" + "mv %0, r4 \n" + "mv %1, r7 \n" + : "=&r" (__r4), "=r" (__r7) + : "r" (__r4), "r" (__r5), "r" (__r6), "i" (__NR_execve) + : "r8", "r9", "r10", "r11", "r22", "r23", "r24", "r25", + "r26", "r27", "memory"); + + if (__r7 == 0) + return __r4; + + return -__r4; +} -- cgit v1.2.3 From 0402c91af944c61bf788370f03326959a35cb8be Mon Sep 17 00:00:00 2001 From: Chen Liqin Date: Fri, 19 Jun 2009 13:53:49 +0800 Subject: score: update files according to review comments modified: arch/score/include/asm/cacheflush.h modified: arch/score/include/asm/delay.h modified: arch/score/include/asm/errno.h modified: arch/score/include/asm/pgtable-bits.h modified: arch/score/include/asm/pgtable.h modified: arch/score/include/asm/ptrace.h modified: arch/score/include/asm/unistd.h modified: arch/score/kernel/entry.S modified: arch/score/kernel/process.c modified: arch/score/kernel/ptrace.c modified: arch/score/kernel/signal.c modified: arch/score/kernel/sys_score.c modified: arch/score/kernel/traps.c modified: arch/score/mm/cache.c Signed-off-by: Chen Liqin Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 6a60d1ee533..68655f4cbce 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -64,8 +64,7 @@ sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, * Clone a task - this clones the calling program thread. * This is called indirectly via a small wrapper */ -asmlinkage int -score_clone(struct pt_regs *regs) +int score_clone(struct pt_regs *regs) { unsigned long clone_flags; unsigned long newsp; @@ -93,7 +92,7 @@ score_clone(struct pt_regs *regs) * sys_execve() executes a new program. * This is called indirectly via a small wrapper */ -asmlinkage int score_execve(struct pt_regs *regs) +int score_execve(struct pt_regs *regs) { int error; char *filename; @@ -114,7 +113,7 @@ asmlinkage int score_execve(struct pt_regs *regs) * If we ever come here the user sp is bad. Zap the process right away. * Due to the bad stack signaling wouldn't work. */ -asmlinkage void bad_stack(void) +void bad_stack(void) { do_exit(SIGSEGV); } -- cgit v1.2.3 From f673c032ed13ed8f3fda5922c2190da2892398bc Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 19 Jun 2009 11:31:54 +0200 Subject: score: add generic sys_call_table This adds back a sys_call_table to the score architecture, which got lost in the conversion to the generic unistd.h file. It's rather worrying that the code got submitted without a system call table, which evidently means that it got zero testing. Since the system call table has a different layout from the old one (which was modeled after the mips-o32 one), I also try to fix the entry.S path to use it. In the modified calling conventions, all system call arguments are passed as registers r4 through r9, instead of r4 through r7 plus stack for the fifth and sixth argument. This matches what other architectures to when they normally pass arguments on the stack. Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 68655f4cbce..33188610432 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -75,14 +75,7 @@ int score_clone(struct pt_regs *regs) if (!newsp) newsp = regs->regs[0]; parent_tidptr = (int __user *)regs->regs[6]; - - child_tidptr = NULL; - if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { - int __user *__user *usp = (int __user *__user *)regs->regs[0]; - - if (get_user(child_tidptr, &usp[4])) - return -EFAULT; - } + child_tidptr = (int __user *)regs->regs[8]; return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr); -- cgit v1.2.3 From 9fb24cc50045ec8d13d0a6c3d4d454750b466d61 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 27 Jun 2009 14:50:51 +0200 Subject: score: add missing #includes Files that define a global function should #include the header with its declaration to make sure that the prototypes do not diverge. Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 33188610432..eb4d2d3b97a 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include unsigned long shm_align_mask = PAGE_SIZE - 1; EXPORT_SYMBOL(shm_align_mask); -- cgit v1.2.3 From a1f8213b9518d0e9124a48a34bdd58b4bc2650e5 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 27 Jun 2009 15:05:30 +0200 Subject: score: add address space annotations Annotate the address space for pointers that are used correctly with __user and __iomem, so that sparse can better warn about incorrect casts. Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index eb4d2d3b97a..16ace29935b 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -87,18 +87,19 @@ int score_clone(struct pt_regs *regs) * sys_execve() executes a new program. * This is called indirectly via a small wrapper */ -int score_execve(struct pt_regs *regs) +asmlinkage long +score_execve(struct pt_regs *regs) { int error; char *filename; - filename = getname((char *) (long) regs->regs[4]); + filename = getname((char __user*)regs->regs[4]); error = PTR_ERR(filename); if (IS_ERR(filename)) return error; - error = do_execve(filename, (char **) (long) regs->regs[5], - (char **) (long) regs->regs[6], regs); + error = do_execve(filename, (char __user *__user*)regs->regs[5], + (char __user *__user *) regs->regs[6], regs); putname(filename); return error; -- cgit v1.2.3 From bddc605955bca2d914ca621a7ef4ca6c271f55d8 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 27 Jun 2009 15:12:16 +0200 Subject: score: fix function prototypes Syscalls should return 'long' and be marked as 'asmlinkage'. Functions that are only used in a single file should be 'static'. Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 16ace29935b..5b3cc4e685a 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -34,7 +34,7 @@ unsigned long shm_align_mask = PAGE_SIZE - 1; EXPORT_SYMBOL(shm_align_mask); -asmlinkage unsigned long +asmlinkage unsigned sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff) { @@ -66,7 +66,8 @@ sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, * Clone a task - this clones the calling program thread. * This is called indirectly via a small wrapper */ -int score_clone(struct pt_regs *regs) +asmlinkage long +score_clone(struct pt_regs *regs) { unsigned long clone_flags; unsigned long newsp; -- cgit v1.2.3 From c6067472252c1d6155c7c01c93e0d580342cdb29 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sat, 27 Jun 2009 14:46:35 +0200 Subject: score: cleanups: dead code, 0 as pointer, shadowed variables A few smaller issues found by sparse, some code that was never used, two instances of '0' instead of 'NULL' and local variables shadowing another one. Signed-off-by: Arnd Bergmann --- arch/score/kernel/sys_score.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 5b3cc4e685a..61aff8a9344 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -31,10 +31,7 @@ #include #include -unsigned long shm_align_mask = PAGE_SIZE - 1; -EXPORT_SYMBOL(shm_align_mask); - -asmlinkage unsigned +asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff) { @@ -106,15 +103,6 @@ score_execve(struct pt_regs *regs) return error; } -/* - * If we ever come here the user sp is bad. Zap the process right away. - * Due to the bad stack signaling wouldn't work. - */ -void bad_stack(void) -{ - do_exit(SIGSEGV); -} - /* * Do a system call from kernel instead of calling sys_execve so we * end up with proper pt_regs. -- cgit v1.2.3 From cf52c468352993ca420fe0b4ada976dc1f614026 Mon Sep 17 00:00:00 2001 From: Chen Liqin Date: Sun, 30 Aug 2009 12:33:30 +0800 Subject: score: add old syscall support --- arch/score/kernel/sys_score.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'arch/score/kernel/sys_score.c') diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 61aff8a9344..00124946986 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -49,8 +50,7 @@ sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, } down_write(¤t->mm->mmap_sem); - error = do_mmap_pgoff(file, addr, len, prot, flags, - pgoff >> (PAGE_SHIFT - 12)); + error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); up_write(¤t->mm->mmap_sem); if (file) @@ -59,6 +59,19 @@ sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, return error; } +asmlinkage long +sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, + unsigned long flags, unsigned long fd, off_t pgoff) +{ + return sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); +} + +asmlinkage long +score_fork(struct pt_regs *regs) +{ + return do_fork(SIGCHLD, regs->regs[0], regs, 0, NULL, NULL); +} + /* * Clone a task - this clones the calling program thread. * This is called indirectly via a small wrapper @@ -81,6 +94,13 @@ score_clone(struct pt_regs *regs) parent_tidptr, child_tidptr); } +asmlinkage long +score_vfork(struct pt_regs *regs) +{ + return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, + regs->regs[0], regs, 0, NULL, NULL); +} + /* * sys_execve() executes a new program. * This is called indirectly via a small wrapper -- cgit v1.2.3