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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [calmrisc32/] [arch/] [v2_0/] [src/] [calm32-stub.c] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 unneback
//========================================================================
2
//
3
//      calm32-stub.h
4
//
5
//      Helper functions for stub, generic to all CalmRISC32 processors
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):     Red Hat, msalter
44
// Contributors:  Red Hat, msalter
45
// Date:          2001-02-12
46
// Purpose:       
47
// Description:   Helper functions for stub, generic to CalmRISC32 processors
48
// Usage:         
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================
53
 
54
#include <stddef.h>
55
 
56
#include <pkgconf/hal.h>
57
 
58
#ifdef CYGPKG_REDBOOT
59
#include <pkgconf/redboot.h>
60
#endif
61
 
62
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
63
 
64
#include <cyg/hal/hal_stub.h>
65
 
66
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
67
 
68
#include <cyg/hal/hal_arch.h>
69
#include <cyg/hal/hal_intr.h>
70
 
71
typedef cyg_uint16 t_inst;
72
 
73
/*----------------------------------------------------------------------
74
 * Asynchronous interrupt support
75
 */
76
 
77
static struct
78
{
79
  t_inst *targetAddr;
80
  t_inst savedInstr;
81
} asyncBuffer;
82
 
83
/* Called to asynchronously interrupt a running program.
84
   Must be passed address of instruction interrupted.
85
   This is typically called in response to a debug port
86
   receive interrupt.
87
*/
88
 
89
void
90
install_async_breakpoint(void *pc)
91
{
92
  asyncBuffer.targetAddr = pc;
93
  asyncBuffer.savedInstr = *(t_inst *)pc;
94
  *(t_inst *)pc = *(t_inst *)_breakinst;
95
  __instruction_cache(CACHE_FLUSH);
96
  __data_cache(CACHE_FLUSH);
97
}
98
 
99
/*--------------------------------------------------------------------*/
100
/* Given a trap value TRAP, return the corresponding signal. */
101
 
102
int __computeSignal (unsigned int trap_number)
103
{
104
    switch (trap_number) {
105
      case CYGNUM_HAL_VECTOR_FIQ:
106
      case CYGNUM_HAL_VECTOR_IRQ:
107
        return SIGINT;
108
      case CYGNUM_HAL_VECTOR_IABRT:
109
      case CYGNUM_HAL_VECTOR_DABRT:
110
        return SIGBUS;
111
    }
112
    return SIGTRAP;
113
}
114
 
115
/* Return the trap number corresponding to the last-taken trap. */
116
 
117
int __get_trap_number (void)
118
{
119
    // The vector is not not part of the GDB register set so get it
120
    // directly from the save context.
121
    return _hal_registers->vector;
122
}
123
 
124
#if defined(CYGSEM_REDBOOT_BSP_SYSCALLS)
125
int __is_bsp_syscall(void)
126
{
127
    return __get_trap_number() >= CYGNUM_HAL_VECTOR_SWI;
128
}
129
#endif
130
 
131
/* Set the current pc register value based on current vector. */
132
 
133
void set_pc (target_register_t pc)
134
{
135
    put_register (REG_PC, pc);
136
    switch (__get_trap_number()) {
137
      case CYGNUM_HAL_VECTOR_SWI:
138
        put_register (REG_SPC_SWI, pc);
139
        break;
140
      case CYGNUM_HAL_VECTOR_FIQ:
141
        put_register (REG_SPC_FIQ, pc);
142
        break;
143
      case CYGNUM_HAL_VECTOR_IRQ:
144
        put_register (REG_SPC_IRQ, pc);
145
        break;
146
      default:
147
        put_register (REG_SPC_EXPT, pc);
148
        break;
149
    }
150
}
151
 
152
/* Get the current pc register value based on current vector. */
153
 
154
target_register_t get_pc(void)
155
{
156
    switch (__get_trap_number()) {
157
      case CYGNUM_HAL_VECTOR_SWI:
158
        return get_register (REG_SPC_SWI);
159
      case CYGNUM_HAL_VECTOR_FIQ:
160
        return get_register (REG_SPC_FIQ);
161
      case CYGNUM_HAL_VECTOR_IRQ:
162
        return get_register (REG_SPC_IRQ);
163
      default:
164
        break;
165
    }
166
    return get_register (REG_SPC_EXPT);
167
}
168
 
