1 /*
2 * include/asm-xtensa/platform-iss/simcall.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 Tensilica Inc.
9 * Copyright (C) 2017 Cadence Design Systems Inc.
10 */
11
12 #ifndef _XTENSA_PLATFORM_ISS_SIMCALL_H
13 #define _XTENSA_PLATFORM_ISS_SIMCALL_H
14
15
16 /*
17 * System call like services offered by the simulator host.
18 */
19
20 #define SYS_nop 0 /* unused */
21 #define SYS_exit 1 /*x*/
22 #define SYS_fork 2
23 #define SYS_read 3 /*x*/
24 #define SYS_write 4 /*x*/
25 #define SYS_open 5 /*x*/
26 #define SYS_close 6 /*x*/
27 #define SYS_rename 7 /*x 38 - waitpid */
28 #define SYS_creat 8 /*x*/
29 #define SYS_link 9 /*x (not implemented on WIN32) */
30 #define SYS_unlink 10 /*x*/
31 #define SYS_execv 11 /* n/a - execve */
32 #define SYS_execve 12 /* 11 - chdir */
33 #define SYS_pipe 13 /* 42 - time */
34 #define SYS_stat 14 /* 106 - mknod */
35 #define SYS_chmod 15
36 #define SYS_chown 16 /* 202 - lchown */
37 #define SYS_utime 17 /* 30 - break */
38 #define SYS_wait 18 /* n/a - oldstat */
39 #define SYS_lseek 19 /*x*/
40 #define SYS_getpid 20
41 #define SYS_isatty 21 /* n/a - mount */
42 #define SYS_fstat 22 /* 108 - oldumount */
43 #define SYS_time 23 /* 13 - setuid */
44 #define SYS_gettimeofday 24 /*x 78 - getuid (not implemented on WIN32) */
45 #define SYS_times 25 /*X 43 - stime (Xtensa-specific implementation) */
46 #define SYS_socket 26
47 #define SYS_sendto 27
48 #define SYS_recvfrom 28
49 #define SYS_select_one 29 /* not compitible select, one file descriptor at the time */
50 #define SYS_bind 30
51 #define SYS_ioctl 31
52
53 #define SYS_iss_argc 1000 /* returns value of argc */
54 #define SYS_iss_argv_size 1001 /* bytes needed for argv & arg strings */
55 #define SYS_iss_set_argv 1002 /* saves argv & arg strings at given addr */
56
57 /*
58 * SYS_select_one specifiers
59 */
60
61 #define XTISS_SELECT_ONE_READ 1
62 #define XTISS_SELECT_ONE_WRITE 2
63 #define XTISS_SELECT_ONE_EXCEPT 3
64
65 static int errno;
66
__simc(int a,int b,int c,int d)67 static inline int __simc(int a, int b, int c, int d)
68 {
69 int ret;
70 register int a1 asm("a2") = a;
71 register int b1 asm("a3") = b;
72 register int c1 asm("a4") = c;
73 register int d1 asm("a5") = d;
74 __asm__ __volatile__ (
75 "simcall\n"
76 "mov %0, a2\n"
77 "mov %1, a3\n"
78 : "=a" (ret), "=a" (errno), "+r"(a1), "+r"(b1)
79 : "r"(c1), "r"(d1)
80 : "memory");
81 return ret;
82 }
83
simc_exit(int exit_code)84 static inline int simc_exit(int exit_code)
85 {
86 return __simc(SYS_exit, exit_code, 0, 0);
87 }
88
simc_open(const char * file,int flags,int mode)89 static inline int simc_open(const char *file, int flags, int mode)
90 {
91 return __simc(SYS_open, (int) file, flags, mode);
92 }
93
simc_close(int fd)94 static inline int simc_close(int fd)
95 {
96 return __simc(SYS_close, fd, 0, 0);
97 }
98
simc_ioctl(int fd,int request,void * arg)99 static inline int simc_ioctl(int fd, int request, void *arg)
100 {
101 return __simc(SYS_ioctl, fd, request, (int) arg);
102 }
103
simc_read(int fd,void * buf,size_t count)104 static inline int simc_read(int fd, void *buf, size_t count)
105 {
106 return __simc(SYS_read, fd, (int) buf, count);
107 }
108
simc_write(int fd,const void * buf,size_t count)109 static inline int simc_write(int fd, const void *buf, size_t count)
110 {
111 return __simc(SYS_write, fd, (int) buf, count);
112 }
113
simc_poll(int fd)114 static inline int simc_poll(int fd)
115 {
116 struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
117
118 return __simc(SYS_select_one, fd, XTISS_SELECT_ONE_READ, (int)&tv);
119 }
120
simc_lseek(int fd,uint32_t off,int whence)121 static inline int simc_lseek(int fd, uint32_t off, int whence)
122 {
123 return __simc(SYS_lseek, fd, off, whence);
124 }
125
simc_argc(void)126 static inline int simc_argc(void)
127 {
128 return __simc(SYS_iss_argc, 0, 0, 0);
129 }
130
simc_argv_size(void)131 static inline int simc_argv_size(void)
132 {
133 return __simc(SYS_iss_argv_size, 0, 0, 0);
134 }
135
simc_argv(void * buf)136 static inline void simc_argv(void *buf)
137 {
138 __simc(SYS_iss_set_argv, (int)buf, 0, 0);
139 }
140
141 #endif /* _XTENSA_PLATFORM_ISS_SIMCALL_H */
142
143