source: rtems-docs/cpu-supplement/m68xxx_and_coldfire.rst

Last change on this file was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 13.6 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3
4M68xxx and Coldfire Specific Information
5****************************************
6
7This chapter discusses the Freescale (formerly Motorola) MC68xxx and Coldfire
8architectural dependencies.  The MC68xxx family has a wide variety of CPU
9models within it based upon different CPU core implementations.  Ignoring the
10Coldfire parts, the part numbers for these models are generally divided into
11MC680xx and MC683xx.  The MC680xx models are more general purpose processors
12with no integrated peripherals.  The MC683xx models, on the other hand, are
13more specialized and have a variety of peripherals on chip including
14sophisticated timers and serial communications controllers.
15
16**Architecture Documents**
17
18For information on the MC68xxx and Coldfire architecture, refer to the
19following documents available from Freescale website
20(http//www.freescale.com/):
21
22- *M68000 Family Reference, Motorola, FR68K/D*.
23
24- *MC68020 User's Manual, Motorola, MC68020UM/AD*.
25
26- *MC68881/MC68882 Floating-Point Coprocessor User's Manual,
27  Motorola, MC68881UM/AD*.
28
29CPU Model Dependent Features
30============================
31
32This section presents the set of features which vary across m68k/Coldfire
33implementations that are of importance to RTEMS.  The set of CPU model feature
34macros are defined in the file :file:`cpukit/score/cpu/m68k/m68k.h` based upon
35the particular CPU model selected on the compilation command line.
36
37BFFFO Instruction
38-----------------
39
40The macro ``M68K_HAS_BFFFO`` is set to 1 to indicate that this CPU model has
41the bfffo instruction.
42
43Vector Base Register
44--------------------
45
46The macro ``M68K_HAS_VBR`` is set to 1 to indicate that this CPU model has a
47vector base register (vbr).
48
49Separate Stacks
50---------------
51
52The macro ``M68K_HAS_SEPARATE_STACKS`` is set to 1 to indicate that this CPU
53model has separate interrupt, user, and supervisor mode stacks.
54
55Pre-Indexing Address Mode
56-------------------------
57
58The macro ``M68K_HAS_PREINDEXING`` is set to 1 to indicate that this CPU model
59has the pre-indexing address mode.
60
61Extend Byte to Long Instruction
62-------------------------------
63
64The macro ``M68K_HAS_EXTB_L`` is set to 1 to indicate that this CPU model has
65the extb.l instruction.  This instruction is supposed to be available in all
66models based on the cpu32 core as well as mc68020 and up models.
67
68Calling Conventions
69===================
70
71The MC68xxx architecture supports a simple yet effective call and return
72mechanism.  A subroutine is invoked via the branch to subroutine (``bsr``) or
73the jump to subroutine (``jsr``) instructions.  These instructions push the
74return address on the current stack.  The return from subroutine (``rts``)
75instruction pops the return address off the current stack and transfers control
76to that instruction.  It is is important to note that the MC68xxx call and
77return mechanism does not automatically save or restore any registers.  It is
78the responsibility of the high-level language compiler to define the register
79preservation and usage convention.
80
81Calling Mechanism
82-----------------
83
84All RTEMS directives are invoked using either a ``bsr`` or ``jsr`` instruction
85and return to the user application via the rts instruction.
86
87Register Usage
88--------------
89
90As discussed above, the ``bsr`` and ``jsr`` instructions do not automatically
91save any registers.  RTEMS uses the registers D0, D1, A0, and A1 as scratch
92registers.  These registers are not preserved by RTEMS directives therefore,
93the contents of these registers should not be assumed upon return from any
94RTEMS directive.
95
96Parameter Passing
97-----------------
98
99RTEMS assumes that arguments are placed on the current stack before the
100directive is invoked via the bsr or jsr instruction.  The first argument is
101assumed to be closest to the return address on the stack.  This means that the
102first argument of the C calling sequence is pushed last.  The following
103pseudo-code illustrates the typical sequence used to call a RTEMS directive
104with three (3) arguments:
105
106.. code-block:: c
107
108    push third argument
109    push second argument
110    push first argument
111    invoke directive
112    remove arguments from the stack
113
114The arguments to RTEMS are typically pushed onto the stack using a move
115instruction with a pre-decremented stack pointer as the destination.  These
116arguments must be removed from the stack after control is returned to the
117caller.  This removal is typically accomplished by adding the size of the
118argument list in bytes to the current stack pointer.
119
120Memory Model
121============
122
123The MC68xxx family supports a flat 32-bit address space with addresses ranging
124from 0x00000000 to 0xFFFFFFFF (4 gigabytes).  Each address is represented by a
12532-bit value and is byte addressable.  The address may be used to reference a
126single byte, word (2-bytes), or long word (4 bytes).  Memory accesses within
127this address space are performed in big endian fashion by the processors in
128this family.
129
130Some of the MC68xxx family members such as the MC68020, MC68030, and MC68040
131support virtual memory and segmentation.  The MC68020 requires external
132hardware support such as the MC68851 Paged Memory Management Unit coprocessor
133which is typically used to perform address translations for these systems.
134RTEMS does not support virtual memory or segmentation on any of the MC68xxx
135family members.
136
137Interrupt Processing
138====================
139
140Discussed in this section are the MC68xxx's interrupt response and control
141mechanisms as they pertain to RTEMS.
142
143Vectoring of an Interrupt Handler
144---------------------------------
145
146Depending on whether or not the particular CPU supports a separate interrupt
147stack, the MC68xxx family has two different interrupt handling models.
148
149Models Without Separate Interrupt Stacks
150~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151
152Upon receipt of an interrupt the MC68xxx family members without separate
153interrupt stacks automatically use software to switch stacks.
154
155Models With Separate Interrupt Stacks
156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157
158Upon receipt of an interrupt the MC68xxx family members with separate interrupt
159stacks automatically perform the following actions:
160
161- saves the current status register (SR),
162
163- clears the master/interrupt (M) bit of the SR to indicate the switch from
164  master state to interrupt state,
165
166- sets the privilege mode to supervisor,
167
168- suppresses tracing,
169
170- sets the interrupt mask level equal to the level of the interrupt being
171  serviced,
172
173- pushes an interrupt stack frame (ISF), which includes the program counter
174  (PC), the status register (SR), and the format/exception vector offset (FVO)
175  word, onto the supervisor and interrupt stacks,
176
177- switches the current stack to the interrupt stack and vectors to an interrupt
178  service routine (ISR).  If the ISR was installed with the interrupt_catch
179  directive, then the RTEMS interrupt handler will begin execution.  The RTEMS
180  interrupt handler saves all registers which are not preserved according to
181  the calling conventions and invokes the application's ISR.
182
183A nested interrupt is processed similarly by these CPU models with the
184exception that only a single ISF is placed on the interrupt stack and the
185current stack need not be switched.
186
187The FVO word in the Interrupt Stack Frame is examined by RTEMS to determine
188when an outer most interrupt is being exited. Since the FVO is used by RTEMS
189for this purpose, the user application code MUST NOT modify this field.
190
191The following shows the Interrupt Stack Frame for MC68xxx CPU models with
192separate interrupt stacks:
193
194+----------------------+-----+
195|    Status Register   | 0x0 |
196+----------------------+-----+
197| Program Counter High | 0x2 |
198+----------------------+-----+
199| Program Counter Low  | 0x4 |
200+----------------------+-----+
201| Format/Vector Offset | 0x6 |
202+----------------------+-----+
203
204
205CPU Models Without VBR and RAM at 0
206-----------------------------------
207
208This is from a post by Zoltan Kocsi <zoltan@bendor.com.au> and is a nice trick
209in certain situations.  In his words:
210
211I think somebody on this list asked about the interupt vector handling w/o VBR
212and RAM at 0.  The usual trick is to initialise the vector table (except the
213first 2 two entries, of course) to point to the same location BUT you also add
214the vector number times 0x1000000 to them. That is, bits 31-24 contain the
215vector number and 23-0 the address of the common handler.  Since the PC is 32
216bit wide but the actual address bus is only 24, the top byte will be in the PC
217but will be ignored when jumping onto your routine.
218
219Then your common interrupt routine gets this info by loading the PC into some
220register and based on that info, you can jump to a vector in a vector table
221pointed by a virtual VBR:
222
223.. code-block:: c
224
225    //
226    //  Real vector table at 0
227    //
228    .long   initial_sp
229    .long   initial_pc
230    .long   myhandler+0x02000000
231    .long   myhandler+0x03000000
232    .long   myhandler+0x04000000
233    ...
234    .long   myhandler+0xff000000
235    //
236    // This handler will jump to the interrupt routine   of which
237    // the address is stored at VBR[ vector_no ]
238    // The registers and stackframe will be intact, the interrupt
239    // routine will see exactly what it would see if it was called
240    // directly from the HW vector table at 0.
241    //
242        .comm    VBR,4,2        // This defines the 'virtual' VBR
243    // From C: extern void *VBR;
244    myhandler:                  // At entry, PC contains the full vector
245        move.l  %d0,-(%sp)      // Save d0
246        move.l  %a0,-(%sp)      // Save a0
247        lea     0(%pc),%a0      // Get the value of the PC
248        move.l  %a0,%d0         // Copy it to a data reg, d0 is VV??????
249        swap    %d0             // Now d0 is ????VV??
250        and.w   #0xff00,%d0     // Now d0 is ????VV00 (1)
251        lsr.w   #6,%d0          // Now d0.w contains the VBR table offset
252        move.l  VBR,%a0         // Get the address from VBR to a0
253        move.l  (%a0,%d0.w),%a0 // Fetch the vector
254        move.l  4(%sp),%d0      // Restore d0
255        move.l  %a0,4(%sp)      // Place target address to the stack
256        move.l  (%sp)+,%a0      // Restore a0, target address is on TOS
257        ret                     // This will jump to the handler and
258    // restore the stack
259
260(1) If 'myhandler' is guaranteed to be in the first 64K, e.g. just
261    after the vector table then that insn is not needed.
262
263There are probably shorter ways to do this, but it I believe is enough to
264illustrate the trick. Optimisation is left as an exercise to the reader :-)
265
266Interrupt Levels
267----------------
268
269Eight levels (0-7) of interrupt priorities are supported by MC68xxx family
270members with level seven (7) being the highest priority.  Level zero (0)
271indicates that interrupts are fully enabled.  Interrupt requests for interrupts
272with priorities less than or equal to the current interrupt mask level are
273ignored.
274
275Although RTEMS supports 256 interrupt levels, the MC68xxx family only supports
276eight.  RTEMS interrupt levels 0 through 7 directly correspond to MC68xxx
277interrupt levels.  All other RTEMS interrupt levels are undefined and their
278behavior is unpredictable.
279
280Default Fatal Error Processing
281==============================
282
283The default fatal error handler for this architecture disables processor
284interrupts to level 7, places the error code in D0, and executes a ``stop``
285instruction to simulate a halt processor instruction.
286
287Symmetric Multiprocessing
288=========================
289
290SMP is not supported.
291
292Thread-Local Storage
293====================
294
295Thread-local storage is supported.
296
297Board Support Packages
298======================
299
300System Reset
301------------
302
303An RTEMS based application is initiated or re-initiated when the MC68020
304processor is reset.  When the MC68020 is reset, the processor performs the
305following actions:
306
307- The tracing bits of the status register are cleared to disable tracing.
308
309- The supervisor interrupt state is entered by setting the supervisor (S) bit
310  and clearing the master/interrupt (M) bit of the status register.
311
312- The interrupt mask of the status register is set to level 7 to effectively
313  disable all maskable interrupts.
314
315- The vector base register (VBR) is set to zero.
316
317- The cache control register (CACR) is set to zero to disable and freeze the
318  processor cache.
319
320- The interrupt stack pointer (ISP) is set to the value stored at vector 0
321  (bytes 0-3) of the exception vector table (EVT).
322
323- The program counter (PC) is set to the value stored at vector 1 (bytes 4-7)
324  of the EVT.
325
326- The processor begins execution at the address stored in the PC.
327
328Processor Initialization
329------------------------
330
331The address of the application's initialization code should be stored in the
332first vector of the EVT which will allow the immediate vectoring to the
333application code.  If the application requires that the VBR be some value
334besides zero, then it should be set to the required value at this point.  All
335tasks share the same MC68020's VBR value.  Because interrupts are enabled
336automatically by RTEMS as part of the context switch to the first task, the VBR
337MUST be set by either RTEMS of the BSP before this occurs ensure correct
338interrupt vectoring.  If processor caching is to be utilized, then it should be
339enabled during the reset application initialization code.
340
341In addition to the requirements described in the Board Support Packages chapter
342of the Applications User's Manual for the reset code which is executed before
343the call to initialize executive, the MC68020 version has the following
344specific requirements:
345
346- Must leave the S bit of the status register set so that the MC68020 remains
347  in the supervisor state.
348
349- Must set the M bit of the status register to remove the MC68020 from the
350  interrupt state.
351
352- Must set the master stack pointer (MSP) such that a minimum stack size of
353  MINIMUM_STACK_SIZE bytes is provided for the initialize executive directive.
354
355- Must initialize the MC68020's vector table.
Note: See TracBrowser for help on using the repository browser.