Subversion Repositories HelenOS

Rev

Rev 106 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 106 Rev 109
Line 62... Line 62...
62
        /*
62
        /*
63
         * Identity mapping for all but 0th page.
63
         * Identity mapping for all but 0th page.
64
         * PA2KA(identity) mapping for all but 0th page.
64
         * PA2KA(identity) mapping for all but 0th page.
65
         */
65
         */
66
        for (i = 1; i < frames; i++) {
66
        for (i = 1; i < frames; i++) {
67
            map_page_to_frame(i * PAGE_SIZE, i * PAGE_SIZE, PAGE_CACHEABLE, 0);
67
            map_page_to_frame(i * PAGE_SIZE, i * PAGE_SIZE, PAGE_CACHEABLE, dba);
68
            map_page_to_frame(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE, 0);         
68
            map_page_to_frame(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE, dba);
69
        }
69
        }
70
 
70
 
71
        trap_register(14, page_fault);
71
        trap_register(14, page_fault);
72
        cpu_write_dba(KA2PA(dba));
72
        cpu_write_dba(KA2PA(dba));
73
    }
73
    }
Line 92... Line 92...
92
 * Besides mapping pages to frames, this function also sets the present bit of
92
 * Besides mapping pages to frames, this function also sets the present bit of
93
 * the page's specifier in both page directory and respective page table. If
93
 * the page's specifier in both page directory and respective page table. If
94
 * the page table for this page has not been allocated so far, it will take
94
 * the page table for this page has not been allocated so far, it will take
95
 * care of it and allocate the necessary frame.
95
 * care of it and allocate the necessary frame.
96
 *
96
 *
97
 * When the copy parameter is positive, map_page_to_frame will not overwrite
-
 
98
 * the current mapping. It will allocate a new frame and do the mapping on it
-
 
99
 * instead.
-
 
100
 *
-
 
101
 * PAGE_CACHEABLE flag: when set, it turns caches for that page on
97
 * PAGE_CACHEABLE flag: when set, it turns caches for that page on
102
 * PAGE_NOT_PRESENT flag: when set, it marks the page not present
98
 * PAGE_NOT_PRESENT flag: when set, it marks the page not present
103
 * PAGE_USER flag: when set, the page is accessible from userspace
99
 * PAGE_USER flag: when set, the page is accessible from userspace
-
 
100
 *
-
 
101
 * When the root parameter is non-zero, it is used as the page directory address.
-
 
102
 * Otherwise, the page directory address is read from CPU.
104
 */
103
 */
105
void map_page_to_frame(__address page, __address frame, int flags, int copy)
104
void map_page_to_frame(__address page, __address frame, int flags, __address root)
106
{
105
{
107
    struct page_specifier *pd, *pt;
106
    struct page_specifier *pd, *pt;
108
    __address dba, newpt;
107
    __address dba, newpt;
109
    int pde, pte;
108
    int pde, pte;
110
 
109
 
111
//  TODO: map_page_to_frame should take dba as a parameter
110
    if (root) dba = root;
112
//  dba = cpu_read_dba();
111
    else dba = cpu_read_dba();
113
    dba = bootstrap_dba;
-
 
114
 
112
 
115
    pde = page >> 22;       /* page directory entry */
113
    pde = page >> 22;       /* page directory entry */
116
    pte = (page >> 12) & 0x3ff; /* page table entry */
114
    pte = (page >> 12) & 0x3ff; /* page table entry */
117
   
115
   
118
    pd = (struct page_specifier *) dba;
116
    pd = (struct page_specifier *) dba;
Line 126... Line 124...
126
        pd[pde].frame_address = KA2PA(newpt) >> 12;
124
        pd[pde].frame_address = KA2PA(newpt) >> 12;
127
        memsetb(newpt, PAGE_SIZE, 0);
125
        memsetb(newpt, PAGE_SIZE, 0);
128
        pd[pde].present = 1;
126
        pd[pde].present = 1;
129
        pd[pde].uaccessible = 1;
127
        pd[pde].uaccessible = 1;
130
    }
128
    }
131
    if (copy) {
-
 
132
        newpt = frame_alloc(FRAME_KA);
-
 
133
        memcopy(pd[pde].frame_address << 12, newpt, PAGE_SIZE);
-
 
134
        pd[pde].frame_address = KA2PA(newpt) >> 12;
-
 
135
    }
-
 
136
   
129
   
137
    pt = (struct page_specifier *) (pd[pde].frame_address << 12);
130
    pt = (struct page_specifier *) (pd[pde].frame_address << 12);
138
 
131
 
139
    pt[pte].frame_address = frame >> 12;
132
    pt[pte].frame_address = frame >> 12;
140
    pt[pte].present = !(flags & PAGE_NOT_PRESENT);
133
    pt[pte].present = !(flags & PAGE_NOT_PRESENT);