;***************************************************************************** ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;终说见到艳阳天了!!!!!!!!!! ; 跳到C语言的main函数处了. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;***************************************************************************** [ :LNOT:THUMBCODE bl Main ;Do not use main() because ...... ;ldr pc, =Main ;hzh b . ]
[ THUMBCODE ;for start-up code for Thumb mode orr lr,pc,#1 bx lr CODE16 bl Main ;Do not use main() because ...... b . CODE32 ]
;function initializing stacks InitStacks ;Do not use DRAM,such as stmfd,ldmfd...... ;SVCstack is initialized before ;Under toolkit ver 2.5, msr cpsr,r1 can be used instead of msr cpsr_cxsf,r1 mrs r0,cpsr bic r0,r0,#MODEMASK orr r1,r0,#UNDEFMODE|NOINT msr cpsr_cxsf,r1 ;UndefMode ldr sp,=UndefStack ; UndefStack=0x33FF_5C00
orr r1,r0,#ABORTMODE|NOINT msr cpsr_cxsf,r1 ;AbortMode ldr sp,=AbortStack ; AbortStack=0x33FF_6000
orr r1,r0,#IRQMODE|NOINT msr cpsr_cxsf,r1 ;IRQMode ldr sp,=IRQStack ; IRQStack=0x33FF_7000
orr r1,r0,#FIQMODE|NOINT msr cpsr_cxsf,r1 ;FIQMode ldr sp,=FIQStack ; FIQStack=0x33FF_8000
bic r0,r0,#MODEMASK|NOINT orr r1,r0,#SVCMODE msr cpsr_cxsf,r1 ;SVCMode ldr sp,=SVCStack ; SVCStack=0x33FF_5800
;USER mode has not be initialized.
mov pc,lr ;The LR register will not be valid if the current mode is not SVC mode.
;=========================================================== ReadNandID mov r7,#NFCONF ldr r0,[r7,#4] ;NFChipEn(); bic r0,r0,#2 str r0,[r7,#4] mov r0,#0x90 ;WrNFCmd(RdIDCMD); strb r0,[r7,#8] mov r4,#0 ;WrNFAddr(0); strb r4,[r7,#0xc] 1 ;while(NFIsBusy()); ldr r0,[r7,#0x20] tst r0,#1 beq %B1 ldrb r0,[r7,#0x10] ;id = RdNFDat()<8; mov r0,r0,lsl #8 ldrb r1,[r7,#0x10] ;id |= RdNFDat(); orr r5,r1,r0 ldr r0,[r7,#4] ;NFChipDs(); orr r0,r0,#2 str r0,[r7,#4] mov pc,lr
ReadNandStatus mov r7,#NFCONF ldr r0,[r7,#4] ;NFChipEn(); bic r0,r0,#2 str r0,[r7,#4] mov r0,#0x70 ;WrNFCmd(QUERYCMD); strb r0,[r7,#8] ldrb r1,[r7,#0x10] ;r1 = RdNFDat(); ldr r0,[r7,#4] ;NFChipDs(); orr r0,r0,#2 str r0,[r7,#4] mov pc,lr
WaitNandBusy mov r0,#0x70 ;WrNFCmd(QUERYCMD); mov r1,#NFCONF strb r0,[r1,#8] 1 ;while(!(RdNFDat()&0x40)); ldrb r0,[r1,#0x10] tst r0,#0x40 beq %B1 mov r0,#0 ;WrNFCmd(READCMD0); strb r0,[r1,#8] mov pc,lr
CheckBadBlk mov r7, lr mov r5, #NFCONF
bic r0,r0,#0x1f ;addr &= ~0x1f; ldr r1,[r5,#4] ;NFChipEn() bic r1,r1,#2 str r1,[r5,#4]
mov r1,#0x50 ;WrNFCmd(READCMD2) strb r1,[r5,#8] mov r1, #5;6 ;6->5 strb r1,[r5,#0xc] ;WrNFAddr(5);(6) 6->5 strb r0,[r5,#0xc] ;WrNFAddr(addr) mov r1,r0,lsr #8 ;WrNFAddr(addr>>8) strb r1,[r5,#0xc] cmp r6,#0 ;if(NandAddr) movne r0,r0,lsr #16 ;WrNFAddr(addr>>16) strneb r0,[r5,#0xc]
; bl WaitNandBusy ;WaitNFBusy() ;do not use WaitNandBusy, after WaitNandBusy will read part A! mov r0, #100 1 subs r0, r0, #1 bne %B1 2 ldr r0, [r5, #0x20] tst r0, #1 beq %B2
ldrb r0, [r5,#0x10] ;RdNFDat() sub r0, r0, #0xff
mov r1,#0 ;WrNFCmd(READCMD0) strb r1,[r5,#8]
ldr r1,[r5,#4] ;NFChipDs() orr r1,r1,#2 str r1,[r5,#4]
mov pc, r7
ReadNandPage mov r7,lr mov r4,r1 mov r5,#NFCONF
ldr r1,[r5,#4] ;NFChipEn() bic r1,r1,#2 str r1,[r5,#4]
mov r1,#0 ;WrNFCmd(READCMD0) strb r1,[r5,#8] strb r1,[r5,#0xc] ;WrNFAddr(0) strb r0,[r5,#0xc] ;WrNFAddr(addr) mov r1,r0,lsr #8 ;WrNFAddr(addr>>8) strb r1,[r5,#0xc] cmp r6,#0 ;if(NandAddr) movne r0,r0,lsr #16 ;WrNFAddr(addr>>16) strneb r0,[r5,#0xc]
ldr r0,[r5,#4] ;InitEcc() orr r0,r0,#0x10 str r0,[r5,#4]
bl WaitNandBusy ;WaitNFBusy()
mov r0,#0 ;for(i=0; i<512; i++) 1 ldrb r1,[r5,#0x10] ;buf[i] = RdNFDat() strb r1,[r4,r0] add r0,r0,#1 bic r0,r0,#0x10000 cmp r0,#0x200 bcc %B1
ldr r0,[r5,#4] ;NFChipDs() orr r0,r0,#2 str r0,[r5,#4]
mov pc,r7
;-------------------- |