blob: 8f6e0447dd1702b571b23a3f561f8ed032ae6abf [file] [log] [blame]
Vineet Guptac121c502013-01-18 15:12:20 +05301/*
2 * ARC CPU startup Code
3 *
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Vineetg: Dec 2007
11 * -Check if we are running on Simulator or on real hardware
12 * to skip certain things during boot on simulator
13 */
14
Vineet Guptaef680cd2014-03-07 18:08:11 +053015#include <linux/linkage.h>
Vineet Guptac121c502013-01-18 15:12:20 +053016#include <asm/asm-offsets.h>
17#include <asm/entry.h>
Vineet Guptac121c502013-01-18 15:12:20 +053018#include <asm/arcregs.h>
Vineet Guptaef680cd2014-03-07 18:08:11 +053019#include <asm/cache.h>
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030020#include <asm/irqflags.h>
Vineet Guptaef680cd2014-03-07 18:08:11 +053021
22.macro CPU_EARLY_SETUP
23
24 ; Setting up Vectror Table (in case exception happens in early boot
25 sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE]
26
27 ; Disable I-cache/D-cache if kernel so configured
28 lr r5, [ARC_REG_IC_BCR]
29 breq r5, 0, 1f ; I$ doesn't exist
30 lr r5, [ARC_REG_IC_CTRL]
31#ifdef CONFIG_ARC_HAS_ICACHE
32 bclr r5, r5, 0 ; 0 - Enable, 1 is Disable
33#else
34 bset r5, r5, 0 ; I$ exists, but is not used
35#endif
36 sr r5, [ARC_REG_IC_CTRL]
37
381:
39 lr r5, [ARC_REG_DC_BCR]
40 breq r5, 0, 1f ; D$ doesn't exist
41 lr r5, [ARC_REG_DC_CTRL]
42 bclr r5, r5, 6 ; Invalidate (discard w/o wback)
43#ifdef CONFIG_ARC_HAS_DCACHE
44 bclr r5, r5, 0 ; Enable (+Inv)
45#else
46 bset r5, r5, 0 ; Disable (+Inv)
47#endif
48 sr r5, [ARC_REG_DC_CTRL]
49
501:
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030051
52#ifdef CONFIG_ISA_ARCV2
53 ; Unaligned access is disabled at reset, so re-enable early as
54 ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
55 ; by default
56 lr r5, [status32]
Eugeniy Paltsev76551462019-01-30 19:32:41 +030057#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030058 bset r5, r5, STATUS_AD_BIT
Eugeniy Paltsev76551462019-01-30 19:32:41 +030059#else
60 ; Although disabled at reset, bootloader might have enabled it
61 bclr r5, r5, STATUS_AD_BIT
62#endif
Eugeniy Paltsev252f6e82019-01-16 14:29:50 +030063 kflag r5
64#endif
Vineet Guptaef680cd2014-03-07 18:08:11 +053065.endm
Vineet Guptac121c502013-01-18 15:12:20 +053066
Vineet Guptac121c502013-01-18 15:12:20 +053067 .section .init.text, "ax",@progbits
Vineet Gupta3971cdc2015-10-09 11:26:12 +053068
69;----------------------------------------------------------------
70; Default Reset Handler (jumped into from Reset vector)
71; - Don't clobber r0,r1,r2 as they might have u-boot provided args
72; - Platforms can override this weak version if needed
73;----------------------------------------------------------------
74WEAK(res_service)
75 j stext
76END(res_service)
77
78;----------------------------------------------------------------
79; Kernel Entry point
80;----------------------------------------------------------------
81ENTRY(stext)
Vineet Guptac121c502013-01-18 15:12:20 +053082
Vineet Guptaef680cd2014-03-07 18:08:11 +053083 CPU_EARLY_SETUP
Vineet Gupta05b016e2013-06-17 18:27:23 +053084
Vineet Gupta41195d22013-01-18 15:12:23 +053085#ifdef CONFIG_SMP
Vineet Gupta41195d22013-01-18 15:12:23 +053086 GET_CPU_ID r5
87 cmp r5, 0
Vineet Gupta3971cdc2015-10-09 11:26:12 +053088 mov.nz r0, r5
Vineet Guptabf024542017-01-12 14:30:29 -080089 bz .Lmaster_proceed
90
Vineet Gupta3971cdc2015-10-09 11:26:12 +053091 ; Non-Masters wait for Master to boot enough and bring them up
Vineet Guptabf024542017-01-12 14:30:29 -080092 ; when they resume, tail-call to entry point
93 mov blink, @first_lines_of_secondary
94 j arc_platform_smp_wait_to_boot
95
96.Lmaster_proceed:
Vineet Gupta3971cdc2015-10-09 11:26:12 +053097#endif
98
Vineet Guptac121c502013-01-18 15:12:20 +053099 ; Clear BSS before updating any globals
100 ; XXX: use ZOL here
101 mov r5, __bss_start
Vineet Guptabef444a2014-04-17 17:13:26 +0530102 sub r6, __bss_stop, r5
103 lsr.f lp_count, r6, 2
104 lpnz 1f
105 st.ab 0, [r5, 4]
Vineet Guptac121c502013-01-18 15:12:20 +05301061:
Vineet Guptac121c502013-01-18 15:12:20 +0530107
Vineet Gupta59ed9412014-01-16 15:01:24 +0530108 ; Uboot - kernel ABI
109 ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300110 ; r1 = magic number (always zero as of now)
Vineet Gupta59ed9412014-01-16 15:01:24 +0530111 ; r2 = pointer to uboot provided cmdline or external DTB in mem
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300112 ; These are handled later in handle_uboot_args()
Vineet Gupta59ed9412014-01-16 15:01:24 +0530113 st r0, [@uboot_tag]
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300114 st r1, [@uboot_magic]
Vineet Gupta59ed9412014-01-16 15:01:24 +0530115 st r2, [@uboot_arg]
Vineet Guptac121c502013-01-18 15:12:20 +0530116
Vineet Guptac121c502013-01-18 15:12:20 +0530117 ; setup "current" tsk and optionally cache it in dedicated r25
118 mov r9, @init_task
119 SET_CURR_TASK_ON_CPU r9, r0 ; r9 = tsk, r0 = scratch
120
121 ; setup stack (fp, sp)
122 mov fp, 0
123
124 ; tsk->thread_info is really a PAGE, whose bottom hoists stack
125 GET_TSK_STACK_BASE r9, sp ; r9 = tsk, sp = stack base(output)
126
127 j start_kernel ; "C" entry point
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530128END(stext)
Vineet Gupta41195d22013-01-18 15:12:23 +0530129
130#ifdef CONFIG_SMP
131;----------------------------------------------------------------
132; First lines of code run by secondary before jumping to 'C'
133;----------------------------------------------------------------
Chen Gang8f5d2212013-10-23 10:16:38 +0800134 .section .text, "ax",@progbits
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530135ENTRY(first_lines_of_secondary)
Vineet Gupta41195d22013-01-18 15:12:23 +0530136
137 ; setup per-cpu idle task as "current" on this CPU
138 ld r0, [@secondary_idle_tsk]
139 SET_CURR_TASK_ON_CPU r0, r1
140
141 ; setup stack (fp, sp)
142 mov fp, 0
143
144 ; set it's stack base to tsk->thread_info bottom
145 GET_TSK_STACK_BASE r0, sp
146
147 j start_kernel_secondary
Vineet Gupta3971cdc2015-10-09 11:26:12 +0530148END(first_lines_of_secondary)
Vineet Gupta41195d22013-01-18 15:12:23 +0530149#endif