⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saverest.asm

📁 这个UCOS II在TI2400DSP平台上的移植源代码
💻 ASM
字号:
****************************************************************************
*  saverest   v7.01
*  Copyright (c) 1988-1996 Texas Instruments Inc.
*
*  Modified by Ding.Curie to accommodate uC/OS-II 2.52
****************************************************************************

****************************************************************************
*
* This module contains the following definitions :
*
* I$$SAVE - Save environment for interrupt routine.
* I$$REST - Restore environment from interrupt.
*
* This is the list of registers preserved by these routines:
*
* 'C2x, 'C2xx, and 'C5x
* ---------------------
* P, T, ST1, ST0, ACC, AR0, AR2, AR3, AR4, AR5, AR6, AR7
*
* 'C5x Only
* ---------
* TREG1, ACCB, PMST, BRCR, PASR, PAER
*
* Additionally, the entire hardware stack is preserved.
*
* This list is all the registers used by the compiler.  Any other registers
* are NOT preserved by these routines.  User assembly routines called by C
* interrupts which modify registers not preserved here must insure those
* registers are preserved.
*
* To handle interrupting user written assembly code, the status bits the
* compiler depends on are set up again.  The status registers are saved before
* making these changes.
*
* The INDX ('C5x only) register is used by the compiler, but because these
* routines run with the NDX bit of PMST set to 0, preserving AR0 will
* preserve INDX as well.
*
* The entire hardware stack is preserved because, in some cases, the entire
* stack may be in use by the C compiler, and the C coded interrupt to be 
* executed next may use all of the hardware stack again.  
*
****************************************************************************
	.global     I$$SAVE, I$$REST

	.if	.tms32050
	.mmregs
	.endif

**************************************************************************
* If you are running on a 'C5x, and you do not nest interrupts, set this
* 'NEST' flag to 0, re-assemble, then re-archive the object file into
* the 'rts50.lib' object library.  You will then depend on the 'C5x shadow
* register capability to preserve certain registers.
**************************************************************************
NEST		.set	1
NO_SHADOW	.set	.tms32025 | .tms3202xx | NEST

**************************************************************************
* Symbol def'd for code to get around 'C5x silicon bugs
* Change to 0 for good silicon
**************************************************************************
SBUGS	.set	.tms32050

**************************************************************************
* Re-define RPTK to get around 'C5x silicon bug
**************************************************************************
	.if	SBUGS
RPTK	.macro	LOOPS
	.word	0BEC4h
	.word	LOOPS
	.endm
	.endif

****************************************************************************
* FUNCTION DEF : i$$save
*                This function is called at the entry to an interrupt
*                handler, to save machine status, and set up a known
*                environment for the interrupt handler.
****************************************************************************
I$$SAVE:
         LARP     AR1            ; CURRENT ARP = STACK POINTER
         ADRK     1              ; SKIP TOP ELEMENT ON STACK

	 .if 	  NO_SHADOW
	 SST1     *+             ; SAVE STATUS REGISTERS
	 SST      *+

     SACH     *+             ; SAVE ACCUMULATOR
	 SACL     *+

	 .if	  .tms32050
	 LAMM     PMST		 ; SAVE PMST STATUS REGISTER
	 SACL     *+
	 LAMM	  TREG1		 ; SAVE TREG1
	 SACL	  *+
	 .endif	  ; .tms32050
	 .endif	  ; NO_SHADOW

	 ROVM			 ; turn off overflow mode
	 SPM	  0		 ; product shift count of 0
	 .if	  .tms32050
	 LDPK	  0
	 APL	  #0fff9h,PMST	 ; set NDX = 0 and TRM = 0
	 .endif	  ; .tms32050

	 .if	  NO_SHADOW
     SPH      *+		 ; SAVE P REGISTER
	 SPL      *+

     MPYK     1              ; SAVE T REGISTER
	 SPL      *+

	 .if      .tms32050

	 LACB			 ; SAVE ACCB
	 SACH	  *+
	 SACL	  *+

	 .endif   ; .tms32050
	 .endif   ; NO_SHADOW

	 .if      .tms32050
	 LAMM     BRCR		 ; SAVE C50 BLOCK REPEAT REGISTERS
	 SACL     *+
	 LAMM     PASR
	 SACL     *+
	 LAMM     PAER
	 SACL     *+
	 .endif   ; .tms32050

	 SAR      AR0,*+         ; SAVE AUXILIARY REGISTERS
	 SAR      AR2,*+
	 SAR      AR3,*+
	 SAR      AR4,*+
	 SAR      AR5,*+
	 SAR      AR6,*+
	 SAR      AR7,*+

     POPD     *              ; POP RETURN ADDRESS OF i$$save
	 LAC      *              ; PUT RETURN ADDRESS IN ACCUMULATOR

     RPTK     6              ; SAVE REST OF HARDWARE STACK
	 POPD     *+     
	        

; Added by Ding Curie
;
	.ref 	_OSRunning, _OSIntNesting, _OSTCBCur
	
	SACL 	*				; Temporary save lower 16 bits of ACC
							; the RETURN ADDRESS OF I$$SAVE     

; Inline call OSIntEnter()
;>>>> 	    if (OSRunning == TRUE) {
	LDPK	_OSRunning
	LAC		_OSRunning
	SUBK	1
	BNZ		L_INTUNAWARE
;>>>> 	        if (OSIntNesting < 255) {
	ZALS	_OSIntNesting
	SUBK	255
	BGEZ	L_INTUNAWARE
;>>>> 	            OSIntNesting++;		/* Increment ISR nesting level */
	LAC		_OSIntNesting
	ADDK	1
	SACL	_OSIntNesting
L_INTUNAWARE:
; End of inline call to OSIntEnter()

	LDPK	_OSIntNesting	; if(OSIntNesting == 1) {
	LAC		_OSIntNesting	;
	SUBK	1				;
	BNZ		L_INTNESTING	;
	
	LDPK 	_OSTCBCur		;     OSTCBCur->OSTCBStkPtr = SP;
	LAR 	AR3, _OSTCBCur	; 
	MAR		*, AR3
	SAR		AR1, *, AR1		;
L_INTNESTING:				; }
	
	LAC		*				; PUT RETURN ADDRESS OF I$$SAVE IN ACC 
;
; End of addition       


	 BACC                    ; RETURN TO INTERRUPT HANDLER

****************************************************************************
* FUNCTION DEF : I$$REST
*                This function is branched to at the end of an interrupt
*                handler to restore the environment of the interrupted
*                code.  This function performs the return from interrupt.
*                In order to ensure correct restoration of the T register,
*                this function assumes that interrupts are disabled during
*                its execution.
****************************************************************************
I$$REST:  
; Added by Ding Curie
;
	.ref 	_OSIntExit   
	
	CALL	_OSIntExit		; OSIntExit();
;
; End of addition	 

	 MAR     *-              ; POINT TO TOP ELEMENT ON STACK 

	 RPTK    6               ; RESTORE TOP 6 ELEMENTS OF STACK
	 PSHD    *-              

	 LAR     AR7,*-          ; RESTORE ALL AUX REGISTERS EXCEPT AR1
	 LAR     AR6,*-
	 LAR     AR5,*-
	 LAR     AR4,*-
	 LAR     AR3,*-
	 LAR     AR2,*-
	 LAR     AR0,*-          

     .if     .tms32050
	 LAC     *-		 ; RESTORE C50 BLOCK REPEAT REGISTERS
	 SAMM	 PAER
	 LAC     *-
	 SAMM    PASR
	 LAC     *-
	 SAMM    BRCR
	 .endif  ; .tms32050

	 .if	 NO_SHADOW

     .if     .tms32050
	 ZALS	 *-		 ; RESTORE ACCB
	 ADDH	 *-
	 SACB
	 .endif  ; .tms32050

     MAR     *-              ; SKIP T REGISTER (FOR NOW)
	 LT      *+              
	 MPYK    1               ; RESTORE LOW PRODUCT REGISTER

	 LT      *-              ; RESTORE T REGISTER
	 MAR     *-              ; SKIP LOW PRODUCT REGISTER VALUE

	 LPH     *-              ; RESTORE HIGH PRODUCT REGISTER

	 .if	 .tms32050
	 LAC	 *-		 ; RESTORE TREG1
	 SAMM	 TREG1
	 LAC     *-		 ; RESTORE PMST
	 SAMM    PMST
	 .endif	 ; .tms32050

	 ZALS    *-              ; RESTORE ACCUMULATOR
	 ADDH    *-

	 LST     *-              ; RESTORE STATUS REGISTERS
	 LST1    *-		 ; OLD ARP IS RESTORED *NOW*

	 EINT                    ; RESTORE INTERRUPTS
	 RET                     ; RETURN TO INTERRUPTED CODE

	 .else  ; SHADOW

	 RETE			 ; RESTORE SHADOW REGS AND INTERRUPTS, RETURN

	 .endif	; NO_SHADOW

	 .end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -