/*1* PARISC Architecture-dependent parts of process handling2* based on the work for i3863*4* Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>5* Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>6* Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>7* Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>8* Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>9* Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>10* Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>11* Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>12* Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>13* Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>14* Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>15* Copyright (C) 2001-2007 Helge Deller <deller at parisc-linux.org>16* Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>17*18*19* This program is free software; you can redistribute it and/or modify20* it under the terms of the GNU General Public License as published by21* the Free Software Foundation; either version 2 of the License, or22* (at your option) any later version.23*24* This program is distributed in the hope that it will be useful,25* but WITHOUT ANY WARRANTY; without even the implied warranty of26* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the27* GNU General Public License for more details.28*29* You should have received a copy of the GNU General Public License30* along with this program; if not, write to the Free Software31* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA32*/3334#include <stdarg.h>3536#include <linux/elf.h>37#include <linux/errno.h>38#include <linux/kernel.h>39#include <linux/mm.h>40#include <linux/fs.h>41#include <linux/module.h>42#include <linux/personality.h>43#include <linux/ptrace.h>44#include <linux/sched.h>45#include <linux/slab.h>46#include <linux/stddef.h>47#include <linux/unistd.h>48#include <linux/kallsyms.h>49#include <linux/uaccess.h>5051#include <asm/io.h>52#include <asm/asm-offsets.h>53#include <asm/pdc.h>54#include <asm/pdc_chassis.h>55#include <asm/pgalloc.h>56#include <asm/unwind.h>57#include <asm/sections.h>5859/*60* The idle thread. There's no useful work to be61* done, so just try to conserve power and have a62* low exit latency (ie sit in a loop waiting for63* somebody to say that they'd like to reschedule)64*/65void cpu_idle(void)66{67set_thread_flag(TIF_POLLING_NRFLAG);6869/* endless idle loop with no priority at all */70while (1) {71while (!need_resched())72barrier();73preempt_enable_no_resched();74schedule();75preempt_disable();76check_pgt_cache();77}78}798081#define COMMAND_GLOBAL F_EXTEND(0xfffe0030)82#define CMD_RESET 5 /* reset any module */8384/*85** The Wright Brothers and Gecko systems have a H/W problem86** (Lasi...'nuf said) may cause a broadcast reset to lockup87** the system. An HVERSION dependent PDC call was developed88** to perform a "safe", platform specific broadcast reset instead89** of kludging up all the code.90**91** Older machines which do not implement PDC_BROADCAST_RESET will92** return (with an error) and the regular broadcast reset can be93** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET94** the PDC call will not return (the system will be reset).95*/96void machine_restart(char *cmd)97{98#ifdef FASTBOOT_SELFTEST_SUPPORT99/*100** If user has modified the Firmware Selftest Bitmap,101** run the tests specified in the bitmap after the102** system is rebooted w/PDC_DO_RESET.103**104** ftc_bitmap = 0x1AUL "Skip destructive memory tests"105**106** Using "directed resets" at each processor with the MEM_TOC107** vector cleared will also avoid running destructive108** memory self tests. (Not implemented yet)109*/110if (ftc_bitmap) {111pdc_do_firm_test_reset(ftc_bitmap);112}113#endif114/* set up a new led state on systems shipped with a LED State panel */115pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);116117/* "Normal" system reset */118pdc_do_reset();119120/* Nope...box should reset with just CMD_RESET now */121gsc_writel(CMD_RESET, COMMAND_GLOBAL);122123/* Wait for RESET to lay us to rest. */124while (1) ;125126}127128void machine_halt(void)129{130/*131** The LED/ChassisCodes are updated by the led_halt()132** function, called by the reboot notifier chain.133*/134}135136void (*chassis_power_off)(void);137138/*139* This routine is called from sys_reboot to actually turn off the140* machine141*/142void machine_power_off(void)143{144/* If there is a registered power off handler, call it. */145if (chassis_power_off)146chassis_power_off();147148/* Put the soft power button back under hardware control.149* If the user had already pressed the power button, the150* following call will immediately power off. */151pdc_soft_power_button(0);152153pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);154155/* It seems we have no way to power the system off via156* software. The user has to press the button himself. */157158printk(KERN_EMERG "System shut down completed.\n"159"Please power this system off now.");160}161162void (*pm_power_off)(void) = machine_power_off;163EXPORT_SYMBOL(pm_power_off);164165/*166* Create a kernel thread167*/168169extern pid_t __kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);170pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)171{172173/*174* FIXME: Once we are sure we don't need any debug here,175* kernel_thread can become a #define.176*/177178return __kernel_thread(fn, arg, flags);179}180EXPORT_SYMBOL(kernel_thread);181182/*183* Free current thread data structures etc..184*/185void exit_thread(void)186{187}188189void flush_thread(void)190{191/* Only needs to handle fpu stuff or perf monitors.192** REVISIT: several arches implement a "lazy fpu state".193*/194set_fs(USER_DS);195}196197void release_thread(struct task_struct *dead_task)198{199}200201/*202* Fill in the FPU structure for a core dump.203*/204205int dump_fpu (struct pt_regs * regs, elf_fpregset_t *r)206{207if (regs == NULL)208return 0;209210memcpy(r, regs->fr, sizeof *r);211return 1;212}213214int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)215{216memcpy(r, tsk->thread.regs.fr, sizeof(*r));217return 1;218}219220/* Note that "fork()" is implemented in terms of clone, with221parameters (SIGCHLD, regs->gr[30], regs). */222int223sys_clone(unsigned long clone_flags, unsigned long usp,224struct pt_regs *regs)225{226/* Arugments from userspace are:227r26 = Clone flags.228r25 = Child stack.229r24 = parent_tidptr.230r23 = Is the TLS storage descriptor231r22 = child_tidptr232233However, these last 3 args are only examined234if the proper flags are set. */235int __user *parent_tidptr = (int __user *)regs->gr[24];236int __user *child_tidptr = (int __user *)regs->gr[22];237238/* usp must be word aligned. This also prevents users from239* passing in the value 1 (which is the signal for a special240* return for a kernel thread) */241usp = ALIGN(usp, 4);242243/* A zero value for usp means use the current stack */244if (usp == 0)245usp = regs->gr[30];246247return do_fork(clone_flags, usp, regs, 0, parent_tidptr, child_tidptr);248}249250int251sys_vfork(struct pt_regs *regs)252{253return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gr[30], regs, 0, NULL, NULL);254}255256int257copy_thread(unsigned long clone_flags, unsigned long usp,258unsigned long unused, /* in ia64 this is "user_stack_size" */259struct task_struct * p, struct pt_regs * pregs)260{261struct pt_regs * cregs = &(p->thread.regs);262void *stack = task_stack_page(p);263264/* We have to use void * instead of a function pointer, because265* function pointers aren't a pointer to the function on 64-bit.266* Make them const so the compiler knows they live in .text */267extern void * const ret_from_kernel_thread;268extern void * const child_return;269#ifdef CONFIG_HPUX270extern void * const hpux_child_return;271#endif272273*cregs = *pregs;274275/* Set the return value for the child. Note that this is not276actually restored by the syscall exit path, but we put it277here for consistency in case of signals. */278cregs->gr[28] = 0; /* child */279280/*281* We need to differentiate between a user fork and a282* kernel fork. We can't use user_mode, because the283* the syscall path doesn't save iaoq. Right now284* We rely on the fact that kernel_thread passes285* in zero for usp.286*/287if (usp == 1) {288/* kernel thread */289cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN;290/* Must exit via ret_from_kernel_thread in order291* to call schedule_tail()292*/293cregs->kpc = (unsigned long) &ret_from_kernel_thread;294/*295* Copy function and argument to be called from296* ret_from_kernel_thread.297*/298#ifdef CONFIG_64BIT299cregs->gr[27] = pregs->gr[27];300#endif301cregs->gr[26] = pregs->gr[26];302cregs->gr[25] = pregs->gr[25];303} else {304/* user thread */305/*306* Note that the fork wrappers are responsible307* for setting gr[21].308*/309310/* Use same stack depth as parent */311cregs->ksp = (unsigned long)stack312+ (pregs->gr[21] & (THREAD_SIZE - 1));313cregs->gr[30] = usp;314if (p->personality == PER_HPUX) {315#ifdef CONFIG_HPUX316cregs->kpc = (unsigned long) &hpux_child_return;317#else318BUG();319#endif320} else {321cregs->kpc = (unsigned long) &child_return;322}323/* Setup thread TLS area from the 4th parameter in clone */324if (clone_flags & CLONE_SETTLS)325cregs->cr27 = pregs->gr[23];326327}328329return 0;330}331332unsigned long thread_saved_pc(struct task_struct *t)333{334return t->thread.regs.kpc;335}336337/*338* sys_execve() executes a new program.339*/340341asmlinkage int sys_execve(struct pt_regs *regs)342{343int error;344char *filename;345346filename = getname((const char __user *) regs->gr[26]);347error = PTR_ERR(filename);348if (IS_ERR(filename))349goto out;350error = do_execve(filename,351(const char __user *const __user *) regs->gr[25],352(const char __user *const __user *) regs->gr[24],353regs);354putname(filename);355out:356357return error;358}359360extern int __execve(const char *filename,361const char *const argv[],362const char *const envp[], struct task_struct *task);363int kernel_execve(const char *filename,364const char *const argv[],365const char *const envp[])366{367return __execve(filename, argv, envp, current);368}369370unsigned long371get_wchan(struct task_struct *p)372{373struct unwind_frame_info info;374unsigned long ip;375int count = 0;376377if (!p || p == current || p->state == TASK_RUNNING)378return 0;379380/*381* These bracket the sleeping functions..382*/383384unwind_frame_init_from_blocked_task(&info, p);385do {386if (unwind_once(&info) < 0)387return 0;388ip = info.ip;389if (!in_sched_functions(ip))390return ip;391} while (count++ < 16);392return 0;393}394395#ifdef CONFIG_64BIT396void *dereference_function_descriptor(void *ptr)397{398Elf64_Fdesc *desc = ptr;399void *p;400401if (!probe_kernel_address(&desc->addr, p))402ptr = p;403return ptr;404}405#endif406407408