traps.c 17.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *  linux/arch/arm/kernel/traps.c
 *
 *  Copyright (C) 1995-2002 Russell King
 *  Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  'traps.c' handles hardware exceptions after we have saved some state in
 *  'linux/arch/arm/lib/traps.S'.  Mostly a debugging aid, but will probably
 *  kill the offending process.
 */
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/spinlock.h>
#include <linux/personality.h>
#include <linux/kallsyms.h>
R
Russell King 已提交
20
#include <linux/delay.h>
L
Linus Torvalds 已提交
21
#include <linux/init.h>
22
#include <linux/kprobes.h>
L
Linus Torvalds 已提交
23 24 25 26 27 28 29

#include <asm/atomic.h>
#include <asm/cacheflush.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <asm/traps.h>
30
#include <asm/io.h>
L
Linus Torvalds 已提交
31 32

#include "ptrace.h"
33
#include "signal.h"
L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47

static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };

#ifdef CONFIG_DEBUG_USER
unsigned int user_debug;

static int __init user_debug_setup(char *str)
{
	get_option(&str, &user_debug);
	return 1;
}
__setup("user_debug=", user_debug_setup);
#endif

48 49 50
static void dump_mem(const char *str, unsigned long bottom, unsigned long top);

void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
L
Linus Torvalds 已提交
51 52 53 54 55 56 57 58 59
{
#ifdef CONFIG_KALLSYMS
	printk("[<%08lx>] ", where);
	print_symbol("(%s) ", where);
	printk("from [<%08lx>] ", from);
	print_symbol("(%s)\n", from);
#else
	printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
#endif
60 61 62

	if (in_exception_text(where))
		dump_mem("Exception stack", frame + 4, frame + 4 + sizeof(struct pt_regs));
L
Linus Torvalds 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
}

/*
 * Stack pointers should always be within the kernels view of
 * physical memory.  If it is not there, then we can't dump
 * out any information relating to the stack.
 */
static int verify_stack(unsigned long sp)
{
	if (sp < PAGE_OFFSET || (sp > (unsigned long)high_memory && high_memory != 0))
		return -EFAULT;

	return 0;
}

/*
 * Dump out the contents of some memory nicely...
 */
static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
{
	unsigned long p = bottom & ~31;
	mm_segment_t fs;
	int i;

	/*
	 * We need to switch to kernel mode so that we can use __get_user
	 * to safely read from kernel space.  Note that we now dump the
	 * code first, just in case the backtrace kills us.
	 */
	fs = get_fs();
	set_fs(KERNEL_DS);

	printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);

	for (p = bottom & ~31; p < top;) {
		printk("%04lx: ", p & 0xffff);

		for (i = 0; i < 8; i++, p += 4) {
			unsigned int val;

			if (p < bottom || p >= top)
				printk("         ");
			else {
				__get_user(val, (unsigned long *)p);
				printk("%08x ", val);
			}
		}
		printk ("\n");
	}

	set_fs(fs);
}

static void dump_instr(struct pt_regs *regs)
{
	unsigned long addr = instruction_pointer(regs);
	const int thumb = thumb_mode(regs);
	const int width = thumb ? 4 : 8;
	mm_segment_t fs;
	int i;

	/*
	 * We need to switch to kernel mode so that we can use __get_user
	 * to safely read from kernel space.  Note that we now dump the
	 * code first, just in case the backtrace kills us.
	 */
	fs = get_fs();
	set_fs(KERNEL_DS);

	printk("Code: ");
	for (i = -4; i < 1; i++) {
		unsigned int val, bad;

		if (thumb)
			bad = __get_user(val, &((u16 *)addr)[i]);
		else
			bad = __get_user(val, &((u32 *)addr)[i]);

		if (!bad)
			printk(i == 0 ? "(%0*x) " : "%0*x ", width, val);
		else {
			printk("bad PC value.");
			break;
		}
	}
	printk("\n");

	set_fs(fs);
}

static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
{
	unsigned int fp;
	int ok = 1;

	printk("Backtrace: ");
	fp = regs->ARM_fp;
	if (!fp) {
		printk("no frame pointer");
		ok = 0;
	} else if (verify_stack(fp)) {
		printk("invalid frame pointer 0x%08x", fp);
		ok = 0;
A
Al Viro 已提交
166
	} else if (fp < (unsigned long)end_of_stack(tsk))
L
Linus Torvalds 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
		printk("frame pointer underflow");
	printk("\n");

	if (ok)
		c_backtrace(fp, processor_mode(regs));
}

void dump_stack(void)
{
	__backtrace();
}

EXPORT_SYMBOL(dump_stack);

void show_stack(struct task_struct *tsk, unsigned long *sp)
{
	unsigned long fp;

	if (!tsk)
		tsk = current;

	if (tsk != current)
		fp = thread_saved_fp(tsk);
	else
191
		asm("mov %0, fp" : "=r" (fp) : : "cc");
L
Linus Torvalds 已提交
192 193 194 195 196

	c_backtrace(fp, 0x10);
	barrier();
}

197 198 199 200 201 202 203 204 205 206 207
#ifdef CONFIG_PREEMPT
#define S_PREEMPT " PREEMPT"
#else
#define S_PREEMPT ""
#endif
#ifdef CONFIG_SMP
#define S_SMP " SMP"
#else
#define S_SMP ""
#endif

R
Russell King 已提交
208
static void __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs)
L
Linus Torvalds 已提交
209
{
R
Russell King 已提交
210
	struct task_struct *tsk = thread->task;
L
Linus Torvalds 已提交
211 212
	static int die_counter;

213 214
	printk("Internal error: %s: %x [#%d]" S_PREEMPT S_SMP "\n",
	       str, err, ++die_counter);
L
Linus Torvalds 已提交
215
	print_modules();
R
Russell King 已提交
216
	__show_regs(regs);
L
Linus Torvalds 已提交
217
	printk("Process %s (pid: %d, stack limit = 0x%p)\n",
218
		tsk->comm, task_pid_nr(tsk), thread + 1);
L
Linus Torvalds 已提交
219 220

	if (!user_mode(regs) || in_interrupt()) {
221
		dump_mem("Stack: ", regs->ARM_sp,
A
Al Viro 已提交
222
			 THREAD_SIZE + (unsigned long)task_stack_page(tsk));
L
Linus Torvalds 已提交
223 224 225
		dump_backtrace(regs, tsk);
		dump_instr(regs);
	}
R
Russell King 已提交
226
}
L
Linus Torvalds 已提交
227

R
Russell King 已提交
228 229 230 231 232 233 234 235 236
DEFINE_SPINLOCK(die_lock);

/*
 * This function is protected against re-entrancy.
 */
NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
{
	struct thread_info *thread = current_thread_info();

237 238
	oops_enter();

R
Russell King 已提交
239 240 241 242
	console_verbose();
	spin_lock_irq(&die_lock);
	bust_spinlocks(1);
	__die(str, err, thread, regs);
L
Linus Torvalds 已提交
243
	bust_spinlocks(0);
244
	add_taint(TAINT_DIE);
L
Linus Torvalds 已提交
245
	spin_unlock_irq(&die_lock);
R
Russell King 已提交
246

247 248 249
	if (in_interrupt())
		panic("Fatal exception in interrupt");

H
Horms 已提交
250
	if (panic_on_oops)
251
		panic("Fatal exception");
R
Russell King 已提交
252

253
	oops_exit();
L
Linus Torvalds 已提交
254 255 256
	do_exit(SIGSEGV);
}

257 258
void arm_notify_die(const char *str, struct pt_regs *regs,
		struct siginfo *info, unsigned long err, unsigned long trap)
L
Linus Torvalds 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
{
	if (user_mode(regs)) {
		current->thread.error_code = err;
		current->thread.trap_no = trap;

		force_sig_info(info->si_signo, info, current);
	} else {
		die(str, regs, err);
	}
}

static LIST_HEAD(undef_hook);
static DEFINE_SPINLOCK(undef_lock);

void register_undef_hook(struct undef_hook *hook)
{
275 276 277
	unsigned long flags;

	spin_lock_irqsave(&undef_lock, flags);
L
Linus Torvalds 已提交
278
	list_add(&hook->node, &undef_hook);
279
	spin_unlock_irqrestore(&undef_lock, flags);
L
Linus Torvalds 已提交
280 281 282 283
}

