start.S 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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)
  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 r12,0xd00-4*3 /* save LR & SRRx */
  282. mflr r0
  283. stw r0,0(r12)
  284. mfspr r0,SRR0
  285. stw r0,4(r12)
  286. mfspr r0,SRR1
  287. stw r0,8(r12)
  288. li r12,0xc00+_back-SystemCall
  289. mtlr r12
  290. mtspr SRR0,r11
  291. 1: SYNC
  292. rfi
  293. _back:
  294. mfmsr r11 /* Disable interrupts */
  295. li r12,0
  296. ori r12,r12,MSR_EE
  297. andc r11,r11,r12
  298. SYNC /* Some chip revs need this... */
  299. mtmsr r11
  300. SYNC
  301. li r12,0xd00-4*3 /* restore regs */
  302. lwz r11,0(r12)
  303. mtlr r11
  304. lwz r11,4(r12)
  305. mtspr SRR0,r11
  306. lwz r11,8(r12)
  307. mtspr SRR1,r11
  308. SYNC
  309. rfi
  310. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  311. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  312. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  313. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  314. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  315. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  316. #ifdef DEBUG
  317. . = 0x1300
  318. /*
  319. * This exception occurs when the program counter matches the
  320. * Instruction Address Breakpoint Register (IABR).
  321. *
  322. * I want the cpu to halt if this occurs so I can hunt around
  323. * with the debugger and look at things.
  324. *
  325. * When DEBUG is defined, both machine check enable (in the MSR)
  326. * and checkstop reset enable (in the reset mode register) are
  327. * turned off and so a checkstop condition will result in the cpu
  328. * halting.
  329. *
  330. * I force the cpu into a checkstop condition by putting an illegal
  331. * instruction here (at least this is the theory).
  332. *
  333. * well - that didnt work, so just do an infinite loop!
  334. */
  335. 1: b 1b
  336. #else
  337. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  338. #endif
  339. STD_EXCEPTION(0x1400, SMI, UnknownException)
  340. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  341. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  342. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  343. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  344. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  345. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  346. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  347. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  348. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  349. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  350. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  351. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  352. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  353. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  354. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  355. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  356. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  357. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  358. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  359. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  360. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  361. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  362. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  363. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  364. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  365. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  366. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  367. .globl _end_of_vectors
  368. _end_of_vectors:
  369. . = 0x3000
  370. /*
  371. * This code finishes saving the registers to the exception frame
  372. * and jumps to the appropriate handler for the exception.
  373. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  374. */
  375. .globl transfer_to_handler
  376. transfer_to_handler:
  377. stw r22,_NIP(r21)
  378. lis r22,MSR_POW@h
  379. andc r23,r23,r22
  380. stw r23,_MSR(r21)
  381. SAVE_GPR(7, r21)
  382. SAVE_4GPRS(8, r21)
  383. SAVE_8GPRS(12, r21)
  384. SAVE_8GPRS(24, r21)
  385. mflr r23
  386. andi. r24,r23,0x3f00 /* get vector offset */
  387. stw r24,TRAP(r21)
  388. li r22,0
  389. stw r22,RESULT(r21)
  390. lwz r24,0(r23) /* virtual address of handler */
  391. lwz r23,4(r23) /* where to go when done */
  392. mtspr SRR0,r24
  393. mtspr SRR1,r20
  394. mtlr r23
  395. SYNC
  396. rfi /* jump to handler, enable MMU */
  397. int_return:
  398. mfmsr r28 /* Disable interrupts */
  399. li r4,0
  400. ori r4,r4,MSR_EE
  401. andc r28,r28,r4
  402. SYNC /* Some chip revs need this... */
  403. mtmsr r28
  404. SYNC
  405. lwz r2,_CTR(r1)
  406. lwz r0,_LINK(r1)
  407. mtctr r2
  408. mtlr r0
  409. lwz r2,_XER(r1)
  410. lwz r0,_CCR(r1)
  411. mtspr XER,r2
  412. mtcrf 0xFF,r0
  413. REST_10GPRS(3, r1)
  414. REST_10GPRS(13, r1)
  415. REST_8GPRS(23, r1)
  416. REST_GPR(31, r1)
  417. lwz r2,_NIP(r1) /* Restore environment */
  418. lwz r0,_MSR(r1)
  419. mtspr SRR0,r2
  420. mtspr SRR1,r0
  421. lwz r0,GPR0(r1)
  422. lwz r2,GPR2(r1)
  423. lwz r1,GPR1(r1)
  424. SYNC
  425. rfi
  426. #if defined(CONFIG_COGENT)
  427. /*
  428. * This code initialises the MPC8260 processor core
  429. * (conforms to PowerPC 603e spec)
  430. */
  431. .globl cogent_init_8260
  432. cogent_init_8260:
  433. /* Taken from page 14 of CMA282 manual */
  434. /*--------------------------------------------------------------*/
  435. lis r4, (CFG_IMMR+IM_REGBASE)@h
  436. lis r3, CFG_IMMR@h
  437. stw r3, IM_IMMR@l(r4)
  438. lwz r3, IM_IMMR@l(r4)
  439. stw r3, 0(r0)
  440. lis r3, CFG_SYPCR@h
  441. ori r3, r3, CFG_SYPCR@l
  442. stw r3, IM_SYPCR@l(r4)
  443. lwz r3, IM_SYPCR@l(r4)
  444. stw r3, 4(r0)
  445. lis r3, CFG_SCCR@h
  446. ori r3, r3, CFG_SCCR@l
  447. stw r3, IM_SCCR@l(r4)
  448. lwz r3, IM_SCCR@l(r4)
  449. stw r3, 8(r0)
  450. /* the rest of this was disassembled from the */
  451. /* EPROM code that came with my CMA282 CPU module */
  452. /*--------------------------------------------------------------*/
  453. lis r1, 0x1234
  454. ori r1, r1, 0x5678
  455. stw r1, 0x20(r0)
  456. lwz r1, 0x20(r0)
  457. stw r1, 0x24(r0)
  458. lwz r1, 0x24(r0)
  459. lis r3, 0x0e80
  460. ori r3, r3, 0
  461. stw r1, 4(r3)
  462. lwz r1, 4(r3)
  463. /* Done! */
  464. /*--------------------------------------------------------------*/
  465. blr
  466. #endif /* CONFIG_COGENT */
  467. /*
  468. * This code initialises the MPC8260 processor core
  469. * (conforms to PowerPC 603e spec)
  470. * Note: expects original MSR contents to be in r5.
  471. */
  472. .globl init_8260_core
  473. init_8260_core:
  474. /* Initialize machine status; enable machine check interrupt */
  475. /*--------------------------------------------------------------*/
  476. li r3, MSR_KERNEL /* Set ME and RI flags */
  477. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  478. #ifdef DEBUG
  479. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  480. #endif
  481. SYNC /* Some chip revs need this... */
  482. mtmsr r3
  483. SYNC
  484. mtspr SRR1, r3 /* Make SRR1 match MSR */
  485. /* Initialise the SYPCR early, and reset the watchdog (if req) */
  486. /*--------------------------------------------------------------*/
  487. lis r3, (CFG_IMMR+IM_REGBASE)@h
  488. #if !defined(CONFIG_COGENT)
  489. lis r4, CFG_SYPCR@h
  490. ori r4, r4, CFG_SYPCR@l
  491. stw r4, IM_SYPCR@l(r3)
  492. #endif /* !CONFIG_COGENT */
  493. #if defined(CONFIG_WATCHDOG)
  494. li r4, 21868 /* = 0x556c */
  495. sth r4, IM_SWSR@l(r3)
  496. li r4, -21959 /* = 0xaa39 */
  497. sth r4, IM_SWSR@l(r3)
  498. #endif /* CONFIG_WATCHDOG */
  499. /* Initialize the Hardware Implementation-dependent Registers */
  500. /* HID0 also contains cache control */
  501. /*--------------------------------------------------------------*/
  502. lis r3, CFG_HID0_INIT@h
  503. ori r3, r3, CFG_HID0_INIT@l
  504. SYNC
  505. mtspr HID0, r3
  506. lis r3, CFG_HID0_FINAL@h
  507. ori r3, r3, CFG_HID0_FINAL@l
  508. SYNC
  509. mtspr HID0, r3
  510. lis r3, CFG_HID2@h
  511. ori r3, r3, CFG_HID2@l
  512. mtspr HID2, r3
  513. /* clear all BAT's */
  514. /*--------------------------------------------------------------*/
  515. li r0, 0
  516. mtspr DBAT0U, r0
  517. mtspr DBAT0L, r0
  518. mtspr DBAT1U, r0
  519. mtspr DBAT1L, r0
  520. mtspr DBAT2U, r0
  521. mtspr DBAT2L, r0
  522. mtspr DBAT3U, r0
  523. mtspr DBAT3L, r0
  524. mtspr IBAT0U, r0
  525. mtspr IBAT0L, r0
  526. mtspr IBAT1U, r0
  527. mtspr IBAT1L, r0
  528. mtspr IBAT2U, r0
  529. mtspr IBAT2L, r0
  530. mtspr IBAT3U, r0
  531. mtspr IBAT3L, r0
  532. SYNC
  533. /* invalidate all tlb's */
  534. /* */
  535. /* From the 603e User Manual: "The 603e provides the ability to */
  536. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  537. /* instruction invalidates the TLB entry indexed by the EA, and */
  538. /* operates on both the instruction and data TLBs simultaneously*/
  539. /* invalidating four TLB entries (both sets in each TLB). The */
  540. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  541. /* entries within both TLBs, 32 tlbie instructions should be */
  542. /* issued, incrementing this field by one each time." */
  543. /* */
  544. /* "Note that the tlbia instruction is not implemented on the */
  545. /* 603e." */
  546. /* */
  547. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  548. /* incrementing by 0x1000 each time. The code below is sort of */
  549. /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
  550. /* */
  551. /*--------------------------------------------------------------*/
  552. li r3, 32
  553. mtctr r3
  554. li r3, 0
  555. 1: tlbie r3
  556. addi r3, r3, 0x1000
  557. bdnz 1b
  558. SYNC
  559. /* Done! */
  560. /*--------------------------------------------------------------*/
  561. blr
  562. #ifdef DEBUG
  563. /*
  564. * initialise things related to debugging.
  565. *
  566. * must be called after the global offset table (GOT) is initialised
  567. * (GET_GOT) and after cpu_init_f() has executed.
  568. */
  569. .globl init_debug
  570. init_debug:
  571. lis r3, (CFG_IMMR+IM_REGBASE)@h
  572. /* Quick and dirty hack to enable the RAM and copy the */
  573. /* vectors so that we can take exceptions. */
  574. /*--------------------------------------------------------------*/
  575. /* write Memory Refresh Prescaler */
  576. li r4, CFG_MPTPR
  577. sth r4, IM_MPTPR@l(r3)
  578. /* write 60x Refresh Timer */
  579. li r4, CFG_PSRT
  580. stb r4, IM_PSRT@l(r3)
  581. /* init the 60x SDRAM Mode Register */
  582. lis r4, (CFG_PSDMR|PSDMR_OP_NORM)@h
  583. ori r4, r4, (CFG_PSDMR|PSDMR_OP_NORM)@l
  584. stw r4, IM_PSDMR@l(r3)
  585. /* write Precharge All Banks command */
  586. lis r4, (CFG_PSDMR|PSDMR_OP_PREA)@h
  587. ori r4, r4, (CFG_PSDMR|PSDMR_OP_PREA)@l
  588. stw r4, IM_PSDMR@l(r3)
  589. stb r0, 0(0)
  590. /* write eight CBR Refresh commands */
  591. lis r4, (CFG_PSDMR|PSDMR_OP_CBRR)@h
  592. ori r4, r4, (CFG_PSDMR|PSDMR_OP_CBRR)@l
  593. stw r4, IM_PSDMR@l(r3)
  594. stb r0, 0(0)
  595. stb r0, 0(0)
  596. stb r0, 0(0)
  597. stb r0, 0(0)
  598. stb r0, 0(0)
  599. stb r0, 0(0)
  600. stb r0, 0(0)
  601. stb r0, 0(0)
  602. /* write Mode Register Write command */
  603. lis r4, (CFG_PSDMR|PSDMR_OP_MRW)@h
  604. ori r4, r4, (CFG_PSDMR|PSDMR_OP_MRW)@l
  605. stw r4, IM_PSDMR@l(r3)
  606. stb r0, 0(0)
  607. /* write Normal Operation command and enable Refresh */
  608. lis r4, (CFG_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@h
  609. ori r4, r4, (CFG_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@l
  610. stw r4, IM_PSDMR@l(r3)
  611. stb r0, 0(0)
  612. /* RAM should now be operational */
  613. #define VEC_WRD_CNT ((_end_of_vectors - _start + EXC_OFF_SYS_RESET) / 4)
  614. lwz r3, GOT(_end_of_vectors)
  615. rlwinm r4, r3, 0, 18, 31 /* _end_of_vectors & 0x3FFF */
  616. lis r5, VEC_WRD_CNT@h
  617. ori r5, r5, VEC_WRD_CNT@l
  618. mtctr r5
  619. 1:
  620. lwzu r5, -4(r3)
  621. stwu r5, -4(r4)
  622. bdnz 1b
  623. /* Load the Instruction Address Breakpoint Register (IABR). */
  624. /* */
  625. /* The address to load is stored in the first word of dual port */
  626. /* ram and should be preserved while the power is on, so you */
  627. /* can plug addresses into that location then reset the cpu and */
  628. /* this code will load that address into the IABR after the */
  629. /* reset. */
  630. /* */
  631. /* When the program counter matches the contents of the IABR, */
  632. /* an exception is generated (before the instruction at that */
  633. /* location completes). The vector for this exception is 0x1300 */
  634. /*--------------------------------------------------------------*/
  635. lis r3, CFG_IMMR@h
  636. lwz r3, 0(r3)
  637. mtspr IABR, r3
  638. /* Set the entire dual port RAM (where the initial stack */
  639. /* resides) to a known value - makes it easier to see where */
  640. /* the stack has been written */
  641. /*--------------------------------------------------------------*/
  642. lis r3, (CFG_IMMR + CFG_INIT_SP_OFFSET)@h
  643. ori r3, r3, (CFG_IMMR + CFG_INIT_SP_OFFSET)@l
  644. li r4, ((CFG_INIT_SP_OFFSET - 4) / 4)
  645. mtctr r4
  646. lis r4, 0xdeadbeaf@h
  647. ori r4, r4, 0xdeadbeaf@l
  648. 1:
  649. stwu r4, -4(r3)
  650. bdnz 1b
  651. /* Done! */
  652. /*--------------------------------------------------------------*/
  653. blr
  654. #endif
  655. /* Cache functions.
  656. *
  657. * Note: requires that all cache bits in
  658. * HID0 are in the low half word.
  659. */
  660. .globl icache_enable
  661. icache_enable:
  662. mfspr r3, HID0
  663. ori r3, r3, HID0_ICE
  664. lis r4, 0
  665. ori r4, r4, HID0_ILOCK
  666. andc r3, r3, r4
  667. ori r4, r3, HID0_ICFI
  668. isync
  669. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  670. isync
  671. mtspr HID0, r3 /* clears invalidate */
  672. blr
  673. .globl icache_disable
  674. icache_disable:
  675. mfspr r3, HID0
  676. lis r4, 0
  677. ori r4, r4, HID0_ICE|HID0_ILOCK
  678. andc r3, r3, r4
  679. ori r4, r3, HID0_ICFI
  680. isync
  681. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  682. isync
  683. mtspr HID0, r3 /* clears invalidate */
  684. blr
  685. .globl icache_status
  686. icache_status:
  687. mfspr r3, HID0
  688. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  689. blr
  690. .globl dcache_enable
  691. dcache_enable:
  692. mfspr r3, HID0
  693. ori r3, r3, HID0_DCE
  694. lis r4, 0
  695. ori r4, r4, HID0_DLOCK
  696. andc r3, r3, r4
  697. ori r4, r3, HID0_DCI
  698. sync
  699. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  700. sync
  701. mtspr HID0, r3 /* clears invalidate */
  702. blr
  703. .globl dcache_disable
  704. dcache_disable:
  705. mfspr r3, HID0
  706. lis r4, 0
  707. ori r4, r4, HID0_DCE|HID0_DLOCK
  708. andc r3, r3, r4
  709. ori r4, r3, HID0_DCI
  710. sync
  711. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  712. sync
  713. mtspr HID0, r3 /* clears invalidate */
  714. blr
  715. .globl dcache_status
  716. dcache_status:
  717. mfspr r3, HID0
  718. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  719. blr
  720. .globl get_pvr
  721. get_pvr:
  722. mfspr r3, PVR
  723. blr
  724. /*------------------------------------------------------------------------------*/
  725. /*
  726. * void relocate_code (addr_sp, gd, addr_moni)
  727. *
  728. * This "function" does not return, instead it continues in RAM
  729. * after relocating the monitor code.
  730. *
  731. * r3 = dest
  732. * r4 = src
  733. * r5 = length in bytes
  734. * r6 = cachelinesize
  735. */
  736. .globl relocate_code
  737. relocate_code:
  738. mr r1, r3 /* Set new stack pointer */
  739. mr r9, r4 /* Save copy of Global Data pointer */
  740. mr r10, r5 /* Save copy of Destination Address */
  741. mr r3, r5 /* Destination Address */
  742. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  743. ori r4, r4, CFG_MONITOR_BASE@l
  744. lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
  745. ori r5, r5, CFG_MONITOR_LEN@l
  746. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  747. /*
  748. * Fix GOT pointer:
  749. *
  750. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  751. *
  752. * Offset:
  753. */
  754. sub r15, r10, r4
  755. /* First our own GOT */
  756. add r14, r14, r15
  757. /* then the one used by the C code */
  758. add r30, r30, r15
  759. /*
  760. * Now relocate code
  761. */
  762. cmplw cr1,r3,r4
  763. addi r0,r5,3
  764. srwi. r0,r0,2
  765. beq cr1,4f /* In place copy is not necessary */
  766. beq 7f /* Protect against 0 count */
  767. mtctr r0
  768. bge cr1,2f
  769. la r8,-4(r4)
  770. la r7,-4(r3)
  771. 1: lwzu r0,4(r8)
  772. stwu r0,4(r7)
  773. bdnz 1b
  774. b 4f
  775. 2: slwi r0,r0,2
  776. add r8,r4,r0
  777. add r7,r3,r0
  778. 3: lwzu r0,-4(r8)
  779. stwu r0,-4(r7)
  780. bdnz 3b
  781. /*
  782. * Now flush the cache: note that we must start from a cache aligned
  783. * address. Otherwise we might miss one cache line.
  784. */
  785. 4: cmpwi r6,0
  786. add r5,r3,r5
  787. beq 7f /* Always flush prefetch queue in any case */
  788. subi r0,r6,1
  789. andc r3,r3,r0
  790. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  791. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  792. cmpwi r7,0
  793. beq 9f
  794. mr r4,r3
  795. 5: dcbst 0,r4
  796. add r4,r4,r6
  797. cmplw r4,r5
  798. blt 5b
  799. sync /* Wait for all dcbst to complete on bus */
  800. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  801. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  802. cmpwi r7,0
  803. beq 7f
  804. mr r4,r3
  805. 6: icbi 0,r4
  806. add r4,r4,r6
  807. cmplw r4,r5
  808. blt 6b
  809. 7: sync /* Wait for all icbi to complete on bus */
  810. isync
  811. /*
  812. * We are done. Do not return, instead branch to second part of board
  813. * initialization, now running from RAM.
  814. */
  815. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  816. mtlr r0
  817. blr
  818. in_ram:
  819. /*
  820. * Relocation Function, r14 point to got2+0x8000
  821. *
  822. * Adjust got2 pointers, no need to check for 0, this code
  823. * already puts a few entries in the table.
  824. */
  825. li r0,__got2_entries@sectoff@l
  826. la r3,GOT(_GOT2_TABLE_)
  827. lwz r11,GOT(_GOT2_TABLE_)
  828. mtctr r0
  829. sub r11,r3,r11
  830. addi r3,r3,-4
  831. 1: lwzu r0,4(r3)
  832. add r0,r0,r11
  833. stw r0,0(r3)
  834. bdnz 1b
  835. /*
  836. * Now adjust the fixups and the pointers to the fixups
  837. * in case we need to move ourselves again.
  838. */
  839. 2: li r0,__fixup_entries@sectoff@l
  840. lwz r3,GOT(_FIXUP_TABLE_)
  841. cmpwi r0,0
  842. mtctr r0
  843. addi r3,r3,-4
  844. beq 4f
  845. 3: lwzu r4,4(r3)
  846. lwzux r0,r4,r11
  847. add r0,r0,r11
  848. stw r10,0(r3)
  849. stw r0,0(r4)
  850. bdnz 3b
  851. 4:
  852. clear_bss:
  853. /*
  854. * Now clear BSS segment
  855. */
  856. lwz r3,GOT(.bss)
  857. #if defined(CONFIG_HYMOD)
  858. /*
  859. * For HYMOD - the environment is the very last item in flash.
  860. * The real .bss stops just before environment starts, so only
  861. * clear up to that point.
  862. *
  863. * taken from mods for FADS board
  864. */
  865. lwz r4,GOT(environment)
  866. #else
  867. lwz r4,GOT(_end)
  868. #endif
  869. cmplw 0, r3, r4
  870. beq 6f
  871. li r0, 0
  872. 5:
  873. stw r0, 0(r3)
  874. addi r3, r3, 4
  875. cmplw 0, r3, r4
  876. bne 5b
  877. 6:
  878. mr r3, r9 /* Global Data pointer */
  879. mr r4, r10 /* Destination Address */
  880. bl board_init_r
  881. /* Problems accessing "end" in C, so do it here */
  882. .globl get_endaddr
  883. get_endaddr:
  884. lwz r3,GOT(_end)
  885. blr
  886. /*
  887. * Copy exception vector code to low memory
  888. *
  889. * r3: dest_addr
  890. * r7: source address, r8: end address, r9: target address
  891. */
  892. .globl trap_init
  893. trap_init:
  894. lwz r7, GOT(_start)
  895. lwz r8, GOT(_end_of_vectors)
  896. rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */
  897. cmplw 0, r7, r8
  898. bgelr /* return if r7>=r8 - just in case */
  899. mflr r4 /* save link register */
  900. 1:
  901. lwz r0, 0(r7)
  902. stw r0, 0(r9)
  903. addi r7, r7, 4
  904. addi r9, r9, 4
  905. cmplw 0, r7, r8
  906. bne 1b
  907. /*
  908. * relocate `hdlr' and `int_return' entries
  909. */
  910. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  911. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  912. 2:
  913. bl trap_reloc
  914. addi r7, r7, 0x100 /* next exception vector */
  915. cmplw 0, r7, r8
  916. blt 2b
  917. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  918. bl trap_reloc
  919. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  920. bl trap_reloc
  921. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  922. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  923. 3:
  924. bl trap_reloc
  925. addi r7, r7, 0x100 /* next exception vector */
  926. cmplw 0, r7, r8
  927. blt 3b
  928. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  929. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  930. 4:
  931. bl trap_reloc
  932. addi r7, r7, 0x100 /* next exception vector */
  933. cmplw 0, r7, r8
  934. blt 4b
  935. mfmsr r3 /* now that the vectors have */
  936. lis r7, MSR_IP@h /* relocated into low memory */
  937. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  938. andc r3, r3, r7 /* (if it was on) */
  939. SYNC /* Some chip revs need this... */
  940. mtmsr r3
  941. SYNC
  942. mtlr r4 /* restore link register */
  943. blr
  944. /*
  945. * Function: relocate entries for one exception vector
  946. */
  947. trap_reloc:
  948. lwz r0, 0(r7) /* hdlr ... */
  949. add r0, r0, r3 /* ... += dest_addr */
  950. stw r0, 0(r7)
  951. lwz r0, 4(r7) /* int_return ... */
  952. add r0, r0, r3 /* ... += dest_addr */
  953. stw r0, 4(r7)
  954. blr