]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/coldfire/arch/v2_0/src/coldfire_stub.c
Initial revision
[karo-tx-redboot.git] / packages / hal / coldfire / arch / v2_0 / src / coldfire_stub.c
1 //========================================================================
2 //
3 //      coldfire_stub.c
4 //
5 //      Helper functions for stub
6 //
7 //========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2006 eCosCentric Ltd.
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //========================================================================
39 //#####DESCRIPTIONBEGIN####
40 //
41 // Author(s):     Enrico Piria
42 // Contributors:
43 // Date:          2005-25-06
44 // Purpose:       Helper functions for stub, generic to all ColdFire
45 //                processors.
46 //
47 //####DESCRIPTIONEND####
48 //========================================================================
49
50 #include <stddef.h>
51 #include <string.h>                     // memcpy, memset
52
53 #include <pkgconf/hal.h>
54
55 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
56 #include <cyg/hal/hal_stub.h>
57
58 #include <cyg/hal/hal_stub.h>
59 #include <cyg/hal/hal_arch.h>
60 #include <cyg/hal/hal_intr.h>
61
62 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
63 #include <cyg/hal/dbg-threads-api.h>    // dbg_currthread_id
64 #endif
65
66 // Given a trap value TRAP, return the corresponding signal.
67 int __computeSignal (unsigned int trap_number)
68 {
69     switch (trap_number)
70     {
71
72         case CYGNUM_HAL_VECTOR_BUSERR:
73         case CYGNUM_HAL_VECTOR_ADDRERR:
74             return SIGBUS;
75
76         case CYGNUM_HAL_VECTOR_ILLINST:
77         case CYGNUM_HAL_VECTOR_UNSUPINST:
78             return SIGILL;
79
80         case CYGNUM_HAL_VECTOR_ZERODIV:
81         case CYGNUM_HAL_VECTOR_FP_BRANCH:
82         case CYGNUM_HAL_VECTOR_FP_INEXACT:
83         case CYGNUM_HAL_VECTOR_FP_ZERODIV:
84         case CYGNUM_HAL_VECTOR_FP_UNDERFLOW:
85         case CYGNUM_HAL_VECTOR_FP_OPERAND:
86         case CYGNUM_HAL_VECTOR_FP_OVERFLOW:
87         case CYGNUM_HAL_VECTOR_FP_NAN:
88         case CYGNUM_HAL_VECTOR_FP_DENORM:
89             // Although not quite accurate, use this signal also for
90             // integer division.
91             return SIGFPE;
92
93         case CYGNUM_HAL_VECTOR_PRIVVIOLATION:
94             return SIGILL;
95         case CYGNUM_HAL_VECTOR_TRACE:
96             // Instruction trace
97             return SIGTRAP;
98
99         case CYGNUM_HAL_VECTOR_L1010:
100         case CYGNUM_HAL_VECTOR_L1111:
101         case CYGNUM_HAL_VECTOR_UNINITINT:
102         case CYGNUM_HAL_VECTOR_SPURINT:
103             return SIGTRAP;
104
105         case CYGNUM_HAL_VECTOR_TRAPFIRST ... CYGNUM_HAL_VECTOR_TRAPLAST:
106             return SIGTRAP;
107
108         case CYGNUM_HAL_VECTOR_AUTOVEC1 ... CYGNUM_HAL_VECTOR_AUTOVEC7:
109         case CYGNUM_HAL_VECTOR_USERINTRFIRST ... CYGNUM_HAL_VECTOR_USERINTRLAST:
110             // External interrupt
111             return SIGINT;
112
113         default:
114             return SIGTERM;
115     }
116 }
117
118
119 // Return the trap number corresponding to the last-taken trap.
120 int __get_trap_number (void)
121 {
122     // The vector is not not part of the GDB register set so get it
123     // directly from the saved context.
124     return HAL_CF_EXCEPTION_VECTOR(_hal_registers->fmt_vec_word);
125 }
126
127
128 // Set the currently-saved pc register value to PC.
129 void set_pc (target_register_t pc)
130 {
131     put_register (PC, pc);
132 }
133
134
135 // Return the offset of a register in the GDB_Registers structure.
136 static int reg_offset(regnames_t reg)
137 {
138     switch(reg)
139     {
140         case D0 ... A7:
141             return reg * 4;
142     
143         case SR:
144             return offsetof(GDB_Registers, sr);
145
146         default:
147         case PC:
148             return offsetof(GDB_Registers, pc);
149     }
150 }
151
152
153 // Return the currently-saved value corresponding to register REG of
154 // the exception context.
155 target_register_t get_register(regnames_t reg)
156 {
157     target_register_t val;
158     int offset = reg_offset(reg);
159
160     if (REGSIZE(reg) > sizeof(target_register_t))
161         return -1;
162
163     val = _registers[offset/sizeof(target_register_t)];
164
165     return val;
166 }
167
168
169 // Store VALUE in the register corresponding to WHICH in the exception
170 // context.
171 void put_register(regnames_t which, target_register_t value)
172 {
173     int offset = reg_offset(which);
174
175     if (REGSIZE(which) > sizeof(target_register_t))
176         return;
177
178     _registers[offset/sizeof(target_register_t)] = value;
179 }
180         
181
182 // Write the contents of register WHICH into VALUE as raw bytes. This
183 // is only used for registers larger than sizeof(target_register_t).
184 // Return non-zero if it is a valid register.
185 int get_register_as_bytes(regnames_t which, char *value)
186 {
187     int offset = reg_offset(which);
188
189     memcpy (value, (char *)_registers + offset, REGSIZE(which));
190     return 1;
191 }
192
193
194 // Alter the contents of saved register WHICH to contain VALUE. This
195 // is only used for registers larger than sizeof(target_register_t).
196 // Return non-zero if it is a valid register.
197 int put_register_as_bytes(regnames_t which, char *value)
198 {
199     int offset = reg_offset(which);
200
201     memcpy ((char *)_registers + offset, value, REGSIZE(which));
202     return 1;
203 }
204
205
206 // ---------------------------------------------------------------------
207 // Single-step support
208
209 // Set things up so that the next user resume will execute one instruction.
210 // This may be done by setting breakpoints or setting a single step flag
211 // in the saved user registers, for example.
212
213 #define SR_TRACE 0x8000
214
215 void __single_step(void)
216 {
217     target_register_t sr = get_register (SR);
218
219     // Set trace flag in the exception context.
220     sr |= SR_TRACE;
221
222     put_register (SR, sr);
223 }
224
225
226 // Clear the single-step state.
227 void __clear_single_step(void)
228 {
229     target_register_t sr = get_register (SR);
230
231     // Clear single-step flag in the exception context.
232     sr &= ~SR_TRACE;
233
234     put_register (SR, sr);
235 }
236
237
238 void __install_breakpoints(void)
239 {
240     // NOP since single-step HW exceptions are used instead of
241     // breakpoints.
242 }
243
244
245 void __clear_breakpoints(void)
246 {
247     // NOP since single-step HW exceptions are used instead of
248     // breakpoints.
249 }
250
251
252 // If the breakpoint we hit is in the breakpoint() instruction, return a
253 // non-zero value.
254 int __is_breakpoint_function(void)
255 {
256     return (get_register(PC) == (target_register_t) &CYG_LABEL_NAME(_breakinst));
257 }
258
259
260 // Skip the current instruction. Since this is only called by the
261 // stub when the PC points to a breakpoint or trap instruction,
262 // we can safely just skip 2.
263 void __skipinst(void)
264 {
265     put_register (PC, get_register (PC) + HAL_BREAKINST_SIZE);
266 }
267
268 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS