start.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Copyright (C) 2003 Motorola,Inc.
  4. * Xianghua Xiao<X.Xiao@motorola.com>
  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 Motorola 85xx PowerPC based Embedded Boards
  25. *
  26. * The processor starts at 0xfffffffc and the code is first executed in the
  27. * last 4K page(0xfffff000-0xffffffff) in flash/rom.
  28. *
  29. */
  30. #include <config.h>
  31. #include <mpc85xx.h>
  32. #include <version.h>
  33. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  34. #include <ppc_asm.tmpl>
  35. #include <ppc_defs.h>
  36. #include <asm/cache.h>
  37. #include <asm/mmu.h>
  38. #ifndef CONFIG_IDENT_STRING
  39. #define CONFIG_IDENT_STRING ""
  40. #endif
  41. #undef MSR_KERNEL
  42. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  43. /*
  44. * Set up GOT: Global Offset Table
  45. *
  46. * Use r14 to access the GOT
  47. */
  48. START_GOT
  49. GOT_ENTRY(_GOT2_TABLE_)
  50. GOT_ENTRY(_FIXUP_TABLE_)
  51. GOT_ENTRY(_start)
  52. GOT_ENTRY(_start_of_vectors)
  53. GOT_ENTRY(_end_of_vectors)
  54. GOT_ENTRY(transfer_to_handler)
  55. GOT_ENTRY(__init_end)
  56. GOT_ENTRY(_end)
  57. GOT_ENTRY(__bss_start)
  58. END_GOT
  59. /*
  60. * e500 Startup -- after reset only the last 4KB of the effective
  61. * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
  62. * section is located at THIS LAST page and basically does three
  63. * things: clear some registers, set up exception tables and
  64. * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
  65. * continue the boot procedure.
  66. * Once the boot rom is mapped by TLB entries we can proceed
  67. * with normal startup.
  68. *
  69. */
  70. .section .bootpg,"ax"
  71. .globl _start_e500
  72. _start_e500:
  73. mfspr r0, PVR
  74. lis r1, PVR_85xx_REV1@h
  75. ori r1, r1, PVR_85xx_REV1@l
  76. cmpw r0, r1
  77. bne 1f
  78. /* Semi-bogus errata fixup for Rev 1 */
  79. li r0,0x2000
  80. mtspr 977,r0
  81. /*
  82. * Before invalidating MMU L1/L2, read TLB1 Entry 0 and then
  83. * write it back immediately to fixup a Rev 1 bug (Errata CPU4)
  84. * for this initial TLB1 entry 0, otherwise the TLB1 entry 0
  85. * will be invalidated (incorrectly).
  86. */
  87. lis r2,0x1000
  88. mtspr MAS0,r2
  89. tlbre
  90. tlbwe
  91. isync
  92. 1:
  93. /*
  94. * Clear and set up some registers.
  95. * Note: Some registers need strict synchronization by
  96. * sync/mbar/msync/isync when being "mtspr".
  97. * BookE: isync before PID,tlbivax,tlbwe
  98. * BookE: isync after MSR,PID; msync_isync after tlbivax & tlbwe
  99. * E500: msync,isync before L1CSR0
  100. * E500: isync after BBEAR,BBTAR,BUCSR,DBCR0,DBCR1,HID0,HID1,
  101. * L1CSR0, L1CSR1, MAS[0,1,2,3,4,6],MMUCSR0, PID[0,1,2],
  102. * SPEFCSR
  103. */
  104. /* invalidate d-cache */
  105. mfspr r0,L1CSR0
  106. ori r0,r0,0x0002
  107. msync
  108. isync
  109. mtspr L1CSR0,r0
  110. isync
  111. /* disable d-cache */
  112. li r0,0x0
  113. mtspr L1CSR0,r0
  114. /* invalidate i-cache */
  115. mfspr r0,L1CSR1
  116. ori r0,r0,0x0002
  117. mtspr L1CSR1,r0
  118. isync
  119. /* disable i-cache */
  120. li r0,0x0
  121. mtspr L1CSR1,r0
  122. isync
  123. /* clear registers */
  124. li r0,0
  125. mtspr SRR0,r0
  126. mtspr SRR1,r0
  127. mtspr CSRR0,r0
  128. mtspr CSRR1,r0
  129. mtspr MCSRR0,r0
  130. mtspr MCSRR1,r0
  131. mtspr ESR,r0
  132. mtspr MCSR,r0
  133. mtspr DEAR,r0
  134. /* not needed and conflicts with some debuggers */
  135. /* mtspr DBCR0,r0 */
  136. mtspr DBCR1,r0
  137. mtspr DBCR2,r0
  138. /* not needed and conflicts with some debuggers */
  139. /* mtspr IAC1,r0 */
  140. /* mtspr IAC2,r0 */
  141. mtspr DAC1,r0
  142. mtspr DAC2,r0
  143. mfspr r1,DBSR
  144. mtspr DBSR,r1 /* Clear all valid bits */
  145. mtspr PID0,r0
  146. mtspr PID1,r0
  147. mtspr PID2,r0
  148. mtspr TCR,r0
  149. mtspr BUCSR,r0 /* disable branch prediction */
  150. mtspr MAS4,r0
  151. mtspr MAS6,r0
  152. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  153. mtspr MAS7,r0
  154. #endif
  155. isync
  156. /* Setup interrupt vectors */
  157. lis r1,TEXT_BASE@h
  158. mtspr IVPR, r1
  159. li r1,0x0100
  160. mtspr IVOR0,r1 /* 0: Critical input */
  161. li r1,0x0200
  162. mtspr IVOR1,r1 /* 1: Machine check */
  163. li r1,0x0300
  164. mtspr IVOR2,r1 /* 2: Data storage */
  165. li r1,0x0400
  166. mtspr IVOR3,r1 /* 3: Instruction storage */
  167. li r1,0x0500
  168. mtspr IVOR4,r1 /* 4: External interrupt */
  169. li r1,0x0600
  170. mtspr IVOR5,r1 /* 5: Alignment */
  171. li r1,0x0700
  172. mtspr IVOR6,r1 /* 6: Program check */
  173. li r1,0x0800
  174. mtspr IVOR7,r1 /* 7: floating point unavailable */
  175. li r1,0x0900
  176. mtspr IVOR8,r1 /* 8: System call */
  177. /* 9: Auxiliary processor unavailable(unsupported) */
  178. li r1,0x0a00
  179. mtspr IVOR10,r1 /* 10: Decrementer */
  180. li r1,0x0b00
  181. mtspr IVOR11,r1 /* 11: Interval timer */
  182. li r1,0x0c00
  183. mtspr IVOR12,r1 /* 12: Watchdog timer */
  184. li r1,0x0d00
  185. mtspr IVOR13,r1 /* 13: Data TLB error */
  186. li r1,0x0e00
  187. mtspr IVOR14,r1 /* 14: Instruction TLB error */
  188. li r1,0x0f00
  189. mtspr IVOR15,r1 /* 15: Debug */
  190. /*
  191. * Invalidate MMU L1/L2
  192. *
  193. * Note: There is a fixup earlier for Errata CPU4 on
  194. * Rev 1 parts that must precede this MMU invalidation.
  195. */
  196. li r2, 0x001e
  197. mtspr MMUCSR0, r2
  198. isync
  199. /*
  200. * Invalidate all TLB0 entries.
  201. */
  202. li r3,4
  203. li r4,0
  204. tlbivax r4,r3
  205. /*
  206. * To avoid REV1 Errata CPU6 issues, make sure
  207. * the instruction following tlbivax is not a store.
  208. */
  209. /*
  210. * After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e.
  211. * 0xff700000-0xff800000. We need add a TLB1 entry for this 1MB
  212. * region before we can access any CCSR registers such as L2
  213. * registers, Local Access Registers,etc. We will also re-allocate
  214. * CFG_CCSRBAR_DEFAULT to CFG_CCSRBAR immediately after TLB1 setup.
  215. *
  216. * Please refer to board-specif directory for TLB1 entry configuration.
  217. * (e.g. board/<yourboard>/init.S)
  218. *
  219. */
  220. bl tlb1_entry
  221. mr r5,r0
  222. lwzu r4,0(r5) /* how many TLB1 entries we actually use */
  223. mtctr r4
  224. 0: lwzu r0,4(r5)
  225. lwzu r1,4(r5)
  226. lwzu r2,4(r5)
  227. lwzu r3,4(r5)
  228. mtspr MAS0,r0
  229. mtspr MAS1,r1
  230. mtspr MAS2,r2
  231. mtspr MAS3,r3
  232. isync
  233. msync
  234. tlbwe
  235. isync
  236. bdnz 0b
  237. 1:
  238. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  239. /* Special sequence needed to update CCSRBAR itself */
  240. lis r4, CFG_CCSRBAR_DEFAULT@h
  241. ori r4, r4, CFG_CCSRBAR_DEFAULT@l
  242. lis r5, CFG_CCSRBAR@h
  243. ori r5, r5, CFG_CCSRBAR@l
  244. srwi r6,r5,12
  245. stw r6, 0(r4)
  246. isync
  247. lis r5, 0xffff
  248. ori r5,r5,0xf000
  249. lwz r5, 0(r5)
  250. isync
  251. lis r3, CFG_CCSRBAR@h
  252. lwz r5, CFG_CCSRBAR@l(r3)
  253. isync
  254. #endif
  255. /* set up local access windows, defined at board/<boardname>/init.S */
  256. lis r7,CFG_CCSRBAR@h
  257. ori r7,r7,CFG_CCSRBAR@l
  258. bl law_entry
  259. mr r6,r0
  260. lwzu r5,0(r6) /* how many windows we actually use */
  261. mtctr r5
  262. li r2,0x0c28 /* the first pair is reserved for boot-over-rio-or-pci */
  263. li r1,0x0c30
  264. 0: lwzu r4,4(r6)
  265. lwzu r3,4(r6)
  266. stwx r4,r7,r2
  267. stwx r3,r7,r1
  268. addi r2,r2,0x0020
  269. addi r1,r1,0x0020
  270. bdnz 0b
  271. /* Jump out the last 4K page and continue to 'normal' start */
  272. 1: bl 3f
  273. b _start
  274. 3: li r0,0
  275. mtspr SRR1,r0 /* Keep things disabled for now */
  276. mflr r1
  277. mtspr SRR0,r1
  278. rfi
  279. /*
  280. * r3 - 1st arg to board_init(): IMMP pointer
  281. * r4 - 2nd arg to board_init(): boot flag
  282. */
  283. .text
  284. .long 0x27051956 /* U-BOOT Magic Number */
  285. .globl version_string
  286. version_string:
  287. .ascii U_BOOT_VERSION
  288. .ascii " (", __DATE__, " - ", __TIME__, ")"
  289. .ascii CONFIG_IDENT_STRING, "\0"
  290. . = EXC_OFF_SYS_RESET
  291. .globl _start
  292. _start:
  293. /* Clear and set up some registers. */
  294. li r0,0x0000
  295. lis r1,0xffff
  296. mtspr DEC,r0 /* prevent dec exceptions */
  297. mttbl r0 /* prevent fit & wdt exceptions */
  298. mttbu r0
  299. mtspr TSR,r1 /* clear all timer exception status */
  300. mtspr TCR,r0 /* disable all */
  301. mtspr ESR,r0 /* clear exception syndrome register */
  302. mtspr MCSR,r0 /* machine check syndrome register */
  303. mtxer r0 /* clear integer exception register */
  304. lis r1,0x0002 /* set CE bit (Critical Exceptions) */
  305. ori r1,r1,0x1200 /* set ME/DE bit */
  306. mtmsr r1 /* change MSR */
  307. isync
  308. /* Enable Time Base and Select Time Base Clock */
  309. lis r0,HID0_EMCP@h /* Enable machine check */
  310. ori r0,r0,0x4000 /* time base is processor clock */
  311. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  312. ori r0,r0,0x0080 /* enable MAS7 updates */
  313. #endif
  314. mtspr HID0,r0
  315. #if defined(CONFIG_ADDR_STREAMING)
  316. li r0,0x3000
  317. #else
  318. li r0,0x1000
  319. #endif
  320. mtspr HID1,r0
  321. /* Enable Branch Prediction */
  322. #if defined(CONFIG_BTB)
  323. li r0,0x201 /* BBFI = 1, BPEN = 1 */
  324. mtspr BUCSR,r0
  325. #endif
  326. #if defined(CFG_INIT_DBCR)
  327. lis r1,0xffff
  328. ori r1,r1,0xffff
  329. mtspr DBSR,r1 /* Clear all status bits */
  330. lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
  331. ori r0,r0,CFG_INIT_DBCR@l
  332. mtspr DBCR0,r0
  333. #endif
  334. /* L1 DCache is used for initial RAM */
  335. mfspr r2, L1CSR0
  336. ori r2, r2, 0x0003
  337. oris r2, r2, 0x0001
  338. mtspr L1CSR0, r2 /* enable/invalidate L1 Dcache */
  339. isync
  340. /* Allocate Initial RAM in data cache.
  341. */
  342. lis r3, CFG_INIT_RAM_ADDR@h
  343. ori r3, r3, CFG_INIT_RAM_ADDR@l
  344. li r2, 512 /* 512*32=16K */
  345. mtctr r2
  346. li r0, 0
  347. 1:
  348. dcbz r0, r3
  349. dcbtls 0,r0, r3
  350. addi r3, r3, 32
  351. bdnz 1b
  352. #ifndef CFG_RAMBOOT
  353. /* Calculate absolute address in FLASH and jump there */
  354. /*--------------------------------------------------------------*/
  355. lis r3, CFG_MONITOR_BASE@h
  356. ori r3, r3, CFG_MONITOR_BASE@l
  357. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  358. mtlr r3
  359. blr
  360. in_flash:
  361. #endif /* CFG_RAMBOOT */
  362. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  363. lis r1,CFG_INIT_RAM_ADDR@h
  364. ori r1,r1,CFG_INIT_SP_OFFSET@l
  365. li r0,0
  366. stwu r0,-4(r1)
  367. stwu r0,-4(r1) /* Terminate call chain */
  368. stwu r1,-8(r1) /* Save back chain and move SP */
  369. lis r0,RESET_VECTOR@h /* Address of reset vector */
  370. ori r0,r0, RESET_VECTOR@l
  371. stwu r1,-8(r1) /* Save back chain and move SP */
  372. stw r0,+12(r1) /* Save return addr (underflow vect) */
  373. GET_GOT
  374. bl cpu_init_f
  375. bl icache_enable
  376. bl board_init_f
  377. isync
  378. /* --FIXME-- machine check with MCSRRn and rfmci */
  379. .globl _start_of_vectors
  380. _start_of_vectors:
  381. #if 0
  382. /* Critical input. */
  383. CRIT_EXCEPTION(0x0100, CritcalInput, CritcalInputException)
  384. #endif
  385. /* Machine check --FIXME-- Should be MACH_EXCEPTION */
  386. CRIT_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
  387. /* Data Storage exception. */
  388. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  389. /* Instruction Storage exception. */
  390. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  391. /* External Interrupt exception. */
  392. STD_EXCEPTION(0x0500, ExtInterrupt, UnknownException)
  393. /* Alignment exception. */
  394. . = 0x0600
  395. Alignment:
  396. EXCEPTION_PROLOG
  397. mfspr r4,DAR
  398. stw r4,_DAR(r21)
  399. mfspr r5,DSISR
  400. stw r5,_DSISR(r21)
  401. addi r3,r1,STACK_FRAME_OVERHEAD
  402. li r20,MSR_KERNEL
  403. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  404. lwz r6,GOT(transfer_to_handler)
  405. mtlr r6
  406. blrl
  407. .L_Alignment:
  408. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  409. .long int_return - _start + EXC_OFF_SYS_RESET
  410. /* Program check exception */
  411. . = 0x0700
  412. ProgramCheck:
  413. EXCEPTION_PROLOG
  414. addi r3,r1,STACK_FRAME_OVERHEAD
  415. li r20,MSR_KERNEL
  416. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  417. lwz r6,GOT(transfer_to_handler)
  418. mtlr r6
  419. blrl
  420. .L_ProgramCheck:
  421. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  422. .long int_return - _start + EXC_OFF_SYS_RESET
  423. /* No FPU on MPC85xx. This exception is not supposed to happen.
  424. */
  425. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  426. . = 0x0900
  427. /*
  428. * r0 - SYSCALL number
  429. * r3-... arguments
  430. */
  431. SystemCall:
  432. addis r11,r0,0 /* get functions table addr */
  433. ori r11,r11,0 /* Note: this code is patched in trap_init */
  434. addis r12,r0,0 /* get number of functions */
  435. ori r12,r12,0
  436. cmplw 0, r0, r12
  437. bge 1f
  438. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  439. add r11,r11,r0
  440. lwz r11,0(r11)
  441. li r20,0xd00-4 /* Get stack pointer */
  442. lwz r12,0(r20)
  443. subi r12,r12,12 /* Adjust stack pointer */
  444. li r0,0xc00+_end_back-SystemCall
  445. cmplw 0, r0, r12 /* Check stack overflow */
  446. bgt 1f
  447. stw r12,0(r20)
  448. mflr r0
  449. stw r0,0(r12)
  450. mfspr r0,SRR0
  451. stw r0,4(r12)
  452. mfspr r0,SRR1
  453. stw r0,8(r12)
  454. li r12,0xc00+_back-SystemCall
  455. mtlr r12
  456. mtspr SRR0,r11
  457. 1: SYNC
  458. rfi
  459. _back:
  460. mfmsr r11 /* Disable interrupts */
  461. li r12,0
  462. ori r12,r12,MSR_EE
  463. andc r11,r11,r12
  464. SYNC /* Some chip revs need this... */
  465. mtmsr r11
  466. SYNC
  467. li r12,0xd00-4 /* restore regs */
  468. lwz r12,0(r12)
  469. lwz r11,0(r12)
  470. mtlr r11
  471. lwz r11,4(r12)
  472. mtspr SRR0,r11
  473. lwz r11,8(r12)
  474. mtspr SRR1,r11
  475. addi r12,r12,12 /* Adjust stack pointer */
  476. li r20,0xd00-4
  477. stw r12,0(r20)
  478. SYNC
  479. rfi
  480. _end_back:
  481. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  482. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  483. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  484. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  485. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  486. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  487. .globl _end_of_vectors
  488. _end_of_vectors:
  489. . = 0x2100
  490. /*
  491. * This code finishes saving the registers to the exception frame
  492. * and jumps to the appropriate handler for the exception.
  493. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  494. */
  495. .globl transfer_to_handler
  496. transfer_to_handler:
  497. stw r22,_NIP(r21)
  498. lis r22,MSR_POW@h
  499. andc r23,r23,r22
  500. stw r23,_MSR(r21)
  501. SAVE_GPR(7, r21)
  502. SAVE_4GPRS(8, r21)
  503. SAVE_8GPRS(12, r21)
  504. SAVE_8GPRS(24, r21)
  505. mflr r23
  506. andi. r24,r23,0x3f00 /* get vector offset */
  507. stw r24,TRAP(r21)
  508. li r22,0
  509. stw r22,RESULT(r21)
  510. mtspr SPRG2,r22 /* r1 is now kernel sp */
  511. lwz r24,0(r23) /* virtual address of handler */
  512. lwz r23,4(r23) /* where to go when done */
  513. mtspr SRR0,r24
  514. mtspr SRR1,r20
  515. mtlr r23
  516. SYNC
  517. rfi /* jump to handler, enable MMU */
  518. int_return:
  519. mfmsr r28 /* Disable interrupts */
  520. li r4,0
  521. ori r4,r4,MSR_EE
  522. andc r28,r28,r4
  523. SYNC /* Some chip revs need this... */
  524. mtmsr r28
  525. SYNC
  526. lwz r2,_CTR(r1)
  527. lwz r0,_LINK(r1)
  528. mtctr r2
  529. mtlr r0
  530. lwz r2,_XER(r1)
  531. lwz r0,_CCR(r1)
  532. mtspr XER,r2
  533. mtcrf 0xFF,r0
  534. REST_10GPRS(3, r1)
  535. REST_10GPRS(13, r1)
  536. REST_8GPRS(23, r1)
  537. REST_GPR(31, r1)
  538. lwz r2,_NIP(r1) /* Restore environment */
  539. lwz r0,_MSR(r1)
  540. mtspr SRR0,r2
  541. mtspr SRR1,r0
  542. lwz r0,GPR0(r1)
  543. lwz r2,GPR2(r1)
  544. lwz r1,GPR1(r1)
  545. SYNC
  546. rfi
  547. crit_return:
  548. mfmsr r28 /* Disable interrupts */
  549. li r4,0
  550. ori r4,r4,MSR_EE
  551. andc r28,r28,r4
  552. SYNC /* Some chip revs need this... */
  553. mtmsr r28
  554. SYNC
  555. lwz r2,_CTR(r1)
  556. lwz r0,_LINK(r1)
  557. mtctr r2
  558. mtlr r0
  559. lwz r2,_XER(r1)
  560. lwz r0,_CCR(r1)
  561. mtspr XER,r2
  562. mtcrf 0xFF,r0
  563. REST_10GPRS(3, r1)
  564. REST_10GPRS(13, r1)
  565. REST_8GPRS(23, r1)
  566. REST_GPR(31, r1)
  567. lwz r2,_NIP(r1) /* Restore environment */
  568. lwz r0,_MSR(r1)
  569. mtspr 990,r2 /* SRR2 */
  570. mtspr 991,r0 /* SRR3 */
  571. lwz r0,GPR0(r1)
  572. lwz r2,GPR2(r1)
  573. lwz r1,GPR1(r1)
  574. SYNC
  575. rfci
  576. /* Cache functions.
  577. */
  578. invalidate_icache:
  579. mfspr r0,L1CSR1
  580. ori r0,r0,0x0002
  581. mtspr L1CSR1,r0
  582. isync
  583. blr /* entire I cache */
  584. invalidate_dcache:
  585. mfspr r0,L1CSR0
  586. ori r0,r0,0x0002
  587. msync
  588. isync
  589. mtspr L1CSR0,r0
  590. isync
  591. blr
  592. .globl icache_enable
  593. icache_enable:
  594. mflr r8
  595. bl invalidate_icache
  596. mtlr r8
  597. isync
  598. mfspr r4,L1CSR1
  599. ori r4,r4,0x0001
  600. oris r4,r4,0x0001
  601. mtspr L1CSR1,r4
  602. isync
  603. blr
  604. .globl icache_disable
  605. icache_disable:
  606. mfspr r0,L1CSR1
  607. lis r1,0xfffffffe@h
  608. ori r1,r1,0xfffffffe@l
  609. and r0,r0,r1
  610. mtspr L1CSR1,r0
  611. isync
  612. blr
  613. .globl icache_status
  614. icache_status:
  615. mfspr r3,L1CSR1
  616. andi. r3,r3,1
  617. blr
  618. .globl dcache_enable
  619. dcache_enable:
  620. mflr r8
  621. bl invalidate_dcache
  622. mtlr r8
  623. isync
  624. mfspr r0,L1CSR0
  625. ori r0,r0,0x0001
  626. oris r0,r0,0x0001
  627. msync
  628. isync
  629. mtspr L1CSR0,r0
  630. isync
  631. blr
  632. .globl dcache_disable
  633. dcache_disable:
  634. mfspr r0,L1CSR0
  635. lis r1,0xfffffffe@h
  636. ori r1,r1,0xfffffffe@l
  637. and r0,r0,r1
  638. msync
  639. isync
  640. mtspr L1CSR0,r0
  641. isync
  642. blr
  643. .globl dcache_status
  644. dcache_status:
  645. mfspr r3,L1CSR0
  646. andi. r3,r3,1
  647. blr
  648. .globl get_pir
  649. get_pir:
  650. mfspr r3, PIR
  651. blr
  652. .globl get_pvr
  653. get_pvr:
  654. mfspr r3, PVR
  655. blr
  656. .globl get_svr
  657. get_svr:
  658. mfspr r3, SVR
  659. blr
  660. .globl wr_tcr
  661. wr_tcr:
  662. mtspr TCR, r3
  663. blr
  664. /*------------------------------------------------------------------------------- */
  665. /* Function: in8 */
  666. /* Description: Input 8 bits */
  667. /*------------------------------------------------------------------------------- */
  668. .globl in8
  669. in8:
  670. lbz r3,0x0000(r3)
  671. blr
  672. /*------------------------------------------------------------------------------- */
  673. /* Function: out8 */
  674. /* Description: Output 8 bits */
  675. /*------------------------------------------------------------------------------- */
  676. .globl out8
  677. out8:
  678. stb r4,0x0000(r3)
  679. blr
  680. /*------------------------------------------------------------------------------- */
  681. /* Function: out16 */
  682. /* Description: Output 16 bits */
  683. /*------------------------------------------------------------------------------- */
  684. .globl out16
  685. out16:
  686. sth r4,0x0000(r3)
  687. blr
  688. /*------------------------------------------------------------------------------- */
  689. /* Function: out16r */
  690. /* Description: Byte reverse and output 16 bits */
  691. /*------------------------------------------------------------------------------- */
  692. .globl out16r
  693. out16r:
  694. sthbrx r4,r0,r3
  695. blr
  696. /*------------------------------------------------------------------------------- */
  697. /* Function: out32 */
  698. /* Description: Output 32 bits */
  699. /*------------------------------------------------------------------------------- */
  700. .globl out32
  701. out32:
  702. stw r4,0x0000(r3)
  703. blr
  704. /*------------------------------------------------------------------------------- */
  705. /* Function: out32r */
  706. /* Description: Byte reverse and output 32 bits */
  707. /*------------------------------------------------------------------------------- */
  708. .globl out32r
  709. out32r:
  710. stwbrx r4,r0,r3
  711. blr
  712. /*------------------------------------------------------------------------------- */
  713. /* Function: in16 */
  714. /* Description: Input 16 bits */
  715. /*------------------------------------------------------------------------------- */
  716. .globl in16
  717. in16:
  718. lhz r3,0x0000(r3)
  719. blr
  720. /*------------------------------------------------------------------------------- */
  721. /* Function: in16r */
  722. /* Description: Input 16 bits and byte reverse */
  723. /*------------------------------------------------------------------------------- */
  724. .globl in16r
  725. in16r:
  726. lhbrx r3,r0,r3
  727. blr
  728. /*------------------------------------------------------------------------------- */
  729. /* Function: in32 */
  730. /* Description: Input 32 bits */
  731. /*------------------------------------------------------------------------------- */
  732. .globl in32
  733. in32:
  734. lwz 3,0x0000(3)
  735. blr
  736. /*------------------------------------------------------------------------------- */
  737. /* Function: in32r */
  738. /* Description: Input 32 bits and byte reverse */
  739. /*------------------------------------------------------------------------------- */
  740. .globl in32r
  741. in32r:
  742. lwbrx r3,r0,r3
  743. blr
  744. /*------------------------------------------------------------------------------- */
  745. /* Function: ppcDcbf */
  746. /* Description: Data Cache block flush */
  747. /* Input: r3 = effective address */
  748. /* Output: none. */
  749. /*------------------------------------------------------------------------------- */
  750. .globl ppcDcbf
  751. ppcDcbf:
  752. dcbf r0,r3
  753. blr
  754. /*------------------------------------------------------------------------------- */
  755. /* Function: ppcDcbi */
  756. /* Description: Data Cache block Invalidate */
  757. /* Input: r3 = effective address */
  758. /* Output: none. */
  759. /*------------------------------------------------------------------------------- */
  760. .globl ppcDcbi
  761. ppcDcbi:
  762. dcbi r0,r3
  763. blr
  764. /*--------------------------------------------------------------------------
  765. * Function: ppcDcbz
  766. * Description: Data Cache block zero.
  767. * Input: r3 = effective address
  768. * Output: none.
  769. *-------------------------------------------------------------------------- */
  770. .globl ppcDcbz
  771. ppcDcbz:
  772. dcbz r0,r3
  773. blr
  774. /*------------------------------------------------------------------------------- */
  775. /* Function: ppcSync */
  776. /* Description: Processor Synchronize */
  777. /* Input: none. */
  778. /* Output: none. */
  779. /*------------------------------------------------------------------------------- */
  780. .globl ppcSync
  781. ppcSync:
  782. sync
  783. blr
  784. /*------------------------------------------------------------------------------*/
  785. /*
  786. * void relocate_code (addr_sp, gd, addr_moni)
  787. *
  788. * This "function" does not return, instead it continues in RAM
  789. * after relocating the monitor code.
  790. *
  791. * r3 = dest
  792. * r4 = src
  793. * r5 = length in bytes
  794. * r6 = cachelinesize
  795. */
  796. .globl relocate_code
  797. relocate_code:
  798. mr r1, r3 /* Set new stack pointer */
  799. mr r9, r4 /* Save copy of Init Data pointer */
  800. mr r10, r5 /* Save copy of Destination Address */
  801. mr r3, r5 /* Destination Address */
  802. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  803. ori r4, r4, CFG_MONITOR_BASE@l
  804. lwz r5,GOT(__init_end)
  805. sub r5,r5,r4
  806. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  807. /*
  808. * Fix GOT pointer:
  809. *
  810. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  811. *
  812. * Offset:
  813. */
  814. sub r15, r10, r4
  815. /* First our own GOT */
  816. add r14, r14, r15
  817. /* the the one used by the C code */
  818. add r30, r30, r15
  819. /*
  820. * Now relocate code
  821. */
  822. cmplw cr1,r3,r4
  823. addi r0,r5,3
  824. srwi. r0,r0,2
  825. beq cr1,4f /* In place copy is not necessary */
  826. beq 7f /* Protect against 0 count */
  827. mtctr r0
  828. bge cr1,2f
  829. la r8,-4(r4)
  830. la r7,-4(r3)
  831. 1: lwzu r0,4(r8)
  832. stwu r0,4(r7)
  833. bdnz 1b
  834. b 4f
  835. 2: slwi r0,r0,2
  836. add r8,r4,r0
  837. add r7,r3,r0
  838. 3: lwzu r0,-4(r8)
  839. stwu r0,-4(r7)
  840. bdnz 3b
  841. /*
  842. * Now flush the cache: note that we must start from a cache aligned
  843. * address. Otherwise we might miss one cache line.
  844. */
  845. 4: cmpwi r6,0
  846. add r5,r3,r5
  847. beq 7f /* Always flush prefetch queue in any case */
  848. subi r0,r6,1
  849. andc r3,r3,r0
  850. mr r4,r3
  851. 5: dcbst 0,r4
  852. add r4,r4,r6
  853. cmplw r4,r5
  854. blt 5b
  855. sync /* Wait for all dcbst to complete on bus */
  856. mr r4,r3
  857. 6: icbi 0,r4
  858. add r4,r4,r6
  859. cmplw r4,r5
  860. blt 6b
  861. 7: sync /* Wait for all icbi to complete on bus */
  862. isync
  863. /*
  864. * Re-point the IVPR at RAM
  865. */
  866. mtspr IVPR,r10
  867. /*
  868. * We are done. Do not return, instead branch to second part of board
  869. * initialization, now running from RAM.
  870. */
  871. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  872. mtlr r0
  873. blr /* NEVER RETURNS! */
  874. in_ram:
  875. /*
  876. * Relocation Function, r14 point to got2+0x8000
  877. *
  878. * Adjust got2 pointers, no need to check for 0, this code
  879. * already puts a few entries in the table.
  880. */
  881. li r0,__got2_entries@sectoff@l
  882. la r3,GOT(_GOT2_TABLE_)
  883. lwz r11,GOT(_GOT2_TABLE_)
  884. mtctr r0
  885. sub r11,r3,r11
  886. addi r3,r3,-4
  887. 1: lwzu r0,4(r3)
  888. add r0,r0,r11
  889. stw r0,0(r3)
  890. bdnz 1b
  891. /*
  892. * Now adjust the fixups and the pointers to the fixups
  893. * in case we need to move ourselves again.
  894. */
  895. 2: li r0,__fixup_entries@sectoff@l
  896. lwz r3,GOT(_FIXUP_TABLE_)
  897. cmpwi r0,0
  898. mtctr r0
  899. addi r3,r3,-4
  900. beq 4f
  901. 3: lwzu r4,4(r3)
  902. lwzux r0,r4,r11
  903. add r0,r0,r11
  904. stw r10,0(r3)
  905. stw r0,0(r4)
  906. bdnz 3b
  907. 4:
  908. clear_bss:
  909. /*
  910. * Now clear BSS segment
  911. */
  912. lwz r3,GOT(__bss_start)
  913. lwz r4,GOT(_end)
  914. cmplw 0, r3, r4
  915. beq 6f
  916. li r0, 0
  917. 5:
  918. stw r0, 0(r3)
  919. addi r3, r3, 4
  920. cmplw 0, r3, r4
  921. bne 5b
  922. 6:
  923. mr r3, r9 /* Init Data pointer */
  924. mr r4, r10 /* Destination Address */
  925. bl board_init_r
  926. /*
  927. * Copy exception vector code to low memory
  928. *
  929. * r3: dest_addr
  930. * r7: source address, r8: end address, r9: target address
  931. */
  932. .globl trap_init
  933. trap_init:
  934. lwz r7, GOT(_start)
  935. lwz r8, GOT(_end_of_vectors)
  936. li r9, 0x100 /* reset vector always at 0x100 */
  937. cmplw 0, r7, r8
  938. bgelr /* return if r7>=r8 - just in case */
  939. mflr r4 /* save link register */
  940. 1:
  941. lwz r0, 0(r7)
  942. stw r0, 0(r9)
  943. addi r7, r7, 4
  944. addi r9, r9, 4
  945. cmplw 0, r7, r8
  946. bne 1b
  947. /*
  948. * relocate `hdlr' and `int_return' entries
  949. */
  950. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  951. bl trap_reloc
  952. li r7, .L_DataStorage - _start + EXC_OFF_SYS_RESET
  953. bl trap_reloc
  954. li r7, .L_InstStorage - _start + EXC_OFF_SYS_RESET
  955. bl trap_reloc
  956. li r7, .L_ExtInterrupt - _start + EXC_OFF_SYS_RESET
  957. bl trap_reloc
  958. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  959. bl trap_reloc
  960. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  961. bl trap_reloc
  962. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  963. bl trap_reloc
  964. li r7, .L_Decrementer - _start + EXC_OFF_SYS_RESET
  965. bl trap_reloc
  966. li r7, .L_IntervalTimer - _start + EXC_OFF_SYS_RESET
  967. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  968. 2:
  969. bl trap_reloc
  970. addi r7, r7, 0x100 /* next exception vector */
  971. cmplw 0, r7, r8
  972. blt 2b
  973. lis r7,0x0
  974. mtspr IVPR, r7
  975. mtlr r4 /* restore link register */
  976. blr
  977. /*
  978. * Function: relocate entries for one exception vector
  979. */
  980. trap_reloc:
  981. lwz r0, 0(r7) /* hdlr ... */
  982. add r0, r0, r3 /* ... += dest_addr */
  983. stw r0, 0(r7)
  984. lwz r0, 4(r7) /* int_return ... */
  985. add r0, r0, r3 /* ... += dest_addr */
  986. stw r0, 4(r7)
  987. blr
  988. #ifdef CFG_INIT_RAM_LOCK
  989. .globl unlock_ram_in_cache
  990. unlock_ram_in_cache:
  991. /* invalidate the INIT_RAM section */
  992. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  993. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  994. li r2,512
  995. mtctr r2
  996. 1: icbi r0, r3
  997. dcbi r0, r3
  998. addi r3, r3, 32
  999. bdnz 1b
  1000. sync /* Wait for all icbi to complete on bus */
  1001. isync
  1002. blr
  1003. #endif