syscall.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * System call entry code Copyright (c) Matthew Wilcox 1999 <willy@bofh.ai>
  5. * Licensed under the GNU GPL.
  6. * thanks to Philipp Rumpf, Mike Shaver and various others
  7. * sorry about the wall, puffin..
  8. */
  9. #include <asm/asm-offsets.h>
  10. #include <asm/unistd.h>
  11. #include <asm/errno.h>
  12. #include <asm/page.h>
  13. #include <asm/psw.h>
  14. #include <asm/thread_info.h>
  15. #include <asm/assembly.h>
  16. #include <asm/processor.h>
  17. #include <asm/cache.h>
  18. #include <linux/linkage.h>
  19. /* We fill the empty parts of the gateway page with
  20. * something that will kill the kernel or a
  21. * userspace application.
  22. */
  23. #define KILL_INSN break 0,0
  24. .level LEVEL
  25. .text
  26. .import syscall_exit,code
  27. .import syscall_exit_rfi,code
  28. /* Linux gateway page is aliased to virtual page 0 in the kernel
  29. * address space. Since it is a gateway page it cannot be
  30. * dereferenced, so null pointers will still fault. We start
  31. * the actual entry point at 0x100. We put break instructions
  32. * at the beginning of the page to trap null indirect function
  33. * pointers.
  34. */
  35. .align PAGE_SIZE
  36. ENTRY(linux_gateway_page)
  37. /* ADDRESS 0x00 to 0xb0 = 176 bytes / 4 bytes per insn = 44 insns */
  38. .rept 44
  39. KILL_INSN
  40. .endr
  41. /* ADDRESS 0xb0 to 0xb8, lws uses two insns for entry */
  42. /* Light-weight-syscall entry must always be located at 0xb0 */
  43. /* WARNING: Keep this number updated with table size changes */
  44. #define __NR_lws_entries (2)
  45. lws_entry:
  46. gate lws_start, %r0 /* increase privilege */
  47. depi 3, 31, 2, %r31 /* Ensure we return into user mode. */
  48. /* Fill from 0xb8 to 0xe0 */
  49. .rept 10
  50. KILL_INSN
  51. .endr
  52. /* This function MUST be located at 0xe0 for glibc's threading
  53. mechanism to work. DO NOT MOVE THIS CODE EVER! */
  54. set_thread_pointer:
  55. gate .+8, %r0 /* increase privilege */
  56. depi 3, 31, 2, %r31 /* Ensure we return into user mode. */
  57. be 0(%sr7,%r31) /* return to user space */
  58. mtctl %r26, %cr27 /* move arg0 to the control register */
  59. /* Increase the chance of trapping if random jumps occur to this
  60. address, fill from 0xf0 to 0x100 */
  61. .rept 4
  62. KILL_INSN
  63. .endr
  64. /* This address must remain fixed at 0x100 for glibc's syscalls to work */
  65. .align 256
  66. linux_gateway_entry:
  67. gate .+8, %r0 /* become privileged */
  68. mtsp %r0,%sr4 /* get kernel space into sr4 */
  69. mtsp %r0,%sr5 /* get kernel space into sr5 */
  70. mtsp %r0,%sr6 /* get kernel space into sr6 */
  71. mfsp %sr7,%r1 /* save user sr7 */
  72. mtsp %r1,%sr3 /* and store it in sr3 */
  73. #ifdef CONFIG_64BIT
  74. /* for now we can *always* set the W bit on entry to the syscall
  75. * since we don't support wide userland processes. We could
  76. * also save the current SM other than in r0 and restore it on
  77. * exit from the syscall, and also use that value to know
  78. * whether to do narrow or wide syscalls. -PB
  79. */
  80. ssm PSW_SM_W, %r1
  81. extrd,u %r1,PSW_W_BIT,1,%r1
  82. /* sp must be aligned on 4, so deposit the W bit setting into
  83. * the bottom of sp temporarily */
  84. or,ev %r1,%r30,%r30
  85. b,n 1f
  86. /* The top halves of argument registers must be cleared on syscall
  87. * entry from narrow executable.
  88. */
  89. depdi 0, 31, 32, %r26
  90. depdi 0, 31, 32, %r25
  91. depdi 0, 31, 32, %r24
  92. depdi 0, 31, 32, %r23
  93. depdi 0, 31, 32, %r22
  94. depdi 0, 31, 32, %r21
  95. 1:
  96. #endif
  97. mfctl %cr30,%r1
  98. xor %r1,%r30,%r30 /* ye olde xor trick */
  99. xor %r1,%r30,%r1
  100. xor %r1,%r30,%r30
  101. ldo THREAD_SZ_ALGN+FRAME_SIZE(%r30),%r30 /* set up kernel stack */
  102. /* N.B.: It is critical that we don't set sr7 to 0 until r30
  103. * contains a valid kernel stack pointer. It is also
  104. * critical that we don't start using the kernel stack
  105. * until after sr7 has been set to 0.
  106. */
  107. mtsp %r0,%sr7 /* get kernel space into sr7 */
  108. STREGM %r1,FRAME_SIZE(%r30) /* save r1 (usp) here for now */
  109. mfctl %cr30,%r1 /* get task ptr in %r1 */
  110. LDREG TI_TASK(%r1),%r1
  111. /* Save some registers for sigcontext and potential task
  112. switch (see entry.S for the details of which ones are
  113. saved/restored). TASK_PT_PSW is zeroed so we can see whether
  114. a process is on a syscall or not. For an interrupt the real
  115. PSW value is stored. This is needed for gdb and sys_ptrace. */
  116. STREG %r0, TASK_PT_PSW(%r1)
  117. STREG %r2, TASK_PT_GR2(%r1) /* preserve rp */
  118. STREG %r19, TASK_PT_GR19(%r1)
  119. LDREGM -FRAME_SIZE(%r30), %r2 /* get users sp back */
  120. #ifdef CONFIG_64BIT
  121. extrd,u %r2,63,1,%r19 /* W hidden in bottom bit */
  122. #if 0
  123. xor %r19,%r2,%r2 /* clear bottom bit */
  124. depd,z %r19,1,1,%r19
  125. std %r19,TASK_PT_PSW(%r1)
  126. #endif
  127. #endif
  128. STREG %r2, TASK_PT_GR30(%r1) /* ... and save it */
  129. STREG %r20, TASK_PT_GR20(%r1) /* Syscall number */
  130. STREG %r21, TASK_PT_GR21(%r1)
  131. STREG %r22, TASK_PT_GR22(%r1)
  132. STREG %r23, TASK_PT_GR23(%r1) /* 4th argument */
  133. STREG %r24, TASK_PT_GR24(%r1) /* 3rd argument */
  134. STREG %r25, TASK_PT_GR25(%r1) /* 2nd argument */
  135. STREG %r26, TASK_PT_GR26(%r1) /* 1st argument */
  136. STREG %r27, TASK_PT_GR27(%r1) /* user dp */
  137. STREG %r28, TASK_PT_GR28(%r1) /* return value 0 */
  138. STREG %r0, TASK_PT_ORIG_R28(%r1) /* don't prohibit restarts */
  139. STREG %r29, TASK_PT_GR29(%r1) /* return value 1 */
  140. STREG %r31, TASK_PT_GR31(%r1) /* preserve syscall return ptr */
  141. ldo TASK_PT_FR0(%r1), %r27 /* save fpregs from the kernel */
  142. save_fp %r27 /* or potential task switch */
  143. mfctl %cr11, %r27 /* i.e. SAR */
  144. STREG %r27, TASK_PT_SAR(%r1)
  145. loadgp
  146. #ifdef CONFIG_64BIT
  147. ldo -16(%r30),%r29 /* Reference param save area */
  148. copy %r19,%r2 /* W bit back to r2 */
  149. #else
  150. /* no need to save these on stack in wide mode because the first 8
  151. * args are passed in registers */
  152. stw %r22, -52(%r30) /* 5th argument */
  153. stw %r21, -56(%r30) /* 6th argument */
  154. #endif
  155. /* Are we being ptraced? */
  156. mfctl %cr30, %r1
  157. LDREG TI_FLAGS(%r1),%r1
  158. ldi _TIF_SYSCALL_TRACE_MASK, %r19
  159. and,COND(=) %r1, %r19, %r0
  160. b,n .Ltracesys
  161. /* Note! We cannot use the syscall table that is mapped
  162. nearby since the gateway page is mapped execute-only. */
  163. #ifdef CONFIG_64BIT
  164. ldil L%sys_call_table, %r1
  165. or,= %r2,%r2,%r2
  166. addil L%(sys_call_table64-sys_call_table), %r1
  167. ldo R%sys_call_table(%r1), %r19
  168. or,= %r2,%r2,%r2
  169. ldo R%sys_call_table64(%r1), %r19
  170. #else
  171. ldil L%sys_call_table, %r1
  172. ldo R%sys_call_table(%r1), %r19
  173. #endif
  174. comiclr,>> __NR_Linux_syscalls, %r20, %r0
  175. b,n .Lsyscall_nosys
  176. LDREGX %r20(%r19), %r19
  177. /* If this is a sys_rt_sigreturn call, and the signal was received
  178. * when not in_syscall, then we want to return via syscall_exit_rfi,
  179. * not syscall_exit. Signal no. in r20, in_syscall in r25 (see
  180. * trampoline code in signal.c).
  181. */
  182. ldi __NR_rt_sigreturn,%r2
  183. comb,= %r2,%r20,.Lrt_sigreturn
  184. .Lin_syscall:
  185. ldil L%syscall_exit,%r2
  186. be 0(%sr7,%r19)
  187. ldo R%syscall_exit(%r2),%r2
  188. .Lrt_sigreturn:
  189. comib,<> 0,%r25,.Lin_syscall
  190. ldil L%syscall_exit_rfi,%r2
  191. be 0(%sr7,%r19)
  192. ldo R%syscall_exit_rfi(%r2),%r2
  193. /* Note! Because we are not running where we were linked, any
  194. calls to functions external to this file must be indirect. To
  195. be safe, we apply the opposite rule to functions within this
  196. file, with local labels given to them to ensure correctness. */
  197. .Lsyscall_nosys:
  198. syscall_nosys:
  199. ldil L%syscall_exit,%r1
  200. be R%syscall_exit(%sr7,%r1)
  201. ldo -ENOSYS(%r0),%r28 /* set errno */
  202. /* Warning! This trace code is a virtual duplicate of the code above so be
  203. * sure to maintain both! */
  204. .Ltracesys:
  205. tracesys:
  206. /* Need to save more registers so the debugger can see where we
  207. * are. This saves only the lower 8 bits of PSW, so that the C
  208. * bit is still clear on syscalls, and the D bit is set if this
  209. * full register save path has been executed. We check the D
  210. * bit on syscall_return_rfi to determine which registers to
  211. * restore. An interrupt results in a full PSW saved with the
  212. * C bit set, a non-straced syscall entry results in C and D clear
  213. * in the saved PSW.
  214. */
  215. ldo -THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1 /* get task ptr */
  216. LDREG TI_TASK(%r1), %r1
  217. ssm 0,%r2
  218. STREG %r2,TASK_PT_PSW(%r1) /* Lower 8 bits only!! */
  219. mfsp %sr0,%r2
  220. STREG %r2,TASK_PT_SR0(%r1)
  221. mfsp %sr1,%r2
  222. STREG %r2,TASK_PT_SR1(%r1)
  223. mfsp %sr2,%r2
  224. STREG %r2,TASK_PT_SR2(%r1)
  225. mfsp %sr3,%r2
  226. STREG %r2,TASK_PT_SR3(%r1)
  227. STREG %r2,TASK_PT_SR4(%r1)
  228. STREG %r2,TASK_PT_SR5(%r1)
  229. STREG %r2,TASK_PT_SR6(%r1)
  230. STREG %r2,TASK_PT_SR7(%r1)
  231. STREG %r2,TASK_PT_IASQ0(%r1)
  232. STREG %r2,TASK_PT_IASQ1(%r1)
  233. LDREG TASK_PT_GR31(%r1),%r2
  234. STREG %r2,TASK_PT_IAOQ0(%r1)
  235. ldo 4(%r2),%r2
  236. STREG %r2,TASK_PT_IAOQ1(%r1)
  237. ldo TASK_REGS(%r1),%r2
  238. /* reg_save %r2 */
  239. STREG %r3,PT_GR3(%r2)
  240. STREG %r4,PT_GR4(%r2)
  241. STREG %r5,PT_GR5(%r2)
  242. STREG %r6,PT_GR6(%r2)
  243. STREG %r7,PT_GR7(%r2)
  244. STREG %r8,PT_GR8(%r2)
  245. STREG %r9,PT_GR9(%r2)
  246. STREG %r10,PT_GR10(%r2)
  247. STREG %r11,PT_GR11(%r2)
  248. STREG %r12,PT_GR12(%r2)
  249. STREG %r13,PT_GR13(%r2)
  250. STREG %r14,PT_GR14(%r2)
  251. STREG %r15,PT_GR15(%r2)
  252. STREG %r16,PT_GR16(%r2)
  253. STREG %r17,PT_GR17(%r2)
  254. STREG %r18,PT_GR18(%r2)
  255. /* Finished saving things for the debugger */
  256. copy %r2,%r26
  257. ldil L%do_syscall_trace_enter,%r1
  258. ldil L%tracesys_next,%r2
  259. be R%do_syscall_trace_enter(%sr7,%r1)
  260. ldo R%tracesys_next(%r2),%r2
  261. tracesys_next:
  262. /* do_syscall_trace_enter either returned the syscallno, or -1L,
  263. * so we skip restoring the PT_GR20 below, since we pulled it from
  264. * task->thread.regs.gr[20] above.
  265. */
  266. copy %ret0,%r20
  267. ldil L%sys_call_table,%r1
  268. ldo R%sys_call_table(%r1), %r19
  269. ldo -THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1 /* get task ptr */
  270. LDREG TI_TASK(%r1), %r1
  271. LDREG TASK_PT_GR26(%r1), %r26 /* Restore the users args */
  272. LDREG TASK_PT_GR25(%r1), %r25
  273. LDREG TASK_PT_GR24(%r1), %r24
  274. LDREG TASK_PT_GR23(%r1), %r23
  275. LDREG TASK_PT_GR22(%r1), %r22
  276. LDREG TASK_PT_GR21(%r1), %r21
  277. #ifdef CONFIG_64BIT
  278. ldo -16(%r30),%r29 /* Reference param save area */
  279. #else
  280. stw %r22, -52(%r30) /* 5th argument */
  281. stw %r21, -56(%r30) /* 6th argument */
  282. #endif
  283. comiclr,>>= __NR_Linux_syscalls, %r20, %r0
  284. b,n .Lsyscall_nosys
  285. LDREGX %r20(%r19), %r19
  286. /* If this is a sys_rt_sigreturn call, and the signal was received
  287. * when not in_syscall, then we want to return via syscall_exit_rfi,
  288. * not syscall_exit. Signal no. in r20, in_syscall in r25 (see
  289. * trampoline code in signal.c).
  290. */
  291. ldi __NR_rt_sigreturn,%r2
  292. comb,= %r2,%r20,.Ltrace_rt_sigreturn
  293. .Ltrace_in_syscall:
  294. ldil L%tracesys_exit,%r2
  295. be 0(%sr7,%r19)
  296. ldo R%tracesys_exit(%r2),%r2
  297. /* Do *not* call this function on the gateway page, because it
  298. makes a direct call to syscall_trace. */
  299. tracesys_exit:
  300. ldo -THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1 /* get task ptr */
  301. LDREG TI_TASK(%r1), %r1
  302. #ifdef CONFIG_64BIT
  303. ldo -16(%r30),%r29 /* Reference param save area */
  304. #endif
  305. ldo TASK_REGS(%r1),%r26
  306. bl do_syscall_trace_exit,%r2
  307. STREG %r28,TASK_PT_GR28(%r1) /* save return value now */
  308. ldo -THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1 /* get task ptr */
  309. LDREG TI_TASK(%r1), %r1
  310. LDREG TASK_PT_GR28(%r1), %r28 /* Restore return val. */
  311. ldil L%syscall_exit,%r1
  312. be,n R%syscall_exit(%sr7,%r1)
  313. .Ltrace_rt_sigreturn:
  314. comib,<> 0,%r25,.Ltrace_in_syscall
  315. ldil L%tracesys_sigexit,%r2
  316. be 0(%sr7,%r19)
  317. ldo R%tracesys_sigexit(%r2),%r2
  318. tracesys_sigexit:
  319. ldo -THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r1 /* get task ptr */
  320. LDREG TI_TASK(%r1), %r1
  321. #ifdef CONFIG_64BIT
  322. ldo -16(%r30),%r29 /* Reference param save area */
  323. #endif
  324. bl do_syscall_trace_exit,%r2
  325. ldo TASK_REGS(%r1),%r26
  326. ldil L%syscall_exit_rfi,%r1
  327. be,n R%syscall_exit_rfi(%sr7,%r1)
  328. /*********************************************************
  329. 32/64-bit Light-Weight-Syscall ABI
  330. * - Indicates a hint for userspace inline asm
  331. implementations.
  332. Syscall number (caller-saves)
  333. - %r20
  334. * In asm clobber.
  335. Argument registers (caller-saves)
  336. - %r26, %r25, %r24, %r23, %r22
  337. * In asm input.
  338. Return registers (caller-saves)
  339. - %r28 (return), %r21 (errno)
  340. * In asm output.
  341. Caller-saves registers
  342. - %r1, %r27, %r29
  343. - %r2 (return pointer)
  344. - %r31 (ble link register)
  345. * In asm clobber.
  346. Callee-saves registers
  347. - %r3-%r18
  348. - %r30 (stack pointer)
  349. * Not in asm clobber.
  350. If userspace is 32-bit:
  351. Callee-saves registers
  352. - %r19 (32-bit PIC register)
  353. Differences from 32-bit calling convention:
  354. - Syscall number in %r20
  355. - Additional argument register %r22 (arg4)
  356. - Callee-saves %r19.
  357. If userspace is 64-bit:
  358. Callee-saves registers
  359. - %r27 (64-bit PIC register)
  360. Differences from 64-bit calling convention:
  361. - Syscall number in %r20
  362. - Additional argument register %r22 (arg4)
  363. - Callee-saves %r27.
  364. Error codes returned by entry path:
  365. ENOSYS - r20 was an invalid LWS number.
  366. *********************************************************/
  367. lws_start:
  368. #ifdef CONFIG_64BIT
  369. /* FIXME: If we are a 64-bit kernel just
  370. * turn this on unconditionally.
  371. */
  372. ssm PSW_SM_W, %r1
  373. extrd,u %r1,PSW_W_BIT,1,%r1
  374. /* sp must be aligned on 4, so deposit the W bit setting into
  375. * the bottom of sp temporarily */
  376. or,ev %r1,%r30,%r30
  377. /* Clip LWS number to a 32-bit value always */
  378. depdi 0, 31, 32, %r20
  379. #endif
  380. /* Is the lws entry number valid? */
  381. comiclr,>> __NR_lws_entries, %r20, %r0
  382. b,n lws_exit_nosys
  383. /* WARNING: Trashing sr2 and sr3 */
  384. mfsp %sr7,%r1 /* get userspace into sr3 */
  385. mtsp %r1,%sr3
  386. mtsp %r0,%sr2 /* get kernel space into sr2 */
  387. /* Load table start */
  388. ldil L%lws_table, %r1
  389. ldo R%lws_table(%r1), %r28 /* Scratch use of r28 */
  390. LDREGX %r20(%sr2,r28), %r21 /* Scratch use of r21 */
  391. /* Jump to lws, lws table pointers already relocated */
  392. be,n 0(%sr2,%r21)
  393. lws_exit_nosys:
  394. ldo -ENOSYS(%r0),%r21 /* set errno */
  395. /* Fall through: Return to userspace */
  396. lws_exit:
  397. #ifdef CONFIG_64BIT
  398. /* decide whether to reset the wide mode bit
  399. *
  400. * For a syscall, the W bit is stored in the lowest bit
  401. * of sp. Extract it and reset W if it is zero */
  402. extrd,u,*<> %r30,63,1,%r1
  403. rsm PSW_SM_W, %r0
  404. /* now reset the lowest bit of sp if it was set */
  405. xor %r30,%r1,%r30
  406. #endif
  407. be,n 0(%sr7, %r31)
  408. /***************************************************
  409. Implementing CAS as an atomic operation:
  410. %r26 - Address to examine
  411. %r25 - Old value to check (old)
  412. %r24 - New value to set (new)
  413. %r28 - Return prev through this register.
  414. %r21 - Kernel error code
  415. If debugging is DISabled:
  416. %r21 has the following meanings:
  417. EAGAIN - CAS is busy, ldcw failed, try again.
  418. EFAULT - Read or write failed.
  419. If debugging is enabled:
  420. EDEADLOCK - CAS called recursively.
  421. EAGAIN && r28 == 1 - CAS is busy. Lock contended.
  422. EAGAIN && r28 == 2 - CAS is busy. ldcw failed.
  423. EFAULT - Read or write failed.
  424. Scratch: r20, r28, r1
  425. ****************************************************/
  426. /* Do not enable LWS debugging */
  427. #define ENABLE_LWS_DEBUG 0
  428. /* ELF64 Process entry path */
  429. lws_compare_and_swap64:
  430. #ifdef CONFIG_64BIT
  431. b,n lws_compare_and_swap
  432. #else
  433. /* If we are not a 64-bit kernel, then we don't
  434. * have 64-bit input registers, and calling
  435. * the 64-bit LWS CAS returns ENOSYS.
  436. */
  437. b,n lws_exit_nosys
  438. #endif
  439. /* ELF32 Process entry path */
  440. lws_compare_and_swap32:
  441. #ifdef CONFIG_64BIT
  442. /* Clip all the input registers */
  443. depdi 0, 31, 32, %r26
  444. depdi 0, 31, 32, %r25
  445. depdi 0, 31, 32, %r24
  446. #endif
  447. lws_compare_and_swap:
  448. /* Load start of lock table */
  449. ldil L%lws_lock_start, %r20
  450. ldo R%lws_lock_start(%r20), %r28
  451. /* Extract four bits from r26 and hash lock (Bits 4-7) */
  452. extru %r26, 27, 4, %r20
  453. /* Find lock to use, the hash is either one of 0 to
  454. 15, multiplied by 16 (keep it 16-byte aligned)
  455. and add to the lock table offset. */
  456. shlw %r20, 4, %r20
  457. add %r20, %r28, %r20
  458. # if ENABLE_LWS_DEBUG
  459. /*
  460. DEBUG, check for deadlock!
  461. If the thread register values are the same
  462. then we were the one that locked it last and
  463. this is a recurisve call that will deadlock.
  464. We *must* giveup this call and fail.
  465. */
  466. ldw 4(%sr2,%r20), %r28 /* Load thread register */
  467. /* WARNING: If cr27 cycles to the same value we have problems */
  468. mfctl %cr27, %r21 /* Get current thread register */
  469. cmpb,<>,n %r21, %r28, cas_lock /* Called recursive? */
  470. b lws_exit /* Return error! */
  471. ldo -EDEADLOCK(%r0), %r21
  472. cas_lock:
  473. cmpb,=,n %r0, %r28, cas_nocontend /* Is nobody using it? */
  474. ldo 1(%r0), %r28 /* 1st case */
  475. b lws_exit /* Contended... */
  476. ldo -EAGAIN(%r0), %r21 /* Spin in userspace */
  477. cas_nocontend:
  478. # endif
  479. /* ENABLE_LWS_DEBUG */
  480. LDCW 0(%sr2,%r20), %r28 /* Try to acquire the lock */
  481. cmpb,<>,n %r0, %r28, cas_action /* Did we get it? */
  482. cas_wouldblock:
  483. ldo 2(%r0), %r28 /* 2nd case */
  484. b lws_exit /* Contended... */
  485. ldo -EAGAIN(%r0), %r21 /* Spin in userspace */
  486. /*
  487. prev = *addr;
  488. if ( prev == old )
  489. *addr = new;
  490. return prev;
  491. */
  492. /* NOTES:
  493. This all works becuse intr_do_signal
  494. and schedule both check the return iasq
  495. and see that we are on the kernel page
  496. so this process is never scheduled off
  497. or is ever sent any signal of any sort,
  498. thus it is wholly atomic from usrspaces
  499. perspective
  500. */
  501. cas_action:
  502. #if defined CONFIG_SMP && ENABLE_LWS_DEBUG
  503. /* DEBUG */
  504. mfctl %cr27, %r1
  505. stw %r1, 4(%sr2,%r20)
  506. #endif
  507. /* The load and store could fail */
  508. 1: ldw 0(%sr3,%r26), %r28
  509. sub,<> %r28, %r25, %r0
  510. 2: stw %r24, 0(%sr3,%r26)
  511. /* Free lock */
  512. stw %r20, 0(%sr2,%r20)
  513. #if ENABLE_LWS_DEBUG
  514. /* Clear thread register indicator */
  515. stw %r0, 4(%sr2,%r20)
  516. #endif
  517. /* Return to userspace, set no error */
  518. b lws_exit
  519. copy %r0, %r21
  520. 3:
  521. /* Error occurred on load or store */
  522. /* Free lock */
  523. stw %r20, 0(%sr2,%r20)
  524. #if ENABLE_LWS_DEBUG
  525. stw %r0, 4(%sr2,%r20)
  526. #endif
  527. b lws_exit
  528. ldo -EFAULT(%r0),%r21 /* set errno */
  529. nop
  530. nop
  531. nop
  532. nop
  533. /* Two exception table entries, one for the load,
  534. the other for the store. Either return -EFAULT.
  535. Each of the entries must be relocated. */
  536. .section __ex_table,"aw"
  537. ASM_ULONG_INSN (1b - linux_gateway_page), (3b - linux_gateway_page)
  538. ASM_ULONG_INSN (2b - linux_gateway_page), (3b - linux_gateway_page)
  539. .previous
  540. /* Make sure nothing else is placed on this page */
  541. .align PAGE_SIZE
  542. END(linux_gateway_page)
  543. ENTRY(end_linux_gateway_page)
  544. /* Relocate symbols assuming linux_gateway_page is mapped
  545. to virtual address 0x0 */
  546. #define LWS_ENTRY(_name_) ASM_ULONG_INSN (lws_##_name_ - linux_gateway_page)
  547. .section .rodata,"a"
  548. .align 8
  549. /* Light-weight-syscall table */
  550. /* Start of lws table. */
  551. ENTRY(lws_table)
  552. LWS_ENTRY(compare_and_swap32) /* 0 - ELF32 Atomic compare and swap */
  553. LWS_ENTRY(compare_and_swap64) /* 1 - ELF64 Atomic compare and swap */
  554. END(lws_table)
  555. /* End of lws table */
  556. .align 8
  557. ENTRY(sys_call_table)
  558. #include "syscall_table.S"
  559. END(sys_call_table)
  560. #ifdef CONFIG_64BIT
  561. .align 8
  562. ENTRY(sys_call_table64)
  563. #define SYSCALL_TABLE_64BIT
  564. #include "syscall_table.S"
  565. END(sys_call_table64)
  566. #endif
  567. /*
  568. All light-weight-syscall atomic operations
  569. will use this set of locks
  570. NOTE: The lws_lock_start symbol must be
  571. at least 16-byte aligned for safe use
  572. with ldcw.
  573. */
  574. .section .data
  575. .align L1_CACHE_BYTES
  576. ENTRY(lws_lock_start)
  577. /* lws locks */
  578. .rept 16
  579. /* Keep locks aligned at 16-bytes */
  580. .word 1
  581. .word 0
  582. .word 0
  583. .word 0
  584. .endr
  585. END(lws_lock_start)
  586. .previous
  587. .end