Rev 1269 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1215 | decky | 1 | /* |
2 | * Copyright (C) 2006 Martin Decky |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include <arch/mm/tlb.h> |
||
30 | #include <arch/types.h> |
||
31 | #include <mm/tlb.h> |
||
32 | #include <mm/page.h> |
||
33 | #include <mm/as.h> |
||
34 | #include <arch.h> |
||
35 | #include <print.h> |
||
36 | #include <symtab.h> |
||
37 | |||
38 | |||
39 | /** Initialize Page Hash Table. |
||
40 | * |
||
41 | * Setup the Page Hash Table with no entries. |
||
42 | * |
||
43 | */ |
||
44 | void tlb_arch_init(void) |
||
45 | { |
||
46 | } |
||
47 | |||
48 | |||
49 | /** Try to find PTE for faulting address |
||
50 | * |
||
51 | * Try to find PTE for faulting address. |
||
52 | * The AS->lock must be held on entry to this function. |
||
53 | * |
||
54 | * @param badvaddr Faulting virtual address. |
||
55 | * @return PTE on success, NULL otherwise. |
||
56 | * |
||
57 | */ |
||
58 | static pte_t *find_mapping_and_check(__address badvaddr) |
||
59 | { |
||
60 | /* |
||
61 | * Check if the mapping exists in page tables. |
||
62 | */ |
||
63 | pte_t *pte = page_mapping_find(AS, badvaddr); |
||
64 | if ((pte) && (pte->p)) { |
||
65 | /* |
||
66 | * Mapping found in page tables. |
||
67 | * Immediately succeed. |
||
68 | */ |
||
69 | return pte; |
||
70 | } else { |
||
71 | /* |
||
72 | * Mapping not found in page tables. |
||
73 | * Resort to higher-level page fault handler. |
||
74 | */ |
||
75 | page_table_unlock(AS, true); |
||
76 | if (as_page_fault(badvaddr)) { |
||
77 | /* |
||
78 | * The higher-level page fault handler succeeded, |
||
79 | * The mapping ought to be in place. |
||
80 | */ |
||
81 | page_table_lock(AS, true); |
||
82 | pte = page_mapping_find(AS, badvaddr); |
||
83 | ASSERT((pte) && (pte->p)); |
||
84 | return pte; |
||
85 | } else { |
||
86 | page_table_lock(AS, true); |
||
87 | printf("Page fault.\n"); |
||
88 | return NULL; |
||
89 | } |
||
90 | |||
91 | } |
||
92 | } |
||
93 | |||
94 | |||
95 | static void pht_refill_fail(__address badvaddr, istate_t *istate) |
||
96 | { |
||
97 | char *symbol = ""; |
||
98 | char *sym2 = ""; |
||
99 | |||
100 | char *s = get_symtab_entry(istate->pc); |
||
101 | if (s) |
||
102 | symbol = s; |
||
103 | s = get_symtab_entry(istate->lr); |
||
104 | if (s) |
||
105 | sym2 = s; |
||
106 | panic("%X: PHT Refill Exception at %X(%s<-%s)\n", badvaddr, istate->pc, symbol, sym2); |
||
107 | } |
||
108 | |||
109 | |||
110 | /** Process Data Storage Interrupt |
||
111 | * |
||
112 | * @param istate Interrupted register context. |
||
113 | * |
||
114 | */ |
||
115 | void pht_refill(istate_t *istate) |
||
116 | { |
||
117 | asid_t asid; |
||
118 | __address badvaddr; |
||
119 | pte_t *pte; |
||
120 | |||
121 | __asm__ volatile ( |
||
122 | "mfdar %0\n" |
||
123 | : "=r" (badvaddr) |
||
124 | ); |
||
125 | |||
126 | spinlock_lock(&AS->lock); |
||
127 | asid = AS->asid; |
||
128 | spinlock_unlock(&AS->lock); |
||
129 | |||
130 | page_table_lock(AS, true); |
||
131 | |||
132 | pte = find_mapping_and_check(badvaddr); |
||
133 | if (!pte) |
||
134 | goto fail; |
||
135 | |||
136 | /* |
||
137 | * Record access to PTE. |
||
138 | */ |
||
139 | pte->a = 1; |
||
140 | |||
141 | // FIXME: Insert entry into PHT |
||
142 | |||
143 | page_table_unlock(AS, true); |
||
144 | return; |
||
145 | |||
146 | fail: |
||
147 | page_table_unlock(AS, true); |
||
148 | pht_refill_fail(badvaddr, istate); |
||
149 | } |
||
150 | |||
151 | |||
152 | /** Print contents of Page Hash Table. */ |
||
153 | void tlb_print(void) |
||
154 | { |
||
155 | } |