Skip to content

Commit f673c03

Browse files
committed
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 <arnd@arndb.de>
1 parent 78229db commit f673c03

4 files changed

Lines changed: 18 additions & 53 deletions

File tree

‎arch/score/kernel/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
extra-y := head.o vmlinux.lds
66

77
obj-y += entry.o init_task.o irq.o process.o ptrace.o \
8-
setup.o signal.o sys_score.o time.o traps.o
8+
setup.o signal.o sys_score.o time.o traps.o \
9+
sys_call_table.o
910

1011
obj-$(CONFIG_MODULES) += module.o

‎arch/score/kernel/entry.S‎

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ ENTRY(handle_sys)
400400
sw r4, [r0, PT_ORIG_R4] #for restart syscall
401401
sw r7, [r0, PT_ORIG_R7] #for restart syscall
402402
sw r27, [r0, PT_IS_SYSCALL] # it from syscall
403+
sw r8, [r0, 16] # argument 5 from user r8
404+
sw r9, [r0, 20] # argument 6 from user r9
403405

404406
lw r9, [r0, PT_EPC] # skip syscall on return
405407
addi r9, 4
@@ -408,19 +410,14 @@ ENTRY(handle_sys)
408410
cmpi.c r27, __NR_syscalls # check syscall number
409411
bgtu illegal_syscall
410412

411-
slli r8, r27, 3 # get syscall routine
413+
slli r8, r27, 2 # get syscall routine
412414
la r11, sys_call_table
413415
add r11, r11, r8
414416
lw r10, [r11] # get syscall entry
415-
lw r11, [r11, 4] # get number of args
416417

417418
cmpz.c r10
418419
beq illegal_syscall
419420

420-
cmpi.c r11, 4 # more than 4 arguments?
421-
bgtu stackargs
422-
423-
stack_done:
424421
lw r8, [r28, TI_FLAGS]
425422
li r9, _TIF_SYSCALL_TRACE
426423
and.c r8, r8, r9
@@ -475,44 +472,6 @@ syscall_trace_entry:
475472
1: sw r4, [r0, PT_R2] # result
476473
j syscall_exit
477474

478-
stackargs:
479-
lw r8, [r0, PT_R0]
480-
andri.c r9, r8, 3 # test whether user sp is align a word
481-
bne bad_stack
482-
subi r11, 5
483-
slli r9, r11, 2
484-
add.c r9, r9, r8
485-
486-
bmi bad_stack
487-
la r9, 3f # calculate branch address
488-
slli r11, r11, 3
489-
sub r9, r9, r11
490-
br r9
491-
492-
2: lw r9, [r8, 20] # argument 6 from usp
493-
sw r9, [r0, 20]
494-
495-
3: lw r9, [r8, 16] # argument 5 from usp
496-
sw r9, [r0, 16]
497-
j stack_done
498-
499-
.section __ex_table,"a"
500-
.word 2b, bad_stack
501-
.word 3b, bad_stack
502-
.previous
503-
504-
/*
505-
* The stackpointer for a call with more than 4 arguments is bad.
506-
* We probably should handle this case a bit more drastic.
507-
*/
508-
bad_stack:
509-
neg r27, r27 # error
510-
sw r27, [r0, PT_ORIG_R4]
511-
sw r27, [r0, PT_R4]
512-
ldi r8, 1 # set error flag
513-
sw r8, [r0, PT_R7]
514-
j syscall_return
515-
516475
illegal_syscall:
517476
ldi r4, -ENOSYS # error
518477
sw r4, [r0, PT_ORIG_R4]

‎arch/score/kernel/sys_call_table.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <linux/syscalls.h>
2+
#include <linux/signal.h>
3+
#include <linux/unistd.h>
4+
5+
#include <asm/syscalls.h>
6+
7+
#undef __SYSCALL
8+
#define __SYSCALL(nr, call) [nr] = (call),
9+
10+
void *sys_call_table[__NR_syscalls] = {
11+
#include <asm/unistd.h>
12+
};

‎arch/score/kernel/sys_score.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,7 @@ int score_clone(struct pt_regs *regs)
7575
if (!newsp)
7676
newsp = regs->regs[0];
7777
parent_tidptr = (int __user *)regs->regs[6];
78-
79-
child_tidptr = NULL;
80-
if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
81-
int __user *__user *usp = (int __user *__user *)regs->regs[0];
82-
83-
if (get_user(child_tidptr, &usp[4]))
84-
return -EFAULT;
85-
}
78+
child_tidptr = (int __user *)regs->regs[8];
8679

8780
return do_fork(clone_flags, newsp, regs, 0,
8881
parent_tidptr, child_tidptr);

0 commit comments

Comments
 (0)