summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils/gdb/osf-share/cma_tcb_defs.h
blob: 6622050cf73e24b96d58422341910dd0b635b1bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* 
 * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC.
 * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY
 * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION
 * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems
 * To anyone who acknowledges that this file is provided "AS IS" without
 * any express or implied warranty: permission to use, copy, modify, and
 * distribute this file for any purpose is hereby granted without fee,
 * provided that the above copyright notices and this notice appears in
 * all source code copies, and that none of the names listed above be used
 * in advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  None of these organizations
 * makes any representations about the suitability of this software for
 * any purpose.
 */
/*
 *	TCB-related type definitions.
 */

#ifndef CMA_TCB_DEFS
#define CMA_TCB_DEFS

/*
 *  INCLUDE FILES
 */
# if !_CMA_THREAD_SYNC_IO_
#  include <cma_thread_io.h>
# endif
#include <cma.h>
#include <cma_debug_client.h>
#include <cma_attr.h>
#include <cma_defs.h>
#include <cma_handle.h>
#include <cma_queue.h>
#if _CMA_OS_ == _CMA__UNIX
# if defined(SNI_DCOSX)
#   include <sys/ucontext.h>
# endif
# include <signal.h>
#endif
#include <cma_sched.h>

/*
 * CONSTANTS AND MACROS
 */

#if _CMA_PLATFORM_ == _CMA__IBMR2_UNIX
# define cma__c_ibmr2_ctx_stack_size	2048
# define cma__c_ibmr2_ctx_stack_top	(cma__c_ibmr2_ctx_stack_size - 1)
#endif

/*
 * TYPEDEFS
 */

#ifndef __STDC__
# if _CMA_HARDWARE_ != _CMA__HPPA
struct CMA__T_SEMAPHORE;
# endif
struct CMA__T_INT_CV;
struct CMA__T_INT_MUTEX;
struct CMA__T_INT_TCB;
#endif

typedef cma_t_address		*cma__t_context_list;

typedef struct CMA__T_TCB_PAD {
    /* 
     * Adjust to align the tcb prolog at byte 32.
     * 12 bytes are required as object header is currently 
     * 20 bytes long.
     */
    cma_t_integer	pad1;		/* pad bytes */
    cma_t_integer	pad2;		/* pad bytes */
    cma_t_integer	pad3;		/* pad bytes */
    } cma__t_tcb_pad;

#if (_CMA_OS_ == _CMA__UNIX) && !_CMA_THREAD_SYNC_IO_
typedef struct CMA__T_TCB_SELECT {
    cma__t_queue	queue;
#if (_CMA_UNIX_TYPE !=  _CMA__SVR4)
	cma__t_file_mask    *rfds;
	cma__t_file_mask    *wfds;
	cma__t_file_mask    *efds;
#else
	cma__t_poll_info 	poll_info;
#endif /* (_CMA_UNIX_TYPE !=  _CMA__SVR4) */
    cma_t_integer	nfound;
    } cma__t_tcb_select;
#endif

typedef struct CMA__T_TCB_TIME {
    cma__t_queue	queue;		/* must be first entry! */
    cma_t_integer	mode;
    struct CMA__T_SEMAPHORE *semaphore;	/* used for timed semaphores */
    cma_t_date_time	wakeup_time;
    cma_t_integer	quanta_remaining;
    } cma__t_tcb_time;

typedef enum CMA__T_DEBEVT {
	cma__c_debevt_activating = 1,	/* First transition to running */
	cma__c_debevt_running = 2,	/* Any transition to running */
	cma__c_debevt_preempting = 3,	/* Preemted (replaced) another thread */
	cma__c_debevt_blocking = 4,	/* Any transition to blocked */
	cma__c_debevt_terminating = 5,	/* Final state transition */
	cma__c_debevt_term_alert = 6,	/* Terminated due to alert/cancel */
	cma__c_debevt_term_exc = 7,	/* Terminated due to exception */
	cma__c_debevt_exc_handled = 8	/* Exception is being handled */
	} cma__t_debevt;

