1 //========================================================================
5 // Helper functions for stub
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.
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.
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
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.
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.
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####
41 // Author(s): Enrico Piria
44 // Purpose: Helper functions for stub, generic to all ColdFire
47 //####DESCRIPTIONEND####
48 //========================================================================
51 #include <string.h> // memcpy, memset
53 #include <pkgconf/hal.h>
55 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
56 #include <cyg/hal/hal_stub.h>
58 #include <cyg/hal/hal_stub.h>
59 #include <cyg/hal/hal_arch.h>
60 #include <cyg/hal/hal_intr.h>
62 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
63 #include <cyg/hal/dbg-threads-api.h> // dbg_currthread_id
66 // Given a trap value TRAP, return the corresponding signal.
67 int __computeSignal (unsigned int trap_number)
72 case CYGNUM_HAL_VECTOR_BUSERR:
73 case CYGNUM_HAL_VECTOR_ADDRERR:
76 case CYGNUM_HAL_VECTOR_ILLINST:
77 case CYGNUM_HAL_VECTOR_UNSUPINST:
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
93 case CYGNUM_HAL_VECTOR_PRIVVIOLATION:
95 case CYGNUM_HAL_VECTOR_TRACE:
99 case CYGNUM_HAL_VECTOR_L1010:
100 case CYGNUM_HAL_VECTOR_L1111:
101 case CYGNUM_HAL_VECTOR_UNINITINT:
102 case CYGNUM_HAL_VECTOR_SPURINT:
105 case CYGNUM_HAL_VECTOR_TRAPFIRST ... CYGNUM_HAL_VECTOR_TRAPLAST:
108 case CYGNUM_HAL_VECTOR_AUTOVEC1 ... CYGNUM_HAL_VECTOR_AUTOVEC7:
109 case CYGNUM_HAL_VECTOR_USERINTRFIRST ... CYGNUM_HAL_VECTOR_USERINTRLAST:
110 // External interrupt
119 // Return the trap number corresponding to the last-taken trap.
120 int __get_trap_number (void)
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);
128 // Set the currently-saved pc register value to PC.
129 void set_pc (target_register_t pc)
131 put_register (PC, pc);
135 // Return the offset of a register in the GDB_Registers structure.
136 static int reg_offset(regnames_t reg)
144 return offsetof(GDB_Registers, sr);
148 return offsetof(GDB_Registers, pc);
153 // Return the currently-saved value corresponding to register REG of
154 // the exception context.
155 target_register_t get_register(regnames_t reg)
157 target_register_t val;
158 int offset = reg_offset(reg);
160 if (REGSIZE(reg) > sizeof(target_register_t))
163 val = _registers[offset/sizeof(target_register_t)];
169 // Store VALUE in the register corresponding to WHICH in the exception
171 void put_register(regnames_t which, target_register_t value)
173 int offset = reg_offset(which);
175 if (REGSIZE(which) > sizeof(target_register_t))
178 _registers[offset/sizeof(target_register_t)] = value;
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)
187 int offset = reg_offset(which);
189 memcpy (value, (char *)_registers + offset, REGSIZE(which));
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)
199 int offset = reg_offset(which);
201 memcpy ((char *)_registers + offset, value, REGSIZE(which));
206 // ---------------------------------------------------------------------
207 // Single-step support
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.
213 #define SR_TRACE 0x8000
215 void __single_step(void)
217 target_register_t sr = get_register (SR);
219 // Set trace flag in the exception context.
222 put_register (SR, sr);
226 // Clear the single-step state.
227 void __clear_single_step(void)
229 target_register_t sr = get_register (SR);
231 // Clear single-step flag in the exception context.
234 put_register (SR, sr);
238 void __install_breakpoints(void)
240 // NOP since single-step HW exceptions are used instead of
245 void __clear_breakpoints(void)
247 // NOP since single-step HW exceptions are used instead of
252 // If the breakpoint we hit is in the breakpoint() instruction, return a
254 int __is_breakpoint_function(void)
256 return (get_register(PC) == (target_register_t) &CYG_LABEL_NAME(_breakinst));
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)
265 put_register (PC, get_register (PC) + HAL_BREAKINST_SIZE);
268 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS