/*1* arch/score/kernel/process.c2*3* Score Processor version.4*5* Copyright (C) 2009 Sunplus Core Technology Co., Ltd.6* Chen Liqin <[email protected]>7* Lennox Wu <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, see the file COPYING, or write21* to the Free Software Foundation, Inc.,22* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA23*/2425#include <linux/module.h>26#include <linux/reboot.h>27#include <linux/elfcore.h>28#include <linux/pm.h>2930void (*pm_power_off)(void);31EXPORT_SYMBOL(pm_power_off);3233/* If or when software machine-restart is implemented, add code here. */34void machine_restart(char *command) {}3536/* If or when software machine-halt is implemented, add code here. */37void machine_halt(void) {}3839/* If or when software machine-power-off is implemented, add code here. */40void machine_power_off(void) {}4142/*43* The idle thread. There's no useful work to be44* done, so just try to conserve power and have a45* low exit latency (ie sit in a loop waiting for46* somebody to say that they'd like to reschedule)47*/48void __noreturn cpu_idle(void)49{50/* endless idle loop with no priority at all */51while (1) {52while (!need_resched())53barrier();5455preempt_enable_no_resched();56schedule();57preempt_disable();58}59}6061void ret_from_fork(void);6263void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)64{65unsigned long status;6667/* New thread loses kernel privileges. */68status = regs->cp0_psr & ~(KU_MASK);69status |= KU_USER;70regs->cp0_psr = status;71regs->cp0_epc = pc;72regs->regs[0] = sp;73}7475void exit_thread(void) {}7677/*78* When a process does an "exec", machine state like FPU and debug79* registers need to be reset. This is a hook function for that.80* Currently we don't have any such state to reset, so this is empty.81*/82void flush_thread(void) {}8384/*85* set up the kernel stack and exception frames for a new process86*/87int copy_thread(unsigned long clone_flags, unsigned long usp,88unsigned long unused,89struct task_struct *p, struct pt_regs *regs)90{91struct thread_info *ti = task_thread_info(p);92struct pt_regs *childregs = task_pt_regs(p);9394p->set_child_tid = NULL;95p->clear_child_tid = NULL;9697*childregs = *regs;98childregs->regs[7] = 0; /* Clear error flag */99childregs->regs[4] = 0; /* Child gets zero as return value */100regs->regs[4] = p->pid;101102if (childregs->cp0_psr & 0x8) { /* test kernel fork or user fork */103childregs->regs[0] = usp; /* user fork */104} else {105childregs->regs[28] = (unsigned long) ti; /* kernel fork */106childregs->regs[0] = (unsigned long) childregs;107}108109p->thread.reg0 = (unsigned long) childregs;110p->thread.reg3 = (unsigned long) ret_from_fork;111p->thread.cp0_psr = 0;112113return 0;114}115116/* Fill in the fpu structure for a core dump. */117int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)118{119return 1;120}121122static void __noreturn123kernel_thread_helper(void *unused0, int (*fn)(void *),124void *arg, void *unused1)125{126do_exit(fn(arg));127}128129/*130* Create a kernel thread.131*/132long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)133{134struct pt_regs regs;135136memset(®s, 0, sizeof(regs));137138regs.regs[6] = (unsigned long) arg;139regs.regs[5] = (unsigned long) fn;140regs.cp0_epc = (unsigned long) kernel_thread_helper;141regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \142((regs.cp0_psr & 0x3) << 2);143144return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \1450, ®s, 0, NULL, NULL);146}147148unsigned long thread_saved_pc(struct task_struct *tsk)149{150return task_pt_regs(tsk)->cp0_epc;151}152153unsigned long get_wchan(struct task_struct *task)154{155if (!task || task == current || task->state == TASK_RUNNING)156return 0;157158if (!task_stack_page(task))159return 0;160161return task_pt_regs(task)->cp0_epc;162}163164unsigned long arch_align_stack(unsigned long sp)165{166return sp;167}168169170