xref: /OK3568_Linux_fs/kernel/arch/h8300/mm/fault.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  linux/arch/h8300/mm/fault.c
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>,
6*4882a593Smuzhiyun  *  Copyright (C) 2000  Lineo, Inc.  (www.lineo.com)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *  Based on:
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *  linux/arch/m68knommu/mm/fault.c
11*4882a593Smuzhiyun  *  linux/arch/m68k/mm/fault.c
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  *  Copyright (C) 1995  Hamish Macdonald
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <linux/mman.h>
17*4882a593Smuzhiyun #include <linux/mm.h>
18*4882a593Smuzhiyun #include <linux/kernel.h>
19*4882a593Smuzhiyun #include <linux/ptrace.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun void die(const char *str, struct pt_regs *fp, unsigned long err);
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * This routine handles page faults.  It determines the problem, and
26*4882a593Smuzhiyun  * then passes it off to one of the appropriate routines.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * error_code:
29*4882a593Smuzhiyun  *	bit 0 == 0 means no page found, 1 means protection fault
30*4882a593Smuzhiyun  *	bit 1 == 0 means read, 1 means write
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * If this routine detects a bad access, it returns 1, otherwise it
33*4882a593Smuzhiyun  * returns 0.
34*4882a593Smuzhiyun  */
do_page_fault(struct pt_regs * regs,unsigned long address,unsigned long error_code)35*4882a593Smuzhiyun asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
36*4882a593Smuzhiyun 			      unsigned long error_code)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun #ifdef DEBUG
39*4882a593Smuzhiyun 	pr_debug("regs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld\n",
40*4882a593Smuzhiyun 		 regs->sr, regs->pc, address, error_code);
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun  * Oops. The kernel tried to access some bad page. We'll have to
45*4882a593Smuzhiyun  * terminate things with extreme prejudice.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun 	if ((unsigned long) address < PAGE_SIZE)
48*4882a593Smuzhiyun 		pr_alert("Unable to handle kernel NULL pointer dereference");
49*4882a593Smuzhiyun 	else
50*4882a593Smuzhiyun 		pr_alert("Unable to handle kernel access");
51*4882a593Smuzhiyun 	printk(" at virtual address %08lx\n", address);
52*4882a593Smuzhiyun 	if (!user_mode(regs))
53*4882a593Smuzhiyun 		die("Oops", regs, error_code);
54*4882a593Smuzhiyun 	do_exit(SIGKILL);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	return 1;
57*4882a593Smuzhiyun }
58