start.S 26 KB

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