diff options
Diffstat (limited to 'arch/score/kernel/process.c')
-rw-r--r-- | arch/score/kernel/process.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c new file mode 100644 index 00000000000..aaa3085251f --- /dev/null +++ b/arch/score/kernel/process.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /* | ||
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> | ||
27 | |||
28 | void (*pm_power_off)(void); | ||
29 | EXPORT_SYMBOL(pm_power_off); | ||
30 | |||
31 | /* If or when software machine-restart is implemented, add code here. */ | ||
32 | void machine_restart(char *command) {} | ||
33 | |||
34 | /* If or when software machine-halt is implemented, add code here. */ | ||
35 | void machine_halt(void) {} | ||
36 | |||
37 | /* If or when software machine-power-off is implemented, add code here. */ | ||
38 | void machine_power_off(void) {} | ||
39 | |||
40 | /* | ||
41 | * The idle thread. There's no useful work to be | ||
42 | * done, so just try to conserve power and have a | ||
43 | * low exit latency (ie sit in a loop waiting for | ||
44 | * somebody to say that they'd like to reschedule) | ||
45 | */ | ||
46 | void __noreturn cpu_idle(void) | ||
47 | { | ||
48 | /* endless idle loop with no priority at all */ | ||
49 | while (1) { | ||
50 | while (!need_resched()) | ||
51 | barrier(); | ||
52 | |||
53 | preempt_enable_no_resched(); | ||
54 | schedule(); | ||
55 | preempt_disable(); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | asmlinkage void ret_from_fork(void); | ||
60 | |||
61 | void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) | ||
62 | { | ||
63 | unsigned long status; | ||
64 | |||
65 | /* New thread loses kernel privileges. */ | ||
66 | status = regs->cp0_psr & ~(KU_MASK); | ||
67 | status |= KU_USER; | ||
68 | regs->cp0_psr = status; | ||
69 | regs->cp0_epc = pc; | ||
70 | regs->regs[0] = sp; | ||
71 | } | ||
72 | |||
73 | void exit_thread(void) {} | ||
74 | |||
75 | /* | ||
76 | * When a process does an "exec", machine state like FPU and debug | ||
77 | * registers need to be reset. This is a hook function for that. | ||
78 | * Currently we don't have any such state to reset, so this is empty. | ||
79 | */ | ||
80 | void flush_thread(void) {} | ||
81 | |||
82 | /* | ||
83 | * set up the kernel stack and exception frames for a new process | ||
84 | */ | ||
85 | int copy_thread(unsigned long clone_flags, unsigned long usp, | ||
86 | unsigned long unused, | ||
87 | struct task_struct *p, struct pt_regs *regs) | ||
88 | { | ||
89 | struct thread_info *ti = task_thread_info(p); | ||
90 | struct pt_regs *childregs = task_pt_regs(p); | ||
91 | |||
92 | p->set_child_tid = NULL; | ||
93 | p->clear_child_tid = NULL; | ||
94 | |||
95 | *childregs = *regs; | ||
96 | childregs->regs[7] = 0; /* Clear error flag */ | ||
97 | childregs->regs[4] = 0; /* Child gets zero as return value */ | ||
98 | regs->regs[4] = p->pid; | ||
99 | |||
100 | if (childregs->cp0_psr & 0x8) { /* test kernel fork or user fork */ | ||
101 | childregs->regs[0] = usp; /* user fork */ | ||
102 | } else { | ||
103 | childregs->regs[28] = (unsigned long) ti; /* kernel fork */ | ||
104 | childregs->regs[0] = (unsigned long) childregs; | ||
105 | } | ||
106 | |||
107 | p->thread.reg0 = (unsigned long) childregs; | ||
108 | p->thread.reg3 = (unsigned long) ret_from_fork; | ||
109 | p->thread.cp0_psr = 0; | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | /* Fill in the fpu structure for a core dump. */ | ||
115 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r) | ||
116 | { | ||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | static void __noreturn | ||
121 | kernel_thread_helper(void *unused0, int (*fn)(void *), | ||
122 | void *arg, void *unused1) | ||
123 | { | ||
124 | do_exit(fn(arg)); | ||
125 | } | ||
126 | |||
127 | /* | ||
128 | * Create a kernel thread. | ||
129 | */ | ||
130 | long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) | ||
131 | { | ||
132 | struct pt_regs regs; | ||
133 | |||
134 | memset(®s, 0, sizeof(regs)); | ||
135 | |||
136 | regs.regs[6] = (unsigned long) arg; | ||
137 | regs.regs[5] = (unsigned long) fn; | ||
138 | regs.cp0_epc = (unsigned long) kernel_thread_helper; | ||
139 | regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \ | ||
140 | ((regs.cp0_psr & 0x3) << 2); | ||
141 | |||
142 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \ | ||
143 | 0, ®s, 0, NULL, NULL); | ||
144 | } | ||
145 | |||
146 | unsigned long thread_saved_pc(struct task_struct *tsk) | ||
147 | { | ||
148 | return task_pt_regs(tsk)->cp0_epc; | ||
149 | } | ||
150 | |||
151 | unsigned long get_wchan(struct task_struct *task) | ||
152 | { | ||
153 | if (!task || task == current || task->state == TASK_RUNNING) | ||
154 | return 0; | ||
155 | |||
156 | if (!task_stack_page(task)) | ||
157 | return 0; | ||
158 | |||
159 | return task_pt_regs(task)->cp0_epc; | ||
160 | } | ||
161 | |||
162 | unsigned long arch_align_stack(unsigned long sp) | ||
163 | { | ||
164 | return sp; | ||
165 | } | ||