comparison src/cs/services/cst/cst_stack.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 * CST_STACK.C
4 *
5 * Tasks and HISRs stacks monitoring.
6 *
7 * (C) Texas Instruments 2000
8 *
9 ******************************************************************************/
10
11 #include <stdio.h>
12 #include <string.h>
13
14 #include "nucleus.h"
15 #include "cs_defs.h"
16 #include "tc_defs.h"
17
18 // The following stack sizes are defined in int.s
19 #define IRQ_STACK_SIZE 128 // Number of bytes in IRQ stack
20 #define FIQ_STACK_SIZE 512 // Number of bytes in FIQ stack.
21 #define SYSTEM_SIZE 1024 // Define the system stack size
22
23 int vsi_o_trace (char * caller, unsigned long tclass, char * text);
24 int vsi_t_sleep (char * caller, unsigned long tvalue);
25
26 void CST_stack_trace()
27 {
28 int jndex, count, char_count;
29 TC_TCB *head, *ptr;
30 extern CS_NODE *TCD_Created_Tasks_List;
31 extern CS_NODE *TCD_Created_HISRs_List;
32 unsigned untouched;
33 char *top_stack, *top, *bottom;
34 extern char *TCT_System_Limit;
35 char result[80];
36 char name[9];
37
38 vsi_o_trace("CST", 0x08, "Stack Info ...");
39 vsi_o_trace("CST", 0x08, " Name top bottom current untouched");
40 vsi_o_trace("CST", 0x08, "-------------------------------------------------");
41
42 for (jndex=0; jndex<2; jndex++)
43 {
44 // make use of TCB and HCB having same structure from beginning to past stack info
45 if (jndex == 0)
46 ptr = head = (TC_TCB *)TCD_Created_Tasks_List;
47 else {
48 ptr = head = (TC_TCB *)TCD_Created_HISRs_List;
49 vsi_o_trace("CST", 0x08, "-------------------------------------------------");
50 }
51
52 count = 0;
53 do
54 {
55 untouched = 0;
56 top_stack = (char *)ptr->tc_stack_start;
57 while (*top_stack == 0xFE && top_stack <= (char *)ptr->tc_stack_end)
58 {
59 untouched++;
60 top_stack++;
61 }
62
63 // Avoid to get a spurious character when tasks names are 8 characters long
64 memcpy (name, ptr->tc_name, 8);
65 name[8] = 0;
66
67 sprintf(result, "%8s: %08x %08x %08x 0x%x",
68 name,
69 ptr->tc_stack_start,
70 ptr->tc_stack_end,
71 ptr->tc_stack_pointer,
72 untouched);
73 vsi_o_trace("CST", 0x08, result);
74 vsi_t_sleep("",30);
75
76 ptr = (TC_TCB*) ptr->tc_created.cs_next;
77 } while (ptr != head && count++ < 50); //count is protection from infinite loops
78 } // end of for (jndex=0; jndex<2; jndex++)
79
80 // stack allocation algorithm from the int.s function INT_Initialize()
81 //
82 // \ \
83 // \----------\
84 // \ \
85 // \ \
86 // \ \
87 // \ SYSSTACK \
88 // \ \
89 // \ \
90 // \ \
91 // \----------\
92 // \ \
93 // \ IRQSTACK \
94 // \ \
95 // \----------\
96 // \ \
97 // \ \
98 // \ FIQSTACK \
99 // \ \
100 // \ \
101 // \----------\
102 // \ \
103
104 untouched = 0;
105 top_stack = top = (char *)TCT_System_Limit;
106 bottom = (char *) ((unsigned)TCT_System_Limit + SYSTEM_SIZE);
107 while (*top_stack == 0xFE && top_stack <= bottom)
108 {
109 untouched++;
110 top_stack++;
111 }
112
113 // "CST" being the current active task with its related CST_Stack,
114 // the System Stack is unused (current sp_svc = System Stack Bottom)
115 sprintf(result, "SYSSTACK: %08x %08x %08x 0x%x",
116 top,
117 bottom,
118 bottom, // current sp_svc = System Stack Bottom
119 untouched);
120 vsi_o_trace("CST", 0x08, "-------------------------------------------------");
121 vsi_o_trace("CST", 0x08, result);
122 vsi_t_sleep("",30);
123
124 untouched = 0;
125 top_stack = top = bottom + 4;
126 bottom = (char *) ((unsigned)bottom + IRQ_STACK_SIZE);
127 while (*top_stack == 0xFE && top_stack <= bottom)
128 {
129 untouched++;
130 top_stack++;
131 }
132
133 // Since the processor is in supervisor mode (no IRQ & no FIQ),
134 // current sp_irq = IRQ Stack bottom
135 sprintf(result, "IRQSTACK: %08x %08x %08x 0x%x",
136 top,
137 bottom,
138 bottom, // current sp_irq = IRQ Stack bottom
139 untouched);
140 vsi_o_trace("CST", 0x08, result);
141 vsi_t_sleep("",30);
142
143 untouched = 0;
144 top_stack = top = bottom + 4;
145 bottom = (char *) ((unsigned)bottom + FIQ_STACK_SIZE);
146 while (*top_stack == 0xFE && top_stack <= bottom)
147 {
148 untouched++;
149 top_stack++;
150 }
151
152 // Since the processor is in supervisor mode (no IRQ & no FIQ),
153 // current sp_fiq = FIQ Stack bottom
154 sprintf(result, "FIQSTACK: %08x %08x %08x 0x%x",
155 top,
156 bottom,
157 bottom, // current sp_fiq = FIQ Stack bottom
158 untouched);
159 vsi_o_trace("CST", 0x08, result);
160 vsi_o_trace("CST", 0x08, "-------------------------------------------------");
161 vsi_t_sleep("",30);
162 }
163