scall64-o32.S 14 KB

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