/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2020-2022 Loongson Technology Corporation Limited3*/4#include <linux/init.h>5#include <linux/threads.h>67#include <asm/addrspace.h>8#include <asm/asm.h>9#include <asm/asmmacro.h>10#include <asm/bug.h>11#include <asm/regdef.h>12#include <asm/loongarch.h>13#include <asm/stackframe.h>1415#ifdef CONFIG_EFI_STUB1617#include "efi-header.S"1819__HEAD2021_head:22.word IMAGE_DOS_SIGNATURE /* "MZ", MS-DOS header */23.org 0x824.dword _kernel_entry /* Kernel entry point (physical address) */25.dword _kernel_asize /* Kernel image effective size */26.quad PHYS_LINK_KADDR /* Kernel image load offset from start of RAM */27.org 0x38 /* 0x20 ~ 0x37 reserved */28.long LINUX_PE_MAGIC29.long pe_header - _head /* Offset to the PE header */3031pe_header:32__EFI_PE_HEADER3334SYM_DATA(kernel_asize, .long _kernel_asize);35SYM_DATA(kernel_fsize, .long _kernel_fsize);3637#endif3839__REF4041.align 124243SYM_CODE_START(kernel_entry) # kernel entry point44UNWIND_HINT_END_OF_STACK4546SETUP_TWINS47SETUP_MODES t048JUMP_VIRT_ADDR t0, t149SETUP_DMWINS t05051la.pcrel t0, __bss_start # clear .bss52LONG_S zero, t0, 053la.pcrel t1, __bss_stop - LONGSIZE541:55PTR_ADDI t0, t0, LONGSIZE56LONG_S zero, t0, 057bne t0, t1, 1b5859la.pcrel t0, fw_arg060PTR_S a0, t0, 0 # firmware arguments61la.pcrel t0, fw_arg162PTR_S a1, t0, 063la.pcrel t0, fw_arg264PTR_S a2, t0, 06566#ifdef CONFIG_PAGE_SIZE_4KB67LONG_LI t0, 068LONG_LI t1, CSR_STFILL69csrxchg t0, t1, LOONGARCH_CSR_IMPCTL170#endif71/* KSave3 used for percpu base, initialized as 0 */72csrwr zero, PERCPU_BASE_KS73/* GPR21 used for percpu base (runtime), initialized as 0 */74move u0, zero7576la.pcrel tp, init_thread_union77/* Set the SP after an empty pt_regs. */78PTR_LI sp, (_THREAD_SIZE - PT_SIZE)79PTR_ADD sp, sp, tp80set_saved_sp sp, t0, t18182#ifdef CONFIG_RELOCATABLE8384bl relocate_kernel8586#ifdef CONFIG_RANDOMIZE_BASE87/* Repoint the sp into the new kernel */88PTR_LI sp, (_THREAD_SIZE - PT_SIZE)89PTR_ADD sp, sp, tp90set_saved_sp sp, t0, t19192/* Jump to the new kernel: new_pc = current_pc + random_offset */93pcaddi t0, 094PTR_ADD t0, t0, a095jirl zero, t0, 0xc96#endif /* CONFIG_RANDOMIZE_BASE */9798#endif /* CONFIG_RELOCATABLE */99100#ifdef CONFIG_KASAN101bl kasan_early_init102#endif103104bl start_kernel105ASM_BUG()106107SYM_CODE_END(kernel_entry)108109#ifdef CONFIG_SMP110111/*112* SMP slave cpus entry point. Board specific code for bootstrap calls this113* function after setting up the stack and tp registers.114*/115SYM_CODE_START(smpboot_entry)116UNWIND_HINT_END_OF_STACK117118SETUP_TWINS119SETUP_MODES t0120JUMP_VIRT_ADDR t0, t1121SETUP_DMWINS t0122123#ifdef CONFIG_PAGE_SIZE_4KB124LONG_LI t0, 0125LONG_LI t1, CSR_STFILL126csrxchg t0, t1, LOONGARCH_CSR_IMPCTL1127#endif128la.pcrel t0, cpuboot_data129ld.d sp, t0, CPU_BOOT_STACK130ld.d tp, t0, CPU_BOOT_TINFO131132bl start_secondary133ASM_BUG()134135SYM_CODE_END(smpboot_entry)136137#endif /* CONFIG_SMP */138139140