summaryrefslogtreecommitdiff
path: root/ecos/packages/cygmon/current/misc/arm/arm-mon.c
blob: 3ca895c72b71405ad7c62fccf13ba093b5a3af2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//==========================================================================
//
//      arm-mon.c
//
//      Support code to extend the generic monitor code to support
//      ARM(R) processors.
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
// -------------------------------------------                              
// This file is part of eCos, the Embedded Configurable Operating System.   
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under    
// the terms of the GNU General Public License as published by the Free     
// Software Foundation; either version 2 or (at your option) any later      
// version.                                                                 
//
// eCos is distributed in the hope that it will be useful, but WITHOUT      
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
// for more details.                                                        
//
// You should have received a copy of the GNU General Public License        
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
//
// As a special exception, if other files instantiate templates or use      
// macros or inline functions from this file, or you compile this file      
// and link it with other works to produce a work based on this file,       
// this file does not by itself cause the resulting work to be covered by   
// the GNU General Public License. However the source code for this file    
// must still be made available in accordance with section (3) of the GNU   
// General Public License v2.                                               
//
// This exception does not invalidate any other reasons why a work based    
// on this file might be covered by the GNU General Public License.         
// -------------------------------------------                              
// ####ECOSGPLCOPYRIGHTEND####                                              
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    
// Contributors: gthomas
// Date:         1999-10-20
// Purpose:      Support code to extend the generic monitor code to support
//               ARM(R) processors.
// Description:  Further board specific support is in other files.
//               This file contains:
//                 register names lookup table
//
//               Empty Stubs:
//                 Interval timer - This should really belong to the application
//                 operating system.
//
//               Should not contain:
//                 low level uart getchar and putchar functions
//                 delay function to support uart
//
//               ARM is a Registered Trademark of Advanced RISC Machines
//               Limited.
//               Other Brands and Trademarks are the property of their
//               respective owners.               
//
//####DESCRIPTIONEND####
//
//=========================================================================

#include <setjmp.h>
#include <bsp/bsp.h>
#include <bsp/cpu.h>
#ifdef DISASSEMBLER
#include <dis-asm.h>
#endif

#include "cpu_info.h"
#include "monitor.h"

/* This module is required to provide many of the services defined
   in tservice.h */

static char *apcs_names[] = {
  "a1", "a2", "a3", "a4",
  "v1", "v2", "v3", "v4",
  "v5", "v6", "sl", "fp",
  "ip", "sp", "lr", "pc",
#if HAVE_FLOAT_REGS
  "f0", "f1", "f2", "f3",
  "f4", "f5", "f6", "f7",
  "fps",
#endif
  "ps"
};

static char *standard_names[] =
{
  "r0",  "r1",  "r2",  "r3",
  "r4",  "r5",  "r6",  "r7",
  "r8",  "r9",  "r10", "r11",
  "r12", "r13", "r14", "pc",
#if HAVE_FLOAT_REGS
  "f0",  "f1",  "f2",  "f3",
  "f4",  "f5",  "f6",  "f7",
  "fps",
#endif
  "ps",
};


void arm_othernames (void);

struct regstruct regtab[] =
{
  { 0, REG_R0,   REGTYPE_INT   },
  { 0, REG_R1,   REGTYPE_INT   },
  { 0, REG_R2,   REGTYPE_INT   },
  { 0, REG_R3,   REGTYPE_INT   },
  { 0, REG_R4,   REGTYPE_INT   },
  { 0, REG_R5,   REGTYPE_INT   },
  { 0, REG_R6,   REGTYPE_INT   },
  { 0, REG_R7,   REGTYPE_INT   },
  { 0, REG_R8,   REGTYPE_INT   },
  { 0, REG_R9,   REGTYPE_INT   },
  { 0, REG_R10,  REGTYPE_INT   },
  { 0, REG_R11,  REGTYPE_INT   },
  { 0, REG_R12,  REGTYPE_INT   },
  { 0, REG_SP,   REGTYPE_INT   },
  { 0, REG_LR,   REGTYPE_INT   },
  { 0, REG_PC,   REGTYPE_INT   },
#if HAVE_FLOAT_REGS
  { 0, REG_F0,   REGTYPE_FLOAT },
  { 0, REG_F1,   REGTYPE_FLOAT },
  { 0, REG_F2,   REGTYPE_FLOAT },
  { 0, REG_F3,   REGTYPE_FLOAT },
  { 0, REG_F4,   REGTYPE_FLOAT },
  { 0, REG_F5,   REGTYPE_FLOAT },
  { 0, REG_F6,   REGTYPE_FLOAT },
  { 0, REG_F6,   REGTYPE_FLOAT },
  { 0, REG_FPS,  REGTYPE_FLOAT },
#endif
  { 0, REG_CPSR, REGTYPE_INT   },
  { 0, 0,        0             } /* Terminating element must be last */
} ;

