start.S 26 KB

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