1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_m68k.c
|
4 |
|
|
//
|
5 |
|
|
// M68K HAL miscellaneous C functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2003, 2004, 2006, 2008 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): bartv
|
43 |
|
|
// Date: 2003-06-04
|
44 |
|
|
//
|
45 |
|
|
//###DESCRIPTIONEND####
|
46 |
|
|
//========================================================================
|
47 |
|
|
|
48 |
|
|
#include <pkgconf/hal.h>
|
49 |
|
|
#include <pkgconf/hal_m68k.h>
|
50 |
|
|
|
51 |
|
|
#include <cyg/infra/cyg_type.h>
|
52 |
|
|
#include <cyg/infra/cyg_ass.h>
|
53 |
|
|
#include <cyg/infra/diag.h>
|
54 |
|
|
#include <cyg/hal/hal_arch.h>
|
55 |
|
|
#include <cyg/hal/hal_diag.h>
|
56 |
|
|
#include <cyg/hal/hal_intr.h>
|
57 |
|
|
#include <cyg/hal/hal_stub.h>
|
58 |
|
|
|
59 |
|
|
// ----------------------------------------------------------------------------
|
60 |
|
|
// Interrupt support.
|
61 |
|
|
//
|
62 |
|
|
// Space for the interrupt data. These are updated by macros in hal_intr.h
|
63 |
|
|
volatile CYG_ADDRESS cyg_hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
|
64 |
|
|
volatile CYG_ADDRWORD cyg_hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
|
65 |
|
|
volatile CYG_ADDRESS cyg_hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
|
66 |
|
|
|
67 |
|
|
// A status register value that should be used while running DSRs.
|
68 |
|
|
cyg_uint32 hal_m68k_dsr_ipl_level = 0x2000 | (CYGNUM_HAL_INTERRUPT_DEFAULT_IPL_LEVEL << 8);
|
69 |
|
|
|
70 |
|
|
// In virtual vector configurations we can get apparently spurious
|
71 |
|
|
// interrupts in application space when the interrupt will be serviced
|
72 |
|
|
// by RedBoot instead. Hence the virtual vector code in the common HAL
|
73 |
|
|
// provides hal_default_isr() which gets installed as the default
|
74 |
|
|
// handler for all interrupts. If it turns out that RedBoot does not
|
75 |
|
|
// recognize the interrupt either, i.e. it really is spurious, then
|
76 |
|
|
// the virtual vector code will call hal_arch_default_isr().
|
77 |
|
|
//
|
78 |
|
|
// In non-virtual vector configurations hal_default_isr() needs to
|
79 |
|
|
// be provided by the architecture/variant/processor/platform HAL
|
80 |
|
|
// on the off-chance that the interrupt is not entirely spurious
|
81 |
|
|
// and some useful processing can take place.
|
82 |
|
|
|
83 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
|
84 |
|
|
# ifndef _HAL_M68K_HAL_ARCH_DEFAULT_ISR_DEFINED_
|
85 |
|
|
cyg_uint32
|
86 |
|
|
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
87 |
|
|
{
|
88 |
|
|
CYG_FAIL("Spurious interrupt!");
|
89 |
|
|
return 0;
|
90 |
|
|
}
|
91 |
|
|
# endif
|
92 |
|
|
#else
|
93 |
|
|
# ifndef _HAL_M68K_HAL_DEFAULT_ISR_DEFINED_
|
94 |
|
|
cyg_uint32
|
95 |
|
|
hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
96 |
|
|
{
|
97 |
|
|
CYG_FAIL("Spurious interrupt!");
|
98 |
|
|
return 0;
|
99 |
|
|
}
|
100 |
|
|
# endif
|
101 |
|
|
#endif
|
102 |
|
|
|
103 |
|
|
// ----------------------------------------------------------------------------
|
104 |
|
|
// Exception handling. The assembler routine calls this C function as
|
105 |
|
|
// soon as possible. Usually exceptions are passed to gdb stubs - if
|
106 |
|
|
// this application does not have gdb stubs included then the relevant
|
107 |
|
|
// entries in the exception vector table will still belong to the stubs.
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
void
|
111 |
|
|
hal_m68k_exception_handler(HAL_SavedRegisters* regs)
|
112 |
|
|
{
|
113 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
114 |
|
|
|
115 |
|
|
// If we caught an exception inside the stubs, see if we were expecting it
|
116 |
|
|
// and if so jump to the saved address
|
117 |
|
|
extern void* volatile __mem_fault_handler;
|
118 |
|
|
if (__mem_fault_handler) {
|
119 |
|
|
regs->pc = (CYG_ADDRWORD)__mem_fault_handler;
|
120 |
|
|
return; // Caught an exception inside stubs
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
_hal_registers = regs;
|
124 |
|
|
__handle_exception();
|
125 |
|
|
|
126 |
|
|
#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && defined(CYGPKG_HAL_EXCEPTIONS)
|
127 |
|
|
|
128 |
|
|
CYG_WORD code;
|
129 |
|
|
HAL_CONTEXT_PCSR_GET_EXCEPTION(regs, code);
|
130 |
|
|
cyg_hal_deliver_exception(code, (CYG_ADDRWORD) regs);
|
131 |
|
|
|
132 |
|
|
#else
|
133 |
|
|
|
134 |
|
|
CYG_FAIL("Exception!!!");
|
135 |
|
|
|
136 |
|
|
#endif
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
// ----------------------------------------------------------------------------
|
140 |
|
|
// C++ constructor support. The constructors are run in a separate function
|
141 |
|
|
// so that a breakpoint can be set, at the cost of a couple of extra bytes
|
142 |
|
|
// of code.
|
143 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
144 |
|
|
cyg_bool cyg_hal_stop_constructors = 0;
|
145 |
|
|
#endif
|
146 |
|
|
|
147 |
|
|
typedef void (*pfunc)(void);
|
148 |
|
|
extern pfunc __CTOR_LIST__[];
|
149 |
|
|
extern pfunc __CTOR_END__[];
|
150 |
|
|
|
151 |
|
|
void
|
152 |
|
|
cyg_hal_invoke_constructors(void)
|
153 |
|
|
{
|
154 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
155 |
|
|
static pfunc* p = &__CTOR_END__[-1];
|
156 |
|
|
cyg_hal_stop_constructors = 0;
|
157 |
|
|
for ( ; p >= __CTOR_LIST__; p--) {
|
158 |
|
|
(*p)();
|
159 |
|
|
if (cyg_hal_stop_constructors) {
|
160 |
|
|
p--;
|
161 |
|
|
break;
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
#else
|
165 |
|
|
pfunc* p;
|
166 |
|
|
for ( p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) {
|
167 |
|
|
(*p)();
|
168 |
|
|
}
|
169 |
|
|
#endif
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
// ----------------------------------------------------------------------------
|
173 |
|
|
// This entry point is called from vectors.S as soon as the C environment
|
174 |
|
|
// has been set up. We are running on the startup stack, interrupts are
|
175 |
|
|
// disabled, and the hardware is only minimally initialized. Most of
|
176 |
|
|
// the initialization will usually be done by the platform HAL.
|
177 |
|
|
|
178 |
|
|
externC void cyg_start(void);
|
179 |
|
|
|
180 |
|
|
void
|
181 |
|
|
hal_m68k_c_startup(void)
|
182 |
|
|
{
|
183 |
|
|
int i;
|
184 |
|
|
|
185 |
|
|
for (i = 0; i < CYGNUM_HAL_ISR_COUNT; i++) {
|
186 |
|
|
cyg_hal_interrupt_handlers[i] = (CYG_ADDRESS) &hal_default_isr;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
#ifdef HAL_M68K_VAR_INIT
|
190 |
|
|
HAL_M68K_VAR_INIT();
|
191 |
|
|
#endif
|
192 |
|
|
#ifdef HAL_M68K_PROC_INIT
|
193 |
|
|
HAL_M68K_PROC_INIT();
|
194 |
|
|
#endif
|
195 |
|
|
#ifdef HAL_M68K_PLATFORM_INIT
|
196 |
|
|
HAL_M68K_PLATFORM_INIT();
|
197 |
|
|
#endif
|
198 |
|
|
|
199 |
|
|
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
|
200 |
|
|
hal_if_init();
|
201 |
|
|
#endif
|
202 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
|
203 |
|
|
initialize_stub();
|
204 |
|
|
#endif
|
205 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT) || defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
|
206 |
|
|
{
|
207 |
|
|
extern void hal_ctrlc_isr_init(void);
|
208 |
|
|
hal_ctrlc_isr_init();
|
209 |
|
|
}
|
210 |
|
|
#endif
|
211 |
|
|
|
212 |
|
|
cyg_hal_invoke_constructors();
|
213 |
|
|
|
214 |
|
|
#ifdef HAL_M68K_VAR_INIT2
|
215 |
|
|
HAL_M68K_VAR_INIT2();
|
216 |
|
|
#endif
|
217 |
|
|
#ifdef HAL_M68K_PROC_INIT2
|
218 |
|
|
HAL_M68K_PROC_INIT2();
|
219 |
|
|
#endif
|
220 |
|
|
#ifdef HAL_M68K_PLATFORM_INIT2
|
221 |
|
|
HAL_M68K_PLATFORM_INIT2();
|
222 |
|
|
#endif
|
223 |
|
|
|
224 |
|
|
// And call into application-level code
|
225 |
|
|
cyg_start();
|
226 |
|
|
for ( ; ; );
|
227 |
|
|
}
|