@ -75,12 +75,15 @@ _fiq: .word fiq
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* /
.globl _TEXT_BASE
_TEXT_BASE :
.word TEXT_BASE
# if d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C )
.globl _armboot_start
_armboot_start :
.word _start
# endif
/ *
* These a r e d e f i n e d i n t h e b o a r d - s p e c i f i c l i n k e r s c r i p t .
@ -105,6 +108,163 @@ FIQ_STACK_START:
.word 0x0badc0de
# endif
# if ! d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C )
/* IRQ stack memory (calculated at run-time) + 8 bytes */
.globl IRQ_STACK_START_IN
IRQ_STACK_START_IN :
.word 0x0badc0de
.globl _datarel_start
_datarel_start :
.word __datarel_start
.globl _datarelrolocal_start
_datarelrolocal_start :
.word __datarelrolocal_start
.globl _datarellocal_start
_datarellocal_start :
.word __datarellocal_start
.globl _datarelro_start
_datarelro_start :
.word __datarelro_start
.globl _got_start
_got_start :
.word __got_start
.globl _got_end
_got_end :
.word __got_end
/ *
* the a c t u a l r e s e t c o d e
* /
reset :
/ *
* set t h e c p u t o S V C 3 2 m o d e
* /
mrs r0 ,c p s r
bic r0 ,r0 ,#0x1f
orr r0 ,r0 ,#0xd3
msr c p s r ,r0
/ *
* we d o s y s - c r i t i c a l i n i t s o n l y a t r e b o o t ,
* not w h e n b o o t i n g f r o m r a m !
* /
# ifndef C O N F I G _ S K I P _ L O W L E V E L _ I N I T
bl c p u _ i n i t _ c r i t
# endif
# ifdef C O N F I G _ L P C 2 2 9 2
bl l o w l e v e l _ i n i t
# endif
/* Set stackpointer in internal RAM to call board_init_f */
call_board_init_f :
ldr s p , = ( C O N F I G _ S Y S _ I N I T _ S P _ A D D R )
ldr r0 ,=0x00000000
bl b o a r d _ i n i t _ f
/*------------------------------------------------------------------------------*/
/ *
* void r e l o c a t e _ c o d e ( a d d r _ s p , g d , a d d r _ m o n i )
*
* This " f u n c t i o n " d o e s n o t r e t u r n , i n s t e a d i t c o n t i n u e s i n R A M
* after r e l o c a t i n g t h e m o n i t o r c o d e .
*
* /
.globl relocate_code
relocate_code :
mov r4 , r0 / * s a v e a d d r _ s p * /
mov r5 , r1 / * s a v e a d d r o f g d * /
mov r6 , r2 / * s a v e a d d r o f d e s t i n a t i o n * /
mov r7 , r2 / * s a v e a d d r o f d e s t i n a t i o n * /
/* Set up the stack */
stack_setup :
mov s p , r4
adr r0 , _ s t a r t
ldr r2 , _ T E X T _ B A S E
ldr r3 , _ b s s _ s t a r t
sub r2 , r3 , r2 / * r2 < - s i z e o f a r m b o o t * /
add r2 , r0 , r2 / * r2 < - s o u r c e e n d a d d r e s s * /
cmp r0 , r6
beq c l e a r _ b s s
# ifndef C O N F I G _ S K I P _ R E L O C A T E _ U B O O T
copy_loop :
ldmia r0 ! , { r9 - r10 } / * c o p y f r o m s o u r c e a d d r e s s [ r0 ] * /
stmia r6 ! , { r9 - r10 } / * c o p y t o t a r g e t a d d r e s s [ r1 ] * /
cmp r0 , r2 / * u n t i l s o u r c e e n d a d d r e e e [ r2 ] * /
ble c o p y _ l o o p
# ifndef C O N F I G _ P R E L O A D E R
/* fix got entries */
ldr r1 , _ T E X T _ B A S E / * T e x t b a s e * /
mov r0 , r7 / * r e l o c a d d r * /
ldr r2 , _ g o t _ s t a r t / * a d d r i n F l a s h * /
ldr r3 , _ g o t _ e n d / * a d d r i n F l a s h * /
sub r3 , r3 , r1
add r3 , r3 , r0
sub r2 , r2 , r1
add r2 , r2 , r0
fixloop :
ldr r4 , [ r2 ]
sub r4 , r4 , r1
add r4 , r4 , r0
str r4 , [ r2 ]
add r2 , r2 , #4
cmp r2 , r3
bne f i x l o o p
# endif
# endif / * #i f n d e f C O N F I G _ S K I P _ R E L O C A T E _ U B O O T * /
clear_bss :
# ifndef C O N F I G _ P R E L O A D E R
ldr r0 , _ b s s _ s t a r t
ldr r1 , _ b s s _ e n d
ldr r3 , _ T E X T _ B A S E / * T e x t b a s e * /
mov r4 , r7 / * r e l o c a d d r * /
sub r0 , r0 , r3
add r0 , r0 , r4
sub r1 , r1 , r3
add r1 , r1 , r4
mov r2 , #0x00000000 / * c l e a r * /
clbss_l : str r2 , [ r0 ] / * c l e a r l o o p . . . * /
add r0 , r0 , #4
cmp r0 , r1
bne c l b s s _ l
bl c o l o u r e d _ L E D _ i n i t
bl r e d _ L E D _ o n
# endif
/ *
* We a r e d o n e . D o n o t r e t u r n , i n s t e a d b r a n c h t o s e c o n d p a r t o f b o a r d
* initialization, n o w r u n n i n g f r o m R A M .
* /
ldr r0 , _ T E X T _ B A S E
ldr r2 , _ b o a r d _ i n i t _ r
sub r2 , r2 , r0
add r2 , r2 , r7 / * p o s i t i o n f r o m b o a r d _ i n i t _ r i n R A M * /
/* setup parameters for board_init_r */
mov r0 , r5 / * g d _ t * /
mov r1 , r7 / * d e s t _ a d d r * /
/* jump to it ... */
mov l r , r2
mov p c , l r
_board_init_r : .word b o a r d _ i n i t _ r
# else / * #i f ! d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C ) * /
/ *
* the a c t u a l r e s e t c o d e
@ -188,6 +348,8 @@ clbss_l:str r2, [r0] /* clear loop... */
_start_armboot : .word s t a r t _ a r m b o o t
# endif / * #i f ! d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C ) * /
/ *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
@ -444,9 +606,13 @@ lock_loop:
stmia s p , { r0 - r12 } @ Calling r0-r12
add r8 , s p , #S _ P C
# if d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C )
ldr r2 , _ a r m b o o t _ s t a r t
sub r2 , r2 , #( C O N F I G _ S T A C K S I Z E + C O N F I G _ S Y S _ M A L L O C _ L E N )
sub r2 , r2 , #( C O N F I G _ S Y S _ G B L _ D A T A _ S I Z E + 8 ) @ set base 2 words into abort stack
# else
ldr r2 , I R Q _ S T A C K _ S T A R T _ I N
# endif
ldmia r2 , { r2 - r4 } @ get pc, cpsr, old_r0
add r0 , s p , #S _ F R A M E _ S I Z E @ r e s t o r e s p _ S V C
@ -477,9 +643,13 @@ lock_loop:
.endm
.macro get_bad_stack
# if d e f i n e d ( C O N F I G _ S Y S _ A R M _ W I T H O U T _ R E L O C )
ldr r13 , _ a r m b o o t _ s t a r t @ setup our mode stack
sub r13 , r13 , #( C O N F I G _ S T A C K S I Z E + C O N F I G _ S Y S _ M A L L O C _ L E N )
sub r13 , r13 , #( C O N F I G _ S Y S _ G B L _ D A T A _ S I Z E + 8 ) @ reserved a couple spots in abort stack
# else
ldr r13 , I R Q _ S T A C K _ S T A R T _ I N @ setup our mode stack
# endif
str l r , [ r13 ] @ save caller lr / spsr
mrs l r , s p s r