start.S 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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 /* 11: Watchdog timer */
  184. li r10,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. li r1,0x0020 /* max 16 TLB1 plus some TLB0 entries */
  223. mtctr r1
  224. lwzu r4,0(r5) /* how many TLB1 entries we actually use */
  225. 0: cmpwi r4,0
  226. beq 1f
  227. lwzu r0,4(r5)
  228. lwzu r1,4(r5)
  229. lwzu r2,4(r5)
  230. lwzu r3,4(r5)
  231. mtspr MAS0,r0
  232. mtspr MAS1,r1
  233. mtspr MAS2,r2
  234. mtspr MAS3,r3
  235. isync
  236. msync
  237. tlbwe
  238. isync
  239. addi r4,r4,-1
  240. bdnz 0b
  241. 1:
  242. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  243. /* Special sequence needed to update CCSRBAR itself */
  244. lis r4, CFG_CCSRBAR_DEFAULT@h
  245. ori r4, r4, CFG_CCSRBAR_DEFAULT@l
  246. lis r5, CFG_CCSRBAR@h
  247. ori r5, r5, CFG_CCSRBAR@l
  248. srwi r6,r5,12
  249. stw r6, 0(r4)
  250. isync
  251. lis r5, 0xffff
  252. ori r5,r5,0xf000
  253. lwz r5, 0(r5)
  254. isync
  255. lis r3, CFG_CCSRBAR@h
  256. lwz r5, CFG_CCSRBAR@l(r3)
  257. isync
  258. #endif
  259. /* set up local access windows, defined at board/<boardname>/init.S */
  260. lis r7,CFG_CCSRBAR@h
  261. ori r7,r7,CFG_CCSRBAR@l
  262. bl law_entry
  263. mr r6,r0
  264. li r1,0x0007 /* 8 LAWs, but reserve one for boot-over-rio-or-pci */
  265. mtctr r1
  266. lwzu r5,0(r6) /* how many windows we actually use */
  267. li r2,0x0c28 /* the first pair is reserved for boot-over-rio-or-pci */
  268. li r1,0x0c30
  269. 0: cmpwi r5,0
  270. beq 1f
  271. lwzu r4,4(r6)
  272. lwzu r3,4(r6)
  273. stwx r4,r7,r2
  274. stwx r3,r7,r1
  275. addi r5,r5,-1
  276. addi r2,r2,0x0020
  277. addi r1,r1,0x0020
  278. bdnz 0b
  279. /* Jump out the last 4K page and continue to 'normal' start */
  280. 1: bl 3f
  281. b _start
  282. 3: li r0,0
  283. mtspr SRR1,r0 /* Keep things disabled for now */
  284. mflr r1
  285. mtspr SRR0,r1
  286. rfi
  287. /*
  288. * r3 - 1st arg to board_init(): IMMP pointer
  289. * r4 - 2nd arg to board_init(): boot flag
  290. */
  291. .text
  292. .long 0x27051956 /* U-BOOT Magic Number */
  293. .globl version_string
  294. version_string:
  295. .ascii U_BOOT_VERSION
  296. .ascii " (", __DATE__, " - ", __TIME__, ")"
  297. .ascii CONFIG_IDENT_STRING, "\0"
  298. . = EXC_OFF_SYS_RESET
  299. .globl _start
  300. _start:
  301. /* Clear and set up some registers. */
  302. li r0,0x0000
  303. lis r1,0xffff
  304. mtspr DEC,r0 /* prevent dec exceptions */
  305. mttbl r0 /* prevent fit & wdt exceptions */
  306. mttbu r0
  307. mtspr TSR,r1 /* clear all timer exception status */
  308. mtspr TCR,r0 /* disable all */
  309. mtspr ESR,r0 /* clear exception syndrome register */
  310. mtspr MCSR,r0 /* machine check syndrome register */
  311. mtxer r0 /* clear integer exception register */
  312. lis r1,0x0002 /* set CE bit (Critical Exceptions) */
  313. ori r1,r1,0x1200 /* set ME/DE bit */
  314. mtmsr r1 /* change MSR */
  315. isync
  316. /* Enable Time Base and Select Time Base Clock */
  317. lis r0,HID0_EMCP@h /* Enable machine check */
  318. ori r0,r0,0x4000 /* time base is processor clock */
  319. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  320. ori r0,r0,0x0080 /* enable MAS7 updates */
  321. #endif
  322. mtspr HID0,r0
  323. #if defined(CONFIG_ADDR_STREAMING)
  324. li r0,0x3000
  325. #else
  326. li r0,0x1000
  327. #endif
  328. mtspr HID1,r0
  329. /* Enable Branch Prediction */
  330. #if defined(CONFIG_BTB)
  331. li r0,0x201 /* BBFI = 1, BPEN = 1 */
  332. mtspr BUCSR,r0
  333. #endif
  334. #if defined(CFG_INIT_DBCR)
  335. lis r1,0xffff
  336. ori r1,r1,0xffff
  337. mtspr DBSR,r1 /* Clear all status bits */
  338. lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
  339. ori r0,r0,CFG_INIT_DBCR@l
  340. mtspr DBCR0,r0
  341. #endif
  342. /* L1 DCache is used for initial RAM */
  343. mfspr r2, L1CSR0
  344. ori r2, r2, 0x0003
  345. oris r2, r2, 0x0001
  346. mtspr L1CSR0, r2 /* enable/invalidate L1 Dcache */
  347. isync
  348. /* Allocate Initial RAM in data cache.
  349. */
  350. lis r3, CFG_INIT_RAM_ADDR@h
  351. ori r3, r3, CFG_INIT_RAM_ADDR@l
  352. li r2, 512 /* 512*32=16K */
  353. mtctr r2
  354. li r0, 0
  355. 1:
  356. dcbz r0, r3
  357. dcbtls 0,r0, r3
  358. addi r3, r3, 32
  359. bdnz 1b
  360. #ifndef CFG_RAMBOOT
  361. /* Calculate absolute address in FLASH and jump there */
  362. /*--------------------------------------------------------------*/
  363. lis r3, CFG_MONITOR_BASE@h
  364. ori r3, r3, CFG_MONITOR_BASE@l
  365. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  366. mtlr r3
  367. blr
  368. in_flash:
  369. #endif /* CFG_RAMBOOT */
  370. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  371. lis r1,CFG_INIT_RAM_ADDR@h
  372. ori r1,r1,CFG_INIT_SP_OFFSET@l
  373. li r0,0
  374. stwu r0,-4(r1)
  375. stwu r0,-4(r1) /* Terminate call chain */
  376. stwu r1,-8(r1) /* Save back chain and move SP */
  377. lis r0,RESET_VECTOR@h /* Address of reset vector */
  378. ori r0,r0, RESET_VECTOR@l
  379. stwu r1,-8(r1) /* Save back chain and move SP */
  380. stw r0,+12(r1) /* Save return addr (underflow vect) */
  381. GET_GOT
  382. bl cpu_init_f
  383. bl icache_enable
  384. bl board_init_f
  385. isync
  386. /* --FIXME-- machine check with MCSRRn and rfmci */
  387. .globl _start_of_vectors
  388. _start_of_vectors:
  389. #if 0
  390. /* Critical input. */
  391. CRIT_EXCEPTION(0x0100, CritcalInput, CritcalInputException)
  392. #endif
  393. /* Machine check --FIXME-- Should be MACH_EXCEPTION */
  394. CRIT_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
  395. /* Data Storage exception. */
  396. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  397. /* Instruction Storage exception. */
  398. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  399. /* External Interrupt exception. */
  400. STD_EXCEPTION(0x0500, ExtInterrupt, UnknownException)
  401. /* Alignment exception. */
  402. . = 0x0600
  403. Alignment:
  404. EXCEPTION_PROLOG
  405. mfspr r4,DAR
  406. stw r4,_DAR(r21)
  407. mfspr r5,DSISR
  408. stw r5,_DSISR(r21)
  409. addi r3,r1,STACK_FRAME_OVERHEAD
  410. li r20,MSR_KERNEL
  411. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  412. lwz r6,GOT(transfer_to_handler)
  413. mtlr r6
  414. blrl
  415. .L_Alignment:
  416. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  417. .long int_return - _start + EXC_OFF_SYS_RESET
  418. /* Program check exception */
  419. . = 0x0700
  420. ProgramCheck:
  421. EXCEPTION_PROLOG
  422. addi r3,r1,STACK_FRAME_OVERHEAD
  423. li r20,MSR_KERNEL
  424. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  425. lwz r6,GOT(transfer_to_handler)
  426. mtlr r6
  427. blrl
  428. .L_ProgramCheck:
  429. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  430. .long int_return - _start + EXC_OFF_SYS_RESET
  431. /* No FPU on MPC85xx. This exception is not supposed to happen.
  432. */
  433. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  434. . = 0x0900
  435. /*
  436. * r0 - SYSCALL number
  437. * r3-... arguments
  438. */
  439. SystemCall:
  440. addis r11,r0,0 /* get functions table addr */
  441. ori r11,r11,0 /* Note: this code is patched in trap_init */
  442. addis r12,r0,0 /* get number of functions */
  443. ori r12,r12,0
  444. cmplw 0, r0, r12
  445. bge 1f
  446. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  447. add r11,r11,r0
  448. lwz r11,0(r11)
  449. li r20,0xd00-4 /* Get stack pointer */
  450. lwz r12,0(r20)
  451. subi r12,r12,12 /* Adjust stack pointer */
  452. li r0,0xc00+_end_back-SystemCall
  453. cmplw 0, r0, r12 /* Check stack overflow */
  454. bgt 1f
  455. stw r12,0(r20)
  456. mflr r0
  457. stw r0,0(r12)
  458. mfspr r0,SRR0
  459. stw r0,4(r12)
  460. mfspr r0,SRR1
  461. stw r0,8(r12)
  462. li r12,0xc00+_back-SystemCall
  463. mtlr r12
  464. mtspr SRR0,r11
  465. 1: SYNC
  466. rfi
  467. _back:
  468. mfmsr r11 /* Disable interrupts */
  469. li r12,0
  470. ori r12,r12,MSR_EE
  471. andc r11,r11,r12
  472. SYNC /* Some chip revs need this... */
  473. mtmsr r11
  474. SYNC
  475. li r12,0xd00-4 /* restore regs */
  476. lwz r12,0(r12)
  477. lwz r11,0(r12)
  478. mtlr r11
  479. lwz r11,4(r12)
  480. mtspr SRR0,r11
  481. lwz r11,8(r12)
  482. mtspr SRR1,r11
  483. addi r12,r12,12 /* Adjust stack pointer */
  484. li r20,0xd00-4
  485. stw r12,0(r20)
  486. SYNC
  487. rfi
  488. _end_back:
  489. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  490. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  491. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  492. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  493. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  494. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  495. .globl _end_of_vectors
  496. _end_of_vectors:
  497. . = 0x2100
  498. /*
  499. * This code finishes saving the registers to the exception frame
  500. * and jumps to the appropriate handler for the exception.
  501. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  502. */
  503. .globl transfer_to_handler
  504. transfer_to_handler:
  505. stw r22,_NIP(r21)
  506. lis r22,MSR_POW@h
  507. andc r23,r23,r22
  508. stw r23,_MSR(r21)
  509. SAVE_GPR(7, r21)
  510. SAVE_4GPRS(8, r21)
  511. SAVE_8GPRS(12, r21)
  512. SAVE_8GPRS(24, r21)
  513. mflr r23
  514. andi. r24,r23,0x3f00 /* get vector offset */
  515. stw r24,TRAP(r21)
  516. li r22,0
  517. stw r22,RESULT(r21)
  518. mtspr SPRG2,r22 /* r1 is now kernel sp */
  519. lwz r24,0(r23) /* virtual address of handler */
  520. lwz r23,4(r23) /* where to go when done */
  521. mtspr SRR0,r24
  522. mtspr SRR1,r20
  523. mtlr r23
  524. SYNC
  525. rfi /* jump to handler, enable MMU */
  526. int_return:
  527. mfmsr r28 /* Disable interrupts */
  528. li r4,0
  529. ori r4,r4,MSR_EE
  530. andc r28,r28,r4
  531. SYNC /* Some chip revs need this... */
  532. mtmsr r28
  533. SYNC
  534. lwz r2,_CTR(r1)
  535. lwz r0,_LINK(r1)
  536. mtctr r2
  537. mtlr r0
  538. lwz r2,_XER(r1)
  539. lwz r0,_CCR(r1)
  540. mtspr XER,r2
  541. mtcrf 0xFF,r0
  542. REST_10GPRS(3, r1)
  543. REST_10GPRS(13, r1)
  544. REST_8GPRS(23, r1)
  545. REST_GPR(31, r1)
  546. lwz r2,_NIP(r1) /* Restore environment */
  547. lwz r0,_MSR(r1)
  548. mtspr SRR0,r2
  549. mtspr SRR1,r0
  550. lwz r0,GPR0(r1)
  551. lwz r2,GPR2(r1)
  552. lwz r1,GPR1(r1)
  553. SYNC
  554. rfi
  555. crit_return:
  556. mfmsr r28 /* Disable interrupts */
  557. li r4,0
  558. ori r4,r4,MSR_EE
  559. andc r28,r28,r4
  560. SYNC /* Some chip revs need this... */
  561. mtmsr r28
  562. SYNC
  563. lwz r2,_CTR(r1)
  564. lwz r0,_LINK(r1)
  565. mtctr r2
  566. mtlr r0
  567. lwz r2,_XER(r1)
  568. lwz r0,_CCR(r1)
  569. mtspr XER,r2
  570. mtcrf 0xFF,r0
  571. REST_10GPRS(3, r1)
  572. REST_10GPRS(13, r1)
  573. REST_8GPRS(23, r1)
  574. REST_GPR(31, r1)
  575. lwz r2,_NIP(r1) /* Restore environment */
  576. lwz r0,_MSR(r1)
  577. mtspr 990,r2 /* SRR2 */
  578. mtspr 991,r0 /* SRR3 */
  579. lwz r0,GPR0(r1)
  580. lwz r2,GPR2(r1)
  581. lwz r1,GPR1(r1)
  582. SYNC
  583. rfci
  584. /* Cache functions.
  585. */
  586. invalidate_icache:
  587. mfspr r0,L1CSR1
  588. ori r0,r0,0x0002
  589. mtspr L1CSR1,r0
  590. isync
  591. blr /* entire I cache */
  592. invalidate_dcache:
  593. mfspr r0,L1CSR0
  594. ori r0,r0,0x0002
  595. msync
  596. isync
  597. mtspr L1CSR0,r0
  598. isync
  599. blr
  600. .globl icache_enable
  601. icache_enable:
  602. mflr r8
  603. bl invalidate_icache
  604. mtlr r8
  605. isync
  606. mfspr r4,L1CSR1
  607. ori r4,r4,0x0001
  608. oris r4,r4,0x0001
  609. mtspr L1CSR1,r4
  610. isync
  611. blr
  612. .globl icache_disable
  613. icache_disable:
  614. mfspr r0,L1CSR1
  615. lis r1,0xfffffffe@h
  616. ori r1,r1,0xfffffffe@l
  617. and r0,r0,r1
  618. mtspr L1CSR1,r0
  619. isync
  620. blr
  621. .globl icache_status
  622. icache_status:
  623. mfspr r3,L1CSR1
  624. srwi r3, r3, 31 /* >>31 => select bit 0 */
  625. blr
  626. .globl dcache_enable
  627. dcache_enable:
  628. mflr r8
  629. bl invalidate_dcache
  630. mtlr r8
  631. isync
  632. mfspr r0,L1CSR0
  633. ori r0,r0,0x0001
  634. oris r0,r0,0x0001
  635. msync
  636. isync
  637. mtspr L1CSR0,r0
  638. isync
  639. blr
  640. .globl dcache_disable
  641. dcache_disable:
  642. mfspr r0,L1CSR0
  643. lis r1,0xfffffffe@h
  644. ori r1,r1,0xfffffffe@l
  645. and r0,r0,r1
  646. msync
  647. isync
  648. mtspr L1CSR0,r0
  649. isync
  650. blr
  651. .globl dcache_status
  652. dcache_status:
  653. mfspr r3,L1CSR0
  654. srwi r3, r3, 31 /* >>31 => select bit 0 */
  655. blr
  656. .globl get_pir
  657. get_pir:
  658. mfspr r3, PIR
  659. blr
  660. .globl get_pvr
  661. get_pvr:
  662. mfspr r3, PVR
  663. blr
  664. .globl get_svr
  665. get_svr:
  666. mfspr r3, SVR
  667. blr
  668. .globl wr_tcr
  669. wr_tcr:
  670. mtspr TCR, r3
  671. blr
  672. /*------------------------------------------------------------------------------- */
  673. /* Function: in8 */
  674. /* Description: Input 8 bits */
  675. /*------------------------------------------------------------------------------- */
  676. .globl in8
  677. in8:
  678. lbz r3,0x0000(r3)
  679. blr
  680. /*------------------------------------------------------------------------------- */
  681. /* Function: out8 */
  682. /* Description: Output 8 bits */
  683. /*------------------------------------------------------------------------------- */
  684. .globl out8
  685. out8:
  686. stb r4,0x0000(r3)
  687. blr
  688. /*------------------------------------------------------------------------------- */
  689. /* Function: out16 */
  690. /* Description: Output 16 bits */
  691. /*------------------------------------------------------------------------------- */
  692. .globl out16
  693. out16:
  694. sth r4,0x0000(r3)
  695. blr
  696. /*------------------------------------------------------------------------------- */
  697. /* Function: out16r */
  698. /* Description: Byte reverse and output 16 bits */
  699. /*------------------------------------------------------------------------------- */
  700. .globl out16r
  701. out16r:
  702. sthbrx r4,r0,r3
  703. blr
  704. /*------------------------------------------------------------------------------- */
  705. /* Function: out32 */
  706. /* Description: Output 32 bits */
  707. /*------------------------------------------------------------------------------- */
  708. .globl out32
  709. out32:
  710. stw r4,0x0000(r3)
  711. blr
  712. /*------------------------------------------------------------------------------- */
  713. /* Function: out32r */
  714. /* Description: Byte reverse and output 32 bits */
  715. /*------------------------------------------------------------------------------- */
  716. .globl out32r
  717. out32r:
  718. stwbrx r4,r0,r3
  719. blr
  720. /*------------------------------------------------------------------------------- */
  721. /* Function: in16 */
  722. /* Description: Input 16 bits */
  723. /*------------------------------------------------------------------------------- */
  724. .globl in16
  725. in16:
  726. lhz r3,0x0000(r3)
  727. blr
  728. /*------------------------------------------------------------------------------- */
  729. /* Function: in16r */
  730. /* Description: Input 16 bits and byte reverse */
  731. /*------------------------------------------------------------------------------- */
  732. .globl in16r
  733. in16r:
  734. lhbrx r3,r0,r3
  735. blr
  736. /*------------------------------------------------------------------------------- */
  737. /* Function: in32 */
  738. /* Description: Input 32 bits */
  739. /*------------------------------------------------------------------------------- */
  740. .globl in32
  741. in32:
  742. lwz 3,0x0000(3)
  743. blr
  744. /*------------------------------------------------------------------------------- */
  745. /* Function: in32r */
  746. /* Description: Input 32 bits and byte reverse */
  747. /*------------------------------------------------------------------------------- */
  748. .globl in32r
  749. in32r:
  750. lwbrx r3,r0,r3
  751. blr
  752. /*------------------------------------------------------------------------------- */
  753. /* Function: ppcDcbf */
  754. /* Description: Data Cache block flush */
  755. /* Input: r3 = effective address */
  756. /* Output: none. */
  757. /*------------------------------------------------------------------------------- */
  758. .globl ppcDcbf
  759. ppcDcbf:
  760. dcbf r0,r3
  761. blr
  762. /*------------------------------------------------------------------------------- */
  763. /* Function: ppcDcbi */
  764. /* Description: Data Cache block Invalidate */
  765. /* Input: r3 = effective address */
  766. /* Output: none. */
  767. /*------------------------------------------------------------------------------- */
  768. .globl ppcDcbi
  769. ppcDcbi:
  770. dcbi r0,r3
  771. blr
  772. /*--------------------------------------------------------------------------
  773. * Function: ppcDcbz
  774. * Description: Data Cache block zero.
  775. * Input: r3 = effective address
  776. * Output: none.
  777. *-------------------------------------------------------------------------- */
  778. .globl ppcDcbz
  779. ppcDcbz:
  780. dcbz r0,r3
  781. blr
  782. /*------------------------------------------------------------------------------- */
  783. /* Function: ppcSync */
  784. /* Description: Processor Synchronize */
  785. /* Input: none. */
  786. /* Output: none. */
  787. /*------------------------------------------------------------------------------- */
  788. .globl ppcSync
  789. ppcSync:
  790. sync
  791. blr
  792. /*------------------------------------------------------------------------------*/
  793. /*
  794. * void relocate_code (addr_sp, gd, addr_moni)
  795. *
  796. * This "function" does not return, instead it continues in RAM
  797. * after relocating the monitor code.
  798. *
  799. * r3 = dest
  800. * r4 = src
  801. * r5 = length in bytes
  802. * r6 = cachelinesize
  803. */
  804. .globl relocate_code
  805. relocate_code:
  806. mr r1, r3 /* Set new stack pointer */
  807. mr r9, r4 /* Save copy of Init Data pointer */
  808. mr r10, r5 /* Save copy of Destination Address */
  809. mr r3, r5 /* Destination Address */
  810. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  811. ori r4, r4, CFG_MONITOR_BASE@l
  812. lwz r5,GOT(__init_end)
  813. sub r5,r5,r4
  814. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  815. /*
  816. * Fix GOT pointer:
  817. *
  818. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  819. *
  820. * Offset:
  821. */
  822. sub r15, r10, r4
  823. /* First our own GOT */
  824. add r14, r14, r15
  825. /* the the one used by the C code */
  826. add r30, r30, r15
  827. /*
  828. * Now relocate code
  829. */
  830. cmplw cr1,r3,r4
  831. addi r0,r5,3
  832. srwi. r0,r0,2
  833. beq cr1,4f /* In place copy is not necessary */
  834. beq 7f /* Protect against 0 count */
  835. mtctr r0
  836. bge cr1,2f
  837. la r8,-4(r4)
  838. la r7,-4(r3)
  839. 1: lwzu r0,4(r8)
  840. stwu r0,4(r7)
  841. bdnz 1b
  842. b 4f
  843. 2: slwi r0,r0,2
  844. add r8,r4,r0
  845. add r7,r3,r0
  846. 3: lwzu r0,-4(r8)
  847. stwu r0,-4(r7)
  848. bdnz 3b
  849. /*
  850. * Now flush the cache: note that we must start from a cache aligned
  851. * address. Otherwise we might miss one cache line.
  852. */
  853. 4: cmpwi r6,0
  854. add r5,r3,r5
  855. beq 7f /* Always flush prefetch queue in any case */
  856. subi r0,r6,1
  857. andc r3,r3,r0
  858. mr r4,r3
  859. 5: dcbst 0,r4
  860. add r4,r4,r6
  861. cmplw r4,r5
  862. blt 5b
  863. sync /* Wait for all dcbst to complete on bus */
  864. mr r4,r3
  865. 6: icbi 0,r4
  866. add r4,r4,r6
  867. cmplw r4,r5
  868. blt 6b
  869. 7: sync /* Wait for all icbi to complete on bus */
  870. isync
  871. /*
  872. * We are done. Do not return, instead branch to second part of board
  873. * initialization, now running from RAM.
  874. */
  875. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  876. mtlr r0
  877. blr /* NEVER RETURNS! */
  878. in_ram:
  879. /*
  880. * Relocation Function, r14 point to got2+0x8000
  881. *
  882. * Adjust got2 pointers, no need to check for 0, this code
  883. * already puts a few entries in the table.
  884. */
  885. li r0,__got2_entries@sectoff@l
  886. la r3,GOT(_GOT2_TABLE_)
  887. lwz r11,GOT(_GOT2_TABLE_)
  888. mtctr r0
  889. sub r11,r3,r11
  890. addi r3,r3,-4
  891. 1: lwzu r0,4(r3)
  892. add r0,r0,r11
  893. stw r0,0(r3)
  894. bdnz 1b
  895. /*
  896. * Now adjust the fixups and the pointers to the fixups
  897. * in case we need to move ourselves again.
  898. */
  899. 2: li r0,__fixup_entries@sectoff@l
  900. lwz r3,GOT(_FIXUP_TABLE_)
  901. cmpwi r0,0
  902. mtctr r0
  903. addi r3,r3,-4
  904. beq 4f
  905. 3: lwzu r4,4(r3)
  906. lwzux r0,r4,r11
  907. add r0,r0,r11
  908. stw r10,0(r3)
  909. stw r0,0(r4)
  910. bdnz 3b
  911. 4:
  912. clear_bss:
  913. /*
  914. * Now clear BSS segment
  915. */
  916. lwz r3,GOT(__bss_start)
  917. lwz r4,GOT(_end)
  918. cmplw 0, r3, r4
  919. beq 6f
  920. li r0, 0
  921. 5:
  922. stw r0, 0(r3)
  923. addi r3, r3, 4
  924. cmplw 0, r3, r4
  925. bne 5b
  926. 6:
  927. mr r3, r9 /* Init Data pointer */
  928. mr r4, r10 /* Destination Address */
  929. bl board_init_r
  930. /*
  931. * Copy exception vector code to low memory
  932. *
  933. * r3: dest_addr
  934. * r7: source address, r8: end address, r9: target address
  935. */
  936. .globl trap_init
  937. trap_init:
  938. lwz r7, GOT(_start)
  939. lwz r8, GOT(_end_of_vectors)
  940. li r9, 0x100 /* reset vector always at 0x100 */
  941. cmplw 0, r7, r8
  942. bgelr /* return if r7>=r8 - just in case */
  943. mflr r4 /* save link register */
  944. 1:
  945. lwz r0, 0(r7)
  946. stw r0, 0(r9)
  947. addi r7, r7, 4
  948. addi r9, r9, 4
  949. cmplw 0, r7, r8
  950. bne 1b
  951. /*
  952. * relocate `hdlr' and `int_return' entries
  953. */
  954. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  955. bl trap_reloc
  956. li r7, .L_DataStorage - _start + EXC_OFF_SYS_RESET
  957. bl trap_reloc
  958. li r7, .L_InstStorage - _start + EXC_OFF_SYS_RESET
  959. bl trap_reloc
  960. li r7, .L_ExtInterrupt - _start + EXC_OFF_SYS_RESET
  961. bl trap_reloc
  962. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  963. bl trap_reloc
  964. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  965. bl trap_reloc
  966. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  967. bl trap_reloc
  968. li r7, .L_Decrementer - _start + EXC_OFF_SYS_RESET
  969. bl trap_reloc
  970. li r7, .L_IntervalTimer - _start + EXC_OFF_SYS_RESET
  971. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  972. 2:
  973. bl trap_reloc
  974. addi r7, r7, 0x100 /* next exception vector */
  975. cmplw 0, r7, r8
  976. blt 2b
  977. lis r7,0x0
  978. mtspr IVPR, r7
  979. mtlr r4 /* restore link register */
  980. blr
  981. /*
  982. * Function: relocate entries for one exception vector
  983. */
  984. trap_reloc:
  985. lwz r0, 0(r7) /* hdlr ... */
  986. add r0, r0, r3 /* ... += dest_addr */
  987. stw r0, 0(r7)
  988. lwz r0, 4(r7) /* int_return ... */
  989. add r0, r0, r3 /* ... += dest_addr */
  990. stw r0, 4(r7)
  991. blr
  992. #ifdef CFG_INIT_RAM_LOCK
  993. .globl unlock_ram_in_cache
  994. unlock_ram_in_cache:
  995. /* invalidate the INIT_RAM section */
  996. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  997. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  998. li r2,512
  999. mtctr r2
  1000. 1: icbi r0, r3
  1001. dcbi r0, r3
  1002. addi r3, r3, 32
  1003. bdnz 1b
  1004. sync /* Wait for all icbi to complete on bus */
  1005. isync
  1006. blr
  1007. #endif