start.S 17 KB

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