1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright © 2023 Keith Packard
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above
14  *    copyright notice, this list of conditions and the following
15  *    disclaimer in the documentation and/or other materials provided
16  *    with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "arc_semihost.h"
37 
38 void
arc_semihost_errno(int def)39 arc_semihost_errno(int def)
40 {
41     int err = arc_semihost0(SYS_SEMIHOST_errno);
42 
43     switch (err) {
44     case TARGET_ERRNO_EPERM: errno = EPERM; break;
45     case TARGET_ERRNO_ENOENT: errno = ENOENT; break;
46     case TARGET_ERRNO_ESRCH: errno = ESRCH; break;
47     case TARGET_ERRNO_EINTR: errno = EINTR; break;
48     case TARGET_ERRNO_EIO: errno = EIO; break;
49     case TARGET_ERRNO_ENXIO: errno = ENXIO; break;
50     case TARGET_ERRNO_E2BIG: errno = E2BIG; break;
51     case TARGET_ERRNO_ENOEXEC: errno = ENOEXEC; break;
52     case TARGET_ERRNO_EBADF: errno = EBADF; break;
53     case TARGET_ERRNO_ECHILD: errno = ECHILD; break;
54     case TARGET_ERRNO_EAGAIN: errno = EAGAIN; break;
55     case TARGET_ERRNO_ENOMEM: errno = ENOMEM; break;
56     case TARGET_ERRNO_EACCES: errno = EACCES; break;
57     case TARGET_ERRNO_EFAULT: errno = EFAULT; break;
58 //    case TARGET_ERRNO_ENOTBLK: errno = ENOTBLK; break;
59     case TARGET_ERRNO_EBUSY: errno = EBUSY; break;
60     case TARGET_ERRNO_EEXIST: errno = EEXIST; break;
61     case TARGET_ERRNO_EXDEV: errno = EXDEV; break;
62     case TARGET_ERRNO_ENODEV: errno = ENODEV; break;
63     case TARGET_ERRNO_ENOTDIR: errno = ENOTDIR; break;
64     case TARGET_ERRNO_EISDIR: errno = EISDIR; break;
65     case TARGET_ERRNO_EINVAL: errno = EINVAL; break;
66     case TARGET_ERRNO_ENFILE: errno = ENFILE; break;
67     case TARGET_ERRNO_EMFILE: errno = EMFILE; break;
68     case TARGET_ERRNO_ENOTTY: errno = ENOTTY; break;
69     case TARGET_ERRNO_ETXTBSY: errno = ETXTBSY; break;
70     case TARGET_ERRNO_EFBIG: errno = EFBIG; break;
71     case TARGET_ERRNO_ENOSPC: errno = ENOSPC; break;
72     case TARGET_ERRNO_ESPIPE: errno = ESPIPE; break;
73     case TARGET_ERRNO_EROFS: errno = EROFS; break;
74     case TARGET_ERRNO_EMLINK: errno = EMLINK; break;
75     case TARGET_ERRNO_EPIPE: errno = EPIPE; break;
76     case TARGET_ERRNO_EDOM: errno = EDOM; break;
77     case TARGET_ERRNO_ERANGE: errno = ERANGE; break;
78     case TARGET_ERRNO_ENOMSG: errno = ENOMSG; break;
79     case TARGET_ERRNO_EIDRM: errno = EIDRM; break;
80 //    case TARGET_ERRNO_ECHRNG: errno = ECHRNG; break;
81 //    case TARGET_ERRNO_EL2NSYNC: errno = EL2NSYNC; break;
82 //    case TARGET_ERRNO_EL3HLT: errno = EL3HLT; break;
83 //    case TARGET_ERRNO_EL3RST: errno = EL3RST; break;
84 //    case TARGET_ERRNO_ELNRNG: errno = ELNRNG; break;
85 //    case TARGET_ERRNO_EUNATCH: errno = EUNATCH; break;
86 //    case TARGET_ERRNO_ENOCSI: errno = ENOCSI; break;
87 //    case TARGET_ERRNO_EL2HLT: errno = EL2HLT; break;
88     case TARGET_ERRNO_EDEADLK: errno = EDEADLK; break;
89     case TARGET_ERRNO_ENOLCK: errno = ENOLCK; break;
90 //    case TARGET_ERRNO_EBADE: errno = EBADE; break;
91 //    case TARGET_ERRNO_EBADR: errno = EBADR; break;
92 //    case TARGET_ERRNO_EXFULL: errno = EXFULL; break;
93 //    case TARGET_ERRNO_ENOANO: errno = ENOANO; break;
94 //    case TARGET_ERRNO_EBADRQC: errno = EBADRQC; break;
95 //    case TARGET_ERRNO_EBADSLT: errno = EBADSLT; break;
96 //    case TARGET_ERRNO_EDEADLOCK: errno = EDEADLOCK; break;
97 //    case TARGET_ERRNO_EBFONT: errno = EBFONT; break;
98     case TARGET_ERRNO_ENOSTR: errno = ENOSTR; break;
99     case TARGET_ERRNO_ENODATA: errno = ENODATA; break;
100     case TARGET_ERRNO_ETIME: errno = ETIME; break;
101     case TARGET_ERRNO_ENOSR: errno = ENOSR; break;
102 //    case TARGET_ERRNO_ENONET: errno = ENONET; break;
103 //    case TARGET_ERRNO_ENOPKG: errno = ENOPKG; break;
104 //    case TARGET_ERRNO_EREMOTE: errno = EREMOTE; break;
105     case TARGET_ERRNO_ENOLINK: errno = ENOLINK; break;
106 //    case TARGET_ERRNO_EADV: errno = EADV; break;
107 //    case TARGET_ERRNO_ESRMNT: errno = ESRMNT; break;
108 //    case TARGET_ERRNO_ECOMM: errno = ECOMM; break;
109     case TARGET_ERRNO_EPROTO: errno = EPROTO; break;
110     case TARGET_ERRNO_EMULTIHOP: errno = EMULTIHOP; break;
111 //    case TARGET_ERRNO_ELBIN: errno = ELBIN; break;
112 //    case TARGET_ERRNO_EDOTDOT: errno = EDOTDOT; break;
113     case TARGET_ERRNO_EBADMSG: errno = EBADMSG; break;
114 //    case TARGET_ERRNO_EFTYPE: errno = EFTYPE; break;
115 //    case TARGET_ERRNO_ENOTUNIQ: errno = ENOTUNIQ; break;
116 //    case TARGET_ERRNO_EBADFD: errno = EBADFD; break;
117 //    case TARGET_ERRNO_EREMCHG: errno = EREMCHG; break;
118 //    case TARGET_ERRNO_ELIBACC: errno = ELIBACC; break;
119 //    case TARGET_ERRNO_ELIBBAD: errno = ELIBBAD; break;
120 //    case TARGET_ERRNO_ELIBSCN: errno = ELIBSCN; break;
121 //    case TARGET_ERRNO_ELIBMAX: errno = ELIBMAX; break;
122 //    case TARGET_ERRNO_ELIBEXEC: errno = ELIBEXEC; break;
123     case TARGET_ERRNO_ENOSYS: errno = ENOSYS; break;
124 //    case TARGET_ERRNO_ENMFILE: errno = ENMFILE; break;
125     case TARGET_ERRNO_ENOTEMPTY: errno = ENOTEMPTY; break;
126     case TARGET_ERRNO_ENAMETOOLONG: errno = ENAMETOOLONG; break;
127     case TARGET_ERRNO_ELOOP: errno = ELOOP; break;
128     case TARGET_ERRNO_EOPNOTSUPP: errno = EOPNOTSUPP; break;
129 //    case TARGET_ERRNO_EPFNOSUPPORT: errno = EPFNOSUPPORT; break;
130     case TARGET_ERRNO_ECONNRESET: errno = ECONNRESET; break;
131     case TARGET_ERRNO_ENOBUFS: errno = ENOBUFS; break;
132 //    case TARGET_ERRNO_EAFNOSUPPORT: errno = EAFNOSUPPORT; break;
133     case TARGET_ERRNO_EPROTOTYPE: errno = EPROTOTYPE; break;
134     case TARGET_ERRNO_ENOTSOCK: errno = ENOTSOCK; break;
135     case TARGET_ERRNO_ENOPROTOOPT: errno = ENOPROTOOPT; break;
136 //    case TARGET_ERRNO_ESHUTDOWN: errno = ESHUTDOWN; break;
137     case TARGET_ERRNO_ECONNREFUSED: errno = ECONNREFUSED; break;
138     case TARGET_ERRNO_EADDRINUSE: errno = EADDRINUSE; break;
139     case TARGET_ERRNO_ECONNABORTED: errno = ECONNABORTED; break;
140     case TARGET_ERRNO_ENETUNREACH: errno = ENETUNREACH; break;
141     case TARGET_ERRNO_ENETDOWN: errno = ENETDOWN; break;
142     case TARGET_ERRNO_ETIMEDOUT: errno = ETIMEDOUT; break;
143 //    case TARGET_ERRNO_EHOSTDOWN: errno = EHOSTDOWN; break;
144     case TARGET_ERRNO_EHOSTUNREACH: errno = EHOSTUNREACH; break;
145     case TARGET_ERRNO_EINPROGRESS: errno = EINPROGRESS; break;
146     case TARGET_ERRNO_EALREADY: errno = EALREADY; break;
147     case TARGET_ERRNO_EDESTADDRREQ: errno = EDESTADDRREQ; break;
148     case TARGET_ERRNO_EMSGSIZE: errno = EMSGSIZE; break;
149     case TARGET_ERRNO_EPROTONOSUPPORT: errno = EPROTONOSUPPORT; break;
150 //    case TARGET_ERRNO_ESOCKTNOSUPPORT: errno = ESOCKTNOSUPPORT; break;
151     case TARGET_ERRNO_EADDRNOTAVAIL: errno = EADDRNOTAVAIL; break;
152     case TARGET_ERRNO_ENETRESET: errno = ENETRESET; break;
153     case TARGET_ERRNO_EISCONN: errno = EISCONN; break;
154     case TARGET_ERRNO_ENOTCONN: errno = ENOTCONN; break;
155 //    case TARGET_ERRNO_ETOOMANYREFS: errno = ETOOMANYREFS; break;
156 //    case TARGET_ERRNO_EPROCLIM: errno = EPROCLIM; break;
157 //    case TARGET_ERRNO_EUSERS: errno = EUSERS; break;
158     case TARGET_ERRNO_EDQUOT: errno = EDQUOT; break;
159     case TARGET_ERRNO_ESTALE: errno = ESTALE; break;
160     case TARGET_ERRNO_ENOTSUP: errno = ENOTSUP; break;
161 //    case TARGET_ERRNO_ENOMEDIUM: errno = ENOMEDIUM; break;
162 //    case TARGET_ERRNO_ENOSHARE: errno = ENOSHARE; break;
163 //    case TARGET_ERRNO_ECASECLASH: errno = ECASECLASH; break;
164     case TARGET_ERRNO_EILSEQ: errno = EILSEQ; break;
165     case TARGET_ERRNO_EOVERFLOW: errno = EOVERFLOW; break;
166     case TARGET_ERRNO_ECANCELED: errno = ECANCELED; break;
167     case TARGET_ERRNO_ENOTRECOVERABLE: errno = ENOTRECOVERABLE; break;
168     case TARGET_ERRNO_EOWNERDEAD: errno = EOWNERDEAD; break;
169 //    case TARGET_ERRNO_ESTRPIPE: errno = ESTRPIPE; break;
170 //    case TARGET_ERRNO_EHWPOISON: errno = EHWPOISON; break;
171 //    case TARGET_ERRNO_EISNAM: errno = EISNAM; break;
172 //    case TARGET_ERRNO_EKEYEXPIRED: errno = EKEYEXPIRED; break;
173 //    case TARGET_ERRNO_EKEYREJECTED: errno = EKEYREJECTED; break;
174 //    case TARGET_ERRNO_EKEYREVOKED: errno = EKEYREVOKED; break;
175     default: errno = def; break;
176     }
177 }
178