Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 2 | * This file handles the architecture dependent parts of process handling. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999,2009 |
| 5 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>, |
| 6 | * Hartmut Penner <hp@de.ibm.com>, |
| 7 | * Denis Joseph Barrow, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/compiler.h> |
| 11 | #include <linux/cpu.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 16 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/stddef.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/ptrace.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/vmalloc.h> |
| 23 | #include <linux/user.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/reboot.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/notifier.h> |
Heiko Carstens | 5c69971 | 2008-01-26 14:11:01 +0100 | [diff] [blame] | 30 | #include <linux/utsname.h> |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 31 | #include <linux/tick.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 32 | #include <linux/elfcore.h> |
Martin Schwidefsky | 6f43092 | 2008-12-31 15:11:40 +0100 | [diff] [blame] | 33 | #include <linux/kernel_stat.h> |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 34 | #include <linux/syscalls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/pgtable.h> |
| 37 | #include <asm/system.h> |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/processor.h> |
| 40 | #include <asm/irq.h> |
| 41 | #include <asm/timer.h> |
Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 42 | #include <asm/nmi.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 43 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 45 | asmlinkage void ret_from_fork(void) asm ("ret_from_fork"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Return saved PC of a blocked thread. used in kernel/sched. |
| 49 | * resume in entry.S does not create a new stack frame, it |
| 50 | * just stores the registers %r6-%r15 to the frame given by |
| 51 | * schedule. We want to return the address of the caller of |
| 52 | * schedule, so we have to walk the backchain one time to |
| 53 | * find the frame schedule() store its return address. |
| 54 | */ |
| 55 | unsigned long thread_saved_pc(struct task_struct *tsk) |
| 56 | { |
Heiko Carstens | eb33c19 | 2006-01-14 13:20:57 -0800 | [diff] [blame] | 57 | struct stack_frame *sf, *low, *high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Heiko Carstens | eb33c19 | 2006-01-14 13:20:57 -0800 | [diff] [blame] | 59 | if (!tsk || !task_stack_page(tsk)) |
| 60 | return 0; |
| 61 | low = task_stack_page(tsk); |
| 62 | high = (struct stack_frame *) task_pt_regs(tsk); |
| 63 | sf = (struct stack_frame *) (tsk->thread.ksp & PSW_ADDR_INSN); |
| 64 | if (sf <= low || sf > high) |
| 65 | return 0; |
| 66 | sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN); |
| 67 | if (sf <= low || sf > high) |
| 68 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return sf->gprs[8]; |
| 70 | } |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* |
| 73 | * The idle loop on a S390... |
| 74 | */ |
Adrian Bunk | cdb0452 | 2006-03-24 03:15:57 -0800 | [diff] [blame] | 75 | static void default_idle(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* CPU is going idle. */ |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 78 | local_irq_disable(); |
| 79 | if (need_resched()) { |
| 80 | local_irq_enable(); |
| 81 | return; |
| 82 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_HOTPLUG_CPU |
Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 84 | if (cpu_is_offline(smp_processor_id())) { |
Heiko Carstens | 1fca251 | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 85 | preempt_enable_no_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | cpu_die(); |
Heiko Carstens | 1fca251 | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 89 | local_mcck_disable(); |
| 90 | if (test_thread_flag(TIF_MCCK_PENDING)) { |
| 91 | local_mcck_enable(); |
| 92 | local_irq_enable(); |
| 93 | s390_handle_mcck(); |
| 94 | return; |
| 95 | } |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 96 | trace_hardirqs_on(); |
Heiko Carstens | 632448f | 2008-11-14 18:18:04 +0100 | [diff] [blame] | 97 | /* Don't trace preempt off for idle. */ |
| 98 | stop_critical_timings(); |
Martin Schwidefsky | 9cfb9b3 | 2008-12-31 15:11:41 +0100 | [diff] [blame] | 99 | /* Stop virtual timer and halt the cpu. */ |
| 100 | vtime_stop_cpu(); |
| 101 | /* Reenable preemption tracer. */ |
Heiko Carstens | 632448f | 2008-11-14 18:18:04 +0100 | [diff] [blame] | 102 | start_critical_timings(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void cpu_idle(void) |
| 106 | { |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 107 | for (;;) { |
Thomas Gleixner | e338125 | 2008-07-19 09:33:21 +0200 | [diff] [blame] | 108 | tick_nohz_stop_sched_tick(1); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 109 | while (!need_resched()) |
| 110 | default_idle(); |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 111 | tick_nohz_restart_sched_tick(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 112 | preempt_enable_no_resched(); |
| 113 | schedule(); |
| 114 | preempt_disable(); |
| 115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | extern void kernel_thread_starter(void); |
| 119 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 120 | asm( |
| 121 | ".align 4\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | "kernel_thread_starter:\n" |
| 123 | " la 2,0(10)\n" |
| 124 | " basr 14,9\n" |
| 125 | " la 2,0\n" |
| 126 | " br 11\n"); |
| 127 | |
| 128 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) |
| 129 | { |
| 130 | struct pt_regs regs; |
| 131 | |
| 132 | memset(®s, 0, sizeof(regs)); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 133 | regs.psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | regs.psw.addr = (unsigned long) kernel_thread_starter | PSW_ADDR_AMODE; |
| 135 | regs.gprs[9] = (unsigned long) fn; |
| 136 | regs.gprs[10] = (unsigned long) arg; |
| 137 | regs.gprs[11] = (unsigned long) do_exit; |
| 138 | regs.orig_gpr2 = -1; |
| 139 | |
| 140 | /* Ok, create the new process.. */ |
| 141 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, |
| 142 | 0, ®s, 0, NULL, NULL); |
| 143 | } |
Heiko Carstens | 1485c5c | 2009-03-26 15:24:04 +0100 | [diff] [blame] | 144 | EXPORT_SYMBOL(kernel_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * Free current thread data structures etc.. |
| 148 | */ |
| 149 | void exit_thread(void) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | void flush_thread(void) |
| 154 | { |
| 155 | clear_used_math(); |
| 156 | clear_tsk_thread_flag(current, TIF_USEDFPU); |
| 157 | } |
| 158 | |
| 159 | void release_thread(struct task_struct *dead_task) |
| 160 | { |
| 161 | } |
| 162 | |
Alexey Dobriyan | 6f2c55b | 2009-04-02 16:56:59 -0700 | [diff] [blame^] | 163 | int copy_thread(unsigned long clone_flags, unsigned long new_stackp, |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 164 | unsigned long unused, |
| 165 | struct task_struct *p, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Heiko Carstens | 5168ce2c | 2009-03-26 15:23:53 +0100 | [diff] [blame] | 167 | struct thread_info *ti; |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 168 | struct fake_frame |
| 169 | { |
| 170 | struct stack_frame sf; |
| 171 | struct pt_regs childregs; |
| 172 | } *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 174 | frame = container_of(task_pt_regs(p), struct fake_frame, childregs); |
| 175 | p->thread.ksp = (unsigned long) frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* Store access registers to kernel stack of new process. */ |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 177 | frame->childregs = *regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | frame->childregs.gprs[2] = 0; /* child returns 0 on fork. */ |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 179 | frame->childregs.gprs[15] = new_stackp; |
| 180 | frame->sf.back_chain = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 182 | /* new return point is ret_from_fork */ |
| 183 | frame->sf.gprs[8] = (unsigned long) ret_from_fork; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 185 | /* fake return stack for resume(), don't go back to schedule */ |
| 186 | frame->sf.gprs[9] = (unsigned long) frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* Save access registers to new thread structure. */ |
| 189 | save_access_regs(&p->thread.acrs[0]); |
| 190 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 191 | #ifndef CONFIG_64BIT |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 192 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | * save fprs to current->thread.fp_regs to merge them with |
| 194 | * the emulated registers and then copy the result to the child. |
| 195 | */ |
| 196 | save_fp_regs(¤t->thread.fp_regs); |
| 197 | memcpy(&p->thread.fp_regs, ¤t->thread.fp_regs, |
| 198 | sizeof(s390_fp_regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /* Set a new TLS ? */ |
| 200 | if (clone_flags & CLONE_SETTLS) |
| 201 | p->thread.acrs[0] = regs->gprs[6]; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 202 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* Save the fpu registers to new thread structure. */ |
| 204 | save_fp_regs(&p->thread.fp_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* Set a new TLS ? */ |
| 206 | if (clone_flags & CLONE_SETTLS) { |
| 207 | if (test_thread_flag(TIF_31BIT)) { |
| 208 | p->thread.acrs[0] = (unsigned int) regs->gprs[6]; |
| 209 | } else { |
| 210 | p->thread.acrs[0] = (unsigned int)(regs->gprs[6] >> 32); |
| 211 | p->thread.acrs[1] = (unsigned int) regs->gprs[6]; |
| 212 | } |
| 213 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 214 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | /* start new process with ar4 pointing to the correct address space */ |
| 216 | p->thread.mm_segment = get_fs(); |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 217 | /* Don't copy debug registers */ |
| 218 | memset(&p->thread.per_info, 0, sizeof(p->thread.per_info)); |
Heiko Carstens | 5168ce2c | 2009-03-26 15:23:53 +0100 | [diff] [blame] | 219 | /* Initialize per thread user and system timer values */ |
| 220 | ti = task_thread_info(p); |
| 221 | ti->user_timer = 0; |
| 222 | ti->system_timer = 0; |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 223 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 226 | SYSCALL_DEFINE0(fork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 228 | struct pt_regs *regs = task_pt_regs(current); |
| 229 | return do_fork(SIGCHLD, regs->gprs[15], regs, 0, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 232 | SYSCALL_DEFINE0(clone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 234 | struct pt_regs *regs = task_pt_regs(current); |
| 235 | unsigned long clone_flags; |
| 236 | unsigned long newsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | int __user *parent_tidptr, *child_tidptr; |
| 238 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 239 | clone_flags = regs->gprs[3]; |
| 240 | newsp = regs->orig_gpr2; |
| 241 | parent_tidptr = (int __user *) regs->gprs[4]; |
| 242 | child_tidptr = (int __user *) regs->gprs[5]; |
| 243 | if (!newsp) |
| 244 | newsp = regs->gprs[15]; |
| 245 | return do_fork(clone_flags, newsp, regs, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | parent_tidptr, child_tidptr); |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * This is trivial, and on the face of it looks like it |
| 251 | * could equally well be done in user mode. |
| 252 | * |
| 253 | * Not so, for quite unobvious reasons - register pressure. |
| 254 | * In user mode vfork() cannot have a stack frame, and if |
| 255 | * done by calling the "clone()" system call directly, you |
| 256 | * do not have enough call-clobbered registers to hold all |
| 257 | * the information you need. |
| 258 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 259 | SYSCALL_DEFINE0(vfork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 261 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 263 | regs->gprs[15], regs, 0, NULL, NULL); |
| 264 | } |
| 265 | |
| 266 | asmlinkage void execve_tail(void) |
| 267 | { |
| 268 | task_lock(current); |
| 269 | current->ptrace &= ~PT_DTRACE; |
| 270 | task_unlock(current); |
| 271 | current->thread.fp_regs.fpc = 0; |
| 272 | if (MACHINE_HAS_IEEE) |
| 273 | asm volatile("sfpc %0,%0" : : "d" (0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* |
| 277 | * sys_execve() executes a new program. |
| 278 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 279 | SYSCALL_DEFINE0(execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 281 | struct pt_regs *regs = task_pt_regs(current); |
| 282 | char *filename; |
| 283 | unsigned long result; |
| 284 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 286 | filename = getname((char __user *) regs->orig_gpr2); |
| 287 | if (IS_ERR(filename)) { |
| 288 | result = PTR_ERR(filename); |
| 289 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 291 | rc = do_execve(filename, (char __user * __user *) regs->gprs[3], |
| 292 | (char __user * __user *) regs->gprs[4], regs); |
| 293 | if (rc) { |
| 294 | result = rc; |
| 295 | goto out_putname; |
| 296 | } |
| 297 | execve_tail(); |
| 298 | result = regs->gprs[2]; |
| 299 | out_putname: |
| 300 | putname(filename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | out: |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 302 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | /* |
| 306 | * fill in the FPU structure for a core dump. |
| 307 | */ |
| 308 | int dump_fpu (struct pt_regs * regs, s390_fp_regs *fpregs) |
| 309 | { |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 310 | #ifndef CONFIG_64BIT |
Heiko Carstens | cbdc229 | 2009-03-26 15:23:52 +0100 | [diff] [blame] | 311 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | * save fprs to current->thread.fp_regs to merge them with |
| 313 | * the emulated registers and then copy the result to the dump. |
| 314 | */ |
| 315 | save_fp_regs(¤t->thread.fp_regs); |
| 316 | memcpy(fpregs, ¤t->thread.fp_regs, sizeof(s390_fp_regs)); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 317 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | save_fp_regs(fpregs); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 319 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return 1; |
| 321 | } |
Heiko Carstens | 1485c5c | 2009-03-26 15:24:04 +0100 | [diff] [blame] | 322 | EXPORT_SYMBOL(dump_fpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | unsigned long get_wchan(struct task_struct *p) |
| 325 | { |
| 326 | struct stack_frame *sf, *low, *high; |
| 327 | unsigned long return_address; |
| 328 | int count; |
| 329 | |
Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 330 | if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return 0; |
Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 332 | low = task_stack_page(p); |
| 333 | high = (struct stack_frame *) task_pt_regs(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | sf = (struct stack_frame *) (p->thread.ksp & PSW_ADDR_INSN); |
| 335 | if (sf <= low || sf > high) |
| 336 | return 0; |
| 337 | for (count = 0; count < 16; count++) { |
| 338 | sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN); |
| 339 | if (sf <= low || sf > high) |
| 340 | return 0; |
| 341 | return_address = sf->gprs[8] & PSW_ADDR_INSN; |
| 342 | if (!in_sched_functions(return_address)) |
| 343 | return return_address; |
| 344 | } |
| 345 | return 0; |
| 346 | } |