source: rtems-docs/cpu_supplement/m68xxx_and_coldfire.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

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