head.S 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * linux/arch/arm/boot/compressed/head.S
  3. *
  4. * Copyright (C) 1996-2002 Russell King
  5. * Copyright (C) 2004 Hyok S. Choi (MPU support)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/assembler.h>
  13. .arch armv7-a
  14. /*
  15. * Debugging stuff
  16. *
  17. * Note that these macros must not contain any code which is not
  18. * 100% relocatable. Any attempt to do so will result in a crash.
  19. * Please select one of the following when turning on debugging.
  20. */
  21. #ifdef DEBUG
  22. #if defined(CONFIG_DEBUG_ICEDCC)
  23. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
  24. .macro loadsp, rb, tmp
  25. .endm
  26. .macro writeb, ch, rb
  27. mcr p14, 0, \ch, c0, c5, 0
  28. .endm
  29. #elif defined(CONFIG_CPU_XSCALE)
  30. .macro loadsp, rb, tmp
  31. .endm
  32. .macro writeb, ch, rb
  33. mcr p14, 0, \ch, c8, c0, 0
  34. .endm
  35. #else
  36. .macro loadsp, rb, tmp
  37. .endm
  38. .macro writeb, ch, rb
  39. mcr p14, 0, \ch, c1, c0, 0
  40. .endm
  41. #endif
  42. #else
  43. #include CONFIG_DEBUG_LL_INCLUDE
  44. .macro writeb, ch, rb
  45. senduart \ch, \rb
  46. .endm
  47. #if defined(CONFIG_ARCH_SA1100)
  48. .macro loadsp, rb, tmp
  49. mov \rb, #0x80000000 @ physical base address
  50. #ifdef CONFIG_DEBUG_LL_SER3
  51. add \rb, \rb, #0x00050000 @ Ser3
  52. #else
  53. add \rb, \rb, #0x00010000 @ Ser1
  54. #endif
  55. .endm
  56. #elif defined(CONFIG_ARCH_S3C24XX)
  57. .macro loadsp, rb, tmp
  58. mov \rb, #0x50000000
  59. add \rb, \rb, #0x4000 * CONFIG_S3C_LOWLEVEL_UART_PORT
  60. .endm
  61. #else
  62. .macro loadsp, rb, tmp
  63. addruart \rb, \tmp
  64. .endm
  65. #endif
  66. #endif
  67. #endif
  68. .macro kputc,val
  69. mov r0, \val
  70. bl putc
  71. .endm
  72. .macro kphex,val,len
  73. mov r0, \val
  74. mov r1, #\len
  75. bl phex
  76. .endm
  77. .macro debug_reloc_start
  78. #ifdef DEBUG
  79. kputc #'\n'
  80. kphex r6, 8 /* processor id */
  81. kputc #':'
  82. kphex r7, 8 /* architecture id */
  83. #ifdef CONFIG_CPU_CP15
  84. kputc #':'
  85. mrc p15, 0, r0, c1, c0
  86. kphex r0, 8 /* control reg */
  87. #endif
  88. kputc #'\n'
  89. kphex r5, 8 /* decompressed kernel start */
  90. kputc #'-'
  91. kphex r9, 8 /* decompressed kernel end */
  92. kputc #'>'
  93. kphex r4, 8 /* kernel execution address */
  94. kputc #'\n'
  95. #endif
  96. .endm
  97. .macro debug_reloc_end
  98. #ifdef DEBUG
  99. kphex r5, 8 /* end of kernel */
  100. kputc #'\n'
  101. mov r0, r4
  102. bl memdump /* dump 256 bytes at start of kernel */
  103. #endif
  104. .endm
  105. .section ".start", #alloc, #execinstr
  106. /*
  107. * sort out different calling conventions
  108. */
  109. .align
  110. .arm @ Always enter in ARM state
  111. start:
  112. .type start,#function
  113. .rept 7
  114. mov r0, r0
  115. .endr
  116. ARM( mov r0, r0 )
  117. ARM( b 1f )
  118. THUMB( adr r12, BSYM(1f) )
  119. THUMB( bx r12 )
  120. .word 0x016f2818 @ Magic numbers to help the loader
  121. .word start @ absolute load/run zImage address
  122. .word _edata @ zImage end address
  123. THUMB( .thumb )
  124. 1:
  125. mrs r9, cpsr
  126. #ifdef CONFIG_ARM_VIRT_EXT
  127. bl __hyp_stub_install @ get into SVC mode, reversibly
  128. #endif
  129. mov r7, r1 @ save architecture ID
  130. mov r8, r2 @ save atags pointer
  131. #ifndef __ARM_ARCH_2__
  132. /*
  133. * Booting from Angel - need to enter SVC mode and disable
  134. * FIQs/IRQs (numeric definitions from angel arm.h source).
  135. * We only do this if we were in user mode on entry.
  136. */
  137. mrs r2, cpsr @ get current mode
  138. tst r2, #3 @ not user?
  139. bne not_angel
  140. mov r0, #0x17 @ angel_SWIreason_EnterSVC
  141. ARM( swi 0x123456 ) @ angel_SWI_ARM
  142. THUMB( svc 0xab ) @ angel_SWI_THUMB
  143. not_angel:
  144. safe_svcmode_maskall r0
  145. msr spsr_cxsf, r9 @ Save the CPU boot mode in
  146. @ SPSR
  147. #else
  148. teqp pc, #0x0c000003 @ turn off interrupts
  149. #endif
  150. /*
  151. * Note that some cache flushing and other stuff may
  152. * be needed here - is there an Angel SWI call for this?
  153. */
  154. /*
  155. * some architecture specific code can be inserted
  156. * by the linker here, but it should preserve r7, r8, and r9.
  157. */
  158. .text
  159. #ifdef CONFIG_AUTO_ZRELADDR
  160. @ determine final kernel image address
  161. mov r4, pc
  162. and r4, r4, #0xf8000000
  163. add r4, r4, #TEXT_OFFSET
  164. #else
  165. ldr r4, =zreladdr
  166. #endif
  167. bl cache_on
  168. restart: adr r0, LC0
  169. ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
  170. ldr sp, [r0, #28]
  171. /*
  172. * We might be running at a different address. We need
  173. * to fix up various pointers.
  174. */
  175. sub r0, r0, r1 @ calculate the delta offset
  176. add r6, r6, r0 @ _edata
  177. add r10, r10, r0 @ inflated kernel size location
  178. /*
  179. * The kernel build system appends the size of the
  180. * decompressed kernel at the end of the compressed data
  181. * in little-endian form.
  182. */
  183. ldrb r9, [r10, #0]
  184. ldrb lr, [r10, #1]
  185. orr r9, r9, lr, lsl #8
  186. ldrb lr, [r10, #2]
  187. ldrb r10, [r10, #3]
  188. orr r9, r9, lr, lsl #16
  189. orr r9, r9, r10, lsl #24
  190. #ifndef CONFIG_ZBOOT_ROM
  191. /* malloc space is above the relocated stack (64k max) */
  192. add sp, sp, r0
  193. add r10, sp, #0x10000
  194. #else
  195. /*
  196. * With ZBOOT_ROM the bss/stack is non relocatable,
  197. * but someone could still run this code from RAM,
  198. * in which case our reference is _edata.
  199. */
  200. mov r10, r6
  201. #endif
  202. mov r5, #0 @ init dtb size to 0
  203. #ifdef CONFIG_ARM_APPENDED_DTB
  204. /*
  205. * r0 = delta
  206. * r2 = BSS start
  207. * r3 = BSS end
  208. * r4 = final kernel address
  209. * r5 = appended dtb size (still unknown)
  210. * r6 = _edata
  211. * r7 = architecture ID
  212. * r8 = atags/device tree pointer
  213. * r9 = size of decompressed image
  214. * r10 = end of this image, including bss/stack/malloc space if non XIP
  215. * r11 = GOT start
  216. * r12 = GOT end
  217. * sp = stack pointer
  218. *
  219. * if there are device trees (dtb) appended to zImage, advance r10 so that the
  220. * dtb data will get relocated along with the kernel if necessary.
  221. */
  222. ldr lr, [r6, #0]
  223. #ifndef __ARMEB__
  224. ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
  225. #else
  226. ldr r1, =0xd00dfeed
  227. #endif
  228. cmp lr, r1
  229. bne dtb_check_done @ not found
  230. #ifdef CONFIG_ARM_ATAG_DTB_COMPAT
  231. /*
  232. * OK... Let's do some funky business here.
  233. * If we do have a DTB appended to zImage, and we do have
  234. * an ATAG list around, we want the later to be translated
  235. * and folded into the former here. To be on the safe side,
  236. * let's temporarily move the stack away into the malloc
  237. * area. No GOT fixup has occurred yet, but none of the
  238. * code we're about to call uses any global variable.
  239. */
  240. add sp, sp, #0x10000
  241. stmfd sp!, {r0-r3, ip, lr}
  242. mov r0, r8
  243. mov r1, r6
  244. sub r2, sp, r6
  245. bl atags_to_fdt
  246. /*
  247. * If returned value is 1, there is no ATAG at the location
  248. * pointed by r8. Try the typical 0x100 offset from start
  249. * of RAM and hope for the best.
  250. */
  251. cmp r0, #1
  252. sub r0, r4, #TEXT_OFFSET
  253. add r0, r0, #0x100
  254. mov r1, r6
  255. sub r2, sp, r6
  256. bleq atags_to_fdt
  257. ldmfd sp!, {r0-r3, ip, lr}
  258. sub sp, sp, #0x10000
  259. #endif
  260. mov r8, r6 @ use the appended device tree
  261. /*
  262. * Make sure that the DTB doesn't end up in the final
  263. * kernel's .bss area. To do so, we adjust the decompressed
  264. * kernel size to compensate if that .bss size is larger
  265. * than the relocated code.
  266. */
  267. ldr r5, =_kernel_bss_size
  268. adr r1, wont_overwrite
  269. sub r1, r6, r1
  270. subs r1, r5, r1
  271. addhi r9, r9, r1
  272. /* Get the dtb's size */
  273. ldr r5, [r6, #4]
  274. #ifndef __ARMEB__
  275. /* convert r5 (dtb size) to little endian */
  276. eor r1, r5, r5, ror #16
  277. bic r1, r1, #0x00ff0000
  278. mov r5, r5, ror #8
  279. eor r5, r5, r1, lsr #8
  280. #endif
  281. /* preserve 64-bit alignment */
  282. add r5, r5, #7
  283. bic r5, r5, #7
  284. /* relocate some pointers past the appended dtb */
  285. add r6, r6, r5
  286. add r10, r10, r5
  287. add sp, sp, r5
  288. dtb_check_done:
  289. #endif
  290. /*
  291. * Check to see if we will overwrite ourselves.
  292. * r4 = final kernel address
  293. * r9 = size of decompressed image
  294. * r10 = end of this image, including bss/stack/malloc space if non XIP
  295. * We basically want:
  296. * r4 - 16k page directory >= r10 -> OK
  297. * r4 + image length <= address of wont_overwrite -> OK
  298. */
  299. add r10, r10, #16384
  300. cmp r4, r10
  301. bhs wont_overwrite
  302. add r10, r4, r9
  303. adr r9, wont_overwrite
  304. cmp r10, r9
  305. bls wont_overwrite
  306. /*
  307. * Relocate ourselves past the end of the decompressed kernel.
  308. * r6 = _edata
  309. * r10 = end of the decompressed kernel
  310. * Because we always copy ahead, we need to do it from the end and go
  311. * backward in case the source and destination overlap.
  312. */
  313. /*
  314. * Bump to the next 256-byte boundary with the size of
  315. * the relocation code added. This avoids overwriting
  316. * ourself when the offset is small.
  317. */
  318. add r10, r10, #((reloc_code_end - restart + 256) & ~255)
  319. bic r10, r10, #255
  320. /* Get start of code we want to copy and align it down. */
  321. adr r5, restart
  322. bic r5, r5, #31
  323. /* Relocate the hyp vector base if necessary */
  324. #ifdef CONFIG_ARM_VIRT_EXT
  325. mrs r0, spsr
  326. and r0, r0, #MODE_MASK
  327. cmp r0, #HYP_MODE
  328. bne 1f
  329. bl __hyp_get_vectors
  330. sub r0, r0, r5
  331. add r0, r0, r10
  332. bl __hyp_set_vectors
  333. 1:
  334. #endif
  335. sub r9, r6, r5 @ size to copy
  336. add r9, r9, #31 @ rounded up to a multiple
  337. bic r9, r9, #31 @ ... of 32 bytes
  338. add r6, r9, r5
  339. add r9, r9, r10
  340. 1: ldmdb r6!, {r0 - r3, r10 - r12, lr}
  341. cmp r6, r5
  342. stmdb r9!, {r0 - r3, r10 - r12, lr}
  343. bhi 1b
  344. /* Preserve offset to relocated code. */
  345. sub r6, r9, r6
  346. #ifndef CONFIG_ZBOOT_ROM
  347. /* cache_clean_flush may use the stack, so relocate it */
  348. add sp, sp, r6
  349. #endif
  350. bl cache_clean_flush
  351. adr r0, BSYM(restart)
  352. add r0, r0, r6
  353. mov pc, r0
  354. wont_overwrite:
  355. /*
  356. * If delta is zero, we are running at the address we were linked at.
  357. * r0 = delta
  358. * r2 = BSS start
  359. * r3 = BSS end
  360. * r4 = kernel execution address
  361. * r5 = appended dtb size (0 if not present)
  362. * r7 = architecture ID
  363. * r8 = atags pointer
  364. * r11 = GOT start
  365. * r12 = GOT end
  366. * sp = stack pointer
  367. */
  368. orrs r1, r0, r5
  369. beq not_relocated
  370. add r11, r11, r0
  371. add r12, r12, r0
  372. #ifndef CONFIG_ZBOOT_ROM
  373. /*
  374. * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
  375. * we need to fix up pointers into the BSS region.
  376. * Note that the stack pointer has already been fixed up.
  377. */
  378. add r2, r2, r0
  379. add r3, r3, r0
  380. /*
  381. * Relocate all entries in the GOT table.
  382. * Bump bss entries to _edata + dtb size
  383. */
  384. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  385. add r1, r1, r0 @ This fixes up C references
  386. cmp r1, r2 @ if entry >= bss_start &&
  387. cmphs r3, r1 @ bss_end > entry
  388. addhi r1, r1, r5 @ entry += dtb size
  389. str r1, [r11], #4 @ next entry
  390. cmp r11, r12
  391. blo 1b
  392. /* bump our bss pointers too */
  393. add r2, r2, r5
  394. add r3, r3, r5
  395. #else
  396. /*
  397. * Relocate entries in the GOT table. We only relocate
  398. * the entries that are outside the (relocated) BSS region.
  399. */
  400. 1: ldr r1, [r11, #0] @ relocate entries in the GOT
  401. cmp r1, r2 @ entry < bss_start ||
  402. cmphs r3, r1 @ _end < entry
  403. addlo r1, r1, r0 @ table. This fixes up the
  404. str r1, [r11], #4 @ C references.
  405. cmp r11, r12
  406. blo 1b
  407. #endif
  408. not_relocated: mov r0, #0
  409. 1: str r0, [r2], #4 @ clear bss
  410. str r0, [r2], #4
  411. str r0, [r2], #4
  412. str r0, [r2], #4
  413. cmp r2, r3
  414. blo 1b
  415. /*
  416. * The C runtime environment should now be setup sufficiently.
  417. * Set up some pointers, and start decompressing.
  418. * r4 = kernel execution address
  419. * r7 = architecture ID
  420. * r8 = atags pointer
  421. */
  422. mov r0, r4
  423. mov r1, sp @ malloc space above stack
  424. add r2, sp, #0x10000 @ 64k max
  425. mov r3, r7
  426. bl decompress_kernel
  427. bl cache_clean_flush
  428. bl cache_off
  429. mov r1, r7 @ restore architecture number
  430. mov r2, r8 @ restore atags pointer
  431. #ifdef CONFIG_ARM_VIRT_EXT
  432. mrs r0, spsr @ Get saved CPU boot mode
  433. and r0, r0, #MODE_MASK
  434. cmp r0, #HYP_MODE @ if not booted in HYP mode...
  435. bne __enter_kernel @ boot kernel directly
  436. adr r12, .L__hyp_reentry_vectors_offset
  437. ldr r0, [r12]
  438. add r0, r0, r12
  439. bl __hyp_set_vectors
  440. __HVC(0) @ otherwise bounce to hyp mode
  441. b . @ should never be reached
  442. .align 2
  443. .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
  444. #else
  445. b __enter_kernel
  446. #endif
  447. .align 2
  448. .type LC0, #object
  449. LC0: .word LC0 @ r1
  450. .word __bss_start @ r2
  451. .word _end @ r3
  452. .word _edata @ r6
  453. .word input_data_end - 4 @ r10 (inflated size location)
  454. .word _got_start @ r11
  455. .word _got_end @ ip
  456. .word .L_user_stack_end @ sp
  457. .size LC0, . - LC0
  458. #ifdef CONFIG_ARCH_RPC
  459. .globl params
  460. params: ldr r0, =0x10000100 @ params_phys for RPC
  461. mov pc, lr
  462. .ltorg
  463. .align
  464. #endif
  465. /*
  466. * Turn on the cache. We need to setup some page tables so that we
  467. * can have both the I and D caches on.
  468. *
  469. * We place the page tables 16k down from the kernel execution address,
  470. * and we hope that nothing else is using it. If we're using it, we
  471. * will go pop!
  472. *
  473. * On entry,
  474. * r4 = kernel execution address
  475. * r7 = architecture number
  476. * r8 = atags pointer
  477. * On exit,
  478. * r0, r1, r2, r3, r9, r10, r12 corrupted
  479. * This routine must preserve:
  480. * r4, r7, r8
  481. */
  482. .align 5
  483. cache_on: mov r3, #8 @ cache_on function
  484. b call_cache_fn
  485. /*
  486. * Initialize the highest priority protection region, PR7
  487. * to cover all 32bit address and cacheable and bufferable.
  488. */
  489. __armv4_mpu_cache_on:
  490. mov r0, #0x3f @ 4G, the whole
  491. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  492. mcr p15, 0, r0, c6, c7, 1
  493. mov r0, #0x80 @ PR7
  494. mcr p15, 0, r0, c2, c0, 0 @ D-cache on
  495. mcr p15, 0, r0, c2, c0, 1 @ I-cache on
  496. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  497. mov r0, #0xc000
  498. mcr p15, 0, r0, c5, c0, 1 @ I-access permission
  499. mcr p15, 0, r0, c5, c0, 0 @ D-access permission
  500. mov r0, #0
  501. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  502. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  503. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  504. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  505. @ ...I .... ..D. WC.M
  506. orr r0, r0, #0x002d @ .... .... ..1. 11.1
  507. orr r0, r0, #0x1000 @ ...1 .... .... ....
  508. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  509. mov r0, #0
  510. mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
  511. mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
  512. mov pc, lr
  513. __armv3_mpu_cache_on:
  514. mov r0, #0x3f @ 4G, the whole
  515. mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
  516. mov r0, #0x80 @ PR7
  517. mcr p15, 0, r0, c2, c0, 0 @ cache on
  518. mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
  519. mov r0, #0xc000
  520. mcr p15, 0, r0, c5, c0, 0 @ access permission
  521. mov r0, #0
  522. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  523. /*
  524. * ?? ARMv3 MMU does not allow reading the control register,
  525. * does this really work on ARMv3 MPU?
  526. */
  527. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  528. @ .... .... .... WC.M
  529. orr r0, r0, #0x000d @ .... .... .... 11.1
  530. /* ?? this overwrites the value constructed above? */
  531. mov r0, #0
  532. mcr p15, 0, r0, c1, c0, 0 @ write control reg
  533. /* ?? invalidate for the second time? */
  534. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  535. mov pc, lr
  536. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  537. #define CB_BITS 0x08
  538. #else
  539. #define CB_BITS 0x0c
  540. #endif
  541. __setup_mmu: sub r3, r4, #16384 @ Page directory size
  542. bic r3, r3, #0xff @ Align the pointer
  543. bic r3, r3, #0x3f00
  544. /*
  545. * Initialise the page tables, turning on the cacheable and bufferable
  546. * bits for the RAM area only.
  547. */
  548. mov r0, r3
  549. mov r9, r0, lsr #18
  550. mov r9, r9, lsl #18 @ start of RAM
  551. add r10, r9, #0x10000000 @ a reasonable RAM size
  552. mov r1, #0x12 @ XN|U + section mapping
  553. orr r1, r1, #3 << 10 @ AP=11
  554. add r2, r3, #16384
  555. 1: cmp r1, r9 @ if virt > start of RAM
  556. cmphs r10, r1 @ && end of RAM > virt
  557. bic r1, r1, #0x1c @ clear XN|U + C + B
  558. orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
  559. orrhs r1, r1, r6 @ set RAM section settings
  560. str r1, [r0], #4 @ 1:1 mapping
  561. add r1, r1, #1048576
  562. teq r0, r2
  563. bne 1b
  564. /*
  565. * If ever we are running from Flash, then we surely want the cache
  566. * to be enabled also for our execution instance... We map 2MB of it
  567. * so there is no map overlap problem for up to 1 MB compressed kernel.
  568. * If the execution is in RAM then we would only be duplicating the above.
  569. */
  570. orr r1, r6, #0x04 @ ensure B is set for this
  571. orr r1, r1, #3 << 10
  572. mov r2, pc
  573. mov r2, r2, lsr #20
  574. orr r1, r1, r2, lsl #20
  575. add r0, r3, r2, lsl #2
  576. str r1, [r0], #4
  577. add r1, r1, #1048576
  578. str r1, [r0]
  579. mov pc, lr
  580. ENDPROC(__setup_mmu)
  581. @ Enable unaligned access on v6, to allow better code generation
  582. @ for the decompressor C code:
  583. __armv6_mmu_cache_on:
  584. mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
  585. bic r0, r0, #2 @ A (no unaligned access fault)
  586. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  587. mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
  588. b __armv4_mmu_cache_on
  589. __arm926ejs_mmu_cache_on:
  590. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  591. mov r0, #4 @ put dcache in WT mode
  592. mcr p15, 7, r0, c15, c0, 0
  593. #endif
  594. __armv4_mmu_cache_on:
  595. mov r12, lr
  596. #ifdef CONFIG_MMU
  597. mov r6, #CB_BITS | 0x12 @ U
  598. bl __setup_mmu
  599. mov r0, #0
  600. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  601. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  602. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  603. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  604. orr r0, r0, #0x0030
  605. #ifdef CONFIG_CPU_ENDIAN_BE8
  606. orr r0, r0, #1 << 25 @ big-endian page tables
  607. #endif
  608. bl __common_mmu_cache_on
  609. mov r0, #0
  610. mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  611. #endif
  612. mov pc, r12
  613. __armv7_mmu_cache_on:
  614. mov r12, lr
  615. #ifdef CONFIG_MMU
  616. mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
  617. tst r11, #0xf @ VMSA
  618. movne r6, #CB_BITS | 0x02 @ !XN
  619. blne __setup_mmu
  620. mov r0, #0
  621. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  622. tst r11, #0xf @ VMSA
  623. mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
  624. #endif
  625. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  626. bic r0, r0, #1 << 28 @ clear SCTLR.TRE
  627. orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
  628. orr r0, r0, #0x003c @ write buffer
  629. bic r0, r0, #2 @ A (no unaligned access fault)
  630. orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
  631. @ (needed for ARM1176)
  632. #ifdef CONFIG_MMU
  633. #ifdef CONFIG_CPU_ENDIAN_BE8
  634. orr r0, r0, #1 << 25 @ big-endian page tables
  635. #endif
  636. mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
  637. orrne r0, r0, #1 @ MMU enabled
  638. movne r1, #0xfffffffd @ domain 0 = client
  639. bic r6, r6, #1 << 31 @ 32-bit translation system
  640. bic r6, r6, #3 << 0 @ use only ttbr0
  641. mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
  642. mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
  643. mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
  644. #endif
  645. mcr p15, 0, r0, c7, c5, 4 @ ISB
  646. mcr p15, 0, r0, c1, c0, 0 @ load control register
  647. mrc p15, 0, r0, c1, c0, 0 @ and read it back
  648. mov r0, #0
  649. mcr p15, 0, r0, c7, c5, 4 @ ISB
  650. mov pc, r12
  651. __fa526_cache_on:
  652. mov r12, lr
  653. mov r6, #CB_BITS | 0x12 @ U
  654. bl __setup_mmu
  655. mov r0, #0
  656. mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
  657. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  658. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  659. mrc p15, 0, r0, c1, c0, 0 @ read control reg
  660. orr r0, r0, #0x1000 @ I-cache enable
  661. bl __common_mmu_cache_on
  662. mov r0, #0
  663. mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
  664. mov pc, r12
  665. __common_mmu_cache_on:
  666. #ifndef CONFIG_THUMB2_KERNEL
  667. #ifndef DEBUG
  668. orr r0, r0, #0x000d @ Write buffer, mmu
  669. #endif
  670. mov r1, #-1
  671. mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
  672. mcr p15, 0, r1, c3, c0, 0 @ load domain access control
  673. b 1f
  674. .align 5 @ cache line aligned
  675. 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
  676. mrc p15, 0, r0, c1, c0, 0 @ and read it back to
  677. sub pc, lr, r0, lsr #32 @ properly flush pipeline
  678. #endif
  679. #define PROC_ENTRY_SIZE (4*5)
  680. /*
  681. * Here follow the relocatable cache support functions for the
  682. * various processors. This is a generic hook for locating an
  683. * entry and jumping to an instruction at the specified offset
  684. * from the start of the block. Please note this is all position
  685. * independent code.
  686. *
  687. * r1 = corrupted
  688. * r2 = corrupted
  689. * r3 = block offset
  690. * r9 = corrupted
  691. * r12 = corrupted
  692. */
  693. call_cache_fn: adr r12, proc_types
  694. #ifdef CONFIG_CPU_CP15
  695. mrc p15, 0, r9, c0, c0 @ get processor ID
  696. #else
  697. ldr r9, =CONFIG_PROCESSOR_ID
  698. #endif
  699. 1: ldr r1, [r12, #0] @ get value
  700. ldr r2, [r12, #4] @ get mask
  701. eor r1, r1, r9 @ (real ^ match)
  702. tst r1, r2 @ & mask
  703. ARM( addeq pc, r12, r3 ) @ call cache function
  704. THUMB( addeq r12, r3 )
  705. THUMB( moveq pc, r12 ) @ call cache function
  706. add r12, r12, #PROC_ENTRY_SIZE
  707. b 1b
  708. /*
  709. * Table for cache operations. This is basically:
  710. * - CPU ID match
  711. * - CPU ID mask
  712. * - 'cache on' method instruction
  713. * - 'cache off' method instruction
  714. * - 'cache flush' method instruction
  715. *
  716. * We match an entry using: ((real_id ^ match) & mask) == 0
  717. *
  718. * Writethrough caches generally only need 'on' and 'off'
  719. * methods. Writeback caches _must_ have the flush method
  720. * defined.
  721. */
  722. .align 2
  723. .type proc_types,#object
  724. proc_types:
  725. .word 0x41000000 @ old ARM ID
  726. .word 0xff00f000
  727. mov pc, lr
  728. THUMB( nop )
  729. mov pc, lr
  730. THUMB( nop )
  731. mov pc, lr
  732. THUMB( nop )
  733. .word 0x41007000 @ ARM7/710
  734. .word 0xfff8fe00
  735. mov pc, lr
  736. THUMB( nop )
  737. mov pc, lr
  738. THUMB( nop )
  739. mov pc, lr
  740. THUMB( nop )
  741. .word 0x41807200 @ ARM720T (writethrough)
  742. .word 0xffffff00
  743. W(b) __armv4_mmu_cache_on
  744. W(b) __armv4_mmu_cache_off
  745. mov pc, lr
  746. THUMB( nop )
  747. .word 0x41007400 @ ARM74x
  748. .word 0xff00ff00
  749. W(b) __armv3_mpu_cache_on
  750. W(b) __armv3_mpu_cache_off
  751. W(b) __armv3_mpu_cache_flush
  752. .word 0x41009400 @ ARM94x
  753. .word 0xff00ff00
  754. W(b) __armv4_mpu_cache_on
  755. W(b) __armv4_mpu_cache_off
  756. W(b) __armv4_mpu_cache_flush
  757. .word 0x41069260 @ ARM926EJ-S (v5TEJ)
  758. .word 0xff0ffff0
  759. W(b) __arm926ejs_mmu_cache_on
  760. W(b) __armv4_mmu_cache_off
  761. W(b) __armv5tej_mmu_cache_flush
  762. .word 0x00007000 @ ARM7 IDs
  763. .word 0x0000f000
  764. mov pc, lr
  765. THUMB( nop )
  766. mov pc, lr
  767. THUMB( nop )
  768. mov pc, lr
  769. THUMB( nop )
  770. @ Everything from here on will be the new ID system.
  771. .word 0x4401a100 @ sa110 / sa1100
  772. .word 0xffffffe0
  773. W(b) __armv4_mmu_cache_on
  774. W(b) __armv4_mmu_cache_off
  775. W(b) __armv4_mmu_cache_flush
  776. .word 0x6901b110 @ sa1110
  777. .word 0xfffffff0
  778. W(b) __armv4_mmu_cache_on
  779. W(b) __armv4_mmu_cache_off
  780. W(b) __armv4_mmu_cache_flush
  781. .word 0x56056900
  782. .word 0xffffff00 @ PXA9xx
  783. W(b) __armv4_mmu_cache_on
  784. W(b) __armv4_mmu_cache_off
  785. W(b) __armv4_mmu_cache_flush
  786. .word 0x56158000 @ PXA168
  787. .word 0xfffff000
  788. W(b) __armv4_mmu_cache_on
  789. W(b) __armv4_mmu_cache_off
  790. W(b) __armv5tej_mmu_cache_flush
  791. .word 0x56050000 @ Feroceon
  792. .word 0xff0f0000
  793. W(b) __armv4_mmu_cache_on
  794. W(b) __armv4_mmu_cache_off
  795. W(b) __armv5tej_mmu_cache_flush
  796. #ifdef CONFIG_CPU_FEROCEON_OLD_ID
  797. /* this conflicts with the standard ARMv5TE entry */
  798. .long 0x41009260 @ Old Feroceon
  799. .long 0xff00fff0
  800. b __armv4_mmu_cache_on
  801. b __armv4_mmu_cache_off
  802. b __armv5tej_mmu_cache_flush
  803. #endif
  804. .word 0x66015261 @ FA526
  805. .word 0xff01fff1
  806. W(b) __fa526_cache_on
  807. W(b) __armv4_mmu_cache_off
  808. W(b) __fa526_cache_flush
  809. @ These match on the architecture ID
  810. .word 0x00020000 @ ARMv4T
  811. .word 0x000f0000
  812. W(b) __armv4_mmu_cache_on
  813. W(b) __armv4_mmu_cache_off
  814. W(b) __armv4_mmu_cache_flush
  815. .word 0x00050000 @ ARMv5TE
  816. .word 0x000f0000
  817. W(b) __armv4_mmu_cache_on
  818. W(b) __armv4_mmu_cache_off
  819. W(b) __armv4_mmu_cache_flush
  820. .word 0x00060000 @ ARMv5TEJ
  821. .word 0x000f0000
  822. W(b) __armv4_mmu_cache_on
  823. W(b) __armv4_mmu_cache_off
  824. W(b) __armv5tej_mmu_cache_flush
  825. .word 0x0007b000 @ ARMv6
  826. .word 0x000ff000
  827. W(b) __armv6_mmu_cache_on
  828. W(b) __armv4_mmu_cache_off
  829. W(b) __armv6_mmu_cache_flush
  830. .word 0x000f0000 @ new CPU Id
  831. .word 0x000f0000
  832. W(b) __armv7_mmu_cache_on
  833. W(b) __armv7_mmu_cache_off
  834. W(b) __armv7_mmu_cache_flush
  835. .word 0 @ unrecognised type
  836. .word 0
  837. mov pc, lr
  838. THUMB( nop )
  839. mov pc, lr
  840. THUMB( nop )
  841. mov pc, lr
  842. THUMB( nop )
  843. .size proc_types, . - proc_types
  844. /*
  845. * If you get a "non-constant expression in ".if" statement"
  846. * error from the assembler on this line, check that you have
  847. * not accidentally written a "b" instruction where you should
  848. * have written W(b).
  849. */
  850. .if (. - proc_types) % PROC_ENTRY_SIZE != 0
  851. .error "The size of one or more proc_types entries is wrong."
  852. .endif
  853. /*
  854. * Turn off the Cache and MMU. ARMv3 does not support
  855. * reading the control register, but ARMv4 does.
  856. *
  857. * On exit,
  858. * r0, r1, r2, r3, r9, r12 corrupted
  859. * This routine must preserve:
  860. * r4, r7, r8
  861. */
  862. .align 5
  863. cache_off: mov r3, #12 @ cache_off function
  864. b call_cache_fn
  865. __armv4_mpu_cache_off:
  866. mrc p15, 0, r0, c1, c0
  867. bic r0, r0, #0x000d
  868. mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
  869. mov r0, #0
  870. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  871. mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
  872. mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
  873. mov pc, lr
  874. __armv3_mpu_cache_off:
  875. mrc p15, 0, r0, c1, c0
  876. bic r0, r0, #0x000d
  877. mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
  878. mov r0, #0
  879. mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
  880. mov pc, lr
  881. __armv4_mmu_cache_off:
  882. #ifdef CONFIG_MMU
  883. mrc p15, 0, r0, c1, c0
  884. bic r0, r0, #0x000d
  885. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  886. mov r0, #0
  887. mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
  888. mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
  889. #endif
  890. mov pc, lr
  891. __armv7_mmu_cache_off:
  892. mrc p15, 0, r0, c1, c0
  893. #ifdef CONFIG_MMU
  894. bic r0, r0, #0x000d
  895. #else
  896. bic r0, r0, #0x000c
  897. #endif
  898. mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
  899. mov r12, lr
  900. bl __armv7_mmu_cache_flush
  901. mov r0, #0
  902. #ifdef CONFIG_MMU
  903. mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
  904. #endif
  905. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
  906. mcr p15, 0, r0, c7, c10, 4 @ DSB
  907. mcr p15, 0, r0, c7, c5, 4 @ ISB
  908. mov pc, r12
  909. /*
  910. * Clean and flush the cache to maintain consistency.
  911. *
  912. * On exit,
  913. * r1, r2, r3, r9, r10, r11, r12 corrupted
  914. * This routine must preserve:
  915. * r4, r6, r7, r8
  916. */
  917. .align 5
  918. cache_clean_flush:
  919. mov r3, #16
  920. b call_cache_fn
  921. __armv4_mpu_cache_flush:
  922. mov r2, #1
  923. mov r3, #0
  924. mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
  925. mov r1, #7 << 5 @ 8 segments
  926. 1: orr r3, r1, #63 << 26 @ 64 entries
  927. 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
  928. subs r3, r3, #1 << 26
  929. bcs 2b @ entries 63 to 0
  930. subs r1, r1, #1 << 5
  931. bcs 1b @ segments 7 to 0
  932. teq r2, #0
  933. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  934. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  935. mov pc, lr
  936. __fa526_cache_flush:
  937. mov r1, #0
  938. mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
  939. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  940. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  941. mov pc, lr
  942. __armv6_mmu_cache_flush:
  943. mov r1, #0
  944. mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
  945. mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
  946. mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
  947. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  948. mov pc, lr
  949. __armv7_mmu_cache_flush:
  950. mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
  951. tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
  952. mov r10, #0
  953. beq hierarchical
  954. mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
  955. b iflush
  956. hierarchical:
  957. mcr p15, 0, r10, c7, c10, 5 @ DMB
  958. stmfd sp!, {r0-r7, r9-r11}
  959. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  960. ands r3, r0, #0x7000000 @ extract loc from clidr
  961. mov r3, r3, lsr #23 @ left align loc bit field
  962. beq finished @ if loc is 0, then no need to clean
  963. mov r10, #0 @ start clean at cache level 0
  964. loop1:
  965. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  966. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  967. and r1, r1, #7 @ mask of the bits for current cache only
  968. cmp r1, #2 @ see what cache we have at this level
  969. blt skip @ skip if no cache, or just i-cache
  970. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  971. mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
  972. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  973. and r2, r1, #7 @ extract the length of the cache lines
  974. add r2, r2, #4 @ add 4 (line length offset)
  975. ldr r4, =0x3ff
  976. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  977. clz r5, r4 @ find bit position of way size increment
  978. ldr r7, =0x7fff
  979. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  980. loop2:
  981. mov r9, r4 @ create working copy of max way size
  982. loop3:
  983. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  984. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  985. THUMB( lsl r6, r9, r5 )
  986. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  987. THUMB( lsl r6, r7, r2 )
  988. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  989. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  990. subs r9, r9, #1 @ decrement the way
  991. bge loop3
  992. subs r7, r7, #1 @ decrement the index
  993. bge loop2
  994. skip:
  995. add r10, r10, #2 @ increment cache number
  996. cmp r3, r10
  997. bgt loop1
  998. finished:
  999. ldmfd sp!, {r0-r7, r9-r11}
  1000. mov r10, #0 @ swith back to cache level 0
  1001. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  1002. iflush:
  1003. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1004. mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
  1005. mcr p15, 0, r10, c7, c10, 4 @ DSB
  1006. mcr p15, 0, r10, c7, c5, 4 @ ISB
  1007. mov pc, lr
  1008. __armv5tej_mmu_cache_flush:
  1009. 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
  1010. bne 1b
  1011. mcr p15, 0, r0, c7, c5, 0 @ flush I cache
  1012. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  1013. mov pc, lr
  1014. __armv4_mmu_cache_flush:
  1015. mov r2, #64*1024 @ default: 32K dcache size (*2)
  1016. mov r11, #32 @ default: 32 byte line size
  1017. mrc p15, 0, r3, c0, c0, 1 @ read cache type
  1018. teq r3, r9 @ cache ID register present?
  1019. beq no_cache_id
  1020. mov r1, r3, lsr #18
  1021. and r1, r1, #7
  1022. mov r2, #1024
  1023. mov r2, r2, lsl r1 @ base dcache size *2
  1024. tst r3, #1 << 14 @ test M bit
  1025. addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
  1026. mov r3, r3, lsr #12
  1027. and r3, r3, #3
  1028. mov r11, #8
  1029. mov r11, r11, lsl r3 @ cache line size in bytes
  1030. no_cache_id:
  1031. mov r1, pc
  1032. bic r1, r1, #63 @ align to longest cache line
  1033. add r2, r1, r2
  1034. 1:
  1035. ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
  1036. THUMB( ldr r3, [r1] ) @ s/w flush D cache
  1037. THUMB( add r1, r1, r11 )
  1038. teq r1, r2
  1039. bne 1b
  1040. mcr p15, 0, r1, c7, c5, 0 @ flush I cache
  1041. mcr p15, 0, r1, c7, c6, 0 @ flush D cache
  1042. mcr p15, 0, r1, c7, c10, 4 @ drain WB
  1043. mov pc, lr
  1044. __armv3_mmu_cache_flush:
  1045. __armv3_mpu_cache_flush:
  1046. mov r1, #0
  1047. mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
  1048. mov pc, lr
  1049. /*
  1050. * Various debugging routines for printing hex characters and
  1051. * memory, which again must be relocatable.
  1052. */
  1053. #ifdef DEBUG
  1054. .align 2
  1055. .type phexbuf,#object
  1056. phexbuf: .space 12
  1057. .size phexbuf, . - phexbuf
  1058. @ phex corrupts {r0, r1, r2, r3}
  1059. phex: adr r3, phexbuf
  1060. mov r2, #0
  1061. strb r2, [r3, r1]
  1062. 1: subs r1, r1, #1
  1063. movmi r0, r3
  1064. bmi puts
  1065. and r2, r0, #15
  1066. mov r0, r0, lsr #4
  1067. cmp r2, #10
  1068. addge r2, r2, #7
  1069. add r2, r2, #'0'
  1070. strb r2, [r3, r1]
  1071. b 1b
  1072. @ puts corrupts {r0, r1, r2, r3}
  1073. puts: loadsp r3, r1
  1074. 1: ldrb r2, [r0], #1
  1075. teq r2, #0
  1076. moveq pc, lr
  1077. 2: writeb r2, r3
  1078. mov r1, #0x00020000
  1079. 3: subs r1, r1, #1
  1080. bne 3b
  1081. teq r2, #'\n'
  1082. moveq r2, #'\r'
  1083. beq 2b
  1084. teq r0, #0
  1085. bne 1b
  1086. mov pc, lr
  1087. @ putc corrupts {r0, r1, r2, r3}
  1088. putc:
  1089. mov r2, r0
  1090. mov r0, #0
  1091. loadsp r3, r1
  1092. b 2b
  1093. @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
  1094. memdump: mov r12, r0
  1095. mov r10, lr
  1096. mov r11, #0
  1097. 2: mov r0, r11, lsl #2
  1098. add r0, r0, r12
  1099. mov r1, #8
  1100. bl phex
  1101. mov r0, #':'
  1102. bl putc
  1103. 1: mov r0, #' '
  1104. bl putc
  1105. ldr r0, [r12, r11, lsl #2]
  1106. mov r1, #8
  1107. bl phex
  1108. and r0, r11, #7
  1109. teq r0, #3
  1110. moveq r0, #' '
  1111. bleq putc
  1112. and r0, r11, #7
  1113. add r11, r11, #1
  1114. teq r0, #7
  1115. bne 1b
  1116. mov r0, #'\n'
  1117. bl putc
  1118. cmp r11, #64
  1119. blt 2b
  1120. mov pc, r10
  1121. #endif
  1122. .ltorg
  1123. #ifdef CONFIG_ARM_VIRT_EXT
  1124. .align 5
  1125. __hyp_reentry_vectors:
  1126. W(b) . @ reset
  1127. W(b) . @ undef
  1128. W(b) . @ svc
  1129. W(b) . @ pabort
  1130. W(b) . @ dabort
  1131. W(b) __enter_kernel @ hyp
  1132. W(b) . @ irq
  1133. W(b) . @ fiq
  1134. #endif /* CONFIG_ARM_VIRT_EXT */
  1135. __enter_kernel:
  1136. mov r0, #0 @ must be 0
  1137. ARM( mov pc, r4 ) @ call kernel
  1138. THUMB( bx r4 ) @ entry point is always ARM
  1139. reloc_code_end:
  1140. .align
  1141. .section ".stack", "aw", %nobits
  1142. .L_user_stack: .space 4096
  1143. .L_user_stack_end: