📄 intr_notimes.t
字号:
@c@c COPYRIGHT (c) 1988-2002.@c On-Line Applications Research Corporation (OAR).@c All rights reserved.@c@c $Id: intr_NOTIMES.t,v 1.6 2002/01/17 21:47:47 joel Exp $@c@chapter Interrupt Processing@section IntroductionDifferent types of processors respond to theoccurrence of an interrupt in its own unique fashion. Inaddition, each processor type provides a control mechanism toallow for the proper handling of an interrupt. The processordependent response to the interrupt modifies the currentexecution state and results in a change in the execution stream.Most processors require that an interrupt handler utilize somespecial control mechanisms to return to the normal processingstream. Although RTEMS hides many of the processor dependentdetails of interrupt processing, it is important to understandhow the RTEMS interrupt manager is mapped onto the processor'sunique architecture. Discussed in this chapter are the SPARC'sinterrupt response and control mechanisms as they pertain toRTEMS.RTEMS and associated documentation uses the termsinterrupt and vector. In the SPARC architecture, these termscorrespond to traps and trap type, respectively. The terms willbe used interchangeably in this manual.@section Synchronous Versus Asynchronous TrapsThe SPARC architecture includes two classes of traps:synchronous and asynchronous. Asynchronous traps occur when anexternal event interrupts the processor. These traps are notassociated with any instruction executed by the processor andlogically occur between instructions. The instruction currentlyin the execute stage of the processor is allowed to completealthough subsequent instructions are annulled. The returnaddress reported by the processor for asynchronous traps is thepair of instructions following the current instruction.Synchronous traps are caused by the actions of aninstruction. The trap stimulus in this case either occursinternally to the processor or is from an external signal thatwas provoked by the instruction. These traps are takenimmediately and the instruction that caused the trap is abortedbefore any state changes occur in the processor itself. Thereturn address reported by the processor for synchronous trapsis the instruction which caused the trap and the followinginstruction.@section Vectoring of Interrupt HandlerUpon receipt of an interrupt the SPARC automaticallyperforms the following actions:@itemize @bullet@item disables traps (sets the ET bit of the psr to 0),@item the S bit of the psr is copied into the PreviousSupervisor Mode (PS) bit of the psr,@item the cwp is decremented by one (modulo the number ofregister windows) to activate a trap window,@item the PC and nPC are loaded into local register 1 and 2(l0 and l1),@item the trap type (tt) field of the Trap Base Register (TBR)is set to the appropriate value, and@item if the trap is not a reset, then the PC is written withthe contents of the TBR and the nPC is written with TBR + 4. Ifthe trap is a reset, then the PC is set to zero and the nPC isset to 4.@end itemizeTrap processing on the SPARC has two features whichare noticeably different than interrupt processing on otherarchitectures. First, the value of psr register in effectimmediately before the trap occurred is not explicitly saved.Instead only reversible alterations are made to it. Second, theProcessor Interrupt Level (pil) is not set to correspond to thatof the interrupt being processed. When a trap occurs, ALLsubsequent traps are disabled. In order to safely invoke asubroutine during trap handling, traps must be enabled to allowfor the possibility of register window overflow and underflowtraps.If the interrupt handler was installed as an RTEMSinterrupt handler, then upon receipt of the interrupt, theprocessor passes control to the RTEMS interrupt handler whichperforms the following actions:@itemize @bullet@item saves the state of the interrupted task on it's stack,@item insures that a register window is available forsubsequent traps,@item if this is the outermost (i.e. non-nested) interrupt,then the RTEMS interrupt handler switches from the current stackto the interrupt stack,@item enables traps,@item invokes the vectors to a user interrupt service routine (ISR).@end itemizeAsynchronous interrupts are ignored while traps aredisabled. Synchronous traps which occur while traps aredisabled result in the CPU being forced into an error mode.A nested interrupt is processed similarly with theexception that the current stack need not be switched to theinterrupt stack.@section Traps and Register WindowsOne of the register windows must be reserved at alltimes for trap processing. This is critical to the properoperation of the trap mechanism in the SPARC architecture. Itis the responsibility of the trap handler to insure that thereis a register window available for a subsequent trap beforere-enabling traps. It is likely that any high level languageroutines invoked by the trap handler (such as a user-providedRTEMS interrupt handler) will allocate a new register window.The save operation could result in a window overflow trap. Thistrap cannot be correctly processed unless (1) traps are enabledand (2) a register window is reserved for traps. Thus, theRTEMS interrupt handler insures that a register window isavailable for subsequent traps before enabling traps andinvoking the user's interrupt handler.@section Interrupt LevelsSixteen levels (0-15) of interrupt priorities aresupported by the SPARC architecture with level fifteen (15)being the highest priority. Level zero (0) indicates thatinterrupts are fully enabled. Interrupt requests for interruptswith priorities less than or equal to the current interrupt masklevel are ignored.Although RTEMS supports 256 interrupt levels, theSPARC only supports sixteen. RTEMS interrupt levels 0 through15 directly correspond to SPARC processor interrupt levels. Allother RTEMS interrupt levels are undefined and their behavior isunpredictable.@section Disabling of Interrupts by RTEMSDuring the execution of directive calls, criticalsections of code may be executed. When these sections areencountered, RTEMS disables interrupts to level seven (15)before the execution of this section and restores them to theprevious level upon completion of the section. RTEMS has beenoptimized to insure that interrupts are disabled for less thanRTEMS_MAXIMUM_DISABLE_PERIOD microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ Mhz ERC32 with zero wait states.These numbers will vary based the number of wait states andprocessor speed present on the target board.[NOTE: The maximum period with interrupts disabled is hand calculated. Thiscalculation was last performed for Release RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.][NOTE: It is thought that the length of time at whichthe processor interrupt level is elevated to fifteen by RTEMS isnot anywhere near as long as the length of time ALL traps aredisabled as part of the "flush all register windows" operation.]Non-maskable interrupts (NMI) cannot be disabled, andISRs which execute at this level MUST NEVER issue RTEMS systemcalls. If a directive is invoked, unpredictable results mayoccur due to the inability of RTEMS to protect its criticalsections. However, ISRs that make no system calls may safelyexecute as non-maskable interrupts.@section Interrupt StackThe SPARC architecture does not provide for adedicated interrupt stack. Thus by default, trap handlers wouldexecute on the stack of the RTEMS task which they interrupted.This artificially inflates the stack requirements for each tasksince EVERY task stack would have to include enough space toaccount for the worst case interrupt stack requirements inaddition to it's own worst case usage. RTEMS addresses thisproblem on the SPARC by providing a dedicated interrupt stackmanaged by software.During system initialization, RTEMS allocates theinterrupt stack from the Workspace Area. The amount of memoryallocated for the interrupt stack is determined by theinterrupt_stack_size field in the CPU Configuration Table. Aspart of processing a non-nested interrupt, RTEMS will switch tothe interrupt stack before invoking the installed handler.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -