Subversion Repositories HelenOS

Rev

Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2307
Line 59... Line 59...
59
   
59
   
60
        /*
60
        /*
61
         * PA2KA(identity) mapping for all frames until last_frame.
61
         * PA2KA(identity) mapping for all frames until last_frame.
62
         */
62
         */
63
        for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
63
        for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
64
            flags = PAGE_CACHEABLE;
64
            flags = PAGE_CACHEABLE | PAGE_WRITE;
65
            if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
65
            if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
66
                flags |= PAGE_GLOBAL;
66
                flags |= PAGE_GLOBAL;
67
            page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
67
            page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
68
        }
68
        }
69
 
69
 
70
        exc_register(14, "page_fault", (iroutine) page_fault);
70
        exc_register(14, "page_fault", (iroutine) page_fault);
71
        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
71
        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
72
    }
-
 
73
    else {
72
    } else
74
        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
73
        write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
75
    }
-
 
76
 
74
 
77
    paging_on();
75
    paging_on();
78
}
76
}
79
 
77
 
80
 
78
 
Line 84... Line 82...
84
        panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
82
        panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
85
   
83
   
86
    uintptr_t virtaddr = PA2KA(last_frame);
84
    uintptr_t virtaddr = PA2KA(last_frame);
87
    pfn_t i;
85
    pfn_t i;
88
    for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
86
    for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
89
        page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE);
87
        page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE | PAGE_WRITE);
90
   
88
   
91
    last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
89
    last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
92
   
90
   
93
    return virtaddr;
91
    return virtaddr;
94
}
92
}
95
 
93
 
96
void page_fault(int n, istate_t *istate)
94
void page_fault(int n, istate_t *istate)
97
{
95
{
98
        uintptr_t page;
96
    uintptr_t page;
99
    pf_access_t access;
97
    pf_access_t access;
100
   
98
   
101
        page = read_cr2();
99
    page = read_cr2();
102
       
100
       
103
        if (istate->error_word & PFERR_CODE_RSVD)
101
    if (istate->error_word & PFERR_CODE_RSVD)
104
        panic("Reserved bit set in page directory.\n");
102
        panic("Reserved bit set in page directory.\n");
105
 
103
 
106
    if (istate->error_word & PFERR_CODE_RW)
104
    if (istate->error_word & PFERR_CODE_RW)
107
        access = PF_ACCESS_WRITE;
105
        access = PF_ACCESS_WRITE;
108
    else
106
    else
109
        access = PF_ACCESS_READ;
107
        access = PF_ACCESS_READ;
110
 
108
   
111
        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
109
    if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
112
        fault_if_from_uspace(istate, "Page fault: %#x", page);
110
        fault_if_from_uspace(istate, "Page fault: %#x", page);
113
 
111
       
114
                decode_istate(istate);
112
        decode_istate(istate);
115
                printf("page fault address: %#x\n", page);
113
        printf("page fault address: %#x\n", page);
116
                panic("page fault\n");
114
        panic("page fault\n");
117
        }
115
    }
118
}
116
}
119
 
117
 
120
/** @}
118
/** @}
121
 */
119
 */