comparison src/nucleus/tcf.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /*************************************************************************/
2 /* */
3 /* Copyright Mentor Graphics Corporation 2002 */
4 /* All Rights Reserved. */
5 /* */
6 /* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
7 /* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
8 /* SUBJECT TO LICENSE TERMS. */
9 /* */
10 /*************************************************************************/
11
12 /*************************************************************************/
13 /* */
14 /* FILE NAME VERSION */
15 /* */
16 /* tcf.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* TC - Thread Control */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains information (fact) routines for the Thread */
25 /* Control component. */
26 /* */
27 /* DATA STRUCTURES */
28 /* */
29 /* None */
30 /* */
31 /* FUNCTIONS */
32 /* */
33 /* TCF_Established_Tasks Number of created tasks */
34 /* TCF_Established_HISRs Number of created HISRs */
35 /* TCF_Task_Pointers Build list of task pointers */
36 /* TCF_HISR_Pointers Build list of HISR pointers */
37 /* TCF_Task_Information Retrieve task information */
38 /* TCF_HISR_Information Retrieve HISR information */
39 /* */
40 /* DEPENDENCIES */
41 /* */
42 /* cs_extr.h Common Service functions */
43 /* tc_extr.h Thread Control functions */
44 /* in_extr.h Initialization/Interrupt */
45 /* functions */
46 /* tm_extr.h Timer Control function */
47 /* er_extr.h Error handling function */
48 /* hi_extr.h History functions */
49 /* */
50 /* HISTORY */
51 /* */
52 /* DATE REMARKS */
53 /* */
54 /* 03-01-1994 Created initial version 1.1 from */
55 /* original 1.0g version of TCC.C */
56 /* */
57 /* 03-18-1994 Verified version 1.1 */
58 /* 04-17-1996 updated to version 1.2 */
59 /* 11-18-1996 Protected Informational service */
60 /* from NULL Control Block pointers */
61 /* creating 1.2a. (SPR220) */
62 /* 03-24-1998 Released version 1.3. */
63 /* 03-26-1999 Released 1.11m (new release */
64 /* numbering scheme) */
65 /* 04-17-2002 Released version 1.13m */
66 /* 11-07-2002 Released version 1.14 */
67 /*************************************************************************/
68 #define NU_SOURCE_FILE
69
70
71 #include "cs_extr.h" /* Common service functions */
72 #include "tc_extr.h" /* Thread control functions */
73 #include "in_extr.h" /* Initialization/Interrupt */
74 /* functions */
75 #include "tm_extr.h" /* Timer control functions */
76 #include "er_extr.h" /* Error handling function */
77 #include "hi_extr.h" /* History functions */
78
79
80 /* Define external inner-component global data references. */
81
82 extern CS_NODE *TCD_Created_Tasks_List;
83 extern UNSIGNED TCD_Total_Tasks;
84 extern TC_TCB *TCD_Priority_List[TC_PRIORITIES];
85 extern UNSIGNED TCD_Priority_Groups;
86 extern DATA_ELEMENT TCD_Sub_Priority_Groups[TC_MAX_GROUPS];
87 extern UNSIGNED_CHAR TCD_Lowest_Set_Bit[];
88 extern INT TCD_Highest_Priority;
89 extern TC_TCB *TCD_Execute_Task;
90 extern VOID *TCD_Current_Thread;
91 extern UNSIGNED_CHAR TCD_Registered_LISRs[NU_MAX_VECTORS+1];
92 extern VOID (*TCD_LISR_Pointers[NU_MAX_LISRS+1])(INT vector);
93 extern INT TCD_Interrupt_Count;
94 extern INT TCD_Stack_Switched;
95 extern TC_PROTECT TCD_List_Protect;
96 extern TC_PROTECT TCD_Schedule_Protect;
97 extern TC_PROTECT TCD_LISR_Protect;
98 extern CS_NODE *TCD_Created_HISRs_List;
99 extern UNSIGNED TCD_Total_HISRs;
100 extern TC_PROTECT TCD_HISR_Protect;
101 extern INT TCD_Unhandled_Interrupt;
102
103
104 /* Define external inner-component function calls that are not available to
105 other components. */
106
107 VOID TCT_Build_Task_Stack(TC_TCB *task_ptr);
108 VOID TCT_Build_HISR_Stack(TC_HCB *hisr_ptr);
109 VOID TCT_Build_Signal_Frame(TC_TCB *task_ptr);
110 VOID TCT_Protect_Switch(TC_TCB *task);
111 VOID TCT_Signal_Exit(VOID);
112
113
114
115 /*************************************************************************/
116 /* */
117 /* FUNCTION */
118 /* */
119 /* TCF_Established_Tasks */
120 /* */
121 /* DESCRIPTION */
122 /* */
123 /* This function returns the current number of established tasks. */
124 /* Tasks previously deleted are no longer considered established. */
125 /* */
126 /* CALLED BY */
127 /* */
128 /* Application */
129 /* */
130 /* CALLS */
131 /* */
132 /* [TCT_Check_Stack] Stack checking function */
133 /* */
134 /* INPUTS */
135 /* */
136 /* None */
137 /* */
138 /* OUTPUTS */
139 /* */
140 /* TCD_Total_Tasks Number of established tasks */
141 /* */
142 /* HISTORY */
143 /* */
144 /* DATE REMARKS */
145 /* */
146 /* 03-01-1993 Created initial version 1.0 */
147 /* 04-19-1993 Verified version 1.0 */
148 /* */
149 /*************************************************************************/
150 UNSIGNED TCF_Established_Tasks(VOID)
151 {
152
153
154 #ifdef NU_ENABLE_STACK_CHECK
155
156 /* Call stack checking function to check for an overflow condition. */
157 TCT_Check_Stack();
158
159 #endif
160
161 /* Return the number of established tasks. */
162 return(TCD_Total_Tasks);
163 }
164
165
166 /*************************************************************************/
167 /* */
168 /* FUNCTION */
169 /* */
170 /* TCF_Established_HISRs */
171 /* */
172 /* DESCRIPTION */
173 /* */
174 /* This function returns the current number of established HISRs. */
175 /* HISRs previously deleted are no longer considered established. */
176 /* */
177 /* CALLED BY */
178 /* */
179 /* Application */
180 /* */
181 /* CALLS */
182 /* */
183 /* [TCT_Check_Stack] Stack checking function */
184 /* */
185 /* INPUTS */
186 /* */
187 /* None */
188 /* */
189 /* OUTPUTS */
190 /* */
191 /* TCD_Total_HISRs Number of established HISRs */
192 /* */
193 /* HISTORY */
194 /* */
195 /* DATE REMARKS */
196 /* */
197 /* 03-01-1993 Created initial version 1.0 */
198 /* 04-19-1993 Verified version 1.0 */
199 /* */
200 /*************************************************************************/
201 UNSIGNED TCF_Established_HISRs(VOID)
202 {
203
204
205 #ifdef NU_ENABLE_STACK_CHECK
206
207 /* Call stack checking function to check for an overflow condition. */
208 TCT_Check_Stack();
209
210 #endif
211
212 /* Return the number of established HISRs. */
213 return(TCD_Total_HISRs);
214 }
215
216
217 /*************************************************************************/
218 /* */
219 /* FUNCTION */
220 /* */
221 /* TCF_Task_Pointers */
222 /* */
223 /* DESCRIPTION */
224 /* */
225 /* This function builds a list of task pointers, starting at the */
226 /* specified location. The number of task pointers placed in the */
227 /* list is equivalent to the total number of tasks or the maximum */
228 /* number of pointers specified in the call. */
229 /* */
230 /* CALLED BY */
231 /* */
232 /* Application */
233 /* */
234 /* CALLS */
235 /* */
236 /* [TCT_Check_Stack] Stack checking function */
237 /* TCT_System_Protect Protect task created list */
238 /* TCT_Unprotect Release protection of list */
239 /* */
240 /* INPUTS */
241 /* */
242 /* pointer_list Pointer to the list area */
243 /* maximum_pointers Maximum number of pointers */
244 /* */
245 /* OUTPUTS */
246 /* */
247 /* pointers Number of tasks placed in */
248 /* list */
249 /* HISTORY */
250 /* */
251 /* DATE REMARKS */
252 /* */
253 /* 03-01-1993 Created initial version 1.0 */
254 /* 04-19-1993 Verified version 1.0 */
255 /* 08-09-1993 Corrected pointer retrieval */
256 /* loop, resulting in version 1.0c */
257 /* 08-09-1993 Verified version 1.0c */
258 /* 03-01-1994 Modified function interface, */
259 /* resulting in version 1.1 */
260 /* */
261 /* 03-18-1994 Verified version 1.1 */
262 /* */
263 /*************************************************************************/
264 UNSIGNED TCF_Task_Pointers(NU_TASK **pointer_list, UNSIGNED maximum_pointers)
265 {
266
267 CS_NODE *node_ptr; /* Pointer to each TCB */
268 UNSIGNED pointers; /* Number of pointers in list*/
269 NU_SUPERV_USER_VARIABLES
270
271 /* Switch to supervisor mode */
272 NU_SUPERVISOR_MODE();
273
274 #ifdef NU_ENABLE_STACK_CHECK
275
276 /* Call stack checking function to check for an overflow condition. */
277 TCT_Check_Stack();
278
279 #endif
280
281 /* Initialize the number of pointers returned. */
282 pointers = 0;
283
284 /* Protect the task created list. */
285 TCT_Protect(&TCD_List_Protect);
286
287 /* Loop until all task pointers are in the list or until the maximum
288 list size is reached. */
289 node_ptr = TCD_Created_Tasks_List;
290 while ((node_ptr) && (pointers < maximum_pointers))
291 {
292
293 /* Place the node into the destination list. */
294 *pointer_list++ = (NU_TASK *) node_ptr;
295
296 /* Increment the pointers variable. */
297 pointers++;
298
299 /* Position the node pointer to the next node. */
300 node_ptr = node_ptr -> cs_next;
301
302 /* Determine if the pointer is at the head of the list. */
303 if (node_ptr == TCD_Created_Tasks_List)
304
305 /* The list search is complete. */
306 node_ptr = NU_NULL;
307 }
308
309 /* Release protection. */
310 TCT_Unprotect();
311
312 /* Return to user mode */
313 NU_USER_MODE();
314
315 /* Return the number of pointers in the list. */
316 return(pointers);
317 }
318
319
320 /*************************************************************************/
321 /* */
322 /* FUNCTION */
323 /* */
324 /* TCF_HISR_Pointers */
325 /* */
326 /* DESCRIPTION */
327 /* */
328 /* This function builds a list of HISR pointers, starting at the */
329 /* specified location. The number of HISR pointers placed in the */
330 /* list is equivalent to the total number of HISRs or the maximum */
331 /* number of pointers specified in the call. */
332 /* */
333 /* CALLED BY */
334 /* */
335 /* Application */
336 /* */
337 /* CALLS */
338 /* */
339 /* [TCT_Check_Stack] Stack checking function */
340 /* TCT_Protect Protect HISR created list */
341 /* TCT_Unprotect Release protection of list */
342 /* */
343 /* INPUTS */
344 /* */
345 /* pointer_list Pointer to the list area */
346 /* maximum_pointers Maximum number of pointers */
347 /* */
348 /* OUTPUTS */
349 /* */
350 /* Number of HISRs placed in */
351 /* list */
352 /* HISTORY */
353 /* */
354 /* DATE REMARKS */
355 /* */
356 /* 03-01-1993 Created initial version 1.0 */
357 /* 04-19-1993 Verified version 1.0 */
358 /* 08-09-1993 Corrected pointer retrieval */
359 /* loop, resulting in version 1.0c */
360 /* 08-09-1993 Verified version 1.0c */
361 /* 03-01-1994 Modified function interface, */
362 /* resulting in version 1.1 */
363 /* */
364 /* 03-18-1994 Verified version 1.1 */
365 /* */
366 /*************************************************************************/
367 UNSIGNED TCF_HISR_Pointers(NU_HISR **pointer_list, UNSIGNED maximum_pointers)
368 {
369
370 CS_NODE *node_ptr; /* Pointer to each TCB */
371 UNSIGNED pointers; /* Number of pointers in list*/
372 NU_SUPERV_USER_VARIABLES
373
374 /* Switch to supervisor mode */
375 NU_SUPERVISOR_MODE();
376
377 #ifdef NU_ENABLE_STACK_CHECK
378
379 /* Call stack checking function to check for an overflow condition. */
380 TCT_Check_Stack();
381
382 #endif
383
384 /* Initialize the number of pointers returned. */
385 pointers = 0;
386
387 /* Protect the HISR created list. */
388 TCT_Protect(&TCD_HISR_Protect);
389
390 /* Loop until all HISR pointers are in the list or until the maximum
391 list size is reached. */
392 node_ptr = TCD_Created_HISRs_List;
393 while ((node_ptr) && (pointers < maximum_pointers))
394 {
395
396 /* Place the node into the destination list. */
397 *pointer_list++ = (NU_HISR *) node_ptr;
398
399 /* Increment the pointers variable. */
400 pointers++;
401
402 /* Position the node pointer to the next node. */
403 node_ptr = node_ptr -> cs_next;
404
405 /* Determine if the pointer is at the head of the list. */
406 if (node_ptr == TCD_Created_HISRs_List)
407
408 /* The list search is complete. */
409 node_ptr = NU_NULL;
410 }
411
412 /* Release protection. */
413 TCT_Unprotect();
414
415 /* Return to user mode */
416 NU_USER_MODE();
417
418 /* Return the number of pointers in the list. */
419 return(pointers);
420 }
421
422
423 /*************************************************************************/
424 /* */
425 /* FUNCTION */
426 /* */
427 /* TCF_Task_Information */
428 /* */
429 /* DESCRIPTION */
430 /* */
431 /* This function returns information about the specified task. */
432 /* However, if the supplied task pointer is invalid, the function */
433 /* simply returns an error status. */
434 /* */
435 /* CALLED BY */
436 /* */
437 /* Application */
438 /* */
439 /* CALLS */
440 /* */
441 /* [TCT_Check_Stack] Stack checking function */
442 /* TCT_System_Protect Protect scheduling info */
443 /* TCT_Unprotect Release protection */
444 /* */
445 /* INPUTS */
446 /* */
447 /* task_ptr Pointer to the task */
448 /* name Destination for the name */
449 /* status Destination for task status */
450 /* scheduled_count Destination for scheduled */
451 /* count of the task */
452 /* priority Destination for task priority*/
453 /* preempt Destination for preempt flag */
454 /* time_slice Destination for time slice */
455 /* stack_base Destination for pointer to */
456 /* base of task's stack */
457 /* stack_size Destination for stack size */
458 /* minimum_stack Destination for the minimum */
459 /* running size of the stack */
460 /* */
461 /* OUTPUTS */
462 /* */
463 /* NU_SUCCESS If a valid task pointer is */
464 /* supplied */
465 /* NU_INVALID_TASK If task pointer is invalid */
466 /* */
467 /* HISTORY */
468 /* */
469 /* DATE REMARKS */
470 /* */
471 /* 03-01-1993 Created initial version 1.0 */
472 /* 04-19-1993 Verified version 1.0 */
473 /* 03-01-1994 Modified function interface, */
474 /* added register optimizations, */
475 /* changed protection logic, */
476 /* resulting in version 1.1 */
477 /* */
478 /* 03-18-1994 Verified version 1.1 */
479 /* 11-18-1996 Corrected SPR220. */
480 /* */
481 /*************************************************************************/
482 STATUS TCF_Task_Information(NU_TASK *task_ptr, CHAR *name,
483 DATA_ELEMENT *status, UNSIGNED *scheduled_count,
484 DATA_ELEMENT *priority, OPTION *preempt, UNSIGNED *time_slice,
485 VOID **stack_base, UNSIGNED *stack_size, UNSIGNED *minimum_stack)
486 {
487
488 R1 TC_TCB *task; /* Task control block ptr */
489 INT i; /* Working index */
490 STATUS completion; /* Completion status */
491 NU_SUPERV_USER_VARIABLES
492
493 /* Switch to supervisor mode */
494 NU_SUPERVISOR_MODE();
495
496 /* Move task control block pointer into internal pointer. */
497 task = (TC_TCB *) task_ptr;
498
499
500 #ifdef NU_ENABLE_STACK_CHECK
501
502 /* Call stack checking function to check for an overflow condition. */
503 TCT_Check_Stack();
504
505 #endif
506
507 /* Determine if this task is valid. */
508 if ((task != NU_NULL) && (task -> tc_id == TC_TASK_ID))
509 {
510
511 /* Protect against scheduling changes. */
512 TCT_System_Protect();
513
514 /* The task pointer is successful. Reflect this in the completion
515 status and fill in the actual information. */
516 completion = NU_SUCCESS;
517
518 /* Copy the task's name. */
519 for (i = 0; i < NU_MAX_NAME; i++)
520 *name++ = task -> tc_name[i];
521
522 /* Determine the preemption posture. */
523 if (task -> tc_preemption)
524 *preempt = NU_PREEMPT;
525 else
526 *preempt = NU_NO_PREEMPT;
527
528 /* Setup the remaining fields. */
529 *status = task -> tc_status;
530 *scheduled_count = task -> tc_scheduled;
531 *priority = task -> tc_priority;
532 *time_slice = task -> tc_time_slice;
533 *stack_base = task -> tc_stack_start;
534 *stack_size = task -> tc_stack_size;
535 *minimum_stack = task -> tc_stack_minimum;
536
537 /* Release protection. */
538 TCT_Unprotect();
539 }
540 else
541
542 /* Indicate that the task pointer is invalid. */
543 completion = NU_INVALID_TASK;
544
545 /* Return to user mode */
546 NU_USER_MODE();
547
548 /* Return the appropriate completion status. */
549 return(completion);
550 }
551
552
553 /*************************************************************************/
554 /* */
555 /* FUNCTION */
556 /* */
557 /* TCF_HISR_Information */
558 /* */
559 /* DESCRIPTION */
560 /* */
561 /* This function returns information about the specified HISR. */
562 /* However, if the supplied HISR pointer is invalid, the function */
563 /* simply returns an error status. */
564 /* */
565 /* CALLED BY */
566 /* */
567 /* Application */
568 /* */
569 /* CALLS */
570 /* */
571 /* [TCT_Check_Stack] Stack checking function */
572 /* TCT_System_Protect Protect scheduling info */
573 /* TCT_Unprotect Release protection */
574 /* */
575 /* INPUTS */
576 /* */
577 /* hisr_ptr Pointer to the hisr */
578 /* name Destination for the name */
579 /* scheduled_count Destination for scheduled */
580 /* count of the HISR */
581 /* priority Destination for HISR priority*/
582 /* stack_base Destination for pointer to */
583 /* base of HISR's stack */
584 /* stack_size Destination for stack size */
585 /* minimum_stack Destination for the minimum */
586 /* running size of the stack */
587 /* */
588 /* OUTPUTS */
589 /* */
590 /* NU_SUCCESS If a valid HISR pointer is */
591 /* supplied */
592 /* NU_INVALID_HISR If HISR pointer is invalid */
593 /* */
594 /* HISTORY */
595 /* */
596 /* DATE REMARKS */
597 /* */
598 /* 03-01-1993 Created initial version 1.0 */
599 /* 04-19-1993 Verified version 1.0 */
600 /* 03-01-1994 Modified function interface, */
601 /* added register optimizations, */
602 /* changed protection logic, */
603 /* resulting in version 1.1 */
604 /* */
605 /* 03-18-1994 Verified version 1.1 */
606 /* 11-18-1996 Corrected SPR220. */
607 /* */
608 /*************************************************************************/
609 STATUS TCF_HISR_Information(NU_HISR *hisr_ptr, CHAR *name,
610 UNSIGNED *scheduled_count, DATA_ELEMENT *priority,
611 VOID **stack_base, UNSIGNED *stack_size, UNSIGNED *minimum_stack)
612 {
613
614 R1 TC_HCB *hisr; /* HISR control block ptr */
615 INT i; /* Working index */
616 STATUS completion; /* Completion status */
617 NU_SUPERV_USER_VARIABLES
618
619 /* Switch to supervisor mode */
620 NU_SUPERVISOR_MODE();
621
622 /* Move input HISR control block pointer into internal pointer. */
623 hisr = (TC_HCB *) hisr_ptr;
624
625
626 #ifdef NU_ENABLE_STACK_CHECK
627
628 /* Call stack checking function to check for an overflow condition. */
629 TCT_Check_Stack();
630
631 #endif
632
633 /* Determine if this HISR is valid. */
634 if ((hisr != NU_NULL) && (hisr -> tc_id == TC_HISR_ID))
635 {
636
637 /* Protect against scheduling changes. */
638 TCT_System_Protect();
639
640 /* The HISR pointer is successful. Reflect this in the completion
641 status and fill in the actual information. */
642 completion = NU_SUCCESS;
643
644 /* Copy the hisr's name. */
645 for (i = 0; i < NU_MAX_NAME; i++)
646 *name++ = hisr -> tc_name[i];
647
648 /* Setup the remaining fields. */
649 *scheduled_count = hisr -> tc_scheduled;
650 *priority = hisr -> tc_priority;
651 *stack_base = hisr -> tc_stack_start;
652 *stack_size = hisr -> tc_stack_size;
653 *minimum_stack = hisr -> tc_stack_minimum;
654
655 /* Release protection. */
656 TCT_Unprotect();
657 }
658 else
659
660 /* Indicate that the HISR pointer is invalid. */
661 completion = NU_INVALID_HISR;
662
663 /* Return to user mode */
664 NU_USER_MODE();
665
666 /* Return the appropriate completion status. */
667 return(completion);
668 }
669
670
671
672