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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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