#define cma__c_debevt__first ((cma_t_integer)cma__c_debevt_activating)
#define cma__c_debevt__last  ((cma_t_integer)cma__c_debevt_exc_handled)
#define cma__c_debevt__dim (cma__c_debevt__last + 1)

/* 
 * Type defining thread substate, which is used by the debugger.
 * If the state is blocked, substate indicates WHY the thread is blocked.
 */
typedef enum CMA__T_SUBSTATE {
    cma__c_substa_normal = 0,
    cma__c_substa_mutex = 1,
    cma__c_substa_cv = 2,
    cma__c_substa_timed_cv = 3,
    cma__c_substa_term_alt = 4,
    cma__c_substa_term_exc = 5,
    cma__c_substa_delay =6,
    cma__c_substa_not_yet_run = 7
    } cma__t_substate;
#define cma__c_substa__first ((cma_t_integer)cma__c_substa_normal)
#define cma__c_substa__last  ((cma_t_integer)cma__c_substa_not_yet_run)
#define cma__c_substa__dim (cma__c_substa__last + 1)


/*
 * Per-thread state for the debugger
 */
typedef struct CMA__T_TCB_DEBUG {
    cma_t_boolean	on_hold;	/* Thread was put on hold by debugger */
    cma_t_boolean	activated;	/* Activation event was reported */
    cma_t_boolean	did_preempt;	/* Thread preempted prior one */
    cma_t_address	start_pc;	/* Start routine address */
    cma_t_address	object_addr;	/* Addr of thread object */
    cma__t_substate	substate;	/* Reason blocked, terminated, etc.*/
    cma_t_boolean	notify_debugger;/* Notify debugger thread is running */
    cma_t_address	SPARE2;		/* SPARE */
    cma_t_address	SPARE3;		/* SPARE */
    struct CMA__T_INT_TCB	
			*preempted_tcb;	/* TCB of thread that got preempted */
    cma_t_boolean	flags[cma__c_debevt__dim]; 	
					/* Events enabled for this thread */
    } cma__t_tcb_debug;

typedef struct CMA__T_TCB_SCHED {
    cma_t_integer	adj_time;	/* Abs. time in ticks of last prio adj */
    cma_t_integer	tot_time;	/* Weighted ave in ticks (scaled) */
    cma_t_integer	time_stamp;	/* Abs. time in ticks of last update */
    cma_t_integer	cpu_time;	/* Weighted average in ticks */
    cma_t_integer	cpu_ticks;	/* # of ticks while comp. (scaled) */
    cma_t_integer	q_num;		/* Number of last ready queue on */
    cma_t_priority	priority;	/* Thread priority */
    cma_t_sched_policy  policy;         /* Scheduling policy of thread */
    cma_t_boolean	rtb;		/* "Run 'Till Block" scheduling */
    cma_t_boolean	spp;		/* "Strict Priority Preemption" sched */
    cma_t_boolean	fixed_prio;	/* Fixed priority */
    cma__t_sched_class	class;		/* Scheduling class */
    struct CMA__T_VP	*processor;	/* Current processor (if running) */
    } cma__t_tcb_sched;

typedef struct CMA__T_INT_ALERT {
    cma_t_boolean	pending : 1;	/* alert_pending bit */
    cma_t_boolean	g_enable : 1;	/* general delivery state */
    cma_t_boolean	a_enable : 1;	/* asynchronous delivery state */
    cma_t_integer	spare : 29;	/* Pad to longword */
    cma_t_natural	count;		/* Alert scope nesting count */
    } cma__t_int_alert;

typedef enum CMA__T_STATE {
    cma__c_state_running = 0,		/* For consistency with initial TCB */
    cma__c_state_ready	= 1,
    cma__c_state_blocked = 2,
    cma__c_state_terminated = 3
    } cma__t_state;
#define cma__c_state__first ((cma_t_integer)cma__c_state_running)
#define cma__c_state__last  ((cma_t_integer)cma__c_state_terminated)
#define cma__c_state__dim (cma__c_state__last + 1)

typedef enum CMA__T_THKIND {
    cma__c_thkind_initial = 0,		/* Initial thread */
    cma__c_thkind_normal = 1,		/* Normal thread */
    cma__c_thkind_null	= 2		/* A null thread */
    } cma__t_thkind;
