1 |
786 |
skrzyp |
#ifndef CYGONCE_HAL_HAL_IO_H
|
2 |
|
|
#define CYGONCE_HAL_HAL_IO_H
|
3 |
|
|
|
4 |
|
|
//=============================================================================
|
5 |
|
|
//
|
6 |
|
|
// hal_io.h
|
7 |
|
|
//
|
8 |
|
|
// HAL device IO register support.
|
9 |
|
|
//
|
10 |
|
|
//=============================================================================
|
11 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
19 |
|
|
// version.
|
20 |
|
|
//
|
21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
24 |
|
|
// for more details.
|
25 |
|
|
//
|
26 |
|
|
// You should have received a copy of the GNU General Public License
|
27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
29 |
|
|
//
|
30 |
|
|
// As a special exception, if other files instantiate templates or use
|
31 |
|
|
// macros or inline functions from this file, or you compile this file
|
32 |
|
|
// and link it with other works to produce a work based on this file,
|
33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
34 |
|
|
// the GNU General Public License. However the source code for this file
|
35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
36 |
|
|
// General Public License v2.
|
37 |
|
|
//
|
38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
39 |
|
|
// on this file might be covered by the GNU General Public License.
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//=============================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): nickg
|
46 |
|
|
// Contributors:nickg, bartv, alunn, jlarmour
|
47 |
|
|
// Date: 1998-02-17
|
48 |
|
|
// Purpose: Define IO register support
|
49 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
50 |
|
|
// device IO control registers.
|
51 |
|
|
//
|
52 |
|
|
// For the synthetic target these macros should never
|
53 |
|
|
// actually be used since the application will run as an
|
54 |
|
|
// ordinary user application and should not have
|
55 |
|
|
// permission to access any real hardware. Instead
|
56 |
|
|
// hardware access should go via the auxiliary. Possibly
|
57 |
|
|
// the macros should be #pragma poison'd, but some people
|
58 |
|
|
// may want to run the synthetic target in a way that
|
59 |
|
|
// does involve accessing real hardware.
|
60 |
|
|
//
|
61 |
|
|
// The synthetic target provides some additional I/O
|
62 |
|
|
// facilities in the form of Linux system calls. A useful
|
63 |
|
|
// subset of these are prototyped here, together with
|
64 |
|
|
// associated constants. There are also I/O operations to
|
65 |
|
|
// interact with the auxiliary.
|
66 |
|
|
//
|
67 |
|
|
// Usage:
|
68 |
|
|
// #include <cyg/hal/hal_io.h>
|
69 |
|
|
// ...
|
70 |
|
|
//
|
71 |
|
|
//####DESCRIPTIONEND####
|
72 |
|
|
//
|
73 |
|
|
//=============================================================================
|
74 |
|
|
|
75 |
|
|
#include <cyg/infra/cyg_type.h>
|
76 |
|
|
|
77 |
|
|
#include <cyg/hal/var_io.h> // Variant-specific definitions
|
78 |
|
|
|
79 |
|
|
//-----------------------------------------------------------------------------
|
80 |
|
|
// IO Register address.
|
81 |
|
|
// This type is for recording the address of an IO register.
|
82 |
|
|
|
83 |
|
|
typedef volatile CYG_ADDRWORD HAL_IO_REGISTER;
|
84 |
|
|
|
85 |
|
|
//-----------------------------------------------------------------------------
|
86 |
|
|
// BYTE Register access.
|
87 |
|
|
// Individual and vectorized access to 8 bit registers.
|
88 |
|
|
|
89 |
|
|
#define HAL_READ_UINT8( _register_, _value_ ) \
|
90 |
|
|
CYG_MACRO_START \
|
91 |
|
|
((_value_) = *((volatile CYG_BYTE *)(_register_))); \
|
92 |
|
|
CYG_MACRO_END
|
93 |
|
|
|
94 |
|
|
#define HAL_WRITE_UINT8( _register_, _value_ ) \
|
95 |
|
|
CYG_MACRO_START \
|
96 |
|
|
(*((volatile CYG_BYTE *)(_register_)) = (_value_)); \
|
97 |
|
|
CYG_MACRO_END
|
98 |
|
|
|
99 |
|
|
#define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
100 |
|
|
CYG_MACRO_START \
|
101 |
|
|
cyg_count32 _i_,_j_; \
|
102 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
103 |
|
|
(_buf_)[_i_] = ((volatile CYG_BYTE *)(_register_))[_j_]; \
|
104 |
|
|
} \
|
105 |
|
|
CYG_MACRO_END
|
106 |
|
|
|
107 |
|
|
#define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
108 |
|
|
CYG_MACRO_START \
|
109 |
|
|
cyg_count32 _i_,_j_; \
|
110 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
111 |
|
|
((volatile CYG_BYTE *)(_register_))[_j_] = (_buf_)[_i_]; \
|
112 |
|
|
} \
|
113 |
|
|
CYG_MACRO_END
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
//-----------------------------------------------------------------------------
|
117 |
|
|
// 16 bit access.
|
118 |
|
|
// Individual and vectorized access to 16 bit registers.
|
119 |
|
|
|
120 |
|
|
#define HAL_READ_UINT16( _register_, _value_ ) \
|
121 |
|
|
CYG_MACRO_START \
|
122 |
|
|
((_value_) = *((volatile CYG_WORD16 *)(_register_))); \
|
123 |
|
|
CYG_MACRO_END
|
124 |
|
|
|
125 |
|
|
#define HAL_WRITE_UINT16( _register_, _value_ ) \
|
126 |
|
|
CYG_MACRO_START \
|
127 |
|
|
(*((volatile CYG_WORD16 *)(_register_)) = (_value_)); \
|
128 |
|
|
CYG_MACRO_END
|
129 |
|
|
|
130 |
|
|
#define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
131 |
|
|
CYG_MACRO_START \
|
132 |
|
|
cyg_count32 _i_,_j_; \
|
133 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
134 |
|
|
(_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_j_]; \
|
135 |
|
|
} \
|
136 |
|
|
CYG_MACRO_END
|
137 |
|
|
|
138 |
|
|
#define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
139 |
|
|
CYG_MACRO_START \
|
140 |
|
|
cyg_count32 _i_,_j_; \
|
141 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
142 |
|
|
((volatile CYG_WORD16 *)(_register_))[_j_] = (_buf_)[_i_]; \
|
143 |
|
|
} \
|
144 |
|
|
CYG_MACRO_END
|
145 |
|
|
|
146 |
|
|
//-----------------------------------------------------------------------------
|
147 |
|
|
// 32 bit access.
|
148 |
|
|
// Individual and vectorized access to 32 bit registers.
|
149 |
|
|
|
150 |
|
|
#define HAL_READ_UINT32( _register_, _value_ ) \
|
151 |
|
|
CYG_MACRO_START \
|
152 |
|
|
((_value_) = *((volatile CYG_WORD32 *)(_register_))); \
|
153 |
|
|
CYG_MACRO_END
|
154 |
|
|
|
155 |
|
|
#define HAL_WRITE_UINT32( _register_, _value_ ) \
|
156 |
|
|
CYG_MACRO_START \
|
157 |
|
|
(*((volatile CYG_WORD32 *)(_register_)) = (_value_)); \
|
158 |
|
|
CYG_MACRO_END
|
159 |
|
|
|
160 |
|
|
#define HAL_READ_UINT32_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
161 |
|
|
CYG_MACRO_START \
|
162 |
|
|
cyg_count32 _i_,_j_; \
|
163 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
164 |
|
|
(_buf_)[_i_] = ((volatile CYG_WORD32 *)(_register_))[_j_]; \
|
165 |
|
|
} \
|
166 |
|
|
CYG_MACRO_END
|
167 |
|
|
|
168 |
|
|
#define HAL_WRITE_UINT32_VECTOR( _register_, _buf_, _count_, _step_ ) \
|
169 |
|
|
CYG_MACRO_START \
|
170 |
|
|
cyg_count32 _i_,_j_; \
|
171 |
|
|
for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \
|
172 |
|
|
((volatile CYG_WORD32 *)(_register_))[_j_] = (_buf_)[_i_]; \
|
173 |
|
|
} \
|
174 |
|
|
CYG_MACRO_END
|
175 |
|
|
|
176 |
|
|
// ----------------------------------------------------------------------------
|
177 |
|
|
// Linux system calls and associated structures and constants. This is
|
178 |
|
|
// by no means a complete list, but there is enough information for
|
179 |
|
|
// the needs of the relevant HAL packages. The information needs to be
|
180 |
|
|
// kept in synch with the Linux header files, but in practice
|
181 |
|
|
// divergence will be rare because that would imply incompatible
|
182 |
|
|
// changes in the Linux kernel API.
|
183 |
|
|
//
|
184 |
|
|
// It may seem tempting to import the Linux header files directly, but
|
185 |
|
|
// that would prevent cross-compilation and introduce all kinds of
|
186 |
|
|
// namespace pollution.
|
187 |
|
|
//
|
188 |
|
|
// The actual implementation lives in variant HAL packages since
|
189 |
|
|
// typically they involve direct system calls via bits of assembler.
|
190 |
|
|
// Note that only a subset of system calls are actually implemented,
|
191 |
|
|
// so the variant HALs may need to be updated if this list needs to
|
192 |
|
|
// be extended.
|
193 |
|
|
|
194 |
|
|
// Error codes.
|
195 |
|
|
#define CYG_HAL_SYS_EINTR 4
|
196 |
|
|
#define CYG_HAL_SYS_EAGAIN 11
|
197 |
|
|
|
198 |
|
|
// Signal-related information
|
199 |
|
|
#define CYG_HAL_SYS_SIGHUP 1
|
200 |
|
|
#define CYG_HAL_SYS_SIGINT 2
|
201 |
|
|
#define CYG_HAL_SYS_SIGQUIT 3
|
202 |
|
|
#define CYG_HAL_SYS_SIGILL 4
|
203 |
|
|
#define CYG_HAL_SYS_SIGTRAP 5
|
204 |
|
|
#define CYG_HAL_SYS_SIGABRT 6
|
205 |
|
|
#define CYG_HAL_SYS_SIGBUS 7
|
206 |
|
|
#define CYG_HAL_SYS_SIGFPE 8
|
207 |
|
|
#define CYG_HAL_SYS_SIGKILL 9
|
208 |
|
|
#define CYG_HAL_SYS_SIGUSR1 10
|
209 |
|
|
#define CYG_HAL_SYS_SIGSEGV 11
|
210 |
|
|
#define CYG_HAL_SYS_SIGUSR2 12
|
211 |
|
|
#define CYG_HAL_SYS_SIGPIPE 13
|
212 |
|
|
#define CYG_HAL_SYS_SIGALRM 14
|
213 |
|
|
#define CYG_HAL_SYS_SIGTERM 15
|
214 |
|
|
#define CYG_HAL_SYS_SIGSTKFLT 16
|
215 |
|
|
#define CYG_HAL_SYS_SIGCHLD 17
|
216 |
|
|
#define CYG_HAL_SYS_SIGCONT 18
|
217 |
|
|
#define CYG_HAL_SYS_SIGSTOP 19
|
218 |
|
|
#define CYG_HAL_SYS_SIGTSTP 20
|
219 |
|
|
#define CYG_HAL_SYS_SIGTTIN 21
|
220 |
|
|
#define CYG_HAL_SYS_SIGTTOU 22
|
221 |
|
|
#define CYG_HAL_SYS_SIGURG 23
|
222 |
|
|
#define CYG_HAL_SYS_SIGXCPU 24
|
223 |
|
|
#define CYG_HAL_SYS_SIGXFSZ 25
|
224 |
|
|
#define CYG_HAL_SYS_SIGVTALRM 26
|
225 |
|
|
#define CYG_HAL_SYS_SIGPROF 27
|
226 |
|
|
#define CYG_HAL_SYS_SIGWINCH 28
|
227 |
|
|
#define CYG_HAL_SYS_SIGIO 29
|
228 |
|
|
#define CYG_HAL_SYS_SIGPWR 30
|
229 |
|
|
#define CYG_HAL_SYS_SIGSYS 31
|
230 |
|
|
|
231 |
|
|
#define CYG_HAL_SYS_SA_NOCLDSTOP 0x00000001
|
232 |
|
|
#define CYG_HAL_SYS_SA_NOCLDWAIT 0x00000002
|
233 |
|
|
#define CYG_HAL_SYS_SA_SIGINFO 0x00000004
|
234 |
|
|
#define CYG_HAL_SYS_SA_RESTORER 0x04000000
|
235 |
|
|
#define CYG_HAL_SYS_SA_RESTART 0x10000000
|
236 |
|
|
#define CYG_HAL_SYS_SA_NODEFER 0x40000000
|
237 |
|
|
|
238 |
|
|
#define CYG_HAL_SYS_SIG_BLOCK 0
|
239 |
|
|
#define CYG_HAL_SYS_SIG_UNBLOCK 1
|
240 |
|
|
#define CYG_HAL_SYS_SIG_SETMASK 2
|
241 |
|
|
|
242 |
|
|
#define CYG_HAL_SYS__NSIG 64
|
243 |
|
|
#define CYG_HAL_SYS__SIGBITS (8 * sizeof(unsigned long))
|
244 |
|
|
#define CYG_HAL_SYS__SIGELT(_d_) ((_d_) / CYG_HAL_SYS__SIGBITS)
|
245 |
|
|
#define CYG_HAL_SYS__SIGMASK(_d_) ((unsigned long)1 << ((_d_) % CYG_HAL_SYS__SIGBITS))
|
246 |
|
|
|
247 |
|
|
typedef struct cyg_hal_sys_sigset_t {
|
248 |
|
|
unsigned long hal_sig_bits[CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS];
|
249 |
|
|
} cyg_hal_sys_sigset_t;
|
250 |
|
|
|
251 |
|
|
#define CYG_HAL_SYS_SIGFILLSET(_set_) \
|
252 |
|
|
CYG_MACRO_START \
|
253 |
|
|
unsigned int __i; \
|
254 |
|
|
for (__i = 0; __i < (CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS); __i++) { \
|
255 |
|
|
(_set_)->hal_sig_bits[__i] = ~0; \
|
256 |
|
|
} \
|
257 |
|
|
CYG_MACRO_END
|
258 |
|
|
|
259 |
|
|
#define CYG_HAL_SYS_SIGEMPTYSET(_set_) \
|
260 |
|
|
CYG_MACRO_START \
|
261 |
|
|
unsigned int __i; \
|
262 |
|
|
for (__i = 0; __i < (CYG_HAL_SYS__NSIG / CYG_HAL_SYS__SIGBITS); __i++) { \
|
263 |
|
|
(_set_)->hal_sig_bits[__i] = 0; \
|
264 |
|
|
} \
|
265 |
|
|
CYG_MACRO_END
|
266 |
|
|
|
267 |
|
|
#define CYG_HAL_SYS_SIGADDSET(_set_, _bit_) \
|
268 |
|
|
CYG_MACRO_START \
|
269 |
|
|
(_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] |= CYG_HAL_SYS__SIGMASK(_bit_ - 1); \
|
270 |
|
|
CYG_MACRO_END
|
271 |
|
|
|
272 |
|
|
#define CYG_HAL_SYS_SIGDELSET(_set_, _bit_) \
|
273 |
|
|
CYG_MACRO_START \
|
274 |
|
|
(_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] &= ~CYG_HAL_SYS__SIGMASK(_bit_ - 1); \
|
275 |
|
|
CYG_MACRO_END
|
276 |
|
|
|
277 |
|
|
#define CYG_HAL_SYS_SIGISMEMBER(_set_, _bit_) \
|
278 |
|
|
(0 != ((_set_)->hal_sig_bits[CYG_HAL_SYS__SIGELT(_bit_ - 1)] & CYG_HAL_SYS__SIGMASK(_bit_ - 1)))
|
279 |
|
|
|
280 |
|
|
// The kernel sigaction structure has changed, to allow for >32
|
281 |
|
|
// signals. This is the old version, i.e. a struct old_sigaction, for
|
282 |
|
|
// use with the sigaction() system call rather than rt_sigaction(). It
|
283 |
|
|
// is preferred to the more modern version because gdb knows about
|
284 |
|
|
// rt_sigaction() and will start intercepting signals, but it seems to
|
285 |
|
|
// ignore sigaction().
|
286 |
|
|
struct cyg_hal_sys_sigaction {
|
287 |
|
|
void (*hal_handler)(int);
|
288 |
|
|
long hal_mask;
|
289 |
|
|
int hal_flags;
|
290 |
|
|
void (*hal_restorer)(void);
|
291 |
|
|
};
|
292 |
|
|
|
293 |
|
|
// Time support.
|
294 |
|
|
struct cyg_hal_sys_timeval {
|
295 |
|
|
long hal_tv_sec;
|
296 |
|
|
long hal_tv_usec;
|
297 |
|
|
};
|
298 |
|
|
|
299 |
|
|
struct cyg_hal_sys_timezone {
|
300 |
|
|
int hal_tz_minuteswest;
|
301 |
|
|
int hal_tz_dsttime;
|
302 |
|
|
};
|
303 |
|
|
|
304 |
|
|
// Select support. Initially this is used only by the idle handler.
|
305 |
|
|
#define CYG_HAL_SYS_FD_SETSIZE 1024
|
306 |
|
|
#define CYG_HAL_SYS__NFDBITS (8 * sizeof(unsigned long))
|
307 |
|
|
#define CYG_HAL_SYS__FDELT(_d_) ((_d_) / CYG_HAL_SYS__NFDBITS)
|
308 |
|
|
#define CYG_HAL_SYS__FDMASK(_d_) ((unsigned long)1 << ((_d_) % CYG_HAL_SYS__NFDBITS))
|
309 |
|
|
|
310 |
|
|
struct cyg_hal_sys_fd_set {
|
311 |
|
|
unsigned long hal_fds_bits[CYG_HAL_SYS_FD_SETSIZE / CYG_HAL_SYS__NFDBITS];
|
312 |
|
|
};
|
313 |
|
|
#define CYG_HAL_SYS_FD_ZERO(_fdsp_) \
|
314 |
|
|
do { \
|
315 |
|
|
unsigned int __i; \
|
316 |
|
|
for (__i = 0; \
|
317 |
|
|
__i < (CYG_HAL_SYS_FD_SETSIZE / CYG_HAL_SYS__NFDBITS); \
|
318 |
|
|
__i++) { \
|
319 |
|
|
(_fdsp_)->hal_fds_bits[__i] = 0; \
|
320 |
|
|
} \
|
321 |
|
|
} while (0);
|
322 |
|
|
|
323 |
|
|
#define CYG_HAL_SYS_FD_SET(_fd_, _fdsp_) \
|
324 |
|
|
CYG_MACRO_START \
|
325 |
|
|
(_fdsp_)->hal_fds_bits[CYG_HAL_SYS__FDELT(_fd_)] |= CYG_HAL_SYS__FDMASK(_fd_); \
|
326 |
|
|
CYG_MACRO_END
|
327 |
|
|
|
328 |
|
|
#define CYG_HAL_SYS_FD_CLR(_fd_, _fdsp_) \
|
329 |
|
|
CYG_MACRO_START \
|
330 |
|
|
(_fdsp_)->hal_fds_bits[CYG_HAL_SYS__FDELT(_fd_)] &= ~CYG_HAL_SYS__FDMASK(_fd_); \
|
331 |
|
|
CYG_MACRO_END
|
332 |
|
|
|
333 |
|
|
#define CYG_HAL_SYS_FD_ISSET(_fd_, _fdsp_) \
|
334 |
|
|
(0 != ((_fdsp_)->hal_fds_bits[CYG_HAL_SYS__FDELT(_fd_)] & CYG_HAL_SYS__FDMASK(_fd_)))
|
335 |
|
|
|
336 |
|
|
// Interval timer support, needed for the clock.
|
337 |
|
|
#define CYG_HAL_SYS_ITIMER_REAL 0
|
338 |
|
|
#define CYG_HAL_SYS_ITIMER_VIRTUAL 1
|
339 |
|
|
#define CYG_HAL_SYS_ITIMER_PROF 2
|
340 |
|
|
|
341 |
|
|
struct cyg_hal_sys_itimerval {
|
342 |
|
|
struct cyg_hal_sys_timeval hal_it_interval;
|
343 |
|
|
struct cyg_hal_sys_timeval hal_it_value;
|
344 |
|
|
};
|
345 |
|
|
|
346 |
|
|
// System calls and related constants, or rather the subset that is
|
347 |
|
|
// needed internally.
|
348 |
|
|
#define CYG_HAL_SYS_R_OK 0x04
|
349 |
|
|
#define CYG_HAL_SYS_W_OK 0x02
|
350 |
|
|
#define CYG_HAL_SYS_X_OK 0x01
|
351 |
|
|
#define CYG_HAL_SYS_F_OK 0x00
|
352 |
|
|
|
353 |
|
|
/* lseek whence flags */
|
354 |
|
|
#define CYG_HAL_SYS_SEEK_SET 0 /* Seek from beginning of file. */
|
355 |
|
|
#define CYG_HAL_SYS_SEEK_CUR 1 /* Seek from current position. */
|
356 |
|
|
#define CYG_HAL_SYS_SEEK_END 2 /* Seek from end of file. */
|
357 |
|
|
|
358 |
|
|
/* open/fcntl flags */
|
359 |
|
|
|
360 |
|
|
#define CYG_HAL_SYS_O_RDONLY 0
|
361 |
|
|
#define CYG_HAL_SYS_O_WRONLY 01
|
362 |
|
|
#define CYG_HAL_SYS_O_RDWR 02
|
363 |
|
|
#define CYG_HAL_SYS_O_CREAT 0100
|
364 |
|
|
#define CYG_HAL_SYS_O_EXCL 0200
|
365 |
|
|
#define CYG_HAL_SYS_O_NOCTTY 0400
|
366 |
|
|
#define CYG_HAL_SYS_O_TRUNC 01000
|
367 |
|
|
#define CYG_HAL_SYS_O_APPEND 02000
|
368 |
|
|
#define CYG_HAL_SYS_O_NONBLOCK 04000
|
369 |
|
|
#define CYG_HAL_SYS_O_NDELAY CYG_HAL_SYS_O_NONBLOCK
|
370 |
|
|
#define CYG_HAL_SYS_O_SYNC 010000
|
371 |
|
|
#define CYG_HAL_SYS_O_FSYNC CYG_HAL_SYS_O_SYNC
|
372 |
|
|
#define CYG_HAL_SYS_O_ASYNC 020000
|
373 |
|
|
|
374 |
|
|
/* open mode flags */
|
375 |
|
|
#define CYG_HAL_SYS_S_IRUSR 0400
|
376 |
|
|
#define CYG_HAL_SYS_S_IREAD CYG_HAL_SYS_S_IRUSR
|
377 |
|
|
#define CYG_HAL_SYS_S_IWUSR 0200
|
378 |
|
|
#define CYG_HAL_SYS_S_IWRITE CYG_HAL_SYS_S_IWUSR
|
379 |
|
|
#define CYG_HAL_SYS_S_IXUSR 0100
|
380 |
|
|
#define CYG_HAL_SYS_S_IEXEC CYG_HAL_SYS_S_IXUSR
|
381 |
|
|
#define CYG_HAL_SYS_S_IRWXU \
|
382 |
|
|
(CYG_HAL_SYS_S_IREAD|CYG_HAL_SYS_S_IWRITE|CYG_HAL_SYS_S_IEXEC)
|
383 |
|
|
#define CYG_HAL_SYS_S_IRWXG (CYG_HAL_SYS_S_IRWXU>>3)
|
384 |
|
|
#define CYG_HAL_SYS_S_IRGRP (CYG_HAL_SYS_S_IRUSR>>3)
|
385 |
|
|
#define CYG_HAL_SYS_S_IWGRP (CYG_HAL_SYS_S_IWUSR>>3)
|
386 |
|
|
#define CYG_HAL_SYS_S_IXGRP (CYG_HAL_SYS_S_IXUSR>>3)
|
387 |
|
|
#define CYG_HAL_SYS_S_IRWXO (CYG_HAL_SYS_S_IRWXG>>3)
|
388 |
|
|
#define CYG_HAL_SYS_S_IROTH (CYG_HAL_SYS_S_IRGRP>>3)
|
389 |
|
|
#define CYG_HAL_SYS_S_IWOTH (CYG_HAL_SYS_S_IWGRP>>3)
|
390 |
|
|
#define CYG_HAL_SYS_S_IXOTH (CYG_HAL_SYS_S_IXGRP>>3)
|
391 |
|
|
|
392 |
|
|
/* stat flags */
|
393 |
|
|
#define CYG_HAL_SYS_S_IFMT 0170000 /*bitmask for the file type bitfields*/
|
394 |
|
|
#define CYG_HAL_SYS_S_IFSOCK 0140000 /*socket*/
|
395 |
|
|
#define CYG_HAL_SYS_S_IFLNK 0120000 /*symbolic link*/
|
396 |
|
|
#define CYG_HAL_SYS_S_IFREG 0100000 /*regular file*/
|
397 |
|
|
#define CYG_HAL_SYS_S_IFBLK 0060000 /*block device*/
|
398 |
|
|
#define CYG_HAL_SYS_S_IFDIR 0040000 /*directory*/
|
399 |
|
|
#define CYG_HAL_SYS_S_IFCHR 0020000 /*character device*/
|
400 |
|
|
#define CYG_HAL_SYS_S_IFIFO 0010000 /*fifo*/
|
401 |
|
|
#define CYG_HAL_SYS_S_ISUID 0004000 /*set UID bit*/
|
402 |
|
|
#define CYG_HAL_SYS_S_ISGID 0002000 /*set GID bit (see below)*/
|
403 |
|
|
#define CYG_HAL_SYS_S_ISVTX 0001000 /*sticky bit (see below)*/
|
404 |
|
|
|
405 |
|
|
struct cyg_hal_sys_mmap_args {
|
406 |
|
|
unsigned long addr;
|
407 |
|
|
unsigned long len;
|
408 |
|
|
unsigned long prot;
|
409 |
|
|
unsigned long flags;
|
410 |
|
|
unsigned long fd;
|
411 |
|
|
unsigned long offset;
|
412 |
|
|
};
|
413 |
|
|
|
414 |
|
|
/* Protection flags for mmap */
|
415 |
|
|
#define CYG_HAL_SYS_PROT_READ 0x1 /* page can be read */
|
416 |
|
|
#define CYG_HAL_SYS_PROT_WRITE 0x2 /* page can be written */
|
417 |
|
|
#define CYG_HAL_SYS_PROT_EXEC 0x4 /* page can be executed */
|
418 |
|
|
#define CYG_HAL_SYS_PROT_NONE 0x0 /* page can not be accessed */
|
419 |
|
|
|
420 |
|
|
/* Sharing types and other flags */
|
421 |
|
|
#define CYG_HAL_SYS_MAP_SHARED 0x01 /* Share changes. */
|
422 |
|
|
#define CYG_HAL_SYS_MAP_PRIVATE 0x02 /* Changes are private. */
|
423 |
|
|
#define CYG_HAL_SYS_MAP_FIXED 0x10 /* Interpret addr exactly. */
|
424 |
|
|
|
425 |
|
|
struct cyg_hal_sys_dirent
|
426 |
|
|
{
|
427 |
|
|
unsigned long d_ino;
|
428 |
|
|
unsigned long d_off;
|
429 |
|
|
unsigned short int d_reclen;
|
430 |
|
|
char d_name[256];
|
431 |
|
|
};
|
432 |
|
|
|
433 |
|
|
struct cyg_hal_sys_timespec
|
434 |
|
|
{
|
435 |
|
|
unsigned int tv_sec;
|
436 |
|
|
unsigned int tv_nsec;
|
437 |
|
|
};
|
438 |
|
|
|
439 |
|
|
// NOTE: This corresponds to __old_kernel_stat in the kernel sources
|
440 |
|
|
// and should be used with cyg_hal_sys_oldstat etc.
|
441 |
|
|
|
442 |
|
|
struct cyg_hal_sys_old_stat
|
443 |
|
|
{
|
444 |
|
|
unsigned short st_dev; /* device */
|
445 |
|
|
unsigned short st_ino; /* inode */
|
446 |
|
|
unsigned short st_mode; /* protection */
|
447 |
|
|
unsigned short st_nlink; /* number of hard links */
|
448 |
|
|
unsigned short st_uid; /* user ID of owner */
|
449 |
|
|
unsigned short st_gid; /* group ID of owner */
|
450 |
|
|
unsigned short st_rdev; /* device type (if inode device) */
|
451 |
|
|
unsigned long st_size; /* total size, in bytes */
|
452 |
|
|
unsigned long st_atime; /* time of last access */
|
453 |
|
|
unsigned long st_mtime; /* time of last modification */
|
454 |
|
|
unsigned long st_ctime; /* time of last change */
|
455 |
|
|
};
|
456 |
|
|
|
457 |
|
|
struct cyg_hal_sys_new_stat
|
458 |
|
|
{
|
459 |
|
|
unsigned long st_dev;
|
460 |
|
|
unsigned long st_ino;
|
461 |
|
|
unsigned short st_mode;
|
462 |
|
|
unsigned short st_nlink;
|
463 |
|
|
unsigned short st_uid;
|
464 |
|
|
unsigned short st_gid;
|
465 |
|
|
unsigned long st_rdev;
|
466 |
|
|
unsigned long st_size;
|
467 |
|
|
unsigned long st_blksize;
|
468 |
|
|
unsigned long st_blocks;
|
469 |
|
|
unsigned long st_atime;
|
470 |
|
|
unsigned long st_atime_nsec;
|
471 |
|
|
unsigned long st_mtime;
|
472 |
|
|
unsigned long st_mtime_nsec;
|
473 |
|
|
unsigned long st_ctime;
|
474 |
|
|
unsigned long st_ctime_nsec;
|
475 |
|
|
unsigned long __unused4;
|
476 |
|
|
unsigned long __unused5;
|
477 |
|
|
};
|
478 |
|
|
|
479 |
|
|
// System calls, or rather the subset that is needed internally or by
|
480 |
|
|
// applications which want to access the host OS.
|
481 |
|
|
|
482 |
|
|
externC unsigned long cyg_hal_sys_write(int, const void*, long);
|
483 |
|
|
externC unsigned long cyg_hal_sys_read(int, void*, long);
|
484 |
|
|
externC int cyg_hal_sys_lseek(int, int, int);
|
485 |
|
|
externC int cyg_hal_sys_open(const char *,int,int);
|
486 |
|
|
externC int cyg_hal_sys_fdatasync(int);
|
487 |
|
|
externC int cyg_hal_sys_sigaction(int,
|
488 |
|
|
const struct cyg_hal_sys_sigaction*,
|
489 |
|
|
struct cyg_hal_sys_sigaction*);
|
490 |
|
|
externC int cyg_hal_sys_sigprocmask(int,
|
491 |
|
|
const cyg_hal_sys_sigset_t*,
|
492 |
|
|
cyg_hal_sys_sigset_t*);
|
493 |
|
|
externC int cyg_hal_sys__newselect(int,
|
494 |
|
|
struct cyg_hal_sys_fd_set*,
|
495 |
|
|
struct cyg_hal_sys_fd_set*,
|
496 |
|
|
struct cyg_hal_sys_fd_set*,
|
497 |
|
|
struct cyg_hal_sys_timeval*);
|
498 |
|
|
externC int cyg_hal_sys_setitimer(int,
|
499 |
|
|
const struct cyg_hal_sys_itimerval*,
|
500 |
|
|
struct cyg_hal_sys_itimerval*);
|
501 |
|
|
externC int cyg_hal_sys_gettimeofday(struct cyg_hal_sys_timeval*,
|
502 |
|
|
struct cyg_hal_sys_timezone*);
|
503 |
|
|
|
504 |
|
|
externC int cyg_hal_sys_access(const char*, int);
|
505 |
|
|
externC int cyg_hal_sys_fork(void);
|
506 |
|
|
externC int cyg_hal_sys_execve(const char*, const char* [], const char* []);
|
507 |
|
|
externC int cyg_hal_sys_pipe(int []);
|
508 |
|
|
externC int cyg_hal_sys_close(int);
|
509 |
|
|
externC int cyg_hal_sys_dup2(int, int);
|
510 |
|
|
externC int cyg_hal_sys_unlink(const char*);
|
511 |
|
|
externC int cyg_hal_sys_rename(const char*, const char*);
|
512 |
|
|
|
513 |
|
|
#define CYG_HAL_SYS_IPCOP_semop 1
|
514 |
|
|
#define CYG_HAL_SYS_IPCOP_semget 2
|
515 |
|
|
#define CYG_HAL_SYS_IPCOP_semctl 3
|
516 |
|
|
#define CYG_HAL_SYS_IPCOP_msgsnd 11
|
517 |
|
|
#define CYG_HAL_SYS_IPCOP_msgrcv 12
|
518 |
|
|
#define CYG_HAL_SYS_IPCOP_msgget 13
|
519 |
|
|
#define CYG_HAL_SYS_IPCOP_msgctl 14
|
520 |
|
|
#define CYG_HAL_SYS_IPCOP_shmat 21
|
521 |
|
|
#define CYG_HAL_SYS_IPCOP_shmdt 22
|
522 |
|
|
#define CYG_HAL_SYS_IPCOP_shmget 23
|
523 |
|
|
#define CYG_HAL_SYS_IPCOP_shmctl 24
|
524 |
|
|
|
525 |
|
|
/*The ipc system call, which is used by the following shmem
|
526 |
|
|
functions. These may be unportable*/
|
527 |
|
|
|
528 |
|
|
// Generic system call. Depending on the value of call, it will
|
529 |
|
|
// perform the following functions.
|
530 |
|
|
externC int cyg_hal_sys_ipc(int call, int first, int second,
|
531 |
|
|
int third, void* ptr);
|
532 |
|
|
//get an identifier for a shared memory segment
|
533 |
|
|
externC int cyg_hal_sys_shmget (int key, int size, int shmflg);
|
534 |
|
|
//attach to an shared memory segment
|
535 |
|
|
externC void * cyg_hal_sys_shmat (int shmid, const void* shmaddr,
|
536 |
|
|
int shmflg);
|
537 |
|
|
//detach from it again
|
538 |
|
|
externC int cyg_hal_sys_shmdt (const void* shmaddr);
|
539 |
|
|
|
540 |
|
|
// Convert a pathname and an identifier into a System V IPC key
|
541 |
|
|
externC int cyg_hal_sys_ftok(const char* path, int id);
|
542 |
|
|
|
543 |
|
|
// The actual implementation appears to return the new brk() value.
|
544 |
|
|
externC void* cyg_hal_sys_brk(void*);
|
545 |
|
|
|
546 |
|
|
// Returns the number of characters placed in the buffer or <0 for error,
|
547 |
|
|
// not a char*.
|
548 |
|
|
externC int cyg_hal_sys_getcwd(char*, int);
|
549 |
|
|
|
550 |
|
|
// mmap on the "host" system - this may be unportable. This is the
|
551 |
|
|
// really system call into the kernel which passes one structure
|
552 |
|
|
// containing all the arguments.
|
553 |
|
|
externC int cyg_hal_sys_mmapx(struct cyg_hal_sys_mmap_args *);
|
554 |
|
|
|
555 |
|
|
// This is the mmap call that users are used to.
|
556 |
|
|
externC int cyg_hal_sys_mmap(void *addr,
|
557 |
|
|
unsigned long length,
|
558 |
|
|
unsigned long prot,
|
559 |
|
|
unsigned long flags,
|
560 |
|
|
unsigned long fd,
|
561 |
|
|
unsigned long off);
|
562 |
|
|
|
563 |
|
|
externC int cyg_hal_sys_readdir(unsigned int fd,
|
564 |
|
|
struct cyg_hal_sys_dirent *dp,
|
565 |
|
|
unsigned int count);
|
566 |
|
|
// Old syscall versions
|
567 |
|
|
externC int cyg_hal_sys_oldlstat(const char* name,
|
568 |
|
|
struct cyg_hal_sys_old_stat *buf);
|
569 |
|
|
externC int cyg_hal_sys_oldfstat(int fd, struct cyg_hal_sys_old_stat *buf);
|
570 |
|
|
externC int cyg_hal_sys_oldstat(const char* name,
|
571 |
|
|
struct cyg_hal_sys_old_stat *buf);
|
572 |
|
|
// New syscall versions
|
573 |
|
|
externC int cyg_hal_sys_newlstat(const char* name,
|
574 |
|
|
struct cyg_hal_sys_new_stat *buf);
|
575 |
|
|
externC int cyg_hal_sys_newfstat(int fd, struct cyg_hal_sys_new_stat *buf);
|
576 |
|
|
externC int cyg_hal_sys_newstat(const char* name,
|
577 |
|
|
struct cyg_hal_sys_old_stat *buf);
|
578 |
|
|
|
579 |
|
|
externC int cyg_hal_sys_mkdir(const char* path, int mode);
|
580 |
|
|
|
581 |
|
|
// Access to environmental data
|
582 |
|
|
extern int cyg_hal_sys_argc;
|
583 |
|
|
extern const char** cyg_hal_sys_argv;
|
584 |
|
|
extern const char** cyg_hal_sys_environ;
|
585 |
|
|
|
586 |
|
|
// ----------------------------------------------------------------------------
|
587 |
|
|
// Interaction between the application and the auxiliary.
|
588 |
|
|
|
589 |
|
|
// Is the auxiliary actually in use/available? This flag should be tested by
|
590 |
|
|
// device drivers prior to attempting any communication with the auxiliary.
|
591 |
|
|
extern cyg_bool synth_auxiliary_running;
|
592 |
|
|
|
593 |
|
|
// The fundamental I/O operation: sending a request to the auxiliary and
|
594 |
|
|
// optionally getting back a reply. A null pointer for the response field
|
595 |
|
|
// indicates that no reply is expected.
|
596 |
|
|
externC void synth_auxiliary_xchgmsg(int /* devid */, int /* request */,
|
597 |
|
|
int /* arg1 */, int /* arg2 */,
|
598 |
|
|
const unsigned char* /* txdata */, int /* txlen */,
|
599 |
|
|
int* /* response */,
|
600 |
|
|
unsigned char* /* rxdata */, int* /* actual_rxlen */,
|
601 |
|
|
int /* rxlen */);
|
602 |
|
|
|
603 |
|
|
// Request that the auxiliary instantiates a given device, loading appropriate
|
604 |
|
|
// support code as required. This function takes the following arguments:
|
605 |
|
|
// 1) the location of the package that should provide this device, e.g.
|
606 |
|
|
// devs/eth/synth
|
607 |
|
|
// 2) the version of that package currently being used, e.g. "current"
|
608 |
|
|
// 3) the name of the device, e.g. "ethernet". This identifies the
|
609 |
|
|
// Tcl script that should be loaded to handle requests for this device.
|
610 |
|
|
// 4) the name of the device instance, e.g. "eth0".
|
611 |
|
|
// 5) device-specific initialization data.
|
612 |
|
|
externC int synth_auxiliary_instantiate(const char*, const char*, const char*, const char*, const char*);
|
613 |
|
|
|
614 |
|
|
// Support for generating strings
|
615 |
|
|
#define SYNTH_MAKESTRING1(a) #a
|
616 |
|
|
#define SYNTH_MAKESTRING(a) SYNTH_MAKESTRING1(a)
|
617 |
|
|
|
618 |
|
|
//-----------------------------------------------------------------------------
|
619 |
|
|
#endif // ifndef CYGONCE_HAL_HAL_IO_H
|
620 |
|
|
// End of hal_io.h
|