scall64-o32.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995 - 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. * Copyright (C) 2001 MIPS Technologies, Inc.
  9. * Copyright (C) 2004 Thiemo Seufer
  10. *
  11. * Hairy, the userspace application uses a different argument passing
  12. * convention than the kernel, so we have to translate things from o32
  13. * to ABI64 calling convention. 64-bit syscalls are also processed
  14. * here for now.
  15. */
  16. #include <linux/errno.h>
  17. #include <asm/asm.h>
  18. #include <asm/asmmacro.h>
  19. #include <asm/irqflags.h>
  20. #include <asm/mipsregs.h>
  21. #include <asm/regdef.h>
  22. #include <asm/stackframe.h>
  23. #include <asm/thread_info.h>
  24. #include <asm/unistd.h>
  25. #include <asm/sysmips.h>
  26. .align 5
  27. NESTED(handle_sys, PT_SIZE, sp)
  28. .set noat
  29. SAVE_SOME
  30. TRACE_IRQS_ON_RELOAD
  31. STI
  32. .set at
  33. ld t1, PT_EPC(sp) # skip syscall on return
  34. dsubu t0, v0, __NR_O32_Linux # check syscall number
  35. sltiu t0, t0, __NR_O32_Linux_syscalls + 1
  36. daddiu t1, 4 # skip to next instruction
  37. sd t1, PT_EPC(sp)
  38. beqz t0, not_o32_scall
  39. #if 0
  40. SAVE_ALL
  41. move a1, v0
  42. PRINT("Scall %ld\n")
  43. RESTORE_ALL
  44. #endif
  45. /* We don't want to stumble over broken sign extensions from
  46. userland. O32 does never use the upper half. */
  47. sll a0, a0, 0
  48. sll a1, a1, 0
  49. sll a2, a2, 0
  50. sll a3, a3, 0
  51. dsll t0, v0, 3 # offset into table
  52. ld t2, (sys32_call_table - (__NR_O32_Linux * 8))(t0)
  53. sd a3, PT_R26(sp) # save a3 for syscall restarting
  54. /*
  55. * More than four arguments. Try to deal with it by copying the
  56. * stack arguments from the user stack to the kernel stack.
  57. * This Sucks (TM).
  58. *
  59. * We intentionally keep the kernel stack a little below the top of
  60. * userspace so we don't have to do a slower byte accurate check here.
  61. */
  62. ld t0, PT_R29(sp) # get old user stack pointer
  63. daddu t1, t0, 32
  64. bltz t1, bad_stack
  65. 1: lw a4, 16(t0) # argument #5 from usp
  66. 2: lw a5, 20(t0) # argument #6 from usp
  67. 3: lw a6, 24(t0) # argument #7 from usp
  68. 4: lw a7, 28(t0) # argument #8 from usp (for indirect syscalls)
  69. .section __ex_table,"a"
  70. PTR 1b, bad_stack
  71. PTR 2b, bad_stack
  72. PTR 3b, bad_stack
  73. PTR 4b, bad_stack
  74. .previous
  75. li t1, _TIF_WORK_SYSCALL_ENTRY
  76. LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
  77. and t0, t1, t0
  78. bnez t0, trace_a_syscall
  79. jalr t2 # Do The Real Thing (TM)
  80. li t0, -EMAXERRNO - 1 # error?
  81. sltu t0, t0, v0
  82. sd t0, PT_R7(sp) # set error flag
  83. beqz t0, 1f
  84. ld t1, PT_R2(sp) # syscall number
  85. dnegu v0 # error
  86. sd t1, PT_R0(sp) # save it for syscall restarting
  87. 1: sd v0, PT_R2(sp) # result
  88. o32_syscall_exit:
  89. j syscall_exit_partial
  90. /* ------------------------------------------------------------------------ */
  91. trace_a_syscall:
  92. SAVE_STATIC
  93. sd a4, PT_R8(sp) # Save argument registers
  94. sd a5, PT_R9(sp)
  95. sd a6, PT_R10(sp)
  96. sd a7, PT_R11(sp) # For indirect syscalls
  97. move s0, t2 # Save syscall pointer
  98. move a0, sp
  99. /*
  100. * absolute syscall number is in v0 unless we called syscall(__NR_###)
  101. * where the real syscall number is in a0
  102. * note: NR_syscall is the first O32 syscall but the macro is
  103. * only defined when compiling with -mabi=32 (CONFIG_32BIT)
  104. * therefore __NR_O32_Linux is used (4000)
  105. */
  106. .set push
  107. .set reorder
  108. subu t1, v0, __NR_O32_Linux
  109. move a1, v0
  110. bnez t1, 1f /* __NR_syscall at offset 0 */
  111. lw a1, PT_R4(sp) /* Arg1 for __NR_syscall case */
  112. .set pop
  113. 1: jal syscall_trace_enter
  114. bltz v0, 2f # seccomp failed? Skip syscall
  115. move t0, s0
  116. RESTORE_STATIC
  117. ld a0, PT_R4(sp) # Restore argument registers
  118. ld a1, PT_R5(sp)
  119. ld a2, PT_R6(sp)
  120. ld a3, PT_R7(sp)
  121. ld a4, PT_R8(sp)
  122. ld a5, PT_R9(sp)
  123. ld a6, PT_R10(sp)
  124. ld a7, PT_R11(sp) # For indirect syscalls
  125. jalr t0
  126. li t0, -EMAXERRNO - 1 # error?
  127. sltu t0, t0, v0
  128. sd t0, PT_R7(sp) # set error flag
  129. beqz t0, 1f
  130. ld t1, PT_R2(sp) # syscall number
  131. dnegu v0 # error
  132. sd t1, PT_R0(sp) # save it for syscall restarting
  133. 1: sd v0, PT_R2(sp) # result
  134. 2: j syscall_exit
  135. /* ------------------------------------------------------------------------ */
  136. /*
  137. * The stackpointer for a call with more than 4 arguments is bad.
  138. */
  139. bad_stack:
  140. li v0, EFAULT
  141. sd v0, PT_R2(sp)
  142. li t0, 1 # set error flag
  143. sd t0, PT_R7(sp)
  144. j o32_syscall_exit
  145. not_o32_scall:
  146. /*
  147. * This is not an o32 compatibility syscall, pass it on
  148. * to the 64-bit syscall handlers.
  149. */
  150. #ifdef CONFIG_MIPS32_N32
  151. j handle_sysn32
  152. #else
  153. j handle_sys64
  154. #endif
  155. END(handle_sys)
  156. LEAF(sys32_syscall)
  157. subu t0, a0, __NR_O32_Linux # check syscall number
  158. sltiu v0, t0, __NR_O32_Linux_syscalls + 1
  159. beqz t0, einval # do not recurse
  160. dsll t1, t0, 3
  161. beqz v0, einval
  162. ld t2, sys32_call_table(t1) # syscall routine
  163. sd a0, PT_R2(sp) # call routine directly on restart
  164. move a0, a1 # shift argument registers
  165. move a1, a2
  166. move a2, a3
  167. move a3, a4
  168. move a4, a5
  169. move a5, a6
  170. move a6, a7
  171. sd a0, PT_R4(sp) # ... and push back a0 - a3, some
  172. sd a1, PT_R5(sp) # syscalls expect them there
  173. sd a2, PT_R6(sp)
  174. sd a3, PT_R7(sp)
  175. sd a3, PT_R26(sp) # update a3 for syscall restarting
  176. jr t2
  177. /* Unreached */
  178. einval: li v0, -ENOSYS
  179. jr ra
  180. END(sys32_syscall)
  181. .align 3
  182. .type sys32_call_table,@object
  183. EXPORT(sys32_call_table)
  184. PTR sys32_syscall /* 4000 */
  185. PTR sys_exit
  186. PTR __sys_fork
  187. PTR sys_read
  188. PTR sys_write
  189. PTR compat_sys_open /* 4005 */
  190. PTR sys_close
  191. PTR sys_waitpid
  192. PTR sys_creat
  193. PTR sys_link
  194. PTR sys_unlink /* 4010 */
  195. PTR compat_sys_execve
  196. PTR sys_chdir
  197. PTR compat_sys_time
  198. PTR sys_mknod
  199. PTR sys_chmod /* 4015 */
  200. PTR sys_lchown
  201. PTR sys_ni_syscall
  202. PTR sys_ni_syscall /* was sys_stat */
  203. PTR sys_lseek
  204. PTR sys_getpid /* 4020 */
  205. PTR compat_sys_mount
  206. PTR sys_oldumount
  207. PTR sys_setuid
  208. PTR sys_getuid
  209. PTR compat_sys_stime /* 4025 */
  210. PTR compat_sys_ptrace
  211. PTR sys_alarm
  212. PTR sys_ni_syscall /* was sys_fstat */
  213. PTR sys_pause
  214. PTR compat_sys_utime /* 4030 */
  215. PTR sys_ni_syscall
  216. PTR sys_ni_syscall
  217. PTR sys_access
  218. PTR sys_nice
  219. PTR sys_ni_syscall /* 4035 */
  220. PTR sys_sync
  221. PTR sys_kill
  222. PTR sys_rename
  223. PTR sys_mkdir
  224. PTR sys_rmdir /* 4040 */
  225. PTR sys_dup
  226. PTR sysm_pipe
  227. PTR compat_sys_times
  228. PTR sys_ni_syscall
  229. PTR sys_brk /* 4045 */
  230. PTR sys_setgid
  231. PTR sys_getgid
  232. PTR sys_ni_syscall /* was signal 2 */
  233. PTR sys_geteuid
  234. PTR sys_getegid /* 4050 */
  235. PTR sys_acct
  236. PTR sys_umount
  237. PTR sys_ni_syscall
  238. PTR compat_sys_ioctl
  239. PTR compat_sys_fcntl /* 4055 */
  240. PTR sys_ni_syscall
  241. PTR sys_setpgid
  242. PTR sys_ni_syscall
  243. PTR sys_olduname
  244. PTR sys_umask /* 4060 */
  245. PTR sys_chroot
  246. PTR compat_sys_ustat
  247. PTR sys_dup2
  248. PTR sys_getppid
  249. PTR sys_getpgrp /* 4065 */
  250. PTR sys_setsid
  251. PTR sys_32_sigaction
  252. PTR sys_sgetmask
  253. PTR sys_ssetmask
  254. PTR sys_setreuid /* 4070 */
  255. PTR sys_setregid
  256. PTR sys32_sigsuspend
  257. PTR compat_sys_sigpending
  258. PTR sys_sethostname
  259. PTR compat_sys_setrlimit /* 4075 */
  260. PTR compat_sys_getrlimit
  261. PTR compat_sys_getrusage
  262. PTR compat_sys_gettimeofday
  263. PTR compat_sys_settimeofday
  264. PTR sys_getgroups /* 4080 */
  265. PTR sys_setgroups
  266. PTR sys_ni_syscall /* old_select */
  267. PTR sys_symlink
  268. PTR sys_ni_syscall /* was sys_lstat */
  269. PTR sys_readlink /* 4085 */
  270. PTR sys_uselib
  271. PTR sys_swapon
  272. PTR sys_reboot
  273. PTR compat_sys_old_readdir
  274. PTR sys_mips_mmap /* 4090 */
  275. PTR sys_munmap
  276. PTR compat_sys_truncate
  277. PTR compat_sys_ftruncate
  278. PTR sys_fchmod
  279. PTR sys_fchown /* 4095 */
  280. PTR sys_getpriority
  281. PTR sys_setpriority
  282. PTR sys_ni_syscall
  283. PTR compat_sys_statfs
  284. PTR compat_sys_fstatfs /* 4100 */
  285. PTR sys_ni_syscall /* sys_ioperm */
  286. PTR compat_sys_socketcall
  287. PTR sys_syslog
  288. PTR compat_sys_setitimer
  289. PTR compat_sys_getitimer /* 4105 */
  290. PTR compat_sys_newstat
  291. PTR compat_sys_newlstat
  292. PTR compat_sys_newfstat
  293. PTR sys_uname
  294. PTR sys_ni_syscall /* sys_ioperm *//* 4110 */
  295. PTR sys_vhangup
  296. PTR sys_ni_syscall /* was sys_idle */
  297. PTR sys_ni_syscall /* sys_vm86 */
  298. PTR compat_sys_wait4
  299. PTR sys_swapoff /* 4115 */
  300. PTR compat_sys_sysinfo
  301. PTR compat_sys_ipc
  302. PTR sys_fsync
  303. PTR sys32_sigreturn
  304. PTR __sys_clone /* 4120 */
  305. PTR sys_setdomainname
  306. PTR sys_newuname
  307. PTR sys_ni_syscall /* sys_modify_ldt */
  308. PTR compat_sys_adjtimex
  309. PTR sys_mprotect /* 4125 */
  310. PTR compat_sys_sigprocmask
  311. PTR sys_ni_syscall /* was creat_module */
  312. PTR sys_init_module
  313. PTR sys_delete_module
  314. PTR sys_ni_syscall /* 4130, get_kernel_syms */
  315. PTR sys_quotactl
  316. PTR sys_getpgid
  317. PTR sys_fchdir
  318. PTR sys_bdflush
  319. PTR sys_sysfs /* 4135 */
  320. PTR sys_32_personality
  321. PTR sys_ni_syscall /* for afs_syscall */
  322. PTR sys_setfsuid
  323. PTR sys_setfsgid
  324. PTR sys_32_llseek /* 4140 */
  325. PTR compat_sys_getdents
  326. PTR compat_sys_select
  327. PTR sys_flock
  328. PTR sys_msync
  329. PTR compat_sys_readv /* 4145 */
  330. PTR compat_sys_writev
  331. PTR sys_cacheflush
  332. PTR sys_cachectl
  333. PTR sys_sysmips
  334. PTR sys_ni_syscall /* 4150 */
  335. PTR sys_getsid
  336. PTR sys_fdatasync
  337. PTR compat_sys_sysctl
  338. PTR sys_mlock
  339. PTR sys_munlock /* 4155 */
  340. PTR sys_mlockall
  341. PTR sys_munlockall
  342. PTR sys_sched_setparam
  343. PTR sys_sched_getparam
  344. PTR sys_sched_setscheduler /* 4160 */
  345. PTR sys_sched_getscheduler
  346. PTR sys_sched_yield
  347. PTR sys_sched_get_priority_max
  348. PTR sys_sched_get_priority_min
  349. PTR compat_sys_sched_rr_get_interval /* 4165 */
  350. PTR compat_sys_nanosleep
  351. PTR sys_mremap
  352. PTR sys_accept
  353. PTR sys_bind
  354. PTR sys_connect /* 4170 */
  355. PTR sys_getpeername
  356. PTR sys_getsockname
  357. PTR sys_getsockopt
  358. PTR sys_listen
  359. PTR compat_sys_recv /* 4175 */
  360. PTR compat_sys_recvfrom
  361. PTR compat_sys_recvmsg
  362. PTR sys_send
  363. PTR compat_sys_sendmsg
  364. PTR sys_sendto /* 4180 */
  365. PTR compat_sys_setsockopt
  366. PTR sys_shutdown
  367. PTR sys_socket
  368. PTR sys_socketpair
  369. PTR sys_setresuid /* 4185 */
  370. PTR sys_getresuid
  371. PTR sys_ni_syscall /* was query_module */
  372. PTR sys_poll
  373. PTR sys_ni_syscall /* was nfsservctl */
  374. PTR sys_setresgid /* 4190 */
  375. PTR sys_getresgid
  376. PTR sys_prctl
  377. PTR sys32_rt_sigreturn
  378. PTR compat_sys_rt_sigaction
  379. PTR compat_sys_rt_sigprocmask /* 4195 */
  380. PTR compat_sys_rt_sigpending
  381. PTR compat_sys_rt_sigtimedwait
  382. PTR compat_sys_rt_sigqueueinfo
  383. PTR compat_sys_rt_sigsuspend
  384. PTR sys_32_pread /* 4200 */
  385. PTR sys_32_pwrite
  386. PTR sys_chown
  387. PTR sys_getcwd
  388. PTR sys_capget
  389. PTR sys_capset /* 4205 */
  390. PTR compat_sys_sigaltstack
  391. PTR compat_sys_sendfile
  392. PTR sys_ni_syscall
  393. PTR sys_ni_syscall
  394. PTR sys_mips_mmap2 /* 4210 */
  395. PTR sys_32_truncate64
  396. PTR sys_32_ftruncate64
  397. PTR sys_newstat
  398. PTR sys_newlstat
  399. PTR sys_newfstat /* 4215 */
  400. PTR sys_pivot_root
  401. PTR sys_mincore
  402. PTR sys_madvise
  403. PTR sys_getdents64
  404. PTR compat_sys_fcntl64 /* 4220 */
  405. PTR sys_ni_syscall
  406. PTR sys_gettid
  407. PTR sys32_readahead
  408. PTR sys_setxattr
  409. PTR sys_lsetxattr /* 4225 */
  410. PTR sys_fsetxattr
  411. PTR sys_getxattr
  412. PTR sys_lgetxattr
  413. PTR sys_fgetxattr
  414. PTR sys_listxattr /* 4230 */
  415. PTR sys_llistxattr
  416. PTR sys_flistxattr
  417. PTR sys_removexattr
  418. PTR sys_lremovexattr
  419. PTR sys_fremovexattr /* 4235 */
  420. PTR sys_tkill
  421. PTR sys_sendfile64
  422. PTR compat_sys_futex
  423. PTR compat_sys_sched_setaffinity
  424. PTR compat_sys_sched_getaffinity /* 4240 */
  425. PTR compat_sys_io_setup
  426. PTR sys_io_destroy
  427. PTR compat_sys_io_getevents
  428. PTR compat_sys_io_submit
  429. PTR sys_io_cancel /* 4245 */
  430. PTR sys_exit_group
  431. PTR compat_sys_lookup_dcookie
  432. PTR sys_epoll_create
  433. PTR sys_epoll_ctl
  434. PTR sys_epoll_wait /* 4250 */
  435. PTR sys_remap_file_pages
  436. PTR sys_set_tid_address
  437. PTR sys_restart_syscall
  438. PTR sys32_fadvise64_64
  439. PTR compat_sys_statfs64 /* 4255 */
  440. PTR compat_sys_fstatfs64
  441. PTR compat_sys_timer_create
  442. PTR compat_sys_timer_settime
  443. PTR compat_sys_timer_gettime
  444. PTR sys_timer_getoverrun /* 4260 */
  445. PTR sys_timer_delete
  446. PTR compat_sys_clock_settime
  447. PTR compat_sys_clock_gettime
  448. PTR compat_sys_clock_getres
  449. PTR compat_sys_clock_nanosleep /* 4265 */
  450. PTR sys_tgkill
  451. PTR compat_sys_utimes
  452. PTR compat_sys_mbind
  453. PTR compat_sys_get_mempolicy
  454. PTR compat_sys_set_mempolicy /* 4270 */
  455. PTR compat_sys_mq_open
  456. PTR sys_mq_unlink
  457. PTR compat_sys_mq_timedsend
  458. PTR compat_sys_mq_timedreceive
  459. PTR compat_sys_mq_notify /* 4275 */
  460. PTR compat_sys_mq_getsetattr
  461. PTR sys_ni_syscall /* sys_vserver */
  462. PTR compat_sys_waitid
  463. PTR sys_ni_syscall /* available, was setaltroot */
  464. PTR sys_add_key /* 4280 */
  465. PTR sys_request_key
  466. PTR sys_keyctl
  467. PTR sys_set_thread_area
  468. PTR sys_inotify_init
  469. PTR sys_inotify_add_watch /* 4285 */
  470. PTR sys_inotify_rm_watch
  471. PTR compat_sys_migrate_pages
  472. PTR compat_sys_openat
  473. PTR sys_mkdirat
  474. PTR sys_mknodat /* 4290 */
  475. PTR sys_fchownat
  476. PTR compat_sys_futimesat
  477. PTR sys_newfstatat
  478. PTR sys_unlinkat
  479. PTR sys_renameat /* 4295 */
  480. PTR sys_linkat
  481. PTR sys_symlinkat
  482. PTR sys_readlinkat
  483. PTR sys_fchmodat
  484. PTR sys_faccessat /* 4300 */
  485. PTR compat_sys_pselect6
  486. PTR compat_sys_ppoll
  487. PTR sys_unshare
  488. PTR sys_splice
  489. PTR sys32_sync_file_range /* 4305 */
  490. PTR sys_tee
  491. PTR compat_sys_vmsplice
  492. PTR compat_sys_move_pages
  493. PTR compat_sys_set_robust_list
  494. PTR compat_sys_get_robust_list /* 4310 */
  495. PTR compat_sys_kexec_load
  496. PTR sys_getcpu
  497. PTR compat_sys_epoll_pwait
  498. PTR sys_ioprio_set
  499. PTR sys_ioprio_get /* 4315 */
  500. PTR compat_sys_utimensat
  501. PTR compat_sys_signalfd
  502. PTR sys_ni_syscall /* was timerfd */
  503. PTR sys_eventfd
  504. PTR sys32_fallocate /* 4320 */
  505. PTR sys_timerfd_create
  506. PTR compat_sys_timerfd_gettime
  507. PTR compat_sys_timerfd_settime
  508. PTR compat_sys_signalfd4
  509. PTR sys_eventfd2 /* 4325 */
  510. PTR sys_epoll_create1
  511. PTR sys_dup3
  512. PTR sys_pipe2
  513. PTR sys_inotify_init1
  514. PTR compat_sys_preadv /* 4330 */
  515. PTR compat_sys_pwritev
  516. PTR compat_sys_rt_tgsigqueueinfo
  517. PTR sys_perf_event_open
  518. PTR sys_accept4
  519. PTR compat_sys_recvmmsg /* 4335 */
  520. PTR sys_fanotify_init
  521. PTR compat_sys_fanotify_mark
  522. PTR sys_prlimit64
  523. PTR sys_name_to_handle_at
  524. PTR compat_sys_open_by_handle_at /* 4340 */
  525. PTR compat_sys_clock_adjtime
  526. PTR sys_syncfs
  527. PTR compat_sys_sendmmsg
  528. PTR sys_setns
  529. PTR compat_sys_process_vm_readv /* 4345 */
  530. PTR compat_sys_process_vm_writev
  531. PTR sys_kcmp
  532. PTR sys_finit_module
  533. PTR sys_sched_setattr
  534. PTR sys_sched_getattr /* 4350 */
  535. PTR sys_renameat2
  536. PTR sys_seccomp
  537. PTR sys_getrandom
  538. PTR sys_memfd_create
  539. PTR sys_bpf /* 4355 */
  540. PTR compat_sys_execveat
  541. .size sys32_call_table,.-sys32_call_table