start.S 17 KB

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