資源描述:
《(mips體系結(jié)構(gòu)剖析,編程與實(shí)踐)第4章 mips 異常與中斷處理文庫(kù)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、(MIPS體系結(jié)構(gòu)剖析,編程與實(shí)踐)第4章MIPS異常和中斷處理文庫(kù)MIPS異常和中斷處理(ExceptionandInterrupthandling)任何一個(gè)CPU都要提供一個(gè)詳細(xì)的異常和中斷處理機(jī)制。一個(gè)軟件系統(tǒng),如操作系統(tǒng),就是一個(gè)時(shí)序邏輯系統(tǒng),通過時(shí)鐘,外部事件來(lái)驅(qū)動(dòng)整個(gè)預(yù)先定義好的邏輯行為。這也是為什么當(dāng)寫一個(gè)操作系統(tǒng)時(shí)如何定義時(shí)間的計(jì)算是非常重要的原因。大家都非常清楚UNIX提供了一整套系統(tǒng)調(diào)用(SystemCall)。系統(tǒng)調(diào)用其實(shí)就是一段EXCEPTION處理程序。我們可能要問:為什么CPU要提供Excpetion和InterruptHandling呢?*處
2、理illegalbehavior,例如,TLBFault,or,wesay,thePagefault;CacheError;*Provideanapproachforaccessingpriviledgedresources,forexample,CP0registers.Asweknow,foruserleveltasks/processes,theyarerunningwiththeUserModepriviledgeandareprohibilitedtodirectlycontrolCPO.CPUneedprovideamechanismforthemtotrap
3、tokernelmodeandthensafelymanipulateresourcesthatareonlyavailablewhenCPUrunsinkernelmode.*Providehandlingforexternal/internalinterrupts.Forinstance,thetimerinterruptsandwatchdogexceptions.Thosetwointerrupt/exceptionsareveryimportantforanembeddedsystemapplicances.Nowlet'sgetbacktohowMIPSsup
4、portsitsexceptionandinterrupthandling.Forsimplicty,allinformationbelowwillbebasedonR7KCPU,whichisderivedfromtheR4kfamily.*ThefirstthingforunderstandingMIPSexceptionhandlingis:MIPSadopts**PreciseExceptions**mechanisms.Whatthatmeans?Hereistheexplainationfromthebookof"SeeMIPSRun":"Inaprecise
5、-exceptionCPU,onanyexceptionwegetpointedatoneinstruction(theexceptionvictim).Allinstructionsprecedingtheexceptionvictiminexecutionsequencearecomplete;anyworkdoneonthevictimandonanysubsequentinstructions(BNNNOTE:pipelineeffects)hasnosideeffectsthatthesoftwareneedworryabout.Thesoftwarethath
6、andlesexceptionscanignoreallthetimingeffectsoftheCPU'simplementations"上面的意思其實(shí)很簡(jiǎn)單:在發(fā)生EXCEPTION之前的一切計(jì)算行為會(huì)**FINISH**。在發(fā)生EXCEPTION之后的一切計(jì)算行為將不需考慮。對(duì)絕大多數(shù)情況而言,如你要寫一個(gè)系統(tǒng)調(diào)用(SystemCall),你只要記?。篗IPS已經(jīng)把syscall這條指令的地址壓在了EPC寄存器里。換句話說(shuō),在MIPS里,compardtothePowerPCCPUsrr1register,你需要**explicitely**refilltheEPC
7、registerbyEPC<-----EPC+4,beforeyouusetheeret中斷返回。只有這樣,你才能從系統(tǒng)調(diào)用中正確返回。異常/中斷向量(Exception/InterruptVector)MIPS的Exception/InterruptVector的organizaionisnotasgoodasPowerPCCPUs.ForPPC,everydetailedexceptioncauseisdirectedtoaunqiuevectoraddress.MIPSisotherwise.Belowisarecapo