您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > 北京大学操作系统实习JOS lab2实验报告
Í\ûßJOS`,!¥J00848231,zhangchitc@gmail.comMarch29,2011Contents1Introduction22PhysicalPageManagement22.1Physicalpageanditsdatastructure................22.2Physicalmemorylayout.......................43VirtualMemory93.1Virtual,Linear,andPhysicalAddresses..............103.2Referencecounting..........................103.3PageTableManagement.......................134KernelAddressSpace204.1PermissionsandFaultIsolation...................204.2InitializingtheKernelAddressSpace................204.3AddressSpaceLayoutAlternatives.................311Í\ûß`¥J,008482311Introduction(-;ÂN-Ñ'fµ×ÜJOS`ü(µ;uïå~0F/Ù!üÜÜlab1üæ=@åÙÌ eE ¹2PhysicalPageManagementExercise1.Inthefilekern/pmap.c,youmustimplementcodeforthefollowingfunctions.boot_alloc()page_init()page_alloc()page_free()Youalsoneedtoaddsomecodetoi386_vm_init()inpmap.c,asindicatedbycommentsthere.Fornow,justaddthecodeneededleadinguptothecalltocheck_page_alloc().Youprobablywanttoworkonboot_alloc(),theni386_vm_init(),thenpage_init(),page_alloc(),andpage_free().check_page_alloc()testsyourphysicalpageallocator.YoushouldbootJOSandseewhethercheck_page_alloc()reportssuccess.Fixyourcodesothatitpasses.Youmayfindithelpfultoaddyourownassert()stoverifythatyourassumptionsarecorrect.Ùè ¹öublb:6¡ sûì ͹sè/iubÄåÊ¡; sèJOS 8ã-inc/queue.höåÊkern/pmap.cö2.1Physicalpageanditsdatastructure÷ÔÆûµ²I-4.3à, ub¡v-͹ áå ¹1.iuPagepnÓùsû2.ùPage*ubþhÍ\(inc/queue.h-Ìb/ °0î1/¡Â:ÀHJOSÙúþh!bÙ7binc/queue.h165/*166*Resetthelistnamedheadtotheemptylist.2Í\ûß`¥J,00848231167*/168#defineLIST_INIT(head)do{\169LIST_FIRST((head))=NULL;\170}while(0)Ù*î/þhË:zFG*/:ÀH *êgL !whileª¯b/ô¥'ì÷OÙ µíå1ïå¤}IDÙú *æ=áTHÖÙbÙ7test.c1#includestdio.h23#defineMACRO()do{\4printf(hello\n);\5}while(0)67intmain(){8intx;9scanf(%d\n,&x);1011if(x)12MACRO();13else14printf(thisiselse\n);15return0;16}6(gcc-Etest.cÑÙµÂpEî/:©ÑhÅÅÛLÑås\evúÑÓ£Hì0Ù7úintmain(){intx;scanf(%d\n,&x);if(x)do{printf(hello\n);}while(0);elseprintf(thisiselse\n);return0;}zhangchi@zhangchi-desktop:/tmp/test$ì0øsMACRO();(ØvøU ÷y+è(öì/åU*íåb(MACRO()£HU åbØ/á³U*íå( *whileª¯)v(vb ÷ìMACRO9test.c1#defineMACRO(){\2printf(hello\n);\3}£H!U ÓØintmain(){intx;3Í\ûß`¥J,00848231scanf(%d\n,&x);if(x){printf(hello\n);};elseprintf(thisiselse\n);return0;}zhangchi@zhangchi-desktop:/tmp/test$ïåúÙ7lbíÕï('ì÷ùãW ÷ÙÌúà1(ì(MACRO()KM/S *U*íå(U Ø *ãW£HøíÕÓ1ú°Øüôú/Q^8ÆôD2.2Physicalmemorylayout÷ÔÆûµ²I-4.3à, ub¡-“ub¡þh( X-X¨n”͹ã1.pagespÄPage*þhùsû2.pages@(zô/7M3.t*i X@ÙÌô/(Zlab1åìåS(!iubM640KB MŵBIOS}e0@bootloader}e0@Í\ûß 8ELFö44öXzôIIwS@åþ@:(lab1ìÎ0x000100000Ù*Mne 8ô0endÓ_end/þ¥h\þ¥ö0 8Ó_0@£H(úËiubùPage*þhöì :Ù*þhMEi Xzô(§u0@:6-ûßØ *uîUX@ §uh0@Ù*_/ Í\ûßHMzô@åÓþì, eKi X@åþ@:4Í\ûß`¥J,00848231ì, eî1/:uîUpagesM}zôvúËwzòuhpagefreelist ËãöH Zkern/pmap.c-à*ú,ØÏkern/pmap.c12//Thesevariablesaresetbyi386_detect_memory()13staticphysaddr_tmaxpa;//Maximumphysicaladdress14size_tnpage;//Amountofphysicalmemory(inpages)15staticsize_tbasemem;//Amountofbasememory(inbytes)16staticsize_textmem;//Amountofextendedmemory(inbytes)1718//Thesevariablesaresetini386_vm_init()19pde_t*boot_pgdir;//Virtualaddressofboottimepagedirectory20physaddr_tboot_cr3;//Physicaladdressofboottimepagedirectory21staticchar*boot_freemem;//Pointertonextbyteoffreemem2223structPage*pages;//Virtualaddressofphysicalpagearray24staticstructPage_listpage_free_list;//FreelistofphysicalpagesÙÌê åS$*ØÏbootfreemembootpgdirM/SMï( X Ë0@_1/ô 8}eåûß¡@ ¹1Îendå ËMsÎ Ëbootfreemem/IendÙ*(¥eãÌ1ý0 bootpgdir/ûßuîU@(zô Ë0@èèè$$$000@@@ýýý///ZZZßßß000@@@(((ÙÙÙ!!!lab--- ZZZ ***ÆÆÆ111///ZZZßßß000@@@¿¿¿'''000@@@iii000@@@:::+++åååÊÊÊììì(((000@@@ØØØÏÏÏêêê///ZZZßßß000@@@êêê///iii000@@@¥eìïå0i386vminit()ÎÙÌ ËìÙ!lab Ë10suîUËãkern/pmap.c:i386vminit()1//////////////////////////////////////////////////////////////////////2//createinitialpagedirectory.3pgdir=boot_alloc(PGSIZE,PGSIZE);45memset(pgdir,0,PGSIZE);6boot_pgdir=pgdir;7boot_cr3=PADDR(pgdir);5Í\ûß`¥J,00848231v-bootalloc():vM Xzô0@6M0@µz6vi0@PADDR ebootcr3Æ/¨x86ub0@lb:6ÙÌèà¹PGSIZE: *iu'4KB=4096BI(inc/mmu.h-v-Ø ìb(Í8ÏPTSIZE: *uhùEi X's1024*4KB=4MBÎbootalloc()0ub/\øËå\@åùM0zô BzÅ{êñ²ê¨Kmemset¥×z0@/pgdirs *Zß0@Ù*(ìbå\-ùEM0iiiuuubbbÛLËöÐzö(memset_ (Eiubù 888ZZZßßß000@@@bootcr30/ *iii000@@@Ù*ìMb:Ï*0@ØÏ0/Zß0@Ø/i0@ ÆTû¥eìe , * °ýpbootalloc()kern/pmap.c:bootalloc()1staticvoid*2boot_alloc(uint32_tn,uint32_talign)3{4externcharend[];5void*v;67//Initializeboot_freememifthisisthefirsttime.8//’e
本文标题:北京大学操作系统实习JOS lab2实验报告
链接地址:https://www.777doc.com/doc-3514551 .html