start.S 25 KB

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