start.S 24 KB

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