copy_page.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * copy_page, __copy_user_page, __copy_user implementation of SuperH
  3. *
  4. * Copyright (C) 2001 Niibe Yutaka & Kaz Kojima
  5. * Copyright (C) 2002 Toshinobu Sugioka
  6. * Copyright (C) 2006 Paul Mundt
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/page.h>
  10. /*
  11. * copy_page_slow
  12. * @to: P1 address
  13. * @from: P1 address
  14. *
  15. * void copy_page_slow(void *to, void *from)
  16. */
  17. /*
  18. * r0, r1, r2, r3, r4, r5, r6, r7 --- scratch
  19. * r8 --- from + PAGE_SIZE
  20. * r9 --- not used
  21. * r10 --- to
  22. * r11 --- from
  23. */
  24. ENTRY(copy_page_slow)
  25. mov.l r8,@-r15
  26. mov.l r10,@-r15
  27. mov.l r11,@-r15
  28. mov r4,r10
  29. mov r5,r11
  30. mov r5,r8
  31. mov.l .Lpsz,r0
  32. add r0,r8
  33. !
  34. 1: mov.l @r11+,r0
  35. mov.l @r11+,r1
  36. mov.l @r11+,r2
  37. mov.l @r11+,r3
  38. mov.l @r11+,r4
  39. mov.l @r11+,r5
  40. mov.l @r11+,r6
  41. mov.l @r11+,r7
  42. #if defined(CONFIG_CPU_SH3)
  43. mov.l r0,@r10
  44. #elif defined(CONFIG_CPU_SH4)
  45. movca.l r0,@r10
  46. mov r10,r0
  47. #endif
  48. add #32,r10
  49. mov.l r7,@-r10
  50. mov.l r6,@-r10
  51. mov.l r5,@-r10
  52. mov.l r4,@-r10
  53. mov.l r3,@-r10
  54. mov.l r2,@-r10
  55. mov.l r1,@-r10
  56. #if defined(CONFIG_CPU_SH4)
  57. ocbwb @r0
  58. #endif
  59. cmp/eq r11,r8
  60. bf/s 1b
  61. add #28,r10
  62. !
  63. mov.l @r15+,r11
  64. mov.l @r15+,r10
  65. mov.l @r15+,r8
  66. rts
  67. nop
  68. #if defined(CONFIG_CPU_SH4)
  69. /*
  70. * __copy_user_page
  71. * @to: P1 address (with same color)
  72. * @from: P1 address
  73. * @orig_to: P1 address
  74. *
  75. * void __copy_user_page(void *to, void *from, void *orig_to)
  76. */
  77. /*
  78. * r0, r1, r2, r3, r4, r5, r6, r7 --- scratch
  79. * r8 --- from + PAGE_SIZE
  80. * r9 --- orig_to
  81. * r10 --- to
  82. * r11 --- from
  83. */
  84. ENTRY(__copy_user_page)
  85. mov.l r8,@-r15
  86. mov.l r9,@-r15
  87. mov.l r10,@-r15
  88. mov.l r11,@-r15
  89. mov r4,r10
  90. mov r5,r11
  91. mov r6,r9
  92. mov r5,r8
  93. mov.l .Lpsz,r0
  94. add r0,r8
  95. !
  96. 1: ocbi @r9
  97. add #32,r9
  98. mov.l @r11+,r0
  99. mov.l @r11+,r1
  100. mov.l @r11+,r2
  101. mov.l @r11+,r3
  102. mov.l @r11+,r4
  103. mov.l @r11+,r5
  104. mov.l @r11+,r6
  105. mov.l @r11+,r7
  106. movca.l r0,@r10
  107. mov r10,r0
  108. add #32,r10
  109. mov.l r7,@-r10
  110. mov.l r6,@-r10
  111. mov.l r5,@-r10
  112. mov.l r4,@-r10
  113. mov.l r3,@-r10
  114. mov.l r2,@-r10
  115. mov.l r1,@-r10
  116. ocbwb @r0
  117. cmp/eq r11,r8
  118. bf/s 1b
  119. add #28,r10
  120. !
  121. mov.l @r15+,r11
  122. mov.l @r15+,r10
  123. mov.l @r15+,r9
  124. mov.l @r15+,r8
  125. rts
  126. nop
  127. #endif
  128. .align 2
  129. .Lpsz: .long PAGE_SIZE
  130. /*
  131. * __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
  132. * Return the number of bytes NOT copied
  133. */
  134. #define EX(...) \
  135. 9999: __VA_ARGS__ ; \
  136. .section __ex_table, "a"; \
  137. .long 9999b, 6000f ; \
  138. .previous
  139. ENTRY(__copy_user)
  140. ! Check if small number of bytes
  141. mov #11,r0
  142. mov r4,r3
  143. cmp/gt r0,r6 ! r6 (len) > r0 (11)
  144. bf/s .L_cleanup_loop_no_pop
  145. add r6,r3 ! last destination address
  146. ! Calculate bytes needed to align to src
  147. mov.l r11,@-r15
  148. neg r5,r0
  149. mov.l r10,@-r15
  150. add #4,r0
  151. mov.l r9,@-r15
  152. and #3,r0
  153. mov.l r8,@-r15
  154. tst r0,r0
  155. bt 2f
  156. 1:
  157. ! Copy bytes to long word align src
  158. EX( mov.b @r5+,r1 )
  159. dt r0
  160. add #-1,r6
  161. EX( mov.b r1,@r4 )
  162. bf/s 1b
  163. add #1,r4
  164. ! Jump to appropriate routine depending on dest
  165. 2: mov #3,r1
  166. mov r6, r2
  167. and r4,r1
  168. shlr2 r2
  169. shll2 r1
  170. mova .L_jump_tbl,r0
  171. mov.l @(r0,r1),r1
  172. jmp @r1
  173. nop
  174. .align 2
  175. .L_jump_tbl:
  176. .long .L_dest00
  177. .long .L_dest01
  178. .long .L_dest10
  179. .long .L_dest11
  180. /*
  181. * Come here if there are less than 12 bytes to copy
  182. *
  183. * Keep the branch target close, so the bf/s callee doesn't overflow
  184. * and result in a more expensive branch being inserted. This is the
  185. * fast-path for small copies, the jump via the jump table will hit the
  186. * default slow-path cleanup. -PFM.
  187. */
  188. .L_cleanup_loop_no_pop:
  189. tst r6,r6 ! Check explicitly for zero
  190. bt 1f
  191. 2:
  192. EX( mov.b @r5+,r0 )
  193. dt r6
  194. EX( mov.b r0,@r4 )
  195. bf/s 2b
  196. add #1,r4
  197. 1: mov #0,r0 ! normal return
  198. 5000:
  199. # Exception handler:
  200. .section .fixup, "ax"
  201. 6000:
  202. mov.l 8000f,r1
  203. mov r3,r0
  204. jmp @r1
  205. sub r4,r0
  206. .align 2
  207. 8000: .long 5000b
  208. .previous
  209. rts
  210. nop
  211. ! Destination = 00
  212. .L_dest00:
  213. ! Skip the large copy for small transfers
  214. mov #(32+32-4), r0
  215. cmp/gt r6, r0 ! r0 (60) > r6 (len)
  216. bt 1f
  217. ! Align dest to a 32 byte boundary
  218. neg r4,r0
  219. add #0x20, r0
  220. and #0x1f, r0
  221. tst r0, r0
  222. bt 2f
  223. sub r0, r6
  224. shlr2 r0
  225. 3:
  226. EX( mov.l @r5+,r1 )
  227. dt r0
  228. EX( mov.l r1,@r4 )
  229. bf/s 3b
  230. add #4,r4
  231. 2:
  232. EX( mov.l @r5+,r0 )
  233. EX( mov.l @r5+,r1 )
  234. EX( mov.l @r5+,r2 )
  235. EX( mov.l @r5+,r7 )
  236. EX( mov.l @r5+,r8 )
  237. EX( mov.l @r5+,r9 )
  238. EX( mov.l @r5+,r10 )
  239. EX( mov.l @r5+,r11 )
  240. #ifdef CONFIG_CPU_SH4
  241. EX( movca.l r0,@r4 )
  242. #else
  243. EX( mov.l r0,@r4 )
  244. #endif
  245. add #-32, r6
  246. EX( mov.l r1,@(4,r4) )
  247. mov #32, r0
  248. EX( mov.l r2,@(8,r4) )
  249. cmp/gt r6, r0 ! r0 (32) > r6 (len)
  250. EX( mov.l r7,@(12,r4) )
  251. EX( mov.l r8,@(16,r4) )
  252. EX( mov.l r9,@(20,r4) )
  253. EX( mov.l r10,@(24,r4) )
  254. EX( mov.l r11,@(28,r4) )
  255. bf/s 2b
  256. add #32,r4
  257. 1: mov r6, r0
  258. shlr2 r0
  259. tst r0, r0
  260. bt .L_cleanup
  261. 1:
  262. EX( mov.l @r5+,r1 )
  263. dt r0
  264. EX( mov.l r1,@r4 )
  265. bf/s 1b
  266. add #4,r4
  267. bra .L_cleanup
  268. nop
  269. ! Destination = 10
  270. .L_dest10:
  271. mov r2,r7
  272. shlr2 r7
  273. shlr r7
  274. tst r7,r7
  275. mov #7,r0
  276. bt/s 1f
  277. and r0,r2
  278. 2:
  279. dt r7
  280. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  281. EX( mov.l @r5+,r0 )
  282. EX( mov.l @r5+,r1 )
  283. EX( mov.l @r5+,r8 )
  284. EX( mov.l @r5+,r9 )
  285. EX( mov.l @r5+,r10 )
  286. EX( mov.w r0,@r4 )
  287. add #2,r4
  288. xtrct r1,r0
  289. xtrct r8,r1
  290. xtrct r9,r8
  291. xtrct r10,r9
  292. EX( mov.l r0,@r4 )
  293. EX( mov.l r1,@(4,r4) )
  294. EX( mov.l r8,@(8,r4) )
  295. EX( mov.l r9,@(12,r4) )
  296. EX( mov.l @r5+,r1 )
  297. EX( mov.l @r5+,r8 )
  298. EX( mov.l @r5+,r0 )
  299. xtrct r1,r10
  300. xtrct r8,r1
  301. xtrct r0,r8
  302. shlr16 r0
  303. EX( mov.l r10,@(16,r4) )
  304. EX( mov.l r1,@(20,r4) )
  305. EX( mov.l r8,@(24,r4) )
  306. EX( mov.w r0,@(28,r4) )
  307. bf/s 2b
  308. add #30,r4
  309. #else
  310. EX( mov.l @(28,r5),r0 )
  311. EX( mov.l @(24,r5),r8 )
  312. EX( mov.l @(20,r5),r9 )
  313. EX( mov.l @(16,r5),r10 )
  314. EX( mov.w r0,@(30,r4) )
  315. add #-2,r4
  316. xtrct r8,r0
  317. xtrct r9,r8
  318. xtrct r10,r9
  319. EX( mov.l r0,@(28,r4) )
  320. EX( mov.l r8,@(24,r4) )
  321. EX( mov.l r9,@(20,r4) )
  322. EX( mov.l @(12,r5),r0 )
  323. EX( mov.l @(8,r5),r8 )
  324. xtrct r0,r10
  325. EX( mov.l @(4,r5),r9 )
  326. mov.l r10,@(16,r4)
  327. EX( mov.l @r5,r10 )
  328. xtrct r8,r0
  329. xtrct r9,r8
  330. xtrct r10,r9
  331. EX( mov.l r0,@(12,r4) )
  332. EX( mov.l r8,@(8,r4) )
  333. swap.w r10,r0
  334. EX( mov.l r9,@(4,r4) )
  335. EX( mov.w r0,@(2,r4) )
  336. add #32,r5
  337. bf/s 2b
  338. add #34,r4
  339. #endif
  340. tst r2,r2
  341. bt .L_cleanup
  342. 1: ! Read longword, write two words per iteration
  343. EX( mov.l @r5+,r0 )
  344. dt r2
  345. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  346. EX( mov.w r0,@r4 )
  347. shlr16 r0
  348. EX( mov.w r0,@(2,r4) )
  349. #else
  350. EX( mov.w r0,@(2,r4) )
  351. shlr16 r0
  352. EX( mov.w r0,@r4 )
  353. #endif
  354. bf/s 1b
  355. add #4,r4
  356. bra .L_cleanup
  357. nop
  358. ! Destination = 01 or 11
  359. .L_dest01:
  360. .L_dest11:
  361. ! Read longword, write byte, word, byte per iteration
  362. EX( mov.l @r5+,r0 )
  363. dt r2
  364. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  365. EX( mov.b r0,@r4 )
  366. shlr8 r0
  367. add #1,r4
  368. EX( mov.w r0,@r4 )
  369. shlr16 r0
  370. EX( mov.b r0,@(2,r4) )
  371. bf/s .L_dest01
  372. add #3,r4
  373. #else
  374. EX( mov.b r0,@(3,r4) )
  375. shlr8 r0
  376. swap.w r0,r7
  377. EX( mov.b r7,@r4 )
  378. add #1,r4
  379. EX( mov.w r0,@r4 )
  380. bf/s .L_dest01
  381. add #3,r4
  382. #endif
  383. ! Cleanup last few bytes
  384. .L_cleanup:
  385. mov r6,r0
  386. and #3,r0
  387. tst r0,r0
  388. bt .L_exit
  389. mov r0,r6
  390. .L_cleanup_loop:
  391. EX( mov.b @r5+,r0 )
  392. dt r6
  393. EX( mov.b r0,@r4 )
  394. bf/s .L_cleanup_loop
  395. add #1,r4
  396. .L_exit:
  397. mov #0,r0 ! normal return
  398. 5000:
  399. # Exception handler:
  400. .section .fixup, "ax"
  401. 6000:
  402. mov.l 8000f,r1
  403. mov r3,r0
  404. jmp @r1
  405. sub r4,r0
  406. .align 2
  407. 8000: .long 5000b
  408. .previous
  409. mov.l @r15+,r8
  410. mov.l @r15+,r9
  411. mov.l @r15+,r10
  412. rts
  413. mov.l @r15+,r11