OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [cpu/] [m68k/] [cpu_asm.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*  cpu_asm.s
2
 *
3
 *  This file contains all assembly code for the MC68020 implementation
4
 *  of RTEMS.
5
 *
6
 *  COPYRIGHT (c) 1989-2001.
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.OARcorp.com/rtems/license.html.
12
 *
13
 *  cpu_asm.S,v 1.4 2001/08/09 21:04:29 joel Exp
14
 */
15
 
16
 
17
#include 
18
 
19
        .text
20
 
21
/*  void _CPU_Context_switch( run_context, heir_context )
22
 *
23
 *  This routine performs a normal non-FP context.
24
 */
25
 
26
        .align  4
27
        .global SYM (_CPU_Context_switch)
28
 
29
.set RUNCONTEXT_ARG,   4                   | save context argument
30
.set HEIRCONTEXT_ARG,  8                   | restore context argument
31
 
32
SYM (_CPU_Context_switch):
33
          moval    a7@(RUNCONTEXT_ARG),a0| a0 = running thread context
34
          movw     sr,d1                 | d1 = status register
35
          movml    d1-d7/a2-a7,a0@       | save context
36
 
37
          moval    a7@(HEIRCONTEXT_ARG),a0| a0 = heir thread context
38
restore:  movml    a0@,d1-d7/a2-a7     | restore context
39
          movw     d1,sr                  | restore status register
40
          rts
41
 
42
/*PAGE
43
 *  void __CPU_Context_save_fp_context( &fp_context_ptr )
44
 *  void __CPU_Context_restore_fp_context( &fp_context_ptr )
45
 *
46
 *  These routines are used to context switch a MC68881 or MC68882.
47
 *
48
 *  NOTE:  Context save and restore code is based upon the code shown
49
 *         on page 6-38 of the MC68881/68882 Users Manual (rev 1).
50
 *
51
 *         CPU_FP_CONTEXT_SIZE is higher than expected to account for the
52
 *         -1 pushed at end of this sequence.
53
 *
54
 *         Neither of these entries is required if we have software FPU
55
 *         emulation.  But if we don't have an FPU or emulation, then
56
 *         we need the stub versions of these routines.
57
 */
58
 
59
#if (CPU_SOFTWARE_FP == FALSE)
60
 
61
.set FPCONTEXT_ARG,   4                    | save FP context argument
62
 
63
        .align  4
64
        .global SYM (_CPU_Context_save_fp)
65
SYM (_CPU_Context_save_fp):
66
#if ( M68K_HAS_FPU == 1 )
67
        moval    a7@(FPCONTEXT_ARG),a1    | a1 = &ptr to context area
68
        moval    a1@,a0                   | a0 = Save context area
69
        fsave    a0@-                     | save 68881/68882 state frame
70
        tstb     a0@                      | check for a null frame
71
        beq.b    nosv                     | Yes, skip save of user model
72
        fmovem   fp0-fp7,a0@-             | save data registers (fp0-fp7)
73
        fmovem   fpc/fps/fpi,a0@-         | and save control registers
74
        movl     #-1,a0@-                 | place not-null flag on stack
75
nosv:   movl     a0,a1@                   | save pointer to saved context
76
#endif
77
        rts
78
 
79
        .align  4
80
        .global SYM (_CPU_Context_restore_fp)
81
SYM (_CPU_Context_restore_fp):
82
#if ( M68K_HAS_FPU == 1 )
83
        moval    a7@(FPCONTEXT_ARG),a1    | a1 = &ptr to context area
84
        moval    a1@,a0                   | a0 = address of saved context
85
        tstb     a0@                      | Null context frame?
86
        beq.b    norst                    | Yes, skip fp restore
87
        addql    #4,a0                    | throwaway non-null flag
88
        fmovem   a0@+,fpc/fps/fpi         | restore control registers
89
        fmovem   a0@+,fp0-fp7             | restore data regs (fp0-fp7)
90
norst:  frestore a0@+                     | restore the fp state frame
91
        movl     a0,a1@                   | save pointer to saved context
92
#endif
93
        rts
94
#endif
95
 
96
/*PAGE
97
 *  void _ISR_Handler()
98
 *
99
 *  This routine provides the RTEMS interrupt management.
100
 *
101
 *  NOTE:
102
 *    Upon entry, the master stack will contain an interrupt stack frame
103
 *    back to the interrupted thread and the interrupt stack will contain
104
 *    a throwaway interrupt stack frame.  If dispatching is enabled, and this
105
 *    is the outer most interrupt, and a context switch is necessary or
106
 *    the current thread has pending signals, then set up the master stack to
107
 *    transfer control to the interrupt dispatcher.
108
 */
109
 
110
#if ( M68K_COLDFIRE_ARCH == 1 )
111
.set SR_OFFSET,    2                     | Status register offset
112
.set PC_OFFSET,    4                     | Program Counter offset
113
.set FVO_OFFSET,   0                     | Format/vector offset
114
#elif ( M68K_HAS_VBR == 1)
115
.set SR_OFFSET,    0                     | Status register offset
116
.set PC_OFFSET,    2                     | Program Counter offset
117
.set FVO_OFFSET,   6                     | Format/vector offset
118
#else
119
.set SR_OFFSET,    2                     | Status register offset
120
.set PC_OFFSET,    4                     | Program Counter offset
121
.set FVO_OFFSET,   0                     | Format/vector offset placed in the stack
122
#endif /* M68K_HAS_VBR */
123
 
124
.set SAVED,        16                    | space for saved registers
125
 
126
        .align  4
127
        .global SYM (_ISR_Handler)
128
 
129
SYM (_ISR_Handler):
130
        addql   #1,SYM (_Thread_Dispatch_disable_level) | disable multitasking
131
#if ( M68K_COLDFIRE_ARCH == 0 )
132
        moveml  d0-d1/a0-a1,a7@-         | save d0-d1,a0-a1
133
#else
134
        lea     a7@(-SAVED),a7
135
        movm.l  d0-d1/a0-a1,a7@          | save d0-d1,a0-a1
136
#endif
137
        movew   a7@(SAVED+FVO_OFFSET),d0 | d0 = F/VO
138
        andl    #0x0ffc,d0               | d0 = vector offset in vbr
139
 
140
 
141
#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
142
        movel   _CPU_Interrupt_stack_high,a0    | a0 now point just above interrupt stack
143
        cmpl    _CPU_Interrupt_stack_low,a7     | stack below interrupt stack?
144
        bcs.b   1f                      | yes, switch to interrupt stack
145
        cmpl    a0,a7                   | stack above interrupt stack?
146
        bcs.b   2f                      | no, do not switch stacks
147
1:
148
        movel   a7,a1                   | copy task stack pointer
149
        movel   a0,a7                   | switch to interrupt stack
150
        movel   a1,a7@-                 | store task stack pointer on interrupt stack
151
2:
152
#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
153
 
154
        movel   SYM (_ISR_Vector_table),a0 | a0= base of RTEMS table
155
#if ( M68K_HAS_PREINDEXING == 1 )
156
        movel   (a0,d0:w:1),a0           | a0 = address of user routine
157
#else
158
        addal   d0,a0                    | a0 = address of vector
159
        movel   (a0),a0                  | a0 = address of user routine
160
#endif
161
 
162
        lsrl    #2,d0                    | d0 = vector number
163
        movel   d0,a7@-                  | push vector number
164
        jbsr    a0@                      | invoke the user ISR
165
        addql   #4,a7                    | remove vector number
166
 
167
#if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 )
168
        movel   _CPU_Interrupt_stack_high,a0
169
        subql   #4,a0
170
        cmpl    a0,a7                   | At top of interrupt stack?
171
        bne.b   1f                      | No, do not restore task stack pointer
172
        movel   (a7),a7                 | Restore task stack pointer
173
1:
174
#endif /* CPU_HAS_SOFTWARE_INTERRUPT_STACK == 1 */
175
 
176
        subql   #1,SYM (_Thread_Dispatch_disable_level)
177
                                         | unnest multitasking
178
        bne.b    exit                    | If dispatch disabled, exit
179
 
180
#if ( M68K_HAS_SEPARATE_STACKS == 1 )
181
        movew   #0xf000,d0               | isolate format nibble
182
        andw    a7@(SAVED+FVO_OFFSET),d0 | get F/VO
183
        cmpiw   #0x1000,d0               | is it a throwaway isf?
184
        bne.b   exit                     | NOT outer level, so branch
185
#else
186
/*
187
 * If we have a CPU which allows a higher-priority interrupt to preempt a
188
 * lower priority handler before the lower-priority handler can increment
189
 * _Thread_Dispatch_disable_level then we must check the PC on the stack to
190
 * see if it is _ISR_Handler.  If it is we have the case of nesting interrupts
191
 * without the dispatch level being incremented.
192
 */
193
  #if ( M68K_COLDFIRE_ARCH == 0 && M68K_MC68060_ARCH == 0 )
194
        cmpl    #_ISR_Handler,a7@(SAVED+PC_OFFSET)
195
        beq.b   exit
196
  #endif
197
#endif
198
        tstl    SYM (_Context_Switch_necessary)
199
                                         | Is thread switch necessary?
200
        bne.b   bframe                   | Yes, invoke dispatcher
201
 
202
        tstl    SYM (_ISR_Signals_to_thread_executing)
203
                                         | signals sent to Run_thread
204
                                         |   while in interrupt handler?
205
        beq.b   exit                     | No, then exit
206
 
207
bframe: clrl    SYM (_ISR_Signals_to_thread_executing)
208
                                         | If sent, will be processed
209
#if ( M68K_HAS_SEPARATE_STACKS == 1 )
210
        movec   msp,a0                   | a0 = master stack pointer
211
        movew   #0,a0@-                  | push format word
212
        movel   #SYM(_ISR_Dispatch),a0@- | push return addr
213
        movew   a0@(6),a0@-              | push saved sr
214
        movec   a0,msp                   | set master stack pointer
215
#else
216
        jsr SYM (_Thread_Dispatch)       | Perform context switch
217
#endif
218
 
219
#if ( M68K_COLDFIRE_ARCH == 0 )
220
exit:   moveml  a7@+,d0-d1/a0-a1         | restore d0-d1,a0-a1
221
#else
222
exit:   moveml  a7@,d0-d1/a0-a1          | restore d0-d1,a0-a1
223
        lea     a7@(SAVED),a7
224
#endif
225
 
226
#if ( M68K_HAS_VBR == 0 )
227
        addql   #2,a7                    | pop format/id
228
#endif /* M68K_HAS_VBR */
229
        rte                              | return to thread
230
                                         |   OR _Isr_dispatch
231
 
232
/*PAGE
233
 *  void _ISR_Dispatch()
234
 *
235
 *  Entry point from the outermost interrupt service routine exit.
236
 *  The current stack is the supervisor mode stack if this processor
237
 *  has separate stacks.
238
 *
239
 *    1.  save all registers not preserved across C calls.
240
 *    2.  invoke the _Thread_Dispatch routine to switch tasks
241
 *        or a signal to the currently executing task.
242
 *    3.  restore all registers not preserved across C calls.
243
 *    4.  return from interrupt
244
 */
245
 
246
        .global SYM (_ISR_Dispatch)
247
SYM (_ISR_Dispatch):
248
#if ( M68K_COLDFIRE_ARCH == 0 )
249
        movml   d0-d1/a0-a1,a7@-
250
        jsr     SYM (_Thread_Dispatch)
251
        movml   a7@+,d0-d1/a0-a1
252
#else
253
        lea     a7@(-SAVED),a7
254
        movml   d0-d1/a0-a1,a7@
255
        jsr     SYM (_Thread_Dispatch)
256
        movml   a7@,d0-d1/a0-a1
257
        lea     a7@(SAVED),a7
258
#endif
259
 
260
#if ( M68K_HAS_VBR == 0 )
261
        addql   #2,a7                    | pop format/id
262
#endif /* M68K_HAS_VBR */
263
        rte

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.