1 |
27 |
unneback |
//=============================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_if.c
|
4 |
|
|
//
|
5 |
|
|
// ROM/RAM interfacing functions
|
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 |
|
|
// Copyright (C) 2002 Gary Thomas
|
13 |
|
|
//
|
14 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
15 |
|
|
// the terms of the GNU General Public License as published by the Free
|
16 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
19 |
|
|
// 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 along
|
24 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
28 |
|
|
// or inline functions from this file, or you compile this file and link it
|
29 |
|
|
// with other works to produce a work based on this file, this file does not
|
30 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
31 |
|
|
// License. However the source code for this file must still be made available
|
32 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
33 |
|
|
//
|
34 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
35 |
|
|
// this file might be covered by the GNU General Public License.
|
36 |
|
|
//
|
37 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
38 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//=============================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): jskov
|
45 |
|
|
// Contributors:jskov
|
46 |
|
|
// Date: 2000-06-07
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//=============================================================================
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/hal.h>
|
53 |
|
|
|
54 |
|
|
#ifdef CYGPKG_KERNEL
|
55 |
|
|
# include <pkgconf/kernel.h>
|
56 |
|
|
#endif
|
57 |
|
|
|
58 |
|
|
#include <cyg/infra/cyg_ass.h> // assertions
|
59 |
|
|
|
60 |
|
|
#include <cyg/hal/hal_arch.h> // set/restore GP
|
61 |
|
|
|
62 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
63 |
|
|
#include <cyg/hal/hal_if.h> // our interface
|
64 |
|
|
|
65 |
|
|
#include <cyg/hal/hal_diag.h> // Diag IO
|
66 |
|
|
#include <cyg/hal/hal_misc.h> // User break
|
67 |
|
|
|
68 |
|
|
#include <cyg/hal/hal_stub.h> // stub functionality
|
69 |
|
|
|
70 |
|
|
#include <cyg/hal/hal_intr.h> // hal_vsr_table and others
|
71 |
|
|
|
72 |
|
|
#ifdef CYGPKG_REDBOOT
|
73 |
|
|
#include <pkgconf/redboot.h>
|
74 |
|
|
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
|
75 |
|
|
#include <redboot.h>
|
76 |
|
|
#include <flash_config.h>
|
77 |
|
|
#endif
|
78 |
|
|
#endif
|
79 |
|
|
|
80 |
|
|
//--------------------------------------------------------------------------
|
81 |
|
|
|
82 |
|
|
externC void patch_dbg_syscalls(void * vector);
|
83 |
|
|
externC void init_thread_syscall(void * vector);
|
84 |
|
|
|
85 |
|
|
//--------------------------------------------------------------------------
|
86 |
|
|
// Implementations and function wrappers for monitor services
|
87 |
|
|
|
88 |
|
|
// flash config state queries
|
89 |
|
|
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
|
90 |
|
|
|
91 |
|
|
static __call_if_flash_cfg_op_fn_t flash_config_op;
|
92 |
|
|
|
93 |
|
|
static cyg_bool
|
94 |
|
|
flash_config_op( int op, char * key, void *val, int type)
|
95 |
|
|
{
|
96 |
|
|
cyg_bool res = false;
|
97 |
|
|
|
98 |
|
|
CYGARC_HAL_SAVE_GP();
|
99 |
|
|
|
100 |
|
|
switch ( op ) {
|
101 |
|
|
case CYGNUM_CALL_IF_FLASH_CFG_GET:
|
102 |
|
|
res = flash_get_config( key, val, type );
|
103 |
|
|
break;
|
104 |
|
|
default:
|
105 |
|
|
// nothing else supported yet - though it is expected that "set"
|
106 |
|
|
// will fit the same set of arguments, potentially.
|
107 |
|
|
break;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
CYGARC_HAL_RESTORE_GP();
|
111 |
|
|
return res;
|
112 |
|
|
}
|
113 |
|
|
#endif
|
114 |
|
|
|
115 |
|
|
//----------------------------
|
116 |
|
|
// Delay uS
|
117 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_DELAY_US
|
118 |
|
|
|
119 |
|
|
static __call_if_delay_us_t delay_us;
|
120 |
|
|
|
121 |
|
|
static void
|
122 |
|
|
delay_us(cyg_int32 usecs)
|
123 |
|
|
{
|
124 |
|
|
CYGARC_HAL_SAVE_GP();
|
125 |
|
|
#ifdef CYGPKG_KERNEL
|
126 |
|
|
{
|
127 |
|
|
cyg_int32 start, elapsed;
|
128 |
|
|
cyg_int32 usec_ticks, slice;
|
129 |
|
|
|
130 |
|
|
// How many ticks total we should wait for.
|
131 |
|
|
usec_ticks = usecs*CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
|
132 |
|
|
usec_ticks /= CYGNUM_HAL_RTC_NUMERATOR/CYGNUM_HAL_RTC_DENOMINATOR/1000;
|
133 |
|
|
|
134 |
|
|
do {
|
135 |
|
|
// Spin in slices of 1/2 the RTC period. Allows interrupts
|
136 |
|
|
// time to run without messing up the algorithm. If we spun
|
137 |
|
|
// for 1 period (or more) of the RTC, there'd be also problems
|
138 |
|
|
// figuring out when the timer wrapped. We may lose a tick or
|
139 |
|
|
// two for each cycle but it shouldn't matter much.
|
140 |
|
|
slice = usec_ticks % (CYGNUM_KERNEL_COUNTERS_RTC_PERIOD / 2);
|
141 |
|
|
|
142 |
|
|
HAL_CLOCK_READ(&start);
|
143 |
|
|
do {
|
144 |
|
|
HAL_CLOCK_READ(&elapsed);
|
145 |
|
|
elapsed = (elapsed - start); // counts up!
|
146 |
|
|
if (elapsed < 0)
|
147 |
|
|
elapsed += CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
|
148 |
|
|
} while (elapsed < slice);
|
149 |
|
|
|
150 |
|
|
// Adjust by elapsed, not slice, since an interrupt may have
|
151 |
|
|
// been stalling us for some time.
|
152 |
|
|
usec_ticks -= elapsed;
|
153 |
|
|
} while (usec_ticks > 0);
|
154 |
|
|
}
|
155 |
|
|
#else // CYGPKG_KERNEL
|
156 |
|
|
#ifdef HAL_DELAY_US
|
157 |
|
|
// Use a HAL feature if defined
|
158 |
|
|
HAL_DELAY_US(usecs);
|
159 |
|
|
#else
|
160 |
|
|
// If no accurate delay mechanism, just spin for a while. Having
|
161 |
|
|
// an inaccurate delay is much better than no delay at all. The
|
162 |
|
|
// count of 10 should mean the loop takes something resembling
|
163 |
|
|
// 1us on most CPUs running between 30-100MHz [depends on how many
|
164 |
|
|
// instructions this compiles to, how many dispatch units can be
|
165 |
|
|
// used for the simple loop, actual CPU frequency, etc]
|
166 |
|
|
while (usecs-- > 0) {
|
167 |
|
|
int i;
|
168 |
|
|
for (i = 0; i < 10; i++);
|
169 |
|
|
}
|
170 |
|
|
#endif // HAL_DELAY_US
|
171 |
|
|
#endif // CYGPKG_KERNEL
|
172 |
|
|
CYGARC_HAL_RESTORE_GP();
|
173 |
|
|
}
|
174 |
|
|
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_DELAY_US
|
175 |
|
|
|
176 |
|
|
// Reset functions
|
177 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_RESET
|
178 |
|
|
|
179 |
|
|
static __call_if_reset_t reset;
|
180 |
|
|
|
181 |
|
|
static void
|
182 |
|
|
reset(void)
|
183 |
|
|
{
|
184 |
|
|
CYGARC_HAL_SAVE_GP();
|
185 |
|
|
// With luck, the platform defines some magic that will cause a hardware
|
186 |
|
|
// reset.
|
187 |
|
|
HAL_PLATFORM_RESET();
|
188 |
|
|
|
189 |
|
|
#ifdef HAL_PLATFORM_RESET_ENTRY
|
190 |
|
|
// If that's not the case (above is an empty statement) there may
|
191 |
|
|
// be defined an address we can jump to - and effectively
|
192 |
|
|
// reinitialize the system. Not quite as good as a reset, but it
|
193 |
|
|
// is often enough.
|
194 |
|
|
goto *HAL_PLATFORM_RESET_ENTRY;
|
195 |
|
|
|
196 |
|
|
#else
|
197 |
|
|
#error " no RESET_ENTRY"
|
198 |
|
|
#endif
|
199 |
|
|
|
200 |
|
|
CYGARC_HAL_RESTORE_GP();
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
// This is the system's default kill signal routine. Unless overridden
|
204 |
|
|
// by the application, it will cause a board reset when GDB quits the
|
205 |
|
|
// connection. (The user can avoid the reset by using the GDB 'detach'
|
206 |
|
|
// command instead of 'kill' or 'quit').
|
207 |
|
|
static int
|
208 |
|
|
kill_by_reset(int __irq_nr, void* __regs)
|
209 |
|
|
{
|
210 |
|
|
CYGARC_HAL_SAVE_GP();
|
211 |
|
|
|
212 |
|
|
reset();
|
213 |
|
|
|
214 |
|
|
CYGARC_HAL_RESTORE_GP();
|
215 |
|
|
return 0;
|
216 |
|
|
}
|
217 |
|
|
#endif
|
218 |
|
|
|
219 |
|
|
//------------------------------------
|
220 |
|
|
// NOP service
|
221 |
|
|
#if defined(CYGSEM_HAL_VIRTUAL_VECTOR_INIT_WHOLE_TABLE) || \
|
222 |
|
|
defined(CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_COMMS)
|
223 |
|
|
static int
|
224 |
|
|
nop_service(void)
|
225 |
|
|
{
|
226 |
|
|
// This is the default service. It always returns false (0), and
|
227 |
|
|
// _does not_ trigger any assertions. Clients must either cope
|
228 |
|
|
// with the service failure or assert.
|
229 |
|
|
return 0;
|
230 |
|
|
}
|
231 |
|
|
#endif
|
232 |
|
|
|
233 |
|
|
//----------------------------------
|
234 |
|
|
// Comm controls
|
235 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_COMMS
|
236 |
|
|
|
237 |
|
|
#ifdef CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS
|
238 |
|
|
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
|
239 |
|
|
(CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS+CYGNUM_HAL_VIRTUAL_VECTOR_AUX_CHANNELS)
|
240 |
|
|
#else
|
241 |
|
|
#define CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS \
|
242 |
|
|
CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
|
243 |
|
|
#endif
|
244 |
|
|
|
245 |
|
|
static hal_virtual_comm_table_t comm_channels[CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS+1];
|
246 |
|
|
|
247 |
|
|
static int
|
248 |
|
|
set_debug_comm(int __comm_id)
|
249 |
|
|
{
|
250 |
|
|
static int __selected_id = CYGNUM_CALL_IF_SET_COMM_ID_EMPTY;
|
251 |
|
|
hal_virtual_comm_table_t* __chan;
|
252 |
|
|
int interrupt_state = 0;
|
253 |
|
|
int res = 1, update = 0;
|
254 |
|
|
CYGARC_HAL_SAVE_GP();
|
255 |
|
|
|
256 |
|
|
CYG_ASSERT(__comm_id >= CYGNUM_CALL_IF_SET_COMM_ID_MANGLER
|
257 |
|
|
&& __comm_id < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS,
|
258 |
|
|
"Invalid channel");
|
259 |
|
|
|
260 |
|
|
switch (__comm_id) {
|
261 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT:
|
262 |
|
|
if (__selected_id > 0)
|
263 |
|
|
res = __selected_id-1;
|
264 |
|
|
else if (__selected_id == 0)
|
265 |
|
|
res = CYGNUM_CALL_IF_SET_COMM_ID_MANGLER;
|
266 |
|
|
else
|
267 |
|
|
res = __selected_id;
|
268 |
|
|
break;
|
269 |
|
|
|
270 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_EMPTY:
|
271 |
|
|
CYGACC_CALL_IF_DEBUG_PROCS_SET(0);
|
272 |
|
|
__selected_id = __comm_id;
|
273 |
|
|
break;
|
274 |
|
|
|
275 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_MANGLER:
|
276 |
|
|
__comm_id = 0;
|
277 |
|
|
update = 1;
|
278 |
|
|
break;
|
279 |
|
|
|
280 |
|
|
default:
|
281 |
|
|
__comm_id++; // skip mangler entry
|
282 |
|
|
update = 1;
|
283 |
|
|
break;
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
if (update) {
|
287 |
|
|
// Find the interrupt state of the channel.
|
288 |
|
|
__chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
289 |
|
|
if (__chan)
|
290 |
|
|
interrupt_state = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_DISABLE);
|
291 |
|
|
|
292 |
|
|
__selected_id = __comm_id;
|
293 |
|
|
CYGACC_CALL_IF_DEBUG_PROCS_SET(comm_channels[__comm_id]);
|
294 |
|
|
|
295 |
|
|
// Set interrupt state on the new channel.
|
296 |
|
|
__chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
297 |
|
|
if (interrupt_state)
|
298 |
|
|
CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_ENABLE);
|
299 |
|
|
else
|
300 |
|
|
CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_DISABLE);
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
CYGARC_HAL_RESTORE_GP();
|
304 |
|
|
return res;
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
static int
|
308 |
|
|
set_console_comm(int __comm_id)
|
309 |
|
|
{
|
310 |
|
|
static int __selected_id = CYGNUM_CALL_IF_SET_COMM_ID_EMPTY;
|
311 |
|
|
int res = 1, update = 0;
|
312 |
|
|
CYGARC_HAL_SAVE_GP();
|
313 |
|
|
|
314 |
|
|
CYG_ASSERT(__comm_id >= CYGNUM_CALL_IF_SET_COMM_ID_MANGLER
|
315 |
|
|
&& __comm_id < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS,
|
316 |
|
|
"Invalid channel");
|
317 |
|
|
|
318 |
|
|
switch (__comm_id) {
|
319 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT:
|
320 |
|
|
if (__selected_id > 0)
|
321 |
|
|
res = __selected_id-1;
|
322 |
|
|
else if (__selected_id == 0)
|
323 |
|
|
res = CYGNUM_CALL_IF_SET_COMM_ID_MANGLER;
|
324 |
|
|
else
|
325 |
|
|
res = __selected_id;
|
326 |
|
|
break;
|
327 |
|
|
|
328 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_EMPTY:
|
329 |
|
|
CYGACC_CALL_IF_CONSOLE_PROCS_SET(0);
|
330 |
|
|
__selected_id = __comm_id;
|
331 |
|
|
break;
|
332 |
|
|
|
333 |
|
|
case CYGNUM_CALL_IF_SET_COMM_ID_MANGLER:
|
334 |
|
|
__comm_id = 0;
|
335 |
|
|
update = 1;
|
336 |
|
|
break;
|
337 |
|
|
|
338 |
|
|
default:
|
339 |
|
|
__comm_id++; // skip mangler entry
|
340 |
|
|
update = 1;
|
341 |
|
|
break;
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
if (update) {
|
345 |
|
|
__selected_id = __comm_id;
|
346 |
|
|
|
347 |
|
|
CYGACC_CALL_IF_CONSOLE_PROCS_SET(comm_channels[__comm_id]);
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
CYGARC_HAL_RESTORE_GP();
|
351 |
|
|
return res;
|
352 |
|
|
}
|
353 |
|
|
#endif
|
354 |
|
|
|
355 |
|
|
//----------------------------------
|
356 |
|
|
// Cache functions
|
357 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_CACHE
|
358 |
|
|
|
359 |
|
|
static void
|
360 |
|
|
flush_icache(void *__p, int __nbytes)
|
361 |
|
|
{
|
362 |
|
|
CYGARC_HAL_SAVE_GP();
|
363 |
|
|
#ifdef HAL_ICACHE_FLUSH
|
364 |
|
|
HAL_ICACHE_FLUSH( __p , __nbytes );
|
365 |
|
|
#elif defined(HAL_ICACHE_INVALIDATE)
|
366 |
|
|
HAL_ICACHE_INVALIDATE();
|
367 |
|
|
#endif
|
368 |
|
|
CYGARC_HAL_RESTORE_GP();
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
static void
|
372 |
|
|
flush_dcache(void *__p, int __nbytes)
|
373 |
|
|
{
|
374 |
|
|
CYGARC_HAL_SAVE_GP();
|
375 |
|
|
#ifdef HAL_DCACHE_FLUSH
|
376 |
|
|
HAL_DCACHE_FLUSH( __p , __nbytes );
|
377 |
|
|
#elif defined(HAL_DCACHE_INVALIDATE)
|
378 |
|
|
HAL_DCACHE_INVALIDATE();
|
379 |
|
|
#endif
|
380 |
|
|
CYGARC_HAL_RESTORE_GP();
|
381 |
|
|
}
|
382 |
|
|
#endif
|
383 |
|
|
|
384 |
|
|
#if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
|
385 |
|
|
//-----------------------------------------------------------------------------
|
386 |
|
|
// GDB console output mangler (O-packetizer)
|
387 |
|
|
// COMMS init function at end.
|
388 |
|
|
|
389 |
|
|
// This gets called via the virtual vector console comms entry and
|
390 |
|
|
// handles O-packetization. The debug comms entries are used for the
|
391 |
|
|
// actual device IO.
|
392 |
|
|
static cyg_uint8
|
393 |
|
|
cyg_hal_diag_mangler_gdb_getc(void* __ch_data)
|
394 |
|
|
{
|
395 |
|
|
cyg_uint8 __ch;
|
396 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
397 |
|
|
CYGARC_HAL_SAVE_GP();
|
398 |
|
|
|
399 |
|
|
__ch = CYGACC_COMM_IF_GETC(*__chan);
|
400 |
|
|
|
401 |
|
|
CYGARC_HAL_RESTORE_GP();
|
402 |
|
|
|
403 |
|
|
return __ch;
|
404 |
|
|
}
|
405 |
|
|
|
406 |
|
|
static char __mangler_line[100];
|
407 |
|
|
static int __mangler_pos = 0;
|
408 |
|
|
|
409 |
|
|
static void
|
410 |
|
|
cyg_hal_diag_mangler_gdb_flush(void* __ch_data)
|
411 |
|
|
{
|
412 |
|
|
CYG_INTERRUPT_STATE old;
|
413 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
414 |
|
|
|
415 |
|
|
// Nothing to do if mangler buffer is empty.
|
416 |
|
|
if (__mangler_pos == 0)
|
417 |
|
|
return;
|
418 |
|
|
|
419 |
|
|
// Disable interrupts. This prevents GDB trying to interrupt us
|
420 |
|
|
// while we are in the middle of sending a packet. The serial
|
421 |
|
|
// receive interrupt will be seen when we re-enable interrupts
|
422 |
|
|
// later.
|
423 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) \
|
424 |
|
|
|| !defined(CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION)
|
425 |
|
|
HAL_DISABLE_INTERRUPTS(old);
|
426 |
|
|
#else
|
427 |
|
|
CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
|
428 |
|
|
#endif
|
429 |
|
|
|
430 |
|
|
#if CYGNUM_HAL_DEBUG_GDB_PROTOCOL_RETRIES != 0
|
431 |
|
|
// Only wait 500ms for data to arrive - avoid "stuck" connections
|
432 |
|
|
CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, CYGNUM_HAL_DEBUG_GDB_PROTOCOL_TIMEOUT);
|
433 |
|
|
#endif
|
434 |
|
|
|
435 |
|
|
while(1)
|
436 |
|
|
{
|
437 |
|
|
static const char hex[] = "0123456789ABCDEF";
|
438 |
|
|
cyg_uint8 csum = 0, c1;
|
439 |
|
|
int i;
|
440 |
|
|
|
441 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, '$');
|
442 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, 'O');
|
443 |
|
|
csum += 'O';
|
444 |
|
|
for( i = 0; i < __mangler_pos; i++ )
|
445 |
|
|
{
|
446 |
|
|
char ch = __mangler_line[i];
|
447 |
|
|
char h = hex[(ch>>4)&0xF];
|
448 |
|
|
char l = hex[ch&0xF];
|
449 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, h);
|
450 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, l);
|
451 |
|
|
csum += h;
|
452 |
|
|
csum += l;
|
453 |
|
|
}
|
454 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, '#');
|
455 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, hex[(csum>>4)&0xF]);
|
456 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, hex[csum&0xF]);
|
457 |
|
|
|
458 |
|
|
nak:
|
459 |
|
|
#if CYGNUM_HAL_DEBUG_GDB_PROTOCOL_RETRIES != 0
|
460 |
|
|
if (CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, &c1) == 0) {
|
461 |
|
|
c1 = '-';
|
462 |
|
|
if (tries && (--tries == 0)) c1 = '+';
|
463 |
|
|
}
|
464 |
|
|
#else
|
465 |
|
|
c1 = CYGACC_COMM_IF_GETC(*__chan);
|
466 |
|
|
#endif
|
467 |
|
|
|
468 |
|
|
if( c1 == '+' ) break;
|
469 |
|
|
|
470 |
|
|
if( cyg_hal_is_break( &c1 , 1 ) ) {
|
471 |
|
|
// Caller's responsibility to react on this.
|
472 |
|
|
CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(1);
|
473 |
|
|
break;
|
474 |
|
|
}
|
475 |
|
|
if( c1 != '-' ) goto nak;
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
__mangler_pos = 0;
|
479 |
|
|
// And re-enable interrupts
|
480 |
|
|
#if defined(CYG_HAL_STARTUP_ROM) \
|
481 |
|
|
|| !defined(CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION)
|
482 |
|
|
HAL_RESTORE_INTERRUPTS(old);
|
483 |
|
|
#else
|
484 |
|
|
CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
|
485 |
|
|
#endif
|
486 |
|
|
}
|
487 |
|
|
|
488 |
|
|
static void
|
489 |
|
|
cyg_hal_diag_mangler_gdb_putc(void* __ch_data, cyg_uint8 c)
|
490 |
|
|
{
|
491 |
|
|
#if CYGNUM_HAL_DEBUG_GDB_PROTOCOL_RETRIES != 0
|
492 |
|
|
int tries = CYGNUM_HAL_DEBUG_GDB_PROTOCOL_RETRIES;
|
493 |
|
|
#endif
|
494 |
|
|
|
495 |
|
|
// No need to send CRs
|
496 |
|
|
if( c == '\r' ) return;
|
497 |
|
|
|
498 |
|
|
CYGARC_HAL_SAVE_GP();
|
499 |
|
|
|
500 |
|
|
__mangler_line[__mangler_pos++] = c;
|
501 |
|
|
|
502 |
|
|
if( c == '\n' || __mangler_pos == sizeof(__mangler_line) )
|
503 |
|
|
cyg_hal_diag_mangler_gdb_flush(__ch_data);
|
504 |
|
|
|
505 |
|
|
CYGARC_HAL_RESTORE_GP();
|
506 |
|
|
}
|
507 |
|
|
|
508 |
|
|
static void
|
509 |
|
|
cyg_hal_diag_mangler_gdb_write(void* __ch_data,
|
510 |
|
|
const cyg_uint8* __buf, cyg_uint32 __len)
|
511 |
|
|
{
|
512 |
|
|
CYGARC_HAL_SAVE_GP();
|
513 |
|
|
|
514 |
|
|
while(__len-- > 0)
|
515 |
|
|
cyg_hal_diag_mangler_gdb_putc(__ch_data, *__buf++);
|
516 |
|
|
|
517 |
|
|
CYGARC_HAL_RESTORE_GP();
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
static void
|
521 |
|
|
cyg_hal_diag_mangler_gdb_read(void* __ch_data,
|
522 |
|
|
cyg_uint8* __buf, cyg_uint32 __len)
|
523 |
|
|
{
|
524 |
|
|
CYGARC_HAL_SAVE_GP();
|
525 |
|
|
|
526 |
|
|
while(__len-- > 0)
|
527 |
|
|
*__buf++ = cyg_hal_diag_mangler_gdb_getc(__ch_data);
|
528 |
|
|
|
529 |
|
|
CYGARC_HAL_RESTORE_GP();
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
static int
|
533 |
|
|
cyg_hal_diag_mangler_gdb_control(void *__ch_data,
|
534 |
|
|
__comm_control_cmd_t __func, ...)
|
535 |
|
|
{
|
536 |
|
|
CYGARC_HAL_SAVE_GP();
|
537 |
|
|
|
538 |
|
|
if (__func == __COMMCTL_FLUSH_OUTPUT)
|
539 |
|
|
cyg_hal_diag_mangler_gdb_flush(__ch_data);
|
540 |
|
|
|
541 |
|
|
CYGARC_HAL_RESTORE_GP();
|
542 |
|
|
return 0;
|
543 |
|
|
}
|
544 |
|
|
|
545 |
|
|
// This is the COMMS init function. It gets called both by the stubs
|
546 |
|
|
// and diag init code to initialize the COMMS mangler channel table -
|
547 |
|
|
// that's all. The callers have to decide whether to actually use this
|
548 |
|
|
// channel.
|
549 |
|
|
void
|
550 |
|
|
cyg_hal_diag_mangler_gdb_init(void)
|
551 |
|
|
{
|
552 |
|
|
hal_virtual_comm_table_t* comm;
|
553 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
554 |
|
|
|
555 |
|
|
// Initialize mangler procs
|
556 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_MANGLER);
|
557 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
558 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_diag_mangler_gdb_write);
|
559 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_diag_mangler_gdb_read);
|
560 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_diag_mangler_gdb_putc);
|
561 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_diag_mangler_gdb_getc);
|
562 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_diag_mangler_gdb_control);
|
563 |
|
|
|
564 |
|
|
// Restore the original console channel.
|
565 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
//-----------------------------------------------------------------------------
|
569 |
|
|
// Null console output mangler
|
570 |
|
|
// COMMS init function at end.
|
571 |
|
|
|
572 |
|
|
// This gets called via the virtual vector console comms entry and
|
573 |
|
|
// just forwards IO to the debug comms entries.
|
574 |
|
|
// This differs from setting the console channel to the same as the
|
575 |
|
|
// debug channel in that console output will go to the debug channel
|
576 |
|
|
// even if the debug channel is changed.
|
577 |
|
|
static cyg_uint8
|
578 |
|
|
cyg_hal_diag_mangler_null_getc(void* __ch_data)
|
579 |
|
|
{
|
580 |
|
|
cyg_uint8 __ch;
|
581 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
582 |
|
|
CYGARC_HAL_SAVE_GP();
|
583 |
|
|
|
584 |
|
|
__ch = CYGACC_COMM_IF_GETC(*__chan);
|
585 |
|
|
|
586 |
|
|
CYGARC_HAL_RESTORE_GP();
|
587 |
|
|
|
588 |
|
|
return __ch;
|
589 |
|
|
}
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
static void
|
593 |
|
|
cyg_hal_diag_mangler_null_putc(void* __ch_data, cyg_uint8 c)
|
594 |
|
|
{
|
595 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
596 |
|
|
|
597 |
|
|
CYGARC_HAL_SAVE_GP();
|
598 |
|
|
|
599 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, c);
|
600 |
|
|
|
601 |
|
|
CYGARC_HAL_RESTORE_GP();
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
static void
|
605 |
|
|
cyg_hal_diag_mangler_null_write(void* __ch_data,
|
606 |
|
|
const cyg_uint8* __buf, cyg_uint32 __len)
|
607 |
|
|
{
|
608 |
|
|
CYGARC_HAL_SAVE_GP();
|
609 |
|
|
|
610 |
|
|
while(__len-- > 0)
|
611 |
|
|
cyg_hal_diag_mangler_null_putc(__ch_data, *__buf++);
|
612 |
|
|
|
613 |
|
|
CYGARC_HAL_RESTORE_GP();
|
614 |
|
|
}
|
615 |
|
|
|
616 |
|
|
static void
|
617 |
|
|
cyg_hal_diag_mangler_null_read(void* __ch_data,
|
618 |
|
|
cyg_uint8* __buf, cyg_uint32 __len)
|
619 |
|
|
{
|
620 |
|
|
CYGARC_HAL_SAVE_GP();
|
621 |
|
|
|
622 |
|
|
while(__len-- > 0)
|
623 |
|
|
*__buf++ = cyg_hal_diag_mangler_null_getc(__ch_data);
|
624 |
|
|
|
625 |
|
|
CYGARC_HAL_RESTORE_GP();
|
626 |
|
|
}
|
627 |
|
|
|
628 |
|
|
static int
|
629 |
|
|
cyg_hal_diag_mangler_null_control(void *__ch_data,
|
630 |
|
|
__comm_control_cmd_t __func, ...)
|
631 |
|
|
{
|
632 |
|
|
// Do nothing (yet).
|
633 |
|
|
return 0;
|
634 |
|
|
}
|
635 |
|
|
|
636 |
|
|
// This is the COMMS init function. It gets called both by the stubs
|
637 |
|
|
// and diag init code to initialize the COMMS mangler channel table -
|
638 |
|
|
// that's all. The callers have to decide whether to actually use this
|
639 |
|
|
// channel.
|
640 |
|
|
void
|
641 |
|
|
cyg_hal_diag_mangler_null_init(void)
|
642 |
|
|
{
|
643 |
|
|
hal_virtual_comm_table_t* comm;
|
644 |
|
|
int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
|
645 |
|
|
|
646 |
|
|
// Initialize mangler procs
|
647 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_MANGLER);
|
648 |
|
|
comm = CYGACC_CALL_IF_CONSOLE_PROCS();
|
649 |
|
|
CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_diag_mangler_null_write);
|
650 |
|
|
CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_diag_mangler_null_read);
|
651 |
|
|
CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_diag_mangler_null_putc);
|
652 |
|
|
CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_diag_mangler_null_getc);
|
653 |
|
|
CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_diag_mangler_null_control);
|
654 |
|
|
|
655 |
|
|
// Restore the original console channel.
|
656 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
|
657 |
|
|
}
|
658 |
|
|
|
659 |
|
|
//-----------------------------------------------------------------------------
|
660 |
|
|
// Console IO functions that adhere to the virtual vector table semantics in
|
661 |
|
|
// order to ensure proper debug agent mangling when required.
|
662 |
|
|
//
|
663 |
|
|
externC void cyg_hal_plf_comms_init(void);
|
664 |
|
|
|
665 |
|
|
void
|
666 |
|
|
hal_if_diag_init(void)
|
667 |
|
|
{
|
668 |
|
|
// This function may be called from various places and the code
|
669 |
|
|
// should only run once.
|
670 |
|
|
static cyg_uint8 called = 0;
|
671 |
|
|
if (called) return;
|
672 |
|
|
called = 1;
|
673 |
|
|
|
674 |
|
|
#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_INHERIT_CONSOLE
|
675 |
|
|
|
676 |
|
|
#if defined(CYGDBG_HAL_DIAG_TO_DEBUG_CHAN)
|
677 |
|
|
// Use the mangler channel, which in turn uses the debug channel.
|
678 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_MANGLER);
|
679 |
|
|
|
680 |
|
|
// Initialize the mangler channel.
|
681 |
|
|
#if defined(CYGSEM_HAL_DIAG_MANGLER_GDB)
|
682 |
|
|
cyg_hal_diag_mangler_gdb_init();
|
683 |
|
|
#elif defined(CYGSEM_HAL_DIAG_MANGLER_None)
|
684 |
|
|
cyg_hal_diag_mangler_null_init();
|
685 |
|
|
#endif
|
686 |
|
|
|
687 |
|
|
#else // CYGDBG_HAL_DIAG_TO_DEBUG_CHAN
|
688 |
|
|
|
689 |
|
|
// Use an actual (raw) IO channel
|
690 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL);
|
691 |
|
|
|
692 |
|
|
#endif // CYGDBG_HAL_DIAG_TO_DEBUG_CHAN
|
693 |
|
|
|
694 |
|
|
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_INHERIT_CONSOLE
|
695 |
|
|
}
|
696 |
|
|
|
697 |
|
|
void
|
698 |
|
|
hal_if_diag_write_char(char c)
|
699 |
|
|
{
|
700 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
|
701 |
|
|
|
702 |
|
|
if (__chan)
|
703 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, c);
|
704 |
|
|
else {
|
705 |
|
|
__chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
706 |
|
|
|
707 |
|
|
// FIXME: What should be done if assertions are not enabled?
|
708 |
|
|
// This is a bad bad situation - we have no means for diag
|
709 |
|
|
// output; we want to hit a breakpoint to alert the developer
|
710 |
|
|
// or something like that.
|
711 |
|
|
CYG_ASSERT(__chan, "No valid channel set");
|
712 |
|
|
|
713 |
|
|
CYGACC_COMM_IF_PUTC(*__chan, c);
|
714 |
|
|
}
|
715 |
|
|
|
716 |
|
|
// Check interrupt flag
|
717 |
|
|
if (CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG()) {
|
718 |
|
|
CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(0);
|
719 |
|
|
cyg_hal_user_break(0);
|
720 |
|
|
}
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
void
|
724 |
|
|
hal_if_diag_read_char(char *c)
|
725 |
|
|
{
|
726 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
|
727 |
|
|
|
728 |
|
|
if (__chan)
|
729 |
|
|
*c = CYGACC_COMM_IF_GETC(*__chan);
|
730 |
|
|
else {
|
731 |
|
|
__chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
732 |
|
|
|
733 |
|
|
// FIXME: What should be done if assertions are not enabled?
|
734 |
|
|
// This is a bad bad situation - we have no means for diag
|
735 |
|
|
// output; we want to hit a breakpoint to alert the developer
|
736 |
|
|
// or something like that.
|
737 |
|
|
CYG_ASSERT(__chan, "No valid channel set");
|
738 |
|
|
|
739 |
|
|
*c = CYGACC_COMM_IF_GETC(*__chan);
|
740 |
|
|
}
|
741 |
|
|
}
|
742 |
|
|
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
|
743 |
|
|
|
744 |
|
|
//=============================================================================
|
745 |
|
|
// CtrlC support
|
746 |
|
|
//=============================================================================
|
747 |
|
|
|
748 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT) \
|
749 |
|
|
|| defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
|
750 |
|
|
|
751 |
|
|
struct Hal_SavedRegisters *hal_saved_interrupt_state;
|
752 |
|
|
|
753 |
|
|
void
|
754 |
|
|
hal_ctrlc_isr_init(void)
|
755 |
|
|
{
|
756 |
|
|
// A ROM monitor never enables the interrupt itself. This is left
|
757 |
|
|
// to the (RAM) application.
|
758 |
|
|
#ifndef CYGSEM_HAL_ROM_MONITOR
|
759 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
760 |
|
|
|
761 |
|
|
#if 1 // Prevents crash on older stubs
|
762 |
|
|
int v_m;
|
763 |
|
|
// Allow only ctrl-c interrupt enabling when version in table is
|
764 |
|
|
// below legal max and above the necessary service, and _not_
|
765 |
|
|
// the value we set it to below.
|
766 |
|
|
v_m = CYGACC_CALL_IF_VERSION() & CYGNUM_CALL_IF_TABLE_VERSION_CALL_MASK;
|
767 |
|
|
if (v_m >= CYGNUM_CALL_IF_TABLE_VERSION_CALL_MAX
|
768 |
|
|
|| v_m < CYGNUM_CALL_IF_SET_DEBUG_COMM
|
769 |
|
|
|| v_m == CYGNUM_CALL_IF_TABLE_VERSION_CALL_HACK)
|
770 |
|
|
return;
|
771 |
|
|
|
772 |
|
|
// Now trash that value - otherwise downloading an image with
|
773 |
|
|
// builtin stubs on a board with older stubs (which will cause the
|
774 |
|
|
// version to be set to VERSION_CALL) may cause all subsequent
|
775 |
|
|
// runs to (wrongly) fall through to the below code. If there is
|
776 |
|
|
// a new stub on the board, it will reinitialize the version field
|
777 |
|
|
// on reset. Yes, this is a gross hack!
|
778 |
|
|
CYGACC_CALL_IF_VERSION_SET(CYGNUM_CALL_IF_TABLE_VERSION_CALL_HACK);
|
779 |
|
|
#endif
|
780 |
|
|
|
781 |
|
|
// We can only enable interrupts on a valid debug channel.
|
782 |
|
|
if (__chan)
|
783 |
|
|
CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_ENABLE);
|
784 |
|
|
#endif
|
785 |
|
|
}
|
786 |
|
|
|
787 |
|
|
cyg_uint32
|
788 |
|
|
hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
789 |
|
|
{
|
790 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
791 |
|
|
int isr_ret = 0, ctrlc = 0;
|
792 |
|
|
|
793 |
|
|
if (__chan) {
|
794 |
|
|
isr_ret = CYGACC_COMM_IF_DBG_ISR(*__chan, &ctrlc, vector, data);
|
795 |
|
|
if (ctrlc)
|
796 |
|
|
cyg_hal_user_break( (CYG_ADDRWORD *)hal_saved_interrupt_state );
|
797 |
|
|
}
|
798 |
|
|
return isr_ret;
|
799 |
|
|
}
|
800 |
|
|
|
801 |
|
|
cyg_bool
|
802 |
|
|
hal_ctrlc_check(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
803 |
|
|
{
|
804 |
|
|
hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_DEBUG_PROCS();
|
805 |
|
|
int gdb_vector = vector-1;
|
806 |
|
|
int isr_ret, ctrlc = 0;
|
807 |
|
|
|
808 |
|
|
// This check only to avoid crash on older stubs in case of unhandled
|
809 |
|
|
// interrupts. It is a bit messy, but required in a transition period.
|
810 |
|
|
if (__chan &&
|
811 |
|
|
(CYGNUM_CALL_IF_TABLE_VERSION_CALL_HACK ==
|
812 |
|
|
(CYGACC_CALL_IF_VERSION() & CYGNUM_CALL_IF_TABLE_VERSION_CALL_MASK))){
|
813 |
|
|
gdb_vector = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_DBG_ISR_VECTOR);
|
814 |
|
|
}
|
815 |
|
|
if (vector == gdb_vector) {
|
816 |
|
|
isr_ret = CYGACC_COMM_IF_DBG_ISR(*__chan, &ctrlc, vector, data);
|
817 |
|
|
if (ctrlc) {
|
818 |
|
|
cyg_hal_user_break( (CYG_ADDRWORD *)hal_saved_interrupt_state );
|
819 |
|
|
return true;
|
820 |
|
|
}
|
821 |
|
|
}
|
822 |
|
|
return false;
|
823 |
|
|
}
|
824 |
|
|
#endif // CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT || CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
|
825 |
|
|
|
826 |
|
|
//--------------------------------------------------------------------------
|
827 |
|
|
// Init function. It should be called from the platform initialization code.
|
828 |
|
|
// For monitor configurations it will initialize the calling interface table,
|
829 |
|
|
// for client configurations it will patch the existing table as per
|
830 |
|
|
// configuration.
|
831 |
|
|
void
|
832 |
|
|
hal_if_init(void)
|
833 |
|
|
{
|
834 |
|
|
//**********************************************************************
|
835 |
|
|
//
|
836 |
|
|
// Note that if your RAM application is configured to initialize
|
837 |
|
|
// the whole table _or_ the communication channels, you _cannot_
|
838 |
|
|
// step through this function with the debugger. If your channel
|
839 |
|
|
// configurations are set to the default, you should be able to
|
840 |
|
|
// simply step over this function though (or use 'finish' once you
|
841 |
|
|
// have entered this function if that GDB command works).
|
842 |
|
|
//
|
843 |
|
|
// If you really do need to debug this code, the best approach is
|
844 |
|
|
// to have a working RedBoot / GDB stub in ROM and then change the
|
845 |
|
|
// hal_virtual_vector_table to reside at some other address in the
|
846 |
|
|
// RAM configuration than that used by the ROM monitor. Then
|
847 |
|
|
// you'll be able to use the ROM monitor to debug the below code
|
848 |
|
|
// and check that it does the right thing.
|
849 |
|
|
//
|
850 |
|
|
// Note that if you have a ROM monitor in ROM/flash which does
|
851 |
|
|
// support virtual vectors, you should be able to disable the
|
852 |
|
|
// option CYGSEM_HAL_VIRTUAL_VECTOR_INIT_WHOLE_TABLE. On some
|
853 |
|
|
// targets (which predate the introduction of virtual vectors)
|
854 |
|
|
// that option is enabled per default and needs to be explicitly
|
855 |
|
|
// disabled when you have an updated ROM monitor.
|
856 |
|
|
//
|
857 |
|
|
//**********************************************************************
|
858 |
|
|
|
859 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_INIT_WHOLE_TABLE
|
860 |
|
|
{
|
861 |
|
|
int i;
|
862 |
|
|
|
863 |
|
|
// Initialize tables with the NOP service.
|
864 |
|
|
// This should only be done for service routine entries - data
|
865 |
|
|
// pointers should be NULLed.
|
866 |
|
|
for (i = 0; i < CYGNUM_CALL_IF_TABLE_SIZE; i++)
|
867 |
|
|
hal_virtual_vector_table[i] = (CYG_ADDRWORD) &nop_service;
|
868 |
|
|
|
869 |
|
|
// Version number
|
870 |
|
|
CYGACC_CALL_IF_VERSION_SET(CYGNUM_CALL_IF_TABLE_VERSION_CALL
|
871 |
|
|
|((CYG_ADDRWORD)CYGNUM_CALL_IF_TABLE_VERSION_COMM<<CYGNUM_CALL_IF_TABLE_VERSION_COMM_shift));
|
872 |
|
|
}
|
873 |
|
|
#endif
|
874 |
|
|
|
875 |
|
|
// Miscellaneous services with wrappers in this file.
|
876 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_RESET
|
877 |
|
|
CYGACC_CALL_IF_RESET_SET(reset);
|
878 |
|
|
CYGACC_CALL_IF_KILL_VECTOR_SET(kill_by_reset);
|
879 |
|
|
#endif
|
880 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_DELAY_US
|
881 |
|
|
CYGACC_CALL_IF_DELAY_US_SET(delay_us);
|
882 |
|
|
#endif
|
883 |
|
|
|
884 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_CACHE
|
885 |
|
|
// Cache functions
|
886 |
|
|
CYGACC_CALL_IF_FLUSH_ICACHE_SET(flush_icache);
|
887 |
|
|
CYGACC_CALL_IF_FLUSH_DCACHE_SET(flush_dcache);
|
888 |
|
|
#endif
|
889 |
|
|
|
890 |
|
|
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
|
891 |
|
|
CYGACC_CALL_IF_FLASH_CFG_OP_SET(flash_config_op);
|
892 |
|
|
#endif
|
893 |
|
|
|
894 |
|
|
// Data entries not currently supported in eCos
|
895 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_DATA
|
896 |
|
|
CYGACC_CALL_IF_DBG_DATA_SET(0);
|
897 |
|
|
#endif
|
898 |
|
|
|
899 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_VERSION
|
900 |
|
|
CYGACC_CALL_IF_MONITOR_VERSION_SET(0);
|
901 |
|
|
#endif
|
902 |
|
|
|
903 |
|
|
// Comm controls
|
904 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_CLAIM_COMMS
|
905 |
|
|
{
|
906 |
|
|
int i, j;
|
907 |
|
|
|
908 |
|
|
// Clear out tables with safe dummy function.
|
909 |
|
|
for (j = 0; j < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS+1; j++)
|
910 |
|
|
for (i = 0; i < CYGNUM_COMM_IF_TABLE_SIZE; i++)
|
911 |
|
|
comm_channels[j][i] = (CYG_ADDRWORD) &nop_service;
|
912 |
|
|
|
913 |
|
|
// Set accessor functions
|
914 |
|
|
CYGACC_CALL_IF_SET_DEBUG_COMM_SET(set_debug_comm);
|
915 |
|
|
CYGACC_CALL_IF_SET_CONSOLE_COMM_SET(set_console_comm);
|
916 |
|
|
|
917 |
|
|
// Initialize console/debug procs. Note that these _must_
|
918 |
|
|
// be set to empty before the comms init call.
|
919 |
|
|
set_debug_comm(CYGNUM_CALL_IF_SET_COMM_ID_EMPTY);
|
920 |
|
|
set_console_comm(CYGNUM_CALL_IF_SET_COMM_ID_EMPTY);
|
921 |
|
|
|
922 |
|
|
// Initialize channels. This used to be done in
|
923 |
|
|
// hal_diag_init() and the stub initHardware() functions, but
|
924 |
|
|
// it makes more sense to have here.
|
925 |
|
|
cyg_hal_plf_comms_init();
|
926 |
|
|
|
927 |
|
|
// Always set the debug channel. If stubs are included, it is
|
928 |
|
|
// necessary. If no stubs are included it does not hurt and is
|
929 |
|
|
// likely to be required by the hal_if_diag_init code anyway
|
930 |
|
|
// as it may rely on it if using a mangler.
|
931 |
|
|
set_debug_comm(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL);
|
932 |
|
|
// Set console channel to a safe default. hal_if_diag_init
|
933 |
|
|
// will override with console channel or mangler if necessary.
|
934 |
|
|
set_console_comm(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL);
|
935 |
|
|
}
|
936 |
|
|
|
937 |
|
|
// Reset console interrupt flag.
|
938 |
|
|
CYGACC_CALL_IF_CONSOLE_INTERRUPT_FLAG_SET(0);
|
939 |
|
|
#endif
|
940 |
|
|
|
941 |
|
|
// Set up services provided by clients
|
942 |
|
|
#if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
|
943 |
|
|
( defined(CYGSEM_HAL_USE_ROM_MONITOR_GDB_stubs) \
|
944 |
|
|
|| defined(CYGSEM_HAL_USE_ROM_MONITOR_CygMon))
|
945 |
|
|
|
946 |
|
|
patch_dbg_syscalls( (void *)(hal_virtual_vector_table) );
|
947 |
|
|
#endif
|
948 |
|
|
|
949 |
|
|
// Init client services
|
950 |
|
|
#if !defined(CYGPKG_KERNEL) && defined(CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT)
|
951 |
|
|
// Only include this code if we do not have a kernel. Otherwise
|
952 |
|
|
// the kernel supplies the functionality for the app we are linked
|
953 |
|
|
// with.
|
954 |
|
|
|
955 |
|
|
// Prepare for application installation of thread info function in
|
956 |
|
|
// vector table.
|
957 |
|
|
init_thread_syscall( (void *)&hal_virtual_vector_table[CYGNUM_CALL_IF_DBG_SYSCALL] );
|
958 |
|
|
#endif
|
959 |
|
|
|
960 |
|
|
// Finally, install async breakpoint handler if it is configured in.
|
961 |
|
|
// FIXME: this should probably check for STUBS instead (but code is
|
962 |
|
|
// conditional on BREAK for now)
|
963 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
|
964 |
|
|
// Install async breakpoint handler into vector table.
|
965 |
|
|
CYGACC_CALL_IF_INSTALL_BPT_FN_SET(&cyg_hal_gdb_interrupt);
|
966 |
|
|
#endif
|
967 |
|
|
|
968 |
|
|
#if 0 != CYGINT_HAL_PLF_IF_INIT
|
969 |
|
|
// Call platform specific initializations - should only be used
|
970 |
|
|
// to augment what has already been set up, etc.
|
971 |
|
|
plf_if_init();
|
972 |
|
|
#endif
|
973 |
|
|
}
|