操作系统内核知识汇总英文版文档格式.docx

上传人:b****7 文档编号:22598069 上传时间:2023-02-04 格式:DOCX 页数:36 大小:1.16MB
下载 相关 举报
操作系统内核知识汇总英文版文档格式.docx_第1页
第1页 / 共36页
操作系统内核知识汇总英文版文档格式.docx_第2页
第2页 / 共36页
操作系统内核知识汇总英文版文档格式.docx_第3页
第3页 / 共36页
操作系统内核知识汇总英文版文档格式.docx_第4页
第4页 / 共36页
操作系统内核知识汇总英文版文档格式.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

操作系统内核知识汇总英文版文档格式.docx

《操作系统内核知识汇总英文版文档格式.docx》由会员分享,可在线阅读,更多相关《操作系统内核知识汇总英文版文档格式.docx(36页珍藏版)》请在冰豆网上搜索。

操作系统内核知识汇总英文版文档格式.docx

evenifyoumisssomedetailsyoucangetthegistofwhat’shappening.Themainobstacleisthelackofcontextaroundsomeofthecode,suchaswhenorwhyitrunsortheunderlyingfeaturesofthemachine.Ihopetoprovideabitofthatcontext.Duetobrevity(hah!

)alotoffunstuff–likeinterruptsandmemory–getsonlyanodfornow.ThepostendswiththehighlightsfortheWindowsboot.

AtthispointintheIntelx86bootstorytheprocessorisrunninginreal-mode,isabletoaddress1MBofmemory,andRAMlookslikethisforamodernLinuxsystem:

 

RAMcontentsafterbootloaderisdone

ThekernelimagehasbeenloadedtomemorybythebootloaderusingtheBIOSdiskI/Oservices.Thisimageisanexactcopyofthefileinyourharddrivethatcontainsthekernel,e.g./boot/vmlinuz-2.6.22-14-server.Theimageissplitintotwopieces:

asmallpartcontainingthereal-modekernelcodeisloadedbelowthe640Kbarrier;

thebulkofthekernel,whichrunsinprotectedmode,isloadedafterthefirstmegabyteofmemory.

Theactionstartsinthereal-modekernelheaderpicturedabove.Thisregionofmemoryisusedtoimplementthe 

Linuxbootprotocol 

betweenthebootloaderandthekernel.Someofthevaluestherearereadbythebootloaderwhiledoingitswork.Theseincludeamenitiessuchasahuman-readablestringcontainingthekernelversion,butalsocrucialinformationlikethesizeofthereal-modekernelpiece.Thebootloaderalso 

writes 

valuestothisregion,suchasthememoryaddressforthecommand-lineparametersgivenbytheuserinthebootmenu.Oncethebootloaderisfinishedithasfilledinalloftheparametersrequiredbythekernelheader.It’sthentimetojumpintothekernelentrypoint.Thediagrambelowshowsthecodesequenceforthekernelinitialization,alongwithsourcedirectories,files,andlinenumbers:

Architecture-specificLinuxKernelInitialization

Theearlykernelstart-upfortheIntelarchitectureisinfile 

arch/x86/boot/header.S.It’sinassemblylanguage,whichisrareforthekernelatlargebutcommonforbootcode.Thestartofthisfileactuallycontainsbootsectorcode,aleftoverfromthedayswhenLinuxcouldworkwithoutabootloader.Nowadaysthisbootsector,ifexecuted,onlyprintsa“bugger_off_msg”totheuserandreboots.Modernbootloadersignorethislegacycode.Afterthebootsectorcodewehavethefirst15bytesofthereal-modekernelheader;

thesetwopiecestogetheraddupto512bytes,thesizeofatypicaldisksectoronIntelhardware.

Afterthese512bytes,atoffset0×

200,wefindtheveryfirstinstructionthatrunsaspartoftheLinuxkernel:

thereal-modeentrypoint.It’sin 

header.S:

110 

anditisa2-bytejumpwrittendirectlyinmachinecodeas0x3aeb.Youcanverifythisbyrunninghexdumponyourkernelimageandseeingthebytesatthatoffset–justasanitychecktomakesureit’snotalladream.Thebootloaderjumpsintothislocationwhenitisfinished,whichinturnjumpsto 

229 

wherewehavearegularassemblyroutinecalledstart_of_setup.Thisshortroutinesetsupastack,zeroesthe 

bss 

segment(theareathatcontainsstaticvariables,sotheystartwithzerovalues)forthereal-modekernelandthenjumpstogoodoldCcodeat 

arch/x86/boot/main.c:

122.

main()doessomehousekeepinglikedetectingmemorylayout,settingavideomode,etc.Itthencalls 

go_to_protected_mode().BeforetheCPUcanbesettoprotectedmode,however,afewtasksmustbedone.Therearetwomainissues:

interruptsandmemory.Inreal-modethe 

interruptvectortable 

fortheprocessorisalwaysatmemoryaddress0,whereasinprotectedmodethelocationoftheinterruptvectortableisstoredinaCPUregistercalledIDTR.Meanwhile,thetranslationoflogicalmemoryaddresses(theonesprogramsmanipulate)tolinearmemoryaddresses(arawnumberfrom0tothetopofthememory)isdifferentbetweenreal-modeandprotectedmode.ProtectedmoderequiresaregistercalledGDTRtobeloadedwiththeaddressofa 

GlobalDescriptorTable 

formemory.Sogo_to_protected_mode()calls 

setup_idt() 

and 

setup_gdt() 

toinstallatemporaryinterruptdescriptortableandglobaldescriptortable.