#define cma__c_thkind__first ((cma_t_integer)cma__c_thkind_initial)
#define cma__c_thkind__last  ((cma_t_integer)cma__c_thkind_null)
#define cma__c_thkind__dim (cma__c_thkind__last + 1)

typedef enum CMA__T_SYSCALL_STATE {
	cma__c_syscall_ok = 1,                      /* syscall was not interrupted */
	cma__c_syscall_intintrpt = 1,       /* syscall was interrupted by VTALRM */
	cma__c_syscall_extintrpt = 2        /* syscall was interrupted by external signal */
	} cma__t_syscall_state;


typedef struct CMA__T_INT_TCB {
    /* 
     * Fixed part of TCB.
     *   Modifications to the following three fields must be coordinated.  
     *   The object header must always be first, and the prolog must always 
     *   remain at the same offset (32) for all time. Thus the object header
     *   must never grow beyond a maximum of 32 bytes.
     */
    cma__t_object	header;		/* Common object header */
    cma__t_tcb_pad	pad1;		/* Pad required to align prolog */
    cma_t_tcb_prolog	prolog;		/* Standard prolog for tasks, threads */

    /* 
     * Floating part of TCB (fields here on are free to be moved and resized).
     */
    cma__t_queue	threads;	/* List of all known threads */
    cma__t_int_attr	*attributes;	/* Backpointer to attr obj */
    cma__t_state	state;		/* Current state of thread */
    cma__t_thkind	kind;		/* Which kind of thread */
    struct CMA__T_INT_MUTEX 
			*mutex;		/* Mutex to control TCB access */
    struct CMA__T_INT_CV 
			*term_cv;	/* CV for join */
    struct CMA__T_INT_MUTEX 
			*tswait_mutex;	/* Mutex for thread-synchronous waits */
    struct CMA__T_INT_CV 
			*tswait_cv;	/* CV for thread-synchronous waits */
    cma_t_start_routine	start_code;	/* Address of start routine */
    cma_t_address	start_arg;	/* Argument to pass to start_code */
    cma__t_queue	stack;		/* Queue header for stack descr. */
    cma_t_natural	context_count;	/* Size of context array */
    cma__t_context_list	contexts;	/* Context value array pointer */
    cma_t_exit_status	exit_status;	/* Exit status of thread */
    cma_t_address	return_value;	/* Thread's return value */
    cma__t_async_ctx	async_ctx;	/* Asynchronous context switch info */
    cma__t_static_ctx	static_ctx;	/* Static context switch information */
    cma_t_integer	event_status;	/* Status of semaphore operation */
    cma__t_tcb_time	timer;		/* Time info for dispatcher */
    cma__t_tcb_sched	sched;		/* Scheduler info */
    cma__t_tcb_debug	debug;		/* Debugger info */
#if _CMA_OS_ == _CMA__UNIX
# if !_CMA_THREAD_SYNC_IO_
    cma__t_tcb_select	select;		/* Select info for timed selects */
# endif
    struct sigaction	sigaction_data[NSIG];
#endif
    cma_t_natural       syscall_state; /* set if one of the cma wrapped syscalls was interrupted. */
    cma_t_boolean	detached;	/* Set if already detached */
    cma_t_boolean	terminated;	/* Set if terminated */
    cma_t_integer	joiners;	/* Count of joiners, for zombie frees */
    cma__t_int_alert	alert;		/* Current alert state info */
    struct CMA__T_INT_CV 
			*wait_cv;	/* CV thread is currently waiting on */
    struct CMA__T_INT_MUTEX 
			*wait_mutex;	/* Mutex thread is waiting on */
    struct EXC_CONTEXT_T
			*exc_stack;	/* Top of exception stack */
#if _CMA_PLATFORM_ == _CMA__IBMR2_UNIX
    char		ctx_stack[cma__c_ibmr2_ctx_stack_size];
#endif
    cma_t_integer	thd_errno;	/* Per-thread errno value */
#if _CMA_OS_ == _CMA__VMS
    cma_t_integer	thd_vmserrno;	/* Per-thread VMS errno value */
#endif
    } cma__t_int_tcb;

#endif