HelenOS sources
This source file includes following definitions.
- get_pt_level0_flags
- get_pt_level1_flags
- set_pt_level0_flags
- set_pt_level1_flags
- set_pt_level0_present
- set_pt_level1_present
#ifndef KERN_arm32_PAGE_armv4_H_
#define KERN_arm32_PAGE_armv4_H_
#include <arch/cache.h>
#ifndef KERN_arm32_PAGE_H_
#error "Do not include arch specific page.h directly use generic page.h instead"
#endif
#define PTE_VALID_ARCH(pte) \
(((pte_t *) (pte))->l0.should_be_zero != 0 || PTE_PRESENT_ARCH(pte))
#define PTE_PRESENT_ARCH(pte) \
(((pte_t *) (pte))->l0.descriptor_type != 0)
#define PTE_GET_FRAME_ARCH(pte) \
(((uintptr_t) ((pte_t *) (pte))->l1.frame_base_addr) << FRAME_WIDTH)
#define PTE_WRITABLE_ARCH(pte) \
(((pte_t *) (pte))->l1.access_permission_0 == PTE_AP_USER_RW_KERNEL_RW)
#define PTE_EXECUTABLE_ARCH(pte) \
1
#ifndef __ASSEMBLER__
typedef struct {
unsigned descriptor_type : 2;
unsigned impl_specific : 3;
unsigned domain : 4;
unsigned should_be_zero : 1;
unsigned coarse_table_addr : 22;
} ATTRIBUTE_PACKED pte_level0_t;
typedef struct {
unsigned descriptor_type : 2;
unsigned bufferable : 1;
unsigned cacheable : 1;
unsigned access_permission_0 : 2;
unsigned access_permission_1 : 2;
unsigned access_permission_2 : 2;
unsigned access_permission_3 : 2;
unsigned frame_base_addr : 20;
} ATTRIBUTE_PACKED pte_level1_t;
typedef union {
pte_level0_t l0;
pte_level1_t l1;
} pte_t;
#define PTE_AP_USER_NO_KERNEL_NO 0
#define PTE_AP_USER_NO_KERNEL_RW 1
#define PTE_AP_USER_RO_KERNEL_RW 2
#define PTE_AP_USER_RW_KERNEL_RW 3
#define PTE_DESCRIPTOR_NOT_PRESENT 0
#define PTE_DESCRIPTOR_COARSE_TABLE 1
#define PTE_DESCRIPTOR_SMALL_PAGE 2
#define pt_coherence_m(pt, count) \
do { \
for (unsigned i = 0; i < count; ++i) \
dcache_clean_mva_pou((uintptr_t)(pt + i)); \
read_barrier(); \
} while (0)
_NO_TRACE static inline int get_pt_level0_flags(pte_t *pt, size_t i)
{
pte_level0_t *p = &pt[i].l0;
int np = (p->descriptor_type == PTE_DESCRIPTOR_NOT_PRESENT);
return (np << PAGE_PRESENT_SHIFT) | (1 << PAGE_USER_SHIFT) |
(1 << PAGE_READ_SHIFT) | (1 << PAGE_WRITE_SHIFT) |
(1 << PAGE_EXEC_SHIFT) | (1 << PAGE_CACHEABLE_SHIFT);
}
_NO_TRACE static inline int get_pt_level1_flags(pte_t *pt, size_t i)
{
pte_level1_t *p = &pt[i].l1;
int dt = p->descriptor_type;
int ap = p->access_permission_0;
return ((dt == PTE_DESCRIPTOR_NOT_PRESENT) << PAGE_PRESENT_SHIFT) |
((ap == PTE_AP_USER_RO_KERNEL_RW) << PAGE_READ_SHIFT) |
((ap == PTE_AP_USER_RW_KERNEL_RW) << PAGE_READ_SHIFT) |
((ap == PTE_AP_USER_RW_KERNEL_RW) << PAGE_WRITE_SHIFT) |
((ap != PTE_AP_USER_NO_KERNEL_RW) << PAGE_USER_SHIFT) |
((ap == PTE_AP_USER_NO_KERNEL_RW) << PAGE_READ_SHIFT) |
((ap == PTE_AP_USER_NO_KERNEL_RW) << PAGE_WRITE_SHIFT) |
(1 << PAGE_EXEC_SHIFT) |
(p->bufferable << PAGE_CACHEABLE);
}
_NO_TRACE static inline void set_pt_level0_flags(pte_t *pt, size_t i, int flags)
{
pte_level0_t *p = &pt[i].l0;
if (flags & PAGE_NOT_PRESENT) {
p->descriptor_type = PTE_DESCRIPTOR_NOT_PRESENT;
p->should_be_zero = 1;
} else {
p->descriptor_type = PTE_DESCRIPTOR_COARSE_TABLE;
p->should_be_zero = 0;
}
}
_NO_TRACE static inline void set_pt_level1_flags(pte_t *pt, size_t i, int flags)
{
pte_level1_t *p = &pt[i].l1;
if (flags & PAGE_NOT_PRESENT)
p->descriptor_type = PTE_DESCRIPTOR_NOT_PRESENT;
else
p->descriptor_type = PTE_DESCRIPTOR_SMALL_PAGE;
p->cacheable = p->bufferable = (flags & PAGE_CACHEABLE) != 0;
p->access_permission_0 = p->access_permission_1 =
p->access_permission_2 = p->access_permission_3 =
PTE_AP_USER_NO_KERNEL_RW;
if (flags & PAGE_USER) {
if (flags & PAGE_READ) {
p->access_permission_0 = p->access_permission_1 =
p->access_permission_2 = p->access_permission_3 =
PTE_AP_USER_RO_KERNEL_RW;
}
if (flags & PAGE_WRITE) {
p->access_permission_0 = p->access_permission_1 =
p->access_permission_2 = p->access_permission_3 =
PTE_AP_USER_RW_KERNEL_RW;
}
}
}
_NO_TRACE static inline void set_pt_level0_present(pte_t *pt, size_t i)
{
pte_level0_t *p = &pt[i].l0;
p->should_be_zero = 0;
write_barrier();
p->descriptor_type = PTE_DESCRIPTOR_COARSE_TABLE;
}
_NO_TRACE static inline void set_pt_level1_present(pte_t *pt, size_t i)
{
pte_level1_t *p = &pt[i].l1;
p->descriptor_type = PTE_DESCRIPTOR_SMALL_PAGE;
}
extern void page_arch_init(void);
#endif
#endif
HelenOS homepage, sources at GitHub