misc.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /*
  2. * This file contains miscellaneous low-level functions.
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  6. * and Paul Mackerras.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. *
  13. */
  14. #include <linux/config.h>
  15. #include <linux/sys.h>
  16. #include <asm/unistd.h>
  17. #include <asm/errno.h>
  18. #include <asm/processor.h>
  19. #include <asm/page.h>
  20. #include <asm/cache.h>
  21. #include <asm/cputable.h>
  22. #include <asm/mmu.h>
  23. #include <asm/ppc_asm.h>
  24. #include <asm/thread_info.h>
  25. #include <asm/asm-offsets.h>
  26. #ifdef CONFIG_8xx
  27. #define ISYNC_8xx isync
  28. #else
  29. #define ISYNC_8xx
  30. #endif
  31. .text
  32. .align 5
  33. _GLOBAL(__delay)
  34. cmpwi 0,r3,0
  35. mtctr r3
  36. beqlr
  37. 1: bdnz 1b
  38. blr
  39. /*
  40. * Returns (address we're running at) - (address we were linked at)
  41. * for use before the text and data are mapped to KERNELBASE.
  42. */
  43. _GLOBAL(reloc_offset)
  44. mflr r0
  45. bl 1f
  46. 1: mflr r3
  47. lis r4,1b@ha
  48. addi r4,r4,1b@l
  49. subf r3,r4,r3
  50. mtlr r0
  51. blr
  52. /*
  53. * add_reloc_offset(x) returns x + reloc_offset().
  54. */
  55. _GLOBAL(add_reloc_offset)
  56. mflr r0
  57. bl 1f
  58. 1: mflr r5
  59. lis r4,1b@ha
  60. addi r4,r4,1b@l
  61. subf r5,r4,r5
  62. add r3,r3,r5
  63. mtlr r0
  64. blr
  65. /*
  66. * sub_reloc_offset(x) returns x - reloc_offset().
  67. */
  68. _GLOBAL(sub_reloc_offset)
  69. mflr r0
  70. bl 1f
  71. 1: mflr r5
  72. lis r4,1b@ha
  73. addi r4,r4,1b@l
  74. subf r5,r4,r5
  75. subf r3,r5,r3
  76. mtlr r0
  77. blr
  78. /*
  79. * reloc_got2 runs through the .got2 section adding an offset
  80. * to each entry.
  81. */
  82. _GLOBAL(reloc_got2)
  83. mflr r11
  84. lis r7,__got2_start@ha
  85. addi r7,r7,__got2_start@l
  86. lis r8,__got2_end@ha
  87. addi r8,r8,__got2_end@l
  88. subf r8,r7,r8
  89. srwi. r8,r8,2
  90. beqlr
  91. mtctr r8
  92. bl 1f
  93. 1: mflr r0
  94. lis r4,1b@ha
  95. addi r4,r4,1b@l
  96. subf r0,r4,r0
  97. add r7,r0,r7
  98. 2: lwz r0,0(r7)
  99. add r0,r0,r3
  100. stw r0,0(r7)
  101. addi r7,r7,4
  102. bdnz 2b
  103. mtlr r11
  104. blr
  105. /*
  106. * identify_cpu,
  107. * called with r3 = data offset and r4 = CPU number
  108. * doesn't change r3
  109. */
  110. _GLOBAL(identify_cpu)
  111. addis r8,r3,cpu_specs@ha
  112. addi r8,r8,cpu_specs@l
  113. mfpvr r7
  114. 1:
  115. lwz r5,CPU_SPEC_PVR_MASK(r8)
  116. and r5,r5,r7
  117. lwz r6,CPU_SPEC_PVR_VALUE(r8)
  118. cmplw 0,r6,r5
  119. beq 1f
  120. addi r8,r8,CPU_SPEC_ENTRY_SIZE
  121. b 1b
  122. 1:
  123. addis r6,r3,cur_cpu_spec@ha
  124. addi r6,r6,cur_cpu_spec@l
  125. sub r8,r8,r3
  126. stw r8,0(r6)
  127. blr
  128. /*
  129. * do_cpu_ftr_fixups - goes through the list of CPU feature fixups
  130. * and writes nop's over sections of code that don't apply for this cpu.
  131. * r3 = data offset (not changed)
  132. */
  133. _GLOBAL(do_cpu_ftr_fixups)
  134. /* Get CPU 0 features */
  135. addis r6,r3,cur_cpu_spec@ha
  136. addi r6,r6,cur_cpu_spec@l
  137. lwz r4,0(r6)
  138. add r4,r4,r3
  139. lwz r4,CPU_SPEC_FEATURES(r4)
  140. /* Get the fixup table */
  141. addis r6,r3,__start___ftr_fixup@ha
  142. addi r6,r6,__start___ftr_fixup@l
  143. addis r7,r3,__stop___ftr_fixup@ha
  144. addi r7,r7,__stop___ftr_fixup@l
  145. /* Do the fixup */
  146. 1: cmplw 0,r6,r7
  147. bgelr
  148. addi r6,r6,16
  149. lwz r8,-16(r6) /* mask */
  150. and r8,r8,r4
  151. lwz r9,-12(r6) /* value */
  152. cmplw 0,r8,r9
  153. beq 1b
  154. lwz r8,-8(r6) /* section begin */
  155. lwz r9,-4(r6) /* section end */
  156. subf. r9,r8,r9
  157. beq 1b
  158. /* write nops over the section of code */
  159. /* todo: if large section, add a branch at the start of it */
  160. srwi r9,r9,2
  161. mtctr r9
  162. add r8,r8,r3
  163. lis r0,0x60000000@h /* nop */
  164. 3: stw r0,0(r8)
  165. andi. r10,r4,CPU_FTR_SPLIT_ID_CACHE@l
  166. beq 2f
  167. dcbst 0,r8 /* suboptimal, but simpler */
  168. sync
  169. icbi 0,r8
  170. 2: addi r8,r8,4
  171. bdnz 3b
  172. sync /* additional sync needed on g4 */
  173. isync
  174. b 1b
  175. /*
  176. * call_setup_cpu - call the setup_cpu function for this cpu
  177. * r3 = data offset, r24 = cpu number
  178. *
  179. * Setup function is called with:
  180. * r3 = data offset
  181. * r4 = ptr to CPU spec (relocated)
  182. */
  183. _GLOBAL(call_setup_cpu)
  184. addis r4,r3,cur_cpu_spec@ha
  185. addi r4,r4,cur_cpu_spec@l
  186. lwz r4,0(r4)
  187. add r4,r4,r3
  188. lwz r5,CPU_SPEC_SETUP(r4)
  189. cmpi 0,r5,0
  190. add r5,r5,r3
  191. beqlr
  192. mtctr r5
  193. bctr
  194. /*
  195. * complement mask on the msr then "or" some values on.
  196. * _nmask_and_or_msr(nmask, value_to_or)
  197. */
  198. _GLOBAL(_nmask_and_or_msr)
  199. mfmsr r0 /* Get current msr */
  200. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  201. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  202. SYNC /* Some chip revs have problems here... */
  203. mtmsr r0 /* Update machine state */
  204. isync
  205. blr /* Done */
  206. /*
  207. * Flush MMU TLB
  208. */
  209. _GLOBAL(_tlbia)
  210. #if defined(CONFIG_40x)
  211. sync /* Flush to memory before changing mapping */
  212. tlbia
  213. isync /* Flush shadow TLB */
  214. #elif defined(CONFIG_44x)
  215. li r3,0
  216. sync
  217. /* Load high watermark */
  218. lis r4,tlb_44x_hwater@ha
  219. lwz r5,tlb_44x_hwater@l(r4)
  220. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  221. addi r3,r3,1
  222. cmpw 0,r3,r5
  223. ble 1b
  224. isync
  225. #elif defined(CONFIG_FSL_BOOKE)
  226. /* Invalidate all entries in TLB0 */
  227. li r3, 0x04
  228. tlbivax 0,3
  229. /* Invalidate all entries in TLB1 */
  230. li r3, 0x0c
  231. tlbivax 0,3
  232. /* Invalidate all entries in TLB2 */
  233. li r3, 0x14
  234. tlbivax 0,3
  235. /* Invalidate all entries in TLB3 */
  236. li r3, 0x1c
  237. tlbivax 0,3
  238. msync
  239. #ifdef CONFIG_SMP
  240. tlbsync
  241. #endif /* CONFIG_SMP */
  242. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  243. #if defined(CONFIG_SMP)
  244. rlwinm r8,r1,0,0,18
  245. lwz r8,TI_CPU(r8)
  246. oris r8,r8,10
  247. mfmsr r10
  248. SYNC
  249. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  250. rlwinm r0,r0,0,28,26 /* clear DR */
  251. mtmsr r0
  252. SYNC_601
  253. isync
  254. lis r9,mmu_hash_lock@h
  255. ori r9,r9,mmu_hash_lock@l
  256. tophys(r9,r9)
  257. 10: lwarx r7,0,r9
  258. cmpwi 0,r7,0
  259. bne- 10b
  260. stwcx. r8,0,r9
  261. bne- 10b
  262. sync
  263. tlbia
  264. sync
  265. TLBSYNC
  266. li r0,0
  267. stw r0,0(r9) /* clear mmu_hash_lock */
  268. mtmsr r10
  269. SYNC_601
  270. isync
  271. #else /* CONFIG_SMP */
  272. sync
  273. tlbia
  274. sync
  275. #endif /* CONFIG_SMP */
  276. #endif /* ! defined(CONFIG_40x) */
  277. blr
  278. /*
  279. * Flush MMU TLB for a particular address
  280. */
  281. _GLOBAL(_tlbie)
  282. #if defined(CONFIG_40x)
  283. tlbsx. r3, 0, r3
  284. bne 10f
  285. sync
  286. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  287. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  288. * the TLB entry. */
  289. tlbwe r3, r3, TLB_TAG
  290. isync
  291. 10:
  292. #elif defined(CONFIG_44x)
  293. mfspr r4,SPRN_MMUCR
  294. mfspr r5,SPRN_PID /* Get PID */
  295. rlwimi r4,r5,0,24,31 /* Set TID */
  296. mtspr SPRN_MMUCR,r4
  297. tlbsx. r3, 0, r3
  298. bne 10f
  299. sync
  300. /* There are only 64 TLB entries, so r3 < 64,
  301. * which means bit 22, is clear. Since 22 is
  302. * the V bit in the TLB_PAGEID, loading this
  303. * value will invalidate the TLB entry.
  304. */
  305. tlbwe r3, r3, PPC44x_TLB_PAGEID
  306. isync
  307. 10:
  308. #elif defined(CONFIG_FSL_BOOKE)
  309. rlwinm r4, r3, 0, 0, 19
  310. ori r5, r4, 0x08 /* TLBSEL = 1 */
  311. ori r6, r4, 0x10 /* TLBSEL = 2 */
  312. ori r7, r4, 0x18 /* TLBSEL = 3 */
  313. tlbivax 0, r4
  314. tlbivax 0, r5
  315. tlbivax 0, r6
  316. tlbivax 0, r7
  317. msync
  318. #if defined(CONFIG_SMP)
  319. tlbsync
  320. #endif /* CONFIG_SMP */
  321. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  322. #if defined(CONFIG_SMP)
  323. rlwinm r8,r1,0,0,18
  324. lwz r8,TI_CPU(r8)
  325. oris r8,r8,11
  326. mfmsr r10
  327. SYNC
  328. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  329. rlwinm r0,r0,0,28,26 /* clear DR */
  330. mtmsr r0
  331. SYNC_601
  332. isync
  333. lis r9,mmu_hash_lock@h
  334. ori r9,r9,mmu_hash_lock@l
  335. tophys(r9,r9)
  336. 10: lwarx r7,0,r9
  337. cmpwi 0,r7,0
  338. bne- 10b
  339. stwcx. r8,0,r9
  340. bne- 10b
  341. eieio
  342. tlbie r3
  343. sync
  344. TLBSYNC
  345. li r0,0
  346. stw r0,0(r9) /* clear mmu_hash_lock */
  347. mtmsr r10
  348. SYNC_601
  349. isync
  350. #else /* CONFIG_SMP */
  351. tlbie r3
  352. sync
  353. #endif /* CONFIG_SMP */
  354. #endif /* ! CONFIG_40x */
  355. blr
  356. /*
  357. * Flush instruction cache.
  358. * This is a no-op on the 601.
  359. */
  360. _GLOBAL(flush_instruction_cache)
  361. #if defined(CONFIG_8xx)
  362. isync
  363. lis r5, IDC_INVALL@h
  364. mtspr SPRN_IC_CST, r5
  365. #elif defined(CONFIG_4xx)
  366. #ifdef CONFIG_403GCX
  367. li r3, 512
  368. mtctr r3
  369. lis r4, KERNELBASE@h
  370. 1: iccci 0, r4
  371. addi r4, r4, 16
  372. bdnz 1b
  373. #else
  374. lis r3, KERNELBASE@h
  375. iccci 0,r3
  376. #endif
  377. #elif CONFIG_FSL_BOOKE
  378. BEGIN_FTR_SECTION
  379. mfspr r3,SPRN_L1CSR0
  380. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  381. /* msync; isync recommended here */
  382. mtspr SPRN_L1CSR0,r3
  383. isync
  384. blr
  385. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  386. mfspr r3,SPRN_L1CSR1
  387. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  388. mtspr SPRN_L1CSR1,r3
  389. #else
  390. mfspr r3,SPRN_PVR
  391. rlwinm r3,r3,16,16,31
  392. cmpwi 0,r3,1
  393. beqlr /* for 601, do nothing */
  394. /* 603/604 processor - use invalidate-all bit in HID0 */
  395. mfspr r3,SPRN_HID0
  396. ori r3,r3,HID0_ICFI
  397. mtspr SPRN_HID0,r3
  398. #endif /* CONFIG_8xx/4xx */
  399. isync
  400. blr
  401. /*
  402. * Write any modified data cache blocks out to memory
  403. * and invalidate the corresponding instruction cache blocks.
  404. * This is a no-op on the 601.
  405. *
  406. * __flush_icache_range(unsigned long start, unsigned long stop)
  407. */
  408. _GLOBAL(__flush_icache_range)
  409. BEGIN_FTR_SECTION
  410. blr /* for 601, do nothing */
  411. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  412. li r5,L1_CACHE_BYTES-1
  413. andc r3,r3,r5
  414. subf r4,r3,r4
  415. add r4,r4,r5
  416. srwi. r4,r4,L1_CACHE_SHIFT
  417. beqlr
  418. mtctr r4
  419. mr r6,r3
  420. 1: dcbst 0,r3
  421. addi r3,r3,L1_CACHE_BYTES
  422. bdnz 1b
  423. sync /* wait for dcbst's to get to ram */
  424. mtctr r4
  425. 2: icbi 0,r6
  426. addi r6,r6,L1_CACHE_BYTES
  427. bdnz 2b
  428. sync /* additional sync needed on g4 */
  429. isync
  430. blr
  431. /*
  432. * Write any modified data cache blocks out to memory.
  433. * Does not invalidate the corresponding cache lines (especially for
  434. * any corresponding instruction cache).
  435. *
  436. * clean_dcache_range(unsigned long start, unsigned long stop)
  437. */
  438. _GLOBAL(clean_dcache_range)
  439. li r5,L1_CACHE_BYTES-1
  440. andc r3,r3,r5
  441. subf r4,r3,r4
  442. add r4,r4,r5
  443. srwi. r4,r4,L1_CACHE_SHIFT
  444. beqlr
  445. mtctr r4
  446. 1: dcbst 0,r3
  447. addi r3,r3,L1_CACHE_BYTES
  448. bdnz 1b
  449. sync /* wait for dcbst's to get to ram */
  450. blr
  451. /*
  452. * Write any modified data cache blocks out to memory and invalidate them.
  453. * Does not invalidate the corresponding instruction cache blocks.
  454. *
  455. * flush_dcache_range(unsigned long start, unsigned long stop)
  456. */
  457. _GLOBAL(flush_dcache_range)
  458. li r5,L1_CACHE_BYTES-1
  459. andc r3,r3,r5
  460. subf r4,r3,r4
  461. add r4,r4,r5
  462. srwi. r4,r4,L1_CACHE_SHIFT
  463. beqlr
  464. mtctr r4
  465. 1: dcbf 0,r3
  466. addi r3,r3,L1_CACHE_BYTES
  467. bdnz 1b
  468. sync /* wait for dcbst's to get to ram */
  469. blr
  470. /*
  471. * Like above, but invalidate the D-cache. This is used by the 8xx
  472. * to invalidate the cache so the PPC core doesn't get stale data
  473. * from the CPM (no cache snooping here :-).
  474. *
  475. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  476. */
  477. _GLOBAL(invalidate_dcache_range)
  478. li r5,L1_CACHE_BYTES-1
  479. andc r3,r3,r5
  480. subf r4,r3,r4
  481. add r4,r4,r5
  482. srwi. r4,r4,L1_CACHE_SHIFT
  483. beqlr
  484. mtctr r4
  485. 1: dcbi 0,r3
  486. addi r3,r3,L1_CACHE_BYTES
  487. bdnz 1b
  488. sync /* wait for dcbi's to get to ram */
  489. blr
  490. #ifdef CONFIG_NOT_COHERENT_CACHE
  491. /*
  492. * 40x cores have 8K or 16K dcache and 32 byte line size.
  493. * 44x has a 32K dcache and 32 byte line size.
  494. * 8xx has 1, 2, 4, 8K variants.
  495. * For now, cover the worst case of the 44x.
  496. * Must be called with external interrupts disabled.
  497. */
  498. #define CACHE_NWAYS 64
  499. #define CACHE_NLINES 16
  500. _GLOBAL(flush_dcache_all)
  501. li r4, (2 * CACHE_NWAYS * CACHE_NLINES)
  502. mtctr r4
  503. lis r5, KERNELBASE@h
  504. 1: lwz r3, 0(r5) /* Load one word from every line */
  505. addi r5, r5, L1_CACHE_BYTES
  506. bdnz 1b
  507. blr
  508. #endif /* CONFIG_NOT_COHERENT_CACHE */
  509. /*
  510. * Flush a particular page from the data cache to RAM.
  511. * Note: this is necessary because the instruction cache does *not*
  512. * snoop from the data cache.
  513. * This is a no-op on the 601 which has a unified cache.
  514. *
  515. * void __flush_dcache_icache(void *page)
  516. */
  517. _GLOBAL(__flush_dcache_icache)
  518. BEGIN_FTR_SECTION
  519. blr /* for 601, do nothing */
  520. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  521. rlwinm r3,r3,0,0,19 /* Get page base address */
  522. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  523. mtctr r4
  524. mr r6,r3
  525. 0: dcbst 0,r3 /* Write line to ram */
  526. addi r3,r3,L1_CACHE_BYTES
  527. bdnz 0b
  528. sync
  529. mtctr r4
  530. 1: icbi 0,r6
  531. addi r6,r6,L1_CACHE_BYTES
  532. bdnz 1b
  533. sync
  534. isync
  535. blr
  536. /*
  537. * Flush a particular page from the data cache to RAM, identified
  538. * by its physical address. We turn off the MMU so we can just use
  539. * the physical address (this may be a highmem page without a kernel
  540. * mapping).
  541. *
  542. * void __flush_dcache_icache_phys(unsigned long physaddr)
  543. */
  544. _GLOBAL(__flush_dcache_icache_phys)
  545. BEGIN_FTR_SECTION
  546. blr /* for 601, do nothing */
  547. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  548. mfmsr r10
  549. rlwinm r0,r10,0,28,26 /* clear DR */
  550. mtmsr r0
  551. isync
  552. rlwinm r3,r3,0,0,19 /* Get page base address */
  553. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  554. mtctr r4
  555. mr r6,r3
  556. 0: dcbst 0,r3 /* Write line to ram */
  557. addi r3,r3,L1_CACHE_BYTES
  558. bdnz 0b
  559. sync
  560. mtctr r4
  561. 1: icbi 0,r6
  562. addi r6,r6,L1_CACHE_BYTES
  563. bdnz 1b
  564. sync
  565. mtmsr r10 /* restore DR */
  566. isync
  567. blr
  568. /*
  569. * Clear pages using the dcbz instruction, which doesn't cause any
  570. * memory traffic (except to write out any cache lines which get
  571. * displaced). This only works on cacheable memory.
  572. *
  573. * void clear_pages(void *page, int order) ;
  574. */
  575. _GLOBAL(clear_pages)
  576. li r0,4096/L1_CACHE_BYTES
  577. slw r0,r0,r4
  578. mtctr r0
  579. #ifdef CONFIG_8xx
  580. li r4, 0
  581. 1: stw r4, 0(r3)
  582. stw r4, 4(r3)
  583. stw r4, 8(r3)
  584. stw r4, 12(r3)
  585. #else
  586. 1: dcbz 0,r3
  587. #endif
  588. addi r3,r3,L1_CACHE_BYTES
  589. bdnz 1b
  590. blr
  591. /*
  592. * Copy a whole page. We use the dcbz instruction on the destination
  593. * to reduce memory traffic (it eliminates the unnecessary reads of
  594. * the destination into cache). This requires that the destination
  595. * is cacheable.
  596. */
  597. #define COPY_16_BYTES \
  598. lwz r6,4(r4); \
  599. lwz r7,8(r4); \
  600. lwz r8,12(r4); \
  601. lwzu r9,16(r4); \
  602. stw r6,4(r3); \
  603. stw r7,8(r3); \
  604. stw r8,12(r3); \
  605. stwu r9,16(r3)
  606. _GLOBAL(copy_page)
  607. addi r3,r3,-4
  608. addi r4,r4,-4
  609. #ifdef CONFIG_8xx
  610. /* don't use prefetch on 8xx */
  611. li r0,4096/L1_CACHE_BYTES
  612. mtctr r0
  613. 1: COPY_16_BYTES
  614. bdnz 1b
  615. blr
  616. #else /* not 8xx, we can prefetch */
  617. li r5,4
  618. #if MAX_COPY_PREFETCH > 1
  619. li r0,MAX_COPY_PREFETCH
  620. li r11,4
  621. mtctr r0
  622. 11: dcbt r11,r4
  623. addi r11,r11,L1_CACHE_BYTES
  624. bdnz 11b
  625. #else /* MAX_COPY_PREFETCH == 1 */
  626. dcbt r5,r4
  627. li r11,L1_CACHE_BYTES+4
  628. #endif /* MAX_COPY_PREFETCH */
  629. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  630. crclr 4*cr0+eq
  631. 2:
  632. mtctr r0
  633. 1:
  634. dcbt r11,r4
  635. dcbz r5,r3
  636. COPY_16_BYTES
  637. #if L1_CACHE_BYTES >= 32
  638. COPY_16_BYTES
  639. #if L1_CACHE_BYTES >= 64
  640. COPY_16_BYTES
  641. COPY_16_BYTES
  642. #if L1_CACHE_BYTES >= 128
  643. COPY_16_BYTES
  644. COPY_16_BYTES
  645. COPY_16_BYTES
  646. COPY_16_BYTES
  647. #endif
  648. #endif
  649. #endif
  650. bdnz 1b
  651. beqlr
  652. crnot 4*cr0+eq,4*cr0+eq
  653. li r0,MAX_COPY_PREFETCH
  654. li r11,4
  655. b 2b
  656. #endif /* CONFIG_8xx */
  657. /*
  658. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  659. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  660. */
  661. _GLOBAL(atomic_clear_mask)
  662. 10: lwarx r5,0,r4
  663. andc r5,r5,r3
  664. PPC405_ERR77(0,r4)
  665. stwcx. r5,0,r4
  666. bne- 10b
  667. blr
  668. _GLOBAL(atomic_set_mask)
  669. 10: lwarx r5,0,r4
  670. or r5,r5,r3
  671. PPC405_ERR77(0,r4)
  672. stwcx. r5,0,r4
  673. bne- 10b
  674. blr
  675. /*
  676. * I/O string operations
  677. *
  678. * insb(port, buf, len)
  679. * outsb(port, buf, len)
  680. * insw(port, buf, len)
  681. * outsw(port, buf, len)
  682. * insl(port, buf, len)
  683. * outsl(port, buf, len)
  684. * insw_ns(port, buf, len)
  685. * outsw_ns(port, buf, len)
  686. * insl_ns(port, buf, len)
  687. * outsl_ns(port, buf, len)
  688. *
  689. * The *_ns versions don't do byte-swapping.
  690. */
  691. _GLOBAL(_insb)
  692. cmpwi 0,r5,0
  693. mtctr r5
  694. subi r4,r4,1
  695. blelr-
  696. 00: lbz r5,0(r3)
  697. 01: eieio
  698. 02: stbu r5,1(r4)
  699. ISYNC_8xx
  700. .section .fixup,"ax"
  701. 03: blr
  702. .text
  703. .section __ex_table, "a"
  704. .align 2
  705. .long 00b, 03b
  706. .long 01b, 03b
  707. .long 02b, 03b
  708. .text
  709. bdnz 00b
  710. blr
  711. _GLOBAL(_outsb)
  712. cmpwi 0,r5,0
  713. mtctr r5
  714. subi r4,r4,1
  715. blelr-
  716. 00: lbzu r5,1(r4)
  717. 01: stb r5,0(r3)
  718. 02: eieio
  719. ISYNC_8xx
  720. .section .fixup,"ax"
  721. 03: blr
  722. .text
  723. .section __ex_table, "a"
  724. .align 2
  725. .long 00b, 03b
  726. .long 01b, 03b
  727. .long 02b, 03b
  728. .text
  729. bdnz 00b
  730. blr
  731. _GLOBAL(_insw)
  732. cmpwi 0,r5,0
  733. mtctr r5
  734. subi r4,r4,2
  735. blelr-
  736. 00: lhbrx r5,0,r3
  737. 01: eieio
  738. 02: sthu r5,2(r4)
  739. ISYNC_8xx
  740. .section .fixup,"ax"
  741. 03: blr
  742. .text
  743. .section __ex_table, "a"
  744. .align 2
  745. .long 00b, 03b
  746. .long 01b, 03b
  747. .long 02b, 03b
  748. .text
  749. bdnz 00b
  750. blr
  751. _GLOBAL(_outsw)
  752. cmpwi 0,r5,0
  753. mtctr r5
  754. subi r4,r4,2
  755. blelr-
  756. 00: lhzu r5,2(r4)
  757. 01: eieio
  758. 02: sthbrx r5,0,r3
  759. ISYNC_8xx
  760. .section .fixup,"ax"
  761. 03: blr
  762. .text
  763. .section __ex_table, "a"
  764. .align 2
  765. .long 00b, 03b
  766. .long 01b, 03b
  767. .long 02b, 03b
  768. .text
  769. bdnz 00b
  770. blr
  771. _GLOBAL(_insl)
  772. cmpwi 0,r5,0
  773. mtctr r5
  774. subi r4,r4,4
  775. blelr-
  776. 00: lwbrx r5,0,r3
  777. 01: eieio
  778. 02: stwu r5,4(r4)
  779. ISYNC_8xx
  780. .section .fixup,"ax"
  781. 03: blr
  782. .text
  783. .section __ex_table, "a"
  784. .align 2
  785. .long 00b, 03b
  786. .long 01b, 03b
  787. .long 02b, 03b
  788. .text
  789. bdnz 00b
  790. blr
  791. _GLOBAL(_outsl)
  792. cmpwi 0,r5,0
  793. mtctr r5
  794. subi r4,r4,4
  795. blelr-
  796. 00: lwzu r5,4(r4)
  797. 01: stwbrx r5,0,r3
  798. 02: eieio
  799. ISYNC_8xx
  800. .section .fixup,"ax"
  801. 03: blr
  802. .text
  803. .section __ex_table, "a"
  804. .align 2
  805. .long 00b, 03b
  806. .long 01b, 03b
  807. .long 02b, 03b
  808. .text
  809. bdnz 00b
  810. blr
  811. _GLOBAL(__ide_mm_insw)
  812. _GLOBAL(_insw_ns)
  813. cmpwi 0,r5,0
  814. mtctr r5
  815. subi r4,r4,2
  816. blelr-
  817. 00: lhz r5,0(r3)
  818. 01: eieio
  819. 02: sthu r5,2(r4)
  820. ISYNC_8xx
  821. .section .fixup,"ax"
  822. 03: blr
  823. .text
  824. .section __ex_table, "a"
  825. .align 2
  826. .long 00b, 03b
  827. .long 01b, 03b
  828. .long 02b, 03b
  829. .text
  830. bdnz 00b
  831. blr
  832. _GLOBAL(__ide_mm_outsw)
  833. _GLOBAL(_outsw_ns)
  834. cmpwi 0,r5,0
  835. mtctr r5
  836. subi r4,r4,2
  837. blelr-
  838. 00: lhzu r5,2(r4)
  839. 01: sth r5,0(r3)
  840. 02: eieio
  841. ISYNC_8xx
  842. .section .fixup,"ax"
  843. 03: blr
  844. .text
  845. .section __ex_table, "a"
  846. .align 2
  847. .long 00b, 03b
  848. .long 01b, 03b
  849. .long 02b, 03b
  850. .text
  851. bdnz 00b
  852. blr
  853. _GLOBAL(__ide_mm_insl)
  854. _GLOBAL(_insl_ns)
  855. cmpwi 0,r5,0
  856. mtctr r5
  857. subi r4,r4,4
  858. blelr-
  859. 00: lwz r5,0(r3)
  860. 01: eieio
  861. 02: stwu r5,4(r4)
  862. ISYNC_8xx
  863. .section .fixup,"ax"
  864. 03: blr
  865. .text
  866. .section __ex_table, "a"
  867. .align 2
  868. .long 00b, 03b
  869. .long 01b, 03b
  870. .long 02b, 03b
  871. .text
  872. bdnz 00b
  873. blr
  874. _GLOBAL(__ide_mm_outsl)
  875. _GLOBAL(_outsl_ns)
  876. cmpwi 0,r5,0
  877. mtctr r5
  878. subi r4,r4,4
  879. blelr-
  880. 00: lwzu r5,4(r4)
  881. 01: stw r5,0(r3)
  882. 02: eieio
  883. ISYNC_8xx
  884. .section .fixup,"ax"
  885. 03: blr
  886. .text
  887. .section __ex_table, "a"
  888. .align 2
  889. .long 00b, 03b
  890. .long 01b, 03b
  891. .long 02b, 03b
  892. .text
  893. bdnz 00b
  894. blr
  895. /*
  896. * Extended precision shifts.
  897. *
  898. * Updated to be valid for shift counts from 0 to 63 inclusive.
  899. * -- Gabriel
  900. *
  901. * R3/R4 has 64 bit value
  902. * R5 has shift count
  903. * result in R3/R4
  904. *
  905. * ashrdi3: arithmetic right shift (sign propagation)
  906. * lshrdi3: logical right shift
  907. * ashldi3: left shift
  908. */
  909. _GLOBAL(__ashrdi3)
  910. subfic r6,r5,32
  911. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  912. addi r7,r5,32 # could be xori, or addi with -32
  913. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  914. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  915. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  916. or r4,r4,r6 # LSW |= t1
  917. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  918. sraw r3,r3,r5 # MSW = MSW >> count
  919. or r4,r4,r7 # LSW |= t2
  920. blr
  921. _GLOBAL(__ashldi3)
  922. subfic r6,r5,32
  923. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  924. addi r7,r5,32 # could be xori, or addi with -32
  925. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  926. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  927. or r3,r3,r6 # MSW |= t1
  928. slw r4,r4,r5 # LSW = LSW << count
  929. or r3,r3,r7 # MSW |= t2
  930. blr
  931. _GLOBAL(__lshrdi3)
  932. subfic r6,r5,32
  933. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  934. addi r7,r5,32 # could be xori, or addi with -32
  935. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  936. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  937. or r4,r4,r6 # LSW |= t1
  938. srw r3,r3,r5 # MSW = MSW >> count
  939. or r4,r4,r7 # LSW |= t2
  940. blr
  941. _GLOBAL(abs)
  942. srawi r4,r3,31
  943. xor r3,r3,r4
  944. sub r3,r3,r4
  945. blr
  946. _GLOBAL(_get_SP)
  947. mr r3,r1 /* Close enough */
  948. blr
  949. /*
  950. * Create a kernel thread
  951. * kernel_thread(fn, arg, flags)
  952. */
  953. _GLOBAL(kernel_thread)
  954. stwu r1,-16(r1)
  955. stw r30,8(r1)
  956. stw r31,12(r1)
  957. mr r30,r3 /* function */
  958. mr r31,r4 /* argument */
  959. ori r3,r5,CLONE_VM /* flags */
  960. oris r3,r3,CLONE_UNTRACED>>16
  961. li r4,0 /* new sp (unused) */
  962. li r0,__NR_clone
  963. sc
  964. cmpwi 0,r3,0 /* parent or child? */
  965. bne 1f /* return if parent */
  966. li r0,0 /* make top-level stack frame */
  967. stwu r0,-16(r1)
  968. mtlr r30 /* fn addr in lr */
  969. mr r3,r31 /* load arg and call fn */
  970. PPC440EP_ERR42
  971. blrl
  972. li r0,__NR_exit /* exit if function returns */
  973. li r3,0
  974. sc
  975. 1: lwz r30,8(r1)
  976. lwz r31,12(r1)
  977. addi r1,r1,16
  978. blr
  979. /*
  980. * This routine is just here to keep GCC happy - sigh...
  981. */
  982. _GLOBAL(__main)
  983. blr
  984. #define SYSCALL(name) \
  985. _GLOBAL(name) \
  986. li r0,__NR_##name; \
  987. sc; \
  988. bnslr; \
  989. lis r4,errno@ha; \
  990. stw r3,errno@l(r4); \
  991. li r3,-1; \
  992. blr
  993. SYSCALL(execve)