Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 119 → Rev 120

/SPARTAN/trunk/arch/ia32/include/mm/page.h
29,8 → 29,10
#ifndef __ia32_PAGE_H__
#define __ia32_PAGE_H__
 
#include <mm/page.h>
#include <arch/types.h>
#include <arch/mm/frame.h>
#include <typedefs.h>
 
#define PAGE_SIZE FRAME_SIZE
 
46,12 → 48,28
#define PTL2_INDEX_ARCH(vaddr) 0
#define PTL3_INDEX_ARCH(vaddr) (((vaddr)>>12)&0x3ff)
 
#define GET_PTL0_ADDRESS_ARCH() ((pte_t *) read_cr3())
#define GET_PTL1_ADDRESS_ARCH(ptl0, i) ((pte_t *)((((pte_t *)(ptl0))[(i)].frame_address)<<12))
#define GET_PTL2_ADDRESS_ARCH(ptl1, i) (ptl1)
#define GET_PTL3_ADDRESS_ARCH(ptl2, i) (ptl2)
#define GET_FRAME_ADDRESS_ARCH(ptl3, i) ((__address)((((pte_t *)(ptl3))[(i)].frame_address)<<12))
 
#define SET_PTL0_ADDRESS_ARCH(ptl0) (write_cr3((__address) (ptl0)))
#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) (((pte_t *)(ptl0))[(i)].frame_address = (a)>>12)
#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) (((pte_t *)(ptl3))[(i)].frame_address = (a)>>12)
 
#define GET_PTL1_FLAGS_ARCH(ptl0, i) get_pt_flags((pte_t *)(ptl0), (index_t)(i))
#define GET_PTL2_FLAGS_ARCH(ptl1, i) PAGE_PRESENT
#define GET_PTL3_FLAGS_ARCH(ptl2, i) PAGE_PRESENT
#define GET_FRAME_FLAGS_ARCH(ptl3, i) get_pt_flags((pte_t *)(ptl3), (index_t)(i))
 
#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) set_pt_flags((pte_t *)(ptl0), (index_t)(i), (x))
#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) set_pt_flags((pte_t *)(ptl3), (index_t)(i), (x))
 
struct page_specifier {
unsigned present : 1;
unsigned writeable : 1;
65,8 → 83,32
unsigned frame_address : 20;
} __attribute__ ((packed));
 
typedef struct page_specifier pte_t;
typedef struct page_specifier pte_t;
 
static inline int get_pt_flags(pte_t *pt, index_t i)
{
pte_t *p = &pt[i];
return (
(!p->page_cache_disable)<<PAGE_CACHEABLE_SHIFT |
(!p->present)<<PAGE_PRESENT_SHIFT |
p->uaccessible<<PAGE_USER_SHIFT |
1<<PAGE_READ_SHIFT |
p->writeable<<PAGE_WRITE_SHIFT |
1<<PAGE_EXEC_SHIFT
);
}
 
static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
{
pte_t *p = &pt[i];
p->page_cache_disable = !(flags & PAGE_CACHEABLE);
p->present = !(flags & PAGE_NOT_PRESENT);
p->uaccessible = flags & PAGE_USER;
p->writeable = flags & PAGE_WRITE;
}
 
extern void page_arch_init(void);
 
#endif
/SPARTAN/trunk/arch/ia32/src/mm/page.c
86,51 → 86,3
 
paging_on();
}
 
/*
* Besides mapping pages to frames, this function also sets the present bit of
* the page's specifier in both page directory and respective page table. If
* the page table for this page has not been allocated so far, it will take
* care of it and allocate the necessary frame.
*
* PAGE_CACHEABLE flag: when set, it turns caches for that page on
* PAGE_NOT_PRESENT flag: when set, it marks the page not present
* PAGE_USER flag: when set, the page is accessible from userspace
*
* When the root parameter is non-zero, it is used as the page directory address.
* Otherwise, the page directory address is read from CPU.
*/
void map_page_to_frame(__address page, __address frame, int flags, __address root)
{
struct page_specifier *pd, *pt;
__address dba, newpt;
int pde, pte;
 
if (root) dba = root;
else dba = read_cr3();
 
pde = page >> 22; /* page directory entry */
pte = (page >> 12) & 0x3ff; /* page table entry */
pd = (struct page_specifier *) PA2KA(dba);
if (!pd[pde].present) {
/*
* There is currently no page table for this address. Allocate
* frame for the page table and clean it.
*/
newpt = frame_alloc(FRAME_KA);
pd[pde].frame_address = KA2PA(newpt) >> 12;
memsetb(newpt, PAGE_SIZE, 0);
pd[pde].present = 1;
pd[pde].uaccessible = 1;
}
pt = (struct page_specifier *) PA2KA((pd[pde].frame_address << 12));
 
pt[pte].frame_address = frame >> 12;
pt[pte].present = !(flags & PAGE_NOT_PRESENT);
pt[pte].page_cache_disable = !(flags & PAGE_CACHEABLE);
pt[pte].uaccessible = (flags & PAGE_USER) != 0;
pt[pte].writeable = (flags & PAGE_WRITE) != 0;
}