start.S 23 KB

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