1 |
786 |
skrzyp |
|
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 |
|
|
M68000 Architectural Support
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
Overview
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
Overview
|
47 |
|
|
eCos Support for the M68K Family of Processors
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
Description
|
51 |
|
|
|
52 |
|
|
The original Motorola 68000 processor was released in 1979, and
|
53 |
|
|
featured the following:
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
Eight general purpose 32-bit data registers, %D0 to %D7. Seven 32-bit
|
58 |
|
|
address registers %A0 to %A6, with %A7 dedicated as the stack pointer.
|
59 |
|
|
A 16-bit status register.
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
A linear address space, limited to 24-bits because the chip package
|
63 |
|
|
only had 24 address pins. Hence the processor could address 16
|
64 |
|
|
megabytes of memory.
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
No separate address space for I/O operations. Instead devices are
|
68 |
|
|
accessed just like memory via the main address and data buses.
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
16-bit external data bus, even though the data registers were 32 bits
|
72 |
|
|
wide.
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
A CISC variable-length instruction set with no less than 14 different
|
76 |
|
|
addressing modes (although of course the terms RISC and CISC were not
|
77 |
|
|
yet in common use).
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
Separate supervisor and user modes. The processor actually has two
|
81 |
|
|
distinct stack pointer registers %A7, and the mode determines which one
|
82 |
|
|
gets used.
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
An interrupt subsystem with support for vectored and prioritized
|
86 |
|
|
interrupts.
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
The 68000 processor was used in several microcomputers of its time,
|
91 |
|
|
including the original Apple Macintosh, the Commodore Amiga, and the
|
92 |
|
|
Atari ST. Over the years numerous variants have been developed. The
|
93 |
|
|
core instruction set has remained essentially unchanged. Some of the
|
94 |
|
|
variants have additional instructions. The development of MMUs led to
|
95 |
|
|
changes in exception handling. In more recent variants, notably the
|
96 |
|
|
Freescale ColdFire family, some infrequently used instructions and
|
97 |
|
|
addressing modes have been removed.
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
The 68008 reduced the widths of the external data and address buses to
|
102 |
|
|
8 bits and 20 bits respectively, giving the processor slow access to
|
103 |
|
|
only one megabyte.
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
The 68010 (1982) added virtual memory support.
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
In the 68020 (1984) both the address and data buses were made 32-bits wide. A
|
110 |
|
|
256-byte instruction cache was added, as were some new instructions
|
111 |
|
|
and addressing modes.
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
The 68030 (1987) included an on-chip mmu and a 256-byte data cache.
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
The 68040 (1991) added hardware floating point (previous processors relied on
|
118 |
|
|
an external coprocessor or on software emulation). It also had larger
|
119 |
|
|
caches and an improved mmu.
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
The 68060 (1994) involved an internally very different superscalar
|
123 |
|
|
implementation of the architecture, but few changes at the interface
|
124 |
|
|
level. It also contained support for power management.
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
There have been numerous 683xx variants for embedded use, with
|
128 |
|
|
on-chip peripherals like UARTs and timers. The cpu core of these
|
129 |
|
|
variants is also known as cpu32.
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
The MCFxxxx ColdFire series (1995) resembles a stripped-down 68060,
|
133 |
|
|
with some instructions and addressing modes removed to allow for a
|
134 |
|
|
much smaller and more efficient implementation. Various hardware units
|
135 |
|
|
such as the and FPU and MMU have become optional.
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
eCos only provides support for some of these variants, although it
|
141 |
|
|
should be possible to add support for additional variants with few or
|
142 |
|
|
no changes to the architectural HAL package.
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
The architectural HAL provides support for those features which are
|
146 |
|
|
common to all members of the 68000 and ColdFire families, and for
|
147 |
|
|
certain features which are present on some but not all members. A
|
148 |
|
|
typical eCos configuration will also contain: a variant HAL package
|
149 |
|
|
with support code for a family of processors, for example MCFxxxx;
|
150 |
|
|
possibly a processor HAL package with support for one specific
|
151 |
|
|
processor, for example the MCF5272; and a platform HAL
|
152 |
|
|
which contains the code needed for a specific hardware platform such
|
153 |
|
|
as the m5272c3.
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
Configuration
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
Options
|
167 |
|
|
Configuring the M68K Architectural Package
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
Loading and Unloading the Package
|
171 |
|
|
|
172 |
|
|
The M68K architectural HAL package CYGPKG_HAL_M68K
|
173 |
|
|
should be loaded automatically when eCos is configured for M68K-based
|
174 |
|
|
target hardware. It should never be necessary to load this package
|
175 |
|
|
explicitly. Unloading the package should only happen as a side effect
|
176 |
|
|
of switching target hardware. CYGPKG_HAL_M68K
|
177 |
|
|
serves primarily as a container for lower-level HALs and has only a
|
178 |
|
|
small number of configuration options.
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
Stacks
|
183 |
|
|
|
184 |
|
|
By default the architectural HAL provides a single block of memory to
|
185 |
|
|
act as both the startup stack and the interrupt stack. The variant,
|
186 |
|
|
processor or platform HAL may override this. For example if there are
|
187 |
|
|
several banks of RAM with different performance characteristics it may
|
188 |
|
|
be desirable to place the interrupt stack in fast RAM rather than in
|
189 |
|
|
ordinary RAM.
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
The assembler startup code sets the stack pointer to the startup stack
|
193 |
|
|
before switching to C code. This stack used for all HAL
|
194 |
|
|
initialization, running any C++ static constructors defined either by
|
195 |
|
|
eCos or by the application, and the cyg_start
|
196 |
|
|
entry point. In configurations containing the eCos kernel
|
197 |
|
|
cyg_start will enable interrupts, activate the
|
198 |
|
|
scheduler and threads will then run on their own stacks. In non-kernel
|
199 |
|
|
single-threaded applications the whole system continues to run on the
|
200 |
|
|
startup stack.
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
When an interrupt occurs the default behaviour is to switch to a
|
204 |
|
|
separate interrupt stack. This behaviour is controlled by the common
|
205 |
|
|
HAL configuration option
|
206 |
|
|
CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK.
|
207 |
|
|
It reduces the stack requirements of all threads in the system, at the
|
208 |
|
|
cost of some extra instructions during interrupt handling. In kernel
|
209 |
|
|
configurations the startup stack is no longer used once the scheduler
|
210 |
|
|
starts running so its memory can be reused for the interrupt stack. To
|
211 |
|
|
handle the possibility of nested interrupts the interrupt handling
|
212 |
|
|
code will detect if it is already on the interrupt stack, so in
|
213 |
|
|
non-kernel configurations it is also safe to use the same area of
|
214 |
|
|
memory for both startup and interrupt stacks. This leads to the
|
215 |
|
|
following scenarios:
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
If interrupt stacks are enabled via
|
220 |
|
|
CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
|
221 |
|
|
and the interrupt stack is not provided by the variant, processor or
|
222 |
|
|
platform HAL then a single block of memory will be used for both
|
223 |
|
|
startup and interrupt stacks. The size of this block is determined by
|
224 |
|
|
the common HAL configuration option
|
225 |
|
|
CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE, with a
|
226 |
|
|
default value
|
227 |
|
|
CYGNUM_HAL_DEFAULT_INTERRUPT_STACK_SIZE provided by
|
228 |
|
|
the M68K architectural HAL.
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
If the use of an interrupt stack is disabled then the M68K
|
232 |
|
|
architectural HAL will provide just the startup stack, unless this is
|
233 |
|
|
done by the variant, processor or platform HAL. The size of the
|
234 |
|
|
startup stack is controlled by
|
235 |
|
|
CYGNUM_HAL_M68K_STARTUP_STACK_SIZE.
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
Otherwise the interrupt and/or startup stacks are provided by other
|
239 |
|
|
packages and it is up to those packages to provide configuration
|
240 |
|
|
options for setting the sizes.
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
Floating Point Support
|
246 |
|
|
|
247 |
|
|
There are many variants of the basic M68K architecture. Some of these
|
248 |
|
|
have hardware floating point support. Originally this came in the form
|
249 |
|
|
of a separate 68881 coprocessor, but with modern variants it will be
|
250 |
|
|
part of the main processor chip. If the processor does not have
|
251 |
|
|
hardware floating point then software emulation will be used instead.
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
If the processor on the target hardware has a floating point unit then
|
255 |
|
|
the variant or processor HAL will implement the CDL interface
|
256 |
|
|
CYGINT_HAL_M68K_VARIANT_FPU. This allows the
|
257 |
|
|
architectural HAL and other packages to do the right thing on
|
258 |
|
|
different hardware.
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
Saving and restoring hardware floating point context increases
|
262 |
|
|
interrupt and dispatch latency, code size, and data size. If the
|
263 |
|
|
application does not actually use floating point then these overheads
|
264 |
|
|
are unnecessary, and can be suppressed by disabling the configuration
|
265 |
|
|
option CYGIMP_HAL_M68K_FPU_SAVE. Some applications
|
266 |
|
|
do use floating point but only in one thread. In that scenario it is
|
267 |
|
|
also unnecessary to save the floating point context during interrupts
|
268 |
|
|
and context switches, so the configuration option can be disabled.
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
The exact behaviour of the hardware floating point unit is determined
|
272 |
|
|
by the floating point control register %fpcr. By
|
273 |
|
|
default this is initialized to 0, giving IEE754 standard behaviour,
|
274 |
|
|
but another initial value can be specified using the configuration
|
275 |
|
|
option CYGNUM_HAL_M68K_FPU_CR_DEFAULT. For details
|
276 |
|
|
of the various bits in this control register see appropriate hardware
|
277 |
|
|
documentation. eCos assumes that the control register does not change
|
278 |
|
|
on a per-thread basis and hence the register is not saved or restored
|
279 |
|
|
during interrupt handling or a context switch.
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
At the time of writing eCos has not run on an M68K processor with
|
284 |
|
|
hardware floating point so the support for this is untested.
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
Other Options
|
290 |
|
|
|
291 |
|
|
There are configuration options to change the compiler flags used for
|
292 |
|
|
building this packages.
|
293 |
|
|
The M68K architectural HAL package does not define any other
|
294 |
|
|
configuration options that can be manipulated by the user. It does
|
295 |
|
|
define a number of interfaces such as
|
296 |
|
|
CYGINT_HAL_M68K_USE_STANDARD_PLATFORM_STUB_SUPPORT
|
297 |
|
|
which can be used by lower levels of the M68K HAL hierarchy to enable
|
298 |
|
|
certain functionality within the architectural package. Usually these
|
299 |
|
|
are of no interest to application developers.
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
The HAL Port
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
HAL Port
|
313 |
|
|
Implementation Details
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
Description
|
317 |
|
|
|
318 |
|
|
This documentation explains how the eCos HAL specification has been
|
319 |
|
|
mapped onto M68K hardware, and should be read in conjunction with
|
320 |
|
|
that specification. It also describes how variant, processor and
|
321 |
|
|
platform HALs can modify the default behaviour.
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
eCos support for any given target will involve either three or four
|
325 |
|
|
HAL packages: the architectural HAL, the platform HAL, the variant
|
326 |
|
|
HAL, and optionally a processor HAL. This package, the architectural
|
327 |
|
|
HAL, provides code and definitions that are applicable to all M68K
|
328 |
|
|
processors. The platform HAL provides support for one specific
|
329 |
|
|
board, for example an M5272C3 evaluation board, or possibly for a
|
330 |
|
|
number of almost-identical boards. The processor HAL, if present,
|
331 |
|
|
serves mainly to provide details of on-chip peripherals including the
|
332 |
|
|
interrupt controller. The variant HAL provides functionality that is
|
333 |
|
|
common to a group of processors, for example all MCFxxxx processors
|
334 |
|
|
have very similar UARTs and hence can share HAL diagnostic code.
|
335 |
|
|
There is no fixed specification of what should go into the variant HAL
|
336 |
|
|
versus the processor HAL. For simplicity the description below only
|
337 |
|
|
refers to variant HALs, but the work may actually happen in a
|
338 |
|
|
processor HAL instead.
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
As a design goal lower-level HALs can always override functionality
|
342 |
|
|
that is normally provided higher up. For example the architectural HAL
|
343 |
|
|
will provide the required eCos HAL_LSBIT_INDEX
|
344 |
|
|
and HAL_MSBIT_INDEX macros, but these can be
|
345 |
|
|
provided lower down instead. Many but not all ColdFire processors have
|
346 |
|
|
the ff1 and bitrev instructions
|
347 |
|
|
which allow for a more efficient implementation than the default
|
348 |
|
|
architectural ones. In some areas such as handling context switching
|
349 |
|
|
the architectural HAL will usually provide the basic functionality but
|
350 |
|
|
it may be extended by lower HALs, for example to add support for the
|
351 |
|
|
multiply-accumulate units present in certain ColdFire processors.
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
The architectural HAL provides header files
|
355 |
|
|
class="headerfile">cyg/hal/hal_arch.h,
|
356 |
|
|
class="headerfile">cyg/hal/hal_intr.h,
|
357 |
|
|
class="headerfile">cyg/hal/hal_cache.h,
|
358 |
|
|
class="headerfile">cyg/hal/hal_io.h and
|
359 |
|
|
class="headerfile">cyg/hal/arch.inc. These automatically
|
360 |
|
|
include an equivalent header file from the variant HAL, for example
|
361 |
|
|
. The
|
362 |
|
|
variant HAL header will in turn include processor and
|
363 |
|
|
platform-specific headers. This means that application developers and
|
364 |
|
|
other packages can simply include the architectural HAL headers
|
365 |
|
|
without needing to know about variants or platforms. It also allows
|
366 |
|
|
the variant and platform HALs to override architectural settings.
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
The port assumes that eCos and application code always runs in
|
370 |
|
|
supervisor mode, with full access to all hardware and special
|
371 |
|
|
registers.
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
Data Types
|
375 |
|
|
|
376 |
|
|
For eCos purposes all M68K processors are big-endian and 32-bit, so
|
377 |
|
|
the default data types in
|
378 |
|
|
class="headerfile">cyg/infra/cyg_type.h are used. Some
|
379 |
|
|
variants have external bus widths less than 32-bit, but this does not
|
380 |
|
|
affect the architectural HAL.
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
When porting to another variant it is possible to override some or all
|
384 |
|
|
of the type definitions. The variant HAL needs to implement the CDL
|
385 |
|
|
interface CYGINT_HAL_M68K_VARIANT_TYPES and provide
|
386 |
|
|
a header file
|
387 |
|
|
class="headerfile">cyg/hal/var_basetype.h.
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
Startup and Exception Vectors
|
392 |
|
|
|
393 |
|
|
The conventional bootstrap mechanism involves a table of exception
|
394 |
|
|
vectors at the base of memory. The first two words of this table give
|
395 |
|
|
the initial program counter and stack pointer. In a typical embedded
|
396 |
|
|
system the hardware is arranged such that non-volatile flash memory is
|
397 |
|
|
found at location 0x0 so it is the start of flash that contains the
|
398 |
|
|
exception vectors and the boot code. The table of exception vectors is
|
399 |
|
|
used subsequently for interrupt handling and for hardware exceptions
|
400 |
|
|
such as attempts to execute an illegal instruction. There are a number
|
401 |
|
|
of common scenarios:
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
On systems with very limited memory flash may remain mapped at
|
406 |
|
|
location 0 and the table of exception vectors remains mapped there as
|
407 |
|
|
well. The M68K architecture defines the table to have 256 entries and
|
408 |
|
|
hence it occupies 1K of memory, but in reality many of the entries are
|
409 |
|
|
unused so part of the table may get used for code instead. Since the
|
410 |
|
|
whole exception vector table is in read-only memory parts of the eCos
|
411 |
|
|
interrupt and exception handling mechanisms have to be statically
|
412 |
|
|
initialized and macros like HAL_VSR_SET are not
|
413 |
|
|
available.
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
As a minor variation of the previous case, flash remains at location 0
|
417 |
|
|
but the table of exception vectors gets remapped elsewhere in the
|
418 |
|
|
address space, usually RAM. This allows
|
419 |
|
|
HAL_VSR_SET to operate normally but at the cost
|
420 |
|
|
of increased memory usage. The exception vector table in flash only
|
421 |
|
|
contains two entries, for the initial program counter and stack
|
422 |
|
|
pointer. The exception vector table in RAM typically gets initialized
|
423 |
|
|
at run-time.
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
On systems with more memory it is conventional to rearrange the
|
427 |
|
|
address map during bootstrap. The flash gets relocated, typically to
|
428 |
|
|
near the end of the address space, and RAM gets placed at location 0
|
429 |
|
|
instead. The exception vector table stays at location 0 but is now in
|
430 |
|
|
RAM and gets initialized at run-time. The bootstrap exception vector
|
431 |
|
|
table in flash again only needs two entries. A variation places the
|
432 |
|
|
RAM elsewhere in the address space and moves the exception vector
|
433 |
|
|
table there, leaving location 0 unused. This provides some protection
|
434 |
|
|
against null pointer accesses in errant code.
|
435 |
|
|
|
436 |
|
|
|
437 |
|
|
As a further complication, larger systems typically support different
|
438 |
|
|
startup types. The application can be linked against a ROM startup
|
439 |
|
|
configuration and placed directly in flash, as before. Alternatively
|
440 |
|
|
there may be a ROM monitor such as RedBoot in the flash, taking care
|
441 |
|
|
of initial bootstrap. The user's application is linked against a RAM
|
442 |
|
|
startup configuration, loaded into RAM via the ROM monitor, and
|
443 |
|
|
debugged using functionality provided by the ROM monitor. Yet another
|
444 |
|
|
possibility involves a RAM startup application but it gets loaded and
|
445 |
|
|
run via a hardware debug technology such as BDM, and the ROM monitor
|
446 |
|
|
is either missing or not used.
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
The exact hardware details, the various startup types, the steps
|
451 |
|
|
needed for low-level hardware initialization, and so on are not known
|
452 |
|
|
to the architectural HAL. Hence although the architectural HAL does
|
453 |
|
|
provide the basic framework for startup, much of the work is done via
|
454 |
|
|
macros provided by lower-level HAL packages and those macros are
|
455 |
|
|
likely to depend on various configuration options. Rather than try to
|
456 |
|
|
enumerate all the various combinations here it is better to look at
|
457 |
|
|
the actual code in vectors.S and in appropriate
|
458 |
|
|
variant, processor or platform HALs. vectors.S is
|
459 |
|
|
responsible for any low-level initialization that needs to happen.
|
460 |
|
|
This includes setting up a standard C environment with the stack
|
461 |
|
|
pointer set to the startup stack in working RAM, making sure all
|
462 |
|
|
statically initialized global variables have the correct values, and
|
463 |
|
|
that all uninitialized global variables are zeroed. Once the C
|
464 |
|
|
environment has been set up the code jumps to
|
465 |
|
|
hal_m68k_c_startup in file
|
466 |
|
|
hal_m68k.c which completes the initialization and
|
467 |
|
|
jumps to the application entry point.
|
468 |
|
|
|
469 |
|
|
|
470 |
|
|
|
471 |
|
|
Interrupt Handling
|
472 |
|
|
|
473 |
|
|
The M68K architecture reserves a 1K area of memory for 256 exception
|
474 |
|
|
vectors. These are used for internal and external interrupts,
|
475 |
|
|
exceptions, software traps, and special operations such as reset
|
476 |
|
|
handling. Some of the vectors have well-defined uses. However when it
|
477 |
|
|
comes to interrupt handling the details will depend on the processor
|
478 |
|
|
variant and on the platform, and the appropriate package documentation
|
479 |
|
|
should be consulted for full details. Most platforms will not use the
|
480 |
|
|
full set of 256 vectors, instead re-using some of this memory for
|
481 |
|
|
other purposes.
|
482 |
|
|
|
483 |
|
|
|
484 |
|
|
By default the exception vectors are located at location 0, but some
|
485 |
|
|
variants allow the vectors to be located elsewhere. This is managed by
|
486 |
|
|
an M68K-specific macro CYG_HAL_VSR_TABLE. The
|
487 |
|
|
default value is 0, but a variant HAL can provide an alternative value.
|
488 |
|
|
|
489 |
|
|
|
490 |
|
|
The standard eCos macros HAL_VSR_GET and
|
491 |
|
|
HAL_VSR_SET just manipulate one of the 256
|
492 |
|
|
entries in the table of exception vectors. Hence it is usually
|
493 |
|
|
possible to replace the default handlers for exceptions and traps in
|
494 |
|
|
addition to interrupt handlers.
|
495 |
|
|
|
496 |
|
|
provides #define's for the more common exception
|
497 |
|
|
vectors, and additional ones can be provided by the platform or
|
498 |
|
|
variant. It is the responsibility of the platform or variant HAL to
|
499 |
|
|
initialize the table, and to provide the
|
500 |
|
|
HAL_VSR_SET_TO_ECOS_HANDLER macro since that
|
501 |
|
|
requires knowledge of the default table entries.
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
It should be noted that in some configurations the table of exception
|
505 |
|
|
vectors may reside in read-only memory so entries cannot be changed.
|
506 |
|
|
If so then the HAL_VSR_SET and
|
507 |
|
|
HAL_VSR_SET_TO_ECOS_HANDLER macros will not be
|
508 |
|
|
defined. Portable code may need to consider this possibility and test
|
509 |
|
|
for the existence of these macros before using them.
|
510 |
|
|
|
511 |
|
|
|
512 |
|
|
The architectural HAL provides an entry point
|
513 |
|
|
hal_m68k_interrupt_vsr in the file
|
514 |
|
|
hal_arch.S. When an interrupt occurs the original
|
515 |
|
|
68000 pushed the program counter and the status register on to the
|
516 |
|
|
stack, and then called the VSR via the exception table. On newer
|
517 |
|
|
variants some additional information is pushed, including details of
|
518 |
|
|
the interrupt source. hal_m68k_interrupt_vsr
|
519 |
|
|
assumes the latter and can be used directly as the VSR on these newer
|
520 |
|
|
variants. On older variants a small trampoline is needed which pushes
|
521 |
|
|
the additional information and then jumps to the generic VSR.
|
522 |
|
|
Interpreting the additional information is handled via an assembler
|
523 |
|
|
macro hal_context_extract_isr_vector_shl2
|
524 |
|
|
which should be defined by the variant, matching the behaviour of the
|
525 |
|
|
hardware or the trampoline.
|
526 |
|
|
|
527 |
|
|
|
528 |
|
|
At the architecture level there is no fixed mapping between VSR and
|
529 |
|
|
ISR vectors. Instead that is left to the variant or platform HAL. The
|
530 |
|
|
architectural HAL does provide default implementations of
|
531 |
|
|
HAL_INTERRUPT_ATTACH,
|
532 |
|
|
HAL_INTERRUPT_DETACH and
|
533 |
|
|
HAL_INTERRUPT_IN_USE since these just involve
|
534 |
|
|
updating a static table.
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
By default the interrupt state control macros
|
538 |
|
|
HAL_DISABLE_INTERRUPTS,
|
539 |
|
|
HAL_RESTORE_INTERRUPTS,
|
540 |
|
|
HAL_ENABLE_INTERRUPTS and
|
541 |
|
|
HAL_QUERY_INTERRUPTS are implemented by the
|
542 |
|
|
architectural HAL, and simply involve updating the status register.
|
543 |
|
|
Disabling interrupts involves setting the three IPL bits to 0x07.
|
544 |
|
|
Enabling interrupts involves setting those bits to a smaller value,
|
545 |
|
|
CYGNUM_HAL_INTERRUPT_DEFAULT_IPL_LEVEL, which
|
546 |
|
|
defaults to 0.
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
HAL_DISABLE_INTERRUPTS has no effect on
|
550 |
|
|
non-maskable interrupts. This causes a problem because parts of the
|
551 |
|
|
system assume that all normal interrupt sources are affected by this
|
552 |
|
|
macro. If the target hardware can raise non-maskable interrupts then
|
553 |
|
|
it is the responsibility of application code to install a suitable VSR
|
554 |
|
|
and handle non-maskable interrupts entirely within the application,
|
555 |
|
|
bypassing the usual eCos ISR and DSR mechanisms.
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
The architectural HAL does not provide any support for the interrupt
|
559 |
|
|
controller management macros like
|
560 |
|
|
HAL_INTERRUPT_MASK. These can only be implemented
|
561 |
|
|
on a per-variant, per-processor or per-platform basis.
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
Exception Handling
|
566 |
|
|
|
567 |
|
|
Synchronous exception handling is done in much the same way as
|
568 |
|
|
interrupt handling. The architectural HAL provides a generic entry
|
569 |
|
|
point hal_m68k_exception_vsr. On some variants
|
570 |
|
|
this can be used directly as the exception VSR, on others it will be
|
571 |
|
|
called via a small trampoline.
|
572 |
|
|
|
573 |
|
|
|
574 |
|
|
The details of exception handling vary widely from one variant to the
|
575 |
|
|
next. Some variants push a great deal of additional information on to
|
576 |
|
|
the stack for certain exceptions, but not all. The pushed program
|
577 |
|
|
counter may correspond to the specific instruction that caused the
|
578 |
|
|
exception, or the next instruction, or there may be only a loose
|
579 |
|
|
correlation because of buffered writes. The architectural HAL makes no
|
580 |
|
|
attempt to cope with all these differences, although some variants may
|
581 |
|
|
provide more advanced support. Otherwise if an exception needs to be
|
582 |
|
|
handled in a very specific way then it is up to the application to
|
583 |
|
|
install a suitable VSR and handle the exception directly.
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
|
|
Stacks and Stack Sizes
|
588 |
|
|
|
589 |
|
|
defines
|
590 |
|
|
values for minimal and recommended thread stack sizes,
|
591 |
|
|
CYGNUM_HAL_STACK_SIZE_MINIMUM and
|
592 |
|
|
CYGNUM_HAL_STACK_SIZE_TYPICAL. These values are
|
593 |
|
|
specific to the current configuration, and are affected mainly by
|
594 |
|
|
options related to interrupt handling.
|
595 |
|
|
|
596 |
|
|
|
597 |
|
|
By default eCos uses a separate interrupt stack, although this can be
|
598 |
|
|
disabled through the configuration option
|
599 |
|
|
CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK.
|
600 |
|
|
When an interrupt or exception occurs eCos will save the context on
|
601 |
|
|
the current stack and then switch to the interrupt stack before
|
602 |
|
|
calling the appropriate ISR interrupt handler. This means that thread
|
603 |
|
|
stacks can be significantly smaller because there is no need to worry
|
604 |
|
|
about interrupt handling overheads, just the thread context. However
|
605 |
|
|
switching the stack does require some extra work and hence increases
|
606 |
|
|
the interrupt latency. Disabling the interrupt stack removes this
|
607 |
|
|
processing overhead but requires larger stack sizes. It depends on
|
608 |
|
|
the application whether or not this is a sensible trade off.
|
609 |
|
|
|
610 |
|
|
|
611 |
|
|
By default eCos does not allow nested interrupts, but this can be
|
612 |
|
|
controlled via the configuration option
|
613 |
|
|
CYGSEM_HAL_COMMON_INTERRUPTS_ALLOW_NESTING.
|
614 |
|
|
Supporting nested interrupts requires larger thread stacks, especially
|
615 |
|
|
if the separate interrupt stack is also disabled.
|
616 |
|
|
|
617 |
|
|
|
618 |
|
|
Although the M68K has enough registers for typical operation, the
|
619 |
|
|
calling conventions are memory-oriented. In particular all arguments
|
620 |
|
|
are pushed on the stack rather than held in registers, and the return
|
621 |
|
|
address is also pushed rather than ending up in a link register. To
|
622 |
|
|
allow for this the recommended minimum stack sizes are a little bit
|
623 |
|
|
larger than for some other architectures. Variant HALs cannot directly
|
624 |
|
|
affect these stack sizes. However the sizes do depend in part on the
|
625 |
|
|
size of a thread context, so if for example the processor supports
|
626 |
|
|
hardware floating point and support for that is enabled then the stack
|
627 |
|
|
sizes will increase.
|
628 |
|
|
|
629 |
|
|
|
630 |
|
|
Usually the M68K architectural HAL will provide a single block of
|
631 |
|
|
memory which acts as both the startup and interrupt stack, and there
|
632 |
|
|
are configuration options to
|
633 |
|
|
control the size of this block. Alternatively a variant, processor or
|
634 |
|
|
platform HAL may define either or both of
|
635 |
|
|
_HAL_M68K_STARTUP_STACK_ and
|
636 |
|
|
_HAL_M68K_INTERRUPT_STACK_BASE_ if for some reason
|
637 |
|
|
the stacks should not be placed in ordinary RAM.
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
|
641 |
|
|
Thread Contexts and Setjmp/Longjmp
|
642 |
|
|
|
643 |
|
|
A typical thread context consists of the following:
|
644 |
|
|
|
645 |
|
|
|
646 |
|
|
|
647 |
|
|
The integer context. This consists of the data registers
|
648 |
|
|
%d0 to %d7 and the address
|
649 |
|
|
registers %a0 to %a6, The stack
|
650 |
|
|
pointer register %a7 does not have to be saved
|
651 |
|
|
explicitly since it is implicit in the pointer to the saved context.
|
652 |
|
|
|
653 |
|
|
|
654 |
|
|
The caller-save registers are %d0,
|
655 |
|
|
%d1, %a0,
|
656 |
|
|
%a1, %a7 and the status
|
657 |
|
|
register. The remaining registers are callee-save. Function arguments
|
658 |
|
|
are always passed on the stack. The result is held in
|
659 |
|
|
%d0.
|
660 |
|
|
|
661 |
|
|
|
662 |
|
|
Floating point context, consisting of eight 64-bit floating point
|
663 |
|
|
registers %fp0 to %fp7 and two
|
664 |
|
|
support registers %fpsr and
|
665 |
|
|
%fpiar. Support for this is only relevant if the
|
666 |
|
|
processor variant has a hardware floating point unit, and even then
|
667 |
|
|
saving floating point context is optional and can be disabled using a
|
668 |
|
|
configuration option CYGIMP_HAL_M68K_FPU_SAVE. The
|
669 |
|
|
control register %fpcr is not saved as part of the
|
670 |
|
|
context. It is assumed that a single %fpcr value,
|
671 |
|
|
usually 0, will be used throughout the application.
|
672 |
|
|
|
673 |
|
|
|
674 |
|
|
The architectural HAL provides support for the hardware floating point
|
675 |
|
|
unit. The variant or processor HAL should implement the CDL interface
|
676 |
|
|
CYGINT_HAL_M68K_VARIANT_FPU if this hardware unit
|
677 |
|
|
is actually present.
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
Some M68K variants have additional hardware units, for example the
|
681 |
|
|
multiply-accumulate units in certain ColdFire processors. The
|
682 |
|
|
architectural HAL allows the context to be extended through various
|
683 |
|
|
macros such as HAL_CONTEXT_OTHER.
|
684 |
|
|
|
685 |
|
|
|
686 |
|
|
The status register %sr and the program counter.
|
687 |
|
|
These are special because when an interrupt occurs the hardware
|
688 |
|
|
automatically pushes these onto the stack, but exactly what gets
|
689 |
|
|
pushed depends on the variant.
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
|
693 |
|
|
setjmp and longjmp only deal
|
694 |
|
|
with the integer and fpu contexts. It is assumed that any special
|
695 |
|
|
hardware units will only be used by application code, not by the
|
696 |
|
|
compiler. Hence it is the responsibility of application code to
|
697 |
|
|
define and implement appropriate setjmp semantics for these units.
|
698 |
|
|
The variant HAL package can override the default implementations if
|
699 |
|
|
necessary.
|
700 |
|
|
|
701 |
|
|
|
702 |
|
|
When porting to a new M68K variant, if this has a hardware floating
|
703 |
|
|
point unit then the variant HAL should implement the CDL interface
|
704 |
|
|
CYGINT_HAL_M68K_VARIANT_FPU, thus enabling support
|
705 |
|
|
provided by the architectural HAL. If the variant has additional
|
706 |
|
|
hardware units involving state that should be preserved during a
|
707 |
|
|
context switch or when an interrupt occurs, the variant HAL should
|
708 |
|
|
define a number of macros. The header file
|
709 |
|
|
class="headerfile">cyg/hal/var_arch.h should define
|
710 |
|
|
HAL_CONTEXT_OTHER,
|
711 |
|
|
HAL_CONTEXT_OTHER_SIZE, and
|
712 |
|
|
HAL_CONTEXT_OTHER_INIT, either directly or via
|
713 |
|
|
. The
|
714 |
|
|
assembler header file
|
715 |
|
|
class="headerfile">cyg/hal/var.inc should define a number
|
716 |
|
|
of macros such as hal_context_other_save_caller.
|
717 |
|
|
For details of these macros see the architectural
|
718 |
|
|
hal_arch.S file.
|
719 |
|
|
|
720 |
|
|
|
721 |
|
|
Variants also need to define exactly how the status register and
|
722 |
|
|
program counter are saved onto the stack when an interrupt or
|
723 |
|
|
exception occurs. This is handled through C macros
|
724 |
|
|
HAL_CONTEXT_PCSR_SIZE,
|
725 |
|
|
HAL_CONTEXT_PCSR_RTE_ADJUST, and
|
726 |
|
|
HAL_CONTEXT_PCSR_INIT, and a number of assembler
|
727 |
|
|
macros such as hal_context_pcsr_save_sr. Again
|
728 |
|
|
the architectural files
|
729 |
|
|
class="headerfile">cyg/hal/hal_arch.h and
|
730 |
|
|
hal_arch.S provide more details of these.
|
731 |
|
|
|
732 |
|
|
|
733 |
|
|
|
734 |
|
|
Bit Indexing
|
735 |
|
|
|
736 |
|
|
For performance reasons the HAL_LSBIT_INDEX and
|
737 |
|
|
HAL_MSBIT_INDEX macros are implemented using
|
738 |
|
|
assembler functions. A variant HAL can override the default
|
739 |
|
|
definitions if, for example, the variant has special instructions to
|
740 |
|
|
perform these operations.
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
|
744 |
|
|
Idle Thread Processing
|
745 |
|
|
|
746 |
|
|
The default HAL_IDLE_THREAD_ACTION implementation
|
747 |
|
|
is a no-op. A variant HAL may override this, for example to put the
|
748 |
|
|
processor into sleep mode. Alternative implementations should consider
|
749 |
|
|
exactly how this macro gets used in eCos kernel code.
|
750 |
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
Clock Support
|
754 |
|
|
|
755 |
|
|
The architectural HAL cannot provide the required clock support
|
756 |
|
|
because it does not know what timer hardware may be available on the
|
757 |
|
|
target hardware. Instead this is left to either the variant or
|
758 |
|
|
platform HAL, depending on whether the processor has a suitable
|
759 |
|
|
on-chip timer or whether an off-chip timer has to be used.
|
760 |
|
|
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
HAL I/O
|
764 |
|
|
|
765 |
|
|
The M68K architecture does not have a separate I/O bus. Instead all
|
766 |
|
|
hardware is assumed to be memory-mapped. Further it is assumed that
|
767 |
|
|
all peripherals on the memory bus are wired appropriately for a
|
768 |
|
|
big-endian processor and that there is no need for any byte swapping.
|
769 |
|
|
Hence the various HAL macros for performing I/O simply involve
|
770 |
|
|
pointers to volatile memory.
|
771 |
|
|
|
772 |
|
|
|
773 |
|
|
The variant, processor and platform equivalents of the
|
774 |
|
|
class="headerfile">cyg/hal/hal_io.h header will typically
|
775 |
|
|
also provide details of some or all of the peripherals, for example
|
776 |
|
|
register offsets and the meaning of various bits in those registers.
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
|
780 |
|
|
Cache Handling
|
781 |
|
|
|
782 |
|
|
If the processor has a cache then the variant HAL should implement the
|
783 |
|
|
CDL interface CYGINT_HAL_M68K_VARIANT_CACHE. This
|
784 |
|
|
causes the architectural header
|
785 |
|
|
class="headerfile">cyg/hal/hal_cache.h to pick up
|
786 |
|
|
appropriate definitions from
|
787 |
|
|
class="headerfile">cyg/hal/var_cache.h. The architectural
|
788 |
|
|
header will provide null defaults for anything not defined by the
|
789 |
|
|
variant.
|
790 |
|
|
|
791 |
|
|
|
792 |
|
|
|
793 |
|
|
Linker Scripts
|
794 |
|
|
|
795 |
|
|
The architectural HAL will generate the linker script for eCos
|
796 |
|
|
applications. This involves the architectural file
|
797 |
|
|
m68k.ld and a .ldi memory
|
798 |
|
|
layout file provided lower down, typically by the platform HAL. It is
|
799 |
|
|
the LDI file which specifies the types and amount of memory available
|
800 |
|
|
and which places code and data in appropriate places, but most of the
|
801 |
|
|
hard work is done via macros provided by the architectural
|
802 |
|
|
m68k.ld file.
|
803 |
|
|
|
804 |
|
|
|
805 |
|
|
|
806 |
|
|
Diagnostic Support
|
807 |
|
|
|
808 |
|
|
The architectural HAL does not implement diagnostic support. Instead
|
809 |
|
|
this is left to the variant or platform HAL, depending on whether
|
810 |
|
|
suitable peripherals are available on-chip or off-chip.
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
SMP Support
|
815 |
|
|
|
816 |
|
|
The M68K port does not have SMP support.
|
817 |
|
|
|
818 |
|
|
|
819 |
|
|
|
820 |
|
|
Debug Support
|
821 |
|
|
|
822 |
|
|
The M68K architectural HAL package provides basic support only for gdb
|
823 |
|
|
stubs. There is no support for more advanced debug features like
|
824 |
|
|
hardware watchpoints.
|
825 |
|
|
|
826 |
|
|
|
827 |
|
|
The generic gdb support in the common HAL requires a platform header
|
828 |
|
|
. In
|
829 |
|
|
practice there is rarely any need for the contents of this file to
|
830 |
|
|
change between platforms so the architectural HAL can provide a
|
831 |
|
|
suitable default. It will do so if the CDL interface
|
832 |
|
|
CYGINT_HAL_M68K_USE_STANDARD_PLATFORM_STUB_SUPPORT
|
833 |
|
|
is implemented.
|
834 |
|
|
|
835 |
|
|
|
836 |
|
|
|
837 |
|
|
HAL_DELAY_US Macro
|
838 |
|
|
|
839 |
|
|
The architectural HAL provides a default implementation of the
|
840 |
|
|
standard HAL_DELAY_US macro using a simply busy
|
841 |
|
|
loop. To use this support a lower-level HAL should define
|
842 |
|
|
_HAL_M68K_DELAY_US_LOOPS_, typically a small number
|
843 |
|
|
of about 20 but it will need to be calibrated during the porting
|
844 |
|
|
process. If the processor has a cache then the lower-level HAL may
|
845 |
|
|
also define _HAL_M68K_DELAY_US_LOOPS_UNCACHED_ for
|
846 |
|
|
the case when a delay loop is triggered while the cache is disabled.
|
847 |
|
|
|
848 |
|
|
|
849 |
|
|
|
850 |
|
|
Profiling Support
|
851 |
|
|
|
852 |
|
|
The M68K architectural HAL implements the mcount
|
853 |
|
|
function, allowing profiling tools like
|
854 |
|
|
gprof to determine the application's call
|
855 |
|
|
graph. It does not implement the profiling timer. Instead that
|
856 |
|
|
functionality needs to be provided by the variant or platform HAL.
|
857 |
|
|
The implementation of mcount requires a dedicated
|
858 |
|
|
frame pointer register so code should be compiled without the
|
859 |
|
|
flag.
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
|
|
Other Functionality
|
864 |
|
|
|
865 |
|
|
The M68K architectural HAL only implements the functionality provided
|
866 |
|
|
by the eCos HAL specification and does not export any extra
|
867 |
|
|
functionality.
|
868 |
|
|
|
869 |
|
|
|
870 |
|
|
|
871 |
|
|
|
872 |
|
|
|
873 |
|
|
|
874 |
|
|
|
875 |
|
|
|
876 |
|
|
|
877 |
|
|
|