start.S 17 KB

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