1
2
3
4
5
6
7
8
9
10
11#ifndef _XTENSA_PLATFORM_ISS_SIMCALL_H
12#define _XTENSA_PLATFORM_ISS_SIMCALL_H
13
14
15
16
17
18
19#define SYS_nop 0
20#define SYS_exit 1
21#define SYS_fork 2
22#define SYS_read 3
23#define SYS_write 4
24#define SYS_open 5
25#define SYS_close 6
26#define SYS_rename 7
27#define SYS_creat 8
28#define SYS_link 9
29#define SYS_unlink 10
30#define SYS_execv 11
31#define SYS_execve 12
32#define SYS_pipe 13
33#define SYS_stat 14
34#define SYS_chmod 15
35#define SYS_chown 16
36#define SYS_utime 17
37#define SYS_wait 18
38#define SYS_lseek 19
39#define SYS_getpid 20
40#define SYS_isatty 21
41#define SYS_fstat 22
42#define SYS_time 23
43#define SYS_gettimeofday 24
44#define SYS_times 25
45#define SYS_socket 26
46#define SYS_sendto 27
47#define SYS_recvfrom 28
48#define SYS_select_one 29
49#define SYS_bind 30
50#define SYS_ioctl 31
51
52
53
54
55
56#define XTISS_SELECT_ONE_READ 1
57#define XTISS_SELECT_ONE_WRITE 2
58#define XTISS_SELECT_ONE_EXCEPT 3
59
60static int errno;
61
62static inline int __simc(int a, int b, int c, int d)
63{
64 int ret;
65 register int a1 asm("a2") = a;
66 register int b1 asm("a3") = b;
67 register int c1 asm("a4") = c;
68 register int d1 asm("a5") = d;
69 __asm__ __volatile__ (
70 "simcall\n"
71 "mov %0, a2\n"
72 "mov %1, a3\n"
73 : "=a" (ret), "=a" (errno), "+r"(a1), "+r"(b1)
74 : "r"(c1), "r"(d1)
75 : "memory");
76 return ret;
77}
78
79static inline int simc_exit(int exit_code)
80{
81 return __simc(SYS_exit, exit_code, 0, 0);
82}
83
84static inline int simc_open(const char *file, int flags, int mode)
85{
86 return __simc(SYS_open, (int) file, flags, mode);
87}
88
89static inline int simc_close(int fd)
90{
91 return __simc(SYS_close, fd, 0, 0);
92}
93
94static inline int simc_ioctl(int fd, int request, void *arg)
95{
96 return __simc(SYS_ioctl, fd, request, (int) arg);
97}
98
99static inline int simc_read(int fd, void *buf, size_t count)
100{
101 return __simc(SYS_read, fd, (int) buf, count);
102}
103
104static inline int simc_write(int fd, const void *buf, size_t count)
105{
106 return __simc(SYS_write, fd, (int) buf, count);
107}
108
109static inline int simc_poll(int fd)
110{
111 struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
112
113 return __simc(SYS_select_one, fd, XTISS_SELECT_ONE_READ, (int)&tv);
114}
115
116static inline int simc_lseek(int fd, uint32_t off, int whence)
117{
118 return __simc(SYS_lseek, fd, off, whence);
119}
120
121#endif
122
123