【MIPS CPU 体系结构概述2】连载15:

4. exceptions
tlb refill exception(0x80000000):
(1) get badvaddr,pgd
(2) pte table ptr = badvaddr>>22 < 2 + pgd ,
(3) get context,offset = context >> 1 & 0xff8 (bit 21-13 + three zero),
(4) load offset(pte table ptr) and offset+4(pte table ptr), *(5) right shift 6 bits,write to entrylo[01],
(6) tlbwr
tlb modified exception(handle_mod):
(1) load pte,
*(2) if _PAGE_WRITE set,set ACCESSED | MODIFIED | VALID | DIRTY,
reload tlb,tlbwi
else DO_FAULT(1)
tlb load exception(handle_tlbl):

(1) load pte
(2) if _PAGE_PRESENT && _PAGE_READ, set ACCESSED | VALID else DO_FAULT(0)
tlb store exception(handle_tlbs):
(1) load pte
*(2) if _PAGE_PRESENT && _PAGE_WRITE,set ACCESSED | MODIFIED | VALID | DIRTY
else DO_FAULT(1)

items marked with * need modification.

5. protection_map
all _PXXX map to page_copy? Although vm_flags will at last make pte writeable as needed,but will this be inefficient? it seems that alpha is not doing so.

mm setup/tear down:
on fork,copy_mm:
allocate_mm,
memcpy(new,old)
slow path
mm_init-->pgd_alloc-->pgd_init-->all point to invalid_pte
-->copy kseg pgds from init_mm
fast path: what's the content of pgd?
--> point to invalid_pte too,see clear_page_tables
dup_mmap->copy_page_range-->alloc page table entries and do cow if needed. copy_segmens--null
init_new_context--set mm->context=0(allocate an array for SMP first) on exec(elf file),load_elf_binary:
flush_old_exec:
exec_mmap
exit_mmap(old_mm)
free vm_area_struct
zap_page_range: free pages
clear_page_tables
pgd_clear: do nothing
pmd_clear: set to invalid_pte

pte_clear: set to zero
mm_alloc
initialize new mm( init_new_contex,add to list,activate it) mmput(oldmm)
setup_arg_pages:
initialize stack segment. mm_area_struct for stack segment is setup
here.
load elf image into the correct location in memory elf_prot generated from eppnt->p_flags
elf_map(..,elf_prot,..)
do_mmap

a typical session for a user page to be read then written:
(1) user allocates the space
(2) kernel call do_mmap/do_brk, vm_area_struct created
(3) user tries to read
(4) tlb refill exception occurs,invalid_pte_table's entry is loaded into
tlb
(5) tlbl exception occurs,
do_page_fault(0)->handle_mm_fault(allocate pte_table)->handle_pte_fault -->do_no_page-->map to ZERO page,readonly,set_pte,update_mmu_cache (update_mmu_cache put new pte to tlb,NEED change for godson)
(6) read done,user tries to write
(7) tlbs exception occurs(suppose the tlb entry is not yet kicked out)
because pte is write protected,do_page_fault(1) called.
handle_mm_fault(find out the pte)-->handle_pte_fault->do_wp_page -->allocate page,copy page,break_cow-->make a writeable pte,
-->establish_pte-->write pte and update_mmu_cache
(8) write done.

above has shown that handle_mm_fault doesn't care much about what the page_prot is. (Of course,it has to be reasonable)
What really matters is vm_flags,it will decide whether an access is valid

--电子创新网--
粤ICP备12070055号