efi/arm64: libstub: avoid SetVirtualAddressMap() when possible
[linux-block.git] / arch / loongarch / kernel / head.S
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #include <linux/init.h>
6 #include <linux/threads.h>
7
8 #include <asm/addrspace.h>
9 #include <asm/asm.h>
10 #include <asm/asmmacro.h>
11 #include <asm/regdef.h>
12 #include <asm/loongarch.h>
13 #include <asm/stackframe.h>
14
15 #ifdef CONFIG_EFI_STUB
16
17 #include "efi-header.S"
18
19         __HEAD
20
21 _head:
22         .word   MZ_MAGIC                /* "MZ", MS-DOS header */
23         .org    0x3c                    /* 0x04 ~ 0x3b reserved */
24         .long   pe_header - _head       /* Offset to the PE header */
25
26 pe_header:
27         __EFI_PE_HEADER
28
29 SYM_DATA(kernel_asize, .long _end - _text);
30 SYM_DATA(kernel_fsize, .long _edata - _text);
31 SYM_DATA(kernel_offset, .long kernel_offset - _text);
32
33 #endif
34
35         __REF
36
37 SYM_CODE_START(kernel_entry)                    # kernel entry point
38
39         /* Config direct window and set PG */
40         li.d            t0, CSR_DMW0_INIT       # UC, PLV0, 0x8000 xxxx xxxx xxxx
41         csrwr           t0, LOONGARCH_CSR_DMWIN0
42         li.d            t0, CSR_DMW1_INIT       # CA, PLV0, 0x9000 xxxx xxxx xxxx
43         csrwr           t0, LOONGARCH_CSR_DMWIN1
44
45         /* We might not get launched at the address the kernel is linked to,
46            so we jump there.  */
47         la.abs          t0, 0f
48         jr              t0
49 0:
50         /* Enable PG */
51         li.w            t0, 0xb0                # PLV=0, IE=0, PG=1
52         csrwr           t0, LOONGARCH_CSR_CRMD
53         li.w            t0, 0x04                # PLV=0, PIE=1, PWE=0
54         csrwr           t0, LOONGARCH_CSR_PRMD
55         li.w            t0, 0x00                # FPE=0, SXE=0, ASXE=0, BTE=0
56         csrwr           t0, LOONGARCH_CSR_EUEN
57
58         la              t0, __bss_start         # clear .bss
59         st.d            zero, t0, 0
60         la              t1, __bss_stop - LONGSIZE
61 1:
62         addi.d          t0, t0, LONGSIZE
63         st.d            zero, t0, 0
64         bne             t0, t1, 1b
65
66         la              t0, fw_arg0
67         st.d            a0, t0, 0               # firmware arguments
68         la              t0, fw_arg1
69         st.d            a1, t0, 0
70         la              t0, fw_arg2
71         st.d            a2, t0, 0
72
73         /* KSave3 used for percpu base, initialized as 0 */
74         csrwr           zero, PERCPU_BASE_KS
75         /* GPR21 used for percpu base (runtime), initialized as 0 */
76         move            u0, zero
77
78         la              tp, init_thread_union
79         /* Set the SP after an empty pt_regs.  */
80         PTR_LI          sp, (_THREAD_SIZE - 32 - PT_SIZE)
81         PTR_ADD         sp, sp, tp
82         set_saved_sp    sp, t0, t1
83         PTR_ADDI        sp, sp, -4 * SZREG      # init stack pointer
84
85         bl              start_kernel
86
87 SYM_CODE_END(kernel_entry)
88
89 #ifdef CONFIG_SMP
90
91 /*
92  * SMP slave cpus entry point.  Board specific code for bootstrap calls this
93  * function after setting up the stack and tp registers.
94  */
95 SYM_CODE_START(smpboot_entry)
96         li.d            t0, CSR_DMW0_INIT       # UC, PLV0
97         csrwr           t0, LOONGARCH_CSR_DMWIN0
98         li.d            t0, CSR_DMW1_INIT       # CA, PLV0
99         csrwr           t0, LOONGARCH_CSR_DMWIN1
100
101         la.abs          t0, 0f
102         jr              t0
103 0:
104         /* Enable PG */
105         li.w            t0, 0xb0                # PLV=0, IE=0, PG=1
106         csrwr           t0, LOONGARCH_CSR_CRMD
107         li.w            t0, 0x04                # PLV=0, PIE=1, PWE=0
108         csrwr           t0, LOONGARCH_CSR_PRMD
109         li.w            t0, 0x00                # FPE=0, SXE=0, ASXE=0, BTE=0
110         csrwr           t0, LOONGARCH_CSR_EUEN
111
112         la.abs          t0, cpuboot_data
113         ld.d            sp, t0, CPU_BOOT_STACK
114         ld.d            tp, t0, CPU_BOOT_TINFO
115
116         bl              start_secondary
117 SYM_CODE_END(smpboot_entry)
118
119 #endif /* CONFIG_SMP */
120
121 SYM_ENTRY(kernel_entry_end, SYM_L_GLOBAL, SYM_A_NONE)