misc.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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/sys.h>
  15. #include <asm/unistd.h>
  16. #include <asm/errno.h>
  17. #include <asm/processor.h>
  18. #include <asm/page.h>
  19. #include <asm/cache.h>
  20. #include <asm/cputable.h>
  21. #include <asm/mmu.h>
  22. #include <asm/ppc_asm.h>
  23. #include <asm/thread_info.h>
  24. #include <asm/asm-offsets.h>
  25. #ifdef CONFIG_8xx
  26. #define ISYNC_8xx isync
  27. #else
  28. #define ISYNC_8xx
  29. #endif
  30. .text
  31. .align 5
  32. _GLOBAL(__delay)
  33. cmpwi 0,r3,0
  34. mtctr r3
  35. beqlr
  36. 1: bdnz 1b
  37. blr
  38. /*
  39. * Returns (address we're running at) - (address we were linked at)
  40. * for use before the text and data are mapped to KERNELBASE.
  41. */
  42. _GLOBAL(reloc_offset)
  43. mflr r0
  44. bl 1f
  45. 1: mflr r3
  46. lis r4,1b@ha
  47. addi r4,r4,1b@l
  48. subf r3,r4,r3
  49. mtlr r0
  50. blr
  51. /*
  52. * add_reloc_offset(x) returns x + reloc_offset().
  53. */
  54. _GLOBAL(add_reloc_offset)
  55. mflr r0
  56. bl 1f
  57. 1: mflr r5
  58. lis r4,1b@ha
  59. addi r4,r4,1b@l
  60. subf r5,r4,r5
  61. add r3,r3,r5
  62. mtlr r0
  63. blr
  64. /*
  65. * sub_reloc_offset(x) returns x - reloc_offset().
  66. */
  67. _GLOBAL(sub_reloc_offset)
  68. mflr r0
  69. bl 1f
  70. 1: mflr r5
  71. lis r4,1b@ha
  72. addi r4,r4,1b@l
  73. subf r5,r4,r5
  74. subf r3,r5,r3
  75. mtlr r0
  76. blr
  77. /*
  78. * reloc_got2 runs through the .got2 section adding an offset
  79. * to each entry.
  80. */
  81. _GLOBAL(reloc_got2)
  82. mflr r11
  83. lis r7,__got2_start@ha
  84. addi r7,r7,__got2_start@l
  85. lis r8,__got2_end@ha
  86. addi r8,r8,__got2_end@l
  87. subf r8,r7,r8
  88. srwi. r8,r8,2
  89. beqlr
  90. mtctr r8
  91. bl 1f
  92. 1: mflr r0
  93. lis r4,1b@ha
  94. addi r4,r4,1b@l
  95. subf r0,r4,r0
  96. add r7,r0,r7
  97. 2: lwz r0,0(r7)
  98. add r0,r0,r3
  99. stw r0,0(r7)
  100. addi r7,r7,4
  101. bdnz 2b
  102. mtlr r11
  103. blr
  104. /*
  105. * call_setup_cpu - call the setup_cpu function for this cpu
  106. * r3 = data offset, r24 = cpu number
  107. *
  108. * Setup function is called with:
  109. * r3 = data offset
  110. * r4 = ptr to CPU spec (relocated)
  111. */
  112. _GLOBAL(call_setup_cpu)
  113. addis r4,r3,cur_cpu_spec@ha
  114. addi r4,r4,cur_cpu_spec@l
  115. lwz r4,0(r4)
  116. add r4,r4,r3
  117. lwz r5,CPU_SPEC_SETUP(r4)
  118. cmpi 0,r5,0
  119. add r5,r5,r3
  120. beqlr
  121. mtctr r5
  122. bctr
  123. /*
  124. * complement mask on the msr then "or" some values on.
  125. * _nmask_and_or_msr(nmask, value_to_or)
  126. */
  127. _GLOBAL(_nmask_and_or_msr)
  128. mfmsr r0 /* Get current msr */
  129. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  130. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  131. SYNC /* Some chip revs have problems here... */
  132. mtmsr r0 /* Update machine state */
  133. isync
  134. blr /* Done */
  135. /*
  136. * Flush MMU TLB
  137. */
  138. _GLOBAL(_tlbia)
  139. #if defined(CONFIG_40x)
  140. sync /* Flush to memory before changing mapping */
  141. tlbia
  142. isync /* Flush shadow TLB */
  143. #elif defined(CONFIG_44x)
  144. li r3,0
  145. sync
  146. /* Load high watermark */
  147. lis r4,tlb_44x_hwater@ha
  148. lwz r5,tlb_44x_hwater@l(r4)
  149. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  150. addi r3,r3,1
  151. cmpw 0,r3,r5
  152. ble 1b
  153. isync
  154. #else /* !(CONFIG_40x || CONFIG_44x) */
  155. #if defined(CONFIG_SMP)
  156. rlwinm r8,r1,0,0,18
  157. lwz r8,TI_CPU(r8)
  158. oris r8,r8,10
  159. mfmsr r10
  160. SYNC
  161. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  162. rlwinm r0,r0,0,28,26 /* clear DR */
  163. mtmsr r0
  164. SYNC_601
  165. isync
  166. lis r9,mmu_hash_lock@h
  167. ori r9,r9,mmu_hash_lock@l
  168. tophys(r9,r9)
  169. 10: lwarx r7,0,r9
  170. cmpwi 0,r7,0
  171. bne- 10b
  172. stwcx. r8,0,r9
  173. bne- 10b
  174. sync
  175. tlbia
  176. sync
  177. TLBSYNC
  178. li r0,0
  179. stw r0,0(r9) /* clear mmu_hash_lock */
  180. mtmsr r10
  181. SYNC_601
  182. isync
  183. #else /* CONFIG_SMP */
  184. sync
  185. tlbia
  186. sync
  187. #endif /* CONFIG_SMP */
  188. #endif /* ! defined(CONFIG_40x) */
  189. blr
  190. /*
  191. * Flush MMU TLB for a particular address
  192. */
  193. _GLOBAL(_tlbie)
  194. #if defined(CONFIG_40x)
  195. /* We run the search with interrupts disabled because we have to change
  196. * the PID and I don't want to preempt when that happens.
  197. */
  198. mfmsr r5
  199. mfspr r6,SPRN_PID
  200. wrteei 0
  201. mtspr SPRN_PID,r4
  202. tlbsx. r3, 0, r3
  203. mtspr SPRN_PID,r6
  204. wrtee r5
  205. bne 10f
  206. sync
  207. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  208. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  209. * the TLB entry. */
  210. tlbwe r3, r3, TLB_TAG
  211. isync
  212. 10:
  213. #elif defined(CONFIG_44x)
  214. mfspr r5,SPRN_MMUCR
  215. rlwimi r5,r4,0,24,31 /* Set TID */
  216. /* We have to run the search with interrupts disabled, even critical
  217. * and debug interrupts (in fact the only critical exceptions we have
  218. * are debug and machine check). Otherwise an interrupt which causes
  219. * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
  220. mfmsr r4
  221. lis r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
  222. addi r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
  223. andc r6,r4,r6
  224. mtmsr r6
  225. mtspr SPRN_MMUCR,r5
  226. tlbsx. r3, 0, r3
  227. mtmsr r4
  228. bne 10f
  229. sync
  230. /* There are only 64 TLB entries, so r3 < 64,
  231. * which means bit 22, is clear. Since 22 is
  232. * the V bit in the TLB_PAGEID, loading this
  233. * value will invalidate the TLB entry.
  234. */
  235. tlbwe r3, r3, PPC44x_TLB_PAGEID
  236. isync
  237. 10:
  238. #else /* !(CONFIG_40x || CONFIG_44x) */
  239. #if defined(CONFIG_SMP)
  240. rlwinm r8,r1,0,0,18
  241. lwz r8,TI_CPU(r8)
  242. oris r8,r8,11
  243. mfmsr r10
  244. SYNC
  245. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  246. rlwinm r0,r0,0,28,26 /* clear DR */
  247. mtmsr r0
  248. SYNC_601
  249. isync
  250. lis r9,mmu_hash_lock@h
  251. ori r9,r9,mmu_hash_lock@l
  252. tophys(r9,r9)
  253. 10: lwarx r7,0,r9
  254. cmpwi 0,r7,0
  255. bne- 10b
  256. stwcx. r8,0,r9
  257. bne- 10b
  258. eieio
  259. tlbie r3
  260. sync
  261. TLBSYNC
  262. li r0,0
  263. stw r0,0(r9) /* clear mmu_hash_lock */
  264. mtmsr r10
  265. SYNC_601
  266. isync
  267. #else /* CONFIG_SMP */
  268. tlbie r3
  269. sync
  270. #endif /* CONFIG_SMP */
  271. #endif /* ! CONFIG_40x */
  272. blr
  273. /*
  274. * Flush instruction cache.
  275. * This is a no-op on the 601.
  276. */
  277. _GLOBAL(flush_instruction_cache)
  278. #if defined(CONFIG_8xx)
  279. isync
  280. lis r5, IDC_INVALL@h
  281. mtspr SPRN_IC_CST, r5
  282. #elif defined(CONFIG_4xx)
  283. #ifdef CONFIG_403GCX
  284. li r3, 512
  285. mtctr r3
  286. lis r4, KERNELBASE@h
  287. 1: iccci 0, r4
  288. addi r4, r4, 16
  289. bdnz 1b
  290. #else
  291. lis r3, KERNELBASE@h
  292. iccci 0,r3
  293. #endif
  294. #else
  295. mfspr r3,SPRN_PVR
  296. rlwinm r3,r3,16,16,31
  297. cmpwi 0,r3,1
  298. beqlr /* for 601, do nothing */
  299. /* 603/604 processor - use invalidate-all bit in HID0 */
  300. mfspr r3,SPRN_HID0
  301. ori r3,r3,HID0_ICFI
  302. mtspr SPRN_HID0,r3
  303. #endif /* CONFIG_8xx/4xx */
  304. isync
  305. blr
  306. /*
  307. * Write any modified data cache blocks out to memory
  308. * and invalidate the corresponding instruction cache blocks.
  309. * This is a no-op on the 601.
  310. *
  311. * __flush_icache_range(unsigned long start, unsigned long stop)
  312. */
  313. _GLOBAL(__flush_icache_range)
  314. BEGIN_FTR_SECTION
  315. blr /* for 601, do nothing */
  316. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  317. li r5,L1_CACHE_BYTES-1
  318. andc r3,r3,r5
  319. subf r4,r3,r4
  320. add r4,r4,r5
  321. srwi. r4,r4,L1_CACHE_SHIFT
  322. beqlr
  323. mtctr r4
  324. mr r6,r3
  325. 1: dcbst 0,r3
  326. addi r3,r3,L1_CACHE_BYTES
  327. bdnz 1b
  328. sync /* wait for dcbst's to get to ram */
  329. mtctr r4
  330. 2: icbi 0,r6
  331. addi r6,r6,L1_CACHE_BYTES
  332. bdnz 2b
  333. sync /* additional sync needed on g4 */
  334. isync
  335. blr
  336. /*
  337. * Write any modified data cache blocks out to memory.
  338. * Does not invalidate the corresponding cache lines (especially for
  339. * any corresponding instruction cache).
  340. *
  341. * clean_dcache_range(unsigned long start, unsigned long stop)
  342. */
  343. _GLOBAL(clean_dcache_range)
  344. li r5,L1_CACHE_BYTES-1
  345. andc r3,r3,r5
  346. subf r4,r3,r4
  347. add r4,r4,r5
  348. srwi. r4,r4,L1_CACHE_SHIFT
  349. beqlr
  350. mtctr r4
  351. 1: dcbst 0,r3
  352. addi r3,r3,L1_CACHE_BYTES
  353. bdnz 1b
  354. sync /* wait for dcbst's to get to ram */
  355. blr
  356. /*
  357. * Write any modified data cache blocks out to memory and invalidate them.
  358. * Does not invalidate the corresponding instruction cache blocks.
  359. *
  360. * flush_dcache_range(unsigned long start, unsigned long stop)
  361. */
  362. _GLOBAL(flush_dcache_range)
  363. li r5,L1_CACHE_BYTES-1
  364. andc r3,r3,r5
  365. subf r4,r3,r4
  366. add r4,r4,r5
  367. srwi. r4,r4,L1_CACHE_SHIFT
  368. beqlr
  369. mtctr r4
  370. 1: dcbf 0,r3
  371. addi r3,r3,L1_CACHE_BYTES
  372. bdnz 1b
  373. sync /* wait for dcbst's to get to ram */
  374. blr
  375. /*
  376. * Like above, but invalidate the D-cache. This is used by the 8xx
  377. * to invalidate the cache so the PPC core doesn't get stale data
  378. * from the CPM (no cache snooping here :-).
  379. *
  380. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  381. */
  382. _GLOBAL(invalidate_dcache_range)
  383. li r5,L1_CACHE_BYTES-1
  384. andc r3,r3,r5
  385. subf r4,r3,r4
  386. add r4,r4,r5
  387. srwi. r4,r4,L1_CACHE_SHIFT
  388. beqlr
  389. mtctr r4
  390. 1: dcbi 0,r3
  391. addi r3,r3,L1_CACHE_BYTES
  392. bdnz 1b
  393. sync /* wait for dcbi's to get to ram */
  394. blr
  395. #ifdef CONFIG_NOT_COHERENT_CACHE
  396. /*
  397. * 40x cores have 8K or 16K dcache and 32 byte line size.
  398. * 44x has a 32K dcache and 32 byte line size.
  399. * 8xx has 1, 2, 4, 8K variants.
  400. * For now, cover the worst case of the 44x.
  401. * Must be called with external interrupts disabled.
  402. */
  403. #define CACHE_NWAYS 64
  404. #define CACHE_NLINES 16
  405. _GLOBAL(flush_dcache_all)
  406. li r4, (2 * CACHE_NWAYS * CACHE_NLINES)
  407. mtctr r4
  408. lis r5, KERNELBASE@h
  409. 1: lwz r3, 0(r5) /* Load one word from every line */
  410. addi r5, r5, L1_CACHE_BYTES
  411. bdnz 1b
  412. blr
  413. #endif /* CONFIG_NOT_COHERENT_CACHE */
  414. /*
  415. * Flush a particular page from the data cache to RAM.
  416. * Note: this is necessary because the instruction cache does *not*
  417. * snoop from the data cache.
  418. * This is a no-op on the 601 which has a unified cache.
  419. *
  420. * void __flush_dcache_icache(void *page)
  421. */
  422. _GLOBAL(__flush_dcache_icache)
  423. BEGIN_FTR_SECTION
  424. blr /* for 601, do nothing */
  425. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  426. rlwinm r3,r3,0,0,19 /* Get page base address */
  427. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  428. mtctr r4
  429. mr r6,r3
  430. 0: dcbst 0,r3 /* Write line to ram */
  431. addi r3,r3,L1_CACHE_BYTES
  432. bdnz 0b
  433. sync
  434. #ifndef CONFIG_44x
  435. /* We don't flush the icache on 44x. Those have a virtual icache
  436. * and we don't have access to the virtual address here (it's
  437. * not the page vaddr but where it's mapped in user space). The
  438. * flushing of the icache on these is handled elsewhere, when
  439. * a change in the address space occurs, before returning to
  440. * user space
  441. */
  442. mtctr r4
  443. 1: icbi 0,r6
  444. addi r6,r6,L1_CACHE_BYTES
  445. bdnz 1b
  446. sync
  447. isync
  448. #endif /* CONFIG_44x */
  449. blr
  450. /*
  451. * Flush a particular page from the data cache to RAM, identified
  452. * by its physical address. We turn off the MMU so we can just use
  453. * the physical address (this may be a highmem page without a kernel
  454. * mapping).
  455. *
  456. * void __flush_dcache_icache_phys(unsigned long physaddr)
  457. */
  458. _GLOBAL(__flush_dcache_icache_phys)
  459. BEGIN_FTR_SECTION
  460. blr /* for 601, do nothing */
  461. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  462. mfmsr r10
  463. rlwinm r0,r10,0,28,26 /* clear DR */
  464. mtmsr r0
  465. isync
  466. rlwinm r3,r3,0,0,19 /* Get page base address */
  467. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  468. mtctr r4
  469. mr r6,r3
  470. 0: dcbst 0,r3 /* Write line to ram */
  471. addi r3,r3,L1_CACHE_BYTES
  472. bdnz 0b
  473. sync
  474. mtctr r4
  475. 1: icbi 0,r6
  476. addi r6,r6,L1_CACHE_BYTES
  477. bdnz 1b
  478. sync
  479. mtmsr r10 /* restore DR */
  480. isync
  481. blr
  482. /*
  483. * Clear pages using the dcbz instruction, which doesn't cause any
  484. * memory traffic (except to write out any cache lines which get
  485. * displaced). This only works on cacheable memory.
  486. *
  487. * void clear_pages(void *page, int order) ;
  488. */
  489. _GLOBAL(clear_pages)
  490. li r0,4096/L1_CACHE_BYTES
  491. slw r0,r0,r4
  492. mtctr r0
  493. #ifdef CONFIG_8xx
  494. li r4, 0
  495. 1: stw r4, 0(r3)
  496. stw r4, 4(r3)
  497. stw r4, 8(r3)
  498. stw r4, 12(r3)
  499. #else
  500. 1: dcbz 0,r3
  501. #endif
  502. addi r3,r3,L1_CACHE_BYTES
  503. bdnz 1b
  504. blr
  505. /*
  506. * Copy a whole page. We use the dcbz instruction on the destination
  507. * to reduce memory traffic (it eliminates the unnecessary reads of
  508. * the destination into cache). This requires that the destination
  509. * is cacheable.
  510. */
  511. #define COPY_16_BYTES \
  512. lwz r6,4(r4); \
  513. lwz r7,8(r4); \
  514. lwz r8,12(r4); \
  515. lwzu r9,16(r4); \
  516. stw r6,4(r3); \
  517. stw r7,8(r3); \
  518. stw r8,12(r3); \
  519. stwu r9,16(r3)
  520. _GLOBAL(copy_page)
  521. addi r3,r3,-4
  522. addi r4,r4,-4
  523. #ifdef CONFIG_8xx
  524. /* don't use prefetch on 8xx */
  525. li r0,4096/L1_CACHE_BYTES
  526. mtctr r0
  527. 1: COPY_16_BYTES
  528. bdnz 1b
  529. blr
  530. #else /* not 8xx, we can prefetch */
  531. li r5,4
  532. #if MAX_COPY_PREFETCH > 1
  533. li r0,MAX_COPY_PREFETCH
  534. li r11,4
  535. mtctr r0
  536. 11: dcbt r11,r4
  537. addi r11,r11,L1_CACHE_BYTES
  538. bdnz 11b
  539. #else /* MAX_COPY_PREFETCH == 1 */
  540. dcbt r5,r4
  541. li r11,L1_CACHE_BYTES+4
  542. #endif /* MAX_COPY_PREFETCH */
  543. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  544. crclr 4*cr0+eq
  545. 2:
  546. mtctr r0
  547. 1:
  548. dcbt r11,r4
  549. dcbz r5,r3
  550. COPY_16_BYTES
  551. #if L1_CACHE_BYTES >= 32
  552. COPY_16_BYTES
  553. #if L1_CACHE_BYTES >= 64
  554. COPY_16_BYTES
  555. COPY_16_BYTES
  556. #if L1_CACHE_BYTES >= 128
  557. COPY_16_BYTES
  558. COPY_16_BYTES
  559. COPY_16_BYTES
  560. COPY_16_BYTES
  561. #endif
  562. #endif
  563. #endif
  564. bdnz 1b
  565. beqlr
  566. crnot 4*cr0+eq,4*cr0+eq
  567. li r0,MAX_COPY_PREFETCH
  568. li r11,4
  569. b 2b
  570. #endif /* CONFIG_8xx */
  571. /*
  572. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  573. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  574. */
  575. _GLOBAL(atomic_clear_mask)
  576. 10: lwarx r5,0,r4
  577. andc r5,r5,r3
  578. PPC405_ERR77(0,r4)
  579. stwcx. r5,0,r4
  580. bne- 10b
  581. blr
  582. _GLOBAL(atomic_set_mask)
  583. 10: lwarx r5,0,r4
  584. or r5,r5,r3
  585. PPC405_ERR77(0,r4)
  586. stwcx. r5,0,r4
  587. bne- 10b
  588. blr
  589. /*
  590. * I/O string operations
  591. *
  592. * insb(port, buf, len)
  593. * outsb(port, buf, len)
  594. * insw(port, buf, len)
  595. * outsw(port, buf, len)
  596. * insl(port, buf, len)
  597. * outsl(port, buf, len)
  598. * insw_ns(port, buf, len)
  599. * outsw_ns(port, buf, len)
  600. * insl_ns(port, buf, len)
  601. * outsl_ns(port, buf, len)
  602. *
  603. * The *_ns versions don't do byte-swapping.
  604. */
  605. _GLOBAL(_insb)
  606. cmpwi 0,r5,0
  607. mtctr r5
  608. subi r4,r4,1
  609. blelr-
  610. 00: lbz r5,0(r3)
  611. 01: eieio
  612. 02: stbu r5,1(r4)
  613. ISYNC_8xx
  614. .section .fixup,"ax"
  615. 03: blr
  616. .text
  617. .section __ex_table, "a"
  618. .align 2
  619. .long 00b, 03b
  620. .long 01b, 03b
  621. .long 02b, 03b
  622. .text
  623. bdnz 00b
  624. blr
  625. _GLOBAL(_outsb)
  626. cmpwi 0,r5,0
  627. mtctr r5
  628. subi r4,r4,1
  629. blelr-
  630. 00: lbzu r5,1(r4)
  631. 01: stb r5,0(r3)
  632. 02: eieio
  633. ISYNC_8xx
  634. .section .fixup,"ax"
  635. 03: blr
  636. .text
  637. .section __ex_table, "a"
  638. .align 2
  639. .long 00b, 03b
  640. .long 01b, 03b
  641. .long 02b, 03b
  642. .text
  643. bdnz 00b
  644. blr
  645. _GLOBAL(_insw_ns)
  646. cmpwi 0,r5,0
  647. mtctr r5
  648. subi r4,r4,2
  649. blelr-
  650. 00: lhz r5,0(r3)
  651. 01: eieio
  652. 02: sthu r5,2(r4)
  653. ISYNC_8xx
  654. .section .fixup,"ax"
  655. 03: blr
  656. .text
  657. .section __ex_table, "a"
  658. .align 2
  659. .long 00b, 03b
  660. .long 01b, 03b
  661. .long 02b, 03b
  662. .text
  663. bdnz 00b
  664. blr
  665. _GLOBAL(_outsw_ns)
  666. cmpwi 0,r5,0
  667. mtctr r5
  668. subi r4,r4,2
  669. blelr-
  670. 00: lhzu r5,2(r4)
  671. 01: sth r5,0(r3)
  672. 02: eieio
  673. ISYNC_8xx
  674. .section .fixup,"ax"
  675. 03: blr
  676. .text
  677. .section __ex_table, "a"
  678. .align 2
  679. .long 00b, 03b
  680. .long 01b, 03b
  681. .long 02b, 03b
  682. .text
  683. bdnz 00b
  684. blr
  685. _GLOBAL(_insl_ns)
  686. cmpwi 0,r5,0
  687. mtctr r5
  688. subi r4,r4,4
  689. blelr-
  690. 00: lwz r5,0(r3)
  691. 01: eieio
  692. 02: stwu r5,4(r4)
  693. ISYNC_8xx
  694. .section .fixup,"ax"
  695. 03: blr
  696. .text
  697. .section __ex_table, "a"
  698. .align 2
  699. .long 00b, 03b
  700. .long 01b, 03b
  701. .long 02b, 03b
  702. .text
  703. bdnz 00b
  704. blr
  705. _GLOBAL(_outsl_ns)
  706. cmpwi 0,r5,0
  707. mtctr r5
  708. subi r4,r4,4
  709. blelr-
  710. 00: lwzu r5,4(r4)
  711. 01: stw r5,0(r3)
  712. 02: eieio
  713. ISYNC_8xx
  714. .section .fixup,"ax"
  715. 03: blr
  716. .text
  717. .section __ex_table, "a"
  718. .align 2
  719. .long 00b, 03b
  720. .long 01b, 03b
  721. .long 02b, 03b
  722. .text
  723. bdnz 00b
  724. blr
  725. /*
  726. * Extended precision shifts.
  727. *
  728. * Updated to be valid for shift counts from 0 to 63 inclusive.
  729. * -- Gabriel
  730. *
  731. * R3/R4 has 64 bit value
  732. * R5 has shift count
  733. * result in R3/R4
  734. *
  735. * ashrdi3: arithmetic right shift (sign propagation)
  736. * lshrdi3: logical right shift
  737. * ashldi3: left shift
  738. */
  739. _GLOBAL(__ashrdi3)
  740. subfic r6,r5,32
  741. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  742. addi r7,r5,32 # could be xori, or addi with -32
  743. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  744. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  745. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  746. or r4,r4,r6 # LSW |= t1
  747. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  748. sraw r3,r3,r5 # MSW = MSW >> count
  749. or r4,r4,r7 # LSW |= t2
  750. blr
  751. _GLOBAL(__ashldi3)
  752. subfic r6,r5,32
  753. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  754. addi r7,r5,32 # could be xori, or addi with -32
  755. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  756. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  757. or r3,r3,r6 # MSW |= t1
  758. slw r4,r4,r5 # LSW = LSW << count
  759. or r3,r3,r7 # MSW |= t2
  760. blr
  761. _GLOBAL(__lshrdi3)
  762. subfic r6,r5,32
  763. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  764. addi r7,r5,32 # could be xori, or addi with -32
  765. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  766. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  767. or r4,r4,r6 # LSW |= t1
  768. srw r3,r3,r5 # MSW = MSW >> count
  769. or r4,r4,r7 # LSW |= t2
  770. blr
  771. _GLOBAL(abs)
  772. srawi r4,r3,31
  773. xor r3,r3,r4
  774. sub r3,r3,r4
  775. blr
  776. _GLOBAL(_get_SP)
  777. mr r3,r1 /* Close enough */
  778. blr
  779. /*
  780. * Create a kernel thread
  781. * kernel_thread(fn, arg, flags)
  782. */
  783. _GLOBAL(kernel_thread)
  784. stwu r1,-16(r1)
  785. stw r30,8(r1)
  786. stw r31,12(r1)
  787. mr r30,r3 /* function */
  788. mr r31,r4 /* argument */
  789. ori r3,r5,CLONE_VM /* flags */
  790. oris r3,r3,CLONE_UNTRACED>>16
  791. li r4,0 /* new sp (unused) */
  792. li r0,__NR_clone
  793. sc
  794. cmpwi 0,r3,0 /* parent or child? */
  795. bne 1f /* return if parent */
  796. li r0,0 /* make top-level stack frame */
  797. stwu r0,-16(r1)
  798. mtlr r30 /* fn addr in lr */
  799. mr r3,r31 /* load arg and call fn */
  800. PPC440EP_ERR42
  801. blrl
  802. li r0,__NR_exit /* exit if function returns */
  803. li r3,0
  804. sc
  805. 1: lwz r30,8(r1)
  806. lwz r31,12(r1)
  807. addi r1,r1,16
  808. blr
  809. _GLOBAL(kernel_execve)
  810. li r0,__NR_execve
  811. sc
  812. bnslr
  813. neg r3,r3
  814. blr
  815. /*
  816. * This routine is just here to keep GCC happy - sigh...
  817. */
  818. _GLOBAL(__main)
  819. blr