blob: a1519ad3d49d68e0e3202ecadb5b6e1b027a7df3 [file] [log] [blame]
Chen Liqin6bc9a392009-06-12 22:01:00 +08001/*
2 * arch/score/kernel/process.c
3 *
4 * Score Processor version.
5 *
6 * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
7 * Chen Liqin <liqin.chen@sunplusct.com>
8 * Lennox Wu <lennox.wu@sunplusct.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see the file COPYING, or write
22 * to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <linux/module.h>
Arnd Bergmann9fb24cc2009-06-27 14:50:51 +020027#include <linux/reboot.h>
28#include <linux/elfcore.h>
29#include <linux/pm.h>
Frederic Weisbecker0ee23fd2012-08-22 17:27:34 +020030#include <linux/rcupdate.h>
Chen Liqin6bc9a392009-06-12 22:01:00 +080031
32void (*pm_power_off)(void);
33EXPORT_SYMBOL(pm_power_off);
34
35/* If or when software machine-restart is implemented, add code here. */
36void machine_restart(char *command) {}
37
38/* If or when software machine-halt is implemented, add code here. */
39void machine_halt(void) {}
40
41/* If or when software machine-power-off is implemented, add code here. */
42void machine_power_off(void) {}
43
Chen Liqin0402c912009-06-19 13:53:49 +080044void ret_from_fork(void);
Al Viro1856ab62012-10-15 15:26:11 -040045void ret_from_kernel_thread(void);
Chen Liqin6bc9a392009-06-12 22:01:00 +080046
47void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
48{
49 unsigned long status;
50
51 /* New thread loses kernel privileges. */
52 status = regs->cp0_psr & ~(KU_MASK);
53 status |= KU_USER;
54 regs->cp0_psr = status;
55 regs->cp0_epc = pc;
56 regs->regs[0] = sp;
57}
58
59void exit_thread(void) {}
60
61/*
62 * When a process does an "exec", machine state like FPU and debug
63 * registers need to be reset. This is a hook function for that.
64 * Currently we don't have any such state to reset, so this is empty.
65 */
66void flush_thread(void) {}
67
68/*
69 * set up the kernel stack and exception frames for a new process
70 */
71int copy_thread(unsigned long clone_flags, unsigned long usp,
Al Viroafa86fc2012-10-22 22:51:14 -040072 unsigned long arg, struct task_struct *p)
Chen Liqin6bc9a392009-06-12 22:01:00 +080073{
74 struct thread_info *ti = task_thread_info(p);
75 struct pt_regs *childregs = task_pt_regs(p);
Al Viroafa86fc2012-10-22 22:51:14 -040076 struct pt_regs *regs = current_pt_regs();
Chen Liqin6bc9a392009-06-12 22:01:00 +080077
Al Viro1856ab62012-10-15 15:26:11 -040078 p->thread.reg0 = (unsigned long) childregs;
Al Viroeda96972012-10-21 16:44:57 -040079 if (unlikely(p->flags & PF_KTHREAD)) {
Al Viro1856ab62012-10-15 15:26:11 -040080 memset(childregs, 0, sizeof(struct pt_regs));
Lennox Wu5fbbf8a2013-09-14 13:48:37 +080081 p->thread.reg12 = usp;
82 p->thread.reg13 = arg;
Al Viro1856ab62012-10-15 15:26:11 -040083 p->thread.reg3 = (unsigned long) ret_from_kernel_thread;
Chen Liqin6bc9a392009-06-12 22:01:00 +080084 } else {
Al Viroeda96972012-10-21 16:44:57 -040085 *childregs = *current_pt_regs();
Al Viro1856ab62012-10-15 15:26:11 -040086 childregs->regs[7] = 0; /* Clear error flag */
87 childregs->regs[4] = 0; /* Child gets zero as return value */
Al Viroeda96972012-10-21 16:44:57 -040088 if (usp)
89 childregs->regs[0] = usp; /* user fork */
Al Viro1856ab62012-10-15 15:26:11 -040090 p->thread.reg3 = (unsigned long) ret_from_fork;
Chen Liqin6bc9a392009-06-12 22:01:00 +080091 }
92
Chen Liqin6bc9a392009-06-12 22:01:00 +080093 p->thread.cp0_psr = 0;
94
95 return 0;
96}
97
98/* Fill in the fpu structure for a core dump. */
99int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
100{
101 return 1;
102}
103
Chen Liqin6bc9a392009-06-12 22:01:00 +0800104unsigned long thread_saved_pc(struct task_struct *tsk)
105{
106 return task_pt_regs(tsk)->cp0_epc;
107}
108
109unsigned long get_wchan(struct task_struct *task)
110{
111 if (!task || task == current || task->state == TASK_RUNNING)
112 return 0;
113
114 if (!task_stack_page(task))
115 return 0;
116
117 return task_pt_regs(task)->cp0_epc;
118}
119
120unsigned long arch_align_stack(unsigned long sp)
121{
122 return sp;
123}