]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/avr32/kernel/process.c
2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #include <linux/sched.h>
9 #include <linux/module.h>
10 #include <linux/kallsyms.h>
12 #include <linux/ptrace.h>
13 #include <linux/reboot.h>
14 #include <linux/unistd.h>
16 #include <asm/sysreg.h>
19 void (*pm_power_off
)(void) = NULL
;
20 EXPORT_SYMBOL(pm_power_off
);
23 * This file handles the architecture-dependent parts of process handling..
28 /* endless idle loop with no priority at all */
30 /* TODO: Enter sleep mode */
31 while (!need_resched())
33 preempt_enable_no_resched();
39 void machine_halt(void)
43 void machine_power_off(void)
47 void machine_restart(char *cmd
)
49 __mtdr(DBGREG_DC
, DC_DBE
);
50 __mtdr(DBGREG_DC
, DC_RES
);
55 * PC is actually discarded when returning from a system call -- the
56 * return address must be stored in LR. This function will make sure
57 * LR points to do_exit before starting the thread.
59 * Also, when returning from fork(), r12 is 0, so we must copy the
62 * r0 : The argument to the main thread function
63 * r1 : The address of do_exit
64 * r2 : The address of the main thread function
66 asmlinkage
extern void kernel_thread_helper(void);
67 __asm__(" .type kernel_thread_helper, @function\n"
68 "kernel_thread_helper:\n"
72 " .size kernel_thread_helper, . - kernel_thread_helper");
74 int kernel_thread(int (*fn
)(void *), void *arg
, unsigned long flags
)
78 memset(®s
, 0, sizeof(regs
));
80 regs
.r0
= (unsigned long)arg
;
81 regs
.r1
= (unsigned long)fn
;
82 regs
.r2
= (unsigned long)do_exit
;
83 regs
.lr
= (unsigned long)kernel_thread_helper
;
84 regs
.pc
= (unsigned long)kernel_thread_helper
;
85 regs
.sr
= MODE_SUPERVISOR
;
87 return do_fork(flags
| CLONE_VM
| CLONE_UNTRACED
,
88 0, ®s
, 0, NULL
, NULL
);
90 EXPORT_SYMBOL(kernel_thread
);
93 * Free current thread data structures etc
95 void exit_thread(void)
100 void flush_thread(void)
105 void release_thread(struct task_struct
*dead_task
)
110 static const char *cpu_modes
[] = {
111 "Application", "Supervisor", "Interrupt level 0", "Interrupt level 1",
112 "Interrupt level 2", "Interrupt level 3", "Exception", "NMI"
115 void show_regs(struct pt_regs
*regs
)
117 unsigned long sp
= regs
->sp
;
118 unsigned long lr
= regs
->lr
;
119 unsigned long mode
= (regs
->sr
& MODE_MASK
) >> MODE_SHIFT
;
121 if (!user_mode(regs
))
122 sp
= (unsigned long)regs
+ FRAME_SIZE_FULL
;
124 print_symbol("PC is at %s\n", instruction_pointer(regs
));
125 print_symbol("LR is at %s\n", lr
);
126 printk("pc : [<%08lx>] lr : [<%08lx>] %s\n"
127 "sp : %08lx r12: %08lx r11: %08lx\n",
128 instruction_pointer(regs
),
129 lr
, print_tainted(), sp
, regs
->r12
, regs
->r11
);
130 printk("r10: %08lx r9 : %08lx r8 : %08lx\n",
131 regs
->r10
, regs
->r9
, regs
->r8
);
132 printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
133 regs
->r7
, regs
->r6
, regs
->r5
, regs
->r4
);
134 printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
135 regs
->r3
, regs
->r2
, regs
->r1
, regs
->r0
);
136 printk("Flags: %c%c%c%c%c\n",
137 regs
->sr
& SR_Q
? 'Q' : 'q',
138 regs
->sr
& SR_V
? 'V' : 'v',
139 regs
->sr
& SR_N
? 'N' : 'n',
140 regs
->sr
& SR_Z
? 'Z' : 'z',
141 regs
->sr
& SR_C
? 'C' : 'c');
142 printk("Mode bits: %c%c%c%c%c%c%c%c%c\n",
143 regs
->sr
& SR_H
? 'H' : 'h',
144 regs
->sr
& SR_R
? 'R' : 'r',
145 regs
->sr
& SR_J
? 'J' : 'j',
146 regs
->sr
& SR_EM
? 'E' : 'e',
147 regs
->sr
& SR_I3M
? '3' : '.',
148 regs
->sr
& SR_I2M
? '2' : '.',
149 regs
->sr
& SR_I1M
? '1' : '.',
150 regs
->sr
& SR_I0M
? '0' : '.',
151 regs
->sr
& SR_GM
? 'G' : 'g');
152 printk("CPU Mode: %s\n", cpu_modes
[mode
]);
154 show_trace(NULL
, (unsigned long *)sp
, regs
);
156 EXPORT_SYMBOL(show_regs
);
158 /* Fill in the fpu structure for a core dump. This is easy -- we don't have any */
159 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
165 asmlinkage
void ret_from_fork(void);
167 int copy_thread(int nr
, unsigned long clone_flags
, unsigned long usp
,
168 unsigned long unused
,
169 struct task_struct
*p
, struct pt_regs
*regs
)
171 struct pt_regs
*childregs
;
173 childregs
= ((struct pt_regs
*)(THREAD_SIZE
+ (unsigned long)p
->thread_info
)) - 1;
179 childregs
->sp
= (unsigned long)p
->thread_info
+ THREAD_SIZE
;
181 childregs
->r12
= 0; /* Set return value for child */
183 p
->thread
.cpu_context
.sr
= MODE_SUPERVISOR
| SR_GM
;
184 p
->thread
.cpu_context
.ksp
= (unsigned long)childregs
;
185 p
->thread
.cpu_context
.pc
= (unsigned long)ret_from_fork
;
190 /* r12-r8 are dummy parameters to force the compiler to use the stack */
191 asmlinkage
int sys_fork(struct pt_regs
*regs
)
193 return do_fork(SIGCHLD
, regs
->sp
, regs
, 0, NULL
, NULL
);
196 asmlinkage
int sys_clone(unsigned long clone_flags
, unsigned long newsp
,
197 unsigned long parent_tidptr
,
198 unsigned long child_tidptr
, struct pt_regs
*regs
)
202 return do_fork(clone_flags
, newsp
, regs
, 0,
203 (int __user
*)parent_tidptr
,
204 (int __user
*)child_tidptr
);
207 asmlinkage
int sys_vfork(struct pt_regs
*regs
)
209 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, regs
->sp
, regs
,
213 asmlinkage
int sys_execve(char __user
*ufilename
, char __user
*__user
*uargv
,
214 char __user
*__user
*uenvp
, struct pt_regs
*regs
)
219 filename
= getname(ufilename
);
220 error
= PTR_ERR(filename
);
221 if (IS_ERR(filename
))
224 error
= do_execve(filename
, uargv
, uenvp
, regs
);
226 current
->ptrace
&= ~PT_DTRACE
;
235 * This function is supposed to answer the question "who called
238 unsigned long get_wchan(struct task_struct
*p
)
241 unsigned long stack_page
;
243 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
246 stack_page
= (unsigned long)p
->thread_info
;
250 * The stored value of PC is either the address right after
251 * the call to __switch_to() or ret_from_fork.
253 pc
= thread_saved_pc(p
);
254 if (in_sched_functions(pc
)) {
255 #ifdef CONFIG_FRAME_POINTER
256 unsigned long fp
= p
->thread
.cpu_context
.r7
;
257 BUG_ON(fp
< stack_page
|| fp
> (THREAD_SIZE
+ stack_page
));
258 pc
= *(unsigned long *)fp
;
261 * We depend on the frame size of schedule here, which
262 * is actually quite ugly. It might be possible to
263 * determine the frame size automatically at build
264 * time by doing this:
266 * - disassemble the resulting sched.o
267 * - look for 'sub sp,??' shortly after '<schedule>:'
269 unsigned long sp
= p
->thread
.cpu_context
.ksp
+ 16;
270 BUG_ON(sp
< stack_page
|| sp
> (THREAD_SIZE
+ stack_page
));
271 pc
= *(unsigned long *)sp
;