Subversion Repositories HelenOS-historic

Rev

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

Rev 1735 Rev 1780
Line 60... Line 60...
60
#define PTL1_ADDR(ptl0, page) ((pte_t *)PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page))))
60
#define PTL1_ADDR(ptl0, page) ((pte_t *)PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page))))
61
#define PTL2_ADDR(ptl1, page) ((pte_t *)PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page))))
61
#define PTL2_ADDR(ptl1, page) ((pte_t *)PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page))))
62
#define PTL3_ADDR(ptl2, page) ((pte_t *)PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page))))
62
#define PTL3_ADDR(ptl2, page) ((pte_t *)PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page))))
63
 
63
 
64
#define SETUP_PTL1(ptl0, page, tgt)  {  \
64
#define SETUP_PTL1(ptl0, page, tgt)  {  \
65
    SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (__address)KA2PA(tgt)); \
65
    SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
66
        SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
66
        SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
67
    }
67
    }
68
#define SETUP_PTL2(ptl1, page, tgt)  {  \
68
#define SETUP_PTL2(ptl1, page, tgt)  {  \
69
    SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (__address)KA2PA(tgt)); \
69
    SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
70
        SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
70
        SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
71
    }
71
    }
72
#define SETUP_PTL3(ptl2, page, tgt)  {  \
72
#define SETUP_PTL3(ptl2, page, tgt)  {  \
73
    SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (__address)KA2PA(tgt)); \
73
    SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
74
        SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
74
        SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
75
    }
75
    }
76
#define SETUP_FRAME(ptl3, page, tgt)  { \
76
#define SETUP_FRAME(ptl3, page, tgt)  { \
77
    SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (__address)KA2PA(tgt)); \
77
    SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
78
        SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
78
        SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
79
    }
79
    }
80
 
80
 
81
 
81
 
82
void page_arch_init(void)
82
void page_arch_init(void)
83
{
83
{
84
    __address cur;
84
    uintptr_t cur;
85
    int i;
85
    int i;
86
    int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL;
86
    int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL;
87
 
87
 
88
    if (config.cpu_active == 1) {
88
    if (config.cpu_active == 1) {
89
        page_mapping_operations = &pt_mapping_operations;
89
        page_mapping_operations = &pt_mapping_operations;
Line 107... Line 107...
107
                page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);
107
                page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);
108
            }
108
            }
109
        }
109
        }
110
 
110
 
111
        exc_register(14, "page_fault", (iroutine)page_fault);
111
        exc_register(14, "page_fault", (iroutine)page_fault);
112
        write_cr3((__address) AS_KERNEL->page_table);
112
        write_cr3((uintptr_t) AS_KERNEL->page_table);
113
    }
113
    }
114
    else {
114
    else {
115
        write_cr3((__address) AS_KERNEL->page_table);
115
        write_cr3((uintptr_t) AS_KERNEL->page_table);
116
    }
116
    }
117
}
117
}
118
 
118
 
119
 
119
 
120
/** Identity page mapper
120
/** Identity page mapper
Line 123... Line 123...
123
 * is initializaed. This thing clears page table and fills in the specific
123
 * is initializaed. This thing clears page table and fills in the specific
124
 * items.
124
 * items.
125
 */
125
 */
126
void ident_page_fault(int n, istate_t *istate)
126
void ident_page_fault(int n, istate_t *istate)
127
{
127
{
128
    __address page;
128
    uintptr_t page;
129
    static __address oldpage = 0;
129
    static uintptr_t oldpage = 0;
130
    pte_t *aptl_1, *aptl_2, *aptl_3;
130
    pte_t *aptl_1, *aptl_2, *aptl_3;
131
 
131
 
132
    page = read_cr2();
132
    page = read_cr2();
133
    if (oldpage) {
133
    if (oldpage) {
134
        /* Unmap old address */
134
        /* Unmap old address */
Line 171... Line 171...
171
}
171
}
172
 
172
 
173
 
173
 
174
void page_fault(int n, istate_t *istate)
174
void page_fault(int n, istate_t *istate)
175
{
175
{
176
    __address page;
176
    uintptr_t page;
177
    pf_access_t access;
177
    pf_access_t access;
178
   
178
   
179
    page = read_cr2();
179
    page = read_cr2();
180
   
180
   
181
    if (istate->error_word & PFERR_CODE_RSVD)
181
    if (istate->error_word & PFERR_CODE_RSVD)
Line 196... Line 196...
196
        panic("page fault\n");
196
        panic("page fault\n");
197
    }
197
    }
198
}
198
}
199
 
199
 
200
 
200
 
201
__address hw_map(__address physaddr, size_t size)
201
uintptr_t hw_map(uintptr_t physaddr, size_t size)
202
{
202
{
203
    if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
203
    if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
204
        panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
204
        panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
205
   
205
   
206
    __address virtaddr = PA2KA(last_frame);
206
    uintptr_t virtaddr = PA2KA(last_frame);
207
    pfn_t i;
207
    pfn_t i;
208
    for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
208
    for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
209
        page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE);
209
        page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE);
210
   
210
   
211
    last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
211
    last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);