source: rtems/cpukit/score/cpu/m68k/cpu_asm.S @ febaa8a

4.104.115
Last change on this file since febaa8a was febaa8a, checked in by Joel Sherrill <joel.sherrill@…>, on 03/27/10 at 15:03:09

2010-03-27 Joel Sherrill <joel.sherrill@…>

  • cpu.c, cpu_asm.S: Add include of config.h
  • Property mode set to 100644
File size: 13.4 KB
Line 
1/*  cpu_asm.s
2 *
3 *  This file contains all assembly code for the MC68020 implementation
4 *  of RTEMS.
5 *
6 *  COPYRIGHT (c) 1989-2008.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/asm.h>
22
23/*  void _CPU_Context_switch( run_context, heir_context )
24 *
25 *  This routine performs a normal non-FP context.
26 */
27
28        .align  4
29        .global SYM (_CPU_Context_switch)
30
31.set RUNCONTEXT_ARG,   4                 | save context argument
32.set HEIRCONTEXT_ARG,  8                 | restore context argument
33
34SYM (_CPU_Context_switch):
35          moval    a7@(RUNCONTEXT_ARG),a0| a0 = running thread context
36          movw     sr,d1                 | d1 = status register
37          movml    d1-d7/a2-a7,a0@       | save context
38
39          moval    a7@(HEIRCONTEXT_ARG),a0| a0 = heir thread context
40
41#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
42          moveb    a0@(13*4),d0                 | get context specific DF bit info in d0
43          btstb    #4,d0                        | test context specific DF bit info
44          beq      fpu_on                       | branch if FPU needs to be switched on
45
46fpu_off:  movl     _CPU_cacr_shadow,d0          | get content of _CPU_cacr_shadow in d0
47          btstl    #4,d0                        | test DF bit info in d0
48          bne      restore                      | branch if FPU is already switched off
49          bsetl    #4,d0                        | set DF bit in d0
50          bra      cacr_set                     | branch to set the new FPU setting in cacr and _CPU_cacr_shadow
51
52fpu_on:   movl     _CPU_cacr_shadow,d0          | get content of _CPU_cacr_shadow in d1
53          btstl    #4,d0                        | test context specific DF bit info
54          beq      restore                      | branch if FPU is already switched on
55          bclrl    #4,d0                        | clear DF bit info in d0
56
57cacr_set: movew    sr,d1                        | get content of sr in d1
58          oril     #0x00000700,d1               | mask d1
59          movew    d1,sr                        | disable all interrupts
60          movl     d0,_CPU_cacr_shadow          | move _CPU_cacr_shadow to d1
61          movec    d0,cacr                      | enable FPU in cacr
62#endif
63
64restore:  movml    a0@,d1-d7/a2-a7       | restore context
65          movw     d1,sr                 | restore status register
66          rts
67
68/*
69 * Floating point context save and restore.
70 *
71 * The code for the MC68881 or MC68882 is based upon the code shown on pages
72 * 6-38 of the MC68881/68882 Users Manual (rev 1).  CPU_FP_CONTEXT_SIZE is
73 * higher than expected to account for the -1 pushed at end of this sequence.
74 */
75
76#if ( CPU_HARDWARE_FP == TRUE )
77
78.set FPCONTEXT_ARG,   4                   | save FP context argument
79
80        .align  4
81        .global SYM (_CPU_Context_save_fp)
82SYM (_CPU_Context_save_fp):
83
84        /* Get context save area pointer argument from the stack */
85        moval    a7@(FPCONTEXT_ARG), a1
86        moval    a1@, a0
87
88  #if defined( __mcoldfire__ )
89        /* Move MACSR to data register and disable rounding */
90        movel    macsr, d0
91        clrl     d1
92        movl     d1, macsr
93
94        /* Save MACSR and ACC0 */
95        movl     acc0, d1
96        moveml   d0-d1, a0@(0)
97
98        /* Save ACC1 and ACC2 */
99        movl     acc1, d0
100        movl     acc2, d1
101        moveml   d0-d1, a0@(8)
102
103        /* Save ACC3 and ACCEXT01 */
104        movl     acc3, d0
105        movl     accext01, d1
106        moveml   d0-d1, a0@(16)
107
108        /* Save ACCEXT23 and MASK */
109        movl     accext23, d0
110        movl     mask, d1
111        moveml   d0-d1, a0@(24)
112
113    #if ( M68K_HAS_FPU == 1 )
114        /* Save FP state */
115        fsave    a0@(32)
116
117        /* Save FP instruction address */
118        fmovel   fpi, a0@(48)
119
120        /* Save FP data */
121        fmovem   fp0-fp7, a0@(52)
122    #endif
123  #else
124    #if defined( __mc68060__ )
125        lea      a0@(-M68K_FP_STATE_SIZE), a0
126        fsave    a0@                      | save 68060 state frame
127    #else
128        fsave    a0@-                     | save 68881/68882 state frame
129    #endif
130        tstb     a0@                      | check for a null frame
131        beq.b    nosv                     | Yes, skip save of user model
132        fmovem   fp0-fp7, a0@-            | save data registers (fp0-fp7)
133        fmovem   fpc/fps/fpi, a0@-        | and save control registers
134        movl     #-1, a0@-                | place not-null flag on stack
135nosv:
136        movl     a0, a1@                  | save pointer to saved context
137  #endif
138
139        /* Return */
140        rts
141
142        .align  4
143        .global SYM (_CPU_Context_restore_fp)
144SYM (_CPU_Context_restore_fp):
145
146        /* Get context save area pointer argument from the stack */
147        moval    a7@(FPCONTEXT_ARG), a1
148        moval    a1@, a0
149
150  #if defined( __mcoldfire__ )
151    #if ( M68K_HAS_FPU == 1 )
152        /* Restore FP data */
153        fmovem   a0@(52), fp0-fp7
154
155        /* Restore FP instruction address */
156        fmovel   a0@(48), fpi
157
158        /* Restore FP state */
159        frestore a0@(32)
160    #endif
161
162        /* Disable rounding */
163        clrl     d0
164        movl     d0, macsr
165
166        /* Restore MASK and ACCEXT23 */
167        moveml   a0@(24), d0-d1
168        movl     d0, mask
169        movl     d1, accext23
170
171        /* Restore ACCEXT01 and ACC3 */
172        moveml   a0@(16), d0-d1
173        movl     d0, accext01
174        movl     d1, acc3
175
176        /* Restore ACC2 and ACC1 */
177        moveml   a0@(8), d0-d1
178        movl     d0, acc2
179        movl     d1, acc1
180
181        /* Restore ACC0 and MACSR */
182        moveml   a0@(0), d0-d1
183        movl     d0, acc0
184        movl     d1, macsr
185  #else
186        tstb     a0@                      | Null context frame?
187        beq.b    norst                    | Yes, skip fp restore
188        addql    #4, a0                   | throwaway non-null flag
189        fmovem   a0@+, fpc/fps/fpi        | restore control registers
190        fmovem   a0@+, fp0-fp7            | restore data regs (fp0-fp7)
191norst:
192    #if defined( __mc68060__ )
193        frestore a0@                      | restore 68060 state frame
194        lea      a0@(M68K_FP_STATE_SIZE), a0
195    #else
196        frestore a0@+                     | restore 68881/68882 state frame
197    #endif
198        movl     a0, a1@                  | save pointer to saved context
199  #endif
200
201        /* Return */
202        rts
203#endif
204
205/*PAGE
206 *  void _ISR_Handler()
207 *
208 *  This routine provides the RTEMS interrupt management.
209 *
210 *  NOTE:
211 *    Upon entry, the master stack will contain an interrupt stack frame
212 *    back to the interrupted thread and the interrupt stack will contain
213 *    a throwaway interrupt stack frame.  If dispatching is enabled, and this
214 *    is the outer most interrupt, and a context switch is necessary or
215 *    the current thread has pending signals, then set up the master stack to
216 *    transfer control to the interrupt dispatcher.
217 */
218
219#if ( defined(__mcoldfire__) )
220.set SR_OFFSET,    2                     | Status register offset
221.set PC_OFFSET,    4                     | Program Counter offset
222.set FVO_OFFSET,   0                     | Format/vector offset
223#elif ( M68K_HAS_VBR == 1)
224.set SR_OFFSET,    0                     | Status register offset
225.set PC_OFFSET,    2                     | Program Counter offset
226.set FVO_OFFSET,   6                     | Format/vector offset
227#else
228.set SR_OFFSET,    2                     | Status register offset
229.set PC_OFFSET,    4                     | Program Counter offset
230.set FVO_OFFSET,   0                     | Format/vector offset placed in the stack
231#endif /* M68K_HAS_VBR */
232
233.set SAVED,        16                    | space for saved registers
234
235        .align  4
236        .global SYM (_ISR_Handler)
237
238SYM (_ISR_Handler):
239                                         | disable multitasking
240        addql   #1,SYM (_Thread_Dispatch_disable_level)
241#if ( !defined(__mcoldfire__) )
242        moveml  d0-d1/a0-a1,a7@-         | save d0-d1,a0-a1
243#else
244        lea     a7@(-SAVED),a7
245        movm.l  d0-d1/a0-a1,a7@          | save d0-d1,a0-a1
246#endif
247        movew   a7@(SAVED+FVO_OFFSET),d0 | d0 = F/VO
248        andl    #0x03fc,d0               | d0 = vector offset in vbr
249
250
251#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
252        | Make a0 point just above interrupt stack
253        movel   _CPU_Interrupt_stack_high,a0
254        cmpl    _CPU_Interrupt_stack_low,a7  | stack below interrupt stack?
255        bcs.b   1f                      | yes, switch to interrupt stack
256        cmpl    a0,a7                   | stack above interrupt stack?
257        bcs.b   2f                      | no, do not switch stacks
2581:
259        movel   a7,a1                   | copy task stack pointer
260        movel   a0,a7                   | switch to interrupt stack
261        movel   a1,a7@-                 | store task stack pointer
262                                        |     on interrupt stack
2632:
264#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
265
266        addql   #1,SYM(_ISR_Nest_level) | one nest level deeper
267
268        movel   SYM (_ISR_Vector_table),a0 | a0= base of RTEMS table
269#if ( M68K_HAS_PREINDEXING == 1 )
270        movel   (a0,d0:w:1),a0           | a0 = address of user routine
271#else
272        addal   d0,a0                    | a0 = address of vector
273        movel   (a0),a0                  | a0 = address of user routine
274#endif
275
276        lsrl    #2,d0                    | d0 = vector number
277        movel   d0,a7@-                  | push vector number
278        jbsr    a0@                      | invoke the user ISR
279        addql   #4,a7                    | remove vector number
280        subql   #1,SYM(_ISR_Nest_level)  | Reduce interrupt-nesting count
281
282#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
283        movel   _CPU_Interrupt_stack_high,a0
284        subql   #4,a0
285        cmpl    a0,a7                   | At top of interrupt stack?
286        bne.b   1f                      | No, do not restore task stack pointer
287        movel   (a7),a7                 | Restore task stack pointer
2881:
289#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
290        subql   #1,SYM (_Thread_Dispatch_disable_level)
291                                         | unnest multitasking
292        bne.b    exit                    | If dispatch disabled, exit
293
294#if ( M68K_HAS_SEPARATE_STACKS == 1 )
295        movew   #0xf000,d0               | isolate format nibble
296        andw    a7@(SAVED+FVO_OFFSET),d0 | get F/VO
297        cmpiw   #0x1000,d0               | is it a throwaway isf?
298        bne.b   exit                     | NOT outer level, so branch
299#else
300/*
301 * If we have a CPU which allows a higher-priority interrupt to preempt a
302 * lower priority handler before the lower-priority handler can increment
303 * _Thread_Dispatch_disable_level then we must check the PC on the stack to
304 * see if it is _ISR_Handler.  If it is we have the case of nesting interrupts
305 * without the dispatch level being incremented.
306 */
307  #if ( !defined(__mcoldfire__) && !__mc68060__ )
308        cmpl    #_ISR_Handler,a7@(SAVED+PC_OFFSET)
309        beq.b   exit
310  #endif
311#endif
312        tstb    SYM (_Context_Switch_necessary)
313                                         | Is thread switch necessary?
314        bne.b   bframe                   | Yes, invoke dispatcher
315
316        tstb    SYM (_ISR_Signals_to_thread_executing)
317                                         | signals sent to Run_thread
318                                         |   while in interrupt handler?
319        beq.b   exit                     | No, then exit
320
321bframe: clrb    SYM (_ISR_Signals_to_thread_executing)
322                                         | If sent, will be processed
323#if ( M68K_HAS_SEPARATE_STACKS == 1 )
324        movec   msp,a0                   | a0 = master stack pointer
325        movew   #0,a0@-                  | push format word
326        movel   #SYM(_ISR_Dispatch),a0@- | push return addr
327        movew   a0@(6),a0@-              | push saved sr
328        movec   a0,msp                   | set master stack pointer
329#else
330        jsr SYM (_Thread_Dispatch)       | Perform context switch
331#endif
332
333#if ( !defined(__mcoldfire__) )
334exit:   moveml  a7@+,d0-d1/a0-a1         | restore d0-d1,a0-a1
335#else
336exit:   moveml  a7@,d0-d1/a0-a1          | restore d0-d1,a0-a1
337        lea     a7@(SAVED),a7
338#endif
339
340#if ( M68K_HAS_VBR == 0 )
341        addql   #2,a7                    | pop format/id
342#endif /* M68K_HAS_VBR */
343        rte                              | return to thread
344                                         |   OR _Isr_dispatch
345
346/*PAGE
347 *  void _ISR_Dispatch()
348 *
349 *  Entry point from the outermost interrupt service routine exit.
350 *  The current stack is the supervisor mode stack if this processor
351 *  has separate stacks.
352 *
353 *    1.  save all registers not preserved across C calls.
354 *    2.  invoke the _Thread_Dispatch routine to switch tasks
355 *        or a signal to the currently executing task.
356 *    3.  restore all registers not preserved across C calls.
357 *    4.  return from interrupt
358 */
359
360        .global SYM (_ISR_Dispatch)
361SYM (_ISR_Dispatch):
362#if ( !defined(__mcoldfire__) )
363        movml   d0-d1/a0-a1,a7@-
364        jsr     SYM (_Thread_Dispatch)
365        movml   a7@+,d0-d1/a0-a1
366#else
367        lea     a7@(-SAVED),a7
368        movml   d0-d1/a0-a1,a7@
369        jsr     SYM (_Thread_Dispatch)
370        movml   a7@,d0-d1/a0-a1
371        lea     a7@(SAVED),a7
372#endif
373
374#if ( M68K_HAS_VBR == 0 )
375        addql   #2,a7                    | pop format/id
376#endif /* M68K_HAS_VBR */
377        rte
Note: See TracBrowser for help on using the repository browser.