Some questions of Bootloader about jump and _startup functions(fixed)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Some questions of Bootloader about jump and _startup functions(fixed)

434 Views
wangjiajie
Contributor III

I have two project ,one is BOOT,the other is APP.They are both created with Processor Expert,and Have '_EntryPoint' '_Startup' function 。

__EXTERN_C void _Startup(void) {
__asm {
LD S, #__SEG_END_SSTACK-1 /* initialize SP */
}
DoZeroOut();
DoCopyDown();

main();
}

In APP , i use this code to stroe the _EntryPoint,

typedef void (*tFunc)(void);
typedef tFunc* ptFunc;
void CallfunFromAddr(dword funaddress);

#pragma CODE_SEG __NEAR_SEG NON_BANKED
extern void _EntryPoint(void);
#pragma CODE_SEG DEFAULT
const tFunc rst_vec @0xFFD000 = _EntryPoint;

and i use this code to call APP from the BOOT project after successfully download and flash the memory ,

void CallfunFromAddr(dword funaddress)
{
tFunc realpfun;
realpfun = (tFunc) (*((tFunc*) funaddress));
(*realpfun)();
}

it is ok to jump to APP,but there is some problem testing the APP,Under certain conditions,there is a death loop while execute these assembly code:

ff4590: 0860 LEA X,(0,S)
ff4592: A4E010 LD D0,(16,S)
ff4595: 9E46 TFR D0,D6
ff4597: A58E LD D1,(D6,X)
ff4599: A46C LD D0,(12,S)
ff459b: 1B8CBD EOR D0,D1
ff459e: C46C ST D0,(12,S)
ff45a0: A46D LD D0,(13,S)
ff45a2: F4E010 CMP D0,(16,S)
ff45a5: 226B BHI *-21 0xFF4590 (0xff4590)
the function of the code is to decide to reset by watchdog:
445: if((cantype == DATA_FRAME)&&(canformat == STANDARD_FORMAT)&&(canlength == 8U)&&(candata[0] == 0x08))
00FF4571 A46F LD D0,(15,S)
00FF4573 0B048065 TBNE D0,*+101 ;abs = 0xFF45D8
00FF4577 A46E LD D0,(14,S)
00FF4579 0B04805F TBNE D0,*+95 ;abs = 0xFF45D8
00FF457D A478 LD D0,#8
00FF457F F46D CMP D0,(13,S)
00FF4581 268057 BNE *+87 ;abs = 0xFF45D8
00FF4584 A478 LD D0,#8
00FF4586 F460 CMP D0,(0,S)
00FF4588 268050 BNE *+80 ;abs = 0xFF45D8
447: for(i = 0U; i < canlength; )
00FF458B BCE010 CLR.B (16,S)
00FF458E 2012 BRA *+18 ;abs = 0xFF45A0
448: { copreset_dat ^= candata[i]; }
00FF4590 0860 LEA X,(0,S)
00FF4592 A4E010 LD D0,(16,S)
00FF4595 9E46 TFR D0,D6
00FF4597 A58E LD D1,(D6,X)
00FF4599 A46C LD D0,(12,S)
00FF459B 1B8CBD EOR D0,D1
00FF459E C46C ST D0,(12,S)
447: for(i = 0U; i < canlength; )
00FF45A0 A46D LD D0,(13,S)
00FF45A2 F4E010 CMP D0,(16,S)
00FF45A5 226B BHI *-21 ;abs = 0xFF4590
450: if(copreset_dat == 0U)
00FF45A7 A46C LD D0,(12,S)
00FF45A9 0B042F TBNE D0,*+47 ;abs = 0xFF45D8
451: { CPMUARMCOP = 0x00U; CPMUARMCOP = 0x00U; }
00FF45AC BC06CF CLR.B 1743
00FF45AF BC06CF CLR.B 1743

i did some registers reset before jump to APP,but did not clear the _startup function in APP ,in the total codes,the _startup functions has run twice in BOOT and APP.

I don't know the actual behavior of each line of _startup,and i guess some problem with cpu registers and stackpointer .

do we have some references to explain the _startup code and the start up flow ?

-------Fiexed-10/14

0 Kudos
0 Replies