]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/frv/kernel/process.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-bionic-kernel.git] / arch / frv / kernel / process.c
CommitLineData
1da177e4
LT
1/* process.c: FRV specific parts of process handling
2 *
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/process.c
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
9dec17eb 13#include <linux/module.h>
1da177e4
LT
14#include <linux/errno.h>
15#include <linux/sched.h>
b17b0153 16#include <linux/sched/debug.h>
29930025 17#include <linux/sched/task.h>
68db0cf1 18#include <linux/sched/task_stack.h>
1da177e4
LT
19#include <linux/kernel.h>
20#include <linux/mm.h>
21#include <linux/smp.h>
1da177e4
LT
22#include <linux/stddef.h>
23#include <linux/unistd.h>
24#include <linux/ptrace.h>
25#include <linux/slab.h>
26#include <linux/user.h>
27#include <linux/elf.h>
28#include <linux/reboot.h>
29#include <linux/interrupt.h>
8defab33 30#include <linux/pagemap.h>
41d8fe5b 31#include <linux/rcupdate.h>
1da177e4 32
84e8cd6d 33#include <asm/asm-offsets.h>
7c0f6ba6 34#include <linux/uaccess.h>
1da177e4
LT
35#include <asm/setup.h>
36#include <asm/pgtable.h>
8defab33 37#include <asm/tlb.h>
1da177e4
LT
38#include <asm/gdb-stub.h>
39#include <asm/mb-regs.h>
40
41#include "local.h"
42
43asmlinkage void ret_from_fork(void);
02ce496f 44asmlinkage void ret_from_kernel_thread(void);
1da177e4
LT
45
46#include <asm/pgalloc.h>
47
9dec17eb
DH
48void (*pm_power_off)(void);
49EXPORT_SYMBOL(pm_power_off);
50
1da177e4
LT
51static void core_sleep_idle(void)
52{
53#ifdef LED_DEBUG_SLEEP
54 /* Show that we're sleeping... */
55 __set_LEDS(0x55aa);
56#endif
57 frv_cpu_core_sleep();
58#ifdef LED_DEBUG_SLEEP
59 /* ... and that we woke up */
60 __set_LEDS(0);
61#endif
62 mb();
63}
64
ccf8e78f 65void arch_cpu_idle(void)
1da177e4 66{
ccf8e78f
TG
67 if (!frv_dma_inprogress)
68 core_sleep_idle();
69 else
70 local_irq_enable();
1da177e4
LT
71}
72
73void machine_restart(char * __unused)
74{
75 unsigned long reset_addr;
76#ifdef CONFIG_GDBSTUB
77 gdbstub_exit(0);
78#endif
79
80 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
81 reset_addr = 0xfefff500;
82 else
83 reset_addr = 0xfeff0500;
84
85 /* Software reset. */
86 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
87 " sti %1,@(%0,0) !"
88 " nop ! nop ! nop ! nop ! nop ! "
89 " nop ! nop ! nop ! nop ! nop ! "
90 " nop ! nop ! nop ! nop ! nop ! "
91 " nop ! nop ! nop ! nop ! nop ! "
92 : : "r" (reset_addr), "r" (1) );
93
94 for (;;)
95 ;
96}
97
98void machine_halt(void)
99{
100#ifdef CONFIG_GDBSTUB
101 gdbstub_exit(0);
102#endif
103
104 for (;;);
105}
106
107void machine_power_off(void)
108{
109#ifdef CONFIG_GDBSTUB
110 gdbstub_exit(0);
111#endif
112
113 for (;;);
114}
115
116void flush_thread(void)
117{
adc400f6 118 /* nothing */
1da177e4
LT
119}
120
121inline unsigned long user_stack(const struct pt_regs *regs)
122{
123 while (regs->next_frame)
124 regs = regs->next_frame;
125 return user_mode(regs) ? regs->sp : 0;
126}
127
1da177e4
LT
128/*
129 * set up the kernel stack and exception frames for a new process
130 */
6f2c55b8 131int copy_thread(unsigned long clone_flags,
49ed3398 132 unsigned long usp, unsigned long arg,
afa86fc4 133 struct task_struct *p)
1da177e4 134{
02ce496f 135 struct pt_regs *childregs;
1da177e4 136
02ce496f 137 childregs = (struct pt_regs *)
84e8cd6d 138 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
1da177e4 139
e7aa51b2 140 /* set up the userspace frame (the only place that the USP is stored) */
b9763ce3 141 *childregs = *current_pt_regs();
1da177e4
LT
142
143 p->thread.frame = childregs;
144 p->thread.curr = p;
145 p->thread.sp = (unsigned long) childregs;
146 p->thread.fp = 0;
147 p->thread.lr = 0;
02ce496f 148 p->thread.frame0 = childregs;
1da177e4 149
b9763ce3 150 if (unlikely(p->flags & PF_KTHREAD)) {
49ed3398
AV
151 childregs->gr9 = usp; /* function */
152 childregs->gr8 = arg;
49ed3398
AV
153 p->thread.pc = (unsigned long) ret_from_kernel_thread;
154 save_user_regs(p->thread.user);
155 return 0;
156 }
b9763ce3
AV
157 if (usp)
158 childregs->sp = usp;
49ed3398
AV
159 childregs->next_frame = NULL;
160
161 p->thread.pc = (unsigned long) ret_from_fork;
1da177e4
LT
162
163 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
164 if (clone_flags & CLONE_SETTLS)
165 childregs->gr29 = childregs->gr12;
166
167 save_user_regs(p->thread.user);
168
169 return 0;
170} /* end copy_thread() */
171
1da177e4
LT
172unsigned long get_wchan(struct task_struct *p)
173{
174 struct pt_regs *regs0;
175 unsigned long fp, pc;
176 unsigned long stack_limit;
177 int count = 0;
178 if (!p || p == current || p->state == TASK_RUNNING)
179 return 0;
180
181 stack_limit = (unsigned long) (p + 1);
182 fp = p->thread.fp;
183 regs0 = p->thread.frame0;
184
185 do {
186 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
187 return 0;
188
189 pc = ((unsigned long *) fp)[2];
190
191 /* FIXME: This depends on the order of these functions. */
192 if (!in_sched_functions(pc))
193 return pc;
194
195 fp = *(unsigned long *) fp;
196 } while (count++ < 16);
197
198 return 0;
199}
200
201unsigned long thread_saved_pc(struct task_struct *tsk)
202{
203 /* Check whether the thread is blocked in resume() */
204 if (in_sched_functions(tsk->thread.pc))
205 return ((unsigned long *)tsk->thread.fp)[2];
206 else
207 return tsk->thread.pc;
208}
209
210int elf_check_arch(const struct elf32_hdr *hdr)
211{
212 unsigned long hsr0 = __get_HSR(0);
213 unsigned long psr = __get_PSR();
214
215 if (hdr->e_machine != EM_FRV)
216 return 0;
217
218 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
219 case EF_FRV_GPR64:
220 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
221 return 0;
222 case EF_FRV_GPR32:
223 case 0:
224 break;
225 default:
226 return 0;
227 }
228
229 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
230 case EF_FRV_FPR64:
231 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
232 return 0;
233 case EF_FRV_FPR32:
234 case EF_FRV_FPR_NONE:
235 case 0:
236 break;
237 default:
238 return 0;
239 }
240
241 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
242 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
243 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
244 return 0;
245
246 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
247 case EF_FRV_CPU_GENERIC:
248 break;
249 case EF_FRV_CPU_FR300:
250 case EF_FRV_CPU_SIMPLE:
251 case EF_FRV_CPU_TOMCAT:
252 default:
253 return 0;
254 case EF_FRV_CPU_FR400:
255 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
256 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
257 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
258 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
259 return 0;
260 break;
261 case EF_FRV_CPU_FR450:
262 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
263 return 0;
264 break;
265 case EF_FRV_CPU_FR500:
266 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
267 return 0;
268 break;
269 case EF_FRV_CPU_FR550:
270 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
271 return 0;
272 break;
273 }
274
275 return 1;
276}
6d8c4e3b
DH
277
278int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
279{
280 memcpy(fpregs,
281 &current->thread.user->f,
282 sizeof(current->thread.user->f));
283 return 1;
284}