copy_page.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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
  12. * @to: P1 address
  13. * @from: P1 address
  14. *
  15. * void copy_page(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)
  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_SH4)
  43. movca.l r0,@r10
  44. mov r10,r0
  45. #else
  46. mov.l r0,@r10
  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. .balign 4
  69. .Lpsz: .long PAGE_SIZE
  70. /*
  71. * __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
  72. * Return the number of bytes NOT copied
  73. */
  74. #define EX(...) \
  75. 9999: __VA_ARGS__ ; \
  76. .section __ex_table, "a"; \
  77. .long 9999b, 6000f ; \
  78. .previous
  79. ENTRY(__copy_user)
  80. ! Check if small number of bytes
  81. mov #11,r0
  82. mov r4,r3
  83. cmp/gt r0,r6 ! r6 (len) > r0 (11)
  84. bf/s .L_cleanup_loop_no_pop
  85. add r6,r3 ! last destination address
  86. ! Calculate bytes needed to align to src
  87. mov.l r11,@-r15
  88. neg r5,r0
  89. mov.l r10,@-r15
  90. add #4,r0
  91. mov.l r9,@-r15
  92. and #3,r0
  93. mov.l r8,@-r15
  94. tst r0,r0
  95. bt 2f
  96. 1:
  97. ! Copy bytes to long word align src
  98. EX( mov.b @r5+,r1 )
  99. dt r0
  100. add #-1,r6
  101. EX( mov.b r1,@r4 )
  102. bf/s 1b
  103. add #1,r4
  104. ! Jump to appropriate routine depending on dest
  105. 2: mov #3,r1
  106. mov r6, r2
  107. and r4,r1
  108. shlr2 r2
  109. shll2 r1
  110. mova .L_jump_tbl,r0
  111. mov.l @(r0,r1),r1
  112. jmp @r1
  113. nop
  114. .align 2
  115. .L_jump_tbl:
  116. .long .L_dest00
  117. .long .L_dest01
  118. .long .L_dest10
  119. .long .L_dest11
  120. /*
  121. * Come here if there are less than 12 bytes to copy
  122. *
  123. * Keep the branch target close, so the bf/s callee doesn't overflow
  124. * and result in a more expensive branch being inserted. This is the
  125. * fast-path for small copies, the jump via the jump table will hit the
  126. * default slow-path cleanup. -PFM.
  127. */
  128. .L_cleanup_loop_no_pop:
  129. tst r6,r6 ! Check explicitly for zero
  130. bt 1f
  131. 2:
  132. EX( mov.b @r5+,r0 )
  133. dt r6
  134. EX( mov.b r0,@r4 )
  135. bf/s 2b
  136. add #1,r4
  137. 1: mov #0,r0 ! normal return
  138. 5000:
  139. # Exception handler:
  140. .section .fixup, "ax"
  141. 6000:
  142. mov.l 8000f,r1
  143. mov r3,r0
  144. jmp @r1
  145. sub r4,r0
  146. .align 2
  147. 8000: .long 5000b
  148. .previous
  149. rts
  150. nop
  151. ! Destination = 00
  152. .L_dest00:
  153. ! Skip the large copy for small transfers
  154. mov #(32+32-4), r0
  155. cmp/gt r6, r0 ! r0 (60) > r6 (len)
  156. bt 1f
  157. ! Align dest to a 32 byte boundary
  158. neg r4,r0
  159. add #0x20, r0
  160. and #0x1f, r0
  161. tst r0, r0
  162. bt 2f
  163. sub r0, r6
  164. shlr2 r0
  165. 3:
  166. EX( mov.l @r5+,r1 )
  167. dt r0
  168. EX( mov.l r1,@r4 )
  169. bf/s 3b
  170. add #4,r4
  171. 2:
  172. EX( mov.l @r5+,r0 )
  173. EX( mov.l @r5+,r1 )
  174. EX( mov.l @r5+,r2 )
  175. EX( mov.l @r5+,r7 )
  176. EX( mov.l @r5+,r8 )
  177. EX( mov.l @r5+,r9 )
  178. EX( mov.l @r5+,r10 )
  179. EX( mov.l @r5+,r11 )
  180. #ifdef CONFIG_CPU_SH4
  181. EX( movca.l r0,@r4 )
  182. #else
  183. EX( mov.l r0,@r4 )
  184. #endif
  185. add #-32, r6
  186. EX( mov.l r1,@(4,r4) )
  187. mov #32, r0
  188. EX( mov.l r2,@(8,r4) )
  189. cmp/gt r6, r0 ! r0 (32) > r6 (len)
  190. EX( mov.l r7,@(12,r4) )
  191. EX( mov.l r8,@(16,r4) )
  192. EX( mov.l r9,@(20,r4) )
  193. EX( mov.l r10,@(24,r4) )
  194. EX( mov.l r11,@(28,r4) )
  195. bf/s 2b
  196. add #32,r4
  197. 1: mov r6, r0
  198. shlr2 r0
  199. tst r0, r0
  200. bt .L_cleanup
  201. 1:
  202. EX( mov.l @r5+,r1 )
  203. dt r0
  204. EX( mov.l r1,@r4 )
  205. bf/s 1b
  206. add #4,r4
  207. bra .L_cleanup
  208. nop
  209. ! Destination = 10
  210. .L_dest10:
  211. mov r2,r7
  212. shlr2 r7
  213. shlr r7
  214. tst r7,r7
  215. mov #7,r0
  216. bt/s 1f
  217. and r0,r2
  218. 2:
  219. dt r7
  220. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  221. EX( mov.l @r5+,r0 )
  222. EX( mov.l @r5+,r1 )
  223. EX( mov.l @r5+,r8 )
  224. EX( mov.l @r5+,r9 )
  225. EX( mov.l @r5+,r10 )
  226. EX( mov.w r0,@r4 )
  227. add #2,r4
  228. xtrct r1,r0
  229. xtrct r8,r1
  230. xtrct r9,r8
  231. xtrct r10,r9
  232. EX( mov.l r0,@r4 )
  233. EX( mov.l r1,@(4,r4) )
  234. EX( mov.l r8,@(8,r4) )
  235. EX( mov.l r9,@(12,r4) )
  236. EX( mov.l @r5+,r1 )
  237. EX( mov.l @r5+,r8 )
  238. EX( mov.l @r5+,r0 )
  239. xtrct r1,r10
  240. xtrct r8,r1
  241. xtrct r0,r8
  242. shlr16 r0
  243. EX( mov.l r10,@(16,r4) )
  244. EX( mov.l r1,@(20,r4) )
  245. EX( mov.l r8,@(24,r4) )
  246. EX( mov.w r0,@(28,r4) )
  247. bf/s 2b
  248. add #30,r4
  249. #else
  250. EX( mov.l @(28,r5),r0 )
  251. EX( mov.l @(24,r5),r8 )
  252. EX( mov.l @(20,r5),r9 )
  253. EX( mov.l @(16,r5),r10 )
  254. EX( mov.w r0,@(30,r4) )
  255. add #-2,r4
  256. xtrct r8,r0
  257. xtrct r9,r8
  258. xtrct r10,r9
  259. EX( mov.l r0,@(28,r4) )
  260. EX( mov.l r8,@(24,r4) )
  261. EX( mov.l r9,@(20,r4) )
  262. EX( mov.l @(12,r5),r0 )
  263. EX( mov.l @(8,r5),r8 )
  264. xtrct r0,r10
  265. EX( mov.l @(4,r5),r9 )
  266. mov.l r10,@(16,r4)
  267. EX( mov.l @r5,r10 )
  268. xtrct r8,r0
  269. xtrct r9,r8
  270. xtrct r10,r9
  271. EX( mov.l r0,@(12,r4) )
  272. EX( mov.l r8,@(8,r4) )
  273. swap.w r10,r0
  274. EX( mov.l r9,@(4,r4) )
  275. EX( mov.w r0,@(2,r4) )
  276. add #32,r5
  277. bf/s 2b
  278. add #34,r4
  279. #endif
  280. tst r2,r2
  281. bt .L_cleanup
  282. 1: ! Read longword, write two words per iteration
  283. EX( mov.l @r5+,r0 )
  284. dt r2
  285. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  286. EX( mov.w r0,@r4 )
  287. shlr16 r0
  288. EX( mov.w r0,@(2,r4) )
  289. #else
  290. EX( mov.w r0,@(2,r4) )
  291. shlr16 r0
  292. EX( mov.w r0,@r4 )
  293. #endif
  294. bf/s 1b
  295. add #4,r4
  296. bra .L_cleanup
  297. nop
  298. ! Destination = 01 or 11
  299. .L_dest01:
  300. .L_dest11:
  301. ! Read longword, write byte, word, byte per iteration
  302. EX( mov.l @r5+,r0 )
  303. dt r2
  304. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  305. EX( mov.b r0,@r4 )
  306. shlr8 r0
  307. add #1,r4
  308. EX( mov.w r0,@r4 )
  309. shlr16 r0
  310. EX( mov.b r0,@(2,r4) )
  311. bf/s .L_dest01
  312. add #3,r4
  313. #else
  314. EX( mov.b r0,@(3,r4) )
  315. shlr8 r0
  316. swap.w r0,r7
  317. EX( mov.b r7,@r4 )
  318. add #1,r4
  319. EX( mov.w r0,@r4 )
  320. bf/s .L_dest01
  321. add #3,r4
  322. #endif
  323. ! Cleanup last few bytes
  324. .L_cleanup:
  325. mov r6,r0
  326. and #3,r0
  327. tst r0,r0
  328. bt .L_exit
  329. mov r0,r6
  330. .L_cleanup_loop:
  331. EX( mov.b @r5+,r0 )
  332. dt r6
  333. EX( mov.b r0,@r4 )
  334. bf/s .L_cleanup_loop
  335. add #1,r4
  336. .L_exit:
  337. mov #0,r0 ! normal return
  338. 5000:
  339. # Exception handler:
  340. .section .fixup, "ax"
  341. 6000:
  342. mov.l 8000f,r1
  343. mov r3,r0
  344. jmp @r1
  345. sub r4,r0
  346. .align 2
  347. 8000: .long 5000b
  348. .previous
  349. mov.l @r15+,r8
  350. mov.l @r15+,r9
  351. mov.l @r15+,r10
  352. rts
  353. mov.l @r15+,r11