1 //========================================================================
5 // Fujitsu FR30-specific code for remote debugging via gdb
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) 2007 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.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //========================================================================
42 //#####DESCRIPTIONBEGIN####
48 // Description: Helper functions for gdb stub for FR30 processors
51 //####DESCRIPTIONEND####
53 //========================================================================
57 #include <pkgconf/hal.h>
59 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
61 #define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
63 #include <cyg/hal/hal_stub.h>
64 #include <cyg/hal/hal_arch.h>
65 #include <cyg/hal/hal_intr.h>
66 #include <cyg/infra/cyg_ass.h> // assertion macros
68 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
69 #include <cyg/hal/dbg-threads-api.h> // dbg_currthread_id
72 /* Given a trap value TRAP, return the corresponding signal. */
74 int __computeSignal (unsigned int trap_number)
79 case CYGNUM_HAL_VECTOR_COPR_NOT_FOUND:
80 case CYGNUM_HAL_VECTOR_COPR_ERROR:
84 case CYGNUM_HAL_VECTOR_DEBUG:
86 case CYGNUM_HAL_VECTOR_BREAKPOINT:
88 /* System call instruction executed */
89 case CYGNUM_HAL_VECTOR_SYSTEM_CALL ... CYGNUM_HAL_VECTOR_TRAPLAST:
91 /* External interrupt */
92 case CYGNUM_HAL_INTERRUPT_0 ... CYGNUM_HAL_INTERRUPT_DELAYED_IRQ:
94 // Illegal or reserved instruction
95 case CYGNUM_HAL_VECTOR_OPCODE:
98 // Marks port does think to return SIGTRAP as default.
104 /* Return the trap number corresponding to the last-taken trap. */
106 int __get_trap_number (void)
108 // The vector is not not part of the GDB register set so get it
109 // directly from the save context.
110 return _hal_registers->last_trap;
113 /* Set the currently-saved pc register value to PC. This also updates NPC
116 void set_pc (target_register_t pc)
118 put_register (PC, pc);
121 /*----------------------------------------------------------------------
122 * Single-step support
125 /* Set things up so that the next user resume will execute one instruction.
126 This may be done by setting breakpoints or setting a single step flag
127 in the saved user registers, for example. */
129 void __single_step (void)
131 /* Trying to use processors single stepping.
132 This means to set T flag in PS register. */
133 put_register (PS, get_register (PS) | 0x100);
136 /* Clear the single-step state. */
137 void __clear_single_step (void)
139 put_register (PS, get_register (PS) & ~0x100);
142 void __install_breakpoints ()
144 /* if (instrBuffer.targetAddr != NULL)
146 instrBuffer.savedInstr = *instrBuffer.targetAddr;
147 *instrBuffer.targetAddr = __break_opcode ();
150 /* Install the breakpoints in the breakpoint list */
151 __install_breakpoint_list();
153 // No need to flush caches here; Generic stub code will handle this.
156 void __clear_breakpoints (void)
158 __clear_breakpoint_list();
161 /* If the breakpoint we hit is in the breakpoint() instruction, return a
165 __is_breakpoint_function ()
167 return get_register (PC) == (target_register_t)&_breakinst;
170 /* Skip the current instruction. Since this is only called by the
171 stub when the PC points to a breakpoint or trap instruction,
172 we can safely just skip 2. */
174 void __skipinst (void)
176 put_register (PC, get_register (PC) + 2);
179 /* Get a register out of the GDB register structure */
181 get_register (regnames_t reg)
183 GDB_Registers* gdb_regs;
185 gdb_regs = (GDB_Registers*)_registers;
187 if (reg >= R0 && reg <= MDL)
188 return gdb_regs->r[reg];
193 /* Put a register into the GDB register structure */
195 put_register (regnames_t reg, target_register_t value)
197 GDB_Registers* gdb_regs;
199 gdb_regs = (GDB_Registers*)_registers;
201 if (reg >= R0 && reg <= MDL) {
202 gdb_regs->r[reg] = value;
204 CYG_FAIL("Attempt to write to non-existent register ");
208 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
210 // EOF openrisc_stub.c