1 #ifndef CYGONCE_HAL_HAL_STUB_H
2 #define CYGONCE_HAL_HAL_STUB_H
4 //=============================================================================
8 // HAL header for GDB stub support.
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //=============================================================================
44 //#####DESCRIPTIONBEGIN####
49 // Purpose: Generic HAL stub header.
50 // Usage: #include <cyg/hal/hal_stub.h>
51 // Description: This header is included by generic-stub.c to provide an
52 // interface to the eCos-specific stub implementation. It is
53 // not to be included by user code, and is only placed in a
54 // publically accessible directory so that platform stub packages
55 // are able to include it if required.
57 //####DESCRIPTIONEND####
59 //=============================================================================
61 #include <pkgconf/hal.h>
63 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
64 #define USE_GDBSTUB_PROTOTYPES 0 // avoid stub-tservice.h atm
66 #define __ECOS__ // use to mark eCos hacks
69 #include <cyg/hal/basetype.h> // HAL_LABEL_NAME
70 #include <cyg/hal/hal_arch.h> // HAL header
71 #include <cyg/infra/cyg_type.h> // cyg_uint32 and CYG_BYTEORDER
73 #ifndef __CYGMON_TYPES
74 #define __CYGMON_TYPES
75 typedef cyg_uint32 uint32;
76 typedef cyg_int32 int32;
77 #endif // __CYGMON_TYPES
79 #ifdef CYGBLD_HAL_PLATFORM_STUB_H
80 #include CYGBLD_HAL_PLATFORM_STUB_H
82 #include <cyg/hal/plf_stub.h>
84 #include <cyg/hal/generic-stub.h>
90 } // to make below format correctly.
93 //-----------------------------------------------------------------------------
94 // Definitions for generic-stub.c
96 #define __set_mem_fault_trap(x) ({__mem_fault = 0; x(); __mem_fault;})
98 #if (CYG_BYTEORDER==CYG_LSBFIRST)
99 # if !defined(__LITTLE_ENDIAN__)
100 # define __LITTLE_ENDIAN__
102 # if !defined(_LITTLE_ENDIAN)
103 # define _LITTLE_ENDIAN
107 //-----------------------------------------------------------------------------
108 // Dummy definitions for harvard memory support for princeton memory systems.
109 #ifndef TARGET_HAS_HARVARD_MEMORY
110 typedef target_register_t target_addr_t;
111 #define TARGET_ADDR_IS_PROGMEM(x) 0
112 #define TARGET_ADDR_TO_PTR(x) ((char *) (x))
115 //----------------------------------------------------------------------------
116 // Signal definitions to avoid 'signal.h'/
117 #define SIGHUP 1 /* hangup */
118 #define SIGINT 2 /* interrupt */
119 #define SIGQUIT 3 /* quit */
120 #define SIGILL 4 /* illegal instruction (not reset when caught) */
121 #define SIGTRAP 5 /* trace trap (not reset when caught) */
122 #define SIGIOT 6 /* IOT instruction */
123 #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
124 #define SIGEMT 7 /* EMT instruction */
125 #define SIGFPE 8 /* floating point exception */
126 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
127 #define SIGBUS 10 /* bus error */
128 #define SIGSEGV 11 /* segmentation violation */
129 #define SIGSYS 12 /* bad argument to system call */
130 #define SIGPIPE 13 /* write on a pipe with no one to read it */
131 #define SIGALRM 14 /* alarm clock */
132 #define SIGTERM 15 /* software termination signal from kill */
134 //----------------------------------------------------------------------------
135 // Thread support. This setting is used in thread-pkts.h
136 #ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
137 #define DEBUG_THREADS 1
139 #define DEBUG_THREADS 0
142 // The function stub_copy_registers() is statically defined in
143 // thread-packets.c, but in eCos this external stub is defined as it
144 // is used in dbg_gdb.cxx.
145 externC void __stub_copy_registers(target_register_t *dest,
146 target_register_t *src);
148 //----------------------------------------------------------------------------
149 // Hardware Watch/Breakpoint support. These are the possible return values
150 // of HAL_STUB_IS_STOPPED_BY_HARDWARE().
151 #define HAL_STUB_HW_STOP_NONE 0 // target did not stop for hw watch/break
152 #define HAL_STUB_HW_STOP_BREAK 1 // target stopped for hw breakpoint
153 #define HAL_STUB_HW_STOP_WATCH 2 // target stopped for write-only watchpoint
154 #define HAL_STUB_HW_STOP_RWATCH 3 // target stopped for read-only watchpoint
155 #define HAL_STUB_HW_STOP_AWATCH 4 // target stopped for access watchpoint
157 //----------------------------------------------------------------------------
158 // Memory accessor functions.
159 #define TARGET_HAS_OWN_MEM_FUNCS
161 //----------------------------------------------------------------------------
162 // Memory access checks.
164 #ifndef CYG_HAL_STUB_PERMIT_DATA_READ
165 #define CYG_HAL_STUB_PERMIT_DATA_READ(_addr_, __count_) (1)
168 #ifndef CYG_HAL_STUB_PERMIT_DATA_WRITE
169 #define CYG_HAL_STUB_PERMIT_DATA_WRITE(_addr_, __count_) (1)
172 #ifdef TARGET_HAS_HARVARD_MEMORY
174 #ifndef CYG_HAL_STUB_PERMIT_CODE_READ
175 #define CYG_HAL_STUB_PERMIT_CODE_READ(_addr_, __count_) (1)
178 #ifndef CYG_HAL_STUB_PERMIT_CODE_WRITE
179 #define CYG_HAL_STUB_PERMIT_CODE_WRITE(_addr_, __count_) (1)
184 //----------------------------------------------------------------------------
186 extern int __process_target_query(char * pkt, char * out, int maxOut);
187 extern int __process_target_set(char * pkt, char * out, int maxout);
188 extern int __process_target_packet(char * pkt, char * out, int maxout);
190 //---------------------------------------------------------------------------
191 // Declarations to avoid compiler warnings.
193 // Set the baud rate for the current serial port.
194 extern void __set_baud_rate (int baud);
196 // Write C to the current serial port.
197 extern void putDebugChar (int c);
199 // Read one character from the current serial port.
200 extern int getDebugChar (void);
202 // Push CH back onto the debug stream.
203 extern void ungetDebugChar (int ch);
206 extern void __reset (void);
209 #ifndef __set_breakpoint
210 extern int __set_breakpoint (target_register_t addr, target_register_t len);
212 #ifndef __remove_breakpoint
213 extern int __remove_breakpoint (target_register_t addr, target_register_t len);
215 #ifndef __set_hw_breakpoint
216 extern int __set_hw_breakpoint (target_register_t addr, target_register_t len);
218 #ifndef __remove_hw_breakpoint
219 extern int __remove_hw_breakpoint (target_register_t addr, target_register_t len);
221 #ifndef __set_hw_watchpoint
222 extern int __set_hw_watchpoint (target_register_t addr, target_register_t len, int ztype);
224 #ifndef __remove_hw_watchpoint
225 extern int __remove_hw_watchpoint (target_register_t addr, target_register_t len, int ztype);
228 /* Install the standard set of trap handlers for the stub. */
229 extern void __install_traps (void);
231 /* Address in text section of a breakpoint instruction. */
233 #ifndef BREAKINST_DEFINED
234 #define BREAKINST_DEFINED
235 extern void _breakinst (void);
238 /* The opcode for a breakpoint instruction. */
240 extern unsigned long __break_opcode (void);
242 /* Function to flush output buffers */
243 extern void hal_flush_output(void);
245 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
246 // This one may assume a valid saved interrupt context on some platforms
247 extern void cyg_hal_gdb_interrupt (target_register_t pc);
248 // This one does not; use from CRITICAL_IO_REGION macros below.
249 extern void cyg_hal_gdb_place_break (target_register_t pc);
250 // Remove a break from either above - or not if cyg_hal_gdb_running_step
251 extern int cyg_hal_gdb_remove_break (target_register_t pc);
252 // Bool: is such a breakpoint set?
253 extern int cyg_hal_gdb_break_is_set (void);
255 /* This is used so that the generic stub can tell
256 * cyg_hal_gdb_remove_break() not to bother when we are avoiding stepping
257 * through a critical region ie. hal_diag_write_char() usually - that
258 * shares the GDB IO device.
260 extern volatile int cyg_hal_gdb_running_step;
262 // Use these in hal_diag.c when about to write a whole $O packet to GDB.
263 // NB they require __builtin_return_address() to work: if your platform
264 // does not support this, use HAL_DISABLE_INTERRUPTS &c instead.
266 #if 1 // Can use the address of a label: this is more portable
268 // This macro may already have been defined by the architecture HAL
269 #ifndef CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION
270 #define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ ) \
272 HAL_DISABLE_INTERRUPTS(_old_); \
273 cyg_hal_gdb_place_break( (target_register_t)&&cyg_hal_gdb_break_place ); \
277 // This macro may already have been defined by the architecture HAL
278 // Notice the trick to *use* the label - sometimes the tools want to
279 // move the label if unused, which is bad.
280 #ifndef CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION
281 #define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ ) \
283 cyg_hal_gdb_remove_break( (target_register_t)&&cyg_hal_gdb_break_place ); \
284 HAL_RESTORE_INTERRUPTS(_old_); \
285 _old_ = 1; /* actually use the label as a label... */ \
286 cyg_hal_gdb_break_place:; \
287 if ( (_old_)-- > 0 ) /* ...or the compiler might move it! */ \
288 goto cyg_hal_gdb_break_place; \
292 #else // use __builtin_return_address instead.
294 #define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ ) \
296 HAL_DISABLE_INTERRUPTS(_old_); \
297 cyg_hal_gdb_place_break((target_register_t)__builtin_return_address(0)); \
300 #define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ ) \
302 cyg_hal_gdb_remove_break((target_register_t)__builtin_return_address(0)); \
303 HAL_RESTORE_INTERRUPTS(_old_); \
308 #else // NO debug_gdb_break_support
310 // so define these just to do interrupts:
311 #define CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION( _old_ ) \
313 HAL_DISABLE_INTERRUPTS(_old_); \
316 #define CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION( _old_ ) \
318 HAL_RESTORE_INTERRUPTS(_old_); \
323 //----------------------------------------------------------------------------
324 // eCos extensions to the stub
326 extern void hal_output_gdb_string(target_register_t str, int string_len);
328 extern target_register_t registers[]; // The current saved registers.
329 extern target_register_t * _registers ;
330 extern HAL_SavedRegisters *_hal_registers;
332 extern int cyg_hal_gdb_break;
334 #ifdef CYGPKG_ISOINFRA
335 # include <pkgconf/isoinfra.h>
337 #ifdef CYGINT_ISO_STRING_STRFUNCS
340 //-----------------------------------------------------------------------------
341 // String helpers. These really should come from ISOINFRA
342 static inline char *strcpy( char *s, const char *t)
346 while( *t ) *s++ = *t++;
348 // Terminate the copied string.
354 static inline size_t strlen( const char *s )
362 //-----------------------------------------------------------------------------
363 // Repeat the cache definitions here to avoid too much hackery in
365 /* Flush the instruction cache. */
366 extern void flush_i_cache (void);
368 /* Flush the data cache. */
369 extern void __flush_d_cache (void);
372 CACHE_NOOP, CACHE_ENABLE, CACHE_DISABLE, CACHE_FLUSH
375 /* Perform the specified operation on the instruction cache.
376 Returns 1 if the cache is enabled, 0 otherwise. */
377 extern int __instruction_cache (cache_control_t request);
378 /* Perform the specified operation on the data cache.
379 Returns 1 if the cache is enabled, 0 otherwise. */
380 extern int __data_cache (cache_control_t request);
386 #endif // ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
388 //-----------------------------------------------------------------------------
389 #endif // CYGONCE_HAL_HAL_STUB_H