2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2013-01-18 15:12:20 +05:30
/ *
* ARC C P U s t a r t u p C o d e
*
* Copyright ( C ) 2 0 0 4 , 2 0 0 7 - 2 0 1 0 , 2 0 1 1 - 2 0 1 2 S y n o p s y s , I n c . ( w w w . s y n o p s y s . c o m )
*
* Vineetg : Dec 2 0 0 7
* - Check i f w e a r e r u n n i n g o n S i m u l a t o r o r o n r e a l h a r d w a r e
* to s k i p c e r t a i n t h i n g s d u r i n g b o o t o n s i m u l a t o r
* /
2014-03-07 18:08:11 +05:30
# include < l i n u x / l i n k a g e . h >
2013-01-18 15:12:20 +05:30
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / e n t r y . h >
# include < a s m / a r c r e g s . h >
2014-03-07 18:08:11 +05:30
# include < a s m / c a c h e . h >
2020-03-05 23:02:50 +03:00
# include < a s m / d s p - i m p l . h >
2019-01-16 14:29:50 +03:00
# include < a s m / i r q f l a g s . h >
2014-03-07 18:08:11 +05:30
.macro CPU_EARLY_SETUP
; Setting up Vectror Table (in case exception happens in early boot
sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE]
; Disable I-cache/D-cache if kernel so configured
lr r5 , [ A R C _ R E G _ I C _ B C R ]
breq r5 , 0 , 1 f ; I$ doesn't exist
lr r5 , [ A R C _ R E G _ I C _ C T R L ]
# ifdef C O N F I G _ A R C _ H A S _ I C A C H E
bclr r5 , r5 , 0 ; 0 - Enable, 1 is Disable
# else
bset r5 , r5 , 0 ; I$ exists, but is not used
# endif
sr r5 , [ A R C _ R E G _ I C _ C T R L ]
1 :
lr r5 , [ A R C _ R E G _ D C _ B C R ]
breq r5 , 0 , 1 f ; D$ doesn't exist
lr r5 , [ A R C _ R E G _ D C _ C T R L ]
bclr r5 , r5 , 6 ; Invalidate (discard w/o wback)
# ifdef C O N F I G _ A R C _ H A S _ D C A C H E
bclr r5 , r5 , 0 ; Enable (+Inv)
# else
bset r5 , r5 , 0 ; Disable (+Inv)
# endif
sr r5 , [ A R C _ R E G _ D C _ C T R L ]
1 :
2019-01-16 14:29:50 +03:00
# ifdef C O N F I G _ I S A _ A R C V 2
; Unaligned access is disabled at reset, so re-enable early as
; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
; by default
lr r5 , [ s t a t u s32 ]
2019-01-30 19:32:41 +03:00
# ifdef C O N F I G _ A R C _ U S E _ U N A L I G N E D _ M E M _ A C C E S S
2019-01-16 14:29:50 +03:00
bset r5 , r5 , S T A T U S _ A D _ B I T
2019-01-30 19:32:41 +03:00
# else
; Although disabled at reset, bootloader might have enabled it
bclr r5 , r5 , S T A T U S _ A D _ B I T
# endif
2019-01-16 14:29:50 +03:00
kflag r5
2020-06-04 20:39:25 +03:00
# ifdef C O N F I G _ A R C _ L P B _ D I S A B L E
lr r5 , [ A R C _ R E G _ L P B _ B U I L D ]
breq r5 , 0 , 1 f ; LPB doesn't exist
mov r5 , 1
sr r5 , [ A R C _ R E G _ L P B _ C T R L ]
1 :
# endif / * C O N F I G _ A R C _ L P B _ D I S A B L E * /
2019-01-16 14:29:50 +03:00
# endif
2020-03-05 23:02:50 +03:00
; Config DSP_CTRL properly, so kernel may use integer multiply,
; multiply-accumulate, and divide operations
DSP_ E A R L Y _ I N I T
2014-03-07 18:08:11 +05:30
.endm
2013-01-18 15:12:20 +05:30
.section .init .text , " ax" ,@progbits
2015-10-09 11:26:12 +05:30
;----------------------------------------------------------------
; Default Reset Handler (jumped into from Reset vector)
; - Don't clobber r0,r1,r2 as they might have u-boot provided args
; - Platforms can override this weak version if needed
;----------------------------------------------------------------
WEAK( r e s _ s e r v i c e )
j s t e x t
END( r e s _ s e r v i c e )
;----------------------------------------------------------------
; Kernel Entry point
;----------------------------------------------------------------
ENTRY( s t e x t )
2013-01-18 15:12:20 +05:30
2014-03-07 18:08:11 +05:30
CPU_ E A R L Y _ S E T U P
2013-06-17 18:27:23 +05:30
2013-01-18 15:12:23 +05:30
# ifdef C O N F I G _ S M P
GET_ C P U _ I D r5
cmp r5 , 0
2015-10-09 11:26:12 +05:30
mov. n z r0 , r5
2017-01-12 14:30:29 -08:00
bz . L m a s t e r _ p r o c e e d
2015-10-09 11:26:12 +05:30
; Non-Masters wait for Master to boot enough and bring them up
2017-01-12 14:30:29 -08:00
; when they resume, tail-call to entry point
mov b l i n k , @first_lines_of_secondary
j a r c _ p l a t f o r m _ s m p _ w a i t _ t o _ b o o t
.Lmaster_proceed :
2013-01-18 15:12:23 +05:30
# endif
2015-10-09 11:26:12 +05:30
2013-01-18 15:12:20 +05:30
; Clear BSS before updating any globals
; XXX: use ZOL here
mov r5 , _ _ b s s _ s t a r t
2014-04-17 17:13:26 +05:30
sub r6 , _ _ b s s _ s t o p , r5
lsr. f l p _ c o u n t , r6 , 2
lpnz 1 f
st. a b 0 , [ r5 , 4 ]
2013-01-18 15:12:20 +05:30
1 :
2014-01-16 15:01:24 +05:30
; Uboot - kernel ABI
; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2
2019-02-14 18:07:44 +03:00
; r1 = magic number (always zero as of now)
2014-01-16 15:01:24 +05:30
; r2 = pointer to uboot provided cmdline or external DTB in mem
2019-02-14 18:07:44 +03:00
; These are handled later in handle_uboot_args()
2014-01-16 15:01:24 +05:30
st r0 , [ @uboot_tag]
2019-02-25 20:16:01 +03:00
st r1 , [ @uboot_magic]
2014-01-16 15:01:24 +05:30
st r2 , [ @uboot_arg]
2013-01-18 15:12:20 +05:30
; setup "current" tsk and optionally cache it in dedicated r25
mov r9 , @init_task
SET_ C U R R _ T A S K _ O N _ C P U r9 , r0 ; r9 = tsk, r0 = scratch
; setup stack (fp, sp)
mov f p , 0
; tsk->thread_info is really a PAGE, whose bottom hoists stack
GET_ T S K _ S T A C K _ B A S E r9 , s p ; r9 = tsk, sp = stack base(output)
j s t a r t _ k e r n e l ; "C" entry point
2015-10-09 11:26:12 +05:30
END( s t e x t )
2013-01-18 15:12:23 +05:30
# ifdef C O N F I G _ S M P
;----------------------------------------------------------------
; First lines of code run by secondary before jumping to 'C'
;----------------------------------------------------------------
2013-10-23 10:16:38 +08:00
.section .text , " ax" ,@progbits
2015-10-09 11:26:12 +05:30
ENTRY( f i r s t _ l i n e s _ o f _ s e c o n d a r y )
2013-01-18 15:12:23 +05:30
; setup per-cpu idle task as "current" on this CPU
ld r0 , [ @secondary_idle_tsk]
SET_ C U R R _ T A S K _ O N _ C P U r0 , r1
; setup stack (fp, sp)
mov f p , 0
; set it's stack base to tsk->thread_info bottom
GET_ T S K _ S T A C K _ B A S E r0 , s p
j s t a r t _ k e r n e l _ s e c o n d a r y
2015-10-09 11:26:12 +05:30
END( f i r s t _ l i n e s _ o f _ s e c o n d a r y )
2013-01-18 15:12:23 +05:30
# endif