]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/common/v2_0/include/hal_if.h
Initial revision
[karo-tx-redboot.git] / packages / hal / common / v2_0 / include / hal_if.h
1 #ifndef CYGONCE_HAL_HAL_IF_H
2 #define CYGONCE_HAL_HAL_IF_H
3
4 //=============================================================================
5 //
6 //      hal_if.h
7 //
8 //      HAL header for ROM/RAM calling interface.
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, 2003 Red Hat, Inc.
15 // Copyright (C) 2002, 2003, 2004 Gary Thomas
16 //
17 // eCos is free software; you can redistribute it and/or modify it under
18 // the terms of the GNU General Public License as published by the Free
19 // Software Foundation; either version 2 or (at your option) any later version.
20 //
21 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
22 // 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 along
27 // with eCos; if not, write to the Free Software Foundation, Inc.,
28 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 //
30 // As a special exception, if other files instantiate templates or use macros
31 // or inline functions from this file, or you compile this file and link it
32 // with other works to produce a work based on this file, this file does not
33 // by itself cause the resulting work to be covered by the GNU General Public
34 // License. However the source code for this file must still be made available
35 // in accordance with section (3) of the GNU General Public License.
36 //
37 // This exception does not invalidate any other reasons why a work based on
38 // this file might be covered by the GNU General Public License.
39 //
40 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
41 // at http://sources.redhat.com/ecos/ecos-license/
42 // -------------------------------------------
43 //####ECOSGPLCOPYRIGHTEND####
44 //=============================================================================
45 //#####DESCRIPTIONBEGIN####
46 //
47 // Author(s):   jskov
48 // Contributors:jskov, woehler
49 // Date:        2000-06-07
50 // Purpose:     HAL RAM/ROM calling interface
51 // Description: ROM/RAM calling interface table definitions. The layout is a
52 //              combination of libbsp and vectors already in use by some
53 //              eCos platforms.
54 // Usage:       #include <cyg/hal/hal_if.h>
55 //                           
56 //####DESCRIPTIONEND####
57 //
58 //=============================================================================
59
60 #include <cyg/infra/cyg_type.h>         // types & externC
61 #include <cyg/hal/dbg-threads-api.h>
62 #include <cyg/hal/dbg-thread-syscall.h>
63
64 #include <stdarg.h>
65
66 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
67
68 // Architecture/var/platform may override the accessor macros.
69 #include <cyg/hal/hal_arch.h>
70
71 // Special monitor locking procedures.  These are necessary when the monitor
72 // and eCos share facilities, e.g. the network hardware.
73 #if defined (CYGPKG_NET) || defined (CYGPKG_NET_LWIP)
74 #include <cyg/hal/hal_intr.h>
75 #include <cyg/hal/drv_api.h>            // cyg_drv_dsr_lock(), etc
76 #define _ENTER_MONITOR()                        \
77     cyg_uint32 ints;                            \
78     HAL_DISABLE_INTERRUPTS(ints);               \
79     cyg_drv_dsr_lock()
80
81 #define _EXIT_MONITOR()                         \
82     cyg_drv_dsr_unlock();                       \
83     HAL_RESTORE_INTERRUPTS(ints)
84 #else // !CYGPKG_NET && !CYGPKG_NET_LWIP
85 #define _ENTER_MONITOR() CYG_EMPTY_STATEMENT
86 #define _EXIT_MONITOR()  CYG_EMPTY_STATEMENT
87 #endif
88
89 //--------------------------------------------------------------------------
90 #ifndef _BSP_HANDLER_T_DEFINED
91 #define _BSP_HANDLER_T_DEFINED
92 typedef int (*bsp_handler_t)(int __irq_nr, void *__regs);
93 #endif // _BSP_HANDLER_T_DEFINED
94
95 //--------------------------------------------------------------------------
96 // Communication interface table. CYGNUM_CALL_IF_CONSOLE_PROCS and
97 // CYGNUM_CALL_IF_DEBUG_PROCS point to instances (possibly the same)
98 // of this table.
99
100 typedef enum {
101     /*
102      * For serial ports, the control function may be used to set and get the
103      * current baud rate. Usage:
104      * 
105      *   err = (*__control)(COMMCTL_SETBAUD, int bits_per_second);
106      *     err => Zero if successful, -1 if error.
107      *
108      *   baud = (*__control)(COMMCTL_GETBAUD);
109      *     baud => -1 if error, current baud otherwise.
110      */
111     __COMMCTL_SETBAUD=0,
112     __COMMCTL_GETBAUD,
113
114     /*
115      * Install and remove debugger interrupt handlers. These are the receiver
116      * interrupt routines which are used to change control from a running
117      * program to the debugger stub.
118      */
119     __COMMCTL_INSTALL_DBG_ISR,
120     __COMMCTL_REMOVE_DBG_ISR,
121
122     /*
123      * Disable comm port interrupt. Returns TRUE if interrupt was enabled,
124      * FALSE otherwise.
125      */
126     __COMMCTL_IRQ_DISABLE,
127
128     /*
129      * Enable comm port interrupt.
130      */
131     __COMMCTL_IRQ_ENABLE,
132
133     /*
134      * Returns the number of the interrupt vector used by the debug
135      * interrupt handler.
136      */
137     __COMMCTL_DBG_ISR_VECTOR,
138
139     /*
140      * Returns the current timeout value and sets a new timeout.
141      * Timeout resolution is in milliseconds.
142      *   old_timeout = (*__control)(__COMMCTL_SET_TIMEOUT, 
143      *                              cyg_int32 new_timeout);
144      */
145     __COMMCTL_SET_TIMEOUT,
146
147     /*
148      * Forces driver to send all characters which may be buffered in
149      * the driver. This only flushes the driver buffers, not necessarily
150      * any hardware FIFO, etc.
151      */
152     __COMMCTL_FLUSH_OUTPUT,
153
154     /*
155      * Forces driver to enable or disable flushes when a newline is
156      * seen in the output stream. Flushing at line boundaries occurs
157      * in the driver, not necessarily any hardware FIFO, etc. Line
158      * buffering is optional and may only be available in some drivers.
159      */
160     __COMMCTL_ENABLE_LINE_FLUSH,
161     __COMMCTL_DISABLE_LINE_FLUSH,
162
163 } __comm_control_cmd_t;
164
165
166 #define CYGNUM_COMM_IF_CH_DATA                    0
167 #define CYGNUM_COMM_IF_WRITE                      1
168 #define CYGNUM_COMM_IF_READ                       2
169 #define CYGNUM_COMM_IF_PUTC                       3
170 #define CYGNUM_COMM_IF_GETC                       4
171 #define CYGNUM_COMM_IF_CONTROL                    5
172 #define CYGNUM_COMM_IF_DBG_ISR                    6
173 #define CYGNUM_COMM_IF_GETC_TIMEOUT               7
174
175 #define CYGNUM_COMM_IF_TABLE_SIZE                 8
176
177 typedef volatile CYG_ADDRWORD hal_virtual_comm_table_t[CYGNUM_COMM_IF_TABLE_SIZE];
178
179 // The below is a (messy) attempt at adding some type safety to the
180 // above array. At the same time, the accessors allow the
181 // implementation to be easily changed in the future (both tag->data
182 // table and structure implementations have been suggested).
183
184 typedef void* __comm_if_ch_data_t;
185 typedef void (*__comm_if_write_t)(void* __ch_data, const cyg_uint8* __buf,
186                                   cyg_uint32 __len);
187 typedef int (*__comm_if_read_t)(void* __ch_data, cyg_uint8* __buf,
188                                 cyg_uint32 __len);
189 typedef void (*__comm_if_putc_t)(void* __ch_data, cyg_uint8 __ch);
190 typedef cyg_uint8 (*__comm_if_getc_t)(void* __ch_data);
191 typedef int (*__comm_if_control_t)(void *__ch_data, 
192                                    __comm_control_cmd_t __func, ...);
193 typedef int (*__comm_if_dbg_isr_t)(void *__ch_data, 
194                                int* __ctrlc, CYG_ADDRWORD __vector,
195                                CYG_ADDRWORD __data);
196 typedef cyg_bool (*__comm_if_getc_timeout_t)(void* __ch_data, cyg_uint8* __ch);
197
198 #define __call_COMM0(_n_,_rt_,_t_)                              \
199 static __inline__ _rt_                                          \
200 __call_COMM_##_n_(hal_virtual_comm_table_t t)                   \
201 {                                                               \
202     _rt_ res;                                                   \
203     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
204     _ENTER_MONITOR();                                           \
205     res = ((_t_)(t[CYGNUM_COMM_##_n_]))(dp);                    \
206     _EXIT_MONITOR();                                            \
207     return res;                                                 \
208 }
209
210 #define __call_voidCOMM(_n_,_rt_,_t_)                           \
211 static __inline__ _rt_                                          \
212 __call_COMM_##_n_(hal_virtual_comm_table_t t)                   \
213 {                                                               \
214     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
215     _ENTER_MONITOR();                                           \
216     ((_t_)(t[CYGNUM_COMM_##_n_]))(dp);                          \
217     _EXIT_MONITOR();                                            \
218 }
219
220 #define __call_COMM1(_n_,_rt_,_t_,_t1_)                         \
221 static __inline__ _rt_                                          \
222 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_)        \
223 {                                                               \
224     _rt_ res;                                                   \
225     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
226     _ENTER_MONITOR();                                           \
227     res = ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_);              \
228     _EXIT_MONITOR();                                            \
229     return res;                                                 \
230 }
231
232 #define __call_voidCOMM1(_n_,_rt_,_t_,_t1_)                     \
233 static __inline__ _rt_                                          \
234 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_)        \
235 {                                                               \
236     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
237     _ENTER_MONITOR();                                           \
238     ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_);                    \
239     _EXIT_MONITOR();                                            \
240 }
241
242 #define __call_COMM2(_n_,_rt_,_t_,_t1_,_t2_)                    \
243 static __inline__ _rt_                                          \
244 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_, _t2_ _p2_)        \
245 {                                                               \
246     _rt_ res;                                                   \
247     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
248     _ENTER_MONITOR();                                           \
249     res = ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_, _p2_);        \
250     _EXIT_MONITOR();                                            \
251     return res;                                                 \
252 }
253
254 #define __call_voidCOMM2(_n_,_rt_,_t_,_t1_,_t2_)                \
255 static __inline__ _rt_                                          \
256 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_, _t2_ _p2_)        \
257 {                                                               \
258     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
259     _ENTER_MONITOR();                                           \
260     ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_, _p2_);              \
261     _EXIT_MONITOR();                                            \
262 }
263
264 #define __call_COMM3(_n_,_rt_,_t_,_t1_,_t2_,_t3_)               \
265 static __inline__ _rt_                                          \
266 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_, _t2_ _p2_, _t3_ _p3_)        \
267 {                                                               \
268     _rt_ res;                                                   \
269     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
270     _ENTER_MONITOR();                                           \
271     res = ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_, _p2_, _p3_);              \
272     _EXIT_MONITOR();                                            \
273     return res;                                                 \
274 }
275
276 #define __call_voidCOMM3(_n_,_rt_,_t_,_t1_,_t2_,_t3_)           \
277 static __inline__ _rt_                                          \
278 __call_COMM_##_n_(hal_virtual_comm_table_t t, _t1_ _p1_, _t2_ _p2_, _t3_ _p3_)        \
279 {                                                               \
280     void *dp = (__comm_if_ch_data_t)t[CYGNUM_COMM_IF_CH_DATA];  \
281     _ENTER_MONITOR();                                           \
282     ((_t_)(t[CYGNUM_COMM_##_n_]))(dp, _p1_, _p2_, _p3_);        \
283     _EXIT_MONITOR();                                            \
284 }
285
286 #ifndef CYGACC_COMM_IF_DEFINED
287
288 #define CYGACC_COMM_IF_CH_DATA(_t_) \
289  ((__comm_if_ch_data_t)((_t_)[CYGNUM_COMM_IF_CH_DATA]))
290 #define CYGACC_COMM_IF_CH_DATA_SET(_t_, _x_) \
291  (_t_)[CYGNUM_COMM_IF_CH_DATA]=(CYG_ADDRWORD)(_x_)
292
293 __call_voidCOMM2(IF_WRITE, void, __comm_if_write_t, const cyg_uint8 *, cyg_uint32)
294 #define CYGACC_COMM_IF_WRITE(_t_, _b_, _l_) \
295  __call_COMM_IF_WRITE(_t_, _b_, _l_)
296 #define CYGACC_COMM_IF_WRITE_SET(_t_, _x_) \
297  (_t_)[CYGNUM_COMM_IF_WRITE]=(CYG_ADDRWORD)(_x_)
298
299 __call_voidCOMM2(IF_READ, void, __comm_if_read_t, cyg_uint8 *, cyg_uint32)
300 #define CYGACC_COMM_IF_READ(_t_, _b_, _l_) \
301  __call_COMM_IF_READ(_t_, _b_, _l_)
302 #define CYGACC_COMM_IF_READ_SET(_t_, _x_) \
303  (_t_)[CYGNUM_COMM_IF_READ]=(CYG_ADDRWORD)(_x_)
304
305 __call_voidCOMM1(IF_PUTC, void, __comm_if_putc_t, cyg_uint8)
306 #define CYGACC_COMM_IF_PUTC(_t_, _c_) \
307  __call_COMM_IF_PUTC(_t_,_c_)
308 #define CYGACC_COMM_IF_PUTC_SET(_t_, _x_) \
309  (_t_)[CYGNUM_COMM_IF_PUTC]=(CYG_ADDRWORD)(_x_)
310
311 __call_COMM0(IF_GETC, cyg_uint8, __comm_if_getc_t)
312 #define CYGACC_COMM_IF_GETC(_t_) \
313  __call_COMM_IF_GETC(_t_)
314 #define CYGACC_COMM_IF_GETC_SET(_t_, _x_) \
315  (_t_)[CYGNUM_COMM_IF_GETC]=(CYG_ADDRWORD)(_x_)
316
317 // This macro has not been changed to use inline functions like the
318 // others, simply because it uses variable arguments, and the change
319 // would break binary compatibility.
320 #define CYGACC_COMM_IF_CONTROL(_t_, args...)                                                            \
321  ({ int res;                                                                                            \
322     _ENTER_MONITOR();                                                                                   \
323     res = ((__comm_if_control_t)((_t_)[CYGNUM_COMM_IF_CONTROL]))(CYGACC_COMM_IF_CH_DATA(_t_), args);    \
324     _EXIT_MONITOR();                                                                                    \
325     res;})
326 #define CYGACC_COMM_IF_CONTROL_SET(_t_, _x_) \
327  (_t_)[CYGNUM_COMM_IF_CONTROL]=(CYG_ADDRWORD)(_x_)
328
329 __call_COMM3(IF_DBG_ISR, int, __comm_if_dbg_isr_t, int *, CYG_ADDRWORD, CYG_ADDRWORD)
330 #define CYGACC_COMM_IF_DBG_ISR(_t_, _c_, _v_, _d_) \
331  __call_COMM_IF_DBG_ISR(_t_, _c_, _v_, _d_)
332 #define CYGACC_COMM_IF_DBG_ISR_SET(_t_, _x_) \
333  (_t_)[CYGNUM_COMM_IF_DBG_ISR]=(CYG_ADDRWORD)(_x_)
334
335 __call_COMM1(IF_GETC_TIMEOUT, cyg_bool, __comm_if_getc_timeout_t, cyg_uint8 *)
336 #define CYGACC_COMM_IF_GETC_TIMEOUT(_t_, _c_) \
337  __call_COMM_IF_GETC_TIMEOUT(_t_, _c_)
338 #define CYGACC_COMM_IF_GETC_TIMEOUT_SET(_t_, _x_) \
339  (_t_)[CYGNUM_COMM_IF_GETC_TIMEOUT]=(CYG_ADDRWORD)(_x_)
340
341 #endif // CYGACC_COMM_IF_DEFINED
342
343 //--------------------------------------------------------------------------
344 // Main calling interface table. Will be assigned a location by the 
345 // linker script. Both ROM and RAM startup applications will know about
346 // the location.
347 #define CYGNUM_CALL_IF_VERSION                    0
348 #define CYGNUM_CALL_IF_available_1                1
349 #define CYGNUM_CALL_IF_available_2                2
350 #define CYGNUM_CALL_IF_available_3                3
351 #define CYGNUM_CALL_IF_KILL_VECTOR                4
352 #define CYGNUM_CALL_IF_CONSOLE_PROCS              5
353 #define CYGNUM_CALL_IF_DEBUG_PROCS                6
354 #define CYGNUM_CALL_IF_FLUSH_DCACHE               7
355 #define CYGNUM_CALL_IF_FLUSH_ICACHE               8
356 #define CYGNUM_CALL_IF_available_9                9
357 #define CYGNUM_CALL_IF_available_10               10
358 #define CYGNUM_CALL_IF_available_11               11
359 #define CYGNUM_CALL_IF_SET_DEBUG_COMM             12
360 #define CYGNUM_CALL_IF_SET_CONSOLE_COMM           13
361 #define CYGNUM_CALL_IF_MONITOR_VERSION            14
362 #define CYGNUM_CALL_IF_DBG_SYSCALL                15
363 #define CYGNUM_CALL_IF_RESET                      16
364 #define CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG     17
365 #define CYGNUM_CALL_IF_DELAY_US                   18
366 #define CYGNUM_CALL_IF_DBG_DATA                   19
367 #define CYGNUM_CALL_IF_FLASH_CFG_OP               20
368 #define CYGNUM_CALL_IF_MONITOR_RETURN             21
369 #define CYGNUM_CALL_IF_FLASH_FIS_OP               22
370
371 #define CYGNUM_CALL_IF_LAST_ENTRY                 CYGNUM_CALL_IF_FLASH_FIS_OP
372
373 #define CYGNUM_CALL_IF_INSTALL_BPT_FN             35
374
375 #define CYGNUM_CALL_IF_TABLE_SIZE                 64
376
377 externC volatile CYG_ADDRWORD hal_virtual_vector_table[CYGNUM_CALL_IF_TABLE_SIZE];
378
379 // Table version contains version information for both the CALL table
380 // itself (the number of the last active entry in the table), and the
381 // COMM table (the size of the table).
382 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL         CYGNUM_CALL_IF_LAST_ENTRY
383 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_HACK    (CYGNUM_CALL_IF_TABLE_SIZE+1)
384 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_MAX     CYGNUM_CALL_IF_TABLE_SIZE
385 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM         CYGNUM_COMM_IF_TABLE_SIZE
386 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_MASK    0x0000ffff
387 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM_MASK    0xffff0000
388 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM_shift   16
389
390
391 // These are special debug/console procs IDs
392 // QUERY_CURRENT will cause the ID of the currently selected proc ID to be
393 //               returned.
394 // EMPTY         this is the ID used for an empty procs table (i.e, NULL
395 //               pointer)
396 // MANGLER       selects the procs space reserved for the console mangler
397 //               allowing the application to temporarily disable mangling
398 //               or temporarily switch in different console procs.
399 #define CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT -1
400 #define CYGNUM_CALL_IF_SET_COMM_ID_EMPTY         -2
401 #define CYGNUM_CALL_IF_SET_COMM_ID_MANGLER       -3
402
403 // The below is a (messy) attempt at adding some type safety to the
404 // above array. At the same time, the accessors allow the
405 // implementation to be easily changed in the future (both tag->data
406 // table and structure implementations have been suggested).
407
408 typedef int __call_if_version_t;
409 typedef void* __call_if_ictrl_table_t;
410 typedef void* __call_if_exc_table_t;
411 typedef bsp_handler_t *__call_if_dbg_vector_t;
412 typedef bsp_handler_t __call_if_kill_vector_t;
413 typedef hal_virtual_comm_table_t *__call_if_console_procs_t;
414 typedef hal_virtual_comm_table_t *__call_if_debug_procs_t;
415 typedef void (__call_if_flush_dcache_t)(void *__p, int __nbytes);
416 typedef void (__call_if_flush_icache_t)(void *__p, int __nbytes);
417 typedef int (__call_if_set_debug_comm_t)(int __comm_id);
418 typedef int (__call_if_set_console_comm_t)(int __comm_id);
419 typedef void* __call_if_dbg_data_t;
420 typedef int (__call_if_dbg_syscall_t) (enum dbg_syscall_ids id,
421                                         union dbg_thread_syscall_parms  *p );
422 typedef void (__call_if_reset_t)(void);
423 typedef int __call_if_console_interrupt_flag_t;
424 typedef void (__call_if_delay_us_t)(cyg_int32 usecs);
425 typedef void (__call_if_install_bpt_fn_t)(void *__epc);
426 typedef char *__call_if_monitor_version_t;
427 typedef void (__call_if_monitor_return_t)(int status);
428 typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name, void *__val);
429 //
430 // This structure is used to pass parameters to/from the fconfig routines.
431 // This allows a single virtual vector interface, with widely varying functionality
432 //
433 struct cyg_fconfig {
434     char *key;      // Datum 'key'
435     int   keylen;   // Length of key
436     void *val;      // Pointer to data
437     int   type;     // Type of datum
438     int   offset;   // Offset within data (used by _NEXT)
439 };
440 typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, struct cyg_fconfig *__data);
441
442 #ifndef CYGACC_CALL_IF_DEFINED
443
444 #define __data_VV(_n_,_tt_)                             \
445 static __inline__ _tt_                                  \
446 __call_vv_##_n_(void)                                   \
447 {                                                       \
448     return ((_tt_)hal_virtual_vector_table[_n_]);       \
449 }
450
451 #define __call_VV0(_n_,_tt_,_rt_)                                       \
452 static __inline__ _rt_                                                  \
453 __call_vv_##_n_(void)                                                   \
454 {                                                                       \
455     _rt_ res;                                                           \
456     _ENTER_MONITOR();                                                   \
457     res = ((_tt_ *)hal_virtual_vector_table[_n_])();                    \
458     _EXIT_MONITOR();                                                    \
459     return res;                                                         \
460 }
461
462 #define __call_voidVV0(_n_,_tt_,_rt_)                                   \
463 static __inline__ _rt_                                                  \
464 __call_vv_##_n_(void)                                                   \
465 {                                                                       \
466     _ENTER_MONITOR();                                                   \
467     ((_tt_ *)hal_virtual_vector_table[_n_])();                          \
468     _EXIT_MONITOR();                                                    \
469 }
470
471 #define __call_VV1(_n_,_tt_,_rt_,_t1_)                                  \
472 static __inline__ _rt_                                                  \
473 __call_vv_##_n_(_t1_ _p1_)                                              \
474 {                                                                       \
475     _rt_ res;                                                           \
476     _ENTER_MONITOR();                                                   \
477     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_);                \
478     _EXIT_MONITOR();                                                    \
479     return res;                                                         \
480 }
481
482 #define __call_voidVV1(_n_,_tt_,_rt_,_t1_)                              \
483 static __inline__ _rt_                                                  \
484 __call_vv_##_n_(_t1_ _p1_)                                              \
485 {                                                                       \
486     _ENTER_MONITOR();                                                   \
487     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_);                      \
488     _EXIT_MONITOR();                                                    \
489 }
490
491 #define __call_VV2(_n_,_tt_,_rt_,_t1_,_t2_)                             \
492 static __inline__ _rt_                                                  \
493 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_)                                   \
494 {                                                                       \
495     _rt_ res;                                                           \
496     _ENTER_MONITOR();                                                   \
497     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_);           \
498     _EXIT_MONITOR();                                                    \
499     return res;                                                         \
500 }
501
502 #define __call_voidVV2(_n_,_tt_,_rt_,_t1_,_t2_)                         \
503 static __inline__ _rt_                                                  \
504 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_)                                   \
505 {                                                                       \
506     _ENTER_MONITOR();                                                   \
507     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_);                 \
508     _EXIT_MONITOR();                                                    \
509 }
510
511 #define __call_VV3(_n_,_tt_,_rt_,_t1_,_t2_,_t3_)                        \
512 static __inline__ _rt_                                                  \
513 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_)                        \
514 {                                                                       \
515     _rt_ res;                                                           \
516     _ENTER_MONITOR();                                                   \
517     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_);      \
518     _EXIT_MONITOR();                                                    \
519     return res;                                                         \
520 }
521
522 #define __call_voidVV3(_n_,_tt_,_rt_,_t1_,_t2_,_t3_)                    \
523 static __inline__ _rt_                                                  \
524 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_)                        \
525 {                                                                       \
526     _ENTER_MONITOR();                                                   \
527     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_);            \
528     _EXIT_MONITOR();                                                    \
529 }
530
531 #define __call_VV4(_n_,_tt_,_rt_,_t1_,_t2_,_t3_,_t4_)                   \
532 static __inline__ _rt_                                                  \
533 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_, _t4_ _p4_)             \
534 {                                                                       \
535     _rt_ res;                                                           \
536     _ENTER_MONITOR();                                                   \
537     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_,_p4_); \
538     _EXIT_MONITOR();                                                    \
539     return res;                                                         \
540 }
541
542 #define __call_voidVV4(_n_,_tt_,_rt_,_t1_,_t2_,_t3_,_t4_)               \
543 static __inline__ _rt_                                                  \
544 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_, _t4_ _p4_)             \
545 {                                                                       \
546     _ENTER_MONITOR();                                                   \
547     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_,_p4_);       \
548     _EXIT_MONITOR();                                                    \
549 }
550
551
552 #define CYGACC_DATA_VV(t,e)              __call_vv_##e()
553 #define CYGACC_CALL_VV0(t,e)             __call_vv_##e
554 #define CYGACC_CALL_VV1(t,e,p1)          __call_vv_##e((p1))
555 #define CYGACC_CALL_VV2(t,e,p1,p2)       __call_vv_##e((p1),(p2))
556 #define CYGACC_CALL_VV3(t,e,p1,p2,p3)    __call_vv_##e((p1),(p2),(p3))
557 #define CYGACC_CALL_VV4(t,e,p1,p2,p3,p4) __call_vv_##e((p1),(p2),(p3),(p4))
558
559 #define CYGACC_CALL_IF_VERSION() \
560  CYGACC_DATA_VV(__call_if_version_t, CYGNUM_CALL_IF_VERSION)
561 __data_VV(CYGNUM_CALL_IF_VERSION, __call_if_version_t)
562 #define CYGACC_CALL_IF_VERSION_SET(_x_) \
563  hal_virtual_vector_table[CYGNUM_CALL_IF_VERSION]=(CYG_ADDRWORD)(_x_)
564
565 #define CYGACC_CALL_IF_KILL_VECTOR() \
566  CYGACC_DATA_VV(__call_if_kill_vector_t, CYGNUM_CALL_IF_KILL_VECTOR)
567 __data_VV(CYGNUM_CALL_IF_KILL_VECTOR, __call_if_kill_vector_t)
568 #define CYGACC_CALL_IF_KILL_VECTOR_SET(_x_) \
569  hal_virtual_vector_table[CYGNUM_CALL_IF_KILL_VECTOR]=(CYG_ADDRWORD)(_x_)
570
571 #define CYGACC_CALL_IF_CONSOLE_PROCS() \
572  CYGACC_DATA_VV(__call_if_console_procs_t, CYGNUM_CALL_IF_CONSOLE_PROCS)
573 __data_VV(CYGNUM_CALL_IF_CONSOLE_PROCS, __call_if_console_procs_t)
574 #define CYGACC_CALL_IF_CONSOLE_PROCS_SET(_x_) \
575  hal_virtual_vector_table[CYGNUM_CALL_IF_CONSOLE_PROCS]=(CYG_ADDRWORD)(_x_)
576
577 #define CYGACC_CALL_IF_FLUSH_DCACHE(_p_, _n_) \
578  ((__call_if_flush_dcache_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_DCACHE])((_p_), (_n_))
579 #define CYGACC_CALL_IF_FLUSH_DCACHE_SET(_x_) \
580  hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_DCACHE]=(CYG_ADDRWORD)(_x_)
581
582 #define CYGACC_CALL_IF_FLUSH_ICACHE(_p_, _n_) \
583  ((__call_if_flush_icache_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_ICACHE])((_p_), (_n_))
584 #define CYGACC_CALL_IF_FLUSH_ICACHE_SET(_x_) \
585  hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_ICACHE]=(CYG_ADDRWORD)(_x_)
586
587 #define CYGACC_CALL_IF_DEBUG_PROCS() \
588  CYGACC_DATA_VV(__call_if_debug_procs_t, CYGNUM_CALL_IF_DEBUG_PROCS)
589 __data_VV(CYGNUM_CALL_IF_DEBUG_PROCS, __call_if_debug_procs_t)
590 #define CYGACC_CALL_IF_DEBUG_PROCS_SET(_x_) \
591  hal_virtual_vector_table[CYGNUM_CALL_IF_DEBUG_PROCS]=(CYG_ADDRWORD)(_x_)
592
593 #define CYGACC_CALL_IF_SET_DEBUG_COMM(_i_) \
594  CYGACC_CALL_VV1(__call_if_set_debug_comm_t*, CYGNUM_CALL_IF_SET_DEBUG_COMM, (_i_))
595 __call_VV1(CYGNUM_CALL_IF_SET_DEBUG_COMM, __call_if_set_debug_comm_t, int, int)
596 #define CYGACC_CALL_IF_SET_DEBUG_COMM_SET(_x_) \
597  hal_virtual_vector_table[CYGNUM_CALL_IF_SET_DEBUG_COMM]=(CYG_ADDRWORD)(_x_)
598
599 #define CYGACC_CALL_IF_SET_CONSOLE_COMM(_i_) \
600  CYGACC_CALL_VV1(__call_if_set_console_comm_t*, CYGNUM_CALL_IF_SET_CONSOLE_COMM, (_i_))
601 __call_VV1(CYGNUM_CALL_IF_SET_CONSOLE_COMM, __call_if_set_console_comm_t, int, int)
602 #define CYGACC_CALL_IF_SET_CONSOLE_COMM_SET(_x_) \
603  hal_virtual_vector_table[CYGNUM_CALL_IF_SET_CONSOLE_COMM]=(CYG_ADDRWORD)(_x_)
604
605 #define CYGACC_CALL_IF_DBG_DATA() \
606  CYGACC_DATA_VV(__call_if_dbg_data_t, CYGNUM_CALL_IF_DBG_DATA)
607 __data_VV(CYGNUM_CALL_IF_DBG_DATA, __call_if_dbg_data_t)
608 #define CYGACC_CALL_IF_DBG_DATA_SET(_x_) \
609  hal_virtual_vector_table[CYGNUM_CALL_IF_DBG_DATA]=(CYG_ADDRWORD)(_x_)
610
611 #define CYGACC_CALL_IF_DBG_SYSCALL(_id_,_p_) \
612  CYGACC_CALL_VV2(__call_if_dbg_syscall_t, CYGNUM_CALL_IF_DBG_SYSCALL, _id_, _p_)
613 __call_VV2(CYGNUM_CALL_IF_DBG_SYSCALL, __call_if_dbg_syscall_t, int, enum dbg_syscall_ids ,  union dbg_thread_syscall_parms  *)
614 #define CYGACC_CALL_IF_DBG_SYSCALL_SET(_x_) \
615  hal_virtual_vector_table[CYGNUM_CALL_IF_DBG_SYSCALL]=(CYG_ADDRWORD)(_x_)
616
617 #define CYGACC_CALL_IF_RESET() \
618  CYGACC_CALL_VV0(__call_if_reset_t*, CYGNUM_CALL_IF_RESET)()
619 __call_voidVV0(CYGNUM_CALL_IF_RESET, __call_if_reset_t, void)
620 #define CYGACC_CALL_IF_RESET_SET(_x_) \
621  hal_virtual_vector_table[CYGNUM_CALL_IF_RESET]=(CYG_ADDRWORD)(_x_)
622 #define CYGACC_CALL_IF_RESET_GET() \
623  ((__call_if_reset_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_RESET])
624
625 #define CYGACC_CALL_IF_MONITOR_VERSION() \
626  CYGACC_DATA_VV(__call_if_monitor_version_t, CYGNUM_CALL_IF_MONITOR_VERSION)
627 __data_VV(CYGNUM_CALL_IF_MONITOR_VERSION, __call_if_monitor_version_t)
628 #define CYGACC_CALL_IF_MONITOR_VERSION_SET(_x_) \
629  hal_virtual_vector_table[CYGNUM_CALL_IF_MONITOR_VERSION]=(CYG_ADDRWORD)(_x_)
630
631 #define CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG() \
632  CYGACC_DATA_VV(__call_if_console_interrupt_flag_t, CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG)
633 __data_VV(CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG, __call_if_console_interrupt_flag_t)
634 #define CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(_x_) \
635  hal_virtual_vector_table[CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG]=(CYG_ADDRWORD)(_x_)
636
637 #define CYGACC_CALL_IF_DELAY_US(_u_) \
638  CYGACC_CALL_VV1(__call_if_delay_us_t*, CYGNUM_CALL_IF_DELAY_US, (_u_))
639 __call_voidVV1(CYGNUM_CALL_IF_DELAY_US, __call_if_delay_us_t, void, cyg_int32)
640 #define CYGACC_CALL_IF_DELAY_US_SET(_x_) \
641  hal_virtual_vector_table[CYGNUM_CALL_IF_DELAY_US]=(CYG_ADDRWORD)(_x_)
642
643 #define CYGACC_CALL_IF_INSTALL_BPT_FN(_e_) \
644  CYGACC_CALL_VV1(__call_if_install_bpt_fn_t*, CYGNUM_CALL_IF_INSTALL_BPT_FN, (_e_))
645 __call_voidVV1(CYGNUM_CALL_IF_INSTALL_BPT_FN, __call_if_install_bpt_fn_t, void, void *)
646 #define CYGACC_CALL_IF_INSTALL_BPT_FN_SET(_x_) \
647  hal_virtual_vector_table[CYGNUM_CALL_IF_INSTALL_BPT_FN]=(CYG_ADDRWORD)(_x_)
648
649 //
650 // Access persistent data store - kept in FLASH or EEPROM by RedBoot
651 //
652 #define CYGNUM_CALL_IF_FLASH_CFG_GET  (0)     // Get a particular fconfig key
653 #define CYGNUM_CALL_IF_FLASH_CFG_NEXT (1)     // Enumerate keys (get the next one)
654 #define CYGNUM_CALL_IF_FLASH_CFG_SET  (2)     // Update particular fconfig key
655 #define CYGACC_CALL_IF_FLASH_CFG_OP2(_o_,_d_) \
656  CYGACC_CALL_VV2(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_d_))
657 __call_VV2(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, struct cyg_fconfig *)
658
659 static __inline__ cyg_bool
660 __call_if_flash_cfg_op(int op, char *key, void *data, int type)
661 {
662     struct cyg_fconfig info;
663     info.key = key;
664     info.val = data;
665     info.type = type;
666     info.offset = 0;
667     return CYGACC_CALL_IF_FLASH_CFG_OP2(op, &info);
668 }
669 #define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_k_,_d_,_t_) \
670   __call_if_flash_cfg_op(_o_,_k_,_d_,_t_)
671 #define CYGACC_CALL_IF_FLASH_CFG_OP_SET(_x_) \
672  hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_CFG_OP]=(CYG_ADDRWORD)(_x_)
673
674 #define CYGACC_CALL_IF_MONITOR_RETURN(_u_) \
675  CYGACC_CALL_VV1(__call_if_monitor_return_t*, CYGNUM_CALL_IF_MONITOR_RETURN, (_u_))
676 __call_voidVV1(CYGNUM_CALL_IF_MONITOR_RETURN, __call_if_monitor_return_t, void, int)
677 #define CYGACC_CALL_IF_MONITOR_RETURN_SET(_x_) \
678  hal_virtual_vector_table[CYGNUM_CALL_IF_MONITOR_RETURN]=(CYG_ADDRWORD)(_x_)
679
680 #define CYGACC_CALL_IF_FLASH_FIS_OP(_o_,_k_,_d_) \
681  CYGACC_CALL_VV3(__call_if_flash_fis_op_fn_t*, CYGNUM_CALL_IF_FLASH_FIS_OP, (_o_),(_k_),(_d_))
682 __call_VV3(CYGNUM_CALL_IF_FLASH_FIS_OP, __call_if_flash_fis_op_fn_t, cyg_bool, int, char *, void *)
683 #define CYGACC_CALL_IF_FLASH_FIS_OP_SET(_x_) \
684  hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_FIS_OP]=(CYG_ADDRWORD)(_x_)
685 #define CYGNUM_CALL_IF_FLASH_FIS_GET_FLASH_BASE  (0)
686 #define CYGNUM_CALL_IF_FLASH_FIS_GET_SIZE        (1)
687 #define CYGNUM_CALL_IF_FLASH_FIS_GET_MEM_BASE    (2)
688 #define CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY_POINT (3)
689 #define CYGNUM_CALL_IF_FLASH_FIS_GET_DATA_LENGTH (4)
690 #define CYGNUM_CALL_IF_FLASH_FIS_GET_DESC_CKSUM  (5)
691 #define CYGNUM_CALL_IF_FLASH_FIS_GET_FILE_CKSUM  (6)
692
693
694 // These need to be kept uptodate with the (unadorned) masters
695 // in RedBoot's flash_config.h:
696 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_EMPTY   0
697 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL    1
698 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_INT     2
699 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_STRING  3
700 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_SCRIPT  4
701 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_IP      5
702 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_ESA     6
703
704 #endif // CYGACC_CALL_IF_DEFINED
705
706 //--------------------------------------------------------------------------
707 // Diag wrappers.
708 externC void hal_if_diag_init(void);
709 externC void hal_if_diag_write_char(char c);
710 externC void hal_if_diag_read_char(char *c);
711
712 //--------------------------------------------------------------------------
713 // Ctrl-c support.
714 externC cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
715 externC cyg_bool   hal_ctrlc_check(CYG_ADDRWORD vector, CYG_ADDRWORD data);
716
717 #define HAL_CTRLC_ISR hal_ctrlc_isr
718 #define HAL_CTRLC_CHECK hal_ctrlc_check
719
720 #else
721
722 #if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT) \
723     || defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
724 // Then other code might invoke this macro
725 #define HAL_CTRLC_CHECK(a1,a2) (0) // Nothing, no CTRLC here
726 #endif
727
728 #endif // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
729
730 //--------------------------------------------------------------------------
731 // Functions provided by the HAL interface.
732 externC void hal_if_init(void);
733 #if 0 != CYGINT_HAL_PLF_IF_INIT
734 externC void plf_if_init(void);
735 #endif
736
737 //-----------------------------------------------------------------------------
738 #endif // CYGONCE_HAL_HAL_IF_H
739 // End of hal_if.h