syscall.S 19 KB

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