blob: 6f41265f62505cf6850c470a3dc09db1b7066b0c [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vineet Guptac121c502013-01-18 15:12:20 +05302/*
3 * ARC CPU startup Code
4 *
5 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
6 *
Vineet Guptac121c502013-01-18 15:12:20 +05307 * Vineetg: Dec 2007
8 * -Check if we are running on Simulator or on real hardware
9 * to skip certain things during boot on simulator
10 */
11
Vineet Guptaef680cd2014-03-07 18:08:11 +053012#include <linux/linkage.h>
Vineet Guptac121c502013-01-18 15:12:20 +053013#include <asm/asm-offsets.h>
14#include <asm/entry.h>
Vineet Guptac121c502013-01-18 15:12:20 +053015#include <asm/arcregs.h>
Vineet Guptaef680cd2014-03-07 18:08:11 +053016#include <asm/cache.h>
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030017#include <asm/irqflags.h>
Vineet Guptaef680cd2014-03-07 18:08:11 +053018
19.macro CPU_EARLY_SETUP
20
21 ; Setting up Vectror Table (in case exception happens in early boot
22 sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE]
23
24 ; Disable I-cache/D-cache if kernel so configured
25 lr r5, [ARC_REG_IC_BCR]
26 breq r5, 0, 1f ; I$ doesn't exist
27 lr r5, [ARC_REG_IC_CTRL]
28#ifdef CONFIG_ARC_HAS_ICACHE
29 bclr r5, r5, 0 ; 0 - Enable, 1 is Disable
30#else
31 bset r5, r5, 0 ; I$ exists, but is not used
32#endif
33 sr r5, [ARC_REG_IC_CTRL]
34
351:
36 lr r5, [ARC_REG_DC_BCR]
37 breq r5, 0, 1f ; D$ doesn't exist
38 lr r5, [ARC_REG_DC_CTRL]
39 bclr r5, r5, 6 ; Invalidate (discard w/o wback)
40#ifdef CONFIG_ARC_HAS_DCACHE
41 bclr r5, r5, 0 ; Enable (+Inv)
42#else
43 bset r5, r5, 0 ; Disable (+Inv)
44#endif
45 sr r5, [ARC_REG_DC_CTRL]
46
471:
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030048
49#ifdef CONFIG_ISA_ARCV2
50 ; Unaligned access is disabled at reset, so re-enable early as
51 ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
52 ; by default
53 lr r5, [status32]
Eugeniy Paltsev76551462019-01-30 19:32:41 +030054#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030055 bset r5, r5, STATUS_AD_BIT
Eugeniy Paltsev76551462019-01-30 19:32:41 +030056#else
57 ; Although disabled at reset, bootloader might have enabled it
58 bclr r5, r5, STATUS_AD_BIT
59#endif
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030060 kflag r5
61#endif
Vineet Guptaef680cd2014-03-07 18:08:11 +053062.endm
Vineet Guptac121c502013-01-18 15:12:20 +053063
Vineet Guptac121c502013-01-18 15:12:20 +053064 .section .init.text, "ax",@progbits
Vineet Gupta3971cdc2015-10-09 11:26:12 +053065
66;----------------------------------------------------------------
67; Default Reset Handler (jumped into from Reset vector)
68; - Don't clobber r0,r1,r2 as they might have u-boot provided args
69; - Platforms can override this weak version if needed
70;----------------------------------------------------------------
71WEAK(res_service)
72 j stext
73END(res_service)
74
75;----------------------------------------------------------------
76; Kernel Entry point
77;----------------------------------------------------------------
78ENTRY(stext)
Vineet Guptac121c502013-01-18 15:12:20 +053079
Vineet Guptaef680cd2014-03-07 18:08:11 +053080 CPU_EARLY_SETUP
Vineet Gupta05b016e2013-06-17 18:27:23 +053081
Vineet Gupta41195d22013-01-18 15:12:23 +053082#ifdef CONFIG_SMP
Vineet Gupta41195d22013-01-18 15:12:23 +053083 GET_CPU_ID r5
84 cmp r5, 0
Vineet Gupta3971cdc2015-10-09 11:26:12 +053085 mov.nz r0, r5
Vineet Guptabf024542017-01-12 14:30:29 -080086 bz .Lmaster_proceed
87
Vineet Gupta3971cdc2015-10-09 11:26:12 +053088 ; Non-Masters wait for Master to boot enough and bring them up
Vineet Guptabf024542017-01-12 14:30:29 -080089 ; when they resume, tail-call to entry point
90 mov blink, @first_lines_of_secondary
91 j arc_platform_smp_wait_to_boot
92
93.Lmaster_proceed:
Vineet Gupta3971cdc2015-10-09 11:26:12 +053094#endif
95
Vineet Guptac121c502013-01-18 15:12:20 +053096 ; Clear BSS before updating any globals
97 ; XXX: use ZOL here
98 mov r5, __bss_start
Vineet Guptabef444a2014-04-17 17:13:26 +053099 sub r6, __bss_stop, r5
100 lsr.f lp_count, r6, 2
101 lpnz 1f
102 st.ab 0, [r5, 4]
Vineet Guptac121c502013-01-18 15:12:20 +05301031:
Vineet Guptac121c502013-01-18 15:12:20 +0530104
Vineet Gupta59ed9412014-01-16 15:01:24 +0530105 ; Uboot - kernel ABI
106 ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300107 ; r1 = magic number (always zero as of now)
Vineet Gupta59ed9412014-01-16 15:01:24 +0530108 ; r2 = pointer to uboot provided cmdline or external DTB in mem
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300109 ; These are handled later in handle_uboot_args()
Vineet Gupta59ed9412014-01-16 15:01:24 +0530110 st r0, [@uboot_tag]
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300111 st r1, [@uboot_magic]
Vineet Gupta59ed9412014-01-16 15:01:24 +0530112 st r2, [@uboot_arg]
Vineet Guptac121c502013-01-18 15:12:20 +0530113
Vineet Guptac121c502013-01-18 15:12:20 +0530114 ; setup "current" tsk and optionally cache it in dedicated r25
115 mov r9, @init_task
116 SET_CURR_TASK_ON_CPU r9, r0 ; r9 = tsk, r0 = scratch
117
118 ; setup stack (fp, sp)
119 mov fp, 0
120
121 ; tsk->thread_info is really a PAGE, whose bottom hoists stack
122 GET_TSK_STACK_BASE r9, sp ; r9 = tsk, sp = stack base(output)
123
124 j start_kernel ; "C" entry point
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530125END(stext)
Vineet Gupta41195d22013-01-18 15:12:23 +0530126
127#ifdef CONFIG_SMP
128;----------------------------------------------------------------
129; First lines of code run by secondary before jumping to 'C'
130;----------------------------------------------------------------
Chen Gang8f5d2212013-10-23 10:16:38 +0800131 .section .text, "ax",@progbits
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530132ENTRY(first_lines_of_secondary)
Vineet Gupta41195d22013-01-18 15:12:23 +0530133
134 ; setup per-cpu idle task as "current" on this CPU
135 ld r0, [@secondary_idle_tsk]
136 SET_CURR_TASK_ON_CPU r0, r1
137
138 ; setup stack (fp, sp)
139 mov fp, 0
140
141 ; set it's stack base to tsk->thread_info bottom
142 GET_TSK_STACK_BASE r0, sp
143
144 j start_kernel_secondary
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530145END(first_lines_of_secondary)
Vineet Gupta41195d22013-01-18 15:12:23 +0530146#endif