Rev 2241 | Rev 2257 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2241 | Rev 2254 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include "mm.h" |
35 | #include "mm.h" |
36 | 36 | ||
- | 37 | ||
37 | /** Initializes section page table entry. |
38 | /** Initializes section page table entry. |
38 | * |
39 | * |
39 | * Will be readable/writable by kernel with no access from user mode. |
40 | * Will be readable/writable by kernel with no access from user mode. |
40 | * Will belong to domain 0. No cache or buffering is enabled. |
41 | * Will belong to domain 0. No cache or buffering is enabled. |
41 | * |
42 | * |
42 | * \param pte page table entry to set |
43 | * \param pte page table entry to set |
43 | * \param frame first frame in the section (frame number) |
44 | * \param frame first frame in the section (frame number) |
44 | * \note If frame is not 1MB aligned, first lower 1MB aligned frame will be used. |
45 | * \note If frame is not 1MB aligned, first lower 1MB aligned frame will be used. |
45 | */ |
46 | */ |
46 | static void init_pte_level0_section(pte_level0_section* pte, unsigned frame){ |
47 | static void init_pte_level0_section(pte_level0_section* pte, unsigned frame) |
- | 48 | { |
|
47 | pte->descriptor_type = PTE_DESCRIPTOR_SECTION; |
49 | pte->descriptor_type = PTE_DESCRIPTOR_SECTION; |
48 | pte->bufferable = 0; // disable |
50 | pte->bufferable = 0; |
49 | pte->cacheable = 0; |
51 | pte->cacheable = 0; |
50 | pte->impl_specific = 0; |
52 | pte->impl_specific = 0; |
51 | pte->domain = 0; |
53 | pte->domain = 0; |
52 | pte->should_be_zero_1 = 0; |
54 | pte->should_be_zero_1 = 0; |
53 | pte->access_permission = PTE_AP_USER_NO_KERNEL_RW; |
55 | pte->access_permission = PTE_AP_USER_NO_KERNEL_RW; |
54 | pte->should_be_zero_2 = 0; |
56 | pte->should_be_zero_2 = 0; |
55 | pte->section_base_addr = (frame << FRAME_WIDTH) >> 20; |
57 | pte->section_base_addr = (frame << FRAME_WIDTH) >> 20; |
56 | }; |
58 | } |
57 | 59 | ||
58 | 60 | ||
59 | void mm_kernel_mapping(void) { |
61 | static void init_page_table(void) |
- | 62 | { |
|
60 | int i; |
63 | int i; |
61 | 64 | ||
62 | const unsigned int first_kernel_section = ADDR2PFN(PA2KA(0)) / FRAMES_PER_SECTION; |
65 | const unsigned int first_kernel_section = ADDR2PFN(PA2KA(0)) / FRAMES_PER_SECTION; |
63 | // create 1:1 mapping (in lower 2GB) |
66 | // create 1:1 mapping virtual-physical (in lower 2GB) |
64 | for(i = 0; i < first_kernel_section; i++) { |
67 | for(i = 0; i < first_kernel_section; i++) { |
65 | init_pte_level0_section(&page_table[i], i * FRAMES_PER_SECTION); |
68 | init_pte_level0_section(&page_table[i], i * FRAMES_PER_SECTION); |
66 | } |
69 | } |
67 | 70 | ||
68 | // create kernel mapping (in upper 2GB), physical addresses starting from 0 |
71 | // create kernel mapping (in upper 2GB), physical addresses starting from 0 |
69 | for(i = first_kernel_section; i < PTL0_ENTRIES_ARCH; i++) { |
72 | for(i = first_kernel_section; i < PTL0_ENTRIES_ARCH; i++) { |
70 | init_pte_level0_section(&page_table[i], (i - first_kernel_section) * FRAMES_PER_SECTION); |
73 | init_pte_level0_section(&page_table[i], (i - first_kernel_section) * FRAMES_PER_SECTION); |
71 | } |
74 | } |
72 | 75 | } |
|
- | 76 | ||
- | 77 | ||
- | 78 | void mmu_start() { |
|
- | 79 | init_page_table(); |
|
73 | set_ptl0_address(page_table); |
80 | set_ptl0_address(page_table); |
74 | - | ||
75 | // enable paging |
81 | enable_paging(); |
76 | asm volatile ( |
- | |
77 | "ldr r0, =0x55555555 \n" |
- | |
78 | "mcr p15, 0, r0, c3, c0, 0 \n" // TODO: comment: set domain access rights to client <==> take rights from page tables |
- | |
79 | "mrc p15, 0, r0, c1, c0, 0 \n" // get current settings of system |
- | |
80 | "ldr r1, =0xFFFFFE8D \n" // mask to disable aligment checks; system & rom bit disabled |
- | |
81 | "and r0, r0, r1 \n" |
- | |
82 | "ldr r1, =0x00000001 \n" // mask to enable paging |
- | |
83 | "orr r0, r0, r1 \n" |
- | |
84 | "mcr p15, 0, r0, c1, c0, 0 \n" // store settings |
- | |
85 | : |
- | |
86 | : |
- | |
87 | : "r0", "r1" |
- | |
88 | ); |
- | |
89 | }; |
82 | } |
90 | 83 | ||
91 | /** @} |
84 | /** @} |
92 | */ |
85 | */ |
93 | 86 |