start.S 23 KB

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