北京大学操作系统实习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.iuŒPagepnӄ„ù”sû2.ùPage*ubþh„Í\ (inc/queue.h-Ìb/°0„î˜1/¡ Â:ÀHJOSÙú„þh!™ bÙ7„binc/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Ù7„ test.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\ e v“ú„Ñ„ Óœ £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øs„MACRO();(؆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$ïå úÙ7„lbíÕï ('ì÷ù„ã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ô/7M„3.t*i…X„@Ù́ô„/ (ZŒlab1å ìåS†(ž! iubM640KB„›Mŵ ‚BIOS„}e0@bootloader}e0@Í\û߅8ELF‡ö4„4öXzôII wS„@”å‚ þ@:(lab1Œ ìÎ0x000100000Ù*Mne…8 ô0endÓ_end/þ¥h\þ¥ö—0„…8Ó_0@£H(úËiubù”„Page*þhö ì:Ù*þhMžE„i…Xzô (Œ§u0@:6- ûß؁*uîUX @ Œ§uh„0@ Ù*_/Í\û߄HMzô„ @åÓþ ì,eŒKi…X@”å‚ þ@:4Í\ûߞ`¥J,00848231ì,e„î„1/:uîUŒpagesM}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$*ØÏ bootfreememŒbootpgdir M/SMï(…X„Ë0@_1/ô …8}eå ûß¡@„…¹1ÎendåËM sÎËbootfreemem/IŽend Ù*(¥ 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Ë1 0sŽuî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@ 6M„0@µz6vi0@PADDR ebootcr3Æ/¨x86„ub0@lb:6Ù́èà¹PGSIZE:*iu„'4KB=4096B šI(inc/mmu.h- v-Ø ìb(„́8ÏPTSIZE :*uhù”žEi…X„' s1024*4KB=4MBÎbootalloc()—0„ub/\ø”„Ëå\„ @傜ùM0„zô Bz Å{êñ²ê¨Kmemset¥×„z0@/pgdirs*Zß0@ Ù*(ìb„å\-ùžEM0„iiiuuubbbÛLËöВ zö(memset_š(žEiubù”„………888ZZZßßß000@@@bootcr3—0„/*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

1 / 33
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功