Linux Audio

Check our new training course

Yocto distribution development and maintenance

Need a Yocto distribution for your embedded project?
Loading...
v4.6
  1/*
  2 * arch/sh/kernel/process_64.c
  3 *
  4 * This file handles the architecture-dependent parts of process handling..
  5 *
  6 * Copyright (C) 2000, 2001  Paolo Alberelli
  7 * Copyright (C) 2003 - 2007  Paul Mundt
  8 * Copyright (C) 2003, 2004 Richard Curnow
  9 *
 10 * Started from SH3/4 version:
 11 *   Copyright (C) 1999, 2000  Niibe Yutaka & Kaz Kojima
 12 *
 13 *   In turn started from i386 version:
 14 *     Copyright (C) 1995  Linus Torvalds
 15 *
 16 * This file is subject to the terms and conditions of the GNU General Public
 17 * License.  See the file "COPYING" in the main directory of this archive
 18 * for more details.
 19 */
 20#include <linux/mm.h>
 21#include <linux/fs.h>
 22#include <linux/ptrace.h>
 23#include <linux/reboot.h>
 24#include <linux/slab.h>
 25#include <linux/init.h>
 26#include <linux/module.h>
 27#include <linux/io.h>
 28#include <asm/syscalls.h>
 29#include <asm/uaccess.h>
 30#include <asm/pgtable.h>
 31#include <asm/mmu_context.h>
 32#include <asm/fpu.h>
 33#include <asm/switch_to.h>
 34
 35struct task_struct *last_task_used_math = NULL;
 36struct pt_regs fake_swapper_regs = { 0, };
 37
 38void show_regs(struct pt_regs *regs)
 39{
 40	unsigned long long ah, al, bh, bl, ch, cl;
 41
 42	printk("\n");
 43	show_regs_print_info(KERN_DEFAULT);
 44
 45	ah = (regs->pc) >> 32;
 46	al = (regs->pc) & 0xffffffff;
 47	bh = (regs->regs[18]) >> 32;
 48	bl = (regs->regs[18]) & 0xffffffff;
 49	ch = (regs->regs[15]) >> 32;
 50	cl = (regs->regs[15]) & 0xffffffff;
 51	printk("PC  : %08Lx%08Lx LINK: %08Lx%08Lx SP  : %08Lx%08Lx\n",
 52	       ah, al, bh, bl, ch, cl);
 53
 54	ah = (regs->sr) >> 32;
 55	al = (regs->sr) & 0xffffffff;
 56        asm volatile ("getcon   " __TEA ", %0" : "=r" (bh));
 57        asm volatile ("getcon   " __TEA ", %0" : "=r" (bl));
 58	bh = (bh) >> 32;
 59	bl = (bl) & 0xffffffff;
 60        asm volatile ("getcon   " __KCR0 ", %0" : "=r" (ch));
 61        asm volatile ("getcon   " __KCR0 ", %0" : "=r" (cl));
 62	ch = (ch) >> 32;
 63	cl = (cl) & 0xffffffff;
 64	printk("SR  : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
 65	       ah, al, bh, bl, ch, cl);
 66
 67	ah = (regs->regs[0]) >> 32;
 68	al = (regs->regs[0]) & 0xffffffff;
 69	bh = (regs->regs[1]) >> 32;
 70	bl = (regs->regs[1]) & 0xffffffff;
 71	ch = (regs->regs[2]) >> 32;
 72	cl = (regs->regs[2]) & 0xffffffff;
 73	printk("R0  : %08Lx%08Lx R1  : %08Lx%08Lx R2  : %08Lx%08Lx\n",
 74	       ah, al, bh, bl, ch, cl);
 75
 76	ah = (regs->regs[3]) >> 32;
 77	al = (regs->regs[3]) & 0xffffffff;
 78	bh = (regs->regs[4]) >> 32;
 79	bl = (regs->regs[4]) & 0xffffffff;
 80	ch = (regs->regs[5]) >> 32;
 81	cl = (regs->regs[5]) & 0xffffffff;
 82	printk("R3  : %08Lx%08Lx R4  : %08Lx%08Lx R5  : %08Lx%08Lx\n",
 83	       ah, al, bh, bl, ch, cl);
 84
 85	ah = (regs->regs[6]) >> 32;
 86	al = (regs->regs[6]) & 0xffffffff;
 87	bh = (regs->regs[7]) >> 32;
 88	bl = (regs->regs[7]) & 0xffffffff;
 89	ch = (regs->regs[8]) >> 32;
 90	cl = (regs->regs[8]) & 0xffffffff;
 91	printk("R6  : %08Lx%08Lx R7  : %08Lx%08Lx R8  : %08Lx%08Lx\n",
 92	       ah, al, bh, bl, ch, cl);
 93
 94	ah = (regs->regs[9]) >> 32;
 95	al = (regs->regs[9]) & 0xffffffff;
 96	bh = (regs->regs[10]) >> 32;
 97	bl = (regs->regs[10]) & 0xffffffff;
 98	ch = (regs->regs[11]) >> 32;
 99	cl = (regs->regs[11]) & 0xffffffff;
100	printk("R9  : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
101	       ah, al, bh, bl, ch, cl);
102
103	ah = (regs->regs[12]) >> 32;
104	al = (regs->regs[12]) & 0xffffffff;
105	bh = (regs->regs[13]) >> 32;
106	bl = (regs->regs[13]) & 0xffffffff;
107	ch = (regs->regs[14]) >> 32;
108	cl = (regs->regs[14]) & 0xffffffff;
109	printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
110	       ah, al, bh, bl, ch, cl);
111
112	ah = (regs->regs[16]) >> 32;
113	al = (regs->regs[16]) & 0xffffffff;
114	bh = (regs->regs[17]) >> 32;
115	bl = (regs->regs[17]) & 0xffffffff;
116	ch = (regs->regs[19]) >> 32;
117	cl = (regs->regs[19]) & 0xffffffff;
118	printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
119	       ah, al, bh, bl, ch, cl);
120
121	ah = (regs->regs[20]) >> 32;
122	al = (regs->regs[20]) & 0xffffffff;
123	bh = (regs->regs[21]) >> 32;
124	bl = (regs->regs[21]) & 0xffffffff;
125	ch = (regs->regs[22]) >> 32;
126	cl = (regs->regs[22]) & 0xffffffff;
127	printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
128	       ah, al, bh, bl, ch, cl);
129
130	ah = (regs->regs[23]) >> 32;
131	al = (regs->regs[23]) & 0xffffffff;
132	bh = (regs->regs[24]) >> 32;
133	bl = (regs->regs[24]) & 0xffffffff;
134	ch = (regs->regs[25]) >> 32;
135	cl = (regs->regs[25]) & 0xffffffff;
136	printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
137	       ah, al, bh, bl, ch, cl);
138
139	ah = (regs->regs[26]) >> 32;
140	al = (regs->regs[26]) & 0xffffffff;
141	bh = (regs->regs[27]) >> 32;
142	bl = (regs->regs[27]) & 0xffffffff;
143	ch = (regs->regs[28]) >> 32;
144	cl = (regs->regs[28]) & 0xffffffff;
145	printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
146	       ah, al, bh, bl, ch, cl);
147
148	ah = (regs->regs[29]) >> 32;
149	al = (regs->regs[29]) & 0xffffffff;
150	bh = (regs->regs[30]) >> 32;
151	bl = (regs->regs[30]) & 0xffffffff;
152	ch = (regs->regs[31]) >> 32;
153	cl = (regs->regs[31]) & 0xffffffff;
154	printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
155	       ah, al, bh, bl, ch, cl);
156
157	ah = (regs->regs[32]) >> 32;
158	al = (regs->regs[32]) & 0xffffffff;
159	bh = (regs->regs[33]) >> 32;
160	bl = (regs->regs[33]) & 0xffffffff;
161	ch = (regs->regs[34]) >> 32;
162	cl = (regs->regs[34]) & 0xffffffff;
163	printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
164	       ah, al, bh, bl, ch, cl);
165
166	ah = (regs->regs[35]) >> 32;
167	al = (regs->regs[35]) & 0xffffffff;
168	bh = (regs->regs[36]) >> 32;
169	bl = (regs->regs[36]) & 0xffffffff;
170	ch = (regs->regs[37]) >> 32;
171	cl = (regs->regs[37]) & 0xffffffff;
172	printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
173	       ah, al, bh, bl, ch, cl);
174
175	ah = (regs->regs[38]) >> 32;
176	al = (regs->regs[38]) & 0xffffffff;
177	bh = (regs->regs[39]) >> 32;
178	bl = (regs->regs[39]) & 0xffffffff;
179	ch = (regs->regs[40]) >> 32;
180	cl = (regs->regs[40]) & 0xffffffff;
181	printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
182	       ah, al, bh, bl, ch, cl);
183
184	ah = (regs->regs[41]) >> 32;
185	al = (regs->regs[41]) & 0xffffffff;
186	bh = (regs->regs[42]) >> 32;
187	bl = (regs->regs[42]) & 0xffffffff;
188	ch = (regs->regs[43]) >> 32;
189	cl = (regs->regs[43]) & 0xffffffff;
190	printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
191	       ah, al, bh, bl, ch, cl);
192
193	ah = (regs->regs[44]) >> 32;
194	al = (regs->regs[44]) & 0xffffffff;
195	bh = (regs->regs[45]) >> 32;
196	bl = (regs->regs[45]) & 0xffffffff;
197	ch = (regs->regs[46]) >> 32;
198	cl = (regs->regs[46]) & 0xffffffff;
199	printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
200	       ah, al, bh, bl, ch, cl);
201
202	ah = (regs->regs[47]) >> 32;
203	al = (regs->regs[47]) & 0xffffffff;
204	bh = (regs->regs[48]) >> 32;
205	bl = (regs->regs[48]) & 0xffffffff;
206	ch = (regs->regs[49]) >> 32;
207	cl = (regs->regs[49]) & 0xffffffff;
208	printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
209	       ah, al, bh, bl, ch, cl);
210
211	ah = (regs->regs[50]) >> 32;
212	al = (regs->regs[50]) & 0xffffffff;
213	bh = (regs->regs[51]) >> 32;
214	bl = (regs->regs[51]) & 0xffffffff;
215	ch = (regs->regs[52]) >> 32;
216	cl = (regs->regs[52]) & 0xffffffff;
217	printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
218	       ah, al, bh, bl, ch, cl);
219
220	ah = (regs->regs[53]) >> 32;
221	al = (regs->regs[53]) & 0xffffffff;
222	bh = (regs->regs[54]) >> 32;
223	bl = (regs->regs[54]) & 0xffffffff;
224	ch = (regs->regs[55]) >> 32;
225	cl = (regs->regs[55]) & 0xffffffff;
226	printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
227	       ah, al, bh, bl, ch, cl);
228
229	ah = (regs->regs[56]) >> 32;
230	al = (regs->regs[56]) & 0xffffffff;
231	bh = (regs->regs[57]) >> 32;
232	bl = (regs->regs[57]) & 0xffffffff;
233	ch = (regs->regs[58]) >> 32;
234	cl = (regs->regs[58]) & 0xffffffff;
235	printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
236	       ah, al, bh, bl, ch, cl);
237
238	ah = (regs->regs[59]) >> 32;
239	al = (regs->regs[59]) & 0xffffffff;
240	bh = (regs->regs[60]) >> 32;
241	bl = (regs->regs[60]) & 0xffffffff;
242	ch = (regs->regs[61]) >> 32;
243	cl = (regs->regs[61]) & 0xffffffff;
244	printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
245	       ah, al, bh, bl, ch, cl);
246
247	ah = (regs->regs[62]) >> 32;
248	al = (regs->regs[62]) & 0xffffffff;
249	bh = (regs->tregs[0]) >> 32;
250	bl = (regs->tregs[0]) & 0xffffffff;
251	ch = (regs->tregs[1]) >> 32;
252	cl = (regs->tregs[1]) & 0xffffffff;
253	printk("R62 : %08Lx%08Lx T0  : %08Lx%08Lx T1  : %08Lx%08Lx\n",
254	       ah, al, bh, bl, ch, cl);
255
256	ah = (regs->tregs[2]) >> 32;
257	al = (regs->tregs[2]) & 0xffffffff;
258	bh = (regs->tregs[3]) >> 32;
259	bl = (regs->tregs[3]) & 0xffffffff;
260	ch = (regs->tregs[4]) >> 32;
261	cl = (regs->tregs[4]) & 0xffffffff;
262	printk("T2  : %08Lx%08Lx T3  : %08Lx%08Lx T4  : %08Lx%08Lx\n",
263	       ah, al, bh, bl, ch, cl);
264
265	ah = (regs->tregs[5]) >> 32;
266	al = (regs->tregs[5]) & 0xffffffff;
267	bh = (regs->tregs[6]) >> 32;
268	bl = (regs->tregs[6]) & 0xffffffff;
269	ch = (regs->tregs[7]) >> 32;
270	cl = (regs->tregs[7]) & 0xffffffff;
271	printk("T5  : %08Lx%08Lx T6  : %08Lx%08Lx T7  : %08Lx%08Lx\n",
272	       ah, al, bh, bl, ch, cl);
273
274	/*
275	 * If we're in kernel mode, dump the stack too..
276	 */
277	if (!user_mode(regs)) {
278		void show_stack(struct task_struct *tsk, unsigned long *sp);
279		unsigned long sp = regs->regs[15] & 0xffffffff;
280		struct task_struct *tsk = get_current();
281
282		tsk->thread.kregs = regs;
283
284		show_stack(tsk, (unsigned long *)sp);
285	}
286}
287
288/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289 * Free current thread data structures etc..
290 */
291void exit_thread(void)
292{
293	/*
294	 * See arch/sparc/kernel/process.c for the precedent for doing
295	 * this -- RPC.
296	 *
297	 * The SH-5 FPU save/restore approach relies on
298	 * last_task_used_math pointing to a live task_struct.  When
299	 * another task tries to use the FPU for the 1st time, the FPUDIS
300	 * trap handling (see arch/sh/kernel/cpu/sh5/fpu.c) will save the
301	 * existing FPU state to the FP regs field within
302	 * last_task_used_math before re-loading the new task's FPU state
303	 * (or initialising it if the FPU has been used before).  So if
304	 * last_task_used_math is stale, and its page has already been
305	 * re-allocated for another use, the consequences are rather
306	 * grim. Unless we null it here, there is no other path through
307	 * which it would get safely nulled.
308	 */
309#ifdef CONFIG_SH_FPU
310	if (last_task_used_math == current) {
311		last_task_used_math = NULL;
312	}
313#endif
314}
315
316void flush_thread(void)
317{
318
319	/* Called by fs/exec.c (setup_new_exec) to remove traces of a
320	 * previously running executable. */
321#ifdef CONFIG_SH_FPU
322	if (last_task_used_math == current) {
323		last_task_used_math = NULL;
324	}
325	/* Force FPU state to be reinitialised after exec */
326	clear_used_math();
327#endif
328
329	/* if we are a kernel thread, about to change to user thread,
330         * update kreg
331         */
332	if(current->thread.kregs==&fake_swapper_regs) {
333          current->thread.kregs =
334             ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
335	  current->thread.uregs = current->thread.kregs;
336	}
337}
338
339void release_thread(struct task_struct *dead_task)
340{
341	/* do nothing */
342}
343
344/* Fill in the fpu structure for a core dump.. */
345int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
346{
347#ifdef CONFIG_SH_FPU
348	int fpvalid;
349	struct task_struct *tsk = current;
350
351	fpvalid = !!tsk_used_math(tsk);
352	if (fpvalid) {
353		if (current == last_task_used_math) {
354			enable_fpu();
355			save_fpu(tsk);
356			disable_fpu();
357			last_task_used_math = 0;
358			regs->sr |= SR_FD;
359		}
360
361		memcpy(fpu, &tsk->thread.xstate->hardfpu, sizeof(*fpu));
362	}
363
364	return fpvalid;
365#else
366	return 0; /* Task didn't use the fpu at all. */
367#endif
368}
369EXPORT_SYMBOL(dump_fpu);
370
371asmlinkage void ret_from_fork(void);
372asmlinkage void ret_from_kernel_thread(void);
373
374int copy_thread(unsigned long clone_flags, unsigned long usp,
375		unsigned long arg, struct task_struct *p)
 
376{
377	struct pt_regs *childregs;
378
379#ifdef CONFIG_SH_FPU
380	/* can't happen for a kernel thread */
381	if (last_task_used_math == current) {
382		enable_fpu();
383		save_fpu(current);
384		disable_fpu();
385		last_task_used_math = NULL;
386		current_pt_regs()->sr |= SR_FD;
387	}
388#endif
389	/* Copy from sh version */
390	childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
391	p->thread.sp = (unsigned long) childregs;
392
393	if (unlikely(p->flags & PF_KTHREAD)) {
394		memset(childregs, 0, sizeof(struct pt_regs));
395		childregs->regs[2] = (unsigned long)arg;
396		childregs->regs[3] = (unsigned long)usp;
397		childregs->sr = (1 << 30); /* not user_mode */
398		childregs->sr |= SR_FD; /* Invalidate FPU flag */
399		p->thread.pc = (unsigned long) ret_from_kernel_thread;
400		return 0;
401	}
402	*childregs = *current_pt_regs();
403
404	/*
405	 * Sign extend the edited stack.
406	 * Note that thread.pc and thread.pc will stay
407	 * 32-bit wide and context switch must take care
408	 * of NEFF sign extension.
409	 */
410	if (usp)
411		childregs->regs[15] = neff_sign_extend(usp);
412	p->thread.uregs = childregs;
 
 
 
 
 
413
414	childregs->regs[9] = 0; /* Set return value for child */
415	childregs->sr |= SR_FD; /* Invalidate FPU flag */
416
 
417	p->thread.pc = (unsigned long) ret_from_fork;
418
419	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420}
421
422#ifdef CONFIG_FRAME_POINTER
423static int in_sh64_switch_to(unsigned long pc)
424{
425	extern char __sh64_switch_to_end;
426	/* For a sleeping task, the PC is somewhere in the middle of the function,
427	   so we don't have to worry about masking the LSB off */
428	return (pc >= (unsigned long) sh64_switch_to) &&
429	       (pc < (unsigned long) &__sh64_switch_to_end);
430}
431#endif
432
433unsigned long get_wchan(struct task_struct *p)
434{
435	unsigned long pc;
436
437	if (!p || p == current || p->state == TASK_RUNNING)
438		return 0;
439
440	/*
441	 * The same comment as on the Alpha applies here, too ...
442	 */
443	pc = thread_saved_pc(p);
444
445#ifdef CONFIG_FRAME_POINTER
446	if (in_sh64_switch_to(pc)) {
447		unsigned long schedule_fp;
448		unsigned long sh64_switch_to_fp;
449		unsigned long schedule_caller_pc;
450
451		sh64_switch_to_fp = (long) p->thread.sp;
452		/* r14 is saved at offset 4 in the sh64_switch_to frame */
453		schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
454
455		/* and the caller of 'schedule' is (currently!) saved at offset 24
456		   in the frame of schedule (from disasm) */
457		schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
458		return schedule_caller_pc;
459	}
460#endif
461	return pc;
462}
v3.5.6
  1/*
  2 * arch/sh/kernel/process_64.c
  3 *
  4 * This file handles the architecture-dependent parts of process handling..
  5 *
  6 * Copyright (C) 2000, 2001  Paolo Alberelli
  7 * Copyright (C) 2003 - 2007  Paul Mundt
  8 * Copyright (C) 2003, 2004 Richard Curnow
  9 *
 10 * Started from SH3/4 version:
 11 *   Copyright (C) 1999, 2000  Niibe Yutaka & Kaz Kojima
 12 *
 13 *   In turn started from i386 version:
 14 *     Copyright (C) 1995  Linus Torvalds
 15 *
 16 * This file is subject to the terms and conditions of the GNU General Public
 17 * License.  See the file "COPYING" in the main directory of this archive
 18 * for more details.
 19 */
 20#include <linux/mm.h>
 21#include <linux/fs.h>
 22#include <linux/ptrace.h>
 23#include <linux/reboot.h>
 24#include <linux/slab.h>
 25#include <linux/init.h>
 26#include <linux/module.h>
 27#include <linux/io.h>
 28#include <asm/syscalls.h>
 29#include <asm/uaccess.h>
 30#include <asm/pgtable.h>
 31#include <asm/mmu_context.h>
 32#include <asm/fpu.h>
 33#include <asm/switch_to.h>
 34
 35struct task_struct *last_task_used_math = NULL;
 36struct pt_regs fake_swapper_regs = { 0, };
 37
 38void show_regs(struct pt_regs *regs)
 39{
 40	unsigned long long ah, al, bh, bl, ch, cl;
 41
 42	printk("\n");
 
 43
 44	ah = (regs->pc) >> 32;
 45	al = (regs->pc) & 0xffffffff;
 46	bh = (regs->regs[18]) >> 32;
 47	bl = (regs->regs[18]) & 0xffffffff;
 48	ch = (regs->regs[15]) >> 32;
 49	cl = (regs->regs[15]) & 0xffffffff;
 50	printk("PC  : %08Lx%08Lx LINK: %08Lx%08Lx SP  : %08Lx%08Lx\n",
 51	       ah, al, bh, bl, ch, cl);
 52
 53	ah = (regs->sr) >> 32;
 54	al = (regs->sr) & 0xffffffff;
 55        asm volatile ("getcon   " __TEA ", %0" : "=r" (bh));
 56        asm volatile ("getcon   " __TEA ", %0" : "=r" (bl));
 57	bh = (bh) >> 32;
 58	bl = (bl) & 0xffffffff;
 59        asm volatile ("getcon   " __KCR0 ", %0" : "=r" (ch));
 60        asm volatile ("getcon   " __KCR0 ", %0" : "=r" (cl));
 61	ch = (ch) >> 32;
 62	cl = (cl) & 0xffffffff;
 63	printk("SR  : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
 64	       ah, al, bh, bl, ch, cl);
 65
 66	ah = (regs->regs[0]) >> 32;
 67	al = (regs->regs[0]) & 0xffffffff;
 68	bh = (regs->regs[1]) >> 32;
 69	bl = (regs->regs[1]) & 0xffffffff;
 70	ch = (regs->regs[2]) >> 32;
 71	cl = (regs->regs[2]) & 0xffffffff;
 72	printk("R0  : %08Lx%08Lx R1  : %08Lx%08Lx R2  : %08Lx%08Lx\n",
 73	       ah, al, bh, bl, ch, cl);
 74
 75	ah = (regs->regs[3]) >> 32;
 76	al = (regs->regs[3]) & 0xffffffff;
 77	bh = (regs->regs[4]) >> 32;
 78	bl = (regs->regs[4]) & 0xffffffff;
 79	ch = (regs->regs[5]) >> 32;
 80	cl = (regs->regs[5]) & 0xffffffff;
 81	printk("R3  : %08Lx%08Lx R4  : %08Lx%08Lx R5  : %08Lx%08Lx\n",
 82	       ah, al, bh, bl, ch, cl);
 83
 84	ah = (regs->regs[6]) >> 32;
 85	al = (regs->regs[6]) & 0xffffffff;
 86	bh = (regs->regs[7]) >> 32;
 87	bl = (regs->regs[7]) & 0xffffffff;
 88	ch = (regs->regs[8]) >> 32;
 89	cl = (regs->regs[8]) & 0xffffffff;
 90	printk("R6  : %08Lx%08Lx R7  : %08Lx%08Lx R8  : %08Lx%08Lx\n",
 91	       ah, al, bh, bl, ch, cl);
 92
 93	ah = (regs->regs[9]) >> 32;
 94	al = (regs->regs[9]) & 0xffffffff;
 95	bh = (regs->regs[10]) >> 32;
 96	bl = (regs->regs[10]) & 0xffffffff;
 97	ch = (regs->regs[11]) >> 32;
 98	cl = (regs->regs[11]) & 0xffffffff;
 99	printk("R9  : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
100	       ah, al, bh, bl, ch, cl);
101
102	ah = (regs->regs[12]) >> 32;
103	al = (regs->regs[12]) & 0xffffffff;
104	bh = (regs->regs[13]) >> 32;
105	bl = (regs->regs[13]) & 0xffffffff;
106	ch = (regs->regs[14]) >> 32;
107	cl = (regs->regs[14]) & 0xffffffff;
108	printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
109	       ah, al, bh, bl, ch, cl);
110
111	ah = (regs->regs[16]) >> 32;
112	al = (regs->regs[16]) & 0xffffffff;
113	bh = (regs->regs[17]) >> 32;
114	bl = (regs->regs[17]) & 0xffffffff;
115	ch = (regs->regs[19]) >> 32;
116	cl = (regs->regs[19]) & 0xffffffff;
117	printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
118	       ah, al, bh, bl, ch, cl);
119
120	ah = (regs->regs[20]) >> 32;
121	al = (regs->regs[20]) & 0xffffffff;
122	bh = (regs->regs[21]) >> 32;
123	bl = (regs->regs[21]) & 0xffffffff;
124	ch = (regs->regs[22]) >> 32;
125	cl = (regs->regs[22]) & 0xffffffff;
126	printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
127	       ah, al, bh, bl, ch, cl);
128
129	ah = (regs->regs[23]) >> 32;
130	al = (regs->regs[23]) & 0xffffffff;
131	bh = (regs->regs[24]) >> 32;
132	bl = (regs->regs[24]) & 0xffffffff;
133	ch = (regs->regs[25]) >> 32;
134	cl = (regs->regs[25]) & 0xffffffff;
135	printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
136	       ah, al, bh, bl, ch, cl);
137
138	ah = (regs->regs[26]) >> 32;
139	al = (regs->regs[26]) & 0xffffffff;
140	bh = (regs->regs[27]) >> 32;
141	bl = (regs->regs[27]) & 0xffffffff;
142	ch = (regs->regs[28]) >> 32;
143	cl = (regs->regs[28]) & 0xffffffff;
144	printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
145	       ah, al, bh, bl, ch, cl);
146
147	ah = (regs->regs[29]) >> 32;
148	al = (regs->regs[29]) & 0xffffffff;
149	bh = (regs->regs[30]) >> 32;
150	bl = (regs->regs[30]) & 0xffffffff;
151	ch = (regs->regs[31]) >> 32;
152	cl = (regs->regs[31]) & 0xffffffff;
153	printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
154	       ah, al, bh, bl, ch, cl);
155
156	ah = (regs->regs[32]) >> 32;
157	al = (regs->regs[32]) & 0xffffffff;
158	bh = (regs->regs[33]) >> 32;
159	bl = (regs->regs[33]) & 0xffffffff;
160	ch = (regs->regs[34]) >> 32;
161	cl = (regs->regs[34]) & 0xffffffff;
162	printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
163	       ah, al, bh, bl, ch, cl);
164
165	ah = (regs->regs[35]) >> 32;
166	al = (regs->regs[35]) & 0xffffffff;
167	bh = (regs->regs[36]) >> 32;
168	bl = (regs->regs[36]) & 0xffffffff;
169	ch = (regs->regs[37]) >> 32;
170	cl = (regs->regs[37]) & 0xffffffff;
171	printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
172	       ah, al, bh, bl, ch, cl);
173
174	ah = (regs->regs[38]) >> 32;
175	al = (regs->regs[38]) & 0xffffffff;
176	bh = (regs->regs[39]) >> 32;
177	bl = (regs->regs[39]) & 0xffffffff;
178	ch = (regs->regs[40]) >> 32;
179	cl = (regs->regs[40]) & 0xffffffff;
180	printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
181	       ah, al, bh, bl, ch, cl);
182
183	ah = (regs->regs[41]) >> 32;
184	al = (regs->regs[41]) & 0xffffffff;
185	bh = (regs->regs[42]) >> 32;
186	bl = (regs->regs[42]) & 0xffffffff;
187	ch = (regs->regs[43]) >> 32;
188	cl = (regs->regs[43]) & 0xffffffff;
189	printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
190	       ah, al, bh, bl, ch, cl);
191
192	ah = (regs->regs[44]) >> 32;
193	al = (regs->regs[44]) & 0xffffffff;
194	bh = (regs->regs[45]) >> 32;
195	bl = (regs->regs[45]) & 0xffffffff;
196	ch = (regs->regs[46]) >> 32;
197	cl = (regs->regs[46]) & 0xffffffff;
198	printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
199	       ah, al, bh, bl, ch, cl);
200
201	ah = (regs->regs[47]) >> 32;
202	al = (regs->regs[47]) & 0xffffffff;
203	bh = (regs->regs[48]) >> 32;
204	bl = (regs->regs[48]) & 0xffffffff;
205	ch = (regs->regs[49]) >> 32;
206	cl = (regs->regs[49]) & 0xffffffff;
207	printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
208	       ah, al, bh, bl, ch, cl);
209
210	ah = (regs->regs[50]) >> 32;
211	al = (regs->regs[50]) & 0xffffffff;
212	bh = (regs->regs[51]) >> 32;
213	bl = (regs->regs[51]) & 0xffffffff;
214	ch = (regs->regs[52]) >> 32;
215	cl = (regs->regs[52]) & 0xffffffff;
216	printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
217	       ah, al, bh, bl, ch, cl);
218
219	ah = (regs->regs[53]) >> 32;
220	al = (regs->regs[53]) & 0xffffffff;
221	bh = (regs->regs[54]) >> 32;
222	bl = (regs->regs[54]) & 0xffffffff;
223	ch = (regs->regs[55]) >> 32;
224	cl = (regs->regs[55]) & 0xffffffff;
225	printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
226	       ah, al, bh, bl, ch, cl);
227
228	ah = (regs->regs[56]) >> 32;
229	al = (regs->regs[56]) & 0xffffffff;
230	bh = (regs->regs[57]) >> 32;
231	bl = (regs->regs[57]) & 0xffffffff;
232	ch = (regs->regs[58]) >> 32;
233	cl = (regs->regs[58]) & 0xffffffff;
234	printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
235	       ah, al, bh, bl, ch, cl);
236
237	ah = (regs->regs[59]) >> 32;
238	al = (regs->regs[59]) & 0xffffffff;
239	bh = (regs->regs[60]) >> 32;
240	bl = (regs->regs[60]) & 0xffffffff;
241	ch = (regs->regs[61]) >> 32;
242	cl = (regs->regs[61]) & 0xffffffff;
243	printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
244	       ah, al, bh, bl, ch, cl);
245
246	ah = (regs->regs[62]) >> 32;
247	al = (regs->regs[62]) & 0xffffffff;
248	bh = (regs->tregs[0]) >> 32;
249	bl = (regs->tregs[0]) & 0xffffffff;
250	ch = (regs->tregs[1]) >> 32;
251	cl = (regs->tregs[1]) & 0xffffffff;
252	printk("R62 : %08Lx%08Lx T0  : %08Lx%08Lx T1  : %08Lx%08Lx\n",
253	       ah, al, bh, bl, ch, cl);
254
255	ah = (regs->tregs[2]) >> 32;
256	al = (regs->tregs[2]) & 0xffffffff;
257	bh = (regs->tregs[3]) >> 32;
258	bl = (regs->tregs[3]) & 0xffffffff;
259	ch = (regs->tregs[4]) >> 32;
260	cl = (regs->tregs[4]) & 0xffffffff;
261	printk("T2  : %08Lx%08Lx T3  : %08Lx%08Lx T4  : %08Lx%08Lx\n",
262	       ah, al, bh, bl, ch, cl);
263
264	ah = (regs->tregs[5]) >> 32;
265	al = (regs->tregs[5]) & 0xffffffff;
266	bh = (regs->tregs[6]) >> 32;
267	bl = (regs->tregs[6]) & 0xffffffff;
268	ch = (regs->tregs[7]) >> 32;
269	cl = (regs->tregs[7]) & 0xffffffff;
270	printk("T5  : %08Lx%08Lx T6  : %08Lx%08Lx T7  : %08Lx%08Lx\n",
271	       ah, al, bh, bl, ch, cl);
272
273	/*
274	 * If we're in kernel mode, dump the stack too..
275	 */
276	if (!user_mode(regs)) {
277		void show_stack(struct task_struct *tsk, unsigned long *sp);
278		unsigned long sp = regs->regs[15] & 0xffffffff;
279		struct task_struct *tsk = get_current();
280
281		tsk->thread.kregs = regs;
282
283		show_stack(tsk, (unsigned long *)sp);
284	}
285}
286
287/*
288 * Create a kernel thread
289 */
290__noreturn void kernel_thread_helper(void *arg, int (*fn)(void *))
291{
292	do_exit(fn(arg));
293}
294
295/*
296 * This is the mechanism for creating a new kernel thread.
297 *
298 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
299 * who haven't done an "execve()") should use this: it will work within
300 * a system call from a "real" process, but the process memory space will
301 * not be freed until both the parent and the child have exited.
302 */
303int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
304{
305	struct pt_regs regs;
306
307	memset(&regs, 0, sizeof(regs));
308	regs.regs[2] = (unsigned long)arg;
309	regs.regs[3] = (unsigned long)fn;
310
311	regs.pc = (unsigned long)kernel_thread_helper;
312	regs.sr = (1 << 30);
313
314	/* Ok, create the new process.. */
315	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
316		      &regs, 0, NULL, NULL);
317}
318EXPORT_SYMBOL(kernel_thread);
319
320/*
321 * Free current thread data structures etc..
322 */
323void exit_thread(void)
324{
325	/*
326	 * See arch/sparc/kernel/process.c for the precedent for doing
327	 * this -- RPC.
328	 *
329	 * The SH-5 FPU save/restore approach relies on
330	 * last_task_used_math pointing to a live task_struct.  When
331	 * another task tries to use the FPU for the 1st time, the FPUDIS
332	 * trap handling (see arch/sh/kernel/cpu/sh5/fpu.c) will save the
333	 * existing FPU state to the FP regs field within
334	 * last_task_used_math before re-loading the new task's FPU state
335	 * (or initialising it if the FPU has been used before).  So if
336	 * last_task_used_math is stale, and its page has already been
337	 * re-allocated for another use, the consequences are rather
338	 * grim. Unless we null it here, there is no other path through
339	 * which it would get safely nulled.
340	 */
341#ifdef CONFIG_SH_FPU
342	if (last_task_used_math == current) {
343		last_task_used_math = NULL;
344	}
345#endif
346}
347
348void flush_thread(void)
349{
350
351	/* Called by fs/exec.c (setup_new_exec) to remove traces of a
352	 * previously running executable. */
353#ifdef CONFIG_SH_FPU
354	if (last_task_used_math == current) {
355		last_task_used_math = NULL;
356	}
357	/* Force FPU state to be reinitialised after exec */
358	clear_used_math();
359#endif
360
361	/* if we are a kernel thread, about to change to user thread,
362         * update kreg
363         */
364	if(current->thread.kregs==&fake_swapper_regs) {
365          current->thread.kregs =
366             ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
367	  current->thread.uregs = current->thread.kregs;
368	}
369}
370
371void release_thread(struct task_struct *dead_task)
372{
373	/* do nothing */
374}
375
376/* Fill in the fpu structure for a core dump.. */
377int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
378{
379#ifdef CONFIG_SH_FPU
380	int fpvalid;
381	struct task_struct *tsk = current;
382
383	fpvalid = !!tsk_used_math(tsk);
384	if (fpvalid) {
385		if (current == last_task_used_math) {
386			enable_fpu();
387			save_fpu(tsk);
388			disable_fpu();
389			last_task_used_math = 0;
390			regs->sr |= SR_FD;
391		}
392
393		memcpy(fpu, &tsk->thread.xstate->hardfpu, sizeof(*fpu));
394	}
395
396	return fpvalid;
397#else
398	return 0; /* Task didn't use the fpu at all. */
399#endif
400}
401EXPORT_SYMBOL(dump_fpu);
402
403asmlinkage void ret_from_fork(void);
 
404
405int copy_thread(unsigned long clone_flags, unsigned long usp,
406		unsigned long unused,
407		struct task_struct *p, struct pt_regs *regs)
408{
409	struct pt_regs *childregs;
410
411#ifdef CONFIG_SH_FPU
412	if(last_task_used_math == current) {
 
413		enable_fpu();
414		save_fpu(current);
415		disable_fpu();
416		last_task_used_math = NULL;
417		regs->sr |= SR_FD;
418	}
419#endif
420	/* Copy from sh version */
421	childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
 
422
423	*childregs = *regs;
 
 
 
 
 
 
 
 
 
424
425	/*
426	 * Sign extend the edited stack.
427	 * Note that thread.pc and thread.pc will stay
428	 * 32-bit wide and context switch must take care
429	 * of NEFF sign extension.
430	 */
431	if (user_mode(regs)) {
432		childregs->regs[15] = neff_sign_extend(usp);
433		p->thread.uregs = childregs;
434	} else {
435		childregs->regs[15] =
436			neff_sign_extend((unsigned long)task_stack_page(p) +
437					 THREAD_SIZE);
438	}
439
440	childregs->regs[9] = 0; /* Set return value for child */
441	childregs->sr |= SR_FD; /* Invalidate FPU flag */
442
443	p->thread.sp = (unsigned long) childregs;
444	p->thread.pc = (unsigned long) ret_from_fork;
445
446	return 0;
447}
448
449asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
450			unsigned long r4, unsigned long r5,
451			unsigned long r6, unsigned long r7,
452			struct pt_regs *pregs)
453{
454	return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
455}
456
457asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
458			 unsigned long r4, unsigned long r5,
459			 unsigned long r6, unsigned long r7,
460			 struct pt_regs *pregs)
461{
462	if (!newsp)
463		newsp = pregs->regs[15];
464	return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
465}
466
467/*
468 * This is trivial, and on the face of it looks like it
469 * could equally well be done in user mode.
470 *
471 * Not so, for quite unobvious reasons - register pressure.
472 * In user mode vfork() cannot have a stack frame, and if
473 * done by calling the "clone()" system call directly, you
474 * do not have enough call-clobbered registers to hold all
475 * the information you need.
476 */
477asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
478			 unsigned long r4, unsigned long r5,
479			 unsigned long r6, unsigned long r7,
480			 struct pt_regs *pregs)
481{
482	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
483}
484
485/*
486 * sys_execve() executes a new program.
487 */
488asmlinkage int sys_execve(const char *ufilename, char **uargv,
489			  char **uenvp, unsigned long r5,
490			  unsigned long r6, unsigned long r7,
491			  struct pt_regs *pregs)
492{
493	int error;
494	char *filename;
495
496	filename = getname((char __user *)ufilename);
497	error = PTR_ERR(filename);
498	if (IS_ERR(filename))
499		goto out;
500
501	error = do_execve(filename,
502			  (const char __user *const __user *)uargv,
503			  (const char __user *const __user *)uenvp,
504			  pregs);
505	putname(filename);
506out:
507	return error;
508}
509
510#ifdef CONFIG_FRAME_POINTER
511static int in_sh64_switch_to(unsigned long pc)
512{
513	extern char __sh64_switch_to_end;
514	/* For a sleeping task, the PC is somewhere in the middle of the function,
515	   so we don't have to worry about masking the LSB off */
516	return (pc >= (unsigned long) sh64_switch_to) &&
517	       (pc < (unsigned long) &__sh64_switch_to_end);
518}
519#endif
520
521unsigned long get_wchan(struct task_struct *p)
522{
523	unsigned long pc;
524
525	if (!p || p == current || p->state == TASK_RUNNING)
526		return 0;
527
528	/*
529	 * The same comment as on the Alpha applies here, too ...
530	 */
531	pc = thread_saved_pc(p);
532
533#ifdef CONFIG_FRAME_POINTER
534	if (in_sh64_switch_to(pc)) {
535		unsigned long schedule_fp;
536		unsigned long sh64_switch_to_fp;
537		unsigned long schedule_caller_pc;
538
539		sh64_switch_to_fp = (long) p->thread.sp;
540		/* r14 is saved at offset 4 in the sh64_switch_to frame */
541		schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
542
543		/* and the caller of 'schedule' is (currently!) saved at offset 24
544		   in the frame of schedule (from disasm) */
545		schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
546		return schedule_caller_pc;
547	}
548#endif
549	return pc;
550}