start.S 25 KB

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