copyuser_64.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright (C) 2002 Paul Mackerras, IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <asm/processor.h>
  10. #include <asm/ppc_asm.h>
  11. #ifdef __BIG_ENDIAN__
  12. #define sLd sld /* Shift towards low-numbered address. */
  13. #define sHd srd /* Shift towards high-numbered address. */
  14. #else
  15. #define sLd srd /* Shift towards low-numbered address. */
  16. #define sHd sld /* Shift towards high-numbered address. */
  17. #endif
  18. .align 7
  19. _GLOBAL_TOC(__copy_tofrom_user)
  20. BEGIN_FTR_SECTION
  21. nop
  22. FTR_SECTION_ELSE
  23. b __copy_tofrom_user_power7
  24. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
  25. _GLOBAL(__copy_tofrom_user_base)
  26. /* first check for a whole page copy on a page boundary */
  27. cmpldi cr1,r5,16
  28. cmpdi cr6,r5,4096
  29. or r0,r3,r4
  30. neg r6,r3 /* LS 3 bits = # bytes to 8-byte dest bdry */
  31. andi. r0,r0,4095
  32. std r3,-24(r1)
  33. crand cr0*4+2,cr0*4+2,cr6*4+2
  34. std r4,-16(r1)
  35. std r5,-8(r1)
  36. dcbt 0,r4
  37. beq .Lcopy_page_4K
  38. andi. r6,r6,7
  39. PPC_MTOCRF(0x01,r5)
  40. blt cr1,.Lshort_copy
  41. /* Below we want to nop out the bne if we're on a CPU that has the
  42. * CPU_FTR_UNALIGNED_LD_STD bit set and the CPU_FTR_CP_USE_DCBTZ bit
  43. * cleared.
  44. * At the time of writing the only CPU that has this combination of bits
  45. * set is Power6.
  46. */
  47. BEGIN_FTR_SECTION
  48. nop
  49. FTR_SECTION_ELSE
  50. bne .Ldst_unaligned
  51. ALT_FTR_SECTION_END(CPU_FTR_UNALIGNED_LD_STD | CPU_FTR_CP_USE_DCBTZ, \
  52. CPU_FTR_UNALIGNED_LD_STD)
  53. .Ldst_aligned:
  54. addi r3,r3,-16
  55. BEGIN_FTR_SECTION
  56. andi. r0,r4,7
  57. bne .Lsrc_unaligned
  58. END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD)
  59. blt cr1,.Ldo_tail /* if < 16 bytes to copy */
  60. srdi r0,r5,5
  61. cmpdi cr1,r0,0
  62. 20: ld r7,0(r4)
  63. 220: ld r6,8(r4)
  64. addi r4,r4,16
  65. mtctr r0
  66. andi. r0,r5,0x10
  67. beq 22f
  68. addi r3,r3,16
  69. addi r4,r4,-16
  70. mr r9,r7
  71. mr r8,r6
  72. beq cr1,72f
  73. 21: ld r7,16(r4)
  74. 221: ld r6,24(r4)
  75. addi r4,r4,32
  76. 70: std r9,0(r3)
  77. 270: std r8,8(r3)
  78. 22: ld r9,0(r4)
  79. 222: ld r8,8(r4)
  80. 71: std r7,16(r3)
  81. 271: std r6,24(r3)
  82. addi r3,r3,32
  83. bdnz 21b
  84. 72: std r9,0(r3)
  85. 272: std r8,8(r3)
  86. andi. r5,r5,0xf
  87. beq+ 3f
  88. addi r4,r4,16
  89. .Ldo_tail:
  90. addi r3,r3,16
  91. bf cr7*4+0,246f
  92. 244: ld r9,0(r4)
  93. addi r4,r4,8
  94. 245: std r9,0(r3)
  95. addi r3,r3,8
  96. 246: bf cr7*4+1,1f
  97. 23: lwz r9,0(r4)
  98. addi r4,r4,4
  99. 73: stw r9,0(r3)
  100. addi r3,r3,4
  101. 1: bf cr7*4+2,2f
  102. 44: lhz r9,0(r4)
  103. addi r4,r4,2
  104. 74: sth r9,0(r3)
  105. addi r3,r3,2
  106. 2: bf cr7*4+3,3f
  107. 45: lbz r9,0(r4)
  108. 75: stb r9,0(r3)
  109. 3: li r3,0
  110. blr
  111. .Lsrc_unaligned:
  112. srdi r6,r5,3
  113. addi r5,r5,-16
  114. subf r4,r0,r4
  115. srdi r7,r5,4
  116. sldi r10,r0,3
  117. cmpldi cr6,r6,3
  118. andi. r5,r5,7
  119. mtctr r7
  120. subfic r11,r10,64
  121. add r5,r5,r0
  122. bt cr7*4+0,28f
  123. 24: ld r9,0(r4) /* 3+2n loads, 2+2n stores */
  124. 25: ld r0,8(r4)
  125. sLd r6,r9,r10
  126. 26: ldu r9,16(r4)
  127. sHd r7,r0,r11
  128. sLd r8,r0,r10
  129. or r7,r7,r6
  130. blt cr6,79f
  131. 27: ld r0,8(r4)
  132. b 2f
  133. 28: ld r0,0(r4) /* 4+2n loads, 3+2n stores */
  134. 29: ldu r9,8(r4)
  135. sLd r8,r0,r10
  136. addi r3,r3,-8
  137. blt cr6,5f
  138. 30: ld r0,8(r4)
  139. sHd r12,r9,r11
  140. sLd r6,r9,r10
  141. 31: ldu r9,16(r4)
  142. or r12,r8,r12
  143. sHd r7,r0,r11
  144. sLd r8,r0,r10
  145. addi r3,r3,16
  146. beq cr6,78f
  147. 1: or r7,r7,r6
  148. 32: ld r0,8(r4)
  149. 76: std r12,8(r3)
  150. 2: sHd r12,r9,r11
  151. sLd r6,r9,r10
  152. 33: ldu r9,16(r4)
  153. or r12,r8,r12
  154. 77: stdu r7,16(r3)
  155. sHd r7,r0,r11
  156. sLd r8,r0,r10
  157. bdnz 1b
  158. 78: std r12,8(r3)
  159. or r7,r7,r6
  160. 79: std r7,16(r3)
  161. 5: sHd r12,r9,r11
  162. or r12,r8,r12
  163. 80: std r12,24(r3)
  164. bne 6f
  165. li r3,0
  166. blr
  167. 6: cmpwi cr1,r5,8
  168. addi r3,r3,32
  169. sLd r9,r9,r10
  170. ble cr1,7f
  171. 34: ld r0,8(r4)
  172. sHd r7,r0,r11
  173. or r9,r7,r9
  174. 7:
  175. bf cr7*4+1,1f
  176. #ifdef __BIG_ENDIAN__
  177. rotldi r9,r9,32
  178. #endif
  179. 94: stw r9,0(r3)
  180. #ifdef __LITTLE_ENDIAN__
  181. rotrdi r9,r9,32
  182. #endif
  183. addi r3,r3,4
  184. 1: bf cr7*4+2,2f
  185. #ifdef __BIG_ENDIAN__
  186. rotldi r9,r9,16
  187. #endif
  188. 95: sth r9,0(r3)
  189. #ifdef __LITTLE_ENDIAN__
  190. rotrdi r9,r9,16
  191. #endif
  192. addi r3,r3,2
  193. 2: bf cr7*4+3,3f
  194. #ifdef __BIG_ENDIAN__
  195. rotldi r9,r9,8
  196. #endif
  197. 96: stb r9,0(r3)
  198. #ifdef __LITTLE_ENDIAN__
  199. rotrdi r9,r9,8
  200. #endif
  201. 3: li r3,0
  202. blr
  203. .Ldst_unaligned:
  204. PPC_MTOCRF(0x01,r6) /* put #bytes to 8B bdry into cr7 */
  205. subf r5,r6,r5
  206. li r7,0
  207. cmpldi cr1,r5,16
  208. bf cr7*4+3,1f
  209. 35: lbz r0,0(r4)
  210. 81: stb r0,0(r3)
  211. addi r7,r7,1
  212. 1: bf cr7*4+2,2f
  213. 36: lhzx r0,r7,r4
  214. 82: sthx r0,r7,r3
  215. addi r7,r7,2
  216. 2: bf cr7*4+1,3f
  217. 37: lwzx r0,r7,r4
  218. 83: stwx r0,r7,r3
  219. 3: PPC_MTOCRF(0x01,r5)
  220. add r4,r6,r4
  221. add r3,r6,r3
  222. b .Ldst_aligned
  223. .Lshort_copy:
  224. bf cr7*4+0,1f
  225. 38: lwz r0,0(r4)
  226. 39: lwz r9,4(r4)
  227. addi r4,r4,8
  228. 84: stw r0,0(r3)
  229. 85: stw r9,4(r3)
  230. addi r3,r3,8
  231. 1: bf cr7*4+1,2f
  232. 40: lwz r0,0(r4)
  233. addi r4,r4,4
  234. 86: stw r0,0(r3)
  235. addi r3,r3,4
  236. 2: bf cr7*4+2,3f
  237. 41: lhz r0,0(r4)
  238. addi r4,r4,2
  239. 87: sth r0,0(r3)
  240. addi r3,r3,2
  241. 3: bf cr7*4+3,4f
  242. 42: lbz r0,0(r4)
  243. 88: stb r0,0(r3)
  244. 4: li r3,0
  245. blr
  246. /*
  247. * exception handlers follow
  248. * we have to return the number of bytes not copied
  249. * for an exception on a load, we set the rest of the destination to 0
  250. */
  251. 136:
  252. 137:
  253. add r3,r3,r7
  254. b 1f
  255. 130:
  256. 131:
  257. addi r3,r3,8
  258. 120:
  259. 320:
  260. 122:
  261. 322:
  262. 124:
  263. 125:
  264. 126:
  265. 127:
  266. 128:
  267. 129:
  268. 133:
  269. addi r3,r3,8
  270. 132:
  271. addi r3,r3,8
  272. 121:
  273. 321:
  274. 344:
  275. 134:
  276. 135:
  277. 138:
  278. 139:
  279. 140:
  280. 141:
  281. 142:
  282. 123:
  283. 144:
  284. 145:
  285. /*
  286. * here we have had a fault on a load and r3 points to the first
  287. * unmodified byte of the destination
  288. */
  289. 1: ld r6,-24(r1)
  290. ld r4,-16(r1)
  291. ld r5,-8(r1)
  292. subf r6,r6,r3
  293. add r4,r4,r6
  294. subf r5,r6,r5 /* #bytes left to go */
  295. /*
  296. * first see if we can copy any more bytes before hitting another exception
  297. */
  298. mtctr r5
  299. 43: lbz r0,0(r4)
  300. addi r4,r4,1
  301. 89: stb r0,0(r3)
  302. addi r3,r3,1
  303. bdnz 43b
  304. li r3,0 /* huh? all copied successfully this time? */
  305. blr
  306. /*
  307. * here we have trapped again, need to clear ctr bytes starting at r3
  308. */
  309. 143: mfctr r5
  310. li r0,0
  311. mr r4,r3
  312. mr r3,r5 /* return the number of bytes not copied */
  313. 1: andi. r9,r4,7
  314. beq 3f
  315. 90: stb r0,0(r4)
  316. addic. r5,r5,-1
  317. addi r4,r4,1
  318. bne 1b
  319. blr
  320. 3: cmpldi cr1,r5,8
  321. srdi r9,r5,3
  322. andi. r5,r5,7
  323. blt cr1,93f
  324. mtctr r9
  325. 91: std r0,0(r4)
  326. addi r4,r4,8
  327. bdnz 91b
  328. 93: beqlr
  329. mtctr r5
  330. 92: stb r0,0(r4)
  331. addi r4,r4,1
  332. bdnz 92b
  333. blr
  334. /*
  335. * exception handlers for stores: we just need to work
  336. * out how many bytes weren't copied
  337. */
  338. 182:
  339. 183:
  340. add r3,r3,r7
  341. b 1f
  342. 371:
  343. 180:
  344. addi r3,r3,8
  345. 171:
  346. 177:
  347. 179:
  348. addi r3,r3,8
  349. 370:
  350. 372:
  351. 176:
  352. 178:
  353. addi r3,r3,4
  354. 185:
  355. addi r3,r3,4
  356. 170:
  357. 172:
  358. 345:
  359. 173:
  360. 174:
  361. 175:
  362. 181:
  363. 184:
  364. 186:
  365. 187:
  366. 188:
  367. 189:
  368. 194:
  369. 195:
  370. 196:
  371. 1:
  372. ld r6,-24(r1)
  373. ld r5,-8(r1)
  374. add r6,r6,r5
  375. subf r3,r3,r6 /* #bytes not copied */
  376. 190:
  377. 191:
  378. 192:
  379. blr /* #bytes not copied in r3 */
  380. .section __ex_table,"a"
  381. .align 3
  382. .llong 20b,120b
  383. .llong 220b,320b
  384. .llong 21b,121b
  385. .llong 221b,321b
  386. .llong 70b,170b
  387. .llong 270b,370b
  388. .llong 22b,122b
  389. .llong 222b,322b
  390. .llong 71b,171b
  391. .llong 271b,371b
  392. .llong 72b,172b
  393. .llong 272b,372b
  394. .llong 244b,344b
  395. .llong 245b,345b
  396. .llong 23b,123b
  397. .llong 73b,173b
  398. .llong 44b,144b
  399. .llong 74b,174b
  400. .llong 45b,145b
  401. .llong 75b,175b
  402. .llong 24b,124b
  403. .llong 25b,125b
  404. .llong 26b,126b
  405. .llong 27b,127b
  406. .llong 28b,128b
  407. .llong 29b,129b
  408. .llong 30b,130b
  409. .llong 31b,131b
  410. .llong 32b,132b
  411. .llong 76b,176b
  412. .llong 33b,133b
  413. .llong 77b,177b
  414. .llong 78b,178b
  415. .llong 79b,179b
  416. .llong 80b,180b
  417. .llong 34b,134b
  418. .llong 94b,194b
  419. .llong 95b,195b
  420. .llong 96b,196b
  421. .llong 35b,135b
  422. .llong 81b,181b
  423. .llong 36b,136b
  424. .llong 82b,182b
  425. .llong 37b,137b
  426. .llong 83b,183b
  427. .llong 38b,138b
  428. .llong 39b,139b
  429. .llong 84b,184b
  430. .llong 85b,185b
  431. .llong 40b,140b
  432. .llong 86b,186b
  433. .llong 41b,141b
  434. .llong 87b,187b
  435. .llong 42b,142b
  436. .llong 88b,188b
  437. .llong 43b,143b
  438. .llong 89b,189b
  439. .llong 90b,190b
  440. .llong 91b,191b
  441. .llong 92b,192b
  442. .text
  443. /*
  444. * Routine to copy a whole page of data, optimized for POWER4.
  445. * On POWER4 it is more than 50% faster than the simple loop
  446. * above (following the .Ldst_aligned label).
  447. */
  448. .Lcopy_page_4K:
  449. std r31,-32(1)
  450. std r30,-40(1)
  451. std r29,-48(1)
  452. std r28,-56(1)
  453. std r27,-64(1)
  454. std r26,-72(1)
  455. std r25,-80(1)
  456. std r24,-88(1)
  457. std r23,-96(1)
  458. std r22,-104(1)
  459. std r21,-112(1)
  460. std r20,-120(1)
  461. li r5,4096/32 - 1
  462. addi r3,r3,-8
  463. li r0,5
  464. 0: addi r5,r5,-24
  465. mtctr r0
  466. 20: ld r22,640(4)
  467. 21: ld r21,512(4)
  468. 22: ld r20,384(4)
  469. 23: ld r11,256(4)
  470. 24: ld r9,128(4)
  471. 25: ld r7,0(4)
  472. 26: ld r25,648(4)
  473. 27: ld r24,520(4)
  474. 28: ld r23,392(4)
  475. 29: ld r10,264(4)
  476. 30: ld r8,136(4)
  477. 31: ldu r6,8(4)
  478. cmpwi r5,24
  479. 1:
  480. 32: std r22,648(3)
  481. 33: std r21,520(3)
  482. 34: std r20,392(3)
  483. 35: std r11,264(3)
  484. 36: std r9,136(3)
  485. 37: std r7,8(3)
  486. 38: ld r28,648(4)
  487. 39: ld r27,520(4)
  488. 40: ld r26,392(4)
  489. 41: ld r31,264(4)
  490. 42: ld r30,136(4)
  491. 43: ld r29,8(4)
  492. 44: std r25,656(3)
  493. 45: std r24,528(3)
  494. 46: std r23,400(3)
  495. 47: std r10,272(3)
  496. 48: std r8,144(3)
  497. 49: std r6,16(3)
  498. 50: ld r22,656(4)
  499. 51: ld r21,528(4)
  500. 52: ld r20,400(4)
  501. 53: ld r11,272(4)
  502. 54: ld r9,144(4)
  503. 55: ld r7,16(4)
  504. 56: std r28,664(3)
  505. 57: std r27,536(3)
  506. 58: std r26,408(3)
  507. 59: std r31,280(3)
  508. 60: std r30,152(3)
  509. 61: stdu r29,24(3)
  510. 62: ld r25,664(4)
  511. 63: ld r24,536(4)
  512. 64: ld r23,408(4)
  513. 65: ld r10,280(4)
  514. 66: ld r8,152(4)
  515. 67: ldu r6,24(4)
  516. bdnz 1b
  517. 68: std r22,648(3)
  518. 69: std r21,520(3)
  519. 70: std r20,392(3)
  520. 71: std r11,264(3)
  521. 72: std r9,136(3)
  522. 73: std r7,8(3)
  523. 74: addi r4,r4,640
  524. 75: addi r3,r3,648
  525. bge 0b
  526. mtctr r5
  527. 76: ld r7,0(4)
  528. 77: ld r8,8(4)
  529. 78: ldu r9,16(4)
  530. 3:
  531. 79: ld r10,8(4)
  532. 80: std r7,8(3)
  533. 81: ld r7,16(4)
  534. 82: std r8,16(3)
  535. 83: ld r8,24(4)
  536. 84: std r9,24(3)
  537. 85: ldu r9,32(4)
  538. 86: stdu r10,32(3)
  539. bdnz 3b
  540. 4:
  541. 87: ld r10,8(4)
  542. 88: std r7,8(3)
  543. 89: std r8,16(3)
  544. 90: std r9,24(3)
  545. 91: std r10,32(3)
  546. 9: ld r20,-120(1)
  547. ld r21,-112(1)
  548. ld r22,-104(1)
  549. ld r23,-96(1)
  550. ld r24,-88(1)
  551. ld r25,-80(1)
  552. ld r26,-72(1)
  553. ld r27,-64(1)
  554. ld r28,-56(1)
  555. ld r29,-48(1)
  556. ld r30,-40(1)
  557. ld r31,-32(1)
  558. li r3,0
  559. blr
  560. /*
  561. * on an exception, reset to the beginning and jump back into the
  562. * standard __copy_tofrom_user
  563. */
  564. 100: ld r20,-120(1)
  565. ld r21,-112(1)
  566. ld r22,-104(1)
  567. ld r23,-96(1)
  568. ld r24,-88(1)
  569. ld r25,-80(1)
  570. ld r26,-72(1)
  571. ld r27,-64(1)
  572. ld r28,-56(1)
  573. ld r29,-48(1)
  574. ld r30,-40(1)
  575. ld r31,-32(1)
  576. ld r3,-24(r1)
  577. ld r4,-16(r1)
  578. li r5,4096
  579. b .Ldst_aligned
  580. .section __ex_table,"a"
  581. .align 3
  582. .llong 20b,100b
  583. .llong 21b,100b
  584. .llong 22b,100b
  585. .llong 23b,100b
  586. .llong 24b,100b
  587. .llong 25b,100b
  588. .llong 26b,100b
  589. .llong 27b,100b
  590. .llong 28b,100b
  591. .llong 29b,100b
  592. .llong 30b,100b
  593. .llong 31b,100b
  594. .llong 32b,100b
  595. .llong 33b,100b
  596. .llong 34b,100b
  597. .llong 35b,100b
  598. .llong 36b,100b
  599. .llong 37b,100b
  600. .llong 38b,100b
  601. .llong 39b,100b
  602. .llong 40b,100b
  603. .llong 41b,100b
  604. .llong 42b,100b
  605. .llong 43b,100b
  606. .llong 44b,100b
  607. .llong 45b,100b
  608. .llong 46b,100b
  609. .llong 47b,100b
  610. .llong 48b,100b
  611. .llong 49b,100b
  612. .llong 50b,100b
  613. .llong 51b,100b
  614. .llong 52b,100b
  615. .llong 53b,100b
  616. .llong 54b,100b
  617. .llong 55b,100b
  618. .llong 56b,100b
  619. .llong 57b,100b
  620. .llong 58b,100b
  621. .llong 59b,100b
  622. .llong 60b,100b
  623. .llong 61b,100b
  624. .llong 62b,100b
  625. .llong 63b,100b
  626. .llong 64b,100b
  627. .llong 65b,100b
  628. .llong 66b,100b
  629. .llong 67b,100b
  630. .llong 68b,100b
  631. .llong 69b,100b
  632. .llong 70b,100b
  633. .llong 71b,100b
  634. .llong 72b,100b
  635. .llong 73b,100b
  636. .llong 74b,100b
  637. .llong 75b,100b
  638. .llong 76b,100b
  639. .llong 77b,100b
  640. .llong 78b,100b
  641. .llong 79b,100b
  642. .llong 80b,100b
  643. .llong 81b,100b
  644. .llong 82b,100b
  645. .llong 83b,100b
  646. .llong 84b,100b
  647. .llong 85b,100b
  648. .llong 86b,100b
  649. .llong 87b,100b
  650. .llong 88b,100b
  651. .llong 89b,100b
  652. .llong 90b,100b
  653. .llong 91b,100b