Linux Audio

Check our new training course

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