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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [h8300/] [h8300h/] [current/] [src/] [h8300h_stub.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//========================================================================
2
//
3
//      h8300h_stub.c
4
//
5
//      Helper functions for H8/300H stub
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 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):     Yoshinori Sato
43
// Contributors:  Yoshinori Sato
44
// Date:          2002-05-03
45
// Purpose:       
46
// Description:   Helper functions for H8/300H stub
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
#include <cyg/hal/hal_stub.h>
60
#include <cyg/hal/hal_arch.h>
61
#include <cyg/hal/hal_intr.h>
62
#include <cyg/hal/hal_diag.h>
63
 
64
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
65
#include <cyg/hal/dbg-threads-api.h>    // dbg_currthread_id
66
#endif
67
 
68
/*--------------------------------------------------------------------*/
69
/* Given a trap value TRAP, return the corresponding signal. */
70
 
71
int __computeSignal (unsigned int trap_number)
72
{
73
    switch (trap_number) {
74
    case CYGNUM_HAL_VECTOR_TRAP3:
75
        return SIGTRAP;
76
    default:
77
        return SIGINT;
78
    }
79
}
80
 
81
/*--------------------------------------------------------------------*/
82
/* Return the trap number corresponding to the last-taken trap. */
83
 
84
int __get_trap_number (void)
85
{
86
    extern int CYG_LABEL_NAME(_intvector);
87
    // The vector is not not part of the GDB register set so get it
88
    // directly from the save context.
89
    return CYG_LABEL_NAME(_intvector);
90
}
91
 
92
/*--------------------------------------------------------------------*/
93
/* Set the currently-saved pc register value to PC. This also updates NPC
94
   as needed. */
95
 
96
void set_pc (target_register_t pc)
97
{
98
    put_register (PC, pc);
99
}
100
 
101
 
102
/*----------------------------------------------------------------------
103
 * Single-step support.
104
 */
105
 
106
typedef struct {
107
    unsigned short *addr;
108
    unsigned short inst;
109
} breakinfo;
110
 
111
static breakinfo InstBuffer = {(unsigned short *)-1,0};
112
 
113
/* Clear any single-step breakpoint(s) that may have been set.  */
114
 
115
void __clear_single_step (void)
116
{
117
    if ((long)InstBuffer.addr != -1L) {
118
        *InstBuffer.addr = InstBuffer.inst;
119
        InstBuffer.addr = (unsigned short *)-1;
120
    }
121
}
122
 
123
/* calculate next pc */
124
 
125
enum jump_type{none,aabs,aind,ret,reg,relb,relw};
126
 
127
/* opcode decode table define
128
   ptn: opcode pattern
129
   msk: opcode bitmask
130
   len: instruction length (<0 next table index)
131
   jmp: jump operation mode */
132
 
133
struct optable {
134
    unsigned char pattern;
135
    unsigned char mask;
136
    signed   char length;
137
    char          type;
138
} __attribute__((aligned(1),packed));
139
 
140
#define OPTABLE(ptn,msk,len,jmp) {ptn,msk,len,jmp}
141
 
142
const static struct optable optable_0[] = {
143
    OPTABLE(0x00,0xff, 1,none), /* 0x00 */
144
    OPTABLE(0x01,0xff,-1,none), /* 0x01 */
145
    OPTABLE(0x02,0xfe, 1,none), /* 0x02-0x03 */
146
    OPTABLE(0x04,0xee, 1,none), /* 0x04-0x05/0x14-0x15 */
147
    OPTABLE(0x06,0xfe, 1,none), /* 0x06-0x07 */
148
    OPTABLE(0x08,0xea, 1,none), /* 0x08-0x09/0x0c-0x0d/0x18-0x19/0x1c-0x1d */
149
    OPTABLE(0x0a,0xee, 1,none), /* 0x0a-0x0b/0x1a-0x1b */
150
    OPTABLE(0x0e,0xee, 1,none), /* 0x0e-0x0f/0x1e-0x1f */
151
    OPTABLE(0x10,0xfc, 1,none), /* 0x10-0x13 */
152
    OPTABLE(0x16,0xfe, 1,none), /* 0x16-0x17 */
153
    OPTABLE(0x20,0xe0, 1,none), /* 0x20-0x3f */
154
    OPTABLE(0x40,0xf0, 1,relb), /* 0x40-0x4f */
155
    OPTABLE(0x50,0xfc, 1,none), /* 0x50-0x53 */
156
    OPTABLE(0x54,0xfd, 1,ret ), /* 0x54/0x56 */
157
    OPTABLE(0x55,0xff, 1,relb), /* 0x55 */
158
    OPTABLE(0x57,0xff, 1,none), /* 0x57 */
159
    OPTABLE(0x58,0xfb, 2,relw), /* 0x58/0x5c */
160
    OPTABLE(0x59,0xfb, 1,reg ), /* 0x59/0x5b */
161
    OPTABLE(0x5a,0xfb, 2,aabs), /* 0x5a/0x5e */
162
    OPTABLE(0x5b,0xfb, 2,aind), /* 0x5b/0x5f */
163
    OPTABLE(0x60,0xe8, 1,none), /* 0x60-0x67/0x70-0x77 */
164
    OPTABLE(0x68,0xfa, 1,none), /* 0x68-0x69/0x6c-0x6d */
165
    OPTABLE(0x6a,0xfe,-2,none), /* 0x6a-0x6b */
166
    OPTABLE(0x6e,0xfe, 2,none), /* 0x6e-0x6f */
167
    OPTABLE(0x78,0xff, 4,none), /* 0x78 */
168
    OPTABLE(0x79,0xff, 2,none), /* 0x79 */
169
    OPTABLE(0x7a,0xff, 3,none), /* 0x7a */
170
    OPTABLE(0x7b,0xff, 2,none), /* 0x7b */
171
    OPTABLE(0x7c,0xfc, 2,none), /* 0x7c-0x7f */
172
    OPTABLE(0x80,0x80, 1,none), /* 0x80-0xff */
173
};
174
 
175
const static struct optable optable_1[] = {
176
    OPTABLE(0x00,0xff,-3,none), /* 0x0100 */
177
    OPTABLE(0x40,0xf0,-3,none), /* 0x0140-0x14f */
178
    OPTABLE(0x80,0xf0, 1,none), /* 0x0180-0x018f */
179
    OPTABLE(0xc0,0xc0, 2,none), /* 0x01c0-0x01ff */
180
};
181
 
182
const static struct optable optable_2[] = {
183
    OPTABLE(0x00,0x20, 2,none), /* 0x6a0?/0x6a8?/0x6b0?/0x6b8? */
184
    OPTABLE(0x20,0x20, 3,none), /* 0x6a2?/0x6aa?/0x6b2?/0x6ba? */
185
};
186
 
187
const static struct optable optable_3[] = {
188
    OPTABLE(0x69,0xfb, 2,none), /* 0x010069/0x01006d/014069/0x01406d */
189
    OPTABLE(0x6b,0xff,-4,none), /* 0x01006b/0x01406b */
190
    OPTABLE(0x6f,0xff, 3,none), /* 0x01006f/0x01406f */
191
    OPTABLE(0x78,0xff, 5,none), /* 0x010078/0x014078 */
192
};
193
 
194
const static struct optable optable_4[] = {
195
    OPTABLE(0x00,0x78, 3,none), /* 0x0100690?/0x01006d0?/0140690/0x01406d0?/0x0100698?/0x01006d8?/0140698?/0x01406d8? */
196
    OPTABLE(0x20,0x78, 4,none), /* 0x0100692?/0x01006d2?/0140692/0x01406d2?/0x010069a?/0x01006da?/014069a?/0x01406da? */
197
};
198
 
199
const static struct {
200
    const struct optable *op;
201
    int length;
202
} optables[] = {
203
    {optable_0,sizeof(optable_0)/sizeof(struct optable)},
204
    {optable_1,sizeof(optable_1)/sizeof(struct optable)},
205
    {optable_2,sizeof(optable_2)/sizeof(struct optable)},
206
    {optable_3,sizeof(optable_3)/sizeof(struct optable)},
207
    {optable_4,sizeof(optable_4)/sizeof(struct optable)},
208
};
209
 
