Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 340301
b: refs/heads/master
c: 69b58a6
h: refs/heads/master
i:
  340299: 0685dda
v: v3
  • Loading branch information
Al Viro committed Oct 15, 2012
1 parent 6a6ec75 commit f5288b2
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 144 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 999121a10cbf091cdb3c168754de6ddf1992e656
refs/heads/master: 69b58a67213506f98835b0ee8cf24324f59a1442
2 changes: 0 additions & 2 deletions trunk/arch/blackfin/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ config BLACKFIN
select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
select HAVE_MOD_ARCH_SPECIFIC
select MODULES_USE_ELF_RELA
select GENERIC_KERNEL_THREAD
select GENERIC_KERNEL_EXECVE

config GENERIC_CSUM
def_bool y
Expand Down
2 changes: 2 additions & 0 deletions trunk/arch/blackfin/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ static inline void release_thread(struct task_struct *dead_task)
{
}

extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);

/*
* Free current thread data structures etc..
*/
Expand Down
1 change: 0 additions & 1 deletion trunk/arch/blackfin/include/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@
#define __ARCH_WANT_SYS_NICE
#define __ARCH_WANT_SYS_RT_SIGACTION
#define __ARCH_WANT_SYS_RT_SIGSUSPEND
#define __ARCH_WANT_SYS_EXECVE

/*
* "Conditional" syscalls
Expand Down
22 changes: 14 additions & 8 deletions trunk/arch/blackfin/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ ENTRY(_ret_from_fork)
SP += -12;
pseudo_long_call _schedule_tail, p5;
SP += 12;
p1 = [sp++];
r0 = [sp++];
cc = p1 == 0;
if cc jump .Lfork;
sp += -12;
call (p1);
sp += 12;
.Lfork:
r0 = [sp + PT_IPEND];
cc = bittst(r0,1);
if cc jump .Lin_kernel;
RESTORE_CONTEXT
rti;
.Lin_kernel:
bitclr(r0,1);
[sp + PT_IPEND] = r0;
/* do a 'fake' RTI by jumping to [RETI]
* to avoid clearing supervisor mode in child
*/
r0 = [sp + PT_PC];
[sp + PT_P0] = r0;

RESTORE_ALL_SYS
jump (p0);
ENDPROC(_ret_from_fork)

ENTRY(_sys_vfork)
Expand Down
75 changes: 58 additions & 17 deletions trunk/arch/blackfin/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@ void cpu_idle(void)
}
}

/*
* This gets run with P1 containing the
* function to call, and R1 containing
* the "args". Note P0 is clobbered on the way here.
*/
void kernel_thread_helper(void);
__asm__(".section .text\n"
".align 4\n"
"_kernel_thread_helper:\n\t"
"\tsp += -12;\n\t"
"\tr0 = r1;\n\t" "\tcall (p1);\n\t" "\tcall _do_exit;\n" ".previous");

/*
* Create a kernel thread.
*/
pid_t kernel_thread(int (*fn) (void *), void *arg, unsigned long flags)
{
struct pt_regs regs;

memset(&regs, 0, sizeof(regs));

regs.r1 = (unsigned long)arg;
regs.p1 = (unsigned long)fn;
regs.pc = (unsigned long)kernel_thread_helper;
regs.orig_p0 = -1;
/* Set bit 2 to tell ret_from_fork we should be returning to kernel
mode. */
regs.ipend = 0x8002;
__asm__ __volatile__("%0 = syscfg;":"=da"(regs.syscfg):);
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
NULL);
}
EXPORT_SYMBOL(kernel_thread);