void
initialize_mon(void)
{
  /* FIXME: Convert ALL variable initializations to assignments
     in order to support ROMABLE CODE.
     This includes the register table
     */

  /*
   * Call arm_othernames to sync up Cygmon and the disassembler
   * and ensure they are using the same set of registernames
   */
  arm_othernames();

  /*
   * Call arm_othernames again to revert to the assembler
   * default names
   */
  arm_othernames();

} /* initialize_mon */


/*
  read_memory
  write_memory
       Defaults to generic_mem.c
       */


/* SET_BREAKPOINT -
   CLEAR_BREAKPOINT
   Defaults to generic_bp32.c
   */


#ifndef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS

/* Return the currently-saved value corresponding to register "regnum". */
target_regval_t
get_register (int regnum)
{
    struct regstruct *p;
    target_regval_t reg;
    int   offset, len;
    char  *dest = (char*)0;

    for (p = regtab; p->registername && p->registernumber != regnum; ++p)
	;

    if (p->registername) {
	len = bsp_regsize(p->registernumber);
	offset = bsp_regbyte(p->registernumber);
	switch (p->registertype) {
	  case REGTYPE_INT:
	    dest = (char*)&(reg.i);
	    break;
#if HAVE_FLOAT_REGS
        case REGTYPE_FLOAT:
	    dest = (char*)&(reg.f);
	    break;
#endif
#if HAVE_DOUBLE_REGS
        case REGTYPE_DOUBLE:
	    dest = (char*)&(reg.d);
	    break;
#endif
	}
        if (dest)
            memcpy(dest, (char *)mon_saved_regs + offset, len);
    } else
	reg.i = 0;

    return reg;
}



/* Store VALUE in the register corresponding to REGNUM. */
void
put_register (int regnum, target_regval_t value)
{
    int   offset, len;

    len = bsp_regsize(regnum);
    offset = bsp_regbyte(regnum);
    memcpy((char *)mon_saved_regs + offset, &value, len);
}

#endif // !CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS

/* Change to the alternate register set names */
void
arm_othernames (void)
{
    static int regset = 1;
    char **name;
    int  i;

#ifdef DISASSEMBLER
    /* Change the disassembler */
    regset = arm_toggle_regnames();
#else
    regset = (regset == 0) ? 1 : 0;
#endif

    /* Change cygmon */
    if (regset == 1)
        /* Disassembler is using apcs names. */
        name = apcs_names;
    else
        /* Disassembler is using standard names. */
        name = standard_names;

    for (i = 0; i < (sizeof(apcs_names)/sizeof(apcs_names[0])); i++)
	regtab[i].registername = name[i];
}

#ifdef __ECOS__

#include <pkgconf/hal.h>
#include <cyg/hal/hal_arch.h>
#include "bsp/common/bsp_if.h"

int
machine_syscall(HAL_SavedRegisters *regs)
{
    int res, err;
    err = _bsp_do_syscall(regs->d[0], // Function
                          regs->d[1], regs->d[2], regs->d[3], 0, // arguments,
                          &res);
    regs->d[0] = res;
    regs->pc += 4;  // Advance PC
    return err;
}
#endif