start.S 27 KB

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