Path: blob/master/arch/cris/arch-v32/kernel/process.c
15125 views
/*1* Copyright (C) 2000-2003 Axis Communications AB2*3* Authors: Bjorn Wesen ([email protected])4* Mikael Starvik ([email protected])5* Tobias Anderberg ([email protected]), CRISv32 port.6*7* This file handles the architecture-dependent parts of process handling..8*/910#include <linux/sched.h>11#include <linux/slab.h>12#include <linux/err.h>13#include <linux/fs.h>14#include <hwregs/reg_rdwr.h>15#include <hwregs/reg_map.h>16#include <hwregs/timer_defs.h>17#include <hwregs/intr_vect_defs.h>1819extern void stop_watchdog(void);2021extern int cris_hlt_counter;2223/* We use this if we don't have any better idle routine. */24void default_idle(void)25{26local_irq_disable();27if (!need_resched() && !cris_hlt_counter) {28/* Halt until exception. */29__asm__ volatile("ei \n\t"30"halt ");31}32local_irq_enable();33}3435/*36* Free current thread data structures etc..37*/3839extern void deconfigure_bp(long pid);40void exit_thread(void)41{42deconfigure_bp(current->pid);43}4445/*46* If the watchdog is enabled, disable interrupts and enter an infinite loop.47* The watchdog will reset the CPU after 0.1s. If the watchdog isn't enabled48* then enable it and wait.49*/50extern void arch_enable_nmi(void);5152void53hard_reset_now(void)54{55/*56* Don't declare this variable elsewhere. We don't want any other57* code to know about it than the watchdog handler in entry.S and58* this code, implementing hard reset through the watchdog.59*/60#if defined(CONFIG_ETRAX_WATCHDOG)61extern int cause_of_death;62#endif6364printk("*** HARD RESET ***\n");65local_irq_disable();6667#if defined(CONFIG_ETRAX_WATCHDOG)68cause_of_death = 0xbedead;69#else70{71reg_timer_rw_wd_ctrl wd_ctrl = {0};7273stop_watchdog();7475wd_ctrl.key = 16; /* Arbitrary key. */76wd_ctrl.cnt = 1; /* Minimum time. */77wd_ctrl.cmd = regk_timer_start;7879arch_enable_nmi();80REG_WR(timer, regi_timer0, rw_wd_ctrl, wd_ctrl);81}82#endif8384while (1)85; /* Wait for reset. */86}8788/*89* Return saved PC of a blocked thread.90*/91unsigned long thread_saved_pc(struct task_struct *t)92{93return task_pt_regs(t)->erp;94}9596static void97kernel_thread_helper(void* dummy, int (*fn)(void *), void * arg)98{99fn(arg);100do_exit(-1); /* Should never be called, return bad exit value. */101}102103/* Create a kernel thread. */104int105kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)106{107struct pt_regs regs;108109memset(®s, 0, sizeof(regs));110111/* Don't use r10 since that is set to 0 in copy_thread. */112regs.r11 = (unsigned long) fn;113regs.r12 = (unsigned long) arg;114regs.erp = (unsigned long) kernel_thread_helper;115regs.ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);116117/* Create the new process. */118return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, ®s, 0, NULL, NULL);119}120121/*122* Setup the child's kernel stack with a pt_regs and call switch_stack() on it.123* It will be unnested during _resume and _ret_from_sys_call when the new thread124* is scheduled.125*126* Also setup the thread switching structure which is used to keep127* thread-specific data during _resumes.128*/129130extern asmlinkage void ret_from_fork(void);131132int133copy_thread(unsigned long clone_flags, unsigned long usp,134unsigned long unused,135struct task_struct *p, struct pt_regs *regs)136{137struct pt_regs *childregs;138struct switch_stack *swstack;139140/*141* Put the pt_regs structure at the end of the new kernel stack page and142* fix it up. Note: the task_struct doubles as the kernel stack for the143* task.144*/145childregs = task_pt_regs(p);146*childregs = *regs; /* Struct copy of pt_regs. */147p->set_child_tid = p->clear_child_tid = NULL;148childregs->r10 = 0; /* Child returns 0 after a fork/clone. */149150/* Set a new TLS ?151* The TLS is in $mof because it is the 5th argument to sys_clone.152*/153if (p->mm && (clone_flags & CLONE_SETTLS)) {154task_thread_info(p)->tls = regs->mof;155}156157/* Put the switch stack right below the pt_regs. */158swstack = ((struct switch_stack *) childregs) - 1;159160/* Parameter to ret_from_sys_call. 0 is don't restart the syscall. */161swstack->r9 = 0;162163/*164* We want to return into ret_from_sys_call after the _resume.165* ret_from_fork will call ret_from_sys_call.166*/167swstack->return_ip = (unsigned long) ret_from_fork;168169/* Fix the user-mode and kernel-mode stackpointer. */170p->thread.usp = usp;171p->thread.ksp = (unsigned long) swstack;172173return 0;174}175176/*177* Be aware of the "magic" 7th argument in the four system-calls below.178* They need the latest stackframe, which is put as the 7th argument by179* entry.S. The previous arguments are dummies or actually used, but need180* to be defined to reach the 7th argument.181*182* N.B.: Another method to get the stackframe is to use current_regs(). But183* it returns the latest stack-frame stacked when going from _user mode_ and184* some of these (at least sys_clone) are called from kernel-mode sometimes185* (for example during kernel_thread, above) and thus cannot use it. Thus,186* to be sure not to get any surprises, we use the method for the other calls187* as well.188*/189asmlinkage int190sys_fork(long r10, long r11, long r12, long r13, long mof, long srp,191struct pt_regs *regs)192{193return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);194}195196/* FIXME: Is parent_tid/child_tid really third/fourth argument? Update lib? */197asmlinkage int198sys_clone(unsigned long newusp, unsigned long flags, int *parent_tid, int *child_tid,199unsigned long tls, long srp, struct pt_regs *regs)200{201if (!newusp)202newusp = rdusp();203204return do_fork(flags, newusp, regs, 0, parent_tid, child_tid);205}206207/*208* vfork is a system call in i386 because of register-pressure - maybe209* we can remove it and handle it in libc but we put it here until then.210*/211asmlinkage int212sys_vfork(long r10, long r11, long r12, long r13, long mof, long srp,213struct pt_regs *regs)214{215return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);216}217218/* sys_execve() executes a new program. */219asmlinkage int220sys_execve(const char *fname,221const char *const *argv,222const char *const *envp, long r13, long mof, long srp,223struct pt_regs *regs)224{225int error;226char *filename;227228filename = getname(fname);229error = PTR_ERR(filename);230231if (IS_ERR(filename))232goto out;233234error = do_execve(filename, argv, envp, regs);235putname(filename);236out:237return error;238}239240unsigned long241get_wchan(struct task_struct *p)242{243/* TODO */244return 0;245}246#undef last_sched247#undef first_sched248249void show_regs(struct pt_regs * regs)250{251unsigned long usp = rdusp();252printk("ERP: %08lx SRP: %08lx CCS: %08lx USP: %08lx MOF: %08lx\n",253regs->erp, regs->srp, regs->ccs, usp, regs->mof);254255printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",256regs->r0, regs->r1, regs->r2, regs->r3);257258printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",259regs->r4, regs->r5, regs->r6, regs->r7);260261printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",262regs->r8, regs->r9, regs->r10, regs->r11);263264printk("r12: %08lx r13: %08lx oR10: %08lx\n",265regs->r12, regs->r13, regs->orig_r10);266}267268269