Rev 3386 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | 51 | ||
52 | void page_arch_init(void) |
52 | void page_arch_init(void) |
53 | { |
53 | { |
54 | uintptr_t cur; |
54 | uintptr_t cur; |
55 | int flags; |
55 | int flags; |
56 | 56 | ||
57 | if (config.cpu_active == 1) { |
57 | if (config.cpu_active == 1) { |
58 | page_mapping_operations = &pt_mapping_operations; |
58 | page_mapping_operations = &pt_mapping_operations; |
59 | 59 | ||
60 | /* |
60 | /* |
61 | * PA2KA(identity) mapping for all frames until last_frame. |
61 | * PA2KA(identity) mapping for all frames until last_frame. |
Line 64... | Line 64... | ||
64 | flags = PAGE_CACHEABLE | PAGE_WRITE; |
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 | } else |
72 | } else |
73 | write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); |
73 | write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); |
74 | 74 | ||
75 | paging_on(); |
75 | paging_on(); |
76 | } |
76 | } |
77 | 77 | ||
78 | 78 | ||
79 | uintptr_t hw_map(uintptr_t physaddr, size_t size) |
79 | uintptr_t hw_map(uintptr_t physaddr, size_t size) |
80 | { |
80 | { |
81 | if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH)) |
81 | if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH)) |
82 | panic("Unable to map physical memory %p (%d bytes)", physaddr, size) |
82 | panic("Unable to map physical memory %p (%d bytes).", physaddr, size) |
83 | 83 | ||
84 | uintptr_t virtaddr = PA2KA(last_frame); |
84 | uintptr_t virtaddr = PA2KA(last_frame); |
85 | pfn_t i; |
85 | pfn_t i; |
86 | for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++) { |
86 | for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++) { |
87 | uintptr_t addr = PFN2ADDR(i); |
87 | uintptr_t addr = PFN2ADDR(i); |
Line 99... | Line 99... | ||
99 | pf_access_t access; |
99 | pf_access_t access; |
100 | 100 | ||
101 | page = read_cr2(); |
101 | page = read_cr2(); |
102 | 102 | ||
103 | if (istate->error_word & PFERR_CODE_RSVD) |
103 | if (istate->error_word & PFERR_CODE_RSVD) |
104 | panic("Reserved bit set in page directory.\n"); |
104 | panic("Reserved bit set in page directory."); |
105 | 105 | ||
106 | if (istate->error_word & PFERR_CODE_RW) |
106 | if (istate->error_word & PFERR_CODE_RW) |
107 | access = PF_ACCESS_WRITE; |
107 | access = PF_ACCESS_WRITE; |
108 | else |
108 | else |
109 | access = PF_ACCESS_READ; |
109 | access = PF_ACCESS_READ; |
110 | 110 | ||
111 | if (as_page_fault(page, access, istate) == AS_PF_FAULT) { |
111 | if (as_page_fault(page, access, istate) == AS_PF_FAULT) { |
112 | fault_if_from_uspace(istate, "Page fault: %#x", page); |
112 | fault_if_from_uspace(istate, "Page fault: %#x.", page); |
113 | 113 | ||
114 | decode_istate(istate); |
114 | decode_istate(istate); |
115 | printf("page fault address: %#lx\n", page); |
115 | printf("page fault address: %#lx\n", page); |
116 | panic("page fault\n"); |
116 | panic("Page fault."); |
117 | } |
117 | } |
118 | } |
118 | } |
119 | 119 | ||
120 | /** @} |
120 | /** @} |
121 | */ |
121 | */ |