210
const static unsigned char condmask[] = {
211
    0x00,0x40,0x01,0x04,0x02,0x08,0x10,0x20
212
};
213
 
214
static int isbranch(int reson)
215
{
216
    unsigned char cond = get_register(CCR);
217
    /* encode complex conditions */
218
    /* B4: N^V
219
       B5: Z|(N^V)
220
       B6: C|Z */
221
    __asm__("bld #3,%w0\n\t"
222
            "bxor #1,%w0\n\t"
223
            "bst #4,%w0\n\t"
224
            "bor #2,%w0\n\t"
225
            "bst #5,%w0\n\t"
226
            "bld #2,%w0\n\t"
227
            "bor #0,%w0\n\t"
228
            "bst #6,%w0\n\t"
229
            :"=&r"(cond):"g"(cond):"cc");
230
    cond &= condmask[reson >> 1];
231
    if (!(reson & 1))
232
        return cond == 0;
233
    else
234
        return cond != 0;
235
}
236
 
237
static unsigned short *getnextpc(unsigned short *pc)
238
{
239
    const struct optable *op;
240
    unsigned char *fetch_p;
241
    unsigned char inst;
242
    unsigned long addr;
243
    unsigned long *sp;
244
    int op_len;
245
    op = optables[0].op;
246
    op_len = optables[0].length;
247
    fetch_p = (unsigned char *)pc;
248
    inst = *fetch_p++;
249
    do {
250
        if ((inst & op->mask) == op->pattern) {
251
            if (op->length < 0) {
252
                op = optables[-op->length].op;
253
                op_len = optables[-op->length].length + 1;
254
                inst = *fetch_p++;
255
            } else {
256
                switch (op->type) {
257
                case none:
258
                    return pc + op->length;
259
                case aabs:
260
                    addr = *(unsigned long *)pc;
261
                    return (unsigned short *)(addr & 0x00ffffff);
262
                case aind:
263
                    addr = *pc & 0xff;
264
                    return (unsigned short *)(*(unsigned long *)addr);
265
                case ret:
266
                    sp = (unsigned long *)get_register(SP);
267
                    return (unsigned short *)(*(sp+3) & 0x00ffffff);
268
                case reg:
269
                    addr = get_register((*pc >> 4) & 0x07);
270
                    return (unsigned short *)addr;
271
                case relb:
272
                    if ((inst = 0x55) || isbranch(inst & 0x0f))
273
                        (unsigned char *)pc += (signed char)(*fetch_p);
274
                    return pc+1; /* skip myself */
275
                case relw:
276
                    if ((inst = 0x5c) || isbranch((*fetch_p & 0xf0) >> 4))
277
                        (unsigned char *)pc += (signed short)(*(pc+1));
278
                    return pc+2; /* skip myself */
279
                }
280
            }
281
        } else
282
            op++;
283
    } while(--op_len > 0);
284
    return NULL;
285
}
286
 
287
/* Set breakpoint(s) to simulate a single step from the current PC.  */
288
 
289
void __single_step (void)
290
{
291
    unsigned short *nextpc;
292
    nextpc = getnextpc((unsigned short *)get_register(PC));
293
    InstBuffer.addr = nextpc;
294
    InstBuffer.inst = *nextpc;
295
    *nextpc = HAL_BREAKINST;
296
}
297
 
298
void __install_breakpoints (void)
299
{
300
    /* NOP since single-step HW exceptions are used instead of
301
       breakpoints. */
302
}
303
 
304
void __clear_breakpoints (void)
305
{
306
 
307
}
308
 
309
 
310
/* If the breakpoint we hit is in the breakpoint() instruction, return a
311
   non-zero value. */
312
 
313
externC void CYG_LABEL_NAME(breakinst)(void);
314
int
315
__is_breakpoint_function ()
316
{
317
    return get_register (PC) == (target_register_t)&CYG_LABEL_NAME(breakinst);
318
}
319
 
320
 
321
/* Skip the current instruction. */
322
/* only TRAPA instruction */
323
 
324
void __skipinst (void)
325
{
326
    put_register (PC, get_register(PC) + 2);
327
}
328
 
329
#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.