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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [common/] [current/] [include/] [hal_stub.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_HAL_STUB_H
2
#define CYGONCE_HAL_HAL_STUB_H
3
 
4
//=============================================================================
5
//
6
//      hal_stub.h
7
//
8
//      HAL header for GDB stub support.
9
//
10
//=============================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
12
// -------------------------------------------                              
13
// This file is part of eCos, the Embedded Configurable Operating System.   
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2008 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under    
17
// the terms of the GNU General Public License as published by the Free     
18
// Software Foundation; either version 2 or (at your option) any later      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   jskov
46
// Contributors:jskov
47
// Date:        1999-02-12
48
// Purpose:     Generic HAL stub header.
49
// Usage:       #include <cyg/hal/hal_stub.h>
50
// Description: This header is included by generic-stub.c to provide an
51
//              interface to the eCos-specific stub implementation. It is
52
//              not to be included by user code, and is only placed in a
53
//              publically accessible directory so that platform stub packages
54
//              are able to include it if required.
55
//                           
56
//####DESCRIPTIONEND####
57
//
58
//=============================================================================
59
 
60
#include <pkgconf/hal.h>
61
 
62
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
63
#define USE_GDBSTUB_PROTOTYPES 0        // avoid stub-tservice.h atm
64
#ifndef __ECOS__
65
#define __ECOS__                        // use to mark eCos hacks
66
#endif
67
 
68
#include <cyg/hal/basetype.h>           // HAL_LABEL_NAME
69
#include <cyg/hal/hal_arch.h>           // HAL header
70
#include <cyg/infra/cyg_type.h>         // cyg_uint32 and CYG_BYTEORDER
71
 
72
#ifndef __CYGMON_TYPES
73
#define __CYGMON_TYPES
74
typedef cyg_uint32 uint32;
75
typedef cyg_int32  int32;
76
#endif // __CYGMON_TYPES
77
 
78
#ifdef CYGBLD_HAL_PLATFORM_STUB_H
79
#include CYGBLD_HAL_PLATFORM_STUB_H
80
#else
81
#include <cyg/hal/plf_stub.h>
82
#endif
83
#include <cyg/hal/generic-stub.h>
84
 
85
#ifdef __cplusplus
86
extern "C" {
87
#endif
88
#if 0
89
} // to make below format correctly.
90
#endif
91
 
92
//-----------------------------------------------------------------------------
93
// Definitions for generic-stub.c
94
 
95
#define __set_mem_fault_trap(x) ({__mem_fault = 0; x(); __mem_fault;})
96
 
97
#if (CYG_BYTEORDER==CYG_LSBFIRST)
98
# if !defined(__LITTLE_ENDIAN__)
99
#  define __LITTLE_ENDIAN__
100
# endif
101
# if !defined(_LITTLE_ENDIAN)
102
#  define _LITTLE_ENDIAN
103
# endif
104
#endif
105
 
106
//-----------------------------------------------------------------------------
107
// Dummy definitions for harvard memory support for princeton memory systems.
108
#ifndef TARGET_HAS_HARVARD_MEMORY
109
typedef target_register_t target_addr_t;
110
#define TARGET_ADDR_IS_PROGMEM(x) 0
111
#define TARGET_ADDR_TO_PTR(x)     ((char *) (x))
112
#endif
113
 
114
//----------------------------------------------------------------------------
115
// Signal definitions to avoid 'signal.h'/
116
#define SIGHUP  1       /* hangup */
117
#define SIGINT  2       /* interrupt */
118
#define SIGQUIT 3       /* quit */
119
#define SIGILL  4       /* illegal instruction (not reset when caught) */
120
#define SIGTRAP 5       /* trace trap (not reset when caught) */
121
#define SIGIOT  6       /* IOT instruction */
122
#define SIGABRT 6       /* used by abort, replace SIGIOT in the future */
123
#define SIGEMT  7       /* EMT instruction */
124
#define SIGFPE  8       /* floating point exception */
125
#define SIGKILL 9       /* kill (cannot be caught or ignored) */
126
#define SIGBUS  10      /* bus error */
127
#define SIGSEGV 11      /* segmentation violation */
128
#define SIGSYS  12      /* bad argument to system call */
129
#define SIGPIPE 13      /* write on a pipe with no one to read it */
130
#define SIGALRM 14      /* alarm clock */
131
#define SIGTERM 15      /* software termination signal from kill */
132
 
133
//----------------------------------------------------------------------------
134
// Thread support. This setting is used in thread-pkts.h
135
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
136
#define DEBUG_THREADS 1
137
#else
138
#define DEBUG_THREADS 0
139
#endif
140
 
141
// The function stub_copy_registers() is statically defined in
142
// thread-packets.c, but in eCos this external stub is defined as it
143
// is used in dbg_gdb.cxx.
144
externC void __stub_copy_registers(target_register_t *dest,
145
                                   target_register_t *src);
146
 
147
//----------------------------------------------------------------------------
148
// Hardware Watch/Breakpoint support. These are the possible return values
149
// of HAL_STUB_IS_STOPPED_BY_HARDWARE().
150
#define HAL_STUB_HW_STOP_NONE   0   // target did not stop for hw watch/break
151
#define HAL_STUB_HW_STOP_BREAK  1   // target stopped for hw breakpoint
152
#define HAL_STUB_HW_STOP_WATCH  2   // target stopped for write-only watchpoint
153
#define HAL_STUB_HW_STOP_RWATCH 3   // target stopped for read-only watchpoint
154
#define HAL_STUB_HW_STOP_AWATCH 4   // target stopped for access watchpoint
155
 
156
//----------------------------------------------------------------------------
157
// Memory accessor functions.
158
#define TARGET_HAS_OWN_MEM_FUNCS
159
 
160
//----------------------------------------------------------------------------
161
// Memory access checks. 
162
 
163
#ifndef CYG_HAL_STUB_PERMIT_DATA_READ
164
#define CYG_HAL_STUB_PERMIT_DATA_READ(_addr_, __count_) (1)
165
#endif
166
 
167
#ifndef CYG_HAL_STUB_PERMIT_DATA_WRITE
168
#define CYG_HAL_STUB_PERMIT_DATA_WRITE(_addr_, __count_) (1)
169
#endif
170
 
171
#ifdef TARGET_HAS_HARVARD_MEMORY
172
 
173
#ifndef CYG_HAL_STUB_PERMIT_CODE_READ
174
#define CYG_HAL_STUB_PERMIT_CODE_READ(_addr_, __count_) (1)
175
#endif
176
 
177
#ifndef CYG_HAL_STUB_PERMIT_CODE_WRITE
178
#define CYG_HAL_STUB_PERMIT_CODE_WRITE(_addr_, __count_) (1)
179
#endif
180
 
181
#endif
182
 
183
//----------------------------------------------------------------------------
184
// Target extras?!
185
extern int __process_target_query(char * pkt, char * out, int maxOut);
186
extern int __process_target_set(char * pkt, char * out, int maxout);
187
extern int __process_target_packet(char * pkt, char * out, int maxout);
188
 
189
//---------------------------------------------------------------------------
190
// Declarations to avoid compiler warnings.
191
 
192
// Set the baud rate for the current serial port.
193
extern void __set_baud_rate (int baud);
194
 
195
// Write C to the current serial port.
196
extern void putDebugChar (int c);
197
 
198
// Read one character from the current serial port.
199
extern int getDebugChar (void);
200
 
201
// Push CH back onto the debug stream.
202
extern void ungetDebugChar (int ch);
203
 
204
// Reset the board.
205
extern void __reset (void);
206
 
207
// Multi-bp support.
208
#ifndef __set_breakpoint
209
extern int __set_breakpoint (target_register_t addr, target_register_t len);
210
#endif
211
#ifndef __remove_breakpoint
212
extern int __remove_breakpoint (target_register_t addr, target_register_t len);
213
#endif
214
#ifndef __set_hw_breakpoint
215
extern int __set_hw_breakpoint (target_register_t addr, target_register_t len);
216
#endif
217
#ifndef __remove_hw_breakpoint
218
extern int __remove_hw_breakpoint (target_register_t addr, target_register_t len);
219
#endif
220
#ifndef __set_hw_watchpoint
221
extern int __set_hw_watchpoint (target_register_t addr, target_register_t len, int ztype);
222
#endif
223
#ifndef __remove_hw_watchpoint
224
extern int __remove_hw_watchpoint (target_register_t addr, target_register_t len, int ztype);
225
#endif
226
 
227
/* Install the standard set of trap handlers for the stub. */
228
extern void __install_traps (void);
229
 
230
/* Address in text section of a breakpoint instruction.  */
231
 
232
#ifndef BREAKINST_DEFINED
233
#define BREAKINST_DEFINED
234
extern void _breakinst (void);
235
#endif
236
 
237
/* The opcode for a breakpoint instruction.  */
238
 
239
extern unsigned long __break_opcode (void);
240
 
241
/* Function to flush output buffers */
242
extern void hal_flush_output(void);
243
 
244
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
245
// This one may assume a valid saved interrupt context on some platforms
246
extern void cyg_hal_gdb_interrupt    (target_register_t pc);
247
// This one does not; use from CRITICAL_IO_REGION macros below.
248
extern void cyg_hal_gdb_place_break  (target_register_t pc);
249
// Remove a break from either above - or not if cyg_hal_gdb_running_step
250
extern int  cyg_hal_gdb_remove_break (target_register_t pc);
251
// Bool: is such a breakpoint set?
252
extern int  cyg_hal_gdb_break_is_set (void);
253
 
254
/* This is used so that the generic stub can tell
255
 * cyg_hal_gdb_remove_break() not to bother when we are avoiding stepping
256
 * through a critical region ie. hal_diag_write_char() usually - that
257
 * shares the GDB IO device.
258
 */
259
extern volatile int cyg_hal_gdb_running_step;
260
 
261
// Use these in hal_diag.c when about to write a whole $O packet to GDB.
262
// NB they require __builtin_return_address() to work: if your platform
263
// does not support this, use HAL_DISABLE_INTERRUPTS &c instead.
264
// These are used to ensure the user's GDB cannot step through the critical
265
// region, causing everything to go horribly wrong - particularly likely
266
// with watching variables. Instead it will magically skip over the region.
267
 
268
#if 1 // Can use the address of a label: this is more portable
269
 
270
// This macro may already have been defined by the architecture HAL
271
#ifndef CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION
272
#define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ )                        \
273
do {                                                                         \
274
    HAL_DISABLE_INTERRUPTS(_old_);                                           \
275
    cyg_hal_gdb_place_break( (target_register_t)&&cyg_hal_gdb_break_place ); \
276
} while ( 0 )
277
#endif
278
 
279
// This macro may already have been defined by the architecture HAL
280
// Notice the trick to *use* the label - sometimes the tools want to
281
// move the label if unused, which is bad.
282
#ifndef CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION
283
#define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ )                         \
284
do {                                                                          \
285
    cyg_hal_gdb_remove_break( (target_register_t)&&cyg_hal_gdb_break_place ); \
286
    HAL_RESTORE_INTERRUPTS(_old_);                                            \
287
    /* The following is solely to provide the label without the compiler      \
288
     * optimising it away. By referencing an external function, it can't      \
289
     * remove or reorder it. And because we have just called                  \
290
     * cyg_hal_gdb_remove_break(), we know cyg_hal_gdb_break_is_set() will    \
291
     * return 0.                                                              \
292
     */                                                                       \
293
cyg_hal_gdb_break_place:;                                                     \
294
    if ( cyg_hal_gdb_break_is_set() ) /* ...or the compiler might move it! */ \
295
        goto cyg_hal_gdb_break_place;                                         \
296
} while ( 0 )
297
#endif
298
 
299
#else // use __builtin_return_address instead.
300
 
301
#define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ )                        \
302
do {                                                                         \
303
    HAL_DISABLE_INTERRUPTS(_old_);                                           \
304
    cyg_hal_gdb_place_break((target_register_t)__builtin_return_address(0)); \
305
} while ( 0 )
306
 
307
#define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ )                         \
308
do {                                                                          \
309
    cyg_hal_gdb_remove_break((target_register_t)__builtin_return_address(0)); \
310
    HAL_RESTORE_INTERRUPTS(_old_);                                            \
311
} while ( 0 )
312
 
313
#endif
314
 
315
#else // NO debug_gdb_break_support
316
 
317
// so define these just to do interrupts:
318
#define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ )   \
319
do {                                                    \
320
    HAL_DISABLE_INTERRUPTS(_old_);                      \
321
} while (0);
322
 
323
#define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ )   \
324
do {                                                    \
325
    HAL_RESTORE_INTERRUPTS(_old_);                      \
326
} while (0);
327
 
328
#endif
329
 
330
//----------------------------------------------------------------------------
331
// eCos extensions to the stub
332
 
333
extern void hal_output_gdb_string(target_register_t str, int string_len);
334
 
335
extern target_register_t registers[];   // The current saved registers.
336
extern target_register_t * _registers ;
337
extern HAL_SavedRegisters *_hal_registers;
338
 
339
extern int cyg_hal_gdb_break;
340
 
341
#ifdef CYGPKG_ISOINFRA
342
# include <pkgconf/isoinfra.h>
343
#endif
344
#ifdef CYGINT_ISO_STRING_STRFUNCS
345
# include <string.h>
346
#else
347
//-----------------------------------------------------------------------------
348
// String helpers. These really should come from ISOINFRA
349
static inline char *strcpy( char *s, const char *t)
350
{
351
    char *r = s;
352
 
353
    while( *t ) *s++ = *t++;
354
 
355
    // Terminate the copied string.
356
    *s = 0;
357
 
358
    return r;
359
}
360
 
361
static inline size_t strlen( const char *s )
362
{
363
    int r = 0;
364
    while( *s++ ) r++;
365
    return r;
366
}
367
#endif
368
 
369
//-----------------------------------------------------------------------------
370
// Repeat the cache definitions here to avoid too much hackery in 
371
// generic-stub.h
372
/* Flush the instruction cache. */
373
extern void flush_i_cache (void);
374
 
375
/* Flush the data cache. */
376
extern void __flush_d_cache (void);
377
 
378
typedef enum {
379
  CACHE_NOOP, CACHE_ENABLE, CACHE_DISABLE, CACHE_FLUSH
380
} cache_control_t;
381
 
382
/* Perform the specified operation on the instruction cache.
383
   Returns 1 if the cache is enabled, 0 otherwise. */
384
extern int __instruction_cache (cache_control_t request);
385
/* Perform the specified operation on the data cache.
386
   Returns 1 if the cache is enabled, 0 otherwise. */
387
extern int __data_cache (cache_control_t request);
388
 
389
#ifdef __cplusplus
390
} // extern "C"
391
#endif
392
 
393
#endif // ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
394
 
395
//-----------------------------------------------------------------------------
396
#endif // CYGONCE_HAL_HAL_STUB_H
397
// End of hal_stub.h

powered by: WebSVN 2.1.0

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