start.S 28 KB

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