head.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #include <linux/linkage.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/entry.h>
  17. #include <asm/arcregs.h>
  18. #include <asm/cache.h>
  19. #include <asm/irqflags.h>
  20. .macro CPU_EARLY_SETUP
  21. ; Setting up Vectror Table (in case exception happens in early boot
  22. sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE]
  23. ; Disable I-cache/D-cache if kernel so configured
  24. lr r5, [ARC_REG_IC_BCR]
  25. breq r5, 0, 1f ; I$ doesn't exist
  26. lr r5, [ARC_REG_IC_CTRL]
  27. #ifdef CONFIG_ARC_HAS_ICACHE
  28. bclr r5, r5, 0 ; 0 - Enable, 1 is Disable
  29. #else
  30. bset r5, r5, 0 ; I$ exists, but is not used
  31. #endif
  32. sr r5, [ARC_REG_IC_CTRL]
  33. 1:
  34. lr r5, [ARC_REG_DC_BCR]
  35. breq r5, 0, 1f ; D$ doesn't exist
  36. lr r5, [ARC_REG_DC_CTRL]
  37. bclr r5, r5, 6 ; Invalidate (discard w/o wback)
  38. #ifdef CONFIG_ARC_HAS_DCACHE
  39. bclr r5, r5, 0 ; Enable (+Inv)
  40. #else
  41. bset r5, r5, 0 ; Disable (+Inv)
  42. #endif
  43. sr r5, [ARC_REG_DC_CTRL]
  44. 1:
  45. #ifdef CONFIG_ISA_ARCV2
  46. ; Unaligned access is disabled at reset, so re-enable early as
  47. ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access
  48. ; by default
  49. lr r5, [status32]
  50. bset r5, r5, STATUS_AD_BIT
  51. kflag r5
  52. #endif
  53. .endm
  54. .section .init.text, "ax",@progbits
  55. ;----------------------------------------------------------------
  56. ; Default Reset Handler (jumped into from Reset vector)
  57. ; - Don't clobber r0,r1,r2 as they might have u-boot provided args
  58. ; - Platforms can override this weak version if needed
  59. ;----------------------------------------------------------------
  60. WEAK(res_service)
  61. j stext
  62. END(res_service)
  63. ;----------------------------------------------------------------
  64. ; Kernel Entry point
  65. ;----------------------------------------------------------------
  66. ENTRY(stext)
  67. CPU_EARLY_SETUP
  68. #ifdef CONFIG_SMP
  69. GET_CPU_ID r5
  70. cmp r5, 0
  71. mov.nz r0, r5
  72. bz .Lmaster_proceed
  73. ; Non-Masters wait for Master to boot enough and bring them up
  74. ; when they resume, tail-call to entry point
  75. mov blink, @first_lines_of_secondary
  76. j arc_platform_smp_wait_to_boot
  77. .Lmaster_proceed:
  78. #endif
  79. ; Clear BSS before updating any globals
  80. ; XXX: use ZOL here
  81. mov r5, __bss_start
  82. sub r6, __bss_stop, r5
  83. lsr.f lp_count, r6, 2
  84. lpnz 1f
  85. st.ab 0, [r5, 4]
  86. 1:
  87. ; Uboot - kernel ABI
  88. ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2
  89. ; r1 = magic number (always zero as of now)
  90. ; r2 = pointer to uboot provided cmdline or external DTB in mem
  91. ; These are handled later in handle_uboot_args()
  92. st r0, [@uboot_tag]
  93. st r1, [@uboot_magic]
  94. st r2, [@uboot_arg]
  95. ; setup "current" tsk and optionally cache it in dedicated r25
  96. mov r9, @init_task
  97. SET_CURR_TASK_ON_CPU r9, r0 ; r9 = tsk, r0 = scratch
  98. ; setup stack (fp, sp)
  99. mov fp, 0
  100. ; tsk->thread_info is really a PAGE, whose bottom hoists stack
  101. GET_TSK_STACK_BASE r9, sp ; r9 = tsk, sp = stack base(output)
  102. j start_kernel ; "C" entry point
  103. END(stext)
  104. #ifdef CONFIG_SMP
  105. ;----------------------------------------------------------------
  106. ; First lines of code run by secondary before jumping to 'C'
  107. ;----------------------------------------------------------------
  108. .section .text, "ax",@progbits
  109. ENTRY(first_lines_of_secondary)
  110. ; setup per-cpu idle task as "current" on this CPU
  111. ld r0, [@secondary_idle_tsk]
  112. SET_CURR_TASK_ON_CPU r0, r1
  113. ; setup stack (fp, sp)
  114. mov fp, 0
  115. ; set it's stack base to tsk->thread_info bottom
  116. GET_TSK_STACK_BASE r0, sp
  117. j start_kernel_secondary
  118. END(first_lines_of_secondary)
  119. #endif