Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | /* * Last edited: Nov 29 18:14 1995 (cort) */ /* * ARCH/ppc/mm/fault.c * * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds * Ported to PPC by Gary Thomas */ /*#define NOISY_DATAFAULT*/ /*#define NOISY_INSTRFAULT*/ #include <linux/config.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/head.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/types.h> #include <linux/ptrace.h> #include <linux/mman.h> #include <linux/mm.h> #include <asm/page.h> #include <asm/pgtable.h> extern void die_if_kernel(char *, struct pt_regs *, long); extern void do_page_fault(struct pt_regs *, unsigned long, unsigned long); #if 0 #define SHOW_FAULTS #endif void DataAccessException(struct pt_regs *regs) { pgd_t *dir; pmd_t *pmd; pte_t *pte; int tries, mode = 0; if (user_mode(regs)) mode |= 0x04; if (regs->dsisr & 0x02000000) mode |= 0x02; /* Load/store */ if (regs->dsisr & 0x08000000) mode |= 0x01; /* Protection violation */ #ifdef NOISY_DATAFAULT printk("Data fault on %x\n",regs->dar); #endif if (mode & 0x01) { #if 0 printk("Write Protect Fault - Loc: %x, DSISR: %x, PC: %x\n", regs->dar, regs->dsisr, regs->nip); #endif #ifdef NOISY_DATAFAULT printk("Write Protect fault\n "); #endif do_page_fault(regs, regs->dar, mode); #ifdef NOISY_DATAFAULT printk("Write Protect fault handled\n"); #endif return; } /* printk("trying\n"); */ for (tries = 0; tries < 1; tries++) { dir = pgd_offset(current->mm, regs->dar & PAGE_MASK); if (dir) { pmd = pmd_offset(dir, regs->dar & PAGE_MASK); if (pmd && pmd_present(*pmd)) { pte = pte_offset(pmd, regs->dar & PAGE_MASK); if (pte && pte_present(*pte)) { #if 0 printk("Page mapped - PTE: %x[%x]\n", pte, *(long *)pte); #endif MMU_hash_page(¤t->tss, regs->dar & PAGE_MASK, pte); return; } } } else { printk("No PGD\n"); } #ifdef NOISY_DATAFAULT printk("fall through page fault addr=%x; ip=%x\n", regs->dar,regs->nip); printk("beforefault: pgd[0] = %x[%x]\n",current->mm->pgd,*(current->mm->pgd)); #endif do_page_fault(regs, regs->dar, mode); #ifdef NOISY_DATAFAULT printk("handled: pgd[0] = %x[%x]\n",current->mm->pgd,*(current->mm->pgd)); #endif } } void InstructionAccessException(struct pt_regs *regs) { pgd_t *dir; pmd_t *pmd; pte_t *pte; int tries, mode = 0; #if NOISY_INSTRFAULT printk("Instr fault on %x\n",regs->dar); #endif if (user_mode(regs)) mode |= 0x04; if (regs->dsisr & 0x02000000) mode |= 0x02; /* Load/store */ if (regs->dsisr & 0x08000000) mode |= 0x01; /* Protection violation */ if (mode & 0x01) { do_page_fault(regs, regs->dar, mode); return; } for (tries = 0; tries < 1; tries++) { /* dir = pgd_offset(current->mm, regs->nip & PAGE_MASK); */ dir = pgd_offset(current->mm, regs->dar & PAGE_MASK); #ifdef NOISY_INSTRFAULT /* printk("regs->dar=%x current=%x current->mm=%x current->mm->pgd=%x current->tss.pg_tables=%x\n", regs->dar,current,current->mm,current->mm->pgd,current->tss.pg_tables);*/ #endif if (dir) { pmd = pmd_offset(dir, regs->dar & PAGE_MASK); if (pmd && pmd_present(*pmd)) { pte = pte_offset(pmd, regs->dar & PAGE_MASK); #ifdef NOISY_INSTRFAULT /* printk("dir %x(%x) pmd %x(%x) pte %x\n",dir,*dir,pmd,*pmd,pte);*/ #if 0 printk("pgd_offset mm=%x mm->pgd=%x dirshouldbe=%x\n", current->mm, current->mm->pgd, current->mm->pgd+((regs->dar&PAGE_MASK) >> PGDIR_SHIFT)); printk("dir is %x\n", dir); /* printk("got pte\n"); */ if (pte) { printk("pgd=%x; dir=%x->%x; pmd=%x->%x; pte=%x; \n", current->mm->pgd,dir,*dir,pmd,*pmd,pte); if (pte_present(*pte)) { printk("pte present\n"); } else { printk("pte not present\n"); } } else { printk("pte false\n"); } #endif #endif if (pte && pte_present(*pte)) { /* MMU_hash_page(¤t->tss, regs->nip & PAGE_MASK, pte); */ MMU_hash_page(¤t->tss, regs->dar & PAGE_MASK, pte); return; } } } else { #ifdef NOISY_INSTRFAULT panic("No PGD Instruction Access Fault - Loc: %x, DSISR: %x, PC: %x current->mm\n", regs->dar, regs->dsisr, regs->nip, current->mm); #endif } /* do_page_fault(regs, regs->nip, mode); */ do_page_fault(regs, regs->dar, mode); } } /* * This routine handles page faults. It determines the address, * and the problem, and then passes it off to one of the appropriate * routines. * * The error_code parameter just the same as in the i386 version: * * bit 0 == 0 means no page found, 1 means protection fault * bit 1 == 0 means read, 1 means write * bit 2 == 0 means kernel, 1 means user-mode */ void do_page_fault(struct pt_regs *regs, unsigned long address, unsigned long error_code) { struct vm_area_struct * vma; unsigned long page; /* printk("In do_page_fault()\n"); */ #if 1 for (vma = current->mm->mmap ; ; vma = vma->vm_next) { if (!vma) { panic("!vma: ip = %x; current=%x[%d]; mm=%x; mmap=%x; address = %x error_code = %x\n", regs->nip, current,current->pid,current->mm,current->mm->mmap, address, error_code); goto bad_area; } if (vma->vm_end > address) break; } #else vma = find_vma(current, address); if (!vma) { } goto bad_area; #endif if (vma->vm_start <= address){ goto good_area; } if (!(vma->vm_flags & VM_GROWSDOWN)) { printk("stack: gpr[1]=%x ip = %x; current=%x[%d]; mm=%x; mmap=%x; address = %x error_code = %x\n",regs->gpr[1],regs->nip, current,current->pid,current->mm,current->mm->mmap, address, error_code); panic("stack\n"); goto bad_area; } if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur) { printk("stack2: vma->vm_end-address %x rlim %x\n", vma->vm_end - address, current->rlim[RLIMIT_STACK].rlim_cur); printk("stack2: vm_end %x address = %x\n", vma->vm_end,address); printk("stack2: gpr[1]=%x ip = %x; current=%x[%d]; mm=%x; mmap=%x; address = %x error_code = %x\n",regs->gpr[1],regs->nip, current,current->pid,current->mm,current->mm->mmap, address, error_code); panic("stack2\n"); goto bad_area; } vma->vm_offset -= vma->vm_start - (address & PAGE_MASK); vma->vm_start = (address & PAGE_MASK); /* * Ok, we have a good vm_area for this memory access, so * we can handle it.. */ good_area: /* * was it a write? */ if (error_code & 2) { if (!(vma->vm_flags & VM_WRITE)) { panic("do_page_fault() write\n"); panic("do_page_fault() write! current: %x, address:%x, vm_flags: %x, mm: %x; vma(%x) %x to %x\n", current,address,vma->vm_flags,current->mm,vma,vma->vm_start,vma->vm_end); goto bad_area; } } else { /* read with protection fault? */ if (error_code & 1) { panic("do_page_fault() error code thing\n"); goto bad_area; } if (!(vma->vm_flags & (VM_READ | VM_EXEC))) { #if 0 _printk("vma = %x\n", vma); _printk("vma->vm_flags = %x\n", vma->vm_flags); _printk("VM_READ = %x VM_EXEC = %x\n",VM_READ,VM_EXEC); #endif #if 0 printk("vma = %x VM_READ = %x VM_EXEC = %x\n", vma, VM_READ,VM_EXEC); printk("vma->vm_start = %x vma->vm_end = %d\n", vma->vm_start, vma->vm_end); printk("error_code = %x\n", error_code); printk("regs = %x\n", regs); printk("vma->vm_flags = %x\n", vma->vm_flags); #endif /* printk("do_page_fault() multi thing\n"); */ goto bad_area; } } /* printk("premm: pgd[0] = %x[%x]\n",current->mm->pgd,*(current->mm->pgd)); */ handle_mm_fault(vma, address, error_code & 2); /* printk("handled fault for %x in %x to %x flags %x\n", */ /* address,vma->vm_start,vma->vm_end,vma->vm_flags); */ return; /* * Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ bad_area: if (user_mode(regs)) { printk("Task: %x, PC: %x, bad area! - Addr: %x\n", current, regs->nip, address); send_sig(SIGSEGV, current, 1); return; } #if 0 panic("KERNEL! Task: %x, PC: %x, bad area! - Addr: %x, PGDIR: %x\n", current, regs->nip, address, current->tss.pg_tables); #else /* panic("KERNEL mm! current: %x, address:%x, vm_flags: %x, mm: %x; \nvma(%x) %x to %x swapper_pg_dir %x\n", current,address,vma->vm_flags,current->mm,vma,vma->vm_start,vma->vm_end, swapper_pg_dir);*/ printk("KERNEL mm! current: %x, address:%x, vm_flags: %x, mm: %x; vma(%x) %x to %x\n", current,address,vma->vm_flags,current->mm,vma,vma->vm_start,vma->vm_end); panic("Kernel access of bad area\n"); #endif while (1) ; } va_to_phys(unsigned long address) { pgd_t *dir; pmd_t *pmd; pte_t *pte; dir = pgd_offset(current->mm, address & PAGE_MASK); if (dir) { pmd = pmd_offset(dir, address & PAGE_MASK); if (pmd && pmd_present(*pmd)) { pte = pte_offset(pmd, address & PAGE_MASK); if (pte && pte_present(*pte)) { return(pte_page(*pte) | (address & ~(PAGE_MASK-1))); } } else { return (0); } } else { return (0); } } |