OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [i386/] [mm/] [fault.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/*
2
 *  linux/arch/i386/mm/fault.c
3
 *
4
 *  Copyright (C) 1995  Linus Torvalds
5
 */
6
 
7
#include <linux/signal.h>
8
#include <linux/sched.h>
9
#include <linux/head.h>
10
#include <linux/kernel.h>
11
#include <linux/errno.h>
12
#include <linux/string.h>
13
#include <linux/types.h>
14
#include <linux/ptrace.h>
15
#include <linux/mman.h>
16
#include <linux/mm.h>
17
 
18
#include <asm/system.h>
19
#include <asm/segment.h>
20
#include <asm/pgtable.h>
21
 
22
extern void die_if_kernel(const char *,struct pt_regs *,long);
23
 
24
asmlinkage void do_invalid_op (struct pt_regs *, unsigned long);
25
 
26
extern int pentium_f00f_bug;
27
 
28
/*
29
 * This routine handles page faults.  It determines the address,
30
 * and the problem, and then passes it off to one of the appropriate
31
 * routines.
32
 *
33
 * error_code:
34
 *      bit 0 == 0 means no page found, 1 means protection fault
35
 *      bit 1 == 0 means read, 1 means write
36
 *      bit 2 == 0 means kernel, 1 means user-mode
37
 */
38
asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code)
39
{
40
        void (*handler)(struct task_struct *,
41
                        struct vm_area_struct *,
42
                        unsigned long,
43
                        int);
44
        struct task_struct *tsk = current;
45
        struct mm_struct *mm = tsk->mm;
46
        struct vm_area_struct * vma;
47
        unsigned long address;
48
        unsigned long page;
49
        int write;
50
 
51
        /* get the address */
52
        __asm__("movl %%cr2,%0":"=r" (address));
53
        down(&mm->mmap_sem);
54
        vma = find_vma(mm, address);
55
        if (!vma)
56
                goto bad_area;
57
        if (vma->vm_start <= address)
58
                goto good_area;
59
        if (!(vma->vm_flags & VM_GROWSDOWN))
60
                goto bad_area;
61
        if (error_code & 4) {
62
                /*
63
                 * accessing the stack below %esp is always a bug.
64
                 * The "+ 32" is there due to some instructions (like
65
                 * pusha) doing pre-decrement on the stack and that
66
                 * doesn't show up until later..
67
                 */
68
                if (address + 32 < regs->esp)
69
                        goto bad_area;
70
        }
71
        if (expand_stack(vma, address))
72
                goto bad_area;
73
/*
74
 * Ok, we have a good vm_area for this memory access, so
75
 * we can handle it..
76
 */
77
good_area:
78
        write = 0;
79
        handler = do_no_page;
80
        switch (error_code & 3) {
81
                default:        /* 3: write, present */
82
                        handler = do_wp_page;
83
#ifdef TEST_VERIFY_AREA
84
                        if (regs->cs == KERNEL_CS)
85
                                printk("WP fault at %08lx\n", regs->eip);
86
#endif
87
                        /* fall through */
88
                case 2:         /* write, not present */
89
                        if (!(vma->vm_flags & VM_WRITE))
90
                                goto bad_area;
91
                        write++;
92
                        break;
93
                case 1:         /* read, present */
94
                        goto bad_area;
95
                case 0:          /* read, not present */
96
                        if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
97
                                goto bad_area;
98
        }
99
        handler(tsk, vma, address, write);
100
        up(&mm->mmap_sem);
101
        /*
102
         * Did it hit the DOS screen memory VA from vm86 mode?
103
         */
104
        if (regs->eflags & VM_MASK) {
105
                unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
106
                if (bit < 32)
107
                        tsk->tss.screen_bitmap |= 1 << bit;
108
        }
109
        return;
110
 
111
/*
112
 * Something tried to access memory that isn't in our memory map..
113
 * Fix it, but check if it's kernel or user first..
114
 */
115
bad_area:
116
        up(&mm->mmap_sem);
117
        if (error_code & 4) {
118
                tsk->tss.cr2 = address;
119
                tsk->tss.error_code = error_code;
120
                tsk->tss.trap_no = 14;
121
                force_sig(SIGSEGV, tsk);
122
                return;
123
        }
124
 
125
        /*
126
         * Pentium F0 0F C7 C8 bug workaround:
127
         */
128
        if ( pentium_f00f_bug ) {
129
                unsigned long nr;
130
                extern struct {
131
                        unsigned short limit;
132
                        unsigned long addr __attribute__((packed));
133
                } idt_descriptor;
134
 
135
                nr = (address - idt_descriptor.addr) >> 3;
136
 
137
                if (nr == 6) {
138
                        do_invalid_op(regs, 0);
139
                        return;
140
                }
141
        }
142
 
143
 
144
/*
145
 * Oops. The kernel tried to access some bad page. We'll have to
146
 * terminate things with extreme prejudice.
147
 *
148
 * First we check if it was the bootup rw-test, though..
149
 */
150
        if (wp_works_ok < 0 && address == TASK_SIZE && (error_code & 1)) {
151
                wp_works_ok = 1;
152
                pg0[0] = pte_val(mk_pte(0, PAGE_SHARED));
153
                flush_tlb();
154
                printk("This processor honours the WP bit even when in supervisor mode. Good.\n");
155
                return;
156
        }
157
        if ((unsigned long) (address-TASK_SIZE) < PAGE_SIZE)
158
                printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
159
        else
160
                printk(KERN_ALERT "Unable to handle kernel paging request");
161
        printk(" at virtual address %08lx\n",address);
162
        __asm__("movl %%cr3,%0" : "=r" (page));
163
        printk(KERN_ALERT "current->tss.cr3 = %08lx, %%cr3 = %08lx\n",
164
                tsk->tss.cr3, page);
165
        page = ((unsigned long *) page)[address >> 22];
166
        printk(KERN_ALERT "*pde = %08lx\n", page);
167
        if (page & 1) {
168
                page &= PAGE_MASK;
169
                address &= 0x003ff000;
170
                page = ((unsigned long *) page)[address >> PAGE_SHIFT];
171
                printk(KERN_ALERT "*pte = %08lx\n", page);
172
        }
173
        die_if_kernel("Oops", regs, error_code);
174
        do_exit(SIGKILL);
175
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.