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