📄 chipcon_banked_code_support.s51
字号:
/******************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** ++ *** *
* *** + + *** CHIPCON *
* *** + *
* *** + + *** *
* *** ++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************
Filename: chipcon_banked_code_support.s51
Target: cc2430
Author: KJA
Revised: 30/5-2007
Revision: 1.2
Description:
Functions to make banked CALL and RET.
The routines will store the bank number on the stack (which is read
back by the tools for return address) and then load MEMCTL or FMAPE
with the new bits. The "same" thing is done on return.
This file can be used with CC2430/31 Rev. C (and above) by adding REV_C to
the Assembler -> Preprocessor -> Defined Symbols settings. If REV_C is not
added, the BCALL and BRET will use MEMCTR register instead of the new
FMAP register.
******************************************************************************
******************************************************************************
** **
** IMPORTANT: **
** Add $TOOLKIT_DIR$\SRC\LIB\ to the assembler include path. **
** **
** Under General Options set Code model to Banked and under tab "Code Bank" **
** set "Register address" to (only valid if code model == banked): **
** Rev A and B: 0xC7 **
** Rev C and above: 0x9F **
** **
******************************************************************************
******************************************************************************
The register holding current code bank:
?CBANK
Should be defined to IAR XLINK Linker with:
-D?CBANK=xx
******************************************************************************/
MODULE ?BANKED_CODE_SUPPORT
#include "iar_common.h"
EXTERN ?CBANK
EXTERN ?RESET_CODE_BANK
REQUIRE ?RESET_CODE_BANK
RSEG CSTART
;-----------------------------------------------------------------------------
;
; Function: ?BCALL
;
; Description: Saves the caller bank on stack, Switches to bank defined
; by A register and jumps to the banked function A:DPTR.
;
; Register input:
; DPTR: 16-bit function address
; A: 8-bit page address
;
; Stack:
;
; +--------+
; | ?CBANK | <-- SP end
; + - - - -+
; | retH | <-- SP begin
; + - - - -+
; | retL |
; + - - - -+
; CFA --> | xxxxxx |
; +--------+
;
; 16-bit return address
;
; Register output:
; DPTR: 16-bit function-address
; A = 0
;
; Stack usage: 1
;-----------------------------------------------------------------------------
PUBLIC ?BCALL
cfi BLOCK ?BCALL USING cfi_common
cfi NOFUNCTION
cfi A undefined
cfi CFA_MACHINE MACHINE_SP - 2
?BCALL:
#ifdef REV_C
PUSH ?CBANK
cfi CFA_MACHINE MACHINE_SP - 3
#endif
#ifndef REV_C
SWAP A
MOV B, A
MOV A, ?CBANK ; read current MEMCTR
ANL A, #0x30 ; mask bank bits
SWAP A
PUSH A ; store return bank (bank number only)
cfi CFA_MACHINE MACHINE_SP - 3
MOV A, ?CBANK ; read current MEMCTR
ANL A, #0xCF ; mask bank bits
ORL A, B ; add new bank number to MEMCTR
#endif
MOV ?CBANK, A
CLR A
JMP @A+DPTR
;-----------------------------------------------------------------------------
;
; Function: ?BRET
;
; Description: Return from banked function.
; Leaves current function, Switched bank and returns to
; function that called ?BCALL.
;
; NOTE: This function will be jumped to.
;
; Register input:
; None
;
; Stack input:
;
; +------------+ <-- SP
; | RET bank |
; + - - - - - -+
; | RET High |
; + - - - - - -+
; | RET Low |
; +------------+
;
; 24-bit return address
;
; Register output:
; DPTR: 16-bit function-address
; A = 0
;
; Stack usage: 3
; Stack: 16-bit return address
;-----------------------------------------------------------------------------
PUBLIC ?BRET
?BRET:
cfi CFA_MACHINE MACHINE_SP - 3
#ifdef REV_C
POP ?CBANK
#endif
#ifndef REV_C
MOV B, ?CBANK ; get current bank
ANL B, #0xCF ; mask bank bits
POP A ; pop bank number
SWAP A
ORL A, B ; add the MEMCTR bits
MOV ?CBANK, A ; set new bank
#endif
cfi CFA_MACHINE MACHINE_SP - 2
RET
cfi ENDBLOCK ?BCALL
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -