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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [calmrisc16/] [arch/] [v2_0/] [src/] [calm16-stub.c] - Blame information for rev 773

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

Line No. Rev Author Line
1 27 unneback
//========================================================================
2
//
3
//      calm16-stub.h
4
//
5
//      Helper functions for stub, generic to all CalmRISC16 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 CalmRISC16 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
    }
109
    return SIGTRAP;
110
}
111
 
112
/* Return the trap number corresponding to the last-taken trap. */
113
 
114
int __get_trap_number (void)
115
{
116
    // The vector is not not part of the GDB register set so get it
117
    // directly from the save context.
118
    return _hal_registers->vector;
119
}
120
 
121
#if defined(CYGSEM_REDBOOT_BSP_SYSCALLS)
122
int __is_bsp_syscall(void)
123
{
124
    return __get_trap_number() >= CYGNUM_HAL_VECTOR_SWI;
125
}
126
#endif
127
 
128
 
129
/* Set the current pc register value based on current vector. */
130
 
131
void set_pc (target_register_t pc)
132
{
133
    put_register (REG_PC, pc);
134
    switch (__get_trap_number()) {
135
      case CYGNUM_HAL_VECTOR_FIQ:
136
        put_register (REG_SPC_FIQ, pc);
137
        break;
138
      case CYGNUM_HAL_VECTOR_SWI:
139
        put_register (REG_LR, pc);
140
        break;
141
      default:
142
        put_register (REG_SPC_IRQ, pc);
143
        break;
144
    }
145
}
146
 
147
/* Get the current pc register value based on current vector. */
148
 
149
target_register_t get_pc(void)
150
{
151
    switch (__get_trap_number()) {
152
      case CYGNUM_HAL_VECTOR_SWI:
153
        return get_register (REG_LR);
154
      case CYGNUM_HAL_VECTOR_FIQ:
155
        return get_register (REG_SPC_FIQ);
156
      default:
157
        break;
158
    }
159
    return get_register (REG_SPC_IRQ);
160
}
161
 
162
 
163
/*----------------------------------------------------------------------
164
 * Single-step support
165
 */
166
 
167
/* Set things up so that the next user resume will execute one instruction.
168
   This may be done by setting breakpoints or setting a single step flag
169
   in the saved user registers, for example. */
170
 
171
void __single_step (void)
172
{
173
    put_register(REG_SR, get_register(REG_SR) | ((target_register_t)CYGARC_SR_TE << 16));
174
}
175
 
176
 
177
/* Clear the single-step state. */
178
 
179
void __clear_single_step (void)
180
{
181
    put_register(REG_SR, get_register(REG_SR) & ~((target_register_t)CYGARC_SR_TE << 16));
182
}
183
 
184
 
185
void __install_breakpoints ()
186
{
187
  /* Install the breakpoints in the breakpoint list */
188
  __install_breakpoint_list();
189
}
190
 
191
void __clear_breakpoints (void)
192
{
193
  __clear_breakpoint_list();
194
}
195
 
196
 
197
/* If the breakpoint we hit is in the breakpoint() instruction, return a
198
   non-zero value. */
199
 
200
int
201
__is_breakpoint_function ()
202
{
203
    return get_pc() == (target_register_t)(unsigned long)&_breakinst;
204
}
205
 
206
 
207
/* Skip the current instruction.  Since this is only called by the
208
   stub when the PC points to a breakpoint or trap instruction,
209
   we can safely just skip 2. */
210
 
211
void __skipinst (void)
212
{
213
    set_pc(get_pc() + 2);
214
}
215
 
216
unsigned short __read_prog_uint16(void *addr)
217
{
218
    unsigned val;
219
    asm("ldc %0, @%1" : "=r"(val) : "r"(addr) );
220
    return val;
221
}
222
 
223
unsigned char __read_prog_uint8(void *addr)
224
{
225
    unsigned short s;
226
    int is_odd = ((unsigned long)addr & 1) == 1;
227
 
228
    s = __read_prog_uint16((void *)((unsigned long)addr & ~1));
229
    if (is_odd)
230
        return s & 0xff;
231
    else
232
        return (s >> 8) & 0xff;
233
}
234
 
235
unsigned long __read_prog_uint32(void *addr)
236
{
237
    unsigned long u;
238
 
239
    u = (unsigned long)__read_prog_uint16(addr) << 16;
240
    u |= __read_prog_uint16((void *)((unsigned long)addr + 2));
241
 
242
    return u;
243
}
244
 
245
void __write_prog_uint16(void *addr, unsigned short val)
246
{
247
    hal_plf_write_prog_halfword((unsigned long)addr, val);
248
}
249
 
250
void __write_prog_uint32(void *addr, unsigned long val)
251
{
252
    hal_plf_write_prog_halfword((unsigned long)addr, (val >> 16) & 0xffff);
253
    hal_plf_write_prog_halfword((unsigned long)addr + 2, val & 0xffff);
254
}
255
 
256
void __write_prog_uint8(void *addr, unsigned char val)
257
{
258
    unsigned short s;
259
    int is_odd = ((unsigned long)addr & 1) == 1;
260
 
261
    s = __read_prog_uint16((void *)((unsigned long)addr & ~1));
262
 
263
    if (is_odd)
264
        s = (s & 0xff00) | val;
265
    else
266
        s = (s & 0xff) | (val << 8);
267
 
268
    hal_plf_write_prog_halfword((unsigned long)addr & ~1, s);
269
}
270
 
271
#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.