2005-07-27 11:44:44 -07:00
/ *
* Code t h a t s e t s u p t h e D R A M r e g i s t e r s , c a l l s t h e
* decompressor t o u n p a c k t h e p i g g y b a c k e d k e r n e l , a n d j u m p s .
*
2007-11-30 16:40:26 +01:00
* Copyright ( C ) 1 9 9 9 - 2 0 0 6 , A x i s C o m m u n i c a t i o n s A B
2005-07-27 11:44:44 -07:00
* /
# define A S S E M B L E R _ M A C R O S _ O N L Y
2007-11-30 16:40:26 +01:00
# include < h w r e g s / a s m / r e g _ m a p _ a s m . h >
2008-10-21 17:45:58 +02:00
# include < m a c h / s t a r t u p . i n c >
2005-07-27 11:44:44 -07:00
# define R A M _ I N I T _ M A G I C 0 x56 9 0 2 3 8 7
# define C O M M A N D _ L I N E _ M A G I C 0 x87 1 0 9 5 6 3
;; Exported symbols
.globl input_data
.text
2008-10-21 17:45:58 +02:00
_start :
2005-07-27 11:44:44 -07:00
di
;; Start clocks for used blocks.
2007-11-30 16:40:26 +01:00
START_ C L O C K S
;; Initialize the DRAM registers.
2005-07-27 11:44:44 -07:00
cmp. d R A M _ I N I T _ M A G I C , $ r8 ; Already initialized?
beq d r a m _ i n i t _ f i n i s h e d
nop
2008-10-22 23:57:53 +02:00
# if d e f i n e d C O N F I G _ E T R A X F S
# include " . . / . . / m a c h - f s / d r a m _ i n i t . S "
# elif d e f i n e d C O N F I G _ C R I S _ M A C H _ A R T P E C 3
# include " . . / . . / m a c h - a3 / d r a m _ i n i t . S "
# else
# error O n l y E T R A X F S a n d A R T P E C - 3 s u p p o r t e d !
# endif
2005-07-27 11:44:44 -07:00
dram_init_finished :
2007-11-30 16:40:26 +01:00
GIO_ I N I T
2005-07-27 11:44:44 -07:00
;; Setup the stack to a suitably high address.
;; We assume 8 MB is the minimum DRAM and put
;; the SP at the top for now.
move. d 0 x40 8 0 0 0 0 0 , $ s p
2007-11-30 16:40:26 +01:00
;; Figure out where the compressed piggyback image is.
;; It is either in [NOR] flash (we don't want to copy it
;; to DRAM before unpacking), or copied to DRAM
;; by the [NAND] flash boot loader.
;; The piggyback image is at _edata, but relative to where the
;; image is actually located in memory, not where it is linked
;; (the decompressor is linked at 0x40700000+ and runs there).
2005-07-27 11:44:44 -07:00
;; Use (_edata - herami) as offset to the current PC.
hereami :
lapcq . , $ r5 ; get PC
and. d 0 x7 f f f f f f f , $ r5 ; strip any non-cache bit
2007-11-30 16:40:26 +01:00
move. d $ r5 , $ r0 ; source address of 'herami'
2005-07-27 11:44:44 -07:00
add. d _ e d a t a , $ r5
sub. d h e r e a m i , $ r5 ; r5 = flash address of '_edata'
move. d h e r e a m i , $ r1 ; destination
2007-11-30 16:40:26 +01:00
2005-07-27 11:44:44 -07:00
;; Copy text+data to DRAM
move. d _ e d a t a , $ r2 ; end destination
2007-11-30 16:40:26 +01:00
1 : move. w [ $ r0 + ] , $ r3 ; from herami+ source
move. w $ r3 , [ $ r1 + ] ; to hereami+ destination (linked address)
cmp. d $ r2 , $ r1 ; finish when destination == _edata
2005-07-27 11:44:44 -07:00
bcs 1 b
nop
move. d i n p u t _ d a t a , $ r0 ; for the decompressor
move. d $ r5 , [ $ r0 ] ; for the decompressor
;; Clear the decompressors BSS (between _edata and _end)
moveq 0 , $ r0
move. d _ e d a t a , $ r1
move. d _ e n d , $ r2
1 : move. w $ r0 , [ $ r1 + ]
cmp. d $ r2 , $ r1
bcs 1 b
nop
;; Save command line magic and address.
2007-11-30 16:40:26 +01:00
move. d _ c m d _ l i n e _ m a g i c , $ r0
move. d $ r10 , [ $ r0 ]
move. d _ c m d _ l i n e _ a d d r , $ r0
move. d $ r11 , [ $ r0 ]
;; Save boot source indicator
move. d _ b o o t _ s o u r c e , $ r0
move. d $ r12 , [ $ r0 ]
2005-07-27 11:44:44 -07:00
;; Do the decompression and save compressed size in _inptr
jsr d e c o m p r e s s _ k e r n e l
nop
2007-11-30 16:40:26 +01:00
;; Restore boot source indicator
move. d _ b o o t _ s o u r c e , $ r12
move. d [ $ r12 ] , $ r12
2005-07-27 11:44:44 -07:00
;; Restore command line magic and address.
move. d _ c m d _ l i n e _ m a g i c , $ r10
move. d [ $ r10 ] , $ r10
move. d _ c m d _ l i n e _ a d d r , $ r11
move. d [ $ r11 ] , $ r11
;; Put start address of root partition in r9 so the kernel can use it
;; when mounting from flash
move. d i n p u t _ d a t a , $ r0
move. d [ $ r0 ] , $ r9 ; flash address of compressed kernel
move. d i n p t r , $ r0
add. d [ $ r0 ] , $ r9 ; size of compressed kernel
2007-11-30 16:40:26 +01:00
cmp. d 0 x40 0 0 0 0 0 0 , $ r9 ; image in DRAM ?
blo e n t e r _ k e r n e l ; no, must be [NOR] flash, jump
nop ; delay slot
and. d 0 x00 1 f f f f f , $ r9 ; assume compressed kernel was < 2M
2005-07-27 11:44:44 -07:00
enter_kernel :
;; Enter the decompressed kernel
move. d R A M _ I N I T _ M A G I C , $ r8 ; Tell kernel that DRAM is initialized
jump 0 x40 0 0 4 0 0 0 ; kernel is linked to this address
nop
.data
input_data :
.dword 0 ; used by the decompressor
_cmd_line_magic :
.dword 0
_cmd_line_addr :
.dword 0
2007-11-30 16:40:26 +01:00
_boot_source :
.dword 0
2005-07-27 11:44:44 -07:00
2008-10-22 23:57:53 +02:00
# if d e f i n e d C O N F I G _ E T R A X F S
# include " . . / . . / m a c h - f s / h w _ s e t t i n g s . S "
# elif d e f i n e d C O N F I G _ C R I S _ M A C H _ A R T P E C 3
# include " . . / . . / m a c h - a3 / h w _ s e t t i n g s . S "
# else
# error O n l y E T R A X F S a n d A R T P E C - 3 s u p p o r t e d !
# endif