Linux Audio

Check our new training course

Loading...
v3.5.6
  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/kernel.h>
 17#include <linux/mm.h>
 18#include <linux/smp.h>
 19#include <linux/stddef.h>
 20#include <linux/unistd.h>
 21#include <linux/ptrace.h>
 22#include <linux/slab.h>
 23#include <linux/user.h>
 24#include <linux/elf.h>
 25#include <linux/reboot.h>
 26#include <linux/interrupt.h>
 27#include <linux/pagemap.h>
 28
 29#include <asm/asm-offsets.h>
 30#include <asm/uaccess.h>
 
 31#include <asm/setup.h>
 32#include <asm/pgtable.h>
 33#include <asm/tlb.h>
 34#include <asm/gdb-stub.h>
 35#include <asm/mb-regs.h>
 36
 37#include "local.h"
 38
 39asmlinkage void ret_from_fork(void);
 40
 41#include <asm/pgalloc.h>
 42
 43void (*pm_power_off)(void);
 44EXPORT_SYMBOL(pm_power_off);
 45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 46static void core_sleep_idle(void)
 47{
 48#ifdef LED_DEBUG_SLEEP
 49	/* Show that we're sleeping... */
 50	__set_LEDS(0x55aa);
 51#endif
 52	frv_cpu_core_sleep();
 53#ifdef LED_DEBUG_SLEEP
 54	/* ... and that we woke up */
 55	__set_LEDS(0);
 56#endif
 57	mb();
 58}
 59
 60void (*idle)(void) = core_sleep_idle;
 61
 62/*
 63 * The idle thread. There's no useful work to be
 64 * done, so just try to conserve power and have a
 65 * low exit latency (ie sit in a loop waiting for
 66 * somebody to say that they'd like to reschedule)
 67 */
 68void cpu_idle(void)
 69{
 70	/* endless idle loop with no priority at all */
 71	while (1) {
 72		while (!need_resched()) {
 73			check_pgt_cache();
 74
 75			if (!frv_dma_inprogress && idle)
 76				idle();
 77		}
 78
 79		schedule_preempt_disabled();
 
 
 80	}
 81}
 82
 83void machine_restart(char * __unused)
 84{
 85	unsigned long reset_addr;
 86#ifdef CONFIG_GDBSTUB
 87	gdbstub_exit(0);
 88#endif
 89
 90	if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
 91		reset_addr = 0xfefff500;
 92	else
 93		reset_addr = 0xfeff0500;
 94
 95	/* Software reset. */
 96	asm volatile("      dcef @(gr0,gr0),1 ! membar !"
 97		     "      sti     %1,@(%0,0) !"
 98		     "      nop ! nop ! nop ! nop ! nop ! "
 99		     "      nop ! nop ! nop ! nop ! nop ! "
100		     "      nop ! nop ! nop ! nop ! nop ! "
101		     "      nop ! nop ! nop ! nop ! nop ! "
102		     : : "r" (reset_addr), "r" (1) );
103
104	for (;;)
105		;
106}
107
108void machine_halt(void)
109{
110#ifdef CONFIG_GDBSTUB
111	gdbstub_exit(0);
112#endif
113
114	for (;;);
115}
116
117void machine_power_off(void)
118{
119#ifdef CONFIG_GDBSTUB
120	gdbstub_exit(0);
121#endif
122
123	for (;;);
124}
125
126void flush_thread(void)
127{
128	/* nothing */
129}
130
131inline unsigned long user_stack(const struct pt_regs *regs)
132{
133	while (regs->next_frame)
134		regs = regs->next_frame;
135	return user_mode(regs) ? regs->sp : 0;
136}
137
138asmlinkage int sys_fork(void)
139{
140#ifndef CONFIG_MMU
141	/* fork almost works, enough to trick you into looking elsewhere:-( */
142	return -EINVAL;
143#else
144	return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
145#endif
146}
147
148asmlinkage int sys_vfork(void)
149{
150	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
151		       NULL, NULL);
152}
153
154/*****************************************************************************/
155/*
156 * clone a process
157 * - tlsptr is retrieved by copy_thread()
158 */
159asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
160			 int __user *parent_tidptr, int __user *child_tidptr,
161			 int __user *tlsptr)
162{
163	if (!newsp)
164		newsp = user_stack(__frame);
165	return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
166} /* end sys_clone() */
167
 
 
 
 
 
 
 
 
 
 
 