void unregister_undef_hook(struct undef_hook *hook)
{
284 285 286
	unsigned long flags;

	spin_lock_irqsave(&undef_lock, flags);
L
Linus Torvalds 已提交
287
	list_del(&hook->node);
288
	spin_unlock_irqrestore(&undef_lock, flags);
L
Linus Torvalds 已提交
289 290
}

291
asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
L
Linus Torvalds 已提交
292 293 294 295 296 297
{
	unsigned int correction = thumb_mode(regs) ? 2 : 4;
	unsigned int instr;
	struct undef_hook *hook;
	siginfo_t info;
	void __user *pc;
298
	unsigned long flags;
L
Linus Torvalds 已提交
299 300 301 302 303 304 305 306 307

	/*
	 * According to the ARM ARM, PC is 2 or 4 bytes ahead,
	 * depending whether we're in Thumb mode or not.
	 * Correct this offset.
	 */
	regs->ARM_pc -= correction;

	pc = (void __user *)instruction_pointer(regs);
308 309 310 311

	if (processor_mode(regs) == SVC_MODE) {
		instr = *(u32 *) pc;
	} else if (thumb_mode(regs)) {
L
Linus Torvalds 已提交
312 313 314 315 316
		get_user(instr, (u16 __user *)pc);
	} else {
		get_user(instr, (u32 __user *)pc);
	}

317 318 319 320 321 322 323 324 325 326 327
#ifdef CONFIG_KPROBES
	/*
	 * It is possible to have recursive kprobes, so we can't call
	 * the kprobe trap handler with the undef_lock held.
	 */
	if (instr == KPROBE_BREAKPOINT_INSTRUCTION && !user_mode(regs)) {
		kprobe_trap_handler(regs, instr);
		return;
	}
#endif

328
	spin_lock_irqsave(&undef_lock, flags);
L
Linus Torvalds 已提交
329 330 331 332
	list_for_each_entry(hook, &undef_hook, node) {
		if ((instr & hook->instr_mask) == hook->instr_val &&
		    (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val) {
			if (hook->fn(regs, instr) == 0) {
333
				spin_unlock_irqrestore(&undef_lock, flags);
L
Linus Torvalds 已提交
334 335 336 337
				return;
			}
		}
	}
338
	spin_unlock_irqrestore(&undef_lock, flags);
L
Linus Torvalds 已提交
339 340 341 342

#ifdef CONFIG_DEBUG_USER
	if (user_debug & UDBG_UNDEFINED) {
		printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",
343
			current->comm, task_pid_nr(current), pc);
L
Linus Torvalds 已提交
344 345 346 347 348 349 350 351 352
		dump_instr(regs);
	}
#endif

	info.si_signo = SIGILL;
	info.si_errno = 0;
	info.si_code  = ILL_ILLOPC;
	info.si_addr  = pc;

353
	arm_notify_die("Oops - undefined instruction", regs, &info, 0, 6);
L
Linus Torvalds 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367
}

asmlinkage void do_unexp_fiq (struct pt_regs *regs)
{
	printk("Hmm.  Unexpected FIQ received, but trying to continue\n");
	printk("You may have a hardware problem...\n");
}

/*
 * bad_mode handles the impossible case in the vectors.  If you see one of
 * these, then it's extremely serious, and could mean you have buggy hardware.
 * It never returns, and never tries to sync.  We hope that we can at least
 * dump out some state information...
 */
368
asmlinkage void bad_mode(struct pt_regs *regs, int reason)
L
Linus Torvalds 已提交
369 370 371
{
	console_verbose();

372
	printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);
L
Linus Torvalds 已提交
373 374 375 376 377 378 379 380 381 382 383

	die("Oops - bad mode", regs, 0);
	local_irq_disable();
	panic("bad mode");
}

