Linux Audio

Check our new training course

Loading...
v6.2
  1/*
  2 * Architecture-dependent parts of process handling.
  3 *
  4 * Copyright (C) 2013 Altera Corporation
  5 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
  6 * Copyright (C) 2009 Wind River Systems Inc
  7 *   Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
  8 * Copyright (C) 2004 Microtronix Datacom Ltd
  9 *
 10 * This file is subject to the terms and conditions of the GNU General Public
 11 * License.  See the file "COPYING" in the main directory of this archive
 12 * for more details.
 13 */
 14
 15#include <linux/export.h>
 16#include <linux/sched.h>
 17#include <linux/sched/debug.h>
 18#include <linux/sched/task.h>
 19#include <linux/sched/task_stack.h>
 20#include <linux/mm_types.h>
 21#include <linux/tick.h>
 22#include <linux/uaccess.h>
 23
 24#include <asm/unistd.h>
 25#include <asm/traps.h>
 26#include <asm/cpuinfo.h>
 27
 28asmlinkage void ret_from_fork(void);
 29asmlinkage void ret_from_kernel_thread(void);
 30
 31void (*pm_power_off)(void) = NULL;
 32EXPORT_SYMBOL(pm_power_off);
 33
 34void arch_cpu_idle(void)
 35{
 36	raw_local_irq_enable();
 37}
 38
 39/*
 40 * The development boards have no way to pull a board reset. Just jump to the
 41 * cpu reset address and let the boot loader or the code in head.S take care of
 42 * resetting peripherals.
 43 */
 44void machine_restart(char *__unused)
 45{
 46	pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);
 47	local_irq_disable();
 48	__asm__ __volatile__ (
 49	"jmp	%0\n\t"
 50	:
 51	: "r" (cpuinfo.reset_addr)
 52	: "r4");
 53}
 54
 55void machine_halt(void)
 56{
 57	pr_notice("Machine halt...\n");
 58	local_irq_disable();
 59	for (;;)
 60		;
 61}
 62
 63/*
 64 * There is no way to power off the development boards. So just spin for now. If
 65 * we ever have a way of resetting a board using a GPIO we should add that here.
 66 */
 67void machine_power_off(void)
 68{
 69	pr_notice("Machine power off...\n");
 70	local_irq_disable();
 71	for (;;)
 72		;
 73}
 74
 75void show_regs(struct pt_regs *regs)
 76{
 77	pr_notice("\n");
 78	show_regs_print_info(KERN_DEFAULT);
 79
 80	pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",
 81		regs->r1,  regs->r2,  regs->r3,  regs->r4);
 82
 83	pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",
 84		regs->r5,  regs->r6,  regs->r7,  regs->r8);
 85
 86	pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",
 87		regs->r9,  regs->r10, regs->r11, regs->r12);
 88
 89	pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",
 90		regs->r13, regs->r14, regs->r15);
 91
 92	pr_notice("ra: %08lx fp:  %08lx sp: %08lx gp: %08lx\n",
 93		regs->ra,  regs->fp,  regs->sp,  regs->gp);
 94
 95	pr_notice("ea: %08lx estatus: %08lx\n",
 96		regs->ea,  regs->estatus);
 97}
 98
 99void flush_thread(void)
100{
101}
102
103int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
104{
105	unsigned long clone_flags = args->flags;
106	unsigned long usp = args->stack;
107	unsigned long tls = args->tls;
108	struct pt_regs *childregs = task_pt_regs(p);
109	struct pt_regs *regs;
110	struct switch_stack *stack;
111	struct switch_stack *childstack =
112		((struct switch_stack *)childregs) - 1;
113
114	if (unlikely(args->fn)) {
115		memset(childstack, 0,
116			sizeof(struct switch_stack) + sizeof(struct pt_regs));
117
118		childstack->r16 = (unsigned long) args->fn;
119		childstack->r17 = (unsigned long) args->fn_arg;
120		childstack->ra = (unsigned long) ret_from_kernel_thread;
121		childregs->estatus = STATUS_PIE;
122		childregs->sp = (unsigned long) childstack;
123
124		p->thread.ksp = (unsigned long) childstack;
125		p->thread.kregs = childregs;
126		return 0;
127	}
128
129	regs = current_pt_regs();
130	*childregs = *regs;
131	childregs->r2 = 0;	/* Set the return value for the child. */
132	childregs->r7 = 0;
133
134	stack = ((struct switch_stack *) regs) - 1;
135	*childstack = *stack;
136	childstack->ra = (unsigned long)ret_from_fork;
137	p->thread.kregs = childregs;
138	p->thread.ksp = (unsigned long) childstack;
139
140	if (usp)
141		childregs->sp = usp;
142
143	/* Initialize tls register. */
144	if (clone_flags & CLONE_SETTLS)
145		childstack->r23 = tls;
146
147	return 0;
148}
149
150/*
151 *	Generic dumping code. Used for panic and debug.
152 */
153void dump(struct pt_regs *fp)
154{
155	unsigned long	*sp;
156	unsigned char	*tp;
157	int		i;
158
159	pr_emerg("\nCURRENT PROCESS:\n\n");
160	pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);
161
162	if (current->mm) {
163		pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
164			(int) current->mm->start_code,
165			(int) current->mm->end_code,
166			(int) current->mm->start_data,
167			(int) current->mm->end_data,
168			(int) current->mm->end_data,
169			(int) current->mm->brk);
170		pr_emerg("USER-STACK=%08x  KERNEL-STACK=%08x\n\n",
171			(int) current->mm->start_stack,
172			(int)(((unsigned long) current) + THREAD_SIZE));
173	}
174
175	pr_emerg("PC: %08lx\n", fp->ea);
176	pr_emerg("SR: %08lx    SP: %08lx\n",
177		(long) fp->estatus, (long) fp);
178
179	pr_emerg("r1: %08lx    r2: %08lx    r3: %08lx\n",
180		fp->r1, fp->r2, fp->r3);
181
182	pr_emerg("r4: %08lx    r5: %08lx    r6: %08lx    r7: %08lx\n",
183		fp->r4, fp->r5, fp->r6, fp->r7);
184	pr_emerg("r8: %08lx    r9: %08lx    r10: %08lx    r11: %08lx\n",
185		fp->r8, fp->r9, fp->r10, fp->r11);
186	pr_emerg("r12: %08lx  r13: %08lx    r14: %08lx    r15: %08lx\n",
187		fp->r12, fp->r13, fp->r14, fp->r15);
188	pr_emerg("or2: %08lx   ra: %08lx     fp: %08lx    sp: %08lx\n",
189		fp->orig_r2, fp->ra, fp->fp, fp->sp);
190	pr_emerg("\nUSP: %08x   TRAPFRAME: %08x\n",
191		(unsigned int) fp->sp, (unsigned int) fp);
192
193	pr_emerg("\nCODE:");
194	tp = ((unsigned char *) fp->ea) - 0x20;
195	for (sp = (unsigned long *) tp, i = 0; (i < 0x40);  i += 4) {
196		if ((i % 0x10) == 0)
197			pr_emerg("\n%08x: ", (int) (tp + i));
198		pr_emerg("%08x ", (int) *sp++);
199	}
200	pr_emerg("\n");
201
202	pr_emerg("\nKERNEL STACK:");
203	tp = ((unsigned char *) fp) - 0x40;
204	for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
205		if ((i % 0x10) == 0)
206			pr_emerg("\n%08x: ", (int) (tp + i));
207		pr_emerg("%08x ", (int) *sp++);
208	}
209	pr_emerg("\n");
210	pr_emerg("\n");
211
212	pr_emerg("\nUSER STACK:");
213	tp = (unsigned char *) (fp->sp - 0x10);
214	for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
215		if ((i % 0x10) == 0)
216			pr_emerg("\n%08x: ", (int) (tp + i));
217		pr_emerg("%08x ", (int) *sp++);
218	}
219	pr_emerg("\n\n");
220}
221
222unsigned long __get_wchan(struct task_struct *p)
223{
224	unsigned long fp, pc;
225	unsigned long stack_page;
226	int count = 0;
227
228	stack_page = (unsigned long)p;
229	fp = ((struct switch_stack *)p->thread.ksp)->fp;	/* ;dgt2 */
230	do {
231		if (fp < stack_page+sizeof(struct task_struct) ||
232			fp >= 8184+stack_page)	/* ;dgt2;tmp */
233			return 0;
234		pc = ((unsigned long *)fp)[1];
235		if (!in_sched_functions(pc))
236			return pc;
237		fp = *(unsigned long *) fp;
238	} while (count++ < 16);		/* ;dgt2;tmp */
239	return 0;
240}
241
242/*
243 * Do necessary setup to start up a newly executed thread.
244 * Will startup in user mode (status_extension = 0).
245 */
246void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
247{
248	memset((void *) regs, 0, sizeof(struct pt_regs));
249	regs->estatus = ESTATUS_EPIE | ESTATUS_EU;
250	regs->ea = pc;
251	regs->sp = sp;
252}
253
254asmlinkage int nios2_clone(unsigned long clone_flags, unsigned long newsp,
255			   int __user *parent_tidptr, int __user *child_tidptr,
256			   unsigned long tls)
257{
258	struct kernel_clone_args args = {
259		.flags		= (lower_32_bits(clone_flags) & ~CSIGNAL),
260		.pidfd		= parent_tidptr,
261		.child_tid	= child_tidptr,
262		.parent_tid	= parent_tidptr,
263		.exit_signal	= (lower_32_bits(clone_flags) & CSIGNAL),
264		.stack		= newsp,
265		.tls		= tls,
266	};
267
268	return kernel_clone(&args);
269}
v6.9.4
  1/*
  2 * Architecture-dependent parts of process handling.
  3 *
  4 * Copyright (C) 2013 Altera Corporation
  5 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
  6 * Copyright (C) 2009 Wind River Systems Inc
  7 *   Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
  8 * Copyright (C) 2004 Microtronix Datacom Ltd
  9 *
 10 * This file is subject to the terms and conditions of the GNU General Public
 11 * License.  See the file "COPYING" in the main directory of this archive
 12 * for more details.
 13 */
 14
 15#include <linux/export.h>
 16#include <linux/sched.h>
 17#include <linux/sched/debug.h>
 18#include <linux/sched/task.h>
 19#include <linux/sched/task_stack.h>
 20#include <linux/mm_types.h>
 21#include <linux/tick.h>
 22#include <linux/uaccess.h>
 23
 24#include <asm/unistd.h>
 25#include <asm/traps.h>
 26#include <asm/cpuinfo.h>
 27
 28asmlinkage void ret_from_fork(void);
 29asmlinkage void ret_from_kernel_thread(void);
 30
 31void (*pm_power_off)(void) = NULL;
 32EXPORT_SYMBOL(pm_power_off);
 33
 34void arch_cpu_idle(void)
 35{
 
 36}
 37
 38/*
 39 * The development boards have no way to pull a board reset. Just jump to the
 40 * cpu reset address and let the boot loader or the code in head.S take care of
 41 * resetting peripherals.
 42 */
 43void machine_restart(char *__unused)
 44{
 45	pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);
 46	local_irq_disable();
 47	__asm__ __volatile__ (
 48	"jmp	%0\n\t"
 49	:
 50	: "r" (cpuinfo.reset_addr)
 51	: "r4");
 52}
 53
 54void machine_halt(void)
 55{
 56	pr_notice("Machine halt...\n");
 57	local_irq_disable();
 58	for (;;)
 59		;
 60}
 61
 62/*
 63 * There is no way to power off the development boards. So just spin for now. If
 64 * we ever have a way of resetting a board using a GPIO we should add that here.
 65 */
 66void machine_power_off(void)
 67{
 68	pr_notice("Machine power off...\n");
 69	local_irq_disable();
 70	for (;;)
 71		;
 72}
 73
 74void show_regs(struct pt_regs *regs)
 75{
 76	pr_notice("\n");
 77	show_regs_print_info(KERN_DEFAULT);
 78
 79	pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",
 80		regs->r1,  regs->r2,  regs->r3,  regs->r4);
 81
 82	pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",
 83		regs->r5,  regs->r6,  regs->r7,  regs->r8);
 84
 85	pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",
 86		regs->r9,  regs->r10, regs->r11, regs->r12);
 87
 88	pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",
 89		regs->r13, regs->r14, regs->r15);
 90
 91	pr_notice("ra: %08lx fp:  %08lx sp: %08lx gp: %08lx\n",
 92		regs->ra,  regs->fp,  regs->sp,  regs->gp);
 93
 94	pr_notice("ea: %08lx estatus: %08lx\n",
 95		regs->ea,  regs->estatus);
 96}
 97
 98void flush_thread(void)
 99{
100}
101
102int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
103{
104	unsigned long clone_flags = args->flags;
105	unsigned long usp = args->stack;
106	unsigned long tls = args->tls;
107	struct pt_regs *childregs = task_pt_regs(p);
108	struct pt_regs *regs;
109	struct switch_stack *stack;
110	struct switch_stack *childstack =
111		((struct switch_stack *)childregs) - 1;
112
113	if (unlikely(args->fn)) {
114		memset(childstack, 0,
115			sizeof(struct switch_stack) + sizeof(struct pt_regs));
116
117		childstack->r16 = (unsigned long) args->fn;
118		childstack->r17 = (unsigned long) args->fn_arg;
119		childstack->ra = (unsigned long) ret_from_kernel_thread;
120		childregs->estatus = STATUS_PIE;
121		childregs->sp = (unsigned long) childstack;
122
123		p->thread.ksp = (unsigned long) childstack;
124		p->thread.kregs = childregs;
125		return 0;
126	}
127
128	regs = current_pt_regs();
129	*childregs = *regs;
130	childregs->r2 = 0;	/* Set the return value for the child. */
131	childregs->r7 = 0;
132
133	stack = ((struct switch_stack *) regs) - 1;
134	*childstack = *stack;
135	childstack->ra = (unsigned long)ret_from_fork;
136	p->thread.kregs = childregs;
137	p->thread.ksp = (unsigned long) childstack;
138
139	if (usp)
140		childregs->sp = usp;
141
142	/* Initialize tls register. */
143	if (clone_flags & CLONE_SETTLS)
144		childstack->r23 = tls;
145
146	return 0;
147}
148
149/*
150 *	Generic dumping code. Used for panic and debug.
151 */
152void dump(struct pt_regs *fp)
153{
154	unsigned long	*sp;
155	unsigned char	*tp;
156	int		i;
157
158	pr_emerg("\nCURRENT PROCESS:\n\n");
159	pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);
160
161	if (current->mm) {
162		pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
163			(int) current->mm->start_code,
164			(int) current->mm->end_code,
165			(int) current->mm->start_data,
166			(int) current->mm->end_data,
167			(int) current->mm->end_data,
168			(int) current->mm->brk);
169		pr_emerg("USER-STACK=%08x  KERNEL-STACK=%08x\n\n",
170			(int) current->mm->start_stack,
171			(int)(((unsigned long) current) + THREAD_SIZE));
172	}
173
174	pr_emerg("PC: %08lx\n", fp->ea);
175	pr_emerg("SR: %08lx    SP: %08lx\n",
176		(long) fp->estatus, (long) fp);
177
178	pr_emerg("r1: %08lx    r2: %08lx    r3: %08lx\n",
179		fp->r1, fp->r2, fp->r3);
180
181	pr_emerg("r4: %08lx    r5: %08lx    r6: %08lx    r7: %08lx\n",
182		fp->r4, fp->r5, fp->r6, fp->r7);
183	pr_emerg("r8: %08lx    r9: %08lx    r10: %08lx    r11: %08lx\n",
184		fp->r8, fp->r9, fp->r10, fp->r11);
185	pr_emerg("r12: %08lx  r13: %08lx    r14: %08lx    r15: %08lx\n",
186		fp->r12, fp->r13, fp->r14, fp->r15);
187	pr_emerg("or2: %08lx   ra: %08lx     fp: %08lx    sp: %08lx\n",
188		fp->orig_r2, fp->ra, fp->fp, fp->sp);
189	pr_emerg("\nUSP: %08x   TRAPFRAME: %08x\n",
190		(unsigned int) fp->sp, (unsigned int) fp);
191
192	pr_emerg("\nCODE:");
193	tp = ((unsigned char *) fp->ea) - 0x20;
194	for (sp = (unsigned long *) tp, i = 0; (i < 0x40);  i += 4) {
195		if ((i % 0x10) == 0)
196			pr_emerg("\n%08x: ", (int) (tp + i));
197		pr_emerg("%08x ", (int) *sp++);
198	}
199	pr_emerg("\n");
200
201	pr_emerg("\nKERNEL STACK:");
202	tp = ((unsigned char *) fp) - 0x40;
203	for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
204		if ((i % 0x10) == 0)
205			pr_emerg("\n%08x: ", (int) (tp + i));
206		pr_emerg("%08x ", (int) *sp++);
207	}
208	pr_emerg("\n");
209	pr_emerg("\n");
210
211	pr_emerg("\nUSER STACK:");
212	tp = (unsigned char *) (fp->sp - 0x10);
213	for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
214		if ((i % 0x10) == 0)
215			pr_emerg("\n%08x: ", (int) (tp + i));
216		pr_emerg("%08x ", (int) *sp++);
217	}
218	pr_emerg("\n\n");
219}
220
221unsigned long __get_wchan(struct task_struct *p)
222{
223	unsigned long fp, pc;
224	unsigned long stack_page;
225	int count = 0;
226
227	stack_page = (unsigned long)p;
228	fp = ((struct switch_stack *)p->thread.ksp)->fp;	/* ;dgt2 */
229	do {
230		if (fp < stack_page+sizeof(struct task_struct) ||
231			fp >= 8184+stack_page)	/* ;dgt2;tmp */
232			return 0;
233		pc = ((unsigned long *)fp)[1];
234		if (!in_sched_functions(pc))
235			return pc;
236		fp = *(unsigned long *) fp;
237	} while (count++ < 16);		/* ;dgt2;tmp */
238	return 0;
239}
240
241/*
242 * Do necessary setup to start up a newly executed thread.
243 * Will startup in user mode (status_extension = 0).
244 */
245void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
246{
247	memset((void *) regs, 0, sizeof(struct pt_regs));
248	regs->estatus = ESTATUS_EPIE | ESTATUS_EU;
249	regs->ea = pc;
250	regs->sp = sp;
251}
252
253asmlinkage int nios2_clone(unsigned long clone_flags, unsigned long newsp,
254			   int __user *parent_tidptr, int __user *child_tidptr,
255			   unsigned long tls)
256{
257	struct kernel_clone_args args = {
258		.flags		= (lower_32_bits(clone_flags) & ~CSIGNAL),
259		.pidfd		= parent_tidptr,
260		.child_tid	= child_tidptr,
261		.parent_tid	= parent_tidptr,
262		.exit_signal	= (lower_32_bits(clone_flags) & CSIGNAL),
263		.stack		= newsp,
264		.tls		= tls,
265	};
266
267	return kernel_clone(&args);
268}