@ -8,6 +8,7 @@
# include < a s m - o f f s e t s . h >
# include < c o n f i g . h >
# include < a s m / a s m . h >
# include < a s m / r e g d e f . h >
# include < a s m / m i p s r e g s . h >
@ -98,8 +99,8 @@ _start:
reset :
/* Clear watch registers */
mtc 0 z e r o , C P 0 _ W A T C H L O
mtc 0 z e r o , C P 0 _ W A T C H H I
MTC 0 z e r o , C P 0 _ W A T C H L O
MTC 0 z e r o , C P 0 _ W A T C H H I
/* WP(Watch Pending), SW0/1 should be cleared */
mtc0 z e r o , C P 0 _ C A U S E
@ -116,21 +117,26 @@ reset:
mtc0 t 0 , C P 0 _ C O N F I G
# endif
/* Initialize $gp */
/ *
* Initialize $ g p , f o r c e p o i n t e r s i z e d a l i g n m e n t o f b a l i n s t r u c t i o n t o
* forbid t h e c o m p i l e r t o p u t n o p ' s b e t w e e n b a l a n d _ g p . T h i s i s
* required t o k e e p _ g p a n d r a a l i g n e d t o 8 b y t e .
* /
.align PTRLOG
bal 1 f
nop
.word _gp
PTR _ g p
1 :
lw g p , 0 ( r a )
PTR_ L g p , 0 ( r a )
# ifndef C O N F I G _ S K I P _ L O W L E V E L _ I N I T
/* Initialize any external memory */
la t 9 , l o w l e v e l _ i n i t
PTR_ L A t 9 , l o w l e v e l _ i n i t
jalr t 9
nop
/* Initialize caches... */
la t 9 , m i p s _ c a c h e _ r e s e t
PTR_ L A t 9 , m i p s _ c a c h e _ r e s e t
jalr t 9
nop
@ -140,15 +146,15 @@ reset:
# endif
/* Set up temporary stack */
li t 0 , - 1 6
li t 1 , C O N F I G _ S Y S _ I N I T _ S P _ A D D R
PTR_ L I t 0 , - 1 6
PTR_ L I t 1 , C O N F I G _ S Y S _ I N I T _ S P _ A D D R
and s p , t 1 , t 0 # f o r c e 16 b y t e a l i g n m e n t
sub s p , s p , G D _ S I Z E # r e s e r v e s p a c e f o r g d
PTR_ S U B s p , s p , G D _ S I Z E # r e s e r v e s p a c e f o r g d
and s p , s p , t 0 # f o r c e 16 b y t e a l i g n m e n t
move k 0 , s p # s a v e g d p o i n t e r
# ifdef C O N F I G _ S Y S _ M A L L O C _ F _ L E N
li t 2 , C O N F I G _ S Y S _ M A L L O C _ F _ L E N
sub s p , s p , t 2 # r e s e r v e s p a c e f o r e a r l y m a l l o c
PTR_ L I t 2 , C O N F I G _ S Y S _ M A L L O C _ F _ L E N
PTR_ S U B s p , s p , t 2 # r e s e r v e s p a c e f o r e a r l y m a l l o c
and s p , s p , t 0 # f o r c e 16 b y t e a l i g n m e n t
# endif
move f p , s p
@ -158,14 +164,14 @@ reset:
1 :
sw z e r o , 0 ( t 0 )
blt t 0 , t 1 , 1 b
addi t 0 , 4
PTR_ A D D I t 0 , 4
# ifdef C O N F I G _ S Y S _ M A L L O C _ F _ L E N
addu t 0 , k 0 , G D _ M A L L O C _ B A S E # g d - > m a l l o c _ b a s e o f f s e t
PTR_ A D D U t 0 , k 0 , G D _ M A L L O C _ B A S E # g d - > m a l l o c _ b a s e o f f s e t
sw s p , 0 ( t 0 )
# endif
la t 9 , b o a r d _ i n i t _ f
PTR_ L A t 9 , b o a r d _ i n i t _ f
jr t 9
move r a , z e r o
@ -188,14 +194,14 @@ relocate_code:
move s0 , a1 # s a v e g d i n s 0
move s2 , a2 # s a v e d e s t i n a t i o n a d d r e s s i n s 2
li t 0 , C O N F I G _ S Y S _ M O N I T O R _ B A S E
sub s1 , s2 , t 0 # s 1 < - - r e l o c a t i o n o f f s e t
PTR_ L I t 0 , C O N F I G _ S Y S _ M O N I T O R _ B A S E
PTR_ S U B s1 , s2 , t 0 # s 1 < - - r e l o c a t i o n o f f s e t
la t 3 , i n _ r a m
lw t 2 , - 1 2 ( t 3 ) # t 2 < - - _ _ i m a g e _ c o p y _ e n d
PTR_ L A t 3 , i n _ r a m
PTR_ L t 2 , - ( 3 * P T R S I Z E ) ( t 3 ) # t 2 < - - _ _ i m a g e _ c o p y _ e n d
move t 1 , a2
add g p , s1 # a d j u s t g p
PTR_ A D D g p , s1 # a d j u s t g p
/ *
* t0 = s o u r c e a d d r e s s
@ -205,26 +211,26 @@ relocate_code:
1 :
lw t 3 , 0 ( t 0 )
sw t 3 , 0 ( t 1 )
addu t 0 , 4
PTR_ A D D U t 0 , 4
blt t 0 , t 2 , 1 b
addu t 1 , 4
PTR_ A D D U t 1 , 4
/* If caches were enabled, we would have to flush them here. */
sub a1 , t 1 , s2 # a 1 < - - s i z e
la t 9 , f l u s h _ c a c h e
PTR_ S U B a1 , t 1 , s2 # a 1 < - - s i z e
PTR_ L A t 9 , f l u s h _ c a c h e
jalr t 9
move a0 , s2 # a 0 < - - d e s t i n a t i o n a d d r e s s
/* Jump to where we've relocated ourselves */
addi t 0 , s2 , i n _ r a m - _ s t a r t
PTR_ A D D I t 0 , s2 , i n _ r a m - _ s t a r t
jr t 0
nop
.word __rel_dyn_end
.word __rel_dyn_start
.word __image_copy_end
.word _GLOBAL_OFFSET_TABLE_
.word num_got_entries
PTR _ _ r e l _ d y n _ e n d
PTR _ _ r e l _ d y n _ s t a r t
PTR _ _ i m a g e _ c o p y _ e n d
PTR _ G L O B A L _ O F F S E T _ T A B L E _
PTR n u m _ g o t _ e n t r i e s
in_ram :
/ *
@ -233,46 +239,46 @@ in_ram:
* GOT[ 0 ] i s r e s e r v e d . G O T [ 1 ] i s a l s o r e s e r v e d f o r t h e d y n a m i c o b j e c t
* generated b y G N U l d . S k i p t h e s e r e s e r v e d e n t r i e s f r o m r e l o c a t i o n .
* /
lw t 3 , - 4 ( t 0 ) # t 3 < - - n u m _ g o t _ e n t r i e s
lw t 8 , - 8 ( t 0 ) # t 8 < - - _ G L O B A L _ O F F S E T _ T A B L E _
add t 8 , s1 # t 8 n o w h o l d s r e l o c a t e d _ G _ O _ T _
addi t 8 , t 8 , 8 # s k i p p i n g f i r s t t w o e n t r i e s
li t 2 , 2
PTR_ L t 3 , - ( 1 * P T R S I Z E ) ( t 0 ) # t 3 < - - n u m _ g o t _ e n t r i e s
PTR_ L t 8 , - ( 2 * P T R S I Z E ) ( t 0 ) # t 8 < - - _ G L O B A L _ O F F S E T _ T A B L E _
PTR_ A D D t 8 , s1 # t 8 n o w h o l d s r e l o c a t e d _ G _ O _ T _
PTR_ A D D I t 8 , t 8 , 2 * P T R S I Z E # s k i p p i n g f i r s t t w o e n t r i e s
PTR_ L I t 2 , 2
1 :
lw t 1 , 0 ( t 8 )
PTR_ L t 1 , 0 ( t 8 )
beqz t 1 , 2 f
add t 1 , s1
sw t 1 , 0 ( t 8 )
PTR_ A D D t 1 , s1
PTR_ S t 1 , 0 ( t 8 )
2 :
addi t 2 , 1
PTR_ A D D I t 2 , 1
blt t 2 , t 3 , 1 b
addi t 8 , 4
PTR_ A D D I t 8 , P T R S I Z E
/* Update dynamic relocations */
lw t 1 , - 1 6 ( t 0 ) # t 1 < - - _ _ r e l _ d y n _ s t a r t
lw t 2 , - 2 0 ( t 0 ) # t 2 < - - _ _ r e l _ d y n _ e n d
PTR_ L t 1 , - ( 4 * P T R S I Z E ) ( t 0 ) # t 1 < - - _ _ r e l _ d y n _ s t a r t
PTR_ L t 2 , - ( 5 * P T R S I Z E ) ( t 0 ) # t 2 < - - _ _ r e l _ d y n _ e n d
b 2 f # s k i p f i r s t r e s e r v e d e n t r y
addi t 1 , 8
PTR_ A D D I t 1 , 2 * P T R S I Z E
1 :
lw t 8 , - 4 ( t 1 ) # t 8 < - - r e l o c a t i o n i n f o
li t 3 , 3
PTR_ L I t 3 , 3
bne t 8 , t 3 , 2 f # s k i p n o n R _ M I P S _ R E L 32 e n t r i e s
nop
lw t 3 , - 8 ( t 1 ) # t 3 < - - l o c a t i o n t o f i x u p i n F L A S H
PTR_ L t 3 , - ( 2 * P T R S I Z E ) ( t 1 ) # t 3 < - - l o c a t i o n t o f i x u p i n F L A S H
lw t 8 , 0 ( t 3 ) # t 8 < - - o r i g i n a l p o i n t e r
add t 8 , s1 # t 8 < - - a d j u s t e d p o i n t e r
PTR_ L t 8 , 0 ( t 3 ) # t 8 < - - o r i g i n a l p o i n t e r
PTR_ A D D t 8 , s1 # t 8 < - - a d j u s t e d p o i n t e r
add t 3 , s1 # t 3 < - - l o c a t i o n t o f i x u p i n R A M
sw t 8 , 0 ( t 3 )
PTR_ A D D t 3 , s1 # t 3 < - - l o c a t i o n t o f i x u p i n R A M
PTR_ S t 8 , 0 ( t 3 )
2 :
blt t 1 , t 2 , 1 b
addi t 1 , 8 # e a c h r e l . d y n e n t r y i s 8 b y t e s
PTR_ A D D I t 1 , 2 * P T R S I Z E # e a c h r e l . d y n e n t r y i s 2 * P T R S I Z E b y t e s
/ *
* Clear B S S
@ -280,17 +286,17 @@ in_ram:
* GOT i s n o w r e l o c a t e d . T h u s _ _ b s s _ s t a r t a n d _ _ b s s _ e n d c a n b e
* accessed d i r e c t l y v i a $ g p .
* /
la t 1 , _ _ b s s _ s t a r t # t 1 < - - _ _ b s s _ s t a r t
la t 2 , _ _ b s s _ e n d # t 2 < - - _ _ b s s _ e n d
PTR_ L A t 1 , _ _ b s s _ s t a r t # t 1 < - - _ _ b s s _ s t a r t
PTR_ L A t 2 , _ _ b s s _ e n d # t 2 < - - _ _ b s s _ e n d
1 :
sw z e r o , 0 ( t 1 )
PTR_ S z e r o , 0 ( t 1 )
blt t 1 , t 2 , 1 b
addi t 1 , 4
PTR_ A D D I t 1 , P T R S I Z E
move a0 , s0 # a 0 < - - g d
move a1 , s2
la t 9 , b o a r d _ i n i t _ r
PTR_ L A t 9 , b o a r d _ i n i t _ r
jr t 9
move r a , z e r o