1 |
786 |
skrzyp |
//========================================================================
|
2 |
|
|
//
|
3 |
|
|
// fr30_stub.c
|
4 |
|
|
//
|
5 |
|
|
// Fujitsu FR30-specific code for remote debugging via gdb
|
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, 2007 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY 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
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): larsi
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2007-07-09
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description: Helper functions for gdb stub for FR30 processors
|
47 |
|
|
// Usage:
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
//========================================================================
|
52 |
|
|
|
53 |
|
|
#include <stddef.h>
|
54 |
|
|
|
55 |
|
|
#include <pkgconf/hal.h>
|
56 |
|
|
|
57 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
58 |
|
|
|
59 |
|
|
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_stub.h>
|
62 |
|
|
#include <cyg/hal/hal_arch.h>
|
63 |
|
|
#include <cyg/hal/hal_intr.h>
|
64 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
65 |
|
|
|
66 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
|
67 |
|
|
#include <cyg/hal/dbg-threads-api.h> // dbg_currthread_id
|
68 |
|
|
#endif
|
69 |
|
|
|
70 |
|
|
/* Given a trap value TRAP, return the corresponding signal. */
|
71 |
|
|
|
72 |
|
|
int __computeSignal (unsigned int trap_number)
|
73 |
|
|
{
|
74 |
|
|
switch (trap_number)
|
75 |
|
|
{
|
76 |
|
|
|
77 |
|
|
case CYGNUM_HAL_VECTOR_COPR_NOT_FOUND:
|
78 |
|
|
case CYGNUM_HAL_VECTOR_COPR_ERROR:
|
79 |
|
|
return SIGFPE;
|
80 |
|
|
|
81 |
|
|
// step trace TRAP
|
82 |
|
|
case CYGNUM_HAL_VECTOR_DEBUG:
|
83 |
|
|
// INTE
|
84 |
|
|
case CYGNUM_HAL_VECTOR_BREAKPOINT:
|
85 |
|
|
return SIGTRAP;
|
86 |
|
|
/* System call instruction executed */
|
87 |
|
|
case CYGNUM_HAL_VECTOR_SYSTEM_CALL ... CYGNUM_HAL_VECTOR_TRAPLAST:
|
88 |
|
|
return SIGSYS;
|
89 |
|
|
/* External interrupt */
|
90 |
|
|
case CYGNUM_HAL_INTERRUPT_0 ... CYGNUM_HAL_INTERRUPT_DELAYED_IRQ:
|
91 |
|
|
return SIGINT;
|
92 |
|
|
// Illegal or reserved instruction
|
93 |
|
|
case CYGNUM_HAL_VECTOR_OPCODE:
|
94 |
|
|
return SIGILL;
|
95 |
|
|
|
96 |
|
|
// Marks port does think to return SIGTRAP as default.
|
97 |
|
|
default:
|
98 |
|
|
return SIGTERM;
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/* Return the trap number corresponding to the last-taken trap. */
|
103 |
|
|
|
104 |
|
|
int __get_trap_number (void)
|
105 |
|
|
{
|
106 |
|
|
// The vector is not not part of the GDB register set so get it
|
107 |
|
|
// directly from the save context.
|
108 |
|
|
return _hal_registers->last_trap;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/* Set the currently-saved pc register value to PC. This also updates NPC
|
112 |
|
|
as needed. */
|
113 |
|
|
|
114 |
|
|
void set_pc (target_register_t pc)
|
115 |
|
|
{
|
116 |
|
|
put_register (PC, pc);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/*----------------------------------------------------------------------
|
120 |
|
|
* Single-step support
|
121 |
|
|
*/
|
122 |
|
|
|
123 |
|
|
/* Set things up so that the next user resume will execute one instruction.
|
124 |
|
|
This may be done by setting breakpoints or setting a single step flag
|
125 |
|
|
in the saved user registers, for example. */
|
126 |
|
|
|
127 |
|
|
void __single_step (void)
|
128 |
|
|
{
|
129 |
|
|
/* Trying to use processors single stepping.
|
130 |
|
|
This means to set T flag in PS register. */
|
131 |
|
|
put_register (PS, get_register (PS) | 0x100);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
/* Clear the single-step state. */
|
135 |
|
|
void __clear_single_step (void)
|
136 |
|
|
{
|
137 |
|
|
put_register (PS, get_register (PS) & ~0x100);
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
void __install_breakpoints ()
|
141 |
|
|
{
|
142 |
|
|
/* if (instrBuffer.targetAddr != NULL)
|
143 |
|
|
{
|
144 |
|
|
instrBuffer.savedInstr = *instrBuffer.targetAddr;
|
145 |
|
|
*instrBuffer.targetAddr = __break_opcode ();
|
146 |
|
|
} */
|
147 |
|
|
|
148 |
|
|
/* Install the breakpoints in the breakpoint list */
|
149 |
|
|
__install_breakpoint_list();
|
150 |
|
|
|
151 |
|
|
// No need to flush caches here; Generic stub code will handle this.
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
void __clear_breakpoints (void)
|
155 |
|
|
{
|
156 |
|
|
__clear_breakpoint_list();
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
/* If the breakpoint we hit is in the breakpoint() instruction, return a
|
160 |
|
|
non-zero value. */
|
161 |
|
|
|
162 |
|
|
int
|
163 |
|
|
__is_breakpoint_function ()
|
164 |
|
|
{
|
165 |
|
|
return get_register (PC) == (target_register_t)&_breakinst;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
/* Skip the current instruction. Since this is only called by the
|
169 |
|
|
stub when the PC points to a breakpoint or trap instruction,
|
170 |
|
|
we can safely just skip 2. */
|
171 |
|
|
|
172 |
|
|
void __skipinst (void)
|
173 |
|
|
{
|
174 |
|
|
put_register (PC, get_register (PC) + 2);
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
/* Get a register out of the GDB register structure */
|
178 |
|
|
target_register_t
|
179 |
|
|
get_register (regnames_t reg)
|
180 |
|
|
{
|
181 |
|
|
GDB_Registers* gdb_regs;
|
182 |
|
|
|
183 |
|
|
gdb_regs = (GDB_Registers*)_registers;
|
184 |
|
|
|
185 |
|
|
if (reg >= R0 && reg <= MDL)
|
186 |
|
|
return gdb_regs->r[reg];
|
187 |
|
|
|
188 |
|
|
return 0xdeadbeef;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
/* Put a register into the GDB register structure */
|
192 |
|
|
void
|
193 |
|
|
put_register (regnames_t reg, target_register_t value)
|
194 |
|
|
{
|
195 |
|
|
GDB_Registers* gdb_regs;
|
196 |
|
|
|
197 |
|
|
gdb_regs = (GDB_Registers*)_registers;
|
198 |
|
|
|
199 |
|
|
if (reg >= R0 && reg <= MDL) {
|
200 |
|
|
gdb_regs->r[reg] = value;
|
201 |
|
|
} else {
|
202 |
|
|
CYG_FAIL("Attempt to write to non-existent register ");
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
207 |
|
|
|
208 |
|
|
// EOF openrisc_stub.c
|