OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [openrisc/] [arch/] [current/] [src/] [openrisc_stub.c] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//========================================================================
2
//
3
//      openrisc_stub.c
4
//
5
//      OpenRISC-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
//
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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     sfurman
44
// Contributors:  Red Hat, jskov, gthomas
45
// Date:          2003-02-07
46
// Purpose:       
47
// Description:   Helper functions for gdb stub for OpenRISC processors
48
// Usage:         
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================
53
 
54
#include <stddef.h>
55
 
56
#include <pkgconf/hal.h>
57
 
58
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
59
 
60
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
61
 
62
#include <cyg/hal/hal_stub.h>
63
#include <cyg/hal/hal_arch.h>
64
#include <cyg/hal/hal_intr.h>
65
#include <cyg/hal/openrisc_opcode.h>
66
#include <cyg/infra/cyg_ass.h>          // assertion macros
67
 
68
#ifdef CYGNUM_HAL_NO_VECTOR_TRACE
69
#define USE_BREAKPOINTS_FOR_SINGLE_STEP
70
#endif
71
 
72
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
73
#include <cyg/hal/dbg-threads-api.h>    // dbg_currthread_id
74
#endif
75
 
76
/* Given a trap value TRAP, return the corresponding signal. */
77
 
78
int __computeSignal (unsigned int trap_number)
79
{
80
    switch (trap_number)
81
    {
82
        // Either no matching page-table entry or protection fault
83
        // while executing load/store operation
84
    case CYGNUM_HAL_VECTOR_DATA_PAGE_FAULT:
85
        // Either no matching page-table entry or protection fault
86
        // while executing load/store operation
87
    case CYGNUM_HAL_VECTOR_INSTR_PAGE_FAULT:
88
        return SIGSEGV;
89
 
90
        // No matching entry in D-TLB
91
    case CYGNUM_HAL_VECTOR_DTLB_MISS:
92
        // No matching entry in I-TLB
93
    case CYGNUM_HAL_VECTOR_ITLB_MISS:
94
        // Unaligned load/store memory access
95
    case CYGNUM_HAL_VECTOR_UNALIGNED_ACCESS:
96
        // Access to non-existent physical memory/device
97
    case CYGNUM_HAL_VECTOR_BUS_ERROR:
98
        return SIGBUS;
99
 
100
        // TRAP instruction executed
101
    case CYGNUM_HAL_VECTOR_TRAP:
102
        return SIGTRAP;
103
 
104
        /* System call instruction executed */
105
    case CYGNUM_HAL_VECTOR_SYSTEM_CALL:
106
        return SIGSYS;
107
 
108
        /* Tick timer interrupt fired */
109
    case CYGNUM_HAL_VECTOR_TICK_TIMER:
110
        return SIGALRM;
111
 
112
        /* External interrupt */
113
    case CYGNUM_HAL_VECTOR_INTERRUPT:
114
      return SIGINT;
115
 
116
      // Illegal or reserved instruction
117
    case CYGNUM_HAL_VECTOR_RESERVED_INSTRUCTION:
118
        return SIGILL;
119
 
120
        // Numeric overflow, etc.
121
    case CYGNUM_HAL_VECTOR_RANGE:
122
        return SIGFPE;
123
 
124
    default:
125
        return SIGTERM;
126
    }
127
}
128
 
129
 
130
/* Return the trap number corresponding to the last-taken trap. */
131
 
132
int __get_trap_number (void)
133
{
134
    // The vector is not not part of the GDB register set so get it
135
    // directly from the save context.
136
    return _hal_registers->vector;
137
}
138
 
139
/* Set the currently-saved pc register value to PC. This also updates NPC
140
   as needed. */
141
 
142
void set_pc (target_register_t pc)
143
{
144
    put_register (PC, pc);
145
}
146
 
147
 
148
 
149
/*----------------------------------------------------------------------
150
 * Single-step support
151
 */
152
 
153
// Type of a single OpenRISC instruction
154
typedef cyg_uint32 t_inst;
155
 
156
/* Saved instruction data for single step support.  */
157
static struct
158
{
159
  t_inst *targetAddr;
160
  t_inst savedInstr;
161
} instrBuffer;
162
 