169
int __sp_regnum(void)
170
{
171
    target_register_t sr = get_register(REG_SR);
172
 
173
    if ((sr & CYGARC_SR_PM) == 0 || (sr & CYGARC_SR_BS) == 0)
174
        return REG_B0R15;
175
    return REG_B1R15;
176
}
177
 
178
/*----------------------------------------------------------------------
179
 * Single-step support
180
 */
181
 
182
/* Set things up so that the next user resume will execute one instruction.
183
   This may be done by setting breakpoints or setting a single step flag
184
   in the saved user registers, for example. */
185
 
186
void __single_step (void)
187
{
188
    put_register(REG_SR, get_register(REG_SR) | CYGARC_SR_TE);
189
}
190
 
191
 
192
/* Clear the single-step state. */
193
 
194
void __clear_single_step (void)
195
{
196
    put_register(REG_SR, get_register(REG_SR) & ~CYGARC_SR_TE);
197
}
198
 
199
 
200
void __install_breakpoints ()
201
{
202
  /* Install the breakpoints in the breakpoint list */
203
  __install_breakpoint_list();
204
}
205
 
206
void __clear_breakpoints (void)
207
{
208
  __clear_breakpoint_list();
209
}
210
 
211
 
212
/* If the breakpoint we hit is in the breakpoint() instruction, return a
213
   non-zero value. */
214
 
215
int
216
__is_breakpoint_function ()
217
{
218
    return get_pc() == (target_register_t)(unsigned long)&_breakinst;
219
}
220
 
221
 
222
/* Skip the current instruction.  Since this is only called by the
223
   stub when the PC points to a breakpoint or trap instruction,
224
   we can safely just skip 2. */
225
 
226
void __skipinst (void)
227
{
228
    set_pc(get_pc() + 2);
229
}
230
 
231
int __is_prog_addr(unsigned long long addr)
232
{
233
    return addr >= 0x100000000ULL;
234
}
235
 
236
char *__addr_to_ptr(unsigned long long addr)
237
{
238
    return (char *)((unsigned)(addr & 0xffffffff));
239
}
240
 
241
unsigned short __read_prog_uint16(void *addr)
242
{
243
    unsigned val;
244
    asm("ldch %0, @%1" : "=r"(val) : "r"(addr) );
245
    return val;
246
}
247
 
248
unsigned char __read_prog_uint8(void *addr)
249
{
250
    unsigned short s;
251
    int is_odd = ((unsigned)addr & 1) == 1;
252
 
253
    s = __read_prog_uint16((void *)((unsigned)addr & ~1));
254
    if (is_odd)
255
        return s & 0xff;
256
    else
257
        return (s >> 8) & 0xff;
258
}
259
 
260
unsigned int __read_prog_uint32(void *addr)
261
{
262
    unsigned int u;
263
 
264
    u = __read_prog_uint16(addr) << 16;
265
    u |= __read_prog_uint16((void *)((unsigned)addr + 2));
266
 
267
    return u;
268
}
269
 
270
void __write_prog_uint16(void *addr, unsigned short val)
271
{
272
    hal_plf_write_prog_halfword((unsigned)addr, val);
273
}
274
 
275
void __write_prog_uint32(void *addr, unsigned int val)
276
{
277
    hal_plf_write_prog_halfword((unsigned)addr, (val >> 16) & 0xffff);
278
    hal_plf_write_prog_halfword((unsigned)addr + 2, val & 0xffff);
279
}
280
 
281
void __write_prog_uint8(void *addr, unsigned char val)
282
{
283
    unsigned short s;
284
    int is_odd = ((unsigned)addr & 1) == 1;
285
 
286
    s = __read_prog_uint16((void *)((unsigned)addr & ~1));
287
 
288
    if (is_odd)
289
        s = (s & 0xff00) | val;
290
    else
291
        s = (s & 0xff) | (val << 8);
292
 
293
    hal_plf_write_prog_halfword((unsigned)addr & ~1, s);
294
}
295
 
296
 
297
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS

powered by: WebSVN 2.1.0

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