Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. /*
  2. * linux/arch/arm/kernel/head.S
  3. *
  4. * Copyright (C) 1994-2002 Russell King
  5. * Copyright (c) 2003 ARM Limited
  6. * All Rights Reserved
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Kernel startup code for all 32-bit CPUs
  13. */
  14. #include <linux/linkage.h>
  15. #include <linux/init.h>
  16.  
  17. #include <asm/assembler.h>
  18. #include <asm/domain.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/asm-offsets.h>
  21. #include <asm/memory.h>
  22. #include <asm/thread_info.h>
  23. #include <asm/system.h>
  24.  
  25. #if (PHYS_OFFSET & 0x001fffff)
  26. #error "PHYS_OFFSET must be at an even 2MiB boundary!"
  27. #endif
  28.  
  29. #define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
  30. #define KERNEL_RAM_PADDR (PHYS_OFFSET + TEXT_OFFSET)
  31.  
  32.  
  33. /*
  34. * swapper_pg_dir is the virtual address of the initial page table.
  35. * We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we must
  36. * make sure that KERNEL_RAM_VADDR is correctly set. Currently, we expect
  37. * the least significant 16 bits to be 0x8000, but we could probably
  38. * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
  39. */
  40. #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
  41. #error KERNEL_RAM_VADDR must start at 0xXXXX8000
  42. #endif
  43.  
  44. .globl swapper_pg_dir
  45. .equ swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
  46.  
  47. .macro pgtbl, rd
  48. ldr \rd, =(KERNEL_RAM_PADDR - 0x4000)
  49. .endm
  50.  
  51. #ifdef CONFIG_XIP_KERNEL
  52. #define KERNEL_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
  53. #define KERNEL_END _edata_loc
  54. #else
  55. #define KERNEL_START KERNEL_RAM_VADDR
  56. #define KERNEL_END _end
  57. #endif
  58.  
  59. /*
  60. * Kernel startup entry point.
  61. * ---------------------------
  62. *
  63. * This is normally called from the decompressor code. The requirements
  64. * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
  65. * r1 = machine nr, r2 = atags pointer.
  66. *
  67. * This code is mostly position independent, so if you link the kernel at
  68. * 0xc0008000, you call this at __pa(0xc0008000).
  69. *
  70. * See linux/arch/arm/tools/mach-types for the complete list of machine
  71. * numbers for r1.
  72. *
  73. * We're trying to keep crap to a minimum; DO NOT add any machine specific
  74. * crap here - that's what the boot loader (or in extreme, well justified
  75. * circumstances, zImage) is for.
  76. */
  77. __HEAD
  78. ENTRY(stext)
  79. setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
  80. @ and irqs disabled
  81. mrc p15, 0, r9, c0, c0 @ get processor id
  82. bl __lookup_processor_type @ r5=procinfo r9=cpuid
  83. movs r10, r5 @ invalid processor (r5=0)?
  84. beq __error_p @ yes, error 'p'
  85. bl __lookup_machine_type @ r5=machinfo
  86. movs r8, r5 @ invalid machine (r5=0)?
  87. beq __error_a @ yes, error 'a'
  88. bl __vet_atags
  89. bl __create_page_tables
  90.  
  91. /*
  92. * second vibration test
  93. */
  94.  
  95. /*
  96. * The following calls CPU specific code in a position independent
  97. * manner. See arch/arm/mm/proc-*.S for details. r10 = base of
  98. * xxx_proc_info structure selected by __lookup_machine_type
  99. * above. On return, the CPU will be ready for the MMU to be
  100. * turned on, and r0 will hold the CPU control register value.
  101. */
  102. ldr r13, __switch_data @ address to jump to after
  103. @ mmu has been enabled
  104. adr lr, BSYM(__enable_mmu) @ return (PIC) address
  105. ARM( add pc, r10, #PROCINFO_INITFUNC )
  106. THUMB( add r12, r10, #PROCINFO_INITFUNC )
  107. THUMB( mov pc, r12 )
  108. ENDPROC(stext)
  109.  
  110. #if defined(CONFIG_SMP)
  111. ENTRY(secondary_startup)
  112. /*
  113. * Common entry point for secondary CPUs.
  114. *
  115. * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
  116. * the processor type - there is no need to check the machine type
  117. * as it has already been validated by the primary processor.
  118. */
  119. setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9
  120. mrc p15, 0, r9, c0, c0 @ get processor id
  121. bl __lookup_processor_type
  122. movs r10, r5 @ invalid processor?
  123. moveq r0, #'p' @ yes, error 'p'
  124. beq __error
  125. /*
  126. * Use the page tables supplied from __cpu_up.
  127. */
  128. adr r4, __secondary_data
  129. ldmia r4, {r5, r7, r12} @ address to jump to after
  130. sub r4, r4, r5 @ mmu has been enabled
  131. ldr r4, [r7, r4] @ get secondary_data.pgdir
  132. adr lr, BSYM(__enable_mmu) @ return address
  133. mov r13, r12 @ __secondary_switched address
  134. ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor
  135. @ (return control reg)
  136. THUMB( add r12, r10, #PROCINFO_INITFUNC )
  137. THUMB( mov pc, r12 )
  138. ENDPROC(secondary_startup)
  139.  
  140. /*
  141. * r6 = &secondary_data
  142. */
  143. ENTRY(__secondary_switched)
  144. ldr sp, [r7, #4] @ get secondary_data.stack
  145. mov fp, #0
  146. b secondary_start_kernel
  147. ENDPROC(__secondary_switched)
  148.  
  149. .type __secondary_data, %object
  150. __secondary_data:
  151. .long .
  152. .long secondary_data
  153. .long __secondary_switched
  154. #endif /* defined(CONFIG_SMP) */
  155.  
  156.  
  157.  
  158. /*
  159. * Setup common bits before finally enabling the MMU. Essentially
  160. * this is just loading the page table pointer and domain access
  161. * registers.
  162. */
  163. __enable_mmu:
  164.  
  165.  
  166. #ifdef CONFIG_ALIGNMENT_TRAP
  167. orr r0, r0, #CR_A
  168. #else
  169. bic r0, r0, #CR_A
  170. #endif
  171. #ifdef CONFIG_CPU_DCACHE_DISABLE
  172. bic r0, r0, #CR_C
  173. #endif
  174. #ifdef CONFIG_CPU_BPREDICT_DISABLE
  175. bic r0, r0, #CR_Z
  176. #endif
  177. #ifdef CONFIG_CPU_ICACHE_DISABLE
  178. bic r0, r0, #CR_I
  179. #endif
  180. /* ldr r1, =0xa900080c
  181. ldr r0, [r1]
  182. orr r0, r0, #0x20
  183. str r0, [r1]
  184. */
  185. mov r5, #(domain_val(DOMAIN_USER, DOMAIN_CLIENT) | \
  186. domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
  187. domain_val(DOMAIN_TABLE, DOMAIN_CLIENT) | \
  188. domain_val(DOMAIN_IO, DOMAIN_CLIENT))
  189. mcr p15, 0, r5, c3, c0, 0 @ load domain access register
  190. mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
  191. b __turn_mmu_on
  192.  
  193. ENDPROC(__enable_mmu)
  194.  
  195. /*
  196. * Enable the MMU. This completely changes the structure of the visible
  197. * memory space. You will not be able to trace execution through this.
  198. * If you have an enquiry about this, *please* check the linux-arm-kernel
  199. * mailing list archives BEFORE sending another post to the list.
  200. *
  201. * r0 = cp#15 control register
  202. * r13 = *virtual* address to jump to upon completion
  203. *
  204. * other registers depend on the function called upon completion
  205. */
  206. .align 5
  207. __turn_mmu_on:
  208. mov r0, r0
  209. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  210. mrc p15, 0, r3, c0, c0, 0 @ read id reg
  211. mov r3, r3
  212. mov r3, r13
  213. mov pc, r3
  214. ENDPROC(__turn_mmu_on)
  215.  
  216.  
  217. /*
  218. * Setup the initial page tables. We only setup the barest
  219. * amount which are required to get the kernel running, which
  220. * generally means mapping in the kernel code.
  221. *
  222. * r8 = machinfo
  223. * r9 = cpuid
  224. * r10 = procinfo
  225. *
  226. * Returns:
  227. * r0, r3, r6, r7 corrupted
  228. * r4 = physical page table address
  229. */
  230. __create_page_tables:
  231. pgtbl r4 @ page table address
  232.  
  233. /*
  234. * Clear the 16K level 1 swapper page table
  235. */
  236. mov r0, r4
  237. mov r3, #0
  238. add r6, r0, #0x4000
  239. 1: str r3, [r0], #4
  240. str r3, [r0], #4
  241. str r3, [r0], #4
  242. str r3, [r0], #4
  243. teq r0, r6
  244. bne 1b
  245.  
  246. ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
  247.  
  248. /*
  249. * Create identity mapping for first MB of kernel to
  250. * cater for the MMU enable. This identity mapping
  251. * will be removed by paging_init(). We use our current program
  252. * counter to determine corresponding section base address.
  253. */
  254. mov r6, pc
  255. mov r6, r6, lsr #20 @ start of kernel section
  256. orr r3, r7, r6, lsl #20 @ flags + kernel base
  257. str r3, [r4, r6, lsl #2] @ identity mapping
  258.  
  259. /*
  260. * Now setup the pagetables for our kernel direct
  261. * mapped region.
  262. */
  263. add r0, r4, #(KERNEL_START & 0xff000000) >> 18
  264. str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!
  265. ldr r6, =(KERNEL_END - 1)
  266. add r0, r0, #4
  267. add r6, r4, r6, lsr #18
  268. 1: cmp r0, r6
  269. add r3, r3, #1 << 20
  270. strls r3, [r0], #4
  271. bls 1b
  272.  
  273. #ifdef CONFIG_XIP_KERNEL
  274. /*
  275. * Map some ram to cover our .data and .bss areas.
  276. */
  277. orr r3, r7, #(KERNEL_RAM_PADDR & 0xff000000)
  278. .if (KERNEL_RAM_PADDR & 0x00f00000)
  279. orr r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000)
  280. .endif
  281. add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> 18
  282. str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]!
  283. ldr r6, =(_end - 1)
  284. add r0, r0, #4
  285. add r6, r4, r6, lsr #18
  286. 1: cmp r0, r6
  287. add r3, r3, #1 << 20
  288. strls r3, [r0], #4
  289. bls 1b
  290. #endif
  291.  
  292. /*
  293. * Then map first 1MB of ram in case it contains our boot params.
  294. */
  295. add r0, r4, #PAGE_OFFSET >> 18
  296. orr r6, r7, #(PHYS_OFFSET & 0xff000000)
  297. .if (PHYS_OFFSET & 0x00f00000)
  298. orr r6, r6, #(PHYS_OFFSET & 0x00f00000)
  299. .endif
  300. str r6, [r0]
  301.  
  302. #ifdef CONFIG_DEBUG_LL
  303. ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
  304. /*
  305. * Map in IO space for serial debugging.
  306. * This allows debug messages to be output
  307. * via a serial console before paging_init.
  308. */
  309. ldr r3, [r8, #MACHINFO_PGOFFIO]
  310. add r0, r4, r3
  311. rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long)
  312. cmp r3, #0x0800 @ limit to 512MB
  313. movhi r3, #0x0800
  314. add r6, r0, r3
  315. ldr r3, [r8, #MACHINFO_PHYSIO]
  316. orr r3, r3, r7
  317. 1: str r3, [r0], #4
  318. add r3, r3, #1 << 20
  319. teq r0, r6
  320. bne 1b
  321. #if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS)
  322. /*
  323. * If we're using the NetWinder or CATS, we also need to map
  324. * in the 16550-type serial port for the debug messages
  325. */
  326. add r0, r4, #0xff000000 >> 18
  327. orr r3, r7, #0x7c000000
  328. str r3, [r0]
  329. #endif
  330. /*
  331. #ifdef CONFIG_MACH_HTCLEO
  332. *
  333. * I small life sign test for HTC Leo
  334. * We mapping the addresses for the vibration GPIO
  335. *
  336. add r0, r4, #0xff000000 >> 18
  337. orr r3, r7, #0xA9000000
  338. str r3, [r0]
  339. #endif
  340. */
  341. #ifdef CONFIG_ARCH_RPC
  342. /*
  343. * Map in screen at 0x02000000 & SCREEN2_BASE
  344. * Similar reasons here - for debug. This is
  345. * only for Acorn RiscPC architectures.
  346. */
  347. add r0, r4, #0x02000000 >> 18
  348. orr r3, r7, #0x02000000
  349. str r3, [r0]
  350. add r0, r4, #0xd8000000 >> 18
  351. str r3, [r0]
  352. #endif
  353. #endif
  354. mov pc, lr
  355. ENDPROC(__create_page_tables)
  356. .ltorg
  357.  
  358. #include "head-common.S"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement