北京大学操作系统实习JOS lab1实验报告

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Í\ûßJOSž`,!¥J00848231,zhangchitc@gmail.comMarch18,2011Contents1PCBootstrap21.1GettingStartedwithx86assembly.................21.2Simulatingthex86..........................21.3ThePC’sPhysicalAddressSpace..................21.4TheROMBIOS............................22TheBootLoader32.1LoadingtheKernel..........................52.2Linkvs.LoadAddress........................63TheKernel83.1FormattedPrintingtotheConsole.................103.2TheStack................................161Í\ûߞ`¥J,008482311PCBootstrap1.1GettingStartedwithx86assemblyExercise1.Familiarizeyourselfwiththeassemblylanguagematerialsavailableonthe6.828referencepage.Youdon’thavetoreadthemnow,butyou’llalmostcertainlywanttorefertosomeofthismaterialwhenreadingandwritingx86assembly.WedorecommendreadingthesectionTheSyntaxinBrennan’sGuidetoInlineAssembly.Itgivesagood(andquitebrief)descriptionoftheAT&Tassemblysyntaxwe’llbeusingwiththeGNUassemblerinJOS.InlineGåMÎe¡ ¥æÇ @åBrennan’sGuidetoInlineAssembly we ¹L vքØ}1.2Simulatingthex86((QEMUÐLbootloaderö Ñ°„QEMU‚Bochs4Ä*0¹/BochsЛa”infogdt”„}ä ïååӄ„¹SpúGlobalDescriptorTable„ú@Œhy QEMUtЛ ê ”inforegisters”ïåå 0gdt„ú0@ 6)(å0@ïå»ø”„…X(”xp/xNpaddr”å wS…¹Ù*î†+º}Ï_/Ù7åS/ì¡~0Ø/QEMU„1¡ 1.3ThePC’sPhysicalAddressSpace,eå:N0@zô0x000A0000(640KB)KM„zô/ý(„:†ŒH |¹ ӜѰ(bootloader㋅8„ö ÙGLowMem-ory«(\†4özô¨X…8ELF„‡ö4wSeô ELF‡ö4«Ê0†Î0@:0x10000˄G4KBzô…1.4TheROMBIOSExercise2.UseGDB’ssi(StepInstruction)commandtotraceintotheROMBIOSforafewmoreinstructions,andtrytoguesswhatitmightbedoing.YoumightwanttolookatPhilStorrsI/OPortsDescription,aswellasothermaterialsonthe6.828referencematerialspage.Noneedtofigureoutallthedetails-justthegeneralideaofwhattheBIOSisdoingfirst.IOKŒ*†Orz......2Í\ûߞ`¥J,008482312TheBootLoaderExercise3.Takealookatthelabtoolsguide,especiallythesectiononGDBcommands.Evenifyou’refamiliarwithGDB,thisincludessomeesotericGDBcommandsthatareusefulforOSwork.Setabreakpointataddress0x7c00,whichiswherethebootsectorwillbeloaded.Continueexecutionuntilthatbreakpoint.Tracethroughthecodeinboot/boot.S,usingthesourcecodeandthedisassemblyfileobj/boot/boot.asmtokeeptrackofwhereyouare.Alsousethex/icommandinGDBtodisassemblesequencesofinstructionsinthebootloader,andcomparetheoriginalbootloadersourcecodewithboththedisassemblyinobj/boot/boot.asmandGDB.Traceintobootmain()inboot/main.c,andthenintoreadsect().Identifytheexactassemblyinstructionsthatcorrespondtoeachofthestatementsinreadsect().Tracethroughtherestofreadsect()andbackoutintobootmain(),andidentifythebeginandendoftheforloopthatreadstheremainingsectorsofthekernelfromthedisk.Findoutwhatcodewillrunwhentheloopisfinished,setabreakpointthere,andcontinuetothatbreakpoint.Thenstepthroughtheremainderofthebootloader.Beabletoanswerthefollowingquestions:Atwhatpointdoestheprocessorstartexecuting32-bitcode?Whatex-actlycausestheswitchfrom16-to32-bitmode?Whatisthelastinstructionofthebootloaderexecuted,andwhatisthefirstinstructionofthekernelitjustloaded?Whereisthefirstinstructionofthekernel?Howdoesthebootloaderdecidehowmanysectorsitmustreadinordertofetchtheentirekernelfromdisk?Wheredoesitfindthisinformation?1.hÎBIOSÛebootloader (boot/boot.S-,48L0,51Lã bootloaderÄÄÄXXXhhhcr0„„„+++MMMôôô999:::1 ———hhhÎÎΞ!!!ôôô999000ÝÝݤ¤¤!!!boot/boot.S44#Switchfromrealtoprotectedmode,usingabootstrapGDT45#andsegmenttranslationthatmakesvirtualaddresses46#identicaltotheirphysicaladdresses,sothatthe47#effectivememorymapdoesnotchangeduringtheswitch.48lgdtgdtdesc49movl%cr0,%eax50orl$CR0_PE_ON,%eax51movl%eax,%cr02.bootloadergggLLL„„„aaaäää:::………888ELF‡‡‡ööö}}}eee………XXX (((………888eeeããã¹¹¹ (boot/main.c-„,58L3Í\ûߞ`¥J,00848231boot/main.c56//calltheentrypointfromtheELFheader57//note:doesnotreturn!58((void(*)(void))(ELFHDR-e_entry&0xFFFFFF))();3.9nåâobjdump-xobj/kern/kernel„Óœïå—å…8ELF„eã0@:0xf010000c,F/boot/main.c(}e…8öZ†!K¨„0@lb ØM„f»‰† @勞(ÐL-…8/« }0†0x10000c„…X0@ @å/¨GDB(0x10000c¾ ­¹ \ öïå 0Thetargetarchitectureisassumedtobei8086[f000:fff0]0xffff0:ljmp$0xf000,$0xe05b0x0000fff0in??()+symbol-fileobj/kern/kernel(gdb)b*0x10000cBreakpoint1at0x10000c(gdb)cContinuing.Thetargetarchitectureisassumedtobei386=0x10000c:movw$0x1234,0x472Breakpoint1,0x0010000cin??()(gdb)ÙÙÙööö0x10000c„„„ãããmovw$0x1234,0x472111///………888„„„,,,aaaíííåååÙ*öìÍÇ4e»ý¯…8kernel„ã œ6(kern/entry.S-Ñ°†ÙHµã v-,44Lc}1/ì~0„eãíåkern/entry.S36#TheMultibootheader37.align438.longMULTIBOOT_HEADER_MAGIC39.longMULTIBOOT_HEADER_FLAGS40.longCHECKSUM4142.globl_start43_start:44movw$0x1234,0x472#warmboot4546#EstablishourownGDTinplaceofthebootloader’stemporaryGDT47lgdtRELOC(mygdtdesc)#loaddescriptortable4.bootloaderÎÎ΅……888ELF‡‡‡ööö„„„‡‡‡ööö444---ïïïååååååSSSåååELF‡‡‡ööö«««†††sectionŒŒŒprogram 1ïååSø”„ûÖpî†ٛáoïåÇobjdump-xobj/kern/kernel—0 ‚ @:zhangchi@zhangchi-laptop:˜/oslab$objdump-xobj/kern/kernelobj/kern/kernel:fileformatelf32-i386obj/kern/kernelarchitecture:i386,flags0x00000112:EXEC_P,HAS_SYMS,D_PAGEDstartaddress0xf010000cProgramHeade

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

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

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

×
保存成功