Skip to content

Commit

Permalink
Add support for page permission bits in BIOS
Browse files Browse the repository at this point in the history
fallen committed Oct 17, 2012
1 parent de964d4 commit 3834f5d
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions software/include/hal/mmu.h
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@
#define MAPPING_COPY_ON_WRITE (1 << 4)
#define MAPPING_IS_VALID (1 << 5)

#define MAPPING_CAN_RW (MAPPING_CAN_READ | MAPPING_CAN_WRITE)

struct mmu_mapping {

unsigned int vaddr;
10 changes: 9 additions & 1 deletion software/libbase/mmu.c
Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@ unsigned int mmu_map(unsigned int vaddr, unsigned int paddr, char metadata) {
{
puts("Already mapped, updating metadata !");
mappings[i].metadata |= metadata;
// set the permission bits in lower bits of paddr to be written in the TLB
paddr |= (metadata & MAPPING_CAN_RW);

if (mappings[i].metadata & ITLB_MAPPING)
mmu_itlb_map(vaddr, paddr);
if (mappings[i].metadata & DTLB_MAPPING)
@@ -57,6 +60,9 @@ unsigned int mmu_map(unsigned int vaddr, unsigned int paddr, char metadata) {
printf("Vaddr already mapped to another Paddr (0x%08X), overwritting...\n", mappings[i].paddr);
mappings[i].paddr = paddr;
mappings[i].metadata = (metadata | MAPPING_IS_VALID);
// set the permission bits in lower bits of paddr to be written in the TLB
paddr |= (metadata & MAPPING_CAN_RW);

if (mappings[i].metadata & ITLB_MAPPING)
mmu_itlb_map(vaddr, paddr);
if (mappings[i].metadata & DTLB_MAPPING)
@@ -74,6 +80,8 @@ unsigned int mmu_map(unsigned int vaddr, unsigned int paddr, char metadata) {
mappings[empty_slot].vaddr = vaddr;
mappings[empty_slot].paddr = paddr;
mappings[empty_slot].metadata = (metadata | MAPPING_IS_VALID);
// set the permission bits in lower bits of paddr to be written in the TLB
paddr |= (metadata & MAPPING_CAN_RW);

if (metadata & ITLB_MAPPING)
mmu_itlb_map(vaddr, paddr);
@@ -92,7 +100,7 @@ unsigned int get_mmu_mapping_for(unsigned int vaddr) {

for (i = 0 ; i < MAX_MMU_SLOTS ; ++i)
if ((mappings[i].metadata & MAPPING_IS_VALID) && (vaddr == mappings[i].vaddr))
return mappings[i].paddr;
return get_pfn(mappings[i].paddr);

return A_BAD_ADDR;
}

0 comments on commit 3834f5d

Please sign in to comment.