static int bad_syscall(int n, struct pt_regs *regs)
{
	struct thread_info *thread = current_thread_info();
	siginfo_t info;

384 385 386
	if (current->personality != PER_LINUX &&
	    current->personality != PER_LINUX_32BIT &&
	    thread->exec_domain->handler) {
L
Linus Torvalds 已提交
387 388 389 390 391 392 393
		thread->exec_domain->handler(n, regs);
		return regs->ARM_r0;
	}

#ifdef CONFIG_DEBUG_USER
	if (user_debug & UDBG_SYSCALL) {
		printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",
394
			task_pid_nr(current), current->comm, n);
L
Linus Torvalds 已提交
395 396 397 398 399 400 401 402 403 404
		dump_instr(regs);
	}
#endif

	info.si_signo = SIGILL;
	info.si_errno = 0;
	info.si_code  = ILL_ILLTRP;
	info.si_addr  = (void __user *)instruction_pointer(regs) -
			 (thumb_mode(regs) ? 2 : 4);

405
	arm_notify_die("Oops - bad syscall", regs, &info, n, 0);
L
Linus Torvalds 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438

	return regs->ARM_r0;
}

static inline void
do_cache_op(unsigned long start, unsigned long end, int flags)
{
	struct vm_area_struct *vma;

	if (end < start || flags)
		return;

	vma = find_vma(current->active_mm, start);
	if (vma && vma->vm_start < end) {
		if (start < vma->vm_start)
			start = vma->vm_start;
		if (end > vma->vm_end)
			end = vma->vm_end;

		flush_cache_user_range(vma, start, end);
	}
}

/*
 * Handle all unrecognised system calls.
 *  0x9f0000 - 0x9fffff are some more esoteric system calls
 */
#define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
asmlinkage int arm_syscall(int no, struct pt_regs *regs)
{
	struct thread_info *thread = current_thread_info();
	siginfo_t info;

439
	if ((no >> 16) != (__ARM_NR_BASE>> 16))
L
Linus Torvalds 已提交
440 441 442 443 444 445 446 447 448
		return bad_syscall(no, regs);

	switch (no & 0xffff) {
	case 0: /* branch through 0 */
		info.si_signo = SIGSEGV;
		info.si_errno = 0;
		info.si_code  = SEGV_MAPERR;
		info.si_addr  = NULL;

449
		arm_notify_die("branch through zero", regs, &info, 0, 0);
L
Linus Torvalds 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
		return 0;

	case NR(breakpoint): /* SWI BREAK_POINT */
		regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
		ptrace_break(current, regs);
		return regs->ARM_r0;

	/*
	 * Flush a region from virtual address 'r0' to virtual address 'r1'
	 * _exclusive_.  There is no alignment requirement on either address;
	 * user space does not need to know the hardware cache layout.
	 *
	 * r2 contains flags.  It should ALWAYS be passed as ZERO until it
	 * is defined to be something else.  For now we ignore it, but may
	 * the fires of hell burn in your belly if you break this rule. ;)
	 *
	 * (at a later date, we may want to allow this call to not flush
	 * various aspects of the cache.  Passing '0' will guarantee that
	 * everything necessary gets flushed to maintain consistency in
	 * the specified region).
	 */
	case NR(cacheflush):
		do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);
		return 0;

	case NR(usr26):
		if (!(elf_hwcap & HWCAP_26BIT))
			break;
		regs->ARM_cpsr &= ~MODE32_BIT;
		return regs->ARM_r0;

	case NR(usr32):
		if (!(elf_hwcap & HWCAP_26BIT))
			break;
		regs->ARM_cpsr |= MODE32_BIT;
		return regs->ARM_r0;

	case NR(set_tls):
		thread->tp_value = regs->ARM_r0;
489
#if defined(CONFIG_HAS_TLS_REG)
490
		asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
491
#elif !defined(CONFIG_TLS_REG_EMUL)
L
Linus Torvalds 已提交
492
		/*
493 494 495 496
		 * User space must never try to access this directly.
		 * Expect your app to break eventually if you do so.
		 * The user helper at 0xffff0fe0 must be used instead.
		 * (see entry-armv.S for details)
L
Linus Torvalds 已提交
497
		 */
498 499
		*((unsigned int *)0xffff0ff0) = regs->ARM_r0;
#endif
L
Linus Torvalds 已提交
500 501
		return 0;

502 503 504 505 506 507 508 509 510 511 512 513 514
#ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
	/*
	 * Atomically store r1 in *r2 if *r2 is equal to r0 for user space.
	 * Return zero in r0 if *MEM was changed or non-zero if no exchange
	 * happened.  Also set the user C flag accordingly.
	 * If access permissions have to be fixed up then non-zero is
	 * returned and the operation has to be re-attempted.
	 *
	 * *NOTE*: This is a ghost syscall private to the kernel.  Only the
	 * __kuser_cmpxchg code in entry-armv.S should be aware of its
	 * existence.  Don't ever use this from user code.
	 */
	case 0xfff0:
515
	for (;;) {
516 517 518 519 520 521
		extern void do_DataAbort(unsigned long addr, unsigned int fsr,
					 struct pt_regs *regs);
		unsigned long val;
		unsigned long addr = regs->ARM_r2;
		struct mm_struct *mm = current->mm;
		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
522
		spinlock_t *ptl;
523 524

		regs->ARM_cpsr &= ~PSR_C_BIT;
525
		down_read(&mm->mmap_sem);
526 527 528 529 530 531
		pgd = pgd_offset(mm, addr);
		if (!pgd_present(*pgd))
			goto bad_access;
		pmd = pmd_offset(pgd, addr);
		if (!pmd_present(*pmd))
			goto bad_access;
532
		pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
533
		if (!pte_present(*pte) || !pte_dirty(*pte)) {
534
			pte_unmap_unlock(pte, ptl);
535
			goto bad_access;
536
		}
537 538 539 540 541 542
		val = *(unsigned long *)addr;
		val -= regs->ARM_r0;
		if (val == 0) {
			*(unsigned long *)addr = regs->ARM_r1;
			regs->ARM_cpsr |= PSR_C_BIT;
		}
543 544
		pte_unmap_unlock(pte, ptl);
		up_read(&mm->mmap_sem);
545 546 547
		return val;

		bad_access:
548
		up_read(&mm->mmap_sem);
N
Nicolas Pitre 已提交
549
		/* simulate a write access fault */
550 551 552 553
		do_DataAbort(addr, 15 + (1 << 11), regs);
	}
#endif

L
Linus Torvalds 已提交
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
	default:
		/* Calls 9f00xx..9f07ff are defined to return -ENOSYS
		   if not implemented, rather than raising SIGILL.  This
		   way the calling program can gracefully determine whether
		   a feature is supported.  */
		if (no <= 0x7ff)
			return -ENOSYS;
		break;
	}
