2008-01-18 17:23:48 +03:00
|
|
|
/*
|
2005-04-17 02:20:36 +04:00
|
|
|
* linux/arch/cris/kernel/process.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
* Copyright (C) 2000-2002 Axis Communications AB
|
|
|
|
*
|
|
|
|
* Authors: Bjorn Wesen (bjornw@axis.com)
|
|
|
|
* Mikael Starvik (starvik@axis.com)
|
|
|
|
*
|
|
|
|
* This file handles the architecture-dependent parts of process handling..
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/fs.h>
|
2008-10-21 19:45:58 +04:00
|
|
|
#include <arch/svinto.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/init.h>
|
2012-03-28 21:30:02 +04:00
|
|
|
#include <arch/system.h>
|
2012-10-26 23:15:13 +04:00
|
|
|
#include <linux/ptrace.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_ETRAX_GPIO
|
|
|
|
void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We use this if we don't have any better
|
|
|
|
* idle routine..
|
|
|
|
*/
|
|
|
|
void default_idle(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_ETRAX_GPIO
|
|
|
|
etrax_gpio_wake_up_check();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free current thread data structures etc..
|
|
|
|
*/
|
|
|
|
|
|
|
|
void exit_thread(void)
|
|
|
|
{
|
|
|
|
/* Nothing needs to be done. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the watchdog is enabled, we can simply disable interrupts and go
|
|
|
|
* into an eternal loop, and the watchdog will reset the CPU after 0.1s
|
|
|
|
* if on the other hand the watchdog wasn't enabled, we just enable it and wait
|
|
|
|
*/
|
|
|
|
|
|
|
|
void hard_reset_now (void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Don't declare this variable elsewhere. We don't want any other
|
|
|
|
* code to know about it than the watchdog handler in entry.S and
|
|
|
|
* this code, implementing hard reset through the watchdog.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
|
|
|
|
extern int cause_of_death;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printk("*** HARD RESET ***\n");
|
|
|
|
local_irq_disable();
|
|
|
|
|
|
|
|
#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
|
|
|
|
cause_of_death = 0xbedead;
|
|
|
|
#else
|
2007-10-20 03:08:50 +04:00
|
|
|
/* Since we dont plan to keep on resetting the watchdog,
|
2005-04-17 02:20:36 +04:00
|
|
|
the key can be arbitrary hence three */
|
|
|
|
*R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
|
|
|
|
IO_STATE(R_WATCHDOG, enable, start);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while(1) /* waiting for RETRIBUTION! */ ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return saved PC of a blocked thread.
|
|
|
|
*/
|
|
|
|
unsigned long thread_saved_pc(struct task_struct *t)
|
|
|
|
{
|
2006-01-12 12:06:03 +03:00
|
|
|
return task_pt_regs(t)->irp;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
* also setup the thread switching structure which is used to keep
|
|
|
|
* thread-specific data during _resumes.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
asmlinkage void ret_from_fork(void);
|
2012-10-03 22:46:55 +04:00
|
|
|
asmlinkage void ret_from_kernel_thread(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-04-03 03:56:59 +04:00
|
|
|
int copy_thread(unsigned long clone_flags, unsigned long usp,
|
2012-10-03 22:46:55 +04:00
|
|
|
unsigned long arg,
|
2012-10-26 23:15:13 +04:00
|
|
|
struct task_struct *p, struct pt_regs *unused)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-10-03 22:46:55 +04:00
|
|
|
struct pt_regs *childregs = task_pt_regs(p);
|
|
|
|
struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
2012-10-03 22:46:55 +04:00
|
|
|
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;
|
|
|
|
}
|
2012-10-26 23:15:13 +04:00
|
|
|
*childregs = *current_pt_regs(); /* struct copy of pt_regs */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
childregs->r10 = 0; /* child returns 0 after a fork/clone */
|
|
|
|
|
2012-10-03 22:46:55 +04:00
|
|
|
/* put the switch stack right below the pt_regs */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
|
|
|
|
|
|
|
|
/* we want to return into ret_from_sys_call after the _resume */
|
|
|
|
|
|
|
|
swstack->return_ip = (unsigned long) ret_from_fork; /* Will call ret_from_sys_call */
|
|
|
|
|
|
|
|
/* fix the user-mode stackpointer */
|
|
|
|
|
2012-10-26 23:15:13 +04:00
|
|
|
p->thread.usp = usp ?: rdusp();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* and the kernel-mode one */
|
|
|
|
|
|
|
|
p->thread.ksp = (unsigned long) swstack;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
|
|
|
|
show_registers(childregs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long get_wchan(struct task_struct *p)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* YURGH. TODO. */
|
|
|
|
|
|
|
|
unsigned long ebp, esp, eip;
|
|
|
|
unsigned long stack_page;
|
|
|
|
int count = 0;
|
|
|
|
if (!p || p == current || p->state == TASK_RUNNING)
|
|
|
|
return 0;
|
|
|
|
stack_page = (unsigned long)p;
|
|
|
|
esp = p->thread.esp;
|
|
|
|
if (!stack_page || esp < stack_page || esp > 8188+stack_page)
|
|
|
|
return 0;
|
|
|
|
/* include/asm-i386/system.h:switch_to() pushes ebp last. */
|
|
|
|
ebp = *(unsigned long *) esp;
|
|
|
|
do {
|
|
|
|
if (ebp < stack_page || ebp > 8184+stack_page)
|
|
|
|
return 0;
|
|
|
|
eip = *(unsigned long *) (ebp+4);
|
|
|
|
if (!in_sched_functions(eip))
|
|
|
|
return eip;
|
|
|
|
ebp = *(unsigned long *) ebp;
|
|
|
|
} while (count++ < 16);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef last_sched
|
|
|
|
#undef first_sched
|
|
|
|
|
|
|
|
void show_regs(struct pt_regs * regs)
|
|
|
|
{
|
|
|
|
unsigned long usp = rdusp();
|
|
|
|
printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
|
|
|
|
regs->irp, regs->srp, regs->dccr, usp, regs->mof );
|
|
|
|
printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
|
|
|
|
regs->r0, regs->r1, regs->r2, regs->r3);
|
|
|
|
printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
|
|
|
|
regs->r4, regs->r5, regs->r6, regs->r7);
|
|
|
|
printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
|
|
|
|
regs->r8, regs->r9, regs->r10, regs->r11);
|
|
|
|
printk("r12: %08lx r13: %08lx oR10: %08lx\n",
|
|
|
|
regs->r12, regs->r13, regs->orig_r10);
|
|
|
|
}
|
|
|
|
|