2005-04-16 15:20:36 -07:00
/ * The h e a d - f i l e f o r t h e S h a r k
* by A l e x a n d e r S c h u l z
*
* Does t h e f o l l o w i n g :
* - get t h e m e m o r y l a y o u t f r o m f i r m w a r e . T h i s c a n o n l y b e d o n e a s l o n g a s t h e m m u
* is s t i l l o n .
* - switch t h e m m u o f f , s o w e h a v e p h y s i c a l a d d r e s s e s
* - copy t h e k e r n e l t o 0 x08 5 0 8 0 0 0 . T h i s i s d o n e t o h a v e a f i x e d a d d r e s s w h e r e t h e
* C- p a r t s ( m i s c . c ) a r e e x e c u t e d . T h i s a d d r e s s m u s t b e k n o w n a t c o m p i l e - t i m e ,
* but t h e l o a d - a d d r e s s o f t h e k e r n e l d e p e n d s o n h o w m u c h m e m o r y i s i n s t a l l e d .
* - Jump t o t h i s l o c a t i o n .
* - Set r8 w i t h 0 , r7 w i t h t h e a r c h i t e c t u r e I D f o r h e a d . S
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
.section " .start " , " ax"
b _ _ b e g i n n i n g
__ofw_data : .long 0 @ the number of memory blocks
.space 128 @ (startaddr,size) ...
.space 128 @ bootargs
.align
__beginning : mov r4 , r0 @ save the entry to the firmware
mov r0 , #0xC0 @ disable irq and fiq
mov r1 , r0
mrs r3 , c p s r
bic r2 , r3 , r0
eor r2 , r2 , r1
msr c p s r _ c , r2
mov r0 , r4 @ get the Memory layout from firmware
adr r1 , _ _ o f w _ d a t a
add r2 , r1 , #4
mov l r , p c
b o f w _ i n i t
mov r1 , #0
adr r2 , _ _ m m u _ o f f @ calculate physical address
sub r2 , r2 , #0xf0000000 @ openprom maps us at f000 virt, 0e50 phys
adr r0 , _ _ o f w _ d a t a
ldr r0 , [ r0 , #4 ]
add r2 , r2 , r0
add r2 , r2 , #0x00500000
mrc p15 , 0 , r3 , c1 , c0
bic r3 , r3 , #0xC @ Write Buffer and DCache
bic r3 , r3 , #0x1000 @ ICache
mcr p15 , 0 , r3 , c1 , c0 @ disabled
mov r0 , #0
mcr p15 , 0 , r0 , c7 , c7 @ flush I,D caches on v4
mcr p15 , 0 , r0 , c7 , c10 , 4 @ drain write buffer on v4
mcr p15 , 0 , r0 , c8 , c7 @ flush I,D TLBs on v4
bic r3 , r3 , #0x1 @ MMU
mcr p15 , 0 , r3 , c1 , c0 @ disabled
mov p c , r2
2005-07-17 20:12:08 +01:00
__copy_target : .long 0x08507FFC
__copy_end : .long 0x08607FFC
2005-04-16 15:20:36 -07:00
.word _start
.word __bss_start
.align
__temp_stack : .space 128
__mmu_off :
2005-07-17 20:12:08 +01:00
adr r0 , _ _ o f w _ d a t a @ read the 1. entry of the memory map
2005-04-16 15:20:36 -07:00
ldr r0 , [ r0 , #4 ]
orr r0 , r0 , #0x00600000
2005-07-17 20:12:08 +01:00
sub r0 , r0 , #4
2005-04-16 15:20:36 -07:00
ldr r1 , _ _ c o p y _ e n d
ldr r3 , _ _ c o p y _ t a r g e t
/ * r0 = 0 x0 e 6 0 0 0 0 0 ( c u r r e n t e n d o f k e r n e l c o d e )
* r3 = 0 x08 5 0 8 0 0 0 ( w h e r e i t s h o u l d b e g i n )
* r1 = 0 x08 6 0 8 0 0 0 ( e n d o f c o p y i n g a r e a , 1 M B )
* The k e r n e l i s c o m p r e s s e d , s o 1 M B s h o u l d b e e n o u g h .
* copy t h e k e r n e l t o t h e b e g i n n i n g o f p h y s i c a l m e m o r y
* We s t a r t f r o m t h e h i g h e s t a d d r e s s , s o w e c a n c o p y
* from 0 x08 5 0 0 0 0 0 t o 0 x08 5 0 8 0 0 0 i f w e h a v e o n l y 8 M B
* /
2005-07-17 20:12:08 +01:00
/ * As w e g e t m o r e 2 . 6 - k e r n e l s i t g e t s m o r e a n d m o r e
* uncomfortable t o b e b o u n d t o k e r n e l i m a g e s o f 1 M B o n l y .
* So w e a d d a l o o p h e r e , t o b e a b l e t o c o p y s o m e m o r e .
* Alexander S c h u l z 2 0 0 5 - 0 7 - 1 7
* /
mov r4 , #3 @ How many megabytes to copy
__MoveCode : sub r4 , r4 , #1
2005-04-16 15:20:36 -07:00
__Copy : ldr r2 , [ r0 ] , #- 4
str r2 , [ r1 ] , #- 4
teq r1 , r3
bne _ _ C o p y
2005-07-17 20:12:08 +01:00
/ * The f i r m w a r e m a p s u s i n b l o c k s o f 1 M B , t h e n e x t b l o c k i s
_ below_ t h e l a s t o n e . S o o u r d e c r e m e n t i n g s o u r c e p o i n t e r
ist r i g h t h e r e , b u t t h e d e s t i n a t i o n p o i n t e r m u s t b e i n c r e a s e d
by 2 M B * /
add r1 , r1 , #0x00200000
add r3 , r3 , #0x00100000
teq r4 , #0
bne _ _ M o v e C o d e
2005-04-16 15:20:36 -07:00
/* and jump to it */
2005-07-17 20:12:08 +01:00
adr r2 , _ _ g o _ o n @ where we want to jump
adr r0 , _ _ o f w _ d a t a @ read the 1. entry of the memory map
2005-04-16 15:20:36 -07:00
ldr r0 , [ r0 , #4 ]
2005-07-17 20:12:08 +01:00
sub r2 , r2 , r0 @ we are mapped add 0e50 now, sub that (-0e00)
sub r2 , r2 , #0x00500000 @ -0050
ldr r0 , _ _ c o p y _ t a r g e t @ and add 0850 8000 instead
add r0 , r0 , #4
2005-04-16 15:20:36 -07:00
add r2 , r2 , r0
2005-07-17 20:12:08 +01:00
mov p c , r2 @ and jump there
2005-04-16 15:20:36 -07:00
__go_on :
adr s p , _ _ t e m p _ s t a c k
add s p , s p , #128
adr r0 , _ _ o f w _ d a t a
mov l r , p c
b c r e a t e _ p a r a m s
mov r8 , #0
mov r7 , #15