]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/fr30/arch/v2_0/src/fr30_stub.c
Initial revision
[karo-tx-redboot.git] / packages / hal / fr30 / arch / v2_0 / src / fr30_stub.c
1 //========================================================================
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 Red Hat, Inc.
12 // Copyright (C) 2007 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 // 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####
43 //
44 // Author(s):     larsi
45 // Contributors:  
46 // Date:          2007-07-09
47 // Purpose:       
48 // Description:   Helper functions for gdb stub for FR30 processors
49 // Usage:         
50 //
51 //####DESCRIPTIONEND####
52 //
53 //========================================================================
54
55 #include <stddef.h>
56
57 #include <pkgconf/hal.h>
58
59 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
60
61 #define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
62
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
67
68 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
69 #include <cyg/hal/dbg-threads-api.h>    // dbg_currthread_id
70 #endif
71
72 /* Given a trap value TRAP, return the corresponding signal. */
73
74 int __computeSignal (unsigned int trap_number)
75 {
76     switch (trap_number)
77     {
78
79     case CYGNUM_HAL_VECTOR_COPR_NOT_FOUND:
80     case CYGNUM_HAL_VECTOR_COPR_ERROR:
81         return SIGFPE;
82
83         // step trace TRAP
84     case CYGNUM_HAL_VECTOR_DEBUG:
85         // INTE
86     case CYGNUM_HAL_VECTOR_BREAKPOINT:
87         return SIGTRAP;
88         /* System call instruction executed */
89     case CYGNUM_HAL_VECTOR_SYSTEM_CALL ... CYGNUM_HAL_VECTOR_TRAPLAST:
90         return SIGSYS;
91         /* External interrupt */
92     case CYGNUM_HAL_INTERRUPT_0 ... CYGNUM_HAL_INTERRUPT_DELAYED_IRQ:
93       return SIGINT;
94       // Illegal or reserved instruction
95     case CYGNUM_HAL_VECTOR_OPCODE:
96         return SIGILL;
97
98     // Marks port does think to return SIGTRAP as default.
99     default:
100         return SIGTERM;
101     }
102 }
103
104 /* Return the trap number corresponding to the last-taken trap. */
105
106 int __get_trap_number (void)
107 {
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;
111 }
112
113 /* Set the currently-saved pc register value to PC. This also updates NPC
114    as needed. */
115
116 void set_pc (target_register_t pc)
117 {
118     put_register (PC, pc);
119 }
120
121 /*----------------------------------------------------------------------
122  * Single-step support
123  */
124
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. */
128
129 void __single_step (void)
130 {
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);
134 }
135
136 /* Clear the single-step state. */
137 void __clear_single_step (void)
138 {
139     put_register (PS, get_register (PS) & ~0x100);
140 }
141
142 void __install_breakpoints ()
143 {
144   /*  if (instrBuffer.targetAddr != NULL)
145     {
146       instrBuffer.savedInstr = *instrBuffer.targetAddr;
147       *instrBuffer.targetAddr = __break_opcode ();
148       } */
149
150   /* Install the breakpoints in the breakpoint list */
151   __install_breakpoint_list();
152
153   // No need to flush caches here; Generic stub code will handle this.
154 }
155
156 void __clear_breakpoints (void)
157 {
158   __clear_breakpoint_list();
159 }
160
161 /* If the breakpoint we hit is in the breakpoint() instruction, return a
162    non-zero value. */
163
164 int
165 __is_breakpoint_function ()
166 {
167     return get_register (PC) == (target_register_t)&_breakinst;
168 }
169
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. */
173
174 void __skipinst (void)
175 {
176     put_register (PC, get_register (PC) + 2);
177 }
178
179 /* Get a register out of the GDB register structure */
180 target_register_t
181 get_register (regnames_t reg)
182 {
183     GDB_Registers* gdb_regs;
184
185     gdb_regs = (GDB_Registers*)_registers;
186
187     if (reg >= R0 && reg <= MDL)
188         return gdb_regs->r[reg];
189
190     return 0xdeadbeef;
191 }
192
193 /* Put a register into the GDB register structure */
194 void
195 put_register (regnames_t reg, target_register_t value)
196 {
197     GDB_Registers* gdb_regs;
198
199     gdb_regs = (GDB_Registers*)_registers;
200
201     if (reg >= R0 && reg <= MDL) {
202         gdb_regs->r[reg] = value;
203     } else {
204         CYG_FAIL("Attempt to write to non-existent register ");
205     }
206 }
207
208 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
209
210 // EOF openrisc_stub.c