unified MX27, MX25, MX37 trees
[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 __vec,
195                                CYG_ADDRWORD __data);
196 typedef cyg_bool (*__comm_if_getc_timeout_t)(void *__ch_data, void *__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, void *)
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 #define CYGNUM_CALL_IF_FLASH_FIS_OP2              23
371
372 #define CYGNUM_CALL_IF_LAST_ENTRY                 CYGNUM_CALL_IF_FLASH_FIS_OP2
373
374 #define CYGNUM_CALL_IF_INSTALL_BPT_FN             35
375
376 #define CYGNUM_CALL_IF_TABLE_SIZE                 64
377
378 externC volatile CYG_ADDRWORD hal_virtual_vector_table[CYGNUM_CALL_IF_TABLE_SIZE];
379
380 // Table version contains version information for both the CALL table
381 // itself (the number of the last active entry in the table), and the
382 // COMM table (the size of the table).
383 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL         CYGNUM_CALL_IF_LAST_ENTRY
384 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_HACK    (CYGNUM_CALL_IF_TABLE_SIZE+1)
385 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_MAX     CYGNUM_CALL_IF_TABLE_SIZE
386 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM         CYGNUM_COMM_IF_TABLE_SIZE
387 #define CYGNUM_CALL_IF_TABLE_VERSION_CALL_MASK    0x0000ffff
388 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM_MASK    0xffff0000
389 #define CYGNUM_CALL_IF_TABLE_VERSION_COMM_shift   16
390
391
392 // These are special debug/console procs IDs
393 // QUERY_CURRENT will cause the ID of the currently selected proc ID to be
394 //               returned.
395 // EMPTY         this is the ID used for an empty procs table (i.e, NULL
396 //               pointer)
397 // MANGLER       selects the procs space reserved for the console mangler
398 //               allowing the application to temporarily disable mangling
399 //               or temporarily switch in different console procs.
400 #define CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT -1
401 #define CYGNUM_CALL_IF_SET_COMM_ID_EMPTY         -2
402 #define CYGNUM_CALL_IF_SET_COMM_ID_MANGLER       -3
403
404 // The below is a (messy) attempt at adding some type safety to the
405 // above array. At the same time, the accessors allow the
406 // implementation to be easily changed in the future (both tag->data
407 // table and structure implementations have been suggested).
408
409 typedef int __call_if_version_t;
410 typedef void* __call_if_ictrl_table_t;
411 typedef void* __call_if_exc_table_t;
412 typedef bsp_handler_t *__call_if_dbg_vector_t;
413 typedef bsp_handler_t __call_if_kill_vector_t;
414 typedef hal_virtual_comm_table_t *__call_if_console_procs_t;
415 typedef hal_virtual_comm_table_t *__call_if_debug_procs_t;
416 typedef void (__call_if_flush_dcache_t)(void *__p, int __nbytes);
417 typedef void (__call_if_flush_icache_t)(void *__p, int __nbytes);
418 typedef int (__call_if_set_debug_comm_t)(int __comm_id);
419 typedef int (__call_if_set_console_comm_t)(int __comm_id);
420 typedef void* __call_if_dbg_data_t;
421 typedef int (__call_if_dbg_syscall_t) (enum dbg_syscall_ids id,
422                                         union dbg_thread_syscall_parms  *p );
423 typedef void (__call_if_reset_t)(void);
424 typedef int __call_if_console_interrupt_flag_t;
425 typedef void (__call_if_delay_us_t)(cyg_int32 usecs);
426 typedef void (__call_if_install_bpt_fn_t)(void *__epc);
427 typedef char *__call_if_monitor_version_t;
428 typedef void (__call_if_monitor_return_t)(int status);
429 typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name, void *__val);
430
431 //
432 // This structure is used to pass parameters to/from the fis routines
433 //
434 struct fis_table_entry {
435    unsigned char name[16];
436    CYG_ADDRESS   flash_base;
437    CYG_ADDRESS   mem_base;
438    unsigned long size;
439    CYG_ADDRESS   entry_point;
440    unsigned long data_length;
441    unsigned long desc_cksum;
442    unsigned long file_cksum;
443 };
444
445 typedef int (__call_if_flash_fis_op2_fn_t)(int __oper, unsigned int index, struct fis_table_entry *__fis_entry);
446 //
447 // This structure is used to pass parameters to/from the fconfig routines.
448 // This allows a single virtual vector interface, with widely varying functionality
449 //
450 struct cyg_fconfig {
451     char *key;      // Datum 'key'
452     int   keylen;   // Length of key
453     void *val;      // Pointer to data
454     int   type;     // Type of datum
455     int   offset;   // Offset within data (used by _NEXT)
456 };
457 typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, struct cyg_fconfig *__data);
458
459 #ifndef CYGACC_CALL_IF_DEFINED
460
461 #define __data_VV(_n_,_tt_)                             \
462 static __inline__ _tt_                                  \
463 __call_vv_##_n_(void)                                   \
464 {                                                       \
465     return ((_tt_)hal_virtual_vector_table[_n_]);       \
466 }
467
468 #define __call_VV0(_n_,_tt_,_rt_)                                       \
469 static __inline__ _rt_                                                  \
470 __call_vv_##_n_(void)                                                   \
471 {                                                                       \
472     _rt_ res;                                                           \
473     _ENTER_MONITOR();                                                   \
474     res = ((_tt_ *)hal_virtual_vector_table[_n_])();                    \
475     _EXIT_MONITOR();                                                    \
476     return res;                                                         \
477 }
478
479 #define __call_voidVV0(_n_,_tt_,_rt_)                                   \
480 static __inline__ _rt_                                                  \
481 __call_vv_##_n_(void)                                                   \
482 {                                                                       \
483     _ENTER_MONITOR();                                                   \
484     ((_tt_ *)hal_virtual_vector_table[_n_])();                          \
485     _EXIT_MONITOR();                                                    \
486 }
487
488 #define __call_VV1(_n_,_tt_,_rt_,_t1_)                                  \
489 static __inline__ _rt_                                                  \
490 __call_vv_##_n_(_t1_ _p1_)                                              \
491 {                                                                       \
492     _rt_ res;                                                           \
493     _ENTER_MONITOR();                                                   \
494     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_);                \
495     _EXIT_MONITOR();                                                    \
496     return res;                                                         \
497 }
498
499 #define __call_voidVV1(_n_,_tt_,_rt_,_t1_)                              \
500 static __inline__ _rt_                                                  \
501 __call_vv_##_n_(_t1_ _p1_)                                              \
502 {                                                                       \
503     _ENTER_MONITOR();                                                   \
504     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_);                      \
505     _EXIT_MONITOR();                                                    \
506 }
507
508 #define __call_VV2(_n_,_tt_,_rt_,_t1_,_t2_)                             \
509 static __inline__ _rt_                                                  \
510 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_)                                   \
511 {                                                                       \
512     _rt_ res;                                                           \
513     _ENTER_MONITOR();                                                   \
514     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_);           \
515     _EXIT_MONITOR();                                                    \
516     return res;                                                         \
517 }
518
519 #define __call_voidVV2(_n_,_tt_,_rt_,_t1_,_t2_)                         \
520 static __inline__ _rt_                                                  \
521 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_)                                   \
522 {                                                                       \
523     _ENTER_MONITOR();                                                   \
524     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_);                 \
525     _EXIT_MONITOR();                                                    \
526 }
527
528 #define __call_VV3(_n_,_tt_,_rt_,_t1_,_t2_,_t3_)                        \
529 static __inline__ _rt_                                                  \
530 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_)                        \
531 {                                                                       \
532     _rt_ res;                                                           \
533     _ENTER_MONITOR();                                                   \
534     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_);      \
535     _EXIT_MONITOR();                                                    \
536     return res;                                                         \
537 }
538
539 #define __call_voidVV3(_n_,_tt_,_rt_,_t1_,_t2_,_t3_)                    \
540 static __inline__ _rt_                                                  \
541 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_)                        \
542 {                                                                       \
543     _ENTER_MONITOR();                                                   \
544     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_);            \
545     _EXIT_MONITOR();                                                    \
546 }
547
548 #define __call_VV4(_n_,_tt_,_rt_,_t1_,_t2_,_t3_,_t4_)                   \
549 static __inline__ _rt_                                                  \
550 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_, _t4_ _p4_)             \
551 {                                                                       \
552     _rt_ res;                                                           \
553     _ENTER_MONITOR();                                                   \
554     res = ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_,_p4_); \
555     _EXIT_MONITOR();                                                    \
556     return res;                                                         \
557 }
558
559 #define __call_voidVV4(_n_,_tt_,_rt_,_t1_,_t2_,_t3_,_t4_)               \
560 static __inline__ _rt_                                                  \
561 __call_vv_##_n_(_t1_ _p1_, _t2_ _p2_, _t3_ _p3_, _t4_ _p4_)             \
562 {                                                                       \
563     _ENTER_MONITOR();                                                   \
564     ((_tt_ *)hal_virtual_vector_table[_n_])(_p1_,_p2_,_p3_,_p4_);       \
565     _EXIT_MONITOR();                                                    \
566 }
567
568
569 #define CYGACC_DATA_VV(t,e)              __call_vv_##e()
570 #define CYGACC_CALL_VV0(t,e)             __call_vv_##e
571 #define CYGACC_CALL_VV1(t,e,p1)          __call_vv_##e((p1))
572 #define CYGACC_CALL_VV2(t,e,p1,p2)       __call_vv_##e((p1),(p2))
573 #define CYGACC_CALL_VV3(t,e,p1,p2,p3)    __call_vv_##e((p1),(p2),(p3))
574 #define CYGACC_CALL_VV4(t,e,p1,p2,p3,p4) __call_vv_##e((p1),(p2),(p3),(p4))
575
576 #define CYGACC_CALL_IF_VERSION() \
577  CYGACC_DATA_VV(__call_if_version_t, CYGNUM_CALL_IF_VERSION)
578 __data_VV(CYGNUM_CALL_IF_VERSION, __call_if_version_t)
579 #define CYGACC_CALL_IF_VERSION_SET(_x_) \
580  hal_virtual_vector_table[CYGNUM_CALL_IF_VERSION]=(CYG_ADDRWORD)(_x_)
581
582 #define CYGACC_CALL_IF_KILL_VECTOR() \
583  CYGACC_DATA_VV(__call_if_kill_vector_t, CYGNUM_CALL_IF_KILL_VECTOR)
584 __data_VV(CYGNUM_CALL_IF_KILL_VECTOR, __call_if_kill_vector_t)
585 #define CYGACC_CALL_IF_KILL_VECTOR_SET(_x_) \
586  hal_virtual_vector_table[CYGNUM_CALL_IF_KILL_VECTOR]=(CYG_ADDRWORD)(_x_)
587
588 #define CYGACC_CALL_IF_CONSOLE_PROCS() \
589  CYGACC_DATA_VV(__call_if_console_procs_t, CYGNUM_CALL_IF_CONSOLE_PROCS)
590 __data_VV(CYGNUM_CALL_IF_CONSOLE_PROCS, __call_if_console_procs_t)
591 #define CYGACC_CALL_IF_CONSOLE_PROCS_SET(_x_) \
592  hal_virtual_vector_table[CYGNUM_CALL_IF_CONSOLE_PROCS]=(CYG_ADDRWORD)(_x_)
593
594 #define CYGACC_CALL_IF_FLUSH_DCACHE(_p_, _n_) \
595  ((__call_if_flush_dcache_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_DCACHE])((_p_), (_n_))
596 #define CYGACC_CALL_IF_FLUSH_DCACHE_SET(_x_) \
597  hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_DCACHE]=(CYG_ADDRWORD)(_x_)
598
599 #define CYGACC_CALL_IF_FLUSH_ICACHE(_p_, _n_) \
600  ((__call_if_flush_icache_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_ICACHE])((_p_), (_n_))
601 #define CYGACC_CALL_IF_FLUSH_ICACHE_SET(_x_) \
602  hal_virtual_vector_table[CYGNUM_CALL_IF_FLUSH_ICACHE]=(CYG_ADDRWORD)(_x_)
603
604 #define CYGACC_CALL_IF_DEBUG_PROCS() \
605  CYGACC_DATA_VV(__call_if_debug_procs_t, CYGNUM_CALL_IF_DEBUG_PROCS)
606 __data_VV(CYGNUM_CALL_IF_DEBUG_PROCS, __call_if_debug_procs_t)
607 #define CYGACC_CALL_IF_DEBUG_PROCS_SET(_x_) \
608  hal_virtual_vector_table[CYGNUM_CALL_IF_DEBUG_PROCS]=(CYG_ADDRWORD)(_x_)
609
610 #define CYGACC_CALL_IF_SET_DEBUG_COMM(_i_) \
611  CYGACC_CALL_VV1(__call_if_set_debug_comm_t*, CYGNUM_CALL_IF_SET_DEBUG_COMM, (_i_))
612 __call_VV1(CYGNUM_CALL_IF_SET_DEBUG_COMM, __call_if_set_debug_comm_t, int, int)
613 #define CYGACC_CALL_IF_SET_DEBUG_COMM_SET(_x_) \
614  hal_virtual_vector_table[CYGNUM_CALL_IF_SET_DEBUG_COMM]=(CYG_ADDRWORD)(_x_)
615
616 #define CYGACC_CALL_IF_SET_CONSOLE_COMM(_i_) \
617  CYGACC_CALL_VV1(__call_if_set_console_comm_t*, CYGNUM_CALL_IF_SET_CONSOLE_COMM, (_i_))
618 __call_VV1(CYGNUM_CALL_IF_SET_CONSOLE_COMM, __call_if_set_console_comm_t, int, int)
619 #define CYGACC_CALL_IF_SET_CONSOLE_COMM_SET(_x_) \
620  hal_virtual_vector_table[CYGNUM_CALL_IF_SET_CONSOLE_COMM]=(CYG_ADDRWORD)(_x_)
621
622 #define CYGACC_CALL_IF_DBG_DATA() \
623  CYGACC_DATA_VV(__call_if_dbg_data_t, CYGNUM_CALL_IF_DBG_DATA)
624 __data_VV(CYGNUM_CALL_IF_DBG_DATA, __call_if_dbg_data_t)
625 #define CYGACC_CALL_IF_DBG_DATA_SET(_x_) \
626  hal_virtual_vector_table[CYGNUM_CALL_IF_DBG_DATA]=(CYG_ADDRWORD)(_x_)
627
628 #define CYGACC_CALL_IF_DBG_SYSCALL(_id_,_p_) \
629  CYGACC_CALL_VV2(__call_if_dbg_syscall_t, CYGNUM_CALL_IF_DBG_SYSCALL, _id_, _p_)
630 __call_VV2(CYGNUM_CALL_IF_DBG_SYSCALL, __call_if_dbg_syscall_t, int, enum dbg_syscall_ids ,  union dbg_thread_syscall_parms  *)
631 #define CYGACC_CALL_IF_DBG_SYSCALL_SET(_x_) \
632  hal_virtual_vector_table[CYGNUM_CALL_IF_DBG_SYSCALL]=(CYG_ADDRWORD)(_x_)
633
634 #define CYGACC_CALL_IF_RESET() \
635  CYGACC_CALL_VV0(__call_if_reset_t*, CYGNUM_CALL_IF_RESET)()
636 __call_voidVV0(CYGNUM_CALL_IF_RESET, __call_if_reset_t, void)
637 #define CYGACC_CALL_IF_RESET_SET(_x_) \
638  hal_virtual_vector_table[CYGNUM_CALL_IF_RESET]=(CYG_ADDRWORD)(_x_)
639 #define CYGACC_CALL_IF_RESET_GET() \
640  ((__call_if_reset_t*)hal_virtual_vector_table[CYGNUM_CALL_IF_RESET])
641
642 #define CYGACC_CALL_IF_MONITOR_VERSION() \
643  CYGACC_DATA_VV(__call_if_monitor_version_t, CYGNUM_CALL_IF_MONITOR_VERSION)
644 __data_VV(CYGNUM_CALL_IF_MONITOR_VERSION, __call_if_monitor_version_t)
645 #define CYGACC_CALL_IF_MONITOR_VERSION_SET(_x_) \
646  hal_virtual_vector_table[CYGNUM_CALL_IF_MONITOR_VERSION]=(CYG_ADDRWORD)(_x_)
647
648 #define CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG() \
649  CYGACC_DATA_VV(__call_if_console_interrupt_flag_t, CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG)
650 __data_VV(CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG, __call_if_console_interrupt_flag_t)
651 #define CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(_x_) \
652  hal_virtual_vector_table[CYGNUM_CALL_IF_CONSOLE_INTERRUPT_FLAG]=(CYG_ADDRWORD)(_x_)
653
654 #define CYGACC_CALL_IF_DELAY_US(_u_) \
655  CYGACC_CALL_VV1(__call_if_delay_us_t*, CYGNUM_CALL_IF_DELAY_US, (_u_))
656 __call_voidVV1(CYGNUM_CALL_IF_DELAY_US, __call_if_delay_us_t, void, cyg_int32)
657 #define CYGACC_CALL_IF_DELAY_US_SET(_x_) \
658  hal_virtual_vector_table[CYGNUM_CALL_IF_DELAY_US]=(CYG_ADDRWORD)(_x_)
659
660 #define CYGACC_CALL_IF_INSTALL_BPT_FN(_e_) \
661  CYGACC_CALL_VV1(__call_if_install_bpt_fn_t*, CYGNUM_CALL_IF_INSTALL_BPT_FN, (_e_))
662 __call_voidVV1(CYGNUM_CALL_IF_INSTALL_BPT_FN, __call_if_install_bpt_fn_t, void, void *)
663 #define CYGACC_CALL_IF_INSTALL_BPT_FN_SET(_x_) \
664  hal_virtual_vector_table[CYGNUM_CALL_IF_INSTALL_BPT_FN]=(CYG_ADDRWORD)(_x_)
665
666 //
667 // Access persistent data store - kept in FLASH or EEPROM by RedBoot
668 //
669 #define CYGNUM_CALL_IF_FLASH_CFG_GET  (0)     // Get a particular fconfig key
670 #define CYGNUM_CALL_IF_FLASH_CFG_NEXT (1)     // Enumerate keys (get the next one)
671 #define CYGNUM_CALL_IF_FLASH_CFG_SET  (2)     // Update particular fconfig key
672 #define CYGACC_CALL_IF_FLASH_CFG_OP2(_o_,_d_) \
673  CYGACC_CALL_VV2(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_d_))
674 __call_VV2(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, struct cyg_fconfig *)
675
676 static __inline__ cyg_bool
677 __call_if_flash_cfg_op(int op, char *key, void *data, int type)
678 {
679     struct cyg_fconfig info;
680     info.key = key;
681     info.val = data;
682     info.type = type;
683     info.offset = 0;
684     return CYGACC_CALL_IF_FLASH_CFG_OP2(op, &info);
685 }
686 #define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_k_,_d_,_t_) \
687   __call_if_flash_cfg_op(_o_,_k_,_d_,_t_)
688 #define CYGACC_CALL_IF_FLASH_CFG_OP_SET(_x_) \
689  hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_CFG_OP]=(CYG_ADDRWORD)(_x_)
690
691 #define CYGACC_CALL_IF_MONITOR_RETURN(_u_) \
692  CYGACC_CALL_VV1(__call_if_monitor_return_t*, CYGNUM_CALL_IF_MONITOR_RETURN, (_u_))
693 __call_voidVV1(CYGNUM_CALL_IF_MONITOR_RETURN, __call_if_monitor_return_t, void, int)
694 #define CYGACC_CALL_IF_MONITOR_RETURN_SET(_x_) \
695  hal_virtual_vector_table[CYGNUM_CALL_IF_MONITOR_RETURN]=(CYG_ADDRWORD)(_x_)
696
697 #define CYGACC_CALL_IF_FLASH_FIS_OP(_o_,_k_,_d_) \
698  CYGACC_CALL_VV3(__call_if_flash_fis_op_fn_t*, CYGNUM_CALL_IF_FLASH_FIS_OP, (_o_),(_k_),(_d_))
699 __call_VV3(CYGNUM_CALL_IF_FLASH_FIS_OP, __call_if_flash_fis_op_fn_t, cyg_bool, int, char *, void *)
700 #define CYGACC_CALL_IF_FLASH_FIS_OP_SET(_x_) \
701  hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_FIS_OP]=(CYG_ADDRWORD)(_x_)
702 #define CYGNUM_CALL_IF_FLASH_FIS_GET_FLASH_BASE  (0)
703 #define CYGNUM_CALL_IF_FLASH_FIS_GET_SIZE        (1)
704 #define CYGNUM_CALL_IF_FLASH_FIS_GET_MEM_BASE    (2)
705 #define CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY_POINT (3)
706 #define CYGNUM_CALL_IF_FLASH_FIS_GET_DATA_LENGTH (4)
707 #define CYGNUM_CALL_IF_FLASH_FIS_GET_DESC_CKSUM  (5)
708 #define CYGNUM_CALL_IF_FLASH_FIS_GET_FILE_CKSUM  (6)
709
710 #define CYGACC_CALL_IF_FLASH_FIS_OP2(_o_,_k_,_d_) \
711  CYGACC_CALL_VV3(__call_if_flash_fis_op2_fn_t*, CYGNUM_CALL_IF_FLASH_FIS_OP2, (_o_),(_k_),(_d_))
712 __call_VV3(CYGNUM_CALL_IF_FLASH_FIS_OP2, __call_if_flash_fis_op2_fn_t, int, int, unsigned int, struct fis_table_entry *)
713 #define CYGACC_CALL_IF_FLASH_FIS_OP2_SET(_x_) \
714  hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_FIS_OP2]=(CYG_ADDRWORD)(_x_)
715 #define CYGNUM_CALL_IF_FLASH_FIS_GET_VERSION     (0)
716 #define CYGNUM_CALL_IF_FLASH_FIS_INIT            (1)
717 #define CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY_COUNT (2)
718 #define CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY       (3)
719 #define CYGNUM_CALL_IF_FLASH_FIS_START_UPDATE    (4)
720 #define CYGNUM_CALL_IF_FLASH_FIS_FINISH_UPDATE   (5)
721 #define CYGNUM_CALL_IF_FLASH_FIS_MODIFY_ENTRY    (6)
722
723
724
725 // These need to be kept uptodate with the (unadorned) masters
726 // in RedBoot's flash_config.h:
727 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_EMPTY   0
728 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL    1
729 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_INT     2
730 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_STRING  3
731 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_SCRIPT  4
732 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_IP      5
733 #define CYGNUM_FLASH_CFG_TYPE_CONFIG_ESA     6
734
735 #endif // CYGACC_CALL_IF_DEFINED
736
737 //--------------------------------------------------------------------------
738 // Diag wrappers.
739 externC void hal_if_diag_init(void);
740 externC void hal_if_diag_write_char(char c);
741 externC void hal_if_diag_read_char(char *c);
742
743 //--------------------------------------------------------------------------
744 // Ctrl-c support.
745 externC cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
746 externC cyg_bool   hal_ctrlc_check(CYG_ADDRWORD vector, CYG_ADDRWORD data);
747
748 #define HAL_CTRLC_ISR hal_ctrlc_isr
749 #define HAL_CTRLC_CHECK hal_ctrlc_check
750
751 #else
752
753 #if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT) \
754     || defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
755 // Then other code might invoke this macro
756 #define HAL_CTRLC_CHECK(a1,a2) (0) // Nothing, no CTRLC here
757 #endif
758
759 #endif // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
760
761 //--------------------------------------------------------------------------
762 // Functions provided by the HAL interface.
763 externC void hal_if_init(void);
764 #if 0 != CYGINT_HAL_PLF_IF_INIT
765 externC void plf_if_init(void);
766 #endif
767
768 //-----------------------------------------------------------------------------
769 #endif // CYGONCE_HAL_HAL_IF_H
770 // End of hal_if.h