1 | /* |
---|
2 | ************************************************************************** |
---|
3 | * |
---|
4 | * Component = |
---|
5 | * |
---|
6 | * Synopsis = rdbgexcep.c |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | ************************************************************************** |
---|
11 | */ |
---|
12 | |
---|
13 | #include <rtems.h> |
---|
14 | #include <rtems/error.h> |
---|
15 | #include <assert.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <rdbg/rdbg.h> |
---|
18 | #include <rdbg/servrpc.h> |
---|
19 | |
---|
20 | unsigned int NbExceptCtx; |
---|
21 | volatile unsigned int NbSerializedCtx; |
---|
22 | Exception_context *FirstCtx = NULL; |
---|
23 | Exception_context *LastCtx = NULL; |
---|
24 | |
---|
25 | CPU_Exception_frame SavedContext; |
---|
26 | |
---|
27 | |
---|
28 | /********* Save an exception context at the end of a list *****/ |
---|
29 | |
---|
30 | int PushExceptCtx ( Objects_Id Id, Objects_Id semId, CPU_Exception_frame *ctx ) { |
---|
31 | |
---|
32 | Exception_context *SaveCtx; |
---|
33 | |
---|
34 | SaveCtx = (Exception_context *)malloc(sizeof(Exception_context)); |
---|
35 | if (SaveCtx == NULL) |
---|
36 | rtems_panic("Can't allocate memory to save Exception context"); |
---|
37 | |
---|
38 | SaveCtx->id = Id; |
---|
39 | SaveCtx->ctx = ctx; |
---|
40 | SaveCtx->semaphoreId = semId; |
---|
41 | SaveCtx->previous = NULL; |
---|
42 | SaveCtx->next = NULL; |
---|
43 | |
---|
44 | if (FirstCtx == NULL){ /* initialization */ |
---|
45 | FirstCtx = SaveCtx; |
---|
46 | LastCtx = SaveCtx; |
---|
47 | NbExceptCtx = 1; |
---|
48 | } |
---|
49 | else { |
---|
50 | NbExceptCtx ++; |
---|
51 | LastCtx->next = SaveCtx; |
---|
52 | SaveCtx->previous = LastCtx; |
---|
53 | LastCtx = SaveCtx; |
---|
54 | } |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | /********* Save an temporary exception context in a ******/ |
---|
59 | /********* global variable ******/ |
---|
60 | |
---|
61 | int PushSavedExceptCtx ( Objects_Id Id, CPU_Exception_frame *ctx ) { |
---|
62 | |
---|
63 | memcpy (&(SavedContext), ctx, sizeof(CPU_Exception_frame)); |
---|
64 | return 0; |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | /****** Remove the context of the specified Id thread *********/ |
---|
69 | /****** If Id = -1, then return the first context *********/ |
---|
70 | |
---|
71 | |
---|
72 | int PopExceptCtx ( Objects_Id Id ) { |
---|
73 | |
---|
74 | Exception_context *ExtractCtx; |
---|
75 | |
---|
76 | if (FirstCtx == NULL) return -1; |
---|
77 | |
---|
78 | if (Id == -1) { |
---|
79 | ExtractCtx = LastCtx; |
---|
80 | LastCtx = LastCtx->previous; |
---|
81 | free(ExtractCtx); |
---|
82 | NbExceptCtx --; |
---|
83 | return 0; |
---|
84 | } |
---|
85 | |
---|
86 | ExtractCtx = LastCtx; |
---|
87 | |
---|
88 | while (ExtractCtx->id != Id && ExtractCtx != NULL) { |
---|
89 | ExtractCtx = ExtractCtx->previous; |
---|
90 | } |
---|
91 | |
---|
92 | if (ExtractCtx == NULL) |
---|
93 | return -1; |
---|
94 | |
---|
95 | if ( ExtractCtx->previous != NULL) |
---|
96 | (ExtractCtx->previous)->next = ExtractCtx->next; |
---|
97 | |
---|
98 | if ( ExtractCtx->next != NULL) |
---|
99 | (ExtractCtx->next)->previous = ExtractCtx->previous; |
---|
100 | |
---|
101 | if (ExtractCtx == FirstCtx) |
---|
102 | FirstCtx = FirstCtx->next; |
---|
103 | else |
---|
104 | if (ExtractCtx == LastCtx) |
---|
105 | LastCtx = LastCtx->previous; |
---|
106 | |
---|
107 | free(ExtractCtx); |
---|
108 | NbExceptCtx --; |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|
112 | /****** Return the context of the specified Id thread *********/ |
---|
113 | /****** If Id = -1, then return the first context *********/ |
---|
114 | |
---|
115 | |
---|
116 | Exception_context *GetExceptCtx ( Objects_Id Id ) { |
---|
117 | |
---|
118 | Exception_context *ExtractCtx; |
---|
119 | |
---|
120 | if (FirstCtx == NULL) return NULL; |
---|
121 | |
---|
122 | if (Id == -1) { |
---|
123 | return LastCtx; |
---|
124 | } |
---|
125 | |
---|
126 | ExtractCtx = LastCtx; |
---|
127 | |
---|
128 | while (ExtractCtx->id != Id && ExtractCtx != NULL) { |
---|
129 | ExtractCtx = ExtractCtx->previous; |
---|
130 | } |
---|
131 | |
---|
132 | if (ExtractCtx == NULL) |
---|
133 | return NULL; |
---|
134 | |
---|
135 | return ExtractCtx; |
---|
136 | } |
---|