start.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * Copyright 2004, 2007 Freescale Semiconductor.
  3. * Srikanth Srinivasan <srikanth.srinivaan@freescale.com>
  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 86xx PowerPC based Embedded Boards
  24. *
  25. *
  26. * The processor starts at 0xfff00100 and the code is executed
  27. * from flash. The code is organized to be at an other address
  28. * in memory, but as long we don't jump around before relocating.
  29. * board_init lies at a quite high address and when the cpu has
  30. * jumped there, everything is ok.
  31. */
  32. #include <config.h>
  33. #include <mpc86xx.h>
  34. #include <version.h>
  35. #include <ppc_asm.tmpl>
  36. #include <ppc_defs.h>
  37. #include <asm/cache.h>
  38. #include <asm/mmu.h>
  39. #ifndef CONFIG_IDENT_STRING
  40. #define CONFIG_IDENT_STRING ""
  41. #endif
  42. /*
  43. * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
  44. */
  45. /*
  46. * Set up GOT: Global Offset Table
  47. *
  48. * Use r14 to access the GOT
  49. */
  50. START_GOT
  51. GOT_ENTRY(_GOT2_TABLE_)
  52. GOT_ENTRY(_FIXUP_TABLE_)
  53. GOT_ENTRY(_start)
  54. GOT_ENTRY(_start_of_vectors)
  55. GOT_ENTRY(_end_of_vectors)
  56. GOT_ENTRY(transfer_to_handler)
  57. GOT_ENTRY(__init_end)
  58. GOT_ENTRY(_end)
  59. GOT_ENTRY(__bss_start)
  60. END_GOT
  61. /*
  62. * r3 - 1st arg to board_init(): IMMP pointer
  63. * r4 - 2nd arg to board_init(): boot flag
  64. */
  65. .text
  66. .long 0x27051956 /* U-Boot Magic Number */
  67. .globl version_string
  68. version_string:
  69. .ascii U_BOOT_VERSION
  70. .ascii " (", __DATE__, " - ", __TIME__, ")"
  71. .ascii CONFIG_IDENT_STRING, "\0"
  72. . = EXC_OFF_SYS_RESET
  73. .globl _start
  74. _start:
  75. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  76. b boot_cold
  77. sync
  78. . = EXC_OFF_SYS_RESET + 0x10
  79. .globl _start_warm
  80. _start_warm:
  81. li r21, BOOTFLAG_WARM /* Software reboot */
  82. b boot_warm
  83. sync
  84. /* the boot code is located below the exception table */
  85. .globl _start_of_vectors
  86. _start_of_vectors:
  87. /* Machine check */
  88. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  89. /* Data Storage exception. */
  90. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  91. /* Instruction Storage exception. */
  92. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  93. /* External Interrupt exception. */
  94. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  95. /* Alignment exception. */
  96. . = 0x600
  97. Alignment:
  98. EXCEPTION_PROLOG(SRR0, SRR1)
  99. mfspr r4,DAR
  100. stw r4,_DAR(r21)
  101. mfspr r5,DSISR
  102. stw r5,_DSISR(r21)
  103. addi r3,r1,STACK_FRAME_OVERHEAD
  104. li r20,MSR_KERNEL
  105. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  106. lwz r6,GOT(transfer_to_handler)
  107. mtlr r6
  108. blrl
  109. .L_Alignment:
  110. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  111. .long int_return - _start + EXC_OFF_SYS_RESET
  112. /* Program check exception */
  113. . = 0x700
  114. ProgramCheck:
  115. EXCEPTION_PROLOG(SRR0, SRR1)
  116. addi r3,r1,STACK_FRAME_OVERHEAD
  117. li r20,MSR_KERNEL
  118. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  119. lwz r6,GOT(transfer_to_handler)
  120. mtlr r6
  121. blrl
  122. .L_ProgramCheck:
  123. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  124. .long int_return - _start + EXC_OFF_SYS_RESET
  125. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  126. /* I guess we could implement decrementer, and may have
  127. * to someday for timekeeping.
  128. */
  129. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  130. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  131. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  132. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  133. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  134. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  135. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  136. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  137. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  138. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  139. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  140. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  141. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  142. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  143. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  144. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  145. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  146. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  147. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  148. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  149. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  150. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  151. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  152. .globl _end_of_vectors
  153. _end_of_vectors:
  154. . = 0x2000
  155. boot_cold:
  156. boot_warm:
  157. /* if this is a multi-core system we need to check which cpu
  158. * this is, if it is not cpu 0 send the cpu to the linux reset
  159. * vector */
  160. #if (CONFIG_NUM_CPUS > 1)
  161. mfspr r0, MSSCR0
  162. andi. r0, r0, 0x0020
  163. rlwinm r0,r0,27,31,31
  164. mtspr PIR, r0
  165. beq 1f
  166. bl secondary_cpu_setup
  167. #endif
  168. 1:
  169. #ifdef CFG_RAMBOOT
  170. /* disable everything */
  171. li r0, 0
  172. mtspr HID0, r0
  173. sync
  174. mtmsr 0
  175. #endif
  176. bl invalidate_bats
  177. sync
  178. #ifdef CFG_L2
  179. /* init the L2 cache */
  180. lis r3, L2_INIT@h
  181. ori r3, r3, L2_INIT@l
  182. mtspr l2cr, r3
  183. /* invalidate the L2 cache */
  184. bl l2cache_invalidate
  185. sync
  186. #endif
  187. /*
  188. * Calculate absolute address in FLASH and jump there
  189. *------------------------------------------------------*/
  190. lis r3, CFG_MONITOR_BASE@h
  191. ori r3, r3, CFG_MONITOR_BASE@l
  192. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  193. mtlr r3
  194. blr
  195. in_flash:
  196. /* let the C-code set up the rest */
  197. /* */
  198. /* Be careful to keep code relocatable ! */
  199. /*------------------------------------------------------*/
  200. /* perform low-level init */
  201. /* enable extended addressing */
  202. bl enable_ext_addr
  203. /* setup the bats */
  204. bl early_bats
  205. /*
  206. * Cache must be enabled here for stack-in-cache trick.
  207. * This means we need to enable the BATS.
  208. * Cache should be turned on after BATs, since by default
  209. * everything is write-through.
  210. */
  211. /* enable address translation */
  212. bl enable_addr_trans
  213. sync
  214. /* enable and invalidate the data cache */
  215. /* bl l1dcache_enable */
  216. bl dcache_enable
  217. sync
  218. #if 1
  219. bl icache_enable
  220. #endif
  221. #ifdef CFG_INIT_RAM_LOCK
  222. bl lock_ram_in_cache
  223. sync
  224. #endif
  225. /* set up the stack pointer in our newly created
  226. * cache-ram (r1) */
  227. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  228. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  229. li r0, 0 /* Make room for stack frame header and */
  230. stwu r0, -4(r1) /* clear final stack frame so that */
  231. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  232. GET_GOT /* initialize GOT access */
  233. /* setup the rest of the bats */
  234. bl setup_bats
  235. bl clear_tlbs
  236. sync
  237. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  238. /* setup ccsrbar */
  239. bl setup_ccsrbar
  240. #endif
  241. /* run low-level CPU init code (from Flash) */
  242. bl cpu_init_f
  243. sync
  244. #ifdef RUN_DIAG
  245. /* Load PX_AUX register address in r4 */
  246. lis r4, 0xf810
  247. ori r4, r4, 0x6
  248. /* Load contents of PX_AUX in r3 bits 24 to 31*/
  249. lbz r3, 0(r4)
  250. /* Mask and obtain the bit in r3 */
  251. rlwinm. r3, r3, 0, 24, 24
  252. /* If not zero, jump and continue with u-boot */
  253. bne diag_done
  254. /* Load back contents of PX_AUX in r3 bits 24 to 31 */
  255. lbz r3, 0(r4)
  256. /* Set the MSB of the register value */
  257. ori r3, r3, 0x80
  258. /* Write value in r3 back to PX_AUX */
  259. stb r3, 0(r4)
  260. /* Get the address to jump to in r3*/
  261. lis r3, CFG_DIAG_ADDR@h
  262. ori r3, r3, CFG_DIAG_ADDR@l
  263. /* Load the LR with the branch address */
  264. mtlr r3
  265. /* Branch to diagnostic */
  266. blr
  267. diag_done:
  268. #endif
  269. /* bl l2cache_enable */
  270. mr r3, r21
  271. /* r3: BOOTFLAG */
  272. /* run 1st part of board init code (from Flash) */
  273. bl board_init_f
  274. sync
  275. /* NOTREACHED */
  276. .globl invalidate_bats
  277. invalidate_bats:
  278. li r0, 0
  279. /* invalidate BATs */
  280. mtspr IBAT0U, r0
  281. mtspr IBAT1U, r0
  282. mtspr IBAT2U, r0
  283. mtspr IBAT3U, r0
  284. mtspr IBAT4U, r0
  285. mtspr IBAT5U, r0
  286. mtspr IBAT6U, r0
  287. mtspr IBAT7U, r0
  288. isync
  289. mtspr DBAT0U, r0
  290. mtspr DBAT1U, r0
  291. mtspr DBAT2U, r0
  292. mtspr DBAT3U, r0
  293. mtspr DBAT4U, r0
  294. mtspr DBAT5U, r0
  295. mtspr DBAT6U, r0
  296. mtspr DBAT7U, r0
  297. isync
  298. sync
  299. blr
  300. /* setup_bats - set them up to some initial state */
  301. /* Skip any BATS setup in early_bats */
  302. .globl setup_bats
  303. setup_bats:
  304. addis r0, r0, 0x0000
  305. /* IBAT 0 */
  306. addis r4, r0, CFG_IBAT0L@h
  307. ori r4, r4, CFG_IBAT0L@l
  308. addis r3, r0, CFG_IBAT0U@h
  309. ori r3, r3, CFG_IBAT0U@l
  310. mtspr IBAT0L, r4
  311. mtspr IBAT0U, r3
  312. isync
  313. /* DBAT 0 */
  314. addis r4, r0, CFG_DBAT0L@h
  315. ori r4, r4, CFG_DBAT0L@l
  316. addis r3, r0, CFG_DBAT0U@h
  317. ori r3, r3, CFG_DBAT0U@l
  318. mtspr DBAT0L, r4
  319. mtspr DBAT0U, r3
  320. isync
  321. /* IBAT 1 */
  322. addis r4, r0, CFG_IBAT1L@h
  323. ori r4, r4, CFG_IBAT1L@l
  324. addis r3, r0, CFG_IBAT1U@h
  325. ori r3, r3, CFG_IBAT1U@l
  326. mtspr IBAT1L, r4
  327. mtspr IBAT1U, r3
  328. isync
  329. /* DBAT 1 */
  330. addis r4, r0, CFG_DBAT1L@h
  331. ori r4, r4, CFG_DBAT1L@l
  332. addis r3, r0, CFG_DBAT1U@h
  333. ori r3, r3, CFG_DBAT1U@l
  334. mtspr DBAT1L, r4
  335. mtspr DBAT1U, r3
  336. isync
  337. /* IBAT 2 */
  338. addis r4, r0, CFG_IBAT2L@h
  339. ori r4, r4, CFG_IBAT2L@l
  340. addis r3, r0, CFG_IBAT2U@h
  341. ori r3, r3, CFG_IBAT2U@l
  342. mtspr IBAT2L, r4
  343. mtspr IBAT2U, r3
  344. isync
  345. /* DBAT 2 */
  346. addis r4, r0, CFG_DBAT2L@h
  347. ori r4, r4, CFG_DBAT2L@l
  348. addis r3, r0, CFG_DBAT2U@h
  349. ori r3, r3, CFG_DBAT2U@l
  350. mtspr DBAT2L, r4
  351. mtspr DBAT2U, r3
  352. isync
  353. /* IBAT 3 */
  354. addis r4, r0, CFG_IBAT3L@h
  355. ori r4, r4, CFG_IBAT3L@l
  356. addis r3, r0, CFG_IBAT3U@h
  357. ori r3, r3, CFG_IBAT3U@l
  358. mtspr IBAT3L, r4
  359. mtspr IBAT3U, r3
  360. isync
  361. /* DBAT 3 */
  362. addis r4, r0, CFG_DBAT3L@h
  363. ori r4, r4, CFG_DBAT3L@l
  364. addis r3, r0, CFG_DBAT3U@h
  365. ori r3, r3, CFG_DBAT3U@l
  366. mtspr DBAT3L, r4
  367. mtspr DBAT3U, r3
  368. isync
  369. /* IBAT 4 */
  370. addis r4, r0, CFG_IBAT4L@h
  371. ori r4, r4, CFG_IBAT4L@l
  372. addis r3, r0, CFG_IBAT4U@h
  373. ori r3, r3, CFG_IBAT4U@l
  374. mtspr IBAT4L, r4
  375. mtspr IBAT4U, r3
  376. isync
  377. /* DBAT 4 */
  378. addis r4, r0, CFG_DBAT4L@h
  379. ori r4, r4, CFG_DBAT4L@l
  380. addis r3, r0, CFG_DBAT4U@h
  381. ori r3, r3, CFG_DBAT4U@l
  382. mtspr DBAT4L, r4
  383. mtspr DBAT4U, r3
  384. isync
  385. /* IBAT 7 */
  386. addis r4, r0, CFG_IBAT7L@h
  387. ori r4, r4, CFG_IBAT7L@l
  388. addis r3, r0, CFG_IBAT7U@h
  389. ori r3, r3, CFG_IBAT7U@l
  390. mtspr IBAT7L, r4
  391. mtspr IBAT7U, r3
  392. isync
  393. /* DBAT 7 */
  394. addis r4, r0, CFG_DBAT7L@h
  395. ori r4, r4, CFG_DBAT7L@l
  396. addis r3, r0, CFG_DBAT7U@h
  397. ori r3, r3, CFG_DBAT7U@l
  398. mtspr DBAT7L, r4
  399. mtspr DBAT7U, r3
  400. isync
  401. sync
  402. blr
  403. /*
  404. * early_bats:
  405. *
  406. * Set up bats needed early on - this is usually the BAT for the
  407. * stack-in-cache and the Flash
  408. */
  409. .globl early_bats
  410. early_bats:
  411. /* IBAT 5 */
  412. lis r4, CFG_IBAT5L@h
  413. ori r4, r4, CFG_IBAT5L@l
  414. lis r3, CFG_IBAT5U@h
  415. ori r3, r3, CFG_IBAT5U@l
  416. mtspr IBAT5L, r4
  417. mtspr IBAT5U, r3
  418. isync
  419. /* DBAT 5 */
  420. lis r4, CFG_DBAT5L@h
  421. ori r4, r4, CFG_DBAT5L@l
  422. lis r3, CFG_DBAT5U@h
  423. ori r3, r3, CFG_DBAT5U@l
  424. mtspr DBAT5L, r4
  425. mtspr DBAT5U, r3
  426. isync
  427. /* IBAT 6 */
  428. lis r4, CFG_IBAT6L@h
  429. ori r4, r4, CFG_IBAT6L@l
  430. lis r3, CFG_IBAT6U@h
  431. ori r3, r3, CFG_IBAT6U@l
  432. mtspr IBAT6L, r4
  433. mtspr IBAT6U, r3
  434. isync
  435. /* DBAT 6 */
  436. lis r4, CFG_DBAT6L@h
  437. ori r4, r4, CFG_DBAT6L@l
  438. lis r3, CFG_DBAT6U@h
  439. ori r3, r3, CFG_DBAT6U@l
  440. mtspr DBAT6L, r4
  441. mtspr DBAT6U, r3
  442. isync
  443. blr
  444. .globl clear_tlbs
  445. clear_tlbs:
  446. addis r3, 0, 0x0000
  447. addis r5, 0, 0x4
  448. isync
  449. tlblp:
  450. tlbie r3
  451. sync
  452. addi r3, r3, 0x1000
  453. cmp 0, 0, r3, r5
  454. blt tlblp
  455. blr
  456. .globl enable_addr_trans
  457. enable_addr_trans:
  458. /* enable address translation */
  459. mfmsr r5
  460. ori r5, r5, (MSR_IR | MSR_DR)
  461. mtmsr r5
  462. isync
  463. blr
  464. .globl disable_addr_trans
  465. disable_addr_trans:
  466. /* disable address translation */
  467. mflr r4
  468. mfmsr r3
  469. andi. r0, r3, (MSR_IR | MSR_DR)
  470. beqlr
  471. andc r3, r3, r0
  472. mtspr SRR0, r4
  473. mtspr SRR1, r3
  474. rfi
  475. /*
  476. * This code finishes saving the registers to the exception frame
  477. * and jumps to the appropriate handler for the exception.
  478. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  479. */
  480. .globl transfer_to_handler
  481. transfer_to_handler:
  482. stw r22,_NIP(r21)
  483. lis r22,MSR_POW@h
  484. andc r23,r23,r22
  485. stw r23,_MSR(r21)
  486. SAVE_GPR(7, r21)
  487. SAVE_4GPRS(8, r21)
  488. SAVE_8GPRS(12, r21)
  489. SAVE_8GPRS(24, r21)
  490. mflr r23
  491. andi. r24,r23,0x3f00 /* get vector offset */
  492. stw r24,TRAP(r21)
  493. li r22,0
  494. stw r22,RESULT(r21)
  495. mtspr SPRG2,r22 /* r1 is now kernel sp */
  496. lwz r24,0(r23) /* virtual address of handler */
  497. lwz r23,4(r23) /* where to go when done */
  498. mtspr SRR0,r24
  499. mtspr SRR1,r20
  500. mtlr r23
  501. SYNC
  502. rfi /* jump to handler, enable MMU */
  503. int_return:
  504. mfmsr r28 /* Disable interrupts */
  505. li r4,0
  506. ori r4,r4,MSR_EE
  507. andc r28,r28,r4
  508. SYNC /* Some chip revs need this... */
  509. mtmsr r28
  510. SYNC
  511. lwz r2,_CTR(r1)
  512. lwz r0,_LINK(r1)
  513. mtctr r2
  514. mtlr r0
  515. lwz r2,_XER(r1)
  516. lwz r0,_CCR(r1)
  517. mtspr XER,r2
  518. mtcrf 0xFF,r0
  519. REST_10GPRS(3, r1)
  520. REST_10GPRS(13, r1)
  521. REST_8GPRS(23, r1)
  522. REST_GPR(31, r1)
  523. lwz r2,_NIP(r1) /* Restore environment */
  524. lwz r0,_MSR(r1)
  525. mtspr SRR0,r2
  526. mtspr SRR1,r0
  527. lwz r0,GPR0(r1)
  528. lwz r2,GPR2(r1)
  529. lwz r1,GPR1(r1)
  530. SYNC
  531. rfi
  532. .globl dc_read
  533. dc_read:
  534. blr
  535. .globl get_pvr
  536. get_pvr:
  537. mfspr r3, PVR
  538. blr
  539. .globl get_svr
  540. get_svr:
  541. mfspr r3, SVR
  542. blr
  543. /*
  544. * Function: in8
  545. * Description: Input 8 bits
  546. */
  547. .globl in8
  548. in8:
  549. lbz r3,0x0000(r3)
  550. blr
  551. /*
  552. * Function: out8
  553. * Description: Output 8 bits
  554. */
  555. .globl out8
  556. out8:
  557. stb r4,0x0000(r3)
  558. blr
  559. /*
  560. * Function: out16
  561. * Description: Output 16 bits
  562. */
  563. .globl out16
  564. out16:
  565. sth r4,0x0000(r3)
  566. blr
  567. /*
  568. * Function: out16r
  569. * Description: Byte reverse and output 16 bits
  570. */
  571. .globl out16r
  572. out16r:
  573. sthbrx r4,r0,r3
  574. blr
  575. /*
  576. * Function: out32
  577. * Description: Output 32 bits
  578. */
  579. .globl out32
  580. out32:
  581. stw r4,0x0000(r3)
  582. blr
  583. /*
  584. * Function: out32r
  585. * Description: Byte reverse and output 32 bits
  586. */
  587. .globl out32r
  588. out32r:
  589. stwbrx r4,r0,r3
  590. blr
  591. /*
  592. * Function: in16
  593. * Description: Input 16 bits
  594. */
  595. .globl in16
  596. in16:
  597. lhz r3,0x0000(r3)
  598. blr
  599. /*
  600. * Function: in16r
  601. * Description: Input 16 bits and byte reverse
  602. */
  603. .globl in16r
  604. in16r:
  605. lhbrx r3,r0,r3
  606. blr
  607. /*
  608. * Function: in32
  609. * Description: Input 32 bits
  610. */
  611. .globl in32
  612. in32:
  613. lwz 3,0x0000(3)
  614. blr
  615. /*
  616. * Function: in32r
  617. * Description: Input 32 bits and byte reverse
  618. */
  619. .globl in32r
  620. in32r:
  621. lwbrx r3,r0,r3
  622. blr
  623. /*
  624. * void relocate_code (addr_sp, gd, addr_moni)
  625. *
  626. * This "function" does not return, instead it continues in RAM
  627. * after relocating the monitor code.
  628. *
  629. * r3 = dest
  630. * r4 = src
  631. * r5 = length in bytes
  632. * r6 = cachelinesize
  633. */
  634. .globl relocate_code
  635. relocate_code:
  636. mr r1, r3 /* Set new stack pointer */
  637. mr r9, r4 /* Save copy of Global Data pointer */
  638. mr r2, r9 /* Save for DECLARE_GLOBAL_DATA_PTR */
  639. mr r10, r5 /* Save copy of Destination Address */
  640. mr r3, r5 /* Destination Address */
  641. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  642. ori r4, r4, CFG_MONITOR_BASE@l
  643. lwz r5, GOT(__init_end)
  644. sub r5, r5, r4
  645. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  646. /*
  647. * Fix GOT pointer:
  648. *
  649. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  650. *
  651. * Offset:
  652. */
  653. sub r15, r10, r4
  654. /* First our own GOT */
  655. add r14, r14, r15
  656. /* then the one used by the C code */
  657. add r30, r30, r15
  658. /*
  659. * Now relocate code
  660. */
  661. #ifdef CONFIG_ECC
  662. bl board_relocate_rom
  663. sync
  664. mr r3, r10 /* Destination Address */
  665. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  666. ori r4, r4, CFG_MONITOR_BASE@l
  667. lwz r5, GOT(__init_end)
  668. sub r5, r5, r4
  669. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  670. #else
  671. cmplw cr1,r3,r4
  672. addi r0,r5,3
  673. srwi. r0,r0,2
  674. beq cr1,4f /* In place copy is not necessary */
  675. beq 7f /* Protect against 0 count */
  676. mtctr r0
  677. bge cr1,2f
  678. la r8,-4(r4)
  679. la r7,-4(r3)
  680. 1: lwzu r0,4(r8)
  681. stwu r0,4(r7)
  682. bdnz 1b
  683. b 4f
  684. 2: slwi r0,r0,2
  685. add r8,r4,r0
  686. add r7,r3,r0
  687. 3: lwzu r0,-4(r8)
  688. stwu r0,-4(r7)
  689. bdnz 3b
  690. #endif
  691. /*
  692. * Now flush the cache: note that we must start from a cache aligned
  693. * address. Otherwise we might miss one cache line.
  694. */
  695. 4: cmpwi r6,0
  696. add r5,r3,r5
  697. beq 7f /* Always flush prefetch queue in any case */
  698. subi r0,r6,1
  699. andc r3,r3,r0
  700. mr r4,r3
  701. 5: dcbst 0,r4
  702. add r4,r4,r6
  703. cmplw r4,r5
  704. blt 5b
  705. sync /* Wait for all dcbst to complete on bus */
  706. mr r4,r3
  707. 6: icbi 0,r4
  708. add r4,r4,r6
  709. cmplw r4,r5
  710. blt 6b
  711. 7: sync /* Wait for all icbi to complete on bus */
  712. isync
  713. /*
  714. * We are done. Do not return, instead branch to second part of board
  715. * initialization, now running from RAM.
  716. */
  717. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  718. mtlr r0
  719. blr
  720. in_ram:
  721. #ifdef CONFIG_ECC
  722. bl board_init_ecc
  723. #endif
  724. /*
  725. * Relocation Function, r14 point to got2+0x8000
  726. *
  727. * Adjust got2 pointers, no need to check for 0, this code
  728. * already puts a few entries in the table.
  729. */
  730. li r0,__got2_entries@sectoff@l
  731. la r3,GOT(_GOT2_TABLE_)
  732. lwz r11,GOT(_GOT2_TABLE_)
  733. mtctr r0
  734. sub r11,r3,r11
  735. addi r3,r3,-4
  736. 1: lwzu r0,4(r3)
  737. add r0,r0,r11
  738. stw r0,0(r3)
  739. bdnz 1b
  740. /*
  741. * Now adjust the fixups and the pointers to the fixups
  742. * in case we need to move ourselves again.
  743. */
  744. 2: li r0,__fixup_entries@sectoff@l
  745. lwz r3,GOT(_FIXUP_TABLE_)
  746. cmpwi r0,0
  747. mtctr r0
  748. addi r3,r3,-4
  749. beq 4f
  750. 3: lwzu r4,4(r3)
  751. lwzux r0,r4,r11
  752. add r0,r0,r11
  753. stw r10,0(r3)
  754. stw r0,0(r4)
  755. bdnz 3b
  756. 4:
  757. /* clear_bss: */
  758. /*
  759. * Now clear BSS segment
  760. */
  761. lwz r3,GOT(__bss_start)
  762. lwz r4,GOT(_end)
  763. cmplw 0, r3, r4
  764. beq 6f
  765. li r0, 0
  766. 5:
  767. stw r0, 0(r3)
  768. addi r3, r3, 4
  769. cmplw 0, r3, r4
  770. bne 5b
  771. 6:
  772. mr r3, r9 /* Init Date pointer */
  773. mr r4, r10 /* Destination Address */
  774. bl board_init_r
  775. /* not reached - end relocate_code */
  776. /*-----------------------------------------------------------------------*/
  777. /*
  778. * Copy exception vector code to low memory
  779. *
  780. * r3: dest_addr
  781. * r7: source address, r8: end address, r9: target address
  782. */
  783. .globl trap_init
  784. trap_init:
  785. lwz r7, GOT(_start)
  786. lwz r8, GOT(_end_of_vectors)
  787. li r9, 0x100 /* reset vector always at 0x100 */
  788. cmplw 0, r7, r8
  789. bgelr /* return if r7>=r8 - just in case */
  790. mflr r4 /* save link register */
  791. 1:
  792. lwz r0, 0(r7)
  793. stw r0, 0(r9)
  794. addi r7, r7, 4
  795. addi r9, r9, 4
  796. cmplw 0, r7, r8
  797. bne 1b
  798. /*
  799. * relocate `hdlr' and `int_return' entries
  800. */
  801. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  802. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  803. 2:
  804. bl trap_reloc
  805. addi r7, r7, 0x100 /* next exception vector */
  806. cmplw 0, r7, r8
  807. blt 2b
  808. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  809. bl trap_reloc
  810. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  811. bl trap_reloc
  812. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  813. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  814. 3:
  815. bl trap_reloc
  816. addi r7, r7, 0x100 /* next exception vector */
  817. cmplw 0, r7, r8
  818. blt 3b
  819. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  820. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  821. 4:
  822. bl trap_reloc
  823. addi r7, r7, 0x100 /* next exception vector */
  824. cmplw 0, r7, r8
  825. blt 4b
  826. /* enable execptions from RAM vectors */
  827. mfmsr r7
  828. li r8,MSR_IP
  829. andc r7,r7,r8
  830. ori r7,r7,MSR_ME /* Enable Machine Check */
  831. mtmsr r7
  832. mtlr r4 /* restore link register */
  833. blr
  834. /*
  835. * Function: relocate entries for one exception vector
  836. */
  837. trap_reloc:
  838. lwz r0, 0(r7) /* hdlr ... */
  839. add r0, r0, r3 /* ... += dest_addr */
  840. stw r0, 0(r7)
  841. lwz r0, 4(r7) /* int_return ... */
  842. add r0, r0, r3 /* ... += dest_addr */
  843. stw r0, 4(r7)
  844. sync
  845. isync
  846. blr
  847. .globl enable_ext_addr
  848. enable_ext_addr:
  849. mfspr r0, HID0
  850. lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
  851. ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
  852. mtspr HID0, r0
  853. sync
  854. isync
  855. blr
  856. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  857. .globl setup_ccsrbar
  858. setup_ccsrbar:
  859. /* Special sequence needed to update CCSRBAR itself */
  860. lis r4, CFG_CCSRBAR_DEFAULT@h
  861. ori r4, r4, CFG_CCSRBAR_DEFAULT@l
  862. lis r5, CFG_CCSRBAR@h
  863. ori r5, r5, CFG_CCSRBAR@l
  864. srwi r6,r5,12
  865. stw r6, 0(r4)
  866. isync
  867. lis r5, 0xffff
  868. ori r5,r5,0xf000
  869. lwz r5, 0(r5)
  870. isync
  871. lis r3, CFG_CCSRBAR@h
  872. lwz r5, CFG_CCSRBAR@l(r3)
  873. isync
  874. blr
  875. #endif
  876. #ifdef CFG_INIT_RAM_LOCK
  877. lock_ram_in_cache:
  878. /* Allocate Initial RAM in data cache.
  879. */
  880. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  881. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  882. li r2, ((CFG_INIT_RAM_END & ~31) + \
  883. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  884. mtctr r2
  885. 1:
  886. dcbz r0, r3
  887. addi r3, r3, 32
  888. bdnz 1b
  889. #if 1
  890. /* Lock the data cache */
  891. mfspr r0, HID0
  892. ori r0, r0, 0x1000
  893. sync
  894. mtspr HID0, r0
  895. sync
  896. blr
  897. #endif
  898. #if 0
  899. /* Lock the first way of the data cache */
  900. mfspr r0, LDSTCR
  901. ori r0, r0, 0x0080
  902. #if defined(CONFIG_ALTIVEC)
  903. dssall
  904. #endif
  905. sync
  906. mtspr LDSTCR, r0
  907. sync
  908. isync
  909. blr
  910. #endif
  911. .globl unlock_ram_in_cache
  912. unlock_ram_in_cache:
  913. /* invalidate the INIT_RAM section */
  914. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  915. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  916. li r2, ((CFG_INIT_RAM_END & ~31) + \
  917. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  918. mtctr r2
  919. 1: icbi r0, r3
  920. addi r3, r3, 32
  921. bdnz 1b
  922. sync /* Wait for all icbi to complete on bus */
  923. isync
  924. #if 1
  925. /* Unlock the data cache and invalidate it */
  926. mfspr r0, HID0
  927. li r3,0x1000
  928. andc r0,r0,r3
  929. li r3,0x0400
  930. or r0,r0,r3
  931. sync
  932. mtspr HID0, r0
  933. sync
  934. blr
  935. #endif
  936. #if 0
  937. /* Unlock the first way of the data cache */
  938. mfspr r0, LDSTCR
  939. li r3,0x0080
  940. andc r0,r0,r3
  941. #ifdef CONFIG_ALTIVEC
  942. dssall
  943. #endif
  944. sync
  945. mtspr LDSTCR, r0
  946. sync
  947. isync
  948. li r3,0x0400
  949. or r0,r0,r3
  950. sync
  951. mtspr HID0, r0
  952. sync
  953. blr
  954. #endif
  955. #endif
  956. /* If this is a multi-cpu system then we need to handle the
  957. * 2nd cpu. The assumption is that the 2nd cpu is being
  958. * held in boot holdoff mode until the 1st cpu unlocks it
  959. * from Linux. We'll do some basic cpu init and then pass
  960. * it to the Linux Reset Vector.
  961. * Sri: Much of this initialization is not required. Linux
  962. * rewrites the bats, and the sprs and also enables the L1 cache.
  963. */
  964. #if (CONFIG_NUM_CPUS > 1)
  965. .globl secondary_cpu_setup
  966. secondary_cpu_setup:
  967. /* Do only core setup on all cores except cpu0 */
  968. bl invalidate_bats
  969. sync
  970. bl enable_ext_addr
  971. #ifdef CFG_L2
  972. /* init the L2 cache */
  973. addis r3, r0, L2_INIT@h
  974. ori r3, r3, L2_INIT@l
  975. sync
  976. mtspr l2cr, r3
  977. #ifdef CONFIG_ALTIVEC
  978. dssall
  979. #endif
  980. /* invalidate the L2 cache */
  981. bl l2cache_invalidate
  982. sync
  983. #endif
  984. /* enable and invalidate the data cache */
  985. bl dcache_enable
  986. sync
  987. /* enable and invalidate the instruction cache*/
  988. bl icache_enable
  989. sync
  990. /* TBEN in HID0 */
  991. mfspr r4, HID0
  992. oris r4, r4, 0x0400
  993. mtspr HID0, r4
  994. sync
  995. isync
  996. /* MCP|SYNCBE|ABE in HID1 */
  997. mfspr r4, HID1
  998. oris r4, r4, 0x8000
  999. ori r4, r4, 0x0C00
  1000. mtspr HID1, r4
  1001. sync
  1002. isync
  1003. lis r3, CONFIG_LINUX_RESET_VEC@h
  1004. ori r3, r3, CONFIG_LINUX_RESET_VEC@l
  1005. mtlr r3
  1006. blr
  1007. /* Never Returns, Running in Linux Now */
  1008. #endif