start.S 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /*
  2. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * U-Boot - Startup Code for MPC8260 PowerPC based Embedded Boards
  26. */
  27. #include <config.h>
  28. #include <mpc8260.h>
  29. #include <version.h>
  30. #define CONFIG_8260 1 /* needed for Linux kernel header files */
  31. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  32. #include <ppc_asm.tmpl>
  33. #include <ppc_defs.h>
  34. #include <asm/cache.h>
  35. #include <asm/mmu.h>
  36. #ifndef CONFIG_IDENT_STRING
  37. #define CONFIG_IDENT_STRING ""
  38. #endif
  39. /* We don't want the MMU yet.
  40. */
  41. #undef MSR_KERNEL
  42. /* Floating Point enable, Machine Check and Recoverable Interr. */
  43. #ifdef DEBUG
  44. #define MSR_KERNEL (MSR_FP|MSR_RI)
  45. #else
  46. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  47. #endif
  48. /*
  49. * Set up GOT: Global Offset Table
  50. *
  51. * Use r14 to access the GOT
  52. */
  53. START_GOT
  54. GOT_ENTRY(_GOT2_TABLE_)
  55. GOT_ENTRY(_FIXUP_TABLE_)
  56. GOT_ENTRY(_start)
  57. GOT_ENTRY(_start_of_vectors)
  58. GOT_ENTRY(_end_of_vectors)
  59. GOT_ENTRY(transfer_to_handler)
  60. GOT_ENTRY(__init_end)
  61. GOT_ENTRY(_end)
  62. GOT_ENTRY(__bss_start)
  63. #if defined(CONFIG_HYMOD)
  64. GOT_ENTRY(environment)
  65. #endif
  66. END_GOT
  67. /*
  68. * Version string - must be in data segment because MPC8260 uses the first
  69. * 256 bytes for the Hard Reset Configuration Word table (see below).
  70. * Similarly, can't have the U-Boot Magic Number as the first thing in
  71. * the image - don't know how this will affect the image tools, but I guess
  72. * I'll find out soon
  73. */
  74. .data
  75. .globl version_string
  76. version_string:
  77. .ascii U_BOOT_VERSION
  78. .ascii " (", __DATE__, " - ", __TIME__, ")"
  79. .ascii CONFIG_IDENT_STRING, "\0"
  80. /*
  81. * Hard Reset Configuration Word (HRCW) table
  82. *
  83. * The Hard Reset Configuration Word (HRCW) sets a number of useful things
  84. * such as whether there is an external memory controller, whether the
  85. * PowerPC core is disabled (i.e. only the communications processor is
  86. * active, accessed by another CPU on the bus), whether using external
  87. * arbitration, external bus mode, boot port size, core initial prefix,
  88. * internal space base, boot memory space, etc.
  89. *
  90. * These things dictate where the processor begins execution, where the
  91. * boot ROM appears in memory, the memory controller setup when access
  92. * boot ROM, etc. The HRCW is *extremely* important.
  93. *
  94. * The HRCW is read from the bus during reset. One CPU on the bus will
  95. * be a hard reset configuration master, any others will be hard reset
  96. * configuration slaves. The master reads eight HRCWs from flash during
  97. * reset - the first it uses for itself, the other 7 it communicates to
  98. * up to 7 configuration slaves by some complicated mechanism, which is
  99. * not really important here.
  100. *
  101. * The configuration master performs 32 successive reads starting at address
  102. * 0 and incrementing by 8 each read (i.e. on 64 bit boundaries) but only 8
  103. * bits is read, and always from byte lane D[0-7] (so that port size of the
  104. * boot device does not matter). The first four reads form the 32 bit HRCW
  105. * for the master itself. The second four reads form the HRCW for the first
  106. * slave, and so on, up to seven slaves. The 32 bit HRCW is formed by
  107. * concatenating the four bytes, with the first read placed in byte 0 (the
  108. * most significant byte), and so on with the fourth read placed in byte 3
  109. * (the least significant byte).
  110. */
  111. #define _HRCW_TABLE_ENTRY(w) \
  112. .fill 8,1,(((w)>>24)&0xff); \
  113. .fill 8,1,(((w)>>16)&0xff); \
  114. .fill 8,1,(((w)>> 8)&0xff); \
  115. .fill 8,1,(((w) )&0xff)
  116. .text
  117. .globl _hrcw_table
  118. _hrcw_table:
  119. _HRCW_TABLE_ENTRY(CFG_HRCW_MASTER)
  120. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE1)
  121. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE2)
  122. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE3)
  123. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE4)
  124. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE5)
  125. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE6)
  126. _HRCW_TABLE_ENTRY(CFG_HRCW_SLAVE7)
  127. /*
  128. * After configuration, a system reset exception is executed using the
  129. * vector at offset 0x100 relative to the base set by MSR[IP]. If MSR[IP]
  130. * is 0, the base address is 0x00000000. If MSR[IP] is 1, the base address
  131. * is 0xfff00000. In the case of a Power On Reset or Hard Reset, the value
  132. * of MSR[IP] is determined by the CIP field in the HRCW.
  133. *
  134. * Other bits in the HRCW set up the Base Address and Port Size in BR0.
  135. * This determines the location of the boot ROM (flash or EPROM) in the
  136. * processor's address space at boot time. As long as the HRCW is set up
  137. * so that we eventually end up executing the code below when the processor
  138. * executes the reset exception, the actual values used should not matter.
  139. *
  140. * Once we have got here, the address mask in OR0 is cleared so that the
  141. * bottom 32K of the boot ROM is effectively repeated all throughout the
  142. * processor's address space, after which we can jump to the absolute
  143. * address at which the boot ROM was linked at compile time, and proceed
  144. * to initialise the memory controller without worrying if the rug will be
  145. * pulled out from under us, so to speak (it will be fine as long as we
  146. * configure BR0 with the same boot ROM link address).
  147. */
  148. . = EXC_OFF_SYS_RESET
  149. .globl _start
  150. _start:
  151. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH*/
  152. nop
  153. b boot_cold
  154. . = EXC_OFF_SYS_RESET + 0x10
  155. .globl _start_warm
  156. _start_warm:
  157. li r21, BOOTFLAG_WARM /* Software reboot */
  158. b boot_warm
  159. boot_cold:
  160. #if defined(CONFIG_MPC8260ADS)
  161. lis r3, CFG_DEFAULT_IMMR@h
  162. nop
  163. lwz r4, 0(r3)
  164. nop
  165. rlwinm r4, r4, 0, 8, 5
  166. nop
  167. oris r4, r4, 0x0200
  168. nop
  169. stw r4, 0(r3)
  170. nop
  171. #endif /* CONFIG_MPC8260ADS */
  172. boot_warm:
  173. mfmsr r5 /* save msr contents */
  174. #if defined(CONFIG_COGENT)
  175. /* this is what the cogent EPROM does */
  176. li r0, 0
  177. mtmsr r0
  178. isync
  179. bl cogent_init_8260
  180. #endif /* CONFIG_COGENT */
  181. #if defined(CFG_DEFAULT_IMMR)
  182. lis r3, CFG_IMMR@h
  183. ori r3, r3, CFG_IMMR@l
  184. lis r4, CFG_DEFAULT_IMMR@h
  185. stw r3, 0x1A8(r4)
  186. #endif /* CFG_DEFAULT_IMMR */
  187. /* Initialise the MPC8260 processor core */
  188. /*--------------------------------------------------------------*/
  189. bl init_8260_core
  190. #ifndef CFG_RAMBOOT
  191. /* When booting from ROM (Flash or EPROM), clear the */
  192. /* Address Mask in OR0 so ROM appears everywhere */
  193. /*--------------------------------------------------------------*/
  194. lis r3, (CFG_IMMR+IM_REGBASE)@h
  195. lwz r4, IM_OR0@l(r3)
  196. li r5, 0x7fff
  197. and r4, r4, r5
  198. stw r4, IM_OR0@l(r3)
  199. /* Calculate absolute address in FLASH and jump there */
  200. /*--------------------------------------------------------------*/
  201. lis r3, CFG_MONITOR_BASE@h
  202. ori r3, r3, CFG_MONITOR_BASE@l
  203. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  204. mtlr r3
  205. blr
  206. in_flash:
  207. #endif /* CFG_RAMBOOT */
  208. /* initialize some things that are hard to access from C */
  209. /*--------------------------------------------------------------*/
  210. lis r3, CFG_IMMR@h /* set up stack in internal DPRAM */
  211. ori r1, r3, CFG_INIT_SP_OFFSET
  212. li r0, 0 /* Make room for stack frame header and */
  213. stwu r0, -4(r1) /* clear final stack frame so that */
  214. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  215. /* let the C-code set up the rest */
  216. /* */
  217. /* Be careful to keep code relocatable ! */
  218. /*--------------------------------------------------------------*/
  219. GET_GOT /* initialize GOT access */
  220. /* r3: IMMR */
  221. bl cpu_init_f /* run low-level CPU init code (in Flash)*/
  222. #ifdef DEBUG
  223. bl init_debug /* set up debugging stuff */
  224. #endif
  225. mr r3, r21
  226. /* r3: BOOTFLAG */
  227. bl board_init_f /* run 1st part of board init code (in Flash)*/
  228. /*
  229. * Vector Table
  230. */
  231. .globl _start_of_vectors
  232. _start_of_vectors:
  233. /* Machine check */
  234. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  235. /* Data Storage exception. */
  236. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  237. /* Instruction Storage exception. */
  238. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  239. /* External Interrupt exception. */
  240. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  241. /* Alignment exception. */
  242. . = 0x600
  243. Alignment:
  244. EXCEPTION_PROLOG
  245. mfspr r4,DAR
  246. stw r4,_DAR(r21)
  247. mfspr r5,DSISR
  248. stw r5,_DSISR(r21)
  249. addi r3,r1,STACK_FRAME_OVERHEAD
  250. li r20,MSR_KERNEL
  251. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  252. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  253. lwz r6,GOT(transfer_to_handler)
  254. mtlr r6
  255. blrl
  256. .L_Alignment:
  257. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  258. .long int_return - _start + EXC_OFF_SYS_RESET
  259. /* Program check exception */
  260. . = 0x700
  261. ProgramCheck:
  262. EXCEPTION_PROLOG
  263. addi r3,r1,STACK_FRAME_OVERHEAD
  264. li r20,MSR_KERNEL
  265. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  266. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  267. lwz r6,GOT(transfer_to_handler)
  268. mtlr r6
  269. blrl
  270. .L_ProgramCheck:
  271. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  272. .long int_return - _start + EXC_OFF_SYS_RESET
  273. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  274. /* I guess we could implement decrementer, and may have
  275. * to someday for timekeeping.
  276. */
  277. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  278. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  279. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  280. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  281. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  282. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  283. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  284. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  285. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  286. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  287. #ifdef DEBUG
  288. . = 0x1300
  289. /*
  290. * This exception occurs when the program counter matches the
  291. * Instruction Address Breakpoint Register (IABR).
  292. *
  293. * I want the cpu to halt if this occurs so I can hunt around
  294. * with the debugger and look at things.
  295. *
  296. * When DEBUG is defined, both machine check enable (in the MSR)
  297. * and checkstop reset enable (in the reset mode register) are
  298. * turned off and so a checkstop condition will result in the cpu
  299. * halting.
  300. *
  301. * I force the cpu into a checkstop condition by putting an illegal
  302. * instruction here (at least this is the theory).
  303. *
  304. * well - that didnt work, so just do an infinite loop!
  305. */
  306. 1: b 1b
  307. #else
  308. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  309. #endif
  310. STD_EXCEPTION(0x1400, SMI, UnknownException)
  311. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  312. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  313. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  314. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  315. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  316. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  317. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  318. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  319. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  320. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  321. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  322. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  323. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  324. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  325. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  326. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  327. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  328. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  329. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  330. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  331. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  332. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  333. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  334. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  335. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  336. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  337. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  338. .globl _end_of_vectors
  339. _end_of_vectors:
  340. . = 0x3000
  341. /*
  342. * This code finishes saving the registers to the exception frame
  343. * and jumps to the appropriate handler for the exception.
  344. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  345. */
  346. .globl transfer_to_handler
  347. transfer_to_handler:
  348. stw r22,_NIP(r21)
  349. lis r22,MSR_POW@h
  350. andc r23,r23,r22
  351. stw r23,_MSR(r21)
  352. SAVE_GPR(7, r21)
  353. SAVE_4GPRS(8, r21)
  354. SAVE_8GPRS(12, r21)
  355. SAVE_8GPRS(24, r21)
  356. mflr r23
  357. andi. r24,r23,0x3f00 /* get vector offset */
  358. stw r24,TRAP(r21)
  359. li r22,0
  360. stw r22,RESULT(r21)
  361. lwz r24,0(r23) /* virtual address of handler */
  362. lwz r23,4(r23) /* where to go when done */
  363. mtspr SRR0,r24
  364. mtspr SRR1,r20
  365. mtlr r23
  366. SYNC
  367. rfi /* jump to handler, enable MMU */
  368. int_return:
  369. mfmsr r28 /* Disable interrupts */
  370. li r4,0
  371. ori r4,r4,MSR_EE
  372. andc r28,r28,r4
  373. SYNC /* Some chip revs need this... */
  374. mtmsr r28
  375. SYNC
  376. lwz r2,_CTR(r1)
  377. lwz r0,_LINK(r1)
  378. mtctr r2
  379. mtlr r0
  380. lwz r2,_XER(r1)
  381. lwz r0,_CCR(r1)
  382. mtspr XER,r2
  383. mtcrf 0xFF,r0
  384. REST_10GPRS(3, r1)
  385. REST_10GPRS(13, r1)
  386. REST_8GPRS(23, r1)
  387. REST_GPR(31, r1)
  388. lwz r2,_NIP(r1) /* Restore environment */
  389. lwz r0,_MSR(r1)
  390. mtspr SRR0,r2
  391. mtspr SRR1,r0
  392. lwz r0,GPR0(r1)
  393. lwz r2,GPR2(r1)
  394. lwz r1,GPR1(r1)
  395. SYNC
  396. rfi
  397. #if defined(CONFIG_COGENT)
  398. /*
  399. * This code initialises the MPC8260 processor core
  400. * (conforms to PowerPC 603e spec)
  401. */
  402. .globl cogent_init_8260
  403. cogent_init_8260:
  404. /* Taken from page 14 of CMA282 manual */
  405. /*--------------------------------------------------------------*/
  406. lis r4, (CFG_IMMR+IM_REGBASE)@h
  407. lis r3, CFG_IMMR@h
  408. stw r3, IM_IMMR@l(r4)
  409. lwz r3, IM_IMMR@l(r4)
  410. stw r3, 0(r0)
  411. lis r3, CFG_SYPCR@h
  412. ori r3, r3, CFG_SYPCR@l
  413. stw r3, IM_SYPCR@l(r4)
  414. lwz r3, IM_SYPCR@l(r4)
  415. stw r3, 4(r0)
  416. lis r3, CFG_SCCR@h
  417. ori r3, r3, CFG_SCCR@l
  418. stw r3, IM_SCCR@l(r4)
  419. lwz r3, IM_SCCR@l(r4)
  420. stw r3, 8(r0)
  421. /* the rest of this was disassembled from the */
  422. /* EPROM code that came with my CMA282 CPU module */
  423. /*--------------------------------------------------------------*/
  424. lis r1, 0x1234
  425. ori r1, r1, 0x5678
  426. stw r1, 0x20(r0)
  427. lwz r1, 0x20(r0)
  428. stw r1, 0x24(r0)
  429. lwz r1, 0x24(r0)
  430. lis r3, 0x0e80
  431. ori r3, r3, 0
  432. stw r1, 4(r3)
  433. lwz r1, 4(r3)
  434. /* Done! */
  435. /*--------------------------------------------------------------*/
  436. blr
  437. #endif /* CONFIG_COGENT */
  438. /*
  439. * This code initialises the MPC8260 processor core
  440. * (conforms to PowerPC 603e spec)
  441. * Note: expects original MSR contents to be in r5.
  442. */
  443. .globl init_8260_core
  444. init_8260_core:
  445. /* Initialize machine status; enable machine check interrupt */
  446. /*--------------------------------------------------------------*/
  447. li r3, MSR_KERNEL /* Set ME and RI flags */
  448. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  449. #ifdef DEBUG
  450. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  451. #endif
  452. SYNC /* Some chip revs need this... */
  453. mtmsr r3
  454. SYNC
  455. mtspr SRR1, r3 /* Make SRR1 match MSR */
  456. /* Initialise the SYPCR early, and reset the watchdog (if req) */
  457. /*--------------------------------------------------------------*/
  458. lis r3, (CFG_IMMR+IM_REGBASE)@h
  459. #if !defined(CONFIG_COGENT)
  460. lis r4, CFG_SYPCR@h
  461. ori r4, r4, CFG_SYPCR@l
  462. stw r4, IM_SYPCR@l(r3)
  463. #endif /* !CONFIG_COGENT */
  464. #if defined(CONFIG_WATCHDOG)
  465. li r4, 21868 /* = 0x556c */
  466. sth r4, IM_SWSR@l(r3)
  467. li r4, -21959 /* = 0xaa39 */
  468. sth r4, IM_SWSR@l(r3)
  469. #endif /* CONFIG_WATCHDOG */
  470. /* Initialize the Hardware Implementation-dependent Registers */
  471. /* HID0 also contains cache control */
  472. /*--------------------------------------------------------------*/
  473. lis r3, CFG_HID0_INIT@h
  474. ori r3, r3, CFG_HID0_INIT@l
  475. SYNC
  476. mtspr HID0, r3
  477. lis r3, CFG_HID0_FINAL@h
  478. ori r3, r3, CFG_HID0_FINAL@l
  479. SYNC
  480. mtspr HID0, r3
  481. lis r3, CFG_HID2@h
  482. ori r3, r3, CFG_HID2@l
  483. mtspr HID2, r3
  484. /* clear all BAT's */
  485. /*--------------------------------------------------------------*/
  486. li r0, 0
  487. mtspr DBAT0U, r0
  488. mtspr DBAT0L, r0
  489. mtspr DBAT1U, r0
  490. mtspr DBAT1L, r0
  491. mtspr DBAT2U, r0
  492. mtspr DBAT2L, r0
  493. mtspr DBAT3U, r0
  494. mtspr DBAT3L, r0
  495. mtspr IBAT0U, r0
  496. mtspr IBAT0L, r0
  497. mtspr IBAT1U, r0
  498. mtspr IBAT1L, r0
  499. mtspr IBAT2U, r0
  500. mtspr IBAT2L, r0
  501. mtspr IBAT3U, r0
  502. mtspr IBAT3L, r0
  503. SYNC
  504. /* invalidate all tlb's */
  505. /* */
  506. /* From the 603e User Manual: "The 603e provides the ability to */
  507. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  508. /* instruction invalidates the TLB entry indexed by the EA, and */
  509. /* operates on both the instruction and data TLBs simultaneously*/
  510. /* invalidating four TLB entries (both sets in each TLB). The */
  511. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  512. /* entries within both TLBs, 32 tlbie instructions should be */
  513. /* issued, incrementing this field by one each time." */
  514. /* */
  515. /* "Note that the tlbia instruction is not implemented on the */
  516. /* 603e." */
  517. /* */
  518. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  519. /* incrementing by 0x1000 each time. The code below is sort of */
  520. /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
  521. /* */
  522. /*--------------------------------------------------------------*/
  523. li r3, 32
  524. mtctr r3
  525. li r3, 0
  526. 1: tlbie r3
  527. addi r3, r3, 0x1000
  528. bdnz 1b
  529. SYNC
  530. /* Done! */
  531. /*--------------------------------------------------------------*/
  532. blr
  533. #ifdef DEBUG
  534. /*
  535. * initialise things related to debugging.
  536. *
  537. * must be called after the global offset table (GOT) is initialised
  538. * (GET_GOT) and after cpu_init_f() has executed.
  539. */
  540. .globl init_debug
  541. init_debug:
  542. lis r3, (CFG_IMMR+IM_REGBASE)@h
  543. /* Quick and dirty hack to enable the RAM and copy the */
  544. /* vectors so that we can take exceptions. */
  545. /*--------------------------------------------------------------*/
  546. /* write Memory Refresh Prescaler */
  547. li r4, CFG_MPTPR
  548. sth r4, IM_MPTPR@l(r3)
  549. /* write 60x Refresh Timer */
  550. li r4, CFG_PSRT
  551. stb r4, IM_PSRT@l(r3)
  552. /* init the 60x SDRAM Mode Register */
  553. lis r4, (CFG_PSDMR|PSDMR_OP_NORM)@h
  554. ori r4, r4, (CFG_PSDMR|PSDMR_OP_NORM)@l
  555. stw r4, IM_PSDMR@l(r3)
  556. /* write Precharge All Banks command */
  557. lis r4, (CFG_PSDMR|PSDMR_OP_PREA)@h
  558. ori r4, r4, (CFG_PSDMR|PSDMR_OP_PREA)@l
  559. stw r4, IM_PSDMR@l(r3)
  560. stb r0, 0(0)
  561. /* write eight CBR Refresh commands */
  562. lis r4, (CFG_PSDMR|PSDMR_OP_CBRR)@h
  563. ori r4, r4, (CFG_PSDMR|PSDMR_OP_CBRR)@l
  564. stw r4, IM_PSDMR@l(r3)
  565. stb r0, 0(0)
  566. stb r0, 0(0)
  567. stb r0, 0(0)
  568. stb r0, 0(0)
  569. stb r0, 0(0)
  570. stb r0, 0(0)
  571. stb r0, 0(0)
  572. stb r0, 0(0)
  573. /* write Mode Register Write command */
  574. lis r4, (CFG_PSDMR|PSDMR_OP_MRW)@h
  575. ori r4, r4, (CFG_PSDMR|PSDMR_OP_MRW)@l
  576. stw r4, IM_PSDMR@l(r3)
  577. stb r0, 0(0)
  578. /* write Normal Operation command and enable Refresh */
  579. lis r4, (CFG_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@h
  580. ori r4, r4, (CFG_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@l
  581. stw r4, IM_PSDMR@l(r3)
  582. stb r0, 0(0)
  583. /* RAM should now be operational */
  584. #define VEC_WRD_CNT ((_end_of_vectors - _start + EXC_OFF_SYS_RESET) / 4)
  585. lwz r3, GOT(_end_of_vectors)
  586. rlwinm r4, r3, 0, 18, 31 /* _end_of_vectors & 0x3FFF */
  587. lis r5, VEC_WRD_CNT@h
  588. ori r5, r5, VEC_WRD_CNT@l
  589. mtctr r5
  590. 1:
  591. lwzu r5, -4(r3)
  592. stwu r5, -4(r4)
  593. bdnz 1b
  594. /* Load the Instruction Address Breakpoint Register (IABR). */
  595. /* */
  596. /* The address to load is stored in the first word of dual port */
  597. /* ram and should be preserved while the power is on, so you */
  598. /* can plug addresses into that location then reset the cpu and */
  599. /* this code will load that address into the IABR after the */
  600. /* reset. */
  601. /* */
  602. /* When the program counter matches the contents of the IABR, */
  603. /* an exception is generated (before the instruction at that */
  604. /* location completes). The vector for this exception is 0x1300 */
  605. /*--------------------------------------------------------------*/
  606. lis r3, CFG_IMMR@h
  607. lwz r3, 0(r3)
  608. mtspr IABR, r3
  609. /* Set the entire dual port RAM (where the initial stack */
  610. /* resides) to a known value - makes it easier to see where */
  611. /* the stack has been written */
  612. /*--------------------------------------------------------------*/
  613. lis r3, (CFG_IMMR + CFG_INIT_SP_OFFSET)@h
  614. ori r3, r3, (CFG_IMMR + CFG_INIT_SP_OFFSET)@l
  615. li r4, ((CFG_INIT_SP_OFFSET - 4) / 4)
  616. mtctr r4
  617. lis r4, 0xdeadbeaf@h
  618. ori r4, r4, 0xdeadbeaf@l
  619. 1:
  620. stwu r4, -4(r3)
  621. bdnz 1b
  622. /* Done! */
  623. /*--------------------------------------------------------------*/
  624. blr
  625. #endif
  626. /* Cache functions.
  627. *
  628. * Note: requires that all cache bits in
  629. * HID0 are in the low half word.
  630. */
  631. .globl icache_enable
  632. icache_enable:
  633. mfspr r3, HID0
  634. ori r3, r3, HID0_ICE
  635. lis r4, 0
  636. ori r4, r4, HID0_ILOCK
  637. andc r3, r3, r4
  638. ori r4, r3, HID0_ICFI
  639. isync
  640. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  641. isync
  642. mtspr HID0, r3 /* clears invalidate */
  643. blr
  644. .globl icache_disable
  645. icache_disable:
  646. mfspr r3, HID0
  647. lis r4, 0
  648. ori r4, r4, HID0_ICE|HID0_ILOCK
  649. andc r3, r3, r4
  650. ori r4, r3, HID0_ICFI
  651. isync
  652. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  653. isync
  654. mtspr HID0, r3 /* clears invalidate */
  655. blr
  656. .globl icache_status
  657. icache_status:
  658. mfspr r3, HID0
  659. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  660. blr
  661. .globl dcache_enable
  662. dcache_enable:
  663. mfspr r3, HID0
  664. ori r3, r3, HID0_DCE
  665. lis r4, 0
  666. ori r4, r4, HID0_DLOCK
  667. andc r3, r3, r4
  668. ori r4, r3, HID0_DCI
  669. sync
  670. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  671. sync
  672. mtspr HID0, r3 /* clears invalidate */
  673. blr
  674. .globl dcache_disable
  675. dcache_disable:
  676. mfspr r3, HID0
  677. lis r4, 0
  678. ori r4, r4, HID0_DCE|HID0_DLOCK
  679. andc r3, r3, r4
  680. ori r4, r3, HID0_DCI
  681. sync
  682. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  683. sync
  684. mtspr HID0, r3 /* clears invalidate */
  685. blr
  686. .globl dcache_status
  687. dcache_status:
  688. mfspr r3, HID0
  689. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  690. blr
  691. .globl get_pvr
  692. get_pvr:
  693. mfspr r3, PVR
  694. blr
  695. /*------------------------------------------------------------------------------*/
  696. /*
  697. * void relocate_code (addr_sp, gd, addr_moni)
  698. *
  699. * This "function" does not return, instead it continues in RAM
  700. * after relocating the monitor code.
  701. *
  702. * r3 = dest
  703. * r4 = src
  704. * r5 = length in bytes
  705. * r6 = cachelinesize
  706. */
  707. .globl relocate_code
  708. relocate_code:
  709. mr r1, r3 /* Set new stack pointer */
  710. mr r9, r4 /* Save copy of Global Data pointer */
  711. mr r10, r5 /* Save copy of Destination Address */
  712. mr r3, r5 /* Destination Address */
  713. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  714. ori r4, r4, CFG_MONITOR_BASE@l
  715. lwz r5, GOT(__init_end)
  716. sub r5, r5, r4
  717. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  718. /*
  719. * Fix GOT pointer:
  720. *
  721. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  722. *
  723. * Offset:
  724. */
  725. sub r15, r10, r4
  726. /* First our own GOT */
  727. add r14, r14, r15
  728. /* then the one used by the C code */
  729. add r30, r30, r15
  730. /*
  731. * Now relocate code
  732. */
  733. cmplw cr1,r3,r4
  734. addi r0,r5,3
  735. srwi. r0,r0,2
  736. beq cr1,4f /* In place copy is not necessary */
  737. beq 7f /* Protect against 0 count */
  738. mtctr r0
  739. bge cr1,2f
  740. la r8,-4(r4)
  741. la r7,-4(r3)
  742. 1: lwzu r0,4(r8)
  743. stwu r0,4(r7)
  744. bdnz 1b
  745. b 4f
  746. 2: slwi r0,r0,2
  747. add r8,r4,r0
  748. add r7,r3,r0
  749. 3: lwzu r0,-4(r8)
  750. stwu r0,-4(r7)
  751. bdnz 3b
  752. /*
  753. * Now flush the cache: note that we must start from a cache aligned
  754. * address. Otherwise we might miss one cache line.
  755. */
  756. 4: cmpwi r6,0
  757. add r5,r3,r5
  758. beq 7f /* Always flush prefetch queue in any case */
  759. subi r0,r6,1
  760. andc r3,r3,r0
  761. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  762. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  763. cmpwi r7,0
  764. beq 9f
  765. mr r4,r3
  766. 5: dcbst 0,r4
  767. add r4,r4,r6
  768. cmplw r4,r5
  769. blt 5b
  770. sync /* Wait for all dcbst to complete on bus */
  771. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  772. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  773. cmpwi r7,0
  774. beq 7f
  775. mr r4,r3
  776. 6: icbi 0,r4
  777. add r4,r4,r6
  778. cmplw r4,r5
  779. blt 6b
  780. 7: sync /* Wait for all icbi to complete on bus */
  781. isync
  782. /*
  783. * We are done. Do not return, instead branch to second part of board
  784. * initialization, now running from RAM.
  785. */
  786. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  787. mtlr r0
  788. blr
  789. in_ram:
  790. /*
  791. * Relocation Function, r14 point to got2+0x8000
  792. *
  793. * Adjust got2 pointers, no need to check for 0, this code
  794. * already puts a few entries in the table.
  795. */
  796. li r0,__got2_entries@sectoff@l
  797. la r3,GOT(_GOT2_TABLE_)
  798. lwz r11,GOT(_GOT2_TABLE_)
  799. mtctr r0
  800. sub r11,r3,r11
  801. addi r3,r3,-4
  802. 1: lwzu r0,4(r3)
  803. add r0,r0,r11
  804. stw r0,0(r3)
  805. bdnz 1b
  806. /*
  807. * Now adjust the fixups and the pointers to the fixups
  808. * in case we need to move ourselves again.
  809. */
  810. 2: li r0,__fixup_entries@sectoff@l
  811. lwz r3,GOT(_FIXUP_TABLE_)
  812. cmpwi r0,0
  813. mtctr r0
  814. addi r3,r3,-4
  815. beq 4f
  816. 3: lwzu r4,4(r3)
  817. lwzux r0,r4,r11
  818. add r0,r0,r11
  819. stw r10,0(r3)
  820. stw r0,0(r4)
  821. bdnz 3b
  822. 4:
  823. clear_bss:
  824. /*
  825. * Now clear BSS segment
  826. */
  827. lwz r3,GOT(__bss_start)
  828. #if defined(CONFIG_HYMOD)
  829. /*
  830. * For HYMOD - the environment is the very last item in flash.
  831. * The real .bss stops just before environment starts, so only
  832. * clear up to that point.
  833. *
  834. * taken from mods for FADS board
  835. */
  836. lwz r4,GOT(environment)
  837. #else
  838. lwz r4,GOT(_end)
  839. #endif
  840. cmplw 0, r3, r4
  841. beq 6f
  842. li r0, 0
  843. 5:
  844. stw r0, 0(r3)
  845. addi r3, r3, 4
  846. cmplw 0, r3, r4
  847. bne 5b
  848. 6:
  849. mr r3, r9 /* Global Data pointer */
  850. mr r4, r10 /* Destination Address */
  851. bl board_init_r
  852. /*
  853. * Copy exception vector code to low memory
  854. *
  855. * r3: dest_addr
  856. * r7: source address, r8: end address, r9: target address
  857. */
  858. .globl trap_init
  859. trap_init:
  860. lwz r7, GOT(_start)
  861. lwz r8, GOT(_end_of_vectors)
  862. li r9, 0x100 /* reset vector always at 0x100 */
  863. cmplw 0, r7, r8
  864. bgelr /* return if r7>=r8 - just in case */
  865. mflr r4 /* save link register */
  866. 1:
  867. lwz r0, 0(r7)
  868. stw r0, 0(r9)
  869. addi r7, r7, 4
  870. addi r9, r9, 4
  871. cmplw 0, r7, r8
  872. bne 1b
  873. /*
  874. * relocate `hdlr' and `int_return' entries
  875. */
  876. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  877. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  878. 2:
  879. bl trap_reloc
  880. addi r7, r7, 0x100 /* next exception vector */
  881. cmplw 0, r7, r8
  882. blt 2b
  883. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  884. bl trap_reloc
  885. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  886. bl trap_reloc
  887. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  888. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  889. 3:
  890. bl trap_reloc
  891. addi r7, r7, 0x100 /* next exception vector */
  892. cmplw 0, r7, r8
  893. blt 3b
  894. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  895. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  896. 4:
  897. bl trap_reloc
  898. addi r7, r7, 0x100 /* next exception vector */
  899. cmplw 0, r7, r8
  900. blt 4b
  901. mfmsr r3 /* now that the vectors have */
  902. lis r7, MSR_IP@h /* relocated into low memory */
  903. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  904. andc r3, r3, r7 /* (if it was on) */
  905. SYNC /* Some chip revs need this... */
  906. mtmsr r3
  907. SYNC
  908. mtlr r4 /* restore link register */
  909. blr
  910. /*
  911. * Function: relocate entries for one exception vector
  912. */
  913. trap_reloc:
  914. lwz r0, 0(r7) /* hdlr ... */
  915. add r0, r0, r3 /* ... += dest_addr */
  916. stw r0, 0(r7)
  917. lwz r0, 4(r7) /* int_return ... */
  918. add r0, r0, r3 /* ... += dest_addr */
  919. stw r0, 4(r7)
  920. blr