168/*
169 * set up the kernel stack and exception frames for a new process
170 */
171int copy_thread(unsigned long clone_flags,
172		unsigned long usp, unsigned long topstk,
173		struct task_struct *p, struct pt_regs *regs)
174{
175	struct pt_regs *childregs0, *childregs, *regs0;
176
177	regs0 = __kernel_frame0_ptr;
178	childregs0 = (struct pt_regs *)
179		(task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
180	childregs = childregs0;
181
182	/* set up the userspace frame (the only place that the USP is stored) */
183	*childregs0 = *regs0;
184
185	childregs0->gr8		= 0;
186	childregs0->sp		= usp;
187	childregs0->next_frame	= NULL;
188
189	/* set up the return kernel frame if called from kernel_thread() */
190	if (regs != regs0) {
191		childregs--;
192		*childregs = *regs;
193		childregs->sp = (unsigned long) childregs0;
194		childregs->next_frame = childregs0;
195		childregs->gr15 = (unsigned long) task_thread_info(p);
196		childregs->gr29 = (unsigned long) p;
197	}
198
199	p->set_child_tid = p->clear_child_tid = NULL;
200
201	p->thread.frame	 = childregs;
202	p->thread.curr	 = p;
203	p->thread.sp	 = (unsigned long) childregs;
204	p->thread.fp	 = 0;
205	p->thread.lr	 = 0;
206	p->thread.pc	 = (unsigned long) ret_from_fork;
207	p->thread.frame0 = childregs0;
208
209	/* the new TLS pointer is passed in as arg #5 to sys_clone() */
210	if (clone_flags & CLONE_SETTLS)
211		childregs->gr29 = childregs->gr12;
212
213	save_user_regs(p->thread.user);
214
215	return 0;
216} /* end copy_thread() */
217
218/*
219 * sys_execve() executes a new program.
220 */
221asmlinkage int sys_execve(const char __user *name,
222			  const char __user *const __user *argv,
223			  const char __user *const __user *envp)
224{
225	int error;
226	char * filename;
227
228	filename = getname(name);
229	error = PTR_ERR(filename);
230	if (IS_ERR(filename))
231		return error;
232	error = do_execve(filename, argv, envp, __frame);
233	putname(filename);
234	return error;
235}
236
237unsigned long get_wchan(struct task_struct *p)
238{
239	struct pt_regs *regs0;
240	unsigned long fp, pc;
241	unsigned long stack_limit;
242	int count = 0;
243	if (!p || p == current || p->state == TASK_RUNNING)
244		return 0;
245
246	stack_limit = (unsigned long) (p + 1);
247	fp = p->thread.fp;
248	regs0 = p->thread.frame0;
249
250	do {
251		if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
252			return 0;
253
254		pc = ((unsigned long *) fp)[2];
255
256		/* FIXME: This depends on the order of these functions. */
257		if (!in_sched_functions(pc))
258			return pc;
259
260		fp = *(unsigned long *) fp;
261	} while (count++ < 16);
262
263	return 0;
264}
265
266unsigned long thread_saved_pc(struct task_struct *tsk)
267{
268	/* Check whether the thread is blocked in resume() */
269	if (in_sched_functions(tsk->thread.pc))
270		return ((unsigned long *)tsk->thread.fp)[2];
271	else
272		return tsk->thread.pc;
273}
274
275int elf_check_arch(const struct elf32_hdr *hdr)
276{
277	unsigned long hsr0 = __get_HSR(0);
278	unsigned long psr = __get_PSR();
279
280	if (hdr->e_machine != EM_FRV)
281		return 0;
282
283	switch (hdr->e_flags & EF_FRV_GPR_MASK) {
284	case EF_FRV_GPR64:
285		if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
286			return 0;
287	case EF_FRV_GPR32:
288	case 0:
289		break;
290	default:
291		return 0;
292	}
293
294	switch (hdr->e_flags & EF_FRV_FPR_MASK) {
295	case EF_FRV_FPR64:
296		if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
297			return 0;
298	case EF_FRV_FPR32:
299	case EF_FRV_FPR_NONE:
300	case 0:
301		break;
302	default:
303		return 0;
304	}
305
306	if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
307		if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
308		    PSR_IMPLE(psr) != PSR_IMPLE_FR451)
309			return 0;
310
311	switch (hdr->e_flags & EF_FRV_CPU_MASK) {
312	case EF_FRV_CPU_GENERIC:
313		break;
314	case EF_FRV_CPU_FR300:
315	case EF_FRV_CPU_SIMPLE:
316	case EF_FRV_CPU_TOMCAT:
317	default:
318		return 0;
319	case EF_FRV_CPU_FR400:
320		if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
321		    PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
322		    PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
323		    PSR_IMPLE(psr) != PSR_IMPLE_FR551)
324			return 0;
325		break;
326	case EF_FRV_CPU_FR450:
327		if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
328			return 0;
329		break;
330	case EF_FRV_CPU_FR500:
331		if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
332			return 0;
333		break;
334	case EF_FRV_CPU_FR550:
335		if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
336			return 0;
337		break;
338	}
339
340	return 1;
341}
342
343int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
344{
345	memcpy(fpregs,
346	       &current->thread.user->f,
347	       sizeof(current->thread.user->f));
348	return 1;
349}
v3.1
  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/kernel.h>
 17#include <linux/mm.h>
 18#include <linux/smp.h>
 19#include <linux/stddef.h>
 20#include <linux/unistd.h>
 21#include <linux/ptrace.h>
 22#include <linux/slab.h>
 23#include <linux/user.h>
 24#include <linux/elf.h>
 25#include <linux/reboot.h>
 26#include <linux/interrupt.h>
 27#include <linux/pagemap.h>
 28
 29#include <asm/asm-offsets.h>
 30#include <asm/uaccess.h>
 31#include <asm/system.h>
 32#include <asm/setup.h>
 33#include <asm/pgtable.h>
 34#include <asm/tlb.h>
 35#include <asm/gdb-stub.h>
 36#include <asm/mb-regs.h>
 37
 38#include "local.h"
 39
 40asmlinkage void ret_from_fork(void);
 41
 42#include <asm/pgalloc.h>
 43
 44void (*pm_power_off)(void);
 45EXPORT_SYMBOL(pm_power_off);
 46
 47struct task_struct *alloc_task_struct_node(int node)
 48{
 49	struct task_struct *p = kmalloc_node(THREAD_SIZE, GFP_KERNEL, node);
 50
 51	if (p)
 52		atomic_set((atomic_t *)(p+1), 1);
 53	return p;
 54}
 55
 56void free_task_struct(struct task_struct *p)
 57{
 58	if (atomic_dec_and_test((atomic_t *)(p+1)))
 59		kfree(p);
 60}
 61
 62static void core_sleep_idle(void)
 63{
 64#ifdef LED_DEBUG_SLEEP
 65	/* Show that we're sleeping... */
 66	__set_LEDS(0x55aa);
 67#endif
 68	frv_cpu_core_sleep();
 69#ifdef LED_DEBUG_SLEEP
 70	/* ... and that we woke up */
 71	__set_LEDS(0);
 72#endif
 73	mb();
 74}
 75
 76void (*idle)(void) = core_sleep_idle;
 77
 78/*
 79 * The idle thread. There's no useful work to be
 80 * done, so just try to conserve power and have a
 81 * low exit latency (ie sit in a loop waiting for
 82 * somebody to say that they'd like to reschedule)
 83 */
 84void cpu_idle(void)
 85{
 86	/* endless idle loop with no priority at all */
 87	while (1) {
 88		while (!need_resched()) {
 89			check_pgt_cache();
 90
 91			if (!frv_dma_inprogress && idle)
 92				idle();
 93		}
 94
 95		preempt_enable_no_resched();
 96		schedule();
 97		preempt_disable();
 98	}
 99}
100
101void machine_restart(char * __unused)
102{
103	unsigned long reset_addr;
104#ifdef CONFIG_GDBSTUB
105	gdbstub_exit(0);
106#endif
107
108	if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
109		reset_addr = 0xfefff500;
110	else
111		reset_addr = 0xfeff0500;
112
113	/* Software reset. */
114	asm volatile("      dcef @(gr0,gr0),1 ! membar !"
115		     "      sti     %1,@(%0,0) !"
116		     "      nop ! nop ! nop ! nop ! nop ! "
117		     "      nop ! nop ! nop ! nop ! nop ! "
118		     "      nop ! nop ! nop ! nop ! nop ! "
119		     "      nop ! nop ! nop ! nop ! nop ! "
120		     : : "r" (reset_addr), "r" (1) );
121
122	for (;;)
123		;
124}
125
126void machine_halt(void)
127{
128#ifdef CONFIG_GDBSTUB
129	gdbstub_exit(0);
130#endif
131
132	for (;;);
133}
134
135void machine_power_off(void)
136{
137#ifdef CONFIG_GDBSTUB
138	gdbstub_exit(0);
139#endif
140
141	for (;;);
142}
143
144void flush_thread(void)
145{
146	/* nothing */
147}
148
149inline unsigned long user_stack(const struct pt_regs *regs)
150{
151	while (regs->next_frame)
152		regs = regs->next_frame;
153	return user_mode(regs) ? regs->sp : 0;
154}
155
156asmlinkage int sys_fork(void)
157{
158#ifndef CONFIG_MMU
159	/* fork almost works, enough to trick you into looking elsewhere:-( */
160	return -EINVAL;
161#else
162	return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
163#endif
164}
165
166asmlinkage int sys_vfork(void)
167{
168	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
169		       NULL, NULL);
170}
171
172/*****************************************************************************/
173/*
174 * clone a process
175 * - tlsptr is retrieved by copy_thread()
176 */
177asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
178			 int __user *parent_tidptr, int __user *child_tidptr,
179			 int __user *tlsptr)
180{
181	if (!newsp)
182		newsp = user_stack(__frame);
183	return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
184} /* end sys_clone() */
185
186/*****************************************************************************/
187/*
188 * This gets called before we allocate a new thread and copy
189 * the current task into it.
190 */
191void prepare_to_copy(struct task_struct *tsk)
192{
193	//unlazy_fpu(tsk);
194} /* end prepare_to_copy() */
195
196/*****************************************************************************/
197/*
198 * set up the kernel stack and exception frames for a new process
199 */
200int copy_thread(unsigned long clone_flags,
201		unsigned long usp, unsigned long topstk,
202		struct task_struct *p, struct pt_regs *regs)
203{
204	struct pt_regs *childregs0, *childregs, *regs0;
205
206	regs0 = __kernel_frame0_ptr;
207	childregs0 = (struct pt_regs *)
208		(task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
209	childregs = childregs0;
210
211	/* set up the userspace frame (the only place that the USP is stored) */
212	*childregs0 = *regs0;
213
214	childregs0->gr8		= 0;
215	childregs0->sp		= usp;
216	childregs0->next_frame	= NULL;
217
218	/* set up the return kernel frame if called from kernel_thread() */
219	if (regs != regs0) {
220		childregs--;
221		*childregs = *regs;
222		childregs->sp = (unsigned long) childregs0;
223		childregs->next_frame = childregs0;
224		childregs->gr15 = (unsigned long) task_thread_info(p);
225		childregs->gr29 = (unsigned long) p;
226	}
227
228	p->set_child_tid = p->clear_child_tid = NULL;
229
230	p->thread.frame	 = childregs;
231	p->thread.curr	 = p;
232	p->thread.sp	 = (unsigned long) childregs;
233	p->thread.fp	 = 0;
234	p->thread.lr	 = 0;
235	p->thread.pc	 = (unsigned long) ret_from_fork;
236	p->thread.frame0 = childregs0;
237
238	/* the new TLS pointer is passed in as arg #5 to sys_clone() */
239	if (clone_flags & CLONE_SETTLS)
240		childregs->gr29 = childregs->gr12;
241
242	save_user_regs(p->thread.user);
243
244	return 0;
245} /* end copy_thread() */
246
247/*
248 * sys_execve() executes a new program.
249 */
250asmlinkage int sys_execve(const char __user *name,
251			  const char __user *const __user *argv,
252			  const char __user *const __user *envp)
253{
254	int error;
255	char * filename;
256
257	filename = getname(name);
258	error = PTR_ERR(filename);
259	if (IS_ERR(filename))
260		return error;
261	error = do_execve(filename, argv, envp, __frame);
262	putname(filename);
263	return error;
264}
265
266unsigned long get_wchan(struct task_struct *p)
267{
268	struct pt_regs *regs0;
269	unsigned long fp, pc;
270	unsigned long stack_limit;
271	int count = 0;
272	if (!p || p == current || p->state == TASK_RUNNING)
273		return 0;
274
275	stack_limit = (unsigned long) (p + 1);
276	fp = p->thread.fp;
277	regs0 = p->thread.frame0;
278
279	do {
280		if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
281			return 0;
282
283		pc = ((unsigned long *) fp)[2];
284
285		/* FIXME: This depends on the order of these functions. */
286		if (!in_sched_functions(pc))
287			return pc;
288
289		fp = *(unsigned long *) fp;
290	} while (count++ < 16);
291
292	return 0;
293}
294
295unsigned long thread_saved_pc(struct task_struct *tsk)
296{
297	/* Check whether the thread is blocked in resume() */
298	if (in_sched_functions(tsk->thread.pc))
299		return ((unsigned long *)tsk->thread.fp)[2];
300	else
301		return tsk->thread.pc;
302}
303
304int elf_check_arch(const struct elf32_hdr *hdr)
305{
306	unsigned long hsr0 = __get_HSR(0);
307	unsigned long psr = __get_PSR();
308
309	if (hdr->e_machine != EM_FRV)
310		return 0;
311
312	switch (hdr->e_flags & EF_FRV_GPR_MASK) {
313	case EF_FRV_GPR64:
314		if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
315			return 0;
316	case EF_FRV_GPR32:
317	case 0:
318		break;
319	default:
320		return 0;
321	}
322
323	switch (hdr->e_flags & EF_FRV_FPR_MASK) {
324	case EF_FRV_FPR64:
325		if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
326			return 0;
327	case EF_FRV_FPR32:
328	case EF_FRV_FPR_NONE:
329	case 0:
330		break;
331	default:
332		return 0;
333	}
334
335	if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
336		if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
337		    PSR_IMPLE(psr) != PSR_IMPLE_FR451)
338			return 0;
339
340	switch (hdr->e_flags & EF_FRV_CPU_MASK) {
341	case EF_FRV_CPU_GENERIC:
342		break;
343	case EF_FRV_CPU_FR300:
344	case EF_FRV_CPU_SIMPLE:
345	case EF_FRV_CPU_TOMCAT:
346	default:
347		return 0;
348	case EF_FRV_CPU_FR400:
349		if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
350		    PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
351		    PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
352		    PSR_IMPLE(psr) != PSR_IMPLE_FR551)
353			return 0;
354		break;
355	case EF_FRV_CPU_FR450:
356		if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
357			return 0;
358		break;
359	case EF_FRV_CPU_FR500:
360		if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
361			return 0;
362		break;
363	case EF_FRV_CPU_FR550:
364		if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
365			return 0;
366		break;
367	}
368
369	return 1;
370}
371
372int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
373{
374	memcpy(fpregs,
375	       &current->thread.user->f,
376	       sizeof(current->thread.user->f));
377	return 1;
378}