We’renowreadyfortheplungeintoprotectedmode,whichisdoneby 

protected_mode_jump,anotherassemblyroutine.ThisroutineenablesprotectedmodebysettingthePEbitintheCR0CPUregister.Atthispointwe’rerunningwith 

paging 

disabled;

pagingisanoptionalfeatureoftheprocessor,eveninprotectedmode,andthere’snoneedforityet.What’simportantisthatwe’renolongerconfinedtothe640Kbarrierandcannowaddressupto4GBofRAM.Theroutinethencallsthe32-bitkernelentrypoint,whichis 

startup_32 

forcompressedkernels.Thisroutinedoessomebasicregisterinitializationsandcalls 

decompress_kernel(),aCfunctiontodotheactualdecompression.

decompress_kernel()printsthefamiliar“DecompressingLinux…”message.Decompressionhappensin-placeandonceit’sfinishedtheuncompressedkernelimagehasoverwrittenthecompressedonepicturedinthefirstdiagram.Hencetheuncompressedcontentsalsostartat1MB.decompress_kernel()thenprints“done.”andthecomforting“Bootingthekernel.”By“Booting”itmeansajumptothefinalentrypointinthiswholestory,giventoLinusbyGodhimselfatop 

MountainHalti,whichistheprotected-modekernelentrypointatthestartofthesecondmegabyteofRAM(0×

100000).Thatsacredlocationcontainsaroutinecalled,uh, 

startup_32.But 

this 

oneisinadifferentdirectory,yousee.

Thesecondincarnationofstartup_32isalsoanassemblyroutine,butitcontains32-bitmodeinitializations.Itclearsthebsssegmentfortheprotected-modekernel(whichisthe 

true 

kernelthatwillnowrununtilthemachinerebootsorshutsdown),setsupthefinalglobaldescriptortableformemory,buildspagetablessothatpagingcanbeturnedon,enablespaging,initializesastack,createsthefinalinterruptdescriptortable,andfinallyjumpstotothearchitecture-independentkernelstart-up, 

start_kernel().Thediagrambelowshowsthecodeflowforthelastlegoftheboot:

Architecture-independentLinuxKernelInitialization

start_kernel()looksmoreliketypicalkernelcode,whichisnearlyallCandmachineindependent.Thefunctionisalonglistofcallstoinitializationsofthevariouskernelsubsystemsanddatastructures.Theseincludethescheduler,memoryzones,timekeeping,andsoon.start_kernel()thencallsrest_init(),atwhichpointthingsarealmostallworking.rest_init()createsakernelthreadpassinganotherfunction, 

kernel_init(),astheentrypoint.rest_init()thencalls 

schedule() 

tokickstarttaskschedulingandgoestosleepbycalling 

cpu_idle(),whichistheidlethreadfortheLinuxkernel.cpu_idle()runsforeverandsodoesprocesszero,whichhostsit.Wheneverthereisworktodo–arunnableprocess–processzerogetsbootedoutoftheCPU,onlytoreturnwhennorunnableprocessesareavailable.

Buthere’sthekickerforus.Thisidleloopistheendofthelongthreadwefollowedsinceboot,it’sthefinaldescendentoftheveryfirst 

jump 

executedbytheprocessorafterpowerup.Allofthismess,fromresetvectortoBIOStoMBRtobootloadertoreal-modekerneltoprotected-modekernel,allofitleadsrighthere,jumpbyjumpbyjumpitendsintheidleloopforthebootprocessor,cpu_idle().Whichisreallykindofcool.However,thiscan’tbethewholestoryotherwisethecomputerwoulddonowork.

Atthispoint,thekernelthreadstartedpreviouslyisreadytokickin,displacingprocess0anditsidlethread.Andsoitdoes,atwhichpointkernel_init()startsrunningsinceitwasgivenasthethreadentrypoint. 

kernel_init() 

isresponsibleforinitializingtheremainingCPUsinthesystem,whichhavebeenhaltedsinceboot.Allofthecodewe’veseensofarhasbeenexecutedinasingleCPU,calledthebootprocessor.AstheotherCPUs,calledapplicationprocessors,arestartedtheycomeupinreal-modeandmustrunthroughseveralinitializationsaswell.Manyofthecodepathsarecommon,asyoucanseeinthecodefor 

startup_32,butthereareslightforkstakenbythelate-comingapplicationprocessors.Finally,kernel_init()calls 

init_post(),whichtriestoexecuteauser-modeprocessinthefollowingorder:

/sbin/init,/etc/init,/bin/init,and/bin/sh.Ifallfail,thekernelwillpanic.Luckilyinitisusuallythere,andstartsrunningasPID1.Itchecksitsconfigurationfiletofigureoutwhichprocessestolaunch,whichmightincludeX11Windows,programsforlogginginontheconsole,networkdaemons,andsoon.ThusendsthebootprocessasyetanotherLinuxboxstartsrunningsomewhere.Mayyouruptimebelonganduntroubled.

TheprocessforWindowsissimilarinmanyways,giventhecommonarchitecture.Manyofthesameproblemsarefacedandsimilarinitializationsmustbedone.WhenitcomestobootoneofthebiggestdifferencesisthatWindowspacksallofthereal-modekernelcode,andsomeoftheinitialprotectedmodecode,intothebootloaderitself(C:

\NTLDR).Soinsteadofhavingtworegionsinthesamekernelimage,Windowsusesdifferentbinaryimages.PlusLinuxcompletelyseparatesbootloaderandkernel;

inawaythisautomatic

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1