start.S 16 KB

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