start.S 18 KB

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