GNU Linux-libre 4.4.297-gnu1
[releases.git] / arch / arc / kernel / head.S
1 /*
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
15 #include <linux/linkage.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/entry.h>
18 #include <asm/arcregs.h>
19 #include <asm/cache.h>
20 #include <asm/irqflags.h>
21
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
38 1:
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
50 1:
51
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]
57         bset    r5, r5, STATUS_AD_BIT
58         kflag   r5
59 #endif
60 .endm
61
62         .section .init.text, "ax",@progbits
63
64 ;----------------------------------------------------------------
65 ; Default Reset Handler (jumped into from Reset vector)
66 ; - Don't clobber r0,r1,r2 as they might have u-boot provided args
67 ; - Platforms can override this weak version if needed
68 ;----------------------------------------------------------------
69 WEAK(res_service)
70         j       stext
71 END(res_service)
72
73 ;----------------------------------------------------------------
74 ; Kernel Entry point
75 ;----------------------------------------------------------------
76 ENTRY(stext)
77
78         CPU_EARLY_SETUP
79
80 #ifdef CONFIG_SMP
81         GET_CPU_ID  r5
82         cmp     r5, 0
83         mov.nz  r0, r5
84 #ifdef CONFIG_ARC_SMP_HALT_ON_RESET
85         ; Non-Master can proceed as system would be booted sufficiently
86         jnz     first_lines_of_secondary
87 #else
88         ; Non-Masters wait for Master to boot enough and bring them up
89         jnz     arc_platform_smp_wait_to_boot
90 #endif
91         ; Master falls thru
92 #endif
93
94         ; Clear BSS before updating any globals
95         ; XXX: use ZOL here
96         mov     r5, __bss_start
97         sub     r6, __bss_stop, r5
98         lsr.f   lp_count, r6, 2
99         lpnz    1f
100         st.ab   0, [r5, 4]
101 1:
102
103 #ifdef CONFIG_ARC_UBOOT_SUPPORT
104         ; Uboot - kernel ABI
105         ;    r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2
106         ;    r1 = magic number (board identity, unused as of now
107         ;    r2 = pointer to uboot provided cmdline or external DTB in mem
108         ; These are handled later in setup_arch()
109         st      r0, [@uboot_tag]
110         st      r2, [@uboot_arg]
111 #endif
112
113         ; setup "current" tsk and optionally cache it in dedicated r25
114         mov     r9, @init_task
115         SET_CURR_TASK_ON_CPU  r9, r0    ; r9 = tsk, r0 = scratch
116
117         ; setup stack (fp, sp)
118         mov     fp, 0
119
120         ; tsk->thread_info is really a PAGE, whose bottom hoists stack
121         GET_TSK_STACK_BASE r9, sp       ; r9 = tsk, sp = stack base(output)
122
123         j       start_kernel    ; "C" entry point
124 END(stext)
125
126 #ifdef CONFIG_SMP
127 ;----------------------------------------------------------------
128 ;     First lines of code run by secondary before jumping to 'C'
129 ;----------------------------------------------------------------
130         .section .text, "ax",@progbits
131 ENTRY(first_lines_of_secondary)
132
133         ; setup per-cpu idle task as "current" on this CPU
134         ld      r0, [@secondary_idle_tsk]
135         SET_CURR_TASK_ON_CPU  r0, r1
136
137         ; setup stack (fp, sp)
138         mov     fp, 0
139
140         ; set it's stack base to tsk->thread_info bottom
141         GET_TSK_STACK_BASE r0, sp
142
143         j       start_kernel_secondary
144 END(first_lines_of_secondary)
145 #endif