start.S 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. /*
  2. * Copyright 2004, 2007-2010 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2003 Motorola,Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
  24. *
  25. * The processor starts at 0xfffffffc and the code is first executed in the
  26. * last 4K page(0xfffff000-0xffffffff) in flash/rom.
  27. *
  28. */
  29. #include <config.h>
  30. #include <mpc85xx.h>
  31. #include <timestamp.h>
  32. #include <version.h>
  33. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  34. #include <ppc_asm.tmpl>
  35. #include <ppc_defs.h>
  36. #include <asm/cache.h>
  37. #include <asm/mmu.h>
  38. #ifndef CONFIG_IDENT_STRING
  39. #define CONFIG_IDENT_STRING ""
  40. #endif
  41. #undef MSR_KERNEL
  42. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  43. /*
  44. * Set up GOT: Global Offset Table
  45. *
  46. * Use r12 to access the GOT
  47. */
  48. START_GOT
  49. GOT_ENTRY(_GOT2_TABLE_)
  50. GOT_ENTRY(_FIXUP_TABLE_)
  51. #ifndef CONFIG_NAND_SPL
  52. GOT_ENTRY(_start)
  53. GOT_ENTRY(_start_of_vectors)
  54. GOT_ENTRY(_end_of_vectors)
  55. GOT_ENTRY(transfer_to_handler)
  56. #endif
  57. GOT_ENTRY(__init_end)
  58. GOT_ENTRY(_end)
  59. GOT_ENTRY(__bss_start)
  60. END_GOT
  61. /*
  62. * e500 Startup -- after reset only the last 4KB of the effective
  63. * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
  64. * section is located at THIS LAST page and basically does three
  65. * things: clear some registers, set up exception tables and
  66. * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
  67. * continue the boot procedure.
  68. * Once the boot rom is mapped by TLB entries we can proceed
  69. * with normal startup.
  70. *
  71. */
  72. .section .bootpg,"ax"
  73. .globl _start_e500
  74. _start_e500:
  75. /* clear registers/arrays not reset by hardware */
  76. /* L1 */
  77. li r0,2
  78. mtspr L1CSR0,r0 /* invalidate d-cache */
  79. mtspr L1CSR1,r0 /* invalidate i-cache */
  80. mfspr r1,DBSR
  81. mtspr DBSR,r1 /* Clear all valid bits */
  82. /*
  83. * Enable L1 Caches early
  84. *
  85. */
  86. #if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING)
  87. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  88. li r2,(32 + 0)
  89. mtspr L1CSR2,r2
  90. #endif
  91. /* Enable/invalidate the I-Cache */
  92. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  93. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  94. mtspr SPRN_L1CSR1,r2
  95. 1:
  96. mfspr r3,SPRN_L1CSR1
  97. and. r1,r3,r2
  98. bne 1b
  99. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  100. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  101. mtspr SPRN_L1CSR1,r3
  102. isync
  103. 2:
  104. mfspr r3,SPRN_L1CSR1
  105. andi. r1,r3,L1CSR1_ICE@l
  106. beq 2b
  107. /* Enable/invalidate the D-Cache */
  108. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  109. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  110. mtspr SPRN_L1CSR0,r2
  111. 1:
  112. mfspr r3,SPRN_L1CSR0
  113. and. r1,r3,r2
  114. bne 1b
  115. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  116. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  117. mtspr SPRN_L1CSR0,r3
  118. isync
  119. 2:
  120. mfspr r3,SPRN_L1CSR0
  121. andi. r1,r3,L1CSR0_DCE@l
  122. beq 2b
  123. /* Setup interrupt vectors */
  124. lis r1,TEXT_BASE@h
  125. mtspr IVPR,r1
  126. li r1,0x0100
  127. mtspr IVOR0,r1 /* 0: Critical input */
  128. li r1,0x0200
  129. mtspr IVOR1,r1 /* 1: Machine check */
  130. li r1,0x0300
  131. mtspr IVOR2,r1 /* 2: Data storage */
  132. li r1,0x0400
  133. mtspr IVOR3,r1 /* 3: Instruction storage */
  134. li r1,0x0500
  135. mtspr IVOR4,r1 /* 4: External interrupt */
  136. li r1,0x0600
  137. mtspr IVOR5,r1 /* 5: Alignment */
  138. li r1,0x0700
  139. mtspr IVOR6,r1 /* 6: Program check */
  140. li r1,0x0800
  141. mtspr IVOR7,r1 /* 7: floating point unavailable */
  142. li r1,0x0900
  143. mtspr IVOR8,r1 /* 8: System call */
  144. /* 9: Auxiliary processor unavailable(unsupported) */
  145. li r1,0x0a00
  146. mtspr IVOR10,r1 /* 10: Decrementer */
  147. li r1,0x0b00
  148. mtspr IVOR11,r1 /* 11: Interval timer */
  149. li r1,0x0c00
  150. mtspr IVOR12,r1 /* 12: Watchdog timer */
  151. li r1,0x0d00
  152. mtspr IVOR13,r1 /* 13: Data TLB error */
  153. li r1,0x0e00
  154. mtspr IVOR14,r1 /* 14: Instruction TLB error */
  155. li r1,0x0f00
  156. mtspr IVOR15,r1 /* 15: Debug */
  157. /* Clear and set up some registers. */
  158. li r0,0x0000
  159. lis r1,0xffff
  160. mtspr DEC,r0 /* prevent dec exceptions */
  161. mttbl r0 /* prevent fit & wdt exceptions */
  162. mttbu r0
  163. mtspr TSR,r1 /* clear all timer exception status */
  164. mtspr TCR,r0 /* disable all */
  165. mtspr ESR,r0 /* clear exception syndrome register */
  166. mtspr MCSR,r0 /* machine check syndrome register */
  167. mtxer r0 /* clear integer exception register */
  168. #ifdef CONFIG_SYS_BOOK3E_HV
  169. mtspr MAS8,r0 /* make sure MAS8 is clear */
  170. #endif
  171. /* Enable Time Base and Select Time Base Clock */
  172. lis r0,HID0_EMCP@h /* Enable machine check */
  173. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  174. ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
  175. #endif
  176. #ifndef CONFIG_E500MC
  177. ori r0,r0,HID0_TBEN@l /* Enable Timebase */
  178. #endif
  179. mtspr HID0,r0
  180. #ifndef CONFIG_E500MC
  181. li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
  182. mfspr r3,PVR
  183. andi. r3,r3, 0xff
  184. cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */
  185. blt 1f
  186. /* Set MBDD bit also */
  187. ori r0, r0, HID1_MBDD@l
  188. 1:
  189. mtspr HID1,r0
  190. #endif
  191. /* Enable Branch Prediction */
  192. #if defined(CONFIG_BTB)
  193. lis r0,BUCSR_ENABLE@h
  194. ori r0,r0,BUCSR_ENABLE@l
  195. mtspr SPRN_BUCSR,r0
  196. #endif
  197. #if defined(CONFIG_SYS_INIT_DBCR)
  198. lis r1,0xffff
  199. ori r1,r1,0xffff
  200. mtspr DBSR,r1 /* Clear all status bits */
  201. lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
  202. ori r0,r0,CONFIG_SYS_INIT_DBCR@l
  203. mtspr DBCR0,r0
  204. #endif
  205. #ifdef CONFIG_MPC8569
  206. #define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
  207. #define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
  208. /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
  209. * use address space which is more than 12bits, and it must be done in
  210. * the 4K boot page. So we set this bit here.
  211. */
  212. /* create a temp mapping TLB0[0] for LBCR */
  213. lis r6,FSL_BOOKE_MAS0(0, 0, 0)@h
  214. ori r6,r6,FSL_BOOKE_MAS0(0, 0, 0)@l
  215. lis r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h
  216. ori r7,r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l
  217. lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@h
  218. ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@l
  219. lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
  220. (MAS3_SX|MAS3_SW|MAS3_SR))@h
  221. ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
  222. (MAS3_SX|MAS3_SW|MAS3_SR))@l
  223. mtspr MAS0,r6
  224. mtspr MAS1,r7
  225. mtspr MAS2,r8
  226. mtspr MAS3,r9
  227. isync
  228. msync
  229. tlbwe
  230. /* Set LBCR register */
  231. lis r4,CONFIG_SYS_LBCR_ADDR@h
  232. ori r4,r4,CONFIG_SYS_LBCR_ADDR@l
  233. lis r5,CONFIG_SYS_LBC_LBCR@h
  234. ori r5,r5,CONFIG_SYS_LBC_LBCR@l
  235. stw r5,0(r4)
  236. isync
  237. /* invalidate this temp TLB */
  238. lis r4,CONFIG_SYS_LBC_ADDR@h
  239. ori r4,r4,CONFIG_SYS_LBC_ADDR@l
  240. tlbivax 0,r4
  241. isync
  242. #endif /* CONFIG_MPC8569 */
  243. lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
  244. ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
  245. #ifndef CONFIG_SYS_RAMBOOT
  246. /* create a temp mapping in AS=1 to the 4M boot window */
  247. lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@h
  248. ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@l
  249. lis r8,FSL_BOOKE_MAS2(TEXT_BASE & 0xffc00000, (MAS2_I|MAS2_G))@h
  250. ori r8,r8,FSL_BOOKE_MAS2(TEXT_BASE & 0xffc00000, (MAS2_I|MAS2_G))@l
  251. /* The 85xx has the default boot window 0xff800000 - 0xffffffff */
  252. lis r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
  253. ori r9,r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
  254. #else
  255. /*
  256. * create a temp mapping in AS=1 to the 1M TEXT_BASE space, the main
  257. * image has been relocated to TEXT_BASE on the second stage.
  258. */
  259. lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h
  260. ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l
  261. lis r8,FSL_BOOKE_MAS2(TEXT_BASE, (MAS2_I|MAS2_G))@h
  262. ori r8,r8,FSL_BOOKE_MAS2(TEXT_BASE, (MAS2_I|MAS2_G))@l
  263. lis r9,FSL_BOOKE_MAS3(TEXT_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
  264. ori r9,r9,FSL_BOOKE_MAS3(TEXT_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
  265. #endif
  266. mtspr MAS0,r6
  267. mtspr MAS1,r7
  268. mtspr MAS2,r8
  269. mtspr MAS3,r9
  270. isync
  271. msync
  272. tlbwe
  273. /* create a temp mapping in AS=1 to the stack */
  274. lis r6,FSL_BOOKE_MAS0(1, 14, 0)@h
  275. ori r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l
  276. lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h
  277. ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l
  278. lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@h
  279. ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@l
  280. #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
  281. defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
  282. lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
  283. (MAS3_SX|MAS3_SW|MAS3_SR))@h
  284. ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
  285. (MAS3_SX|MAS3_SW|MAS3_SR))@l
  286. li r10,CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH
  287. mtspr MAS7,r10
  288. #else
  289. lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
  290. ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
  291. #endif
  292. mtspr MAS0,r6
  293. mtspr MAS1,r7
  294. mtspr MAS2,r8
  295. mtspr MAS3,r9
  296. isync
  297. msync
  298. tlbwe
  299. lis r6,MSR_IS|MSR_DS@h
  300. ori r6,r6,MSR_IS|MSR_DS@l
  301. lis r7,switch_as@h
  302. ori r7,r7,switch_as@l
  303. mtspr SPRN_SRR0,r7
  304. mtspr SPRN_SRR1,r6
  305. rfi
  306. switch_as:
  307. /* L1 DCache is used for initial RAM */
  308. /* Allocate Initial RAM in data cache.
  309. */
  310. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  311. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  312. mfspr r2, L1CFG0
  313. andi. r2, r2, 0x1ff
  314. /* cache size * 1024 / (2 * L1 line size) */
  315. slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
  316. mtctr r2
  317. li r0,0
  318. 1:
  319. dcbz r0,r3
  320. dcbtls 0,r0,r3
  321. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  322. bdnz 1b
  323. /* Jump out the last 4K page and continue to 'normal' start */
  324. #ifdef CONFIG_SYS_RAMBOOT
  325. b _start_cont
  326. #else
  327. /* Calculate absolute address in FLASH and jump there */
  328. /*--------------------------------------------------------------*/
  329. lis r3,CONFIG_SYS_MONITOR_BASE@h
  330. ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
  331. addi r3,r3,_start_cont - _start + _START_OFFSET
  332. mtlr r3
  333. blr
  334. #endif
  335. .text
  336. .globl _start
  337. _start:
  338. .long 0x27051956 /* U-BOOT Magic Number */
  339. .globl version_string
  340. version_string:
  341. .ascii U_BOOT_VERSION
  342. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  343. .ascii CONFIG_IDENT_STRING, "\0"
  344. .align 4
  345. .globl _start_cont
  346. _start_cont:
  347. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  348. lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
  349. ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
  350. li r0,0
  351. stwu r0,-4(r1)
  352. stwu r0,-4(r1) /* Terminate call chain */
  353. stwu r1,-8(r1) /* Save back chain and move SP */
  354. lis r0,RESET_VECTOR@h /* Address of reset vector */
  355. ori r0,r0,RESET_VECTOR@l
  356. stwu r1,-8(r1) /* Save back chain and move SP */
  357. stw r0,+12(r1) /* Save return addr (underflow vect) */
  358. GET_GOT
  359. bl cpu_init_early_f
  360. /* switch back to AS = 0 */
  361. lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
  362. ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
  363. mtmsr r3
  364. isync
  365. bl cpu_init_f
  366. bl board_init_f
  367. isync
  368. #ifndef CONFIG_NAND_SPL
  369. . = EXC_OFF_SYS_RESET
  370. .globl _start_of_vectors
  371. _start_of_vectors:
  372. /* Critical input. */
  373. CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
  374. /* Machine check */
  375. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  376. /* Data Storage exception. */
  377. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  378. /* Instruction Storage exception. */
  379. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  380. /* External Interrupt exception. */
  381. STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
  382. /* Alignment exception. */
  383. . = 0x0600
  384. Alignment:
  385. EXCEPTION_PROLOG(SRR0, SRR1)
  386. mfspr r4,DAR
  387. stw r4,_DAR(r21)
  388. mfspr r5,DSISR
  389. stw r5,_DSISR(r21)
  390. addi r3,r1,STACK_FRAME_OVERHEAD
  391. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  392. /* Program check exception */
  393. . = 0x0700
  394. ProgramCheck:
  395. EXCEPTION_PROLOG(SRR0, SRR1)
  396. addi r3,r1,STACK_FRAME_OVERHEAD
  397. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  398. MSR_KERNEL, COPY_EE)
  399. /* No FPU on MPC85xx. This exception is not supposed to happen.
  400. */
  401. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  402. . = 0x0900
  403. /*
  404. * r0 - SYSCALL number
  405. * r3-... arguments
  406. */
  407. SystemCall:
  408. addis r11,r0,0 /* get functions table addr */
  409. ori r11,r11,0 /* Note: this code is patched in trap_init */
  410. addis r12,r0,0 /* get number of functions */
  411. ori r12,r12,0
  412. cmplw 0,r0,r12
  413. bge 1f
  414. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  415. add r11,r11,r0
  416. lwz r11,0(r11)
  417. li r20,0xd00-4 /* Get stack pointer */
  418. lwz r12,0(r20)
  419. subi r12,r12,12 /* Adjust stack pointer */
  420. li r0,0xc00+_end_back-SystemCall
  421. cmplw 0,r0,r12 /* Check stack overflow */
  422. bgt 1f
  423. stw r12,0(r20)
  424. mflr r0
  425. stw r0,0(r12)
  426. mfspr r0,SRR0
  427. stw r0,4(r12)
  428. mfspr r0,SRR1
  429. stw r0,8(r12)
  430. li r12,0xc00+_back-SystemCall
  431. mtlr r12
  432. mtspr SRR0,r11
  433. 1: SYNC
  434. rfi
  435. _back:
  436. mfmsr r11 /* Disable interrupts */
  437. li r12,0
  438. ori r12,r12,MSR_EE
  439. andc r11,r11,r12
  440. SYNC /* Some chip revs need this... */
  441. mtmsr r11
  442. SYNC
  443. li r12,0xd00-4 /* restore regs */
  444. lwz r12,0(r12)
  445. lwz r11,0(r12)
  446. mtlr r11
  447. lwz r11,4(r12)
  448. mtspr SRR0,r11
  449. lwz r11,8(r12)
  450. mtspr SRR1,r11
  451. addi r12,r12,12 /* Adjust stack pointer */
  452. li r20,0xd00-4
  453. stw r12,0(r20)
  454. SYNC
  455. rfi
  456. _end_back:
  457. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  458. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  459. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  460. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  461. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  462. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  463. .globl _end_of_vectors
  464. _end_of_vectors:
  465. . = . + (0x100 - ( . & 0xff )) /* align for debug */
  466. /*
  467. * This code finishes saving the registers to the exception frame
  468. * and jumps to the appropriate handler for the exception.
  469. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  470. */
  471. .globl transfer_to_handler
  472. transfer_to_handler:
  473. stw r22,_NIP(r21)
  474. lis r22,MSR_POW@h
  475. andc r23,r23,r22
  476. stw r23,_MSR(r21)
  477. SAVE_GPR(7, r21)
  478. SAVE_4GPRS(8, r21)
  479. SAVE_8GPRS(12, r21)
  480. SAVE_8GPRS(24, r21)
  481. mflr r23
  482. andi. r24,r23,0x3f00 /* get vector offset */
  483. stw r24,TRAP(r21)
  484. li r22,0
  485. stw r22,RESULT(r21)
  486. mtspr SPRG2,r22 /* r1 is now kernel sp */
  487. lwz r24,0(r23) /* virtual address of handler */
  488. lwz r23,4(r23) /* where to go when done */
  489. mtspr SRR0,r24
  490. mtspr SRR1,r20
  491. mtlr r23
  492. SYNC
  493. rfi /* jump to handler, enable MMU */
  494. int_return:
  495. mfmsr r28 /* Disable interrupts */
  496. li r4,0
  497. ori r4,r4,MSR_EE
  498. andc r28,r28,r4
  499. SYNC /* Some chip revs need this... */
  500. mtmsr r28
  501. SYNC
  502. lwz r2,_CTR(r1)
  503. lwz r0,_LINK(r1)
  504. mtctr r2
  505. mtlr r0
  506. lwz r2,_XER(r1)
  507. lwz r0,_CCR(r1)
  508. mtspr XER,r2
  509. mtcrf 0xFF,r0
  510. REST_10GPRS(3, r1)
  511. REST_10GPRS(13, r1)
  512. REST_8GPRS(23, r1)
  513. REST_GPR(31, r1)
  514. lwz r2,_NIP(r1) /* Restore environment */
  515. lwz r0,_MSR(r1)
  516. mtspr SRR0,r2
  517. mtspr SRR1,r0
  518. lwz r0,GPR0(r1)
  519. lwz r2,GPR2(r1)
  520. lwz r1,GPR1(r1)
  521. SYNC
  522. rfi
  523. crit_return:
  524. mfmsr r28 /* Disable interrupts */
  525. li r4,0
  526. ori r4,r4,MSR_EE
  527. andc r28,r28,r4
  528. SYNC /* Some chip revs need this... */
  529. mtmsr r28
  530. SYNC
  531. lwz r2,_CTR(r1)
  532. lwz r0,_LINK(r1)
  533. mtctr r2
  534. mtlr r0
  535. lwz r2,_XER(r1)
  536. lwz r0,_CCR(r1)
  537. mtspr XER,r2
  538. mtcrf 0xFF,r0
  539. REST_10GPRS(3, r1)
  540. REST_10GPRS(13, r1)
  541. REST_8GPRS(23, r1)
  542. REST_GPR(31, r1)
  543. lwz r2,_NIP(r1) /* Restore environment */
  544. lwz r0,_MSR(r1)
  545. mtspr SPRN_CSRR0,r2
  546. mtspr SPRN_CSRR1,r0
  547. lwz r0,GPR0(r1)
  548. lwz r2,GPR2(r1)
  549. lwz r1,GPR1(r1)
  550. SYNC
  551. rfci
  552. mck_return:
  553. mfmsr r28 /* Disable interrupts */
  554. li r4,0
  555. ori r4,r4,MSR_EE
  556. andc r28,r28,r4
  557. SYNC /* Some chip revs need this... */
  558. mtmsr r28
  559. SYNC
  560. lwz r2,_CTR(r1)
  561. lwz r0,_LINK(r1)
  562. mtctr r2
  563. mtlr r0
  564. lwz r2,_XER(r1)
  565. lwz r0,_CCR(r1)
  566. mtspr XER,r2
  567. mtcrf 0xFF,r0
  568. REST_10GPRS(3, r1)
  569. REST_10GPRS(13, r1)
  570. REST_8GPRS(23, r1)
  571. REST_GPR(31, r1)
  572. lwz r2,_NIP(r1) /* Restore environment */
  573. lwz r0,_MSR(r1)
  574. mtspr SPRN_MCSRR0,r2
  575. mtspr SPRN_MCSRR1,r0
  576. lwz r0,GPR0(r1)
  577. lwz r2,GPR2(r1)
  578. lwz r1,GPR1(r1)
  579. SYNC
  580. rfmci
  581. /* Cache functions.
  582. */
  583. .globl invalidate_icache
  584. invalidate_icache:
  585. mfspr r0,L1CSR1
  586. ori r0,r0,L1CSR1_ICFI
  587. msync
  588. isync
  589. mtspr L1CSR1,r0
  590. isync
  591. blr /* entire I cache */
  592. .globl invalidate_dcache
  593. invalidate_dcache:
  594. mfspr r0,L1CSR0
  595. ori r0,r0,L1CSR0_DCFI
  596. msync
  597. isync
  598. mtspr L1CSR0,r0
  599. isync
  600. blr
  601. .globl icache_enable
  602. icache_enable:
  603. mflr r8
  604. bl invalidate_icache
  605. mtlr r8
  606. isync
  607. mfspr r4,L1CSR1
  608. ori r4,r4,0x0001
  609. oris r4,r4,0x0001
  610. mtspr L1CSR1,r4
  611. isync
  612. blr
  613. .globl icache_disable
  614. icache_disable:
  615. mfspr r0,L1CSR1
  616. lis r3,0
  617. ori r3,r3,L1CSR1_ICE
  618. andc r0,r0,r3
  619. mtspr L1CSR1,r0
  620. isync
  621. blr
  622. .globl icache_status
  623. icache_status:
  624. mfspr r3,L1CSR1
  625. andi. r3,r3,L1CSR1_ICE
  626. blr
  627. .globl dcache_enable
  628. dcache_enable:
  629. mflr r8
  630. bl invalidate_dcache
  631. mtlr r8
  632. isync
  633. mfspr r0,L1CSR0
  634. ori r0,r0,0x0001
  635. oris r0,r0,0x0001
  636. msync
  637. isync
  638. mtspr L1CSR0,r0
  639. isync
  640. blr
  641. .globl dcache_disable
  642. dcache_disable:
  643. mfspr r3,L1CSR0
  644. lis r4,0
  645. ori r4,r4,L1CSR0_DCE
  646. andc r3,r3,r4
  647. mtspr L1CSR0,r0
  648. isync
  649. blr
  650. .globl dcache_status
  651. dcache_status:
  652. mfspr r3,L1CSR0
  653. andi. r3,r3,L1CSR0_DCE
  654. blr
  655. .globl get_pir
  656. get_pir:
  657. mfspr r3,PIR
  658. blr
  659. .globl get_pvr
  660. get_pvr:
  661. mfspr r3,PVR
  662. blr
  663. .globl get_svr
  664. get_svr:
  665. mfspr r3,SVR
  666. blr
  667. .globl wr_tcr
  668. wr_tcr:
  669. mtspr TCR,r3
  670. blr
  671. /*------------------------------------------------------------------------------- */
  672. /* Function: in8 */
  673. /* Description: Input 8 bits */
  674. /*------------------------------------------------------------------------------- */
  675. .globl in8
  676. in8:
  677. lbz r3,0x0000(r3)
  678. blr
  679. /*------------------------------------------------------------------------------- */
  680. /* Function: out8 */
  681. /* Description: Output 8 bits */
  682. /*------------------------------------------------------------------------------- */
  683. .globl out8
  684. out8:
  685. stb r4,0x0000(r3)
  686. sync
  687. blr
  688. /*------------------------------------------------------------------------------- */
  689. /* Function: out16 */
  690. /* Description: Output 16 bits */
  691. /*------------------------------------------------------------------------------- */
  692. .globl out16
  693. out16:
  694. sth r4,0x0000(r3)
  695. sync
  696. blr
  697. /*------------------------------------------------------------------------------- */
  698. /* Function: out16r */
  699. /* Description: Byte reverse and output 16 bits */
  700. /*------------------------------------------------------------------------------- */
  701. .globl out16r
  702. out16r:
  703. sthbrx r4,r0,r3
  704. sync
  705. blr
  706. /*------------------------------------------------------------------------------- */
  707. /* Function: out32 */
  708. /* Description: Output 32 bits */
  709. /*------------------------------------------------------------------------------- */
  710. .globl out32
  711. out32:
  712. stw r4,0x0000(r3)
  713. sync
  714. blr
  715. /*------------------------------------------------------------------------------- */
  716. /* Function: out32r */
  717. /* Description: Byte reverse and output 32 bits */
  718. /*------------------------------------------------------------------------------- */
  719. .globl out32r
  720. out32r:
  721. stwbrx r4,r0,r3
  722. sync
  723. blr
  724. /*------------------------------------------------------------------------------- */
  725. /* Function: in16 */
  726. /* Description: Input 16 bits */
  727. /*------------------------------------------------------------------------------- */
  728. .globl in16
  729. in16:
  730. lhz r3,0x0000(r3)
  731. blr
  732. /*------------------------------------------------------------------------------- */
  733. /* Function: in16r */
  734. /* Description: Input 16 bits and byte reverse */
  735. /*------------------------------------------------------------------------------- */
  736. .globl in16r
  737. in16r:
  738. lhbrx r3,r0,r3
  739. blr
  740. /*------------------------------------------------------------------------------- */
  741. /* Function: in32 */
  742. /* Description: Input 32 bits */
  743. /*------------------------------------------------------------------------------- */
  744. .globl in32
  745. in32:
  746. lwz 3,0x0000(3)
  747. blr
  748. /*------------------------------------------------------------------------------- */
  749. /* Function: in32r */
  750. /* Description: Input 32 bits and byte reverse */
  751. /*------------------------------------------------------------------------------- */
  752. .globl in32r
  753. in32r:
  754. lwbrx r3,r0,r3
  755. blr
  756. #endif /* !CONFIG_NAND_SPL */
  757. /*------------------------------------------------------------------------------*/
  758. /*
  759. * void write_tlb(mas0, mas1, mas2, mas3, mas7)
  760. */
  761. .globl write_tlb
  762. write_tlb:
  763. mtspr MAS0,r3
  764. mtspr MAS1,r4
  765. mtspr MAS2,r5
  766. mtspr MAS3,r6
  767. #ifdef CONFIG_ENABLE_36BIT_PHYS
  768. mtspr MAS7,r7
  769. #endif
  770. li r3,0
  771. #ifdef CONFIG_SYS_BOOK3E_HV
  772. mtspr MAS8,r3
  773. #endif
  774. isync
  775. tlbwe
  776. msync
  777. isync
  778. blr
  779. /*
  780. * void relocate_code (addr_sp, gd, addr_moni)
  781. *
  782. * This "function" does not return, instead it continues in RAM
  783. * after relocating the monitor code.
  784. *
  785. * r3 = dest
  786. * r4 = src
  787. * r5 = length in bytes
  788. * r6 = cachelinesize
  789. */
  790. .globl relocate_code
  791. relocate_code:
  792. mr r1,r3 /* Set new stack pointer */
  793. mr r9,r4 /* Save copy of Init Data pointer */
  794. mr r10,r5 /* Save copy of Destination Address */
  795. GET_GOT
  796. mr r3,r5 /* Destination Address */
  797. lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  798. ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
  799. lwz r5,GOT(__init_end)
  800. sub r5,r5,r4
  801. li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  802. /*
  803. * Fix GOT pointer:
  804. *
  805. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  806. *
  807. * Offset:
  808. */
  809. sub r15,r10,r4
  810. /* First our own GOT */
  811. add r12,r12,r15
  812. /* the the one used by the C code */
  813. add r30,r30,r15
  814. /*
  815. * Now relocate code
  816. */
  817. cmplw cr1,r3,r4
  818. addi r0,r5,3
  819. srwi. r0,r0,2
  820. beq cr1,4f /* In place copy is not necessary */
  821. beq 7f /* Protect against 0 count */
  822. mtctr r0
  823. bge cr1,2f
  824. la r8,-4(r4)
  825. la r7,-4(r3)
  826. 1: lwzu r0,4(r8)
  827. stwu r0,4(r7)
  828. bdnz 1b
  829. b 4f
  830. 2: slwi r0,r0,2
  831. add r8,r4,r0
  832. add r7,r3,r0
  833. 3: lwzu r0,-4(r8)
  834. stwu r0,-4(r7)
  835. bdnz 3b
  836. /*
  837. * Now flush the cache: note that we must start from a cache aligned
  838. * address. Otherwise we might miss one cache line.
  839. */
  840. 4: cmpwi r6,0
  841. add r5,r3,r5
  842. beq 7f /* Always flush prefetch queue in any case */
  843. subi r0,r6,1
  844. andc r3,r3,r0
  845. mr r4,r3
  846. 5: dcbst 0,r4
  847. add r4,r4,r6
  848. cmplw r4,r5
  849. blt 5b
  850. sync /* Wait for all dcbst to complete on bus */
  851. mr r4,r3
  852. 6: icbi 0,r4
  853. add r4,r4,r6
  854. cmplw r4,r5
  855. blt 6b
  856. 7: sync /* Wait for all icbi to complete on bus */
  857. isync
  858. /*
  859. * Re-point the IVPR at RAM
  860. */
  861. mtspr IVPR,r10
  862. /*
  863. * We are done. Do not return, instead branch to second part of board
  864. * initialization, now running from RAM.
  865. */
  866. addi r0,r10,in_ram - _start + _START_OFFSET
  867. mtlr r0
  868. blr /* NEVER RETURNS! */
  869. .globl in_ram
  870. in_ram:
  871. /*
  872. * Relocation Function, r12 point to got2+0x8000
  873. *
  874. * Adjust got2 pointers, no need to check for 0, this code
  875. * already puts a few entries in the table.
  876. */
  877. li r0,__got2_entries@sectoff@l
  878. la r3,GOT(_GOT2_TABLE_)
  879. lwz r11,GOT(_GOT2_TABLE_)
  880. mtctr r0
  881. sub r11,r3,r11
  882. addi r3,r3,-4
  883. 1: lwzu r0,4(r3)
  884. cmpwi r0,0
  885. beq- 2f
  886. add r0,r0,r11
  887. stw r0,0(r3)
  888. 2: bdnz 1b
  889. /*
  890. * Now adjust the fixups and the pointers to the fixups
  891. * in case we need to move ourselves again.
  892. */
  893. li r0,__fixup_entries@sectoff@l
  894. lwz r3,GOT(_FIXUP_TABLE_)
  895. cmpwi r0,0
  896. mtctr r0
  897. addi r3,r3,-4
  898. beq 4f
  899. 3: lwzu r4,4(r3)
  900. lwzux r0,r4,r11
  901. add r0,r0,r11
  902. stw r10,0(r3)
  903. stw r0,0(r4)
  904. bdnz 3b
  905. 4:
  906. clear_bss:
  907. /*
  908. * Now clear BSS segment
  909. */
  910. lwz r3,GOT(__bss_start)
  911. lwz r4,GOT(_end)
  912. cmplw 0,r3,r4
  913. beq 6f
  914. li r0,0
  915. 5:
  916. stw r0,0(r3)
  917. addi r3,r3,4
  918. cmplw 0,r3,r4
  919. bne 5b
  920. 6:
  921. mr r3,r9 /* Init Data pointer */
  922. mr r4,r10 /* Destination Address */
  923. bl board_init_r
  924. #ifndef CONFIG_NAND_SPL
  925. /*
  926. * Copy exception vector code to low memory
  927. *
  928. * r3: dest_addr
  929. * r7: source address, r8: end address, r9: target address
  930. */
  931. .globl trap_init
  932. trap_init:
  933. mflr r4 /* save link register */
  934. GET_GOT
  935. lwz r7,GOT(_start_of_vectors)
  936. lwz r8,GOT(_end_of_vectors)
  937. li r9,0x100 /* reset vector always at 0x100 */
  938. cmplw 0,r7,r8
  939. bgelr /* return if r7>=r8 - just in case */
  940. 1:
  941. lwz r0,0(r7)
  942. stw r0,0(r9)
  943. addi r7,r7,4
  944. addi r9,r9,4
  945. cmplw 0,r7,r8
  946. bne 1b
  947. /*
  948. * relocate `hdlr' and `int_return' entries
  949. */
  950. li r7,.L_CriticalInput - _start + _START_OFFSET
  951. bl trap_reloc
  952. li r7,.L_MachineCheck - _start + _START_OFFSET
  953. bl trap_reloc
  954. li r7,.L_DataStorage - _start + _START_OFFSET
  955. bl trap_reloc
  956. li r7,.L_InstStorage - _start + _START_OFFSET
  957. bl trap_reloc
  958. li r7,.L_ExtInterrupt - _start + _START_OFFSET
  959. bl trap_reloc
  960. li r7,.L_Alignment - _start + _START_OFFSET
  961. bl trap_reloc
  962. li r7,.L_ProgramCheck - _start + _START_OFFSET
  963. bl trap_reloc
  964. li r7,.L_FPUnavailable - _start + _START_OFFSET
  965. bl trap_reloc
  966. li r7,.L_Decrementer - _start + _START_OFFSET
  967. bl trap_reloc
  968. li r7,.L_IntervalTimer - _start + _START_OFFSET
  969. li r8,_end_of_vectors - _start + _START_OFFSET
  970. 2:
  971. bl trap_reloc
  972. addi r7,r7,0x100 /* next exception vector */
  973. cmplw 0,r7,r8
  974. blt 2b
  975. lis r7,0x0
  976. mtspr IVPR,r7
  977. mtlr r4 /* restore link register */
  978. blr
  979. .globl unlock_ram_in_cache
  980. unlock_ram_in_cache:
  981. /* invalidate the INIT_RAM section */
  982. lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
  983. ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
  984. mfspr r4,L1CFG0
  985. andi. r4,r4,0x1ff
  986. slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
  987. mtctr r4
  988. 1: dcbi r0,r3
  989. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  990. bdnz 1b
  991. sync
  992. /* Invalidate the TLB entries for the cache */
  993. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  994. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  995. tlbivax 0,r3
  996. addi r3,r3,0x1000
  997. tlbivax 0,r3
  998. addi r3,r3,0x1000
  999. tlbivax 0,r3
  1000. addi r3,r3,0x1000
  1001. tlbivax 0,r3
  1002. isync
  1003. blr
  1004. .globl flush_dcache
  1005. flush_dcache:
  1006. mfspr r3,SPRN_L1CFG0
  1007. rlwinm r5,r3,9,3 /* Extract cache block size */
  1008. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  1009. * are currently defined.
  1010. */
  1011. li r4,32
  1012. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  1013. * log2(number of ways)
  1014. */
  1015. slw r5,r4,r5 /* r5 = cache block size */
  1016. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  1017. mulli r7,r7,13 /* An 8-way cache will require 13
  1018. * loads per set.
  1019. */
  1020. slw r7,r7,r6
  1021. /* save off HID0 and set DCFA */
  1022. mfspr r8,SPRN_HID0
  1023. ori r9,r8,HID0_DCFA@l
  1024. mtspr SPRN_HID0,r9
  1025. isync
  1026. lis r4,0
  1027. mtctr r7
  1028. 1: lwz r3,0(r4) /* Load... */
  1029. add r4,r4,r5
  1030. bdnz 1b
  1031. msync
  1032. lis r4,0
  1033. mtctr r7
  1034. 1: dcbf 0,r4 /* ...and flush. */
  1035. add r4,r4,r5
  1036. bdnz 1b
  1037. /* restore HID0 */
  1038. mtspr SPRN_HID0,r8
  1039. isync
  1040. blr
  1041. .globl setup_ivors
  1042. setup_ivors:
  1043. #include "fixed_ivor.S"
  1044. blr
  1045. #endif /* !CONFIG_NAND_SPL */