在线时间1 小时
UID258195
注册时间2011-1-6
NXP金币0
该用户从未签到
注册会员

- 积分
- 51
- 最后登录
- 1970-1-1
|
在做FLASH BOOTLOADER时,当BOOTLOADER在调用位于RAM区的FLASHDRIVER时出错,通过一步一步调试时发现,在通过rtshc12.c的void __far _FCALL(void)函数时程序跑飞,在rtshc12.c文件中对于void __far _FCALL(void)函数是这样描述的:
/*----------------- FAR FUNCTION PTR Call ------------------------------------------------
Parameters:
- the normal function parameters according
- on the stack: address of function to be called
Result :
- Function is called with unchanged D & X register
- Y is changed
- the function address is removed from the stack before the function call
Stack layout (in):
5, SP : page of function to be called
3-4, SP : offset of function to be called
1-2, SP : offset of return address
0, SP : page of return address
function ptr to be called (3 bytes)
return address caller (3 bytes)
Idea:
exchanging function ptr and return address
because function ptr and return address have the page at different offset a
complicated transformation must be done
before after
0,SP page ret A page fkt F
1,SP high ret B high fkt D
2,SP low ret C low fkt E
3,SP high fkt D page ret A
4,SP low fkt E high ret B
5,SP page fkt F low ret C
*/
#pragma NO_FRAME
#pragma NO_ENTRY
#pragma NO_EXIT
#ifdef __cplusplus
extern "C"
#endif
void __far _FCALL(void) {
__asm {
LDY 1, SP ; A B C D E F Y = B C ; 2 bytes
MOVW 3, SP, 1, SP ; A D E D E F Y = B C ; 4 bytes
MOVB 0, SP, 3, SP ; A D E A E F Y = B C ; 4 bytes
MOVB 5, SP, 0, SP ; F D E A E F Y = B C ; 4 bytes
STY 4, SP ; F D E D B C Y = B C ; 2 bytes
; F D E A B C ;16 bytes
RTC ; call function pointer
}
}
在进入该函数的时候,编译器的汇编窗口显示的指针地址是指向映射到的地址的,但是在运行该函数之后程序就跑飞了,要么是系统重启,或者是提示ILLEGE_BP,
求个人帮忙分析下是什么原因导致出错的,谢谢!
|
|