/*
* Do necessary setup to start up a newly executed thread.
*
Expand Down Expand Up @@ -159,31 +193,38 @@ copy_thread(unsigned long clone_flags,
struct task_struct *p, struct pt_regs *regs)
{
struct pt_regs *childregs;
unsigned long *v;

childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
v = ((unsigned long *)childregs) - 2;
if (unlikely(!regs)) {
memset(childregs, 0, sizeof(struct pt_regs));
v[0] = usp;
v[1] = topstk;
childregs->orig_p0 = -1;
childregs->ipend = 0x8000;
__asm__ __volatile__("%0 = syscfg;":"=da"(childregs->syscfg):);
p->thread.usp = 0;
} else {
*childregs = *regs;
childregs->r0 = 0;
p->thread.usp = usp;
v[0] = v[1] = 0;
}
*childregs = *regs;
childregs->r0 = 0;

p->thread.ksp = (unsigned long)v;
p->thread.usp = usp;
p->thread.ksp = (unsigned long)childregs;
p->thread.pc = (unsigned long)ret_from_fork;

return 0;
}

/*
* sys_execve() executes a new program.
*/
asmlinkage int sys_execve(const char __user *name,
const char __user *const __user *argv,
const char __user *const __user *envp)
{
int error;
struct filename *filename;
struct pt_regs *regs = (struct pt_regs *)((&name) + 6);

filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
return error;
}

unsigned long get_wchan(struct task_struct *p)
{
unsigned long fp, pc;
Expand Down
55 changes: 55 additions & 0 deletions trunk/arch/blackfin/mach-common/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,61 @@ ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
jump .Lsyscall_really_exit;
ENDPROC(_trap)

ENTRY(_kernel_execve)
link SIZEOF_PTREGS;
p0 = sp;
r3 = SIZEOF_PTREGS / 4;
r4 = 0(x);
.Lclear_regs:
[p0++] = r4;
r3 += -1;
cc = r3 == 0;
if !cc jump .Lclear_regs (bp);

p0 = sp;
sp += -16;
[sp + 12] = p0;
pseudo_long_call _do_execve, p5;
SP += 16;
cc = r0 == 0;
if ! cc jump .Lexecve_failed;
/* Success. Copy our temporary pt_regs to the top of the kernel
* stack and do a normal exception return.
*/
r1 = sp;
r0 = (-KERNEL_STACK_SIZE) (x);
r1 = r1 & r0;
p2 = r1;
p3 = [p2];
r0 = KERNEL_STACK_SIZE - 4 (z);
p1 = r0;
p1 = p1 + p2;

p0 = fp;
r4 = [p0--];
r3 = SIZEOF_PTREGS / 4;
.Lcopy_regs:
r4 = [p0--];
[p1--] = r4;
r3 += -1;
cc = r3 == 0;
if ! cc jump .Lcopy_regs (bp);

r0 = (KERNEL_STACK_SIZE - SIZEOF_PTREGS) (z);
p1 = r0;
p1 = p1 + p2;
sp = p1;
r0 = syscfg;
[SP + PT_SYSCFG] = r0;
[p3 + (TASK_THREAD + THREAD_KSP)] = sp;

RESTORE_CONTEXT;
rti;
.Lexecve_failed:
unlink;
rts;
ENDPROC(_kernel_execve)

ENTRY(_system_call)
/* Store IPEND */
p2.l = lo(IPEND);
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/cris/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config CRIS
select GENERIC_SMP_IDLE_THREAD if ETRAX_ARCH_V32
select GENERIC_CMOS_UPDATE
select MODULES_USE_ELF_RELA
select GENERIC_KERNEL_THREAD

config HZ
int
Expand Down
10 changes: 9 additions & 1 deletion trunk/arch/cris/arch-v10/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
.globl system_call
.globl ret_from_intr
.globl ret_from_fork
.globl ret_from_kernel_thread
.globl resume
.globl multiple_interrupt
.globl hwbreakpoint
Expand Down Expand Up @@ -81,7 +82,14 @@ ret_from_fork:
jsr schedule_tail
ba ret_from_sys_call
nop


ret_from_kernel_thread:
jsr schedule_tail
move.d $r2, $r10 ; argument is here
jsr $r1 ; call the payload
moveq 0, $r10
jsr sys_exit ; never returns

ret_from_intr:
;; check for resched if preemptive kernel or if we're going back to user-mode
;; this test matches the user_regs(regs) macro
Expand Down
83 changes: 24 additions & 59 deletions trunk/arch/cris/arch-v10/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <arch/svinto.h>
#include <linux/init.h>
#include <arch/system.h>
#include <asm/ptrace.h>

#ifdef CONFIG_ETRAX_GPIO
void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
Expand Down Expand Up @@ -81,31 +82,6 @@ unsigned long thread_saved_pc(struct task_struct *t)
return task_pt_regs(t)->irp;
}

static void kernel_thread_helper(void* dummy, int (*fn)(void *), void * arg)
{
fn(arg);
do_exit(-1); /* Should never be called, return bad exit value */
}

/*
* Create a kernel thread
*/
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
struct pt_regs regs;

memset(&regs, 0, sizeof(regs));

/* Don't use r10 since that is set to 0 in copy_thread */
regs.r11 = (unsigned long)fn;
regs.r12 = (unsigned long)arg;
regs.irp = (unsigned long)kernel_thread_helper;
regs.dccr = 1 << I_DCCR_BITNR;

/* Ok, create the new process.. */
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}

/* setup the child's kernel stack with a pt_regs and switch_stack on it.
* it will be un-nested during _resume and _ret_from_sys_call when the
* new thread is scheduled.
Expand All @@ -115,29 +91,35 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
*
*/
asmlinkage void ret_from_fork(void);
asmlinkage void ret_from_kernel_thread(void);

int copy_thread(unsigned long clone_flags, unsigned long usp,
unsigned long unused,
unsigned long arg,
struct task_struct *p, struct pt_regs *regs)
{
struct pt_regs * childregs;
struct switch_stack *swstack;
struct pt_regs *childregs = task_pt_regs(p);
struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;

/* put the pt_regs structure at the end of the new kernel stack page and fix it up
* remember that the task_struct doubles as the kernel stack for the task
*/

childregs = task_pt_regs(p);

if (unlikely(p->flags & PF_KTHREAD)) {
memset(swstack, 0,
sizeof(struct switch_stack) + sizeof(struct pt_regs));
swstack->r1 = usp;
swstack->r2 = arg;
childregs->dccr = 1 << I_DCCR_BITNR;
swstack->return_ip = (unsigned long) ret_from_kernel_thread;
p->thread.ksp = (unsigned long) swstack;
p->thread.usp = 0;
return 0;
}
*childregs = *regs; /* struct copy of pt_regs */

p->set_child_tid = p->clear_child_tid = NULL;

childregs->r10 = 0; /* child returns 0 after a fork/clone */

/* put the switch stack right below the pt_regs */

swstack = ((struct switch_stack *)childregs) - 1;
/* put the switch stack right below the pt_regs */

swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */

Expand All @@ -147,7 +129,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,

/* fix the user-mode stackpointer */

p->thread.usp = usp;
p->thread.usp = usp;

/* and the kernel-mode one */

Expand All @@ -161,45 +143,28 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
return 0;
}

/*
* Be aware of the "magic" 7th argument in the four system-calls below.
* They need the latest stackframe, which is put as the 7th argument by
* entry.S. The previous arguments are dummies or actually used, but need
* to be defined to reach the 7th argument.
*
* N.B.: Another method to get the stackframe is to use current_regs(). But
* it returns the latest stack-frame stacked when going from _user mode_ and
* some of these (at least sys_clone) are called from kernel-mode sometimes
* (for example during kernel_thread, above) and thus cannot use it. Thus,
* to be sure not to get any surprises, we use the method for the other calls
* as well.
*/

asmlinkage int sys_fork(long r10, long r11, long r12, long r13, long mof, long srp,
struct pt_regs *regs)
asmlinkage int sys_fork(void)
{
return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
return do_fork(SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

/* if newusp is 0, we just grab the old usp */
/* FIXME: Is parent_tid/child_tid really third/fourth argument? Update lib? */
asmlinkage int sys_clone(unsigned long newusp, unsigned long flags,
int* parent_tid, int* child_tid, long mof, long srp,
struct pt_regs *regs)
int* parent_tid, int* child_tid)
{
if (!newusp)
newusp = rdusp();
return do_fork(flags, newusp, regs, 0, parent_tid, child_tid);
return do_fork(flags, newusp, current_pt_regs(), 0, parent_tid, child_tid);
}

/* vfork is a system call in i386 because of register-pressure - maybe
* we can remove it and handle it in libc but we put it here until then.
*/

asmlinkage int sys_vfork(long r10, long r11, long r12, long r13, long mof, long srp,
struct pt_regs *regs)
asmlinkage int sys_vfork(void)
{
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

/*
Expand Down
Loading

0 comments on commit f5288b2

Please sign in to comment.