head.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #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>
  14. #ifdef CONFIG_EFI_STUB
  15. #include "efi-header.S"
  16. __HEAD
  17. _head:
  18. .word MZ_MAGIC /* "MZ", MS-DOS header */
  19. .org 0x8
  20. .dword kernel_entry /* Kernel entry point */
  21. .dword _end - _text /* Kernel image effective size */
  22. .quad 0 /* Kernel image load offset from start of RAM */
  23. .org 0x3c /* 0x20 ~ 0x3b reserved */
  24. .long pe_header - _head /* Offset to the PE header */
  25. pe_header:
  26. __EFI_PE_HEADER
  27. SYM_DATA(kernel_asize, .long _end - _text);
  28. SYM_DATA(kernel_fsize, .long _edata - _text);
  29. SYM_DATA(kernel_offset, .long kernel_offset - _text);
  30. #endif
  31. __REF
  32. .align 12
  33. SYM_CODE_START(kernel_entry) # kernel entry point
  34. /* Config direct window and set PG */
  35. li.d t0, CSR_DMW0_INIT # UC, PLV0, 0x8000 xxxx xxxx xxxx
  36. csrwr t0, LOONGARCH_CSR_DMWIN0
  37. li.d t0, CSR_DMW1_INIT # CA, PLV0, 0x9000 xxxx xxxx xxxx
  38. csrwr t0, LOONGARCH_CSR_DMWIN1
  39. /* We might not get launched at the address the kernel is linked to,
  40. so we jump there. */
  41. la.abs t0, 0f
  42. jr t0
  43. 0:
  44. /* Enable PG */
  45. li.w t0, 0xb0 # PLV=0, IE=0, PG=1
  46. csrwr t0, LOONGARCH_CSR_CRMD
  47. li.w t0, 0x04 # PLV=0, PIE=1, PWE=0
  48. csrwr t0, LOONGARCH_CSR_PRMD
  49. li.w t0, 0x00 # FPE=0, SXE=0, ASXE=0, BTE=0
  50. csrwr t0, LOONGARCH_CSR_EUEN
  51. la.pcrel t0, __bss_start # clear .bss
  52. st.d zero, t0, 0
  53. la.pcrel t1, __bss_stop - LONGSIZE
  54. 1:
  55. addi.d t0, t0, LONGSIZE
  56. st.d zero, t0, 0
  57. bne t0, t1, 1b
  58. la.pcrel t0, fw_arg0
  59. st.d a0, t0, 0 # firmware arguments
  60. la.pcrel t0, fw_arg1
  61. st.d a1, t0, 0
  62. la.pcrel t0, fw_arg2
  63. st.d a2, t0, 0
  64. /* KSave3 used for percpu base, initialized as 0 */
  65. csrwr zero, PERCPU_BASE_KS
  66. /* GPR21 used for percpu base (runtime), initialized as 0 */
  67. move u0, zero
  68. la.pcrel tp, init_thread_union
  69. /* Set the SP after an empty pt_regs. */
  70. PTR_LI sp, (_THREAD_SIZE - PT_SIZE)
  71. PTR_ADD sp, sp, tp
  72. set_saved_sp sp, t0, t1
  73. bl start_kernel
  74. ASM_BUG()
  75. SYM_CODE_END(kernel_entry)
  76. #ifdef CONFIG_SMP
  77. /*
  78. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  79. * function after setting up the stack and tp registers.
  80. */
  81. SYM_CODE_START(smpboot_entry)
  82. li.d t0, CSR_DMW0_INIT # UC, PLV0
  83. csrwr t0, LOONGARCH_CSR_DMWIN0
  84. li.d t0, CSR_DMW1_INIT # CA, PLV0
  85. csrwr t0, LOONGARCH_CSR_DMWIN1
  86. la.abs t0, 0f
  87. jr t0
  88. 0:
  89. /* Enable PG */
  90. li.w t0, 0xb0 # PLV=0, IE=0, PG=1
  91. csrwr t0, LOONGARCH_CSR_CRMD
  92. li.w t0, 0x04 # PLV=0, PIE=1, PWE=0
  93. csrwr t0, LOONGARCH_CSR_PRMD
  94. li.w t0, 0x00 # FPE=0, SXE=0, ASXE=0, BTE=0
  95. csrwr t0, LOONGARCH_CSR_EUEN
  96. la.abs t0, cpuboot_data
  97. ld.d sp, t0, CPU_BOOT_STACK
  98. ld.d tp, t0, CPU_BOOT_TINFO
  99. bl start_secondary
  100. ASM_BUG()
  101. SYM_CODE_END(smpboot_entry)
  102. #endif /* CONFIG_SMP */
  103. SYM_ENTRY(kernel_entry_end, SYM_L_GLOBAL, SYM_A_NONE)