copy_page.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. EX( movca.l r0,@r4 )
  241. add #-32, r6
  242. EX( mov.l r1,@(4,r4) )
  243. mov #32, r0
  244. EX( mov.l r2,@(8,r4) )
  245. cmp/gt r6, r0 ! r0 (32) > r6 (len)
  246. EX( mov.l r7,@(12,r4) )
  247. EX( mov.l r8,@(16,r4) )
  248. EX( mov.l r9,@(20,r4) )
  249. EX( mov.l r10,@(24,r4) )
  250. EX( mov.l r11,@(28,r4) )
  251. bf/s 2b
  252. add #32,r4
  253. 1: mov r6, r0
  254. shlr2 r0
  255. tst r0, r0
  256. bt .L_cleanup
  257. 1:
  258. EX( mov.l @r5+,r1 )
  259. dt r0
  260. EX( mov.l r1,@r4 )
  261. bf/s 1b
  262. add #4,r4
  263. bra .L_cleanup
  264. nop
  265. ! Destination = 10
  266. .L_dest10:
  267. mov r2,r7
  268. shlr2 r7
  269. shlr r7
  270. tst r7,r7
  271. mov #7,r0
  272. bt/s 1f
  273. and r0,r2
  274. 2:
  275. dt r7
  276. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  277. EX( mov.l @r5+,r0 )
  278. EX( mov.l @r5+,r1 )
  279. EX( mov.l @r5+,r8 )
  280. EX( mov.l @r5+,r9 )
  281. EX( mov.l @r5+,r10 )
  282. EX( mov.w r0,@r4 )
  283. add #2,r4
  284. xtrct r1,r0
  285. xtrct r8,r1
  286. xtrct r9,r8
  287. xtrct r10,r9
  288. EX( mov.l r0,@r4 )
  289. EX( mov.l r1,@(4,r4) )
  290. EX( mov.l r8,@(8,r4) )
  291. EX( mov.l r9,@(12,r4) )
  292. EX( mov.l @r5+,r1 )
  293. EX( mov.l @r5+,r8 )
  294. EX( mov.l @r5+,r0 )
  295. xtrct r1,r10
  296. xtrct r8,r1
  297. xtrct r0,r8
  298. shlr16 r0
  299. EX( mov.l r10,@(16,r4) )
  300. EX( mov.l r1,@(20,r4) )
  301. EX( mov.l r8,@(24,r4) )
  302. EX( mov.w r0,@(28,r4) )
  303. bf/s 2b
  304. add #30,r4
  305. #else
  306. EX( mov.l @(28,r5),r0 )
  307. EX( mov.l @(24,r5),r8 )
  308. EX( mov.l @(20,r5),r9 )
  309. EX( mov.l @(16,r5),r10 )
  310. EX( mov.w r0,@(30,r4) )
  311. add #-2,r4
  312. xtrct r8,r0
  313. xtrct r9,r8
  314. xtrct r10,r9
  315. EX( mov.l r0,@(28,r4) )
  316. EX( mov.l r8,@(24,r4) )
  317. EX( mov.l r9,@(20,r4) )
  318. EX( mov.l @(12,r5),r0 )
  319. EX( mov.l @(8,r5),r8 )
  320. xtrct r0,r10
  321. EX( mov.l @(4,r5),r9 )
  322. mov.l r10,@(16,r4)
  323. EX( mov.l @r5,r10 )
  324. xtrct r8,r0
  325. xtrct r9,r8
  326. xtrct r10,r9
  327. EX( mov.l r0,@(12,r4) )
  328. EX( mov.l r8,@(8,r4) )
  329. swap.w r10,r0
  330. EX( mov.l r9,@(4,r4) )
  331. EX( mov.w r0,@(2,r4) )
  332. add #32,r5
  333. bf/s 2b
  334. add #34,r4
  335. #endif
  336. tst r2,r2
  337. bt .L_cleanup
  338. 1: ! Read longword, write two words per iteration
  339. EX( mov.l @r5+,r0 )
  340. dt r2
  341. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  342. EX( mov.w r0,@r4 )
  343. shlr16 r0
  344. EX( mov.w r0,@(2,r4) )
  345. #else
  346. EX( mov.w r0,@(2,r4) )
  347. shlr16 r0
  348. EX( mov.w r0,@r4 )
  349. #endif
  350. bf/s 1b
  351. add #4,r4
  352. bra .L_cleanup
  353. nop
  354. ! Destination = 01 or 11
  355. .L_dest01:
  356. .L_dest11:
  357. ! Read longword, write byte, word, byte per iteration
  358. EX( mov.l @r5+,r0 )
  359. dt r2
  360. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  361. EX( mov.b r0,@r4 )
  362. shlr8 r0
  363. add #1,r4
  364. EX( mov.w r0,@r4 )
  365. shlr16 r0
  366. EX( mov.b r0,@(2,r4) )
  367. bf/s .L_dest01
  368. add #3,r4
  369. #else
  370. EX( mov.b r0,@(3,r4) )
  371. shlr8 r0
  372. swap.w r0,r7
  373. EX( mov.b r7,@r4 )
  374. add #1,r4
  375. EX( mov.w r0,@r4 )
  376. bf/s .L_dest01
  377. add #3,r4
  378. #endif
  379. ! Cleanup last few bytes
  380. .L_cleanup:
  381. mov r6,r0
  382. and #3,r0
  383. tst r0,r0
  384. bt .L_exit
  385. mov r0,r6
  386. .L_cleanup_loop:
  387. EX( mov.b @r5+,r0 )
  388. dt r6
  389. EX( mov.b r0,@r4 )
  390. bf/s .L_cleanup_loop
  391. add #1,r4
  392. .L_exit:
  393. mov #0,r0 ! normal return
  394. 5000:
  395. # Exception handler:
  396. .section .fixup, "ax"
  397. 6000:
  398. mov.l 8000f,r1
  399. mov r3,r0
  400. jmp @r1
  401. sub r4,r0
  402. .align 2
  403. 8000: .long 5000b
  404. .previous
  405. mov.l @r15+,r8
  406. mov.l @r15+,r9
  407. mov.l @r15+,r10
  408. rts
  409. mov.l @r15+,r11