unistd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. * include/asm-xtensa/unistd.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_UNISTD_H
  11. #define _XTENSA_UNISTD_H
  12. #include <linux/linkage.h>
  13. //#define __NR_setup 0 /* used only by init, to get system going */
  14. #define __NR_spill 0
  15. #define __NR_exit 1
  16. #define __NR_fork 2
  17. #define __NR_read 3
  18. #define __NR_write 4
  19. #define __NR_open 5
  20. #define __NR_close 6
  21. #define __NR_waitpid 7
  22. #define __NR_creat 8
  23. #define __NR_link 9
  24. #define __NR_unlink 10
  25. #define __NR_execve 11
  26. #define __NR_chdir 12
  27. #define __NR_time 13
  28. #define __NR_mknod 14
  29. #define __NR_chmod 15
  30. #define __NR_lchown 16
  31. #define __NR_break 17
  32. #define __NR_oldstat 18
  33. #define __NR_lseek 19
  34. #define __NR_getpid 20
  35. #define __NR_mount 21
  36. #define __NR_oldumount 22
  37. #define __NR_setuid 23
  38. #define __NR_getuid 24
  39. #define __NR_stime 25
  40. #define __NR_ptrace 26
  41. #define __NR_alarm 27
  42. #define __NR_oldfstat 28
  43. #define __NR_pause 29
  44. #define __NR_utime 30
  45. #define __NR_stty 31
  46. #define __NR_gtty 32
  47. #define __NR_access 33
  48. #define __NR_nice 34
  49. #define __NR_ftime 35
  50. #define __NR_sync 36
  51. #define __NR_kill 37
  52. #define __NR_rename 38
  53. #define __NR_mkdir 39
  54. #define __NR_rmdir 40
  55. #define __NR_dup 41
  56. #define __NR_pipe 42
  57. #define __NR_times 43
  58. #define __NR_prof 44
  59. #define __NR_brk 45
  60. #define __NR_setgid 46
  61. #define __NR_getgid 47
  62. #define __NR_signal 48
  63. #define __NR_geteuid 49
  64. #define __NR_getegid 50
  65. #define __NR_acct 51
  66. #define __NR_umount 52
  67. #define __NR_lock 53
  68. #define __NR_ioctl 54
  69. #define __NR_fcntl 55
  70. #define __NR_mpx 56
  71. #define __NR_setpgid 57
  72. #define __NR_ulimit 58
  73. #define __NR_oldolduname 59
  74. #define __NR_umask 60
  75. #define __NR_chroot 61
  76. #define __NR_ustat 62
  77. #define __NR_dup2 63
  78. #define __NR_getppid 64
  79. #define __NR_getpgrp 65
  80. #define __NR_setsid 66
  81. #define __NR_sigaction 67
  82. #define __NR_sgetmask 68
  83. #define __NR_ssetmask 69
  84. #define __NR_setreuid 70
  85. #define __NR_setregid 71
  86. #define __NR_sigsuspend 72
  87. #define __NR_sigpending 73
  88. #define __NR_sethostname 74
  89. #define __NR_setrlimit 75
  90. #define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */
  91. #define __NR_getrusage 77
  92. #define __NR_gettimeofday 78
  93. #define __NR_settimeofday 79
  94. #define __NR_getgroups 80
  95. #define __NR_setgroups 81
  96. #define __NR_select 82
  97. #define __NR_symlink 83
  98. #define __NR_oldlstat 84
  99. #define __NR_readlink 85
  100. #define __NR_uselib 86
  101. #define __NR_swapon 87
  102. #define __NR_reboot 88
  103. #define __NR_readdir 89
  104. #define __NR_mmap 90
  105. #define __NR_munmap 91
  106. #define __NR_truncate 92
  107. #define __NR_ftruncate 93
  108. #define __NR_fchmod 94
  109. #define __NR_fchown 95
  110. #define __NR_getpriority 96
  111. #define __NR_setpriority 97
  112. #define __NR_profil 98
  113. #define __NR_statfs 99
  114. #define __NR_fstatfs 100
  115. #define __NR_ioperm 101
  116. #define __NR_socketcall 102
  117. #define __NR_syslog 103
  118. #define __NR_setitimer 104
  119. #define __NR_getitimer 105
  120. #define __NR_stat 106
  121. #define __NR_lstat 107
  122. #define __NR_fstat 108
  123. #define __NR_olduname 109
  124. #define __NR_iopl 110
  125. #define __NR_vhangup 111
  126. #define __NR_idle 112
  127. #define __NR_vm86 113
  128. #define __NR_wait4 114
  129. #define __NR_swapoff 115
  130. #define __NR_sysinfo 116
  131. #define __NR_ipc 117
  132. #define __NR_fsync 118
  133. #define __NR_sigreturn 119
  134. #define __NR_clone 120
  135. #define __NR_setdomainname 121
  136. #define __NR_uname 122
  137. #define __NR_modify_ldt 123
  138. #define __NR_adjtimex 124
  139. #define __NR_mprotect 125
  140. #define __NR_sigprocmask 126
  141. #define __NR_create_module 127
  142. #define __NR_init_module 128
  143. #define __NR_delete_module 129
  144. #define __NR_get_kernel_syms 130
  145. #define __NR_quotactl 131
  146. #define __NR_getpgid 132
  147. #define __NR_fchdir 133
  148. #define __NR_bdflush 134
  149. #define __NR_sysfs 135
  150. #define __NR_personality 136
  151. #define __NR_afs_syscall 137 /* Syscall for Andrew File System */
  152. #define __NR_setfsuid 138
  153. #define __NR_setfsgid 139
  154. #define __NR__llseek 140
  155. #define __NR_getdents 141
  156. #define __NR__newselect 142
  157. #define __NR_flock 143
  158. #define __NR_msync 144
  159. #define __NR_readv 145
  160. #define __NR_writev 146
  161. #define __NR_cacheflush 147
  162. #define __NR_cachectl 148
  163. #define __NR_sysxtensa 149
  164. #define __NR_sysdummy 150
  165. #define __NR_getsid 151
  166. #define __NR_fdatasync 152
  167. #define __NR__sysctl 153
  168. #define __NR_mlock 154
  169. #define __NR_munlock 155
  170. #define __NR_mlockall 156
  171. #define __NR_munlockall 157
  172. #define __NR_sched_setparam 158
  173. #define __NR_sched_getparam 159
  174. #define __NR_sched_setscheduler 160
  175. #define __NR_sched_getscheduler 161
  176. #define __NR_sched_yield 162
  177. #define __NR_sched_get_priority_max 163
  178. #define __NR_sched_get_priority_min 164
  179. #define __NR_sched_rr_get_interval 165
  180. #define __NR_nanosleep 166
  181. #define __NR_mremap 167
  182. #define __NR_accept 168
  183. #define __NR_bind 169
  184. #define __NR_connect 170
  185. #define __NR_getpeername 171
  186. #define __NR_getsockname 172
  187. #define __NR_getsockopt 173
  188. #define __NR_listen 174
  189. #define __NR_recv 175
  190. #define __NR_recvfrom 176
  191. #define __NR_recvmsg 177
  192. #define __NR_send 178
  193. #define __NR_sendmsg 179
  194. #define __NR_sendto 180
  195. #define __NR_setsockopt 181
  196. #define __NR_shutdown 182
  197. #define __NR_socket 183
  198. #define __NR_socketpair 184
  199. #define __NR_setresuid 185
  200. #define __NR_getresuid 186
  201. #define __NR_query_module 187
  202. #define __NR_poll 188
  203. #define __NR_nfsservctl 189
  204. #define __NR_setresgid 190
  205. #define __NR_getresgid 191
  206. #define __NR_prctl 192
  207. #define __NR_rt_sigreturn 193
  208. #define __NR_rt_sigaction 194
  209. #define __NR_rt_sigprocmask 195
  210. #define __NR_rt_sigpending 196
  211. #define __NR_rt_sigtimedwait 197
  212. #define __NR_rt_sigqueueinfo 198
  213. #define __NR_rt_sigsuspend 199
  214. #define __NR_pread 200
  215. #define __NR_pwrite 201
  216. #define __NR_chown 202
  217. #define __NR_getcwd 203
  218. #define __NR_capget 204
  219. #define __NR_capset 205
  220. #define __NR_sigaltstack 206
  221. #define __NR_sendfile 207
  222. #define __NR_streams1 208 /* some people actually want it */
  223. #define __NR_streams2 209 /* some people actually want it */
  224. #define __NR_mmap2 210
  225. #define __NR_truncate64 211
  226. #define __NR_ftruncate64 212
  227. #define __NR_stat64 213
  228. #define __NR_lstat64 214
  229. #define __NR_fstat64 215
  230. #define __NR_pivot_root 216
  231. #define __NR_mincore 217
  232. #define __NR_madvise 218
  233. #define __NR_getdents64 219
  234. #define __NR_vfork 220
  235. /* Keep this last; should always equal the last valid call number. */
  236. #define __NR_Linux_syscalls 220
  237. /* user-visible error numbers are in the range -1 - -125: see
  238. * <asm-xtensa/errno.h> */
  239. #define SYSXTENSA_RESERVED 0 /* don't use this */
  240. #define SYSXTENSA_ATOMIC_SET 1 /* set variable */
  241. #define SYSXTENSA_ATOMIC_EXG_ADD 2 /* exchange memory and add */
  242. #define SYSXTENSA_ATOMIC_ADD 3 /* add to memory */
  243. #define SYSXTENSA_ATOMIC_CMP_SWP 4 /* compare and swap */
  244. #define SYSXTENSA_COUNT 5 /* count of syscall0 functions*/
  245. #ifdef __KERNEL__
  246. #define __syscall_return(type, res) return ((type)(res))
  247. #else
  248. #define __syscall_return(type, res) \
  249. do { \
  250. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  251. /* Avoid using "res" which is declared to be in register r2; \
  252. * errno might expand to a function call and clobber it. */ \
  253. int __err = -(res); \
  254. errno = __err; \
  255. res = -1; \
  256. } \
  257. return (type) (res); \
  258. } while (0)
  259. #endif
  260. /* Tensilica's xt-xcc compiler is much more agressive at code
  261. * optimization than gcc. Multiple __asm__ statements are
  262. * insufficient for xt-xcc because subsequent optimization passes
  263. * (beyond the front-end that knows of __asm__ statements and other
  264. * such GNU Extensions to C) can modify the register selection for
  265. * containment of C variables.
  266. *
  267. * xt-xcc cannot modify the contents of a single __asm__ statement, so
  268. * we create single-asm versions of the syscall macros that are
  269. * suitable and optimal for both xt-xcc and gcc.
  270. *
  271. * Linux takes system-call arguments in registers. The following
  272. * design is optimized for user-land apps (e.g., glibc) which
  273. * typically have a function wrapper around the "syscall" assembly
  274. * instruction. It satisfies the Xtensa ABI while minizing argument
  275. * shifting.
  276. *
  277. * The Xtensa ABI and software conventions require the system-call
  278. * number in a2. If an argument exists in a2, we move it to the next
  279. * available register. Note that for improved efficiency, we do NOT
  280. * shift all parameters down one register to maintain the original
  281. * order.
  282. *
  283. * At best case (zero arguments), we just write the syscall number to
  284. * a2. At worst case (1 to 6 arguments), we move the argument in a2
  285. * to the next available register, then write the syscall number to
  286. * a2.
  287. *
  288. * For clarity, the following truth table enumerates all possibilities.
  289. *
  290. * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
  291. * --------- -------------- ----------------------------------
  292. * 0 a2
  293. * 1 a2 a3
  294. * 2 a2 a4, a3
  295. * 3 a2 a5, a3, a4
  296. * 4 a2 a6, a3, a4, a5
  297. * 5 a2 a7, a3, a4, a5, a6
  298. * 6 a2 a8, a3, a4, a5, a6, a7
  299. */
  300. #define _syscall0(type,name) \
  301. type name(void) \
  302. { \
  303. long __res; \
  304. __asm__ __volatile__ ( \
  305. " movi a2, %1 \n" \
  306. " syscall \n" \
  307. " mov %0, a2 \n" \
  308. : "=a" (__res) \
  309. : "i" (__NR_##name) \
  310. : "a2" \
  311. ); \
  312. __syscall_return(type,__res); \
  313. }
  314. #define _syscall1(type,name,type0,arg0) \
  315. type name(type0 arg0) \
  316. { \
  317. long __res; \
  318. __asm__ __volatile__ ( \
  319. " mov a3, %2 \n" \
  320. " movi a2, %1 \n" \
  321. " syscall \n" \
  322. " mov %0, a2 \n" \
  323. : "=a" (__res) \
  324. : "i" (__NR_##name), "a" (arg0) \
  325. : "a2", "a3" \
  326. ); \
  327. __syscall_return(type,__res); \
  328. }
  329. #define _syscall2(type,name,type0,arg0,type1,arg1) \
  330. type name(type0 arg0,type1 arg1) \
  331. { \
  332. long __res; \
  333. __asm__ __volatile__ ( \
  334. " mov a4, %2 \n" \
  335. " mov a3, %3 \n" \
  336. " movi a2, %1 \n" \
  337. " syscall \n" \
  338. " mov %0, a2 \n" \
  339. : "=a" (__res) \
  340. : "i" (__NR_##name), "a" (arg0), "a" (arg1) \
  341. : "a2", "a3", "a4" \
  342. ); \
  343. __syscall_return(type,__res); \
  344. }
  345. #define _syscall3(type,name,type0,arg0,type1,arg1,type2,arg2) \
  346. type name(type0 arg0,type1 arg1,type2 arg2) \
  347. { \
  348. long __res; \
  349. __asm__ __volatile__ ( \
  350. " mov a5, %2 \n" \
  351. " mov a4, %4 \n" \
  352. " mov a3, %3 \n" \
  353. " movi a2, %1 \n" \
  354. " syscall \n" \
  355. " mov %0, a2 \n" \
  356. : "=a" (__res) \
  357. : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2) \
  358. : "a2", "a3", "a4", "a5" \
  359. ); \
  360. __syscall_return(type,__res); \
  361. }
  362. #define _syscall4(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3) \
  363. type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3) \
  364. { \
  365. long __res; \
  366. __asm__ __volatile__ ( \
  367. " mov a6, %2 \n" \
  368. " mov a5, %5 \n" \
  369. " mov a4, %4 \n" \
  370. " mov a3, %3 \n" \
  371. " movi a2, %1 \n" \
  372. " syscall \n" \
  373. " mov %0, a2 \n" \
  374. : "=a" (__res) \
  375. : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), "a" (arg3) \
  376. : "a2", "a3", "a4", "a5", "a6" \
  377. ); \
  378. __syscall_return(type,__res); \
  379. }
  380. /* Note that we save and restore the a7 frame pointer.
  381. * Including a7 in the clobber list doesn't do what you'd expect.
  382. */
  383. #define _syscall5(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  384. type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
  385. { \
  386. long __res; \
  387. __asm__ __volatile__ ( \
  388. " mov a9, a7 \n" \
  389. " mov a7, %2 \n" \
  390. " mov a6, %6 \n" \
  391. " mov a5, %5 \n" \
  392. " mov a4, %4 \n" \
  393. " mov a3, %3 \n" \
  394. " movi a2, %1 \n" \
  395. " syscall \n" \
  396. " mov a7, a9 \n" \
  397. " mov %0, a2 \n" \
  398. : "=a" (__res) \
  399. : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), \
  400. "a" (arg3), "a" (arg4) \
  401. : "a2", "a3", "a4", "a5", "a6", "a9" \
  402. ); \
  403. __syscall_return(type,__res); \
  404. }
  405. /* Note that we save and restore the a7 frame pointer.
  406. * Including a7 in the clobber list doesn't do what you'd expect.
  407. */
  408. #define _syscall6(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  409. type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  410. { \
  411. long __res; \
  412. __asm__ __volatile__ ( \
  413. " mov a9, a7 \n" \
  414. " mov a8, %2 \n" \
  415. " mov a7, %7 \n" \
  416. " mov a6, %6 \n" \
  417. " mov a5, %5 \n" \
  418. " mov a4, %4 \n" \
  419. " mov a3, %3 \n" \
  420. " movi a2, %1 \n" \
  421. " syscall \n" \
  422. " mov a7, a9 \n" \
  423. " mov %0, a2 \n" \
  424. : "=a" (__res) \
  425. : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), \
  426. "a" (arg3), "a" (arg4), "a" (arg5) \
  427. : "a2", "a3", "a4", "a5", "a6", "a8", "a9" \
  428. ); \
  429. __syscall_return(type,__res); \
  430. }
  431. #ifdef __KERNEL_SYSCALLS__
  432. #include <linux/compiler.h>
  433. #include <linux/types.h>
  434. #include <linux/syscalls.h>
  435. /*
  436. * we need this inline - forking from kernel space will result
  437. * in NO COPY ON WRITE (!!!), until an execve is executed. This
  438. * is no problem, but for the stack. This is handled by not letting
  439. * main() use the stack at all after fork(). Thus, no function
  440. * calls - which means inline code for fork too, as otherwise we
  441. * would use the stack upon exit from 'fork()'.
  442. *
  443. * Actually only pause and fork are needed inline, so that there
  444. * won't be any messing with the stack from main(), but we define
  445. * some others too.
  446. */
  447. #define __NR__exit __NR_exit
  448. static __inline__ _syscall0(int,pause)
  449. //static __inline__ _syscall1(int,setup,int,magic) FIXME
  450. static __inline__ _syscall0(int,sync)
  451. static __inline__ _syscall0(pid_t,setsid)
  452. static __inline__ _syscall3(int,write,int,fd,const char *,buf,off_t,count)
  453. static __inline__ _syscall3(int,read,int,fd,char *,buf,off_t,count)
  454. static __inline__ _syscall3(off_t,lseek,int,fd,off_t,offset,int,count)
  455. static __inline__ _syscall1(int,dup,int,fd)
  456. static __inline__ _syscall3(int,execve,const char*,file,char**,argv,char**,envp)
  457. static __inline__ _syscall3(int,open,const char *,file,int,flag,int,mode)
  458. static __inline__ _syscall1(int,close,int,fd)
  459. static __inline__ _syscall1(int,_exit,int,exitcode)
  460. static __inline__ _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
  461. static __inline__ _syscall1(int,delete_module,const char *,name)
  462. struct stat;
  463. static __inline__ _syscall2(int,fstat,int,fd,struct stat *,buf)
  464. static __inline__ _syscall0(pid_t,getpid)
  465. static __inline__ _syscall2(int,kill,int,pid,int,sig)
  466. static __inline__ _syscall2(int,stat,const char *, path,struct stat *,buf)
  467. static __inline__ _syscall1(int,unlink,char *,pathname)
  468. extern pid_t waitpid(int, int*, int );
  469. static __inline__ pid_t wait(int * wait_stat)
  470. {
  471. return waitpid(-1,wait_stat,0);
  472. }
  473. #endif
  474. /*
  475. * "Conditional" syscalls
  476. *
  477. * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
  478. * but it doesn't work on all toolchains, so we just do it by hand
  479. */
  480. #define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall");
  481. #ifdef __KERNEL__
  482. #define __ARCH_WANT_IPC_PARSE_VERSION
  483. #define __ARCH_WANT_OLD_READDIR
  484. #define __ARCH_WANT_OLD_STAT
  485. #define __ARCH_WANT_STAT64
  486. #define __ARCH_WANT_SYS_ALARM
  487. #define __ARCH_WANT_SYS_GETHOSTNAME
  488. #define __ARCH_WANT_SYS_PAUSE
  489. #define __ARCH_WANT_SYS_SGETMASK
  490. #define __ARCH_WANT_SYS_SIGNAL
  491. #define __ARCH_WANT_SYS_TIME
  492. #define __ARCH_WANT_SYS_UTIME
  493. #define __ARCH_WANT_SYS_WAITPID
  494. #define __ARCH_WANT_SYS_SOCKETCALL
  495. #define __ARCH_WANT_SYS_FADVISE64
  496. #define __ARCH_WANT_SYS_GETPGRP
  497. #define __ARCH_WANT_SYS_LLSEEK
  498. #define __ARCH_WANT_SYS_NICE
  499. #define __ARCH_WANT_SYS_OLD_GETRLIMIT
  500. #define __ARCH_WANT_SYS_OLDUMOUNT
  501. #define __ARCH_WANT_SYS_SIGPENDING
  502. #define __ARCH_WANT_SYS_SIGPROCMASK
  503. #define __ARCH_WANT_SYS_RT_SIGACTION
  504. #endif
  505. #endif /* _XTENSA_UNISTD_H */