163
 
164
/* Set things up so that the next user resume will execute one instruction.
165
   This may be done by setting breakpoints or setting a single step flag
166
   in the saved user registers, for example. */
167
 
168
void __single_step (void)
169
{
170
  t_inst *pc = (t_inst *) get_register (PC);
171
  t_inst *targetAddr;
172
  InstFmt insn;
173
  int flag;
174
 
175
  targetAddr = pc + 1;              /* set default */
176
 
177
  insn.word = *pc;
178
  switch (insn.JType.op) {
179
  case OP_J:
180
  case OP_JAL:
181
    targetAddr = pc + insn.JType.target;
182
    break;
183
 
184
  case OP_BNF:
185
    flag = get_register(SR) & SPR_SR_F;
186
    if (!flag)
187
      targetAddr = pc + insn.JType.target;
188
    break;
189
 
190
  case OP_BF:
191
    flag = get_register(SR) & SPR_SR_F;
192
    if (flag)
193
      targetAddr = pc + insn.JType.target;
194
    break;
195
 
196
  case OP_JR:
197
  case OP_JALR:
198
    targetAddr = (t_inst*)get_register(insn.JRType.rB);
199
    break;
200
 
201
    /* We don't step into interrupts, syscalls or traps */
202
  default:
203
    break;
204
  }
205
 
206
  instrBuffer.targetAddr = targetAddr;
207
  instrBuffer.savedInstr = *targetAddr;
208
  *targetAddr = __break_opcode ();
209
 
210
  // No need to flush caches; Generic stub code will handle this.
211
}
212
 
213
/* Clear the single-step state. */
214
void __clear_single_step (void)
215
{
216
  if (instrBuffer.targetAddr != NULL)
217
    {
218
      *instrBuffer.targetAddr = instrBuffer.savedInstr;
219
      instrBuffer.targetAddr = NULL;
220
      instrBuffer.savedInstr = 0;
221
    }
222
}
223
 
224
 
225
void __install_breakpoints ()
226
{
227
  /*  if (instrBuffer.targetAddr != NULL)
228
    {
229
      instrBuffer.savedInstr = *instrBuffer.targetAddr;
230
      *instrBuffer.targetAddr = __break_opcode ();
231
      } */
232
 
233
  /* Install the breakpoints in the breakpoint list */
234
  __install_breakpoint_list();
235
 
236
  // No need to flush caches here; Generic stub code will handle this.
237
}
238
 
239
void __clear_breakpoints (void)
240
{
241
  __clear_breakpoint_list();
242
}
243
 
244
/* If the breakpoint we hit is in the breakpoint() instruction, return a
245
   non-zero value. */
246
 
247
int
248
__is_breakpoint_function ()
249
{
250
    return get_register (PC) == (target_register_t)&_breakinst;
251
}
252
 
253
 
254
/* Skip the current instruction.  Since this is only called by the
255
   stub when the PC points to a breakpoint or trap instruction,
256
   we can safely just skip 4. */
257
 
258
void __skipinst (void)
259
{
260
    put_register (PC, get_register (PC) + 4);
261
}
262
 
263
target_register_t
264
get_register (regnames_t reg)
265
{
266
    GDB_Registers* gdb_regs;
267
 
268
    gdb_regs = (GDB_Registers*)_registers;
269
 
270
    if (reg >= R0 && reg <= R31)
271
        return gdb_regs->r[reg];
272
    if (reg == PC)
273
        return gdb_regs->pc;
274
    if (reg == SR)
275
        return gdb_regs->sr;
276
    return 0xdeadbeef;
277
}
278
 
279
void
280
put_register (regnames_t reg, target_register_t value)
281
{
282
    GDB_Registers* gdb_regs;
283
 
284
    gdb_regs = (GDB_Registers*)_registers;
285
 
286
    if (reg >= R0 && reg <= R31) {
287
        gdb_regs->r[reg] = value;
288
    } else if (reg == PC) {
289
        gdb_regs->pc = value;
290
    } else if (reg == SR) {
291
        gdb_regs->sr = value;
292
    } else {
293
        CYG_FAIL("Attempt to write to non-existent register ");
294
    }
295
}
296
 
297
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
298
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.