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