1 #ifndef CYGONCE_KERNEL_KAPIDATA_H
2 #define CYGONCE_KERNEL_KAPIDATA_H
4 /*=============================================================================
8 // Native API data structures
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 2002 Bart Veer
15 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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.
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
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.
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.
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.
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####
48 // Contributors: nickg
50 // Purpose: Native API data structures
51 // Description: This file defines the structures used in the native API. The
52 // sizes of these structures are dependent on the system
53 // configuration and must be kept in step with their real
54 // counterparts in the C++ headers.
55 // IMPORTANT: It is NOT guaranteed that the fields of these
56 // structures correspond to the equivalent fields in the
57 // C++ classes they shadow.
59 // One oddity with this file is that the way many of the "mirror"
60 // classes are defined with macros. The resulting structures
61 // then have a "flat" layout, rather than just declaring a
62 // member structure directly in the structure. The reason for
63 // this is that as of GCC 3.x, the C++ compiler will optimise
64 // classes by removing padding and reusing it for subsequent
65 // members defined in a derived class. This affects some targets
66 // (including PowerPC and MIPS at least) when a C++ base class
67 // includes a long long. By instead arranging for the C structure
68 // to just list all the members directly, the compiler will then
69 // behave the same for the C structures as the C++ classes.
71 // This means that care has to be taken to follow the same
72 // methodology if new stuff is added to this file. Even if
73 // it doesn't contain long longs for your target, it may for
74 // others, depending on HAL definitions.
76 // Usage: included by kapi.h
78 //####DESCRIPTIONEND####
80 //==========================================================================*/
82 #include <pkgconf/system.h>
83 #include <pkgconf/kernel.h>
85 #include <cyg/infra/cyg_type.h>
86 #include <cyg/hal/hal_intr.h> // exception defines
88 /*---------------------------------------------------------------------------*/
94 /*---------------------------------------------------------------------------*/
96 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE
97 #if defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
98 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
99 #elif defined(CYGSEM_KERNEL_SCHED_BITMAP)
100 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
104 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8
105 typedef cyg_ucount8 cyg_sched_bitmap;
106 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16
107 typedef cyg_ucount16 cyg_sched_bitmap;
108 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32
109 typedef cyg_ucount32 cyg_sched_bitmap;
110 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 64
111 typedef cyg_ucount64 cyg_sched_bitmap;
113 #error Bitmaps greater than 64 bits not currently allowed
118 #if defined(CYGSEM_KERNEL_SCHED_BITMAP)
120 cyg_sched_bitmap map;
122 #elif defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
126 #elif defined(CYGSEM_KERNEL_SCHED_LOTTERY)
132 #error Undefined scheduler type
137 /*---------------------------------------------------------------------------*/
142 cyg_priority_t priority;
147 #ifdef CYGIMP_KERNEL_INTERRUPTS_DSRS_LIST
148 cyg_ucount32 dsr_count;
149 cyg_interrupt *next_dsr;
151 #ifdef CYGIMP_KERNEL_INTERRUPTS_CHAIN
157 /*---------------------------------------------------------------------------*/
160 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST)
161 # define CYG_COUNTER_ALARM_LIST_MEMBER \
162 cyg_alarm *alarm_list;
163 #elif defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)
164 # define CYG_COUNTER_ALARM_LIST_MEMBER \
165 cyg_alarm *alarm_list[CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE];
167 # define CYG_COUNTER_ALARM_LIST_MEMBER
170 #define CYG_COUNTER_MEMBERS \
171 CYG_COUNTER_ALARM_LIST_MEMBER \
172 cyg_tick_count_t counter; \
173 cyg_uint32 increment;
180 /*---------------------------------------------------------------------------*/
185 CYG_RESOLUTION_T_MEMBERS
188 /*---------------------------------------------------------------------------*/
191 #if defined(CYGIMP_KERNEL_COUNTERS_SINGLE_LIST) || \
192 defined(CYGIMP_KERNEL_COUNTERS_MULTI_LIST)
193 # define CYG_ALARM_LIST_MEMBERS \
197 # define CYG_ALARM_LIST_MEMBERS
200 #define CYG_ALARM_MEMBERS \
201 CYG_ALARM_LIST_MEMBERS \
202 cyg_counter *counter; \
203 cyg_alarm_t *alarm; \
205 cyg_tick_count_t trigger; \
206 cyg_tick_count_t interval; \
214 /*---------------------------------------------------------------------------*/
215 /* Exception controller */
217 #ifdef CYGPKG_KERNEL_EXCEPTIONS
219 # ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
220 # define CYG_EXCEPTION_CONTROL_MEMBERS \
221 cyg_exception_handler_t *exception_handler[CYGNUM_HAL_EXCEPTION_COUNT]; \
222 CYG_ADDRWORD exception_data[CYGNUM_HAL_EXCEPTION_COUNT];
224 # define CYG_EXCEPTION_CONTROL_MEMBERS \
225 cyg_exception_handler_t *exception_handler; /* Handler function */ \
226 CYG_ADDRWORD exception_data; /* Handler data */
231 CYG_EXCEPTION_CONTROL_MEMBERS
232 } cyg_exception_control;
236 /*---------------------------------------------------------------------------*/
237 /* Hardware Thread structure */
239 #ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT
240 # define CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER \
241 CYG_ADDRESS stack_limit; /* movable stack limit */
243 # define CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER
246 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
247 # define CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER \
248 void *saved_context; // If non-zero, this points at a more
249 // interesting context than stack_ptr.
251 # define CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER
254 typedef void cyg_thread_entry(CYG_ADDRWORD data);
256 #define CYG_HARDWARETHREAD_MEMBERS \
257 CYG_ADDRESS stack_base; /* pointer to base of stack area */ \
258 cyg_uint32 stack_size; /* size of stack area in bytes */ \
259 CYG_HARDWARETHREAD_STACK_LIMIT_MEMBER \
260 CYG_ADDRESS stack_ptr; /* pointer to saved state on stack */ \
261 cyg_thread_entry *entry_point; /* main entry point (code pointer!) */ \
262 CYG_ADDRWORD entry_data; /* entry point argument */ \
263 CYG_HARDWARETHREAD_SAVED_CONTEXT_MEMBER
267 CYG_HARDWARETHREAD_MEMBERS
268 } cyg_hardwarethread;
270 /*---------------------------------------------------------------------------*/
271 /* Scheduler Thread structure */
273 #ifdef CYGPKG_KERNEL_SMP_SUPPORT
274 # define CYG_SCHEDTHREAD_CPU_MEMBER \
275 cyg_uint32 cpu; // CPU id of cpu currently running
277 # define CYG_SCHEDTHREAD_CPU_MEMBER
280 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE_ENABLE
281 # define CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER \
282 cyg_bool timeslice_enabled; /* per-thread timeslice enable */
284 # define CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER
287 #if defined(CYGSEM_KERNEL_SCHED_BITMAP)
288 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS \
289 cyg_priority_t priority; /* current thread priority */
290 #elif defined(CYGSEM_KERNEL_SCHED_MLQUEUE)
291 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS \
294 cyg_priority_t priority; /* current thread priority */ \
295 CYG_SCHEDTHREAD_CPU_MEMBER \
296 CYG_SCHEDTHREAD_TIMESLICE_ENABLED_MEMBER
297 #elif defined(CYGSEM_KERNEL_SCHED_LOTTERY)
298 # define CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS \
301 cyg_priority_t priority; /* current thread priority */ \
302 cyg_priority_t compensation_tickets; /* sleep compensation */
304 # error Undefined scheduler type
307 #ifndef CYGSEM_KERNEL_SCHED_ASR_GLOBAL
308 # define CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER \
309 void (*asr)(CYG_ADDRWORD); // ASR function
311 # define CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER
314 #ifndef CYGSEM_KERNEL_SCHED_ASR_DATA_GLOBAL
315 # define CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER \
316 CYG_ADDRWORD asr_data; // ASR data pointer
318 # define CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER
321 #ifdef CYGSEM_KERNEL_SCHED_ASR_SUPPORT
322 # define CYG_SCHEDTHREAD_ASR_MEMBER \
323 volatile cyg_ucount32 asr_inhibit; /* If true, blocks calls to ASRs */ \
324 volatile cyg_bool asr_pending; /* If true, this thread's ASR */ \
325 /* should be called. */ \
326 CYG_SCHEDTHREAD_ASR_NONGLOBAL_MEMBER \
327 CYG_SCHEDTHREAD_ASR_DATA_NONGLOBAL_MEMBER
329 # define CYG_SCHEDTHREAD_ASR_MEMBER
332 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE
333 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS \
334 cyg_priority_t original_priority; \
335 cyg_bool priority_inherited;
337 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS
340 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL
341 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS \
342 cyg_count32 mutex_count; \
343 CYG_SCHEDTHREAD_MUTEX_INV_PROTO_SIMPLE_MEMBERS
345 # define CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS
348 #define CYG_SCHEDTHREAD_MEMBERS \
349 CYG_SCHEDTHREAD_SCHEDIMP_MEMBERS \
350 cyg_threadqueue *queue; \
351 CYG_SCHEDTHREAD_ASR_MEMBER \
352 CYG_SCHEDTHREAD_MUTEX_INV_PROTO_MEMBERS
357 CYG_SCHEDTHREAD_MEMBERS
360 /* This compiler version test is required because the C++ ABI changed in
361 GCC v3.x and GCC could now reuse "spare" space from base classes in derived
362 classes, and in C++ land, cyg_alarm is a base class of cyg_threadtimer.
364 #if defined(__GNUC__) && (__GNUC__ < 3)
365 #define CYG_THREADTIMER_MEMBERS \
369 #define CYG_THREADTIMER_MEMBERS \
374 /*---------------------------------------------------------------------------*/
375 /* Thread structure */
379 CYG_THREADTIMER_MEMBERS
395 #if defined(CYGPKG_KERNEL_EXCEPTIONS) && !defined(CYGSEM_KERNEL_EXCEPTIONS_GLOBAL)
396 # define CYG_THREAD_EXCEPTION_CONTROL_MEMBER \
397 cyg_exception_control exception_control;
399 # define CYG_THREAD_EXCEPTION_CONTROL_MEMBER
402 #ifdef CYGFUN_KERNEL_THREADS_TIMER
403 # define CYG_THREAD_TIMER_MEMBER \
404 cyg_threadtimer timer;
406 # define CYG_THREAD_TIMER_MEMBER
409 #ifdef CYGVAR_KERNEL_THREADS_DATA
410 # define CYG_THREAD_THREAD_DATA_MEMBER \
411 CYG_ADDRWORD thread_data[CYGNUM_KERNEL_THREADS_DATA_MAX];
413 # define CYG_THREAD_THREAD_DATA_MEMBER
416 #ifdef CYGVAR_KERNEL_THREADS_NAME
417 # define CYG_THREAD_NAME_MEMBER \
420 # define CYG_THREAD_NAME_MEMBER
423 #ifdef CYGVAR_KERNEL_THREADS_LIST
424 # define CYG_THREAD_LIST_NEXT_MEMBER \
425 cyg_thread *list_next;
427 # define CYG_THREAD_LIST_NEXT_MEMBER
432 #ifdef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
433 struct Cyg_Destructor_Entry {
434 cyg_thread_destructor_fn fn;
437 # define CYG_THREAD_DESTRUCTORS_MEMBER \
438 struct Cyg_Destructor_Entry destructors[ CYGNUM_KERNEL_THREADS_DESTRUCTORS ];
440 # define CYG_THREAD_DESTRUCTORS_MEMBER
444 #define CYG_THREAD_MEMBERS \
445 CYG_HARDWARETHREAD_MEMBERS \
446 CYG_SCHEDTHREAD_MEMBERS \
449 cyg_ucount32 suspend_count; \
450 cyg_ucount32 wakeup_count; \
451 CYG_ADDRWORD wait_info; \
452 cyg_uint16 unique_id; \
454 CYG_THREAD_EXCEPTION_CONTROL_MEMBER \
455 CYG_THREAD_TIMER_MEMBER \
457 cyg_reason_t sleep_reason; \
458 cyg_reason_t wake_reason; \
460 CYG_THREAD_THREAD_DATA_MEMBER \
461 CYG_THREAD_DESTRUCTORS_MEMBER \
462 CYG_THREAD_NAME_MEMBER \
463 CYG_THREAD_LIST_NEXT_MEMBER
471 /*---------------------------------------------------------------------------*/
475 cyg_count32 base; /* index of first used slot */
476 cyg_count32 count; /* count of used slots */
477 cyg_threadqueue get_threadq; /* Queue of waiting threads */
478 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
479 cyg_threadqueue put_threadq; /* Queue of waiting threads */
481 void * itemqueue[ CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE ];
484 /*---------------------------------------------------------------------------*/
488 cyg_count32 count; /* The semaphore count */
489 cyg_threadqueue queue; /* Queue of waiting threads */
492 /*---------------------------------------------------------------------------*/
496 cyg_flag_value_t value; /* The flag value */
497 cyg_threadqueue queue; /* Queue of waiting threads */
500 /*---------------------------------------------------------------------------*/
504 CYG_MUTEX_PROTOCOL_NONE,
505 CYG_MUTEX_PROTOCOL_INHERIT,
506 CYG_MUTEX_PROTOCOL_CEILING
507 } cyg_mutex_protocol_t;
511 cyg_atomic locked; /* true if locked */
512 cyg_thread *owner; /* Current locking thread */
513 cyg_threadqueue queue; /* Queue of waiting threads */
515 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC
516 cyg_mutex_protocol_t protocol; /* this mutex's protocol */
518 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_CEILING
519 cyg_priority_t ceiling; /* mutex priority ceiling */
524 /*---------------------------------------------------------------------------*/
528 cyg_mutex_t *mutex; /* Associated mutex */
529 cyg_threadqueue queue; /* Queue of waiting threads */
532 /*------------------------------------------------------------------------*/
534 struct cyg_spinlock_t
536 cyg_uint32 lock; /* lock word */
539 /*------------------------------------------------------------------------*/
541 /* Memory allocator types now come from the "memalloc" package which is */
542 /* where the implementation lives. */
544 #ifdef CYGPKG_MEMALLOC
545 # include <cyg/memalloc/kapidata.h>
552 /*---------------------------------------------------------------------------*/
554 #endif /* CYGONCE_KERNEL_KAPIDATA_H */