#ifdef CONFIG_DEBUG_USER
	/*
	 * experience shows that these seem to indicate that
	 * something catastrophic has happened
	 */
	if (user_debug & UDBG_SYSCALL) {
		printk("[%d] %s: arm syscall %d\n",
570
		       task_pid_nr(current), current->comm, no);
L
Linus Torvalds 已提交
571 572
		dump_instr(regs);
		if (user_mode(regs)) {
R
Russell King 已提交
573
			__show_regs(regs);
L
Linus Torvalds 已提交
574 575 576 577 578 579 580 581 582 583
			c_backtrace(regs->ARM_fp, processor_mode(regs));
		}
	}
#endif
	info.si_signo = SIGILL;
	info.si_errno = 0;
	info.si_code  = ILL_ILLTRP;
	info.si_addr  = (void __user *)instruction_pointer(regs) -
			 (thumb_mode(regs) ? 2 : 4);

584
	arm_notify_die("Oops - bad syscall(2)", regs, &info, no, 0);
L
Linus Torvalds 已提交
585 586 587
	return 0;
}

588
#ifdef CONFIG_TLS_REG_EMUL
589 590 591

/*
 * We might be running on an ARMv6+ processor which should have the TLS
592 593 594 595
 * register but for some reason we can't use it, or maybe an SMP system
 * using a pre-ARMv6 processor (there are apparently a few prototypes like
 * that in existence) and therefore access to that register must be
 * emulated.
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
 */

static int get_tp_trap(struct pt_regs *regs, unsigned int instr)
{
	int reg = (instr >> 12) & 15;
	if (reg == 15)
		return 1;
	regs->uregs[reg] = current_thread_info()->tp_value;
	regs->ARM_pc += 4;
	return 0;
}

static struct undef_hook arm_mrc_hook = {
	.instr_mask	= 0x0fff0fff,
	.instr_val	= 0x0e1d0f70,
	.cpsr_mask	= PSR_T_BIT,
	.cpsr_val	= 0,
	.fn		= get_tp_trap,
};

static int __init arm_mrc_hook_init(void)
{
	register_undef_hook(&arm_mrc_hook);
	return 0;
}

late_initcall(arm_mrc_hook_init);

#endif

L
Linus Torvalds 已提交
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
void __bad_xchg(volatile void *ptr, int size)
{
	printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
		__builtin_return_address(0), ptr, size);
	BUG();
}
EXPORT_SYMBOL(__bad_xchg);

/*
 * A data abort trap was taken, but we did not handle the instruction.
 * Try to abort the user program, or panic if it was the kernel.
 */
asmlinkage void
baddataabort(int code, unsigned long instr, struct pt_regs *regs)
{
	unsigned long addr = instruction_pointer(regs);
	siginfo_t info;

#ifdef CONFIG_DEBUG_USER
	if (user_debug & UDBG_BADABORT) {
		printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",
647
			task_pid_nr(current), current->comm, code, instr);
L
Linus Torvalds 已提交
648 649 650 651 652 653 654 655 656 657
		dump_instr(regs);
		show_pte(current->mm, addr);
	}
#endif

	info.si_signo = SIGILL;
	info.si_errno = 0;
	info.si_code  = ILL_ILLOPC;
	info.si_addr  = (void __user *)addr;

658
	arm_notify_die("unknown data abort code", regs, &info, instr, 0);
L
Linus Torvalds 已提交
659 660
}

661
void __attribute__((noreturn)) __bug(const char *file, int line)
L
Linus Torvalds 已提交
662
{
663
	printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line);
L
Linus Torvalds 已提交
664
	*(int *)0 = 0;
665 666 667

	/* Avoid "noreturn function does return" */
	for (;;);
L
Linus Torvalds 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
}
EXPORT_SYMBOL(__bug);

void __readwrite_bug(const char *fn)
{
	printk("%s called, but not implemented\n", fn);
	BUG();
}
EXPORT_SYMBOL(__readwrite_bug);

void __pte_error(const char *file, int line, unsigned long val)
{
	printk("%s:%d: bad pte %08lx.\n", file, line, val);
}

void __pmd_error(const char *file, int line, unsigned long val)
{
	printk("%s:%d: bad pmd %08lx.\n", file, line, val);
}

void __pgd_error(const char *file, int line, unsigned long val)
{
	printk("%s:%d: bad pgd %08lx.\n", file, line, val);
}

asmlinkage void __div0(void)
{
	printk("Division by zero in kernel.\n");
	dump_stack();
}
EXPORT_SYMBOL(__div0);

void abort(void)
{
	BUG();

	/* if that doesn't kill us, halt */
	panic("Oops failed to kill thread");
}
EXPORT_SYMBOL(abort);

void __init trap_init(void)
{
711
	unsigned long vectors = CONFIG_VECTORS_BASE;
712 713
	extern char __stubs_start[], __stubs_end[];
	extern char __vectors_start[], __vectors_end[];
714 715
	extern char __kuser_helper_start[], __kuser_helper_end[];
	int kuser_sz = __kuser_helper_end - __kuser_helper_start;
L
Linus Torvalds 已提交
716

717
	/*
718 719 720
	 * Copy the vectors, stubs and kuser helpers (in entry-armv.S)
	 * into the vector page, mapped at 0xffff0000, and ensure these
	 * are visible to the instruction stream.
721
	 */
722 723 724
	memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
	memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
	memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
725 726 727 728 729 730 731 732

	/*
	 * Copy signal return handlers into the vector page, and
	 * set sigreturn to be a pointer to these.
	 */
	memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,
	       sizeof(sigreturn_codes));

733
	flush_icache_range(vectors, vectors + PAGE_SIZE);
L
Linus Torvalds 已提交
734 735
	modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
}