start.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /* U-Boot - Startup Code for PowerPC based Embedded Boards
  25. *
  26. *
  27. * The processor starts at 0x00000100 and the code is executed
  28. * from flash. The code is organized to be at an other address
  29. * in memory, but as long we don't jump around before relocating.
  30. * board_init lies at a quite high address and when the cpu has
  31. * jumped there, everything is ok.
  32. * This works because the cpu gives the FLASH (CS0) the whole
  33. * address space at startup, and board_init lies as a echo of
  34. * the flash somewhere up there in the memorymap.
  35. *
  36. * board_init will change CS0 to be positioned at the correct
  37. * address and (s)dram will be positioned at address 0
  38. */
  39. #include <asm-offsets.h>
  40. #include <config.h>
  41. #include <mpc824x.h>
  42. #include <timestamp.h>
  43. #include <version.h>
  44. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  45. #include <ppc_asm.tmpl>
  46. #include <ppc_defs.h>
  47. #include <asm/cache.h>
  48. #include <asm/mmu.h>
  49. #include <asm/u-boot.h>
  50. #ifndef CONFIG_IDENT_STRING
  51. #define CONFIG_IDENT_STRING ""
  52. #endif
  53. /* We don't want the MMU yet.
  54. */
  55. #undef MSR_KERNEL
  56. /* FP, Machine Check and Recoverable Interr. */
  57. #define MSR_KERNEL ( MSR_FP | MSR_ME | MSR_RI )
  58. /*
  59. * Set up GOT: Global Offset Table
  60. *
  61. * Use r12 to access the GOT
  62. */
  63. START_GOT
  64. GOT_ENTRY(_GOT2_TABLE_)
  65. GOT_ENTRY(_FIXUP_TABLE_)
  66. GOT_ENTRY(_start)
  67. GOT_ENTRY(_start_of_vectors)
  68. GOT_ENTRY(_end_of_vectors)
  69. GOT_ENTRY(transfer_to_handler)
  70. GOT_ENTRY(__init_end)
  71. GOT_ENTRY(__bss_end__)
  72. GOT_ENTRY(__bss_start)
  73. #if defined(CONFIG_FADS)
  74. GOT_ENTRY(environment)
  75. #endif
  76. END_GOT
  77. /*
  78. * r3 - 1st arg to board_init(): IMMP pointer
  79. * r4 - 2nd arg to board_init(): boot flag
  80. */
  81. .text
  82. .long 0x27051956 /* U-Boot Magic Number */
  83. .globl version_string
  84. version_string:
  85. .ascii U_BOOT_VERSION
  86. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  87. .ascii CONFIG_IDENT_STRING, "\0"
  88. . = EXC_OFF_SYS_RESET
  89. .globl _start
  90. _start:
  91. /* Initialize machine status; enable machine check interrupt */
  92. /*----------------------------------------------------------------------*/
  93. li r3, MSR_KERNEL /* Set FP, ME, RI flags */
  94. mtmsr r3
  95. mtspr SRR1, r3 /* Make SRR1 match MSR */
  96. addis r0,0,0x0000 /* lets make sure that r0 is really 0 */
  97. mtspr HID0, r0 /* disable I and D caches */
  98. mfspr r3, ICR /* clear Interrupt Cause Register */
  99. mfmsr r3 /* turn off address translation */
  100. addis r4,0,0xffff
  101. ori r4,r4,0xffcf
  102. and r3,r3,r4
  103. mtmsr r3
  104. isync
  105. sync /* the MMU should be off... */
  106. in_flash:
  107. #if defined(CONFIG_BMW)
  108. bl early_init_f /* Must be ASM: no stack yet! */
  109. #endif
  110. /*
  111. * Setup BATs - cannot be done in C since we don't have a stack yet
  112. */
  113. bl setup_bats
  114. /* Enable MMU.
  115. */
  116. mfmsr r3
  117. ori r3, r3, (MSR_IR | MSR_DR)
  118. mtmsr r3
  119. #if !defined(CONFIG_BMW)
  120. /* Enable and invalidate data cache.
  121. */
  122. mfspr r3, HID0
  123. mr r2, r3
  124. ori r3, r3, HID0_DCE | HID0_DCI
  125. ori r2, r2, HID0_DCE
  126. sync
  127. mtspr HID0, r3
  128. mtspr HID0, r2
  129. sync
  130. /* Allocate Initial RAM in data cache.
  131. */
  132. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  133. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  134. li r2, 128
  135. mtctr r2
  136. 1:
  137. dcbz r0, r3
  138. addi r3, r3, 32
  139. bdnz 1b
  140. /* Lock way0 in data cache.
  141. */
  142. mfspr r3, 1011
  143. lis r2, 0xffff
  144. ori r2, r2, 0xff1f
  145. and r3, r3, r2
  146. ori r3, r3, 0x0080
  147. sync
  148. mtspr 1011, r3
  149. #endif /* !CONFIG_BMW */
  150. /*
  151. * Thisk the stack pointer *somewhere* sensible. Doesnt
  152. * matter much where as we'll move it when we relocate
  153. */
  154. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
  155. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
  156. li r0, 0 /* Make room for stack frame header and */
  157. stwu r0, -4(r1) /* clear final stack frame so that */
  158. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  159. /* let the C-code set up the rest */
  160. /* */
  161. /* Be careful to keep code relocatable ! */
  162. /*----------------------------------------------------------------------*/
  163. GET_GOT /* initialize GOT access */
  164. #if defined(__pic__) && __pic__ == 1
  165. /* Needed for upcoming -msingle-pic-base */
  166. bl _GLOBAL_OFFSET_TABLE_@local-4
  167. mflr r30
  168. #endif
  169. /* r3: IMMR */
  170. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  171. bl board_init_f /* run 1st part of board init code (from Flash) */
  172. /* NOTREACHED - board_init_f() does not return */
  173. .globl _start_of_vectors
  174. _start_of_vectors:
  175. /* Machine check */
  176. STD_EXCEPTION(EXC_OFF_MACH_CHCK, MachineCheck, MachineCheckException)
  177. /* Data Storage exception. "Never" generated on the 860. */
  178. STD_EXCEPTION(EXC_OFF_DATA_STOR, DataStorage, UnknownException)
  179. /* Instruction Storage exception. "Never" generated on the 860. */
  180. STD_EXCEPTION(EXC_OFF_INS_STOR, InstStorage, UnknownException)
  181. /* External Interrupt exception. */
  182. STD_EXCEPTION(EXC_OFF_EXTERNAL, ExtInterrupt, external_interrupt)
  183. /* Alignment exception. */
  184. . = EXC_OFF_ALIGN
  185. Alignment:
  186. EXCEPTION_PROLOG(SRR0, SRR1)
  187. mfspr r4,DAR
  188. stw r4,_DAR(r21)
  189. mfspr r5,DSISR
  190. stw r5,_DSISR(r21)
  191. addi r3,r1,STACK_FRAME_OVERHEAD
  192. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  193. /* Program check exception */
  194. . = EXC_OFF_PROGRAM
  195. ProgramCheck:
  196. EXCEPTION_PROLOG(SRR0, SRR1)
  197. addi r3,r1,STACK_FRAME_OVERHEAD
  198. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  199. MSR_KERNEL, COPY_EE)
  200. /* No FPU on MPC8xx. This exception is not supposed to happen.
  201. */
  202. STD_EXCEPTION(EXC_OFF_FPUNAVAIL, FPUnavailable, UnknownException)
  203. /* I guess we could implement decrementer, and may have
  204. * to someday for timekeeping.
  205. */
  206. STD_EXCEPTION(EXC_OFF_DECR, Decrementer, timer_interrupt)
  207. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  208. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  209. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  210. STD_EXCEPTION(EXC_OFF_TRACE, SingleStep, UnknownException)
  211. STD_EXCEPTION(EXC_OFF_FPUNASSIST, Trap_0e, UnknownException)
  212. STD_EXCEPTION(EXC_OFF_PMI, Trap_0f, UnknownException)
  213. STD_EXCEPTION(EXC_OFF_ITME, InstructionTransMiss, UnknownException)
  214. STD_EXCEPTION(EXC_OFF_DLTME, DataLoadTransMiss, UnknownException)
  215. STD_EXCEPTION(EXC_OFF_DSTME, DataStoreTransMiss, UnknownException)
  216. STD_EXCEPTION(EXC_OFF_IABE, InstructionBreakpoint, DebugException)
  217. STD_EXCEPTION(EXC_OFF_SMIE, SysManageInt, UnknownException)
  218. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  219. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  220. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  221. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  222. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  223. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  224. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  225. STD_EXCEPTION(0x1c00, ReservedC, UnknownException)
  226. STD_EXCEPTION(0x1d00, ReservedD, UnknownException)
  227. STD_EXCEPTION(0x1e00, ReservedE, UnknownException)
  228. STD_EXCEPTION(0x1f00, ReservedF, UnknownException)
  229. STD_EXCEPTION(EXC_OFF_RMTE, RunModeTrace, UnknownException)
  230. .globl _end_of_vectors
  231. _end_of_vectors:
  232. . = 0x3000
  233. /*
  234. * This code finishes saving the registers to the exception frame
  235. * and jumps to the appropriate handler for the exception.
  236. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  237. */
  238. .globl transfer_to_handler
  239. transfer_to_handler:
  240. stw r22,_NIP(r21)
  241. lis r22,MSR_POW@h
  242. andc r23,r23,r22
  243. stw r23,_MSR(r21)
  244. SAVE_GPR(7, r21)
  245. SAVE_4GPRS(8, r21)
  246. SAVE_8GPRS(12, r21)
  247. SAVE_8GPRS(24, r21)
  248. #if 0
  249. andi. r23,r23,MSR_PR
  250. mfspr r23,SPRG3 /* if from user, fix up tss.regs */
  251. beq 2f
  252. addi r24,r1,STACK_FRAME_OVERHEAD
  253. stw r24,PT_REGS(r23)
  254. 2: addi r2,r23,-TSS /* set r2 to current */
  255. tovirt(r2,r2,r23)
  256. #endif
  257. mflr r23
  258. andi. r24,r23,0x3f00 /* get vector offset */
  259. stw r24,TRAP(r21)
  260. li r22,0
  261. stw r22,RESULT(r21)
  262. mtspr SPRG2,r22 /* r1 is now kernel sp */
  263. #if 0
  264. addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
  265. cmplw 0,r1,r2
  266. cmplw 1,r1,r24
  267. crand 1,1,4
  268. bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
  269. #endif
  270. lwz r24,0(r23) /* virtual address of handler */
  271. lwz r23,4(r23) /* where to go when done */
  272. mtspr SRR0,r24
  273. ori r20,r20,0x30 /* enable IR, DR */
  274. mtspr SRR1,r20
  275. mtlr r23
  276. SYNC
  277. rfi /* jump to handler, enable MMU */
  278. int_return:
  279. mfmsr r28 /* Disable interrupts */
  280. li r4,0
  281. ori r4,r4,MSR_EE
  282. andc r28,r28,r4
  283. SYNC /* Some chip revs need this... */
  284. mtmsr r28
  285. SYNC
  286. lwz r2,_CTR(r1)
  287. lwz r0,_LINK(r1)
  288. mtctr r2
  289. mtlr r0
  290. lwz r2,_XER(r1)
  291. lwz r0,_CCR(r1)
  292. mtspr XER,r2
  293. mtcrf 0xFF,r0
  294. REST_10GPRS(3, r1)
  295. REST_10GPRS(13, r1)
  296. REST_8GPRS(23, r1)
  297. REST_GPR(31, r1)
  298. lwz r2,_NIP(r1) /* Restore environment */
  299. lwz r0,_MSR(r1)
  300. mtspr SRR0,r2
  301. mtspr SRR1,r0
  302. lwz r0,GPR0(r1)
  303. lwz r2,GPR2(r1)
  304. lwz r1,GPR1(r1)
  305. SYNC
  306. rfi
  307. /* Cache functions.
  308. */
  309. .globl icache_enable
  310. icache_enable:
  311. mfspr r5,HID0 /* turn on the I cache. */
  312. ori r5,r5,0x8800 /* Instruction cache only! */
  313. addis r6,0,0xFFFF
  314. ori r6,r6,0xF7FF
  315. and r6,r5,r6 /* clear the invalidate bit */
  316. sync
  317. mtspr HID0,r5
  318. mtspr HID0,r6
  319. isync
  320. sync
  321. blr
  322. .globl icache_disable
  323. icache_disable:
  324. mfspr r5,HID0
  325. addis r6,0,0xFFFF
  326. ori r6,r6,0x7FFF
  327. and r5,r5,r6
  328. sync
  329. mtspr HID0,r5
  330. isync
  331. sync
  332. blr
  333. .globl icache_status
  334. icache_status:
  335. mfspr r3, HID0
  336. srwi r3, r3, 15 /* >>15 & 1=> select bit 16 */
  337. andi. r3, r3, 1
  338. blr
  339. .globl dcache_enable
  340. dcache_enable:
  341. mfspr r5,HID0 /* turn on the D cache. */
  342. ori r5,r5,0x4400 /* Data cache only! */
  343. mfspr r4, PVR /* read PVR */
  344. srawi r3, r4, 16 /* shift off the least 16 bits */
  345. cmpi 0, 0, r3, 0xC /* Check for Max pvr */
  346. bne NotMax
  347. ori r5,r5,0x0040 /* setting the DCFA bit, for Max rev 1 errata */
  348. NotMax:
  349. addis r6,0,0xFFFF
  350. ori r6,r6,0xFBFF
  351. and r6,r5,r6 /* clear the invalidate bit */
  352. sync
  353. mtspr HID0,r5
  354. mtspr HID0,r6
  355. isync
  356. sync
  357. blr
  358. .globl dcache_disable
  359. dcache_disable:
  360. mfspr r5,HID0
  361. addis r6,0,0xFFFF
  362. ori r6,r6,0xBFFF
  363. and r5,r5,r6
  364. sync
  365. mtspr HID0,r5
  366. isync
  367. sync
  368. blr
  369. .globl dcache_status
  370. dcache_status:
  371. mfspr r3, HID0
  372. srwi r3, r3, 14 /* >>14 & 1=> select bit 17 */
  373. andi. r3, r3, 1
  374. blr
  375. .globl dc_read
  376. dc_read:
  377. /*TODO : who uses this, what should it do?
  378. */
  379. blr
  380. .globl get_pvr
  381. get_pvr:
  382. mfspr r3, PVR
  383. blr
  384. /*------------------------------------------------------------------------------*/
  385. /*
  386. * void relocate_code (addr_sp, gd, addr_moni)
  387. *
  388. * This "function" does not return, instead it continues in RAM
  389. * after relocating the monitor code.
  390. *
  391. * r3 = dest
  392. * r4 = src
  393. * r5 = length in bytes
  394. * r6 = cachelinesize
  395. */
  396. .globl relocate_code
  397. relocate_code:
  398. mr r1, r3 /* Set new stack pointer */
  399. mr r9, r4 /* Save copy of Global Data pointer */
  400. mr r10, r5 /* Save copy of Destination Address */
  401. GET_GOT
  402. #if defined(__pic__) && __pic__ == 1
  403. /* Needed for upcoming -msingle-pic-base */
  404. bl _GLOBAL_OFFSET_TABLE_@local-4
  405. mflr r30
  406. #endif
  407. mr r3, r5 /* Destination Address */
  408. #ifdef CONFIG_SYS_RAMBOOT
  409. lis r4, CONFIG_SYS_SDRAM_BASE@h /* Source Address */
  410. ori r4, r4, CONFIG_SYS_SDRAM_BASE@l
  411. #else
  412. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  413. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  414. #endif
  415. lwz r5, GOT(__init_end)
  416. sub r5, r5, r4
  417. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  418. /*
  419. * Fix GOT pointer:
  420. *
  421. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  422. *
  423. * Offset:
  424. */
  425. sub r15, r10, r4
  426. /* First our own GOT */
  427. add r12, r12, r15
  428. /* the the one used by the C code */
  429. add r30, r30, r15
  430. /*
  431. * Now relocate code
  432. */
  433. cmplw cr1,r3,r4
  434. addi r0,r5,3
  435. srwi. r0,r0,2
  436. beq cr1,4f /* In place copy is not necessary */
  437. beq 7f /* Protect against 0 count */
  438. mtctr r0
  439. bge cr1,2f
  440. la r8,-4(r4)
  441. la r7,-4(r3)
  442. 1: lwzu r0,4(r8)
  443. stwu r0,4(r7)
  444. bdnz 1b
  445. b 4f
  446. 2: slwi r0,r0,2
  447. add r8,r4,r0
  448. add r7,r3,r0
  449. 3: lwzu r0,-4(r8)
  450. stwu r0,-4(r7)
  451. bdnz 3b
  452. 4:
  453. #if !defined(CONFIG_BMW)
  454. /* Unlock the data cache and invalidate locked area */
  455. xor r0, r0, r0
  456. mtspr 1011, r0
  457. lis r4, CONFIG_SYS_INIT_RAM_ADDR@h
  458. ori r4, r4, CONFIG_SYS_INIT_RAM_ADDR@l
  459. li r0, 128
  460. mtctr r0
  461. 41:
  462. dcbi r0, r4
  463. addi r4, r4, 32
  464. bdnz 41b
  465. #endif
  466. /*
  467. * Now flush the cache: note that we must start from a cache aligned
  468. * address. Otherwise we might miss one cache line.
  469. */
  470. cmpwi r6,0
  471. add r5,r3,r5
  472. beq 7f /* Always flush prefetch queue in any case */
  473. subi r0,r6,1
  474. andc r3,r3,r0
  475. mr r4,r3
  476. 5: dcbst 0,r4
  477. add r4,r4,r6
  478. cmplw r4,r5
  479. blt 5b
  480. sync /* Wait for all dcbst to complete on bus */
  481. mr r4,r3
  482. 6: icbi 0,r4
  483. add r4,r4,r6
  484. cmplw r4,r5
  485. blt 6b
  486. 7: sync /* Wait for all icbi to complete on bus */
  487. isync
  488. /*
  489. * We are done. Do not return, instead branch to second part of board
  490. * initialization, now running from RAM.
  491. */
  492. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  493. mtlr r0
  494. blr
  495. in_ram:
  496. /*
  497. * Relocation Function, r12 point to got2+0x8000
  498. *
  499. * Adjust got2 pointers, no need to check for 0, this code
  500. * already puts a few entries in the table.
  501. */
  502. li r0,__got2_entries@sectoff@l
  503. la r3,GOT(_GOT2_TABLE_)
  504. lwz r11,GOT(_GOT2_TABLE_)
  505. mtctr r0
  506. sub r11,r3,r11
  507. addi r3,r3,-4
  508. 1: lwzu r0,4(r3)
  509. cmpwi r0,0
  510. beq- 2f
  511. add r0,r0,r11
  512. stw r0,0(r3)
  513. 2: bdnz 1b
  514. /*
  515. * Now adjust the fixups and the pointers to the fixups
  516. * in case we need to move ourselves again.
  517. */
  518. li r0,__fixup_entries@sectoff@l
  519. lwz r3,GOT(_FIXUP_TABLE_)
  520. cmpwi r0,0
  521. mtctr r0
  522. addi r3,r3,-4
  523. beq 4f
  524. 3: lwzu r4,4(r3)
  525. lwzux r0,r4,r11
  526. cmpwi r0,0
  527. add r0,r0,r11
  528. stw r4,0(r3)
  529. beq- 5f
  530. stw r0,0(r4)
  531. 5: bdnz 3b
  532. 4:
  533. clear_bss:
  534. /*
  535. * Now clear BSS segment
  536. */
  537. lwz r3,GOT(__bss_start)
  538. lwz r4,GOT(__bss_end__)
  539. cmplw 0, r3, r4
  540. beq 6f
  541. li r0, 0
  542. 5:
  543. stw r0, 0(r3)
  544. addi r3, r3, 4
  545. cmplw 0, r3, r4
  546. blt 5b
  547. 6:
  548. mr r3, r9 /* Global Data pointer */
  549. mr r4, r10 /* Destination Address */
  550. bl board_init_r
  551. /*
  552. * Copy exception vector code to low memory
  553. *
  554. * r3: dest_addr
  555. * r7: source address, r8: end address, r9: target address
  556. */
  557. .globl trap_init
  558. trap_init:
  559. mflr r4 /* save link register */
  560. GET_GOT
  561. lwz r7, GOT(_start)
  562. lwz r8, GOT(_end_of_vectors)
  563. li r9, 0x100 /* reset vector always at 0x100 */
  564. cmplw 0, r7, r8
  565. bgelr /* return if r7>=r8 - just in case */
  566. 1:
  567. lwz r0, 0(r7)
  568. stw r0, 0(r9)
  569. addi r7, r7, 4
  570. addi r9, r9, 4
  571. cmplw 0, r7, r8
  572. bne 1b
  573. /*
  574. * relocate `hdlr' and `int_return' entries
  575. */
  576. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  577. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  578. 2:
  579. bl trap_reloc
  580. addi r7, r7, 0x100 /* next exception vector */
  581. cmplw 0, r7, r8
  582. blt 2b
  583. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  584. bl trap_reloc
  585. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  586. bl trap_reloc
  587. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  588. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  589. 3:
  590. bl trap_reloc
  591. addi r7, r7, 0x100 /* next exception vector */
  592. cmplw 0, r7, r8
  593. blt 3b
  594. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  595. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  596. 4:
  597. bl trap_reloc
  598. addi r7, r7, 0x100 /* next exception vector */
  599. cmplw 0, r7, r8
  600. blt 4b
  601. mtlr r4 /* restore link register */
  602. blr
  603. /* Setup the BAT registers.
  604. */
  605. setup_bats:
  606. lis r4, CONFIG_SYS_IBAT0L@h
  607. ori r4, r4, CONFIG_SYS_IBAT0L@l
  608. lis r3, CONFIG_SYS_IBAT0U@h
  609. ori r3, r3, CONFIG_SYS_IBAT0U@l
  610. mtspr IBAT0L, r4
  611. mtspr IBAT0U, r3
  612. isync
  613. lis r4, CONFIG_SYS_DBAT0L@h
  614. ori r4, r4, CONFIG_SYS_DBAT0L@l
  615. lis r3, CONFIG_SYS_DBAT0U@h
  616. ori r3, r3, CONFIG_SYS_DBAT0U@l
  617. mtspr DBAT0L, r4
  618. mtspr DBAT0U, r3
  619. isync
  620. lis r4, CONFIG_SYS_IBAT1L@h
  621. ori r4, r4, CONFIG_SYS_IBAT1L@l
  622. lis r3, CONFIG_SYS_IBAT1U@h
  623. ori r3, r3, CONFIG_SYS_IBAT1U@l
  624. mtspr IBAT1L, r4
  625. mtspr IBAT1U, r3
  626. isync
  627. lis r4, CONFIG_SYS_DBAT1L@h
  628. ori r4, r4, CONFIG_SYS_DBAT1L@l
  629. lis r3, CONFIG_SYS_DBAT1U@h
  630. ori r3, r3, CONFIG_SYS_DBAT1U@l
  631. mtspr DBAT1L, r4
  632. mtspr DBAT1U, r3
  633. isync
  634. lis r4, CONFIG_SYS_IBAT2L@h
  635. ori r4, r4, CONFIG_SYS_IBAT2L@l
  636. lis r3, CONFIG_SYS_IBAT2U@h
  637. ori r3, r3, CONFIG_SYS_IBAT2U@l
  638. mtspr IBAT2L, r4
  639. mtspr IBAT2U, r3
  640. isync
  641. lis r4, CONFIG_SYS_DBAT2L@h
  642. ori r4, r4, CONFIG_SYS_DBAT2L@l
  643. lis r3, CONFIG_SYS_DBAT2U@h
  644. ori r3, r3, CONFIG_SYS_DBAT2U@l
  645. mtspr DBAT2L, r4
  646. mtspr DBAT2U, r3
  647. isync
  648. lis r4, CONFIG_SYS_IBAT3L@h
  649. ori r4, r4, CONFIG_SYS_IBAT3L@l
  650. lis r3, CONFIG_SYS_IBAT3U@h
  651. ori r3, r3, CONFIG_SYS_IBAT3U@l
  652. mtspr IBAT3L, r4
  653. mtspr IBAT3U, r3
  654. isync
  655. lis r4, CONFIG_SYS_DBAT3L@h
  656. ori r4, r4, CONFIG_SYS_DBAT3L@l
  657. lis r3, CONFIG_SYS_DBAT3U@h
  658. ori r3, r3, CONFIG_SYS_DBAT3U@l
  659. mtspr DBAT3L, r4
  660. mtspr DBAT3U, r3
  661. isync
  662. /* Invalidate TLBs.
  663. * -> for (val = 0; val < 0x20000; val+=0x1000)
  664. * -> tlbie(val);
  665. */
  666. lis r3, 0
  667. lis r5, 2
  668. 1:
  669. tlbie r3
  670. addi r3, r3, 0x1000
  671. cmp 0, 0, r3, r5
  672. blt 1b
  673. blr