source: trunk/libs/newlib/src/libgloss/m68k/mvme162lx-asm.S @ 546

Last change on this file since 546 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 10.4 KB
RevLine 
[444]1/*
2 * mvme162lx-asm.S -- assembler routines for the MVME stub.
3 *
4 * This code was pulled out of mvme162lx-stub.c by Ian Taylor so that I
5 * could handle different register and label prefixes in a sensible
6 * way.
7 */
8
9/****************************************************************************
10
11                THIS SOFTWARE IS NOT COPYRIGHTED 
12   
13   HP offers the following for use in the public domain.  HP makes no
14   warranty with regard to the software or it's performance and the
15   user accepts the software "AS IS" with all faults.
16
17   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
18   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20
21****************************************************************************/
22
23#include "asm.h"
24
25        .title "mvme162lx-asm.S for m68k"
26
27        .globl SYM (registers)
28        .globl SYM (lastFrame)
29        .globl SYM (superStack)
30        .globl SYM (exceptionHook)
31        .globl SYM (_returnFromException)
32        .globl SYM (stackPtr)
33        .globl SYM (handle_exception)
34        .globl SYM (exceptionSize)
35
36.text
37.globl SYM (return_to_super)
38SYM (return_to_super):
39        movel   SYM (registers)+60,sp /* get new stack pointer */
40        movel   SYM (lastFrame),a0    /* get last frame info  */
41        bra     return_to_any
42
43.globl SYM (return_to_user)
44SYM (return_to_user):
45        movel   SYM (registers)+60,a0   /* get usp */
46        movel   a0,usp           /* set usp */
47        movel   SYM (superStack),sp    /* get original stack pointer */
48
49return_to_any:
50        movel   SYM (lastFrame),a0     /* get last frame info  */
51        movel   a0@+,SYM (lastFrame)   /* link in previous frame     */
52        addql   IMM (8),a0            /* skip over pc, vector#*/             
53        movew   a0@+,d0         /* get # of words in cpu frame */       
54        addw    d0,a0           /* point to end of data        */       
55        addw    d0,a0           /* point to end of data        */       
56        movel   a0,a1
57/* copy the stack frame */
58        subql   IMM (1),d0
59copyUserLoop:                                                               
60        movew   a1@-,sp@-                                               
61        dbf     d0,copyUserLoop                                             
62
63#ifdef __HAVE_68881__
64        fmoveml  SYM (registers)+168,fpcr/fpsr/fpi
65        fmovemx  SYM (registers)+72,fp0-fp7
66        cmpl     IMM (-1),a0@     /* skip frestore flag set ? */
67        beq      skip_frestore
68        frestore a0@+
69skip_frestore:
70#endif
71
72        moveml  SYM (registers),d0-d7/a0-a6
73        rte  /* pop and go! */
74
75
76/* this function is called immediately when a level 7 interrupt occurs */
77/* if the previous interrupt level was 7 then we're already servicing  */
78/* this interrupt and an rte is in order to return to the debugger.    */
79/* For the 68000, the offset for sr is 6 due to the jsr return address */
80.text
81.globl SYM (_debug_level7)
82SYM (_debug_level7):
83        movew   d0,sp@-
84#ifdef mc68020
85        movew   sp@(2),d0
86#else
87        movew   sp@(6),d0
88#endif
89        andiw   IMM (0x700),d0
90        cmpiw   IMM (0x700),d0
91        beq     _already7
92        movew   sp@+,d0
93        bra     SYM (_catchException)
94_already7:
95        movew   sp@+,d0
96#ifndef mc68020
97        lea     sp@(4),sp     /* pull off 68000 return address */
98#endif
99        rte
100
101#ifdef mc68020
102/* This function is called when a 68020 exception occurs.  It saves
103 * all the cpu and fpcp regs in the _registers array, creates a frame on a
104 * linked list of frames which has the cpu and fpcp stack frames needed
105 * to properly restore the context of these processors, and invokes
106 * an exception handler (remcom_handler).
107 *
108 * stack on entry:                       stack on exit:
109 *   N bytes of junk                     exception # MSWord
110 *   Exception Format Word               exception # MSWord
111 *   Program counter LSWord             
112 *   Program counter MSWord             
113 *   Status Register                   
114 *                                       
115 *                                       
116 */
117
118.text
119.globl SYM (_catchException)
120SYM (_catchException):
121
122        oriw   IMM (0x0700),sr  /* Disable interrupts */
123
124        moveml  d0-d7/a0-a6,SYM (registers) /* save registers        */
125        movel   SYM (lastFrame),a0      /* last frame pointer */
126
127#ifdef __HAVE_68881__
128        /* do an fsave, then remember the address to begin a restore from */
129        fsave   a0@-
130        fmovemx fp0-fp7, SYM (registers)+72
131        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
132#endif
133
134        lea     SYM (registers),a5    /* get address of registers     */
135        movew   sp@,d1          /* get status register          */
136        movew   d1,a5@(66)      /* save sr                      */     
137        movel   sp@(2),a4       /* save pc in a4 for later use  */
138        movel   a4,a5@(68)      /* save pc in _regisers[]       */
139
140/* figure out how many bytes in the stack frame */
141        movew   sp@(6),d0       /* get '020 exception format    */
142        movew   d0,d2           /* make a copy of format word   */
143        andiw   IMM (0xf000),d0 /* mask off format type         */
144        rolw    IMM (5),d0           /* rotate into the low byte *2  */
145        lea     SYM (exceptionSize),a1
146        addw    d0,a1          /* index into the table         */
147        movew   a1@,d0         /* get number of words in frame */
148        movew   d0,d3          /* save it                      */
149        subw    d0,a0          /* adjust save pointer          */
150        subw    d0,a0          /* adjust save pointer(bytes)   */
151        movel   a0,a1          /* copy save pointer            */
152        subql   IMM (1),d0     /* predecrement loop counter    */
153
154/* copy the frame */
155
156saveFrameLoop:
157        movew   sp@+,a1@+
158        dbf     d0,saveFrameLoop
159
160/* now that the stack has been clenaed,
161 * save the a7 in use at time of exception
162 */
163        movel   sp,SYM (superStack)  /* save supervisor sp           */
164        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
165        beq     userMode       
166        movel   a7,a5@(60)      /* save a7                  */
167        bra     a7saveDone
168userMode: 
169        movel   usp,a1         
170        movel   a1,a5@(60)     /* save user stack pointer       */
171a7saveDone:
172
173
174/* save size of frame */
175        movew   d3,a0@-
176
177/* compute exception number */
178        andl    IMM (0xfff),d2          /* mask off vector offset       */
179        lsrw    IMM (2),d2      /* divide by 4 to get vect num  */
180        movel   d2,a0@-       /* save it                      */
181
182/* save pc causing exception */
183        movel   a4,a0@-
184
185/* save old frame link and set the new value*/
186        movel   SYM (lastFrame),a1      /* last frame pointer */
187        movel   a1,a0@-         /* save pointer to prev frame   */
188        movel   a0,SYM (lastFrame)
189
190        movel   d2,sp@-         /* push exception num           */
191#ifdef TMP_HACK
192        movel   SYM (exceptionHook),a0   /* get address of handler */
193        jbsr    a0@            /* and call it */
194#else
195        jbsr    SYM (remcomHandler)
196#endif
197        clrl    sp@             /* replace exception num parm with frame ptr */
198        jbsr    SYM (_returnFromException)    /* jbsr, but never returns */
199
200#else /* mc68000 */
201
202/* This function is called when an exception occurs.  It translates the
203 * return address found on the stack into an exception vector # which
204 * is then handled by either handle_exception or a system handler.
205 * _catchException provides a front end for both. 
206 *
207 * stack on entry:                       stack on exit:
208 *   Program counter MSWord              exception # MSWord
209 *   Program counter LSWord              exception # MSWord
210 *   Status Register                     
211 *   Return Address  MSWord             
212 *   Return Address  LSWord             
213 */
214.text
215.globl SYM (_catchException)
216SYM (_catchException):
217
218        oriw   IMM (0x0700),sr  /* Disable interrupts */
219
220        moveml d0-d7/a0-a6,SYM (registers)  /* save registers               */
221        movel   SYM (lastFrame),a0      /* last frame pointer */
222
223#ifdef __HAVE_68881__
224        /* do an fsave, then remember the address to begin a restore from */
225        fsave   a0@-
226        fmovemx fp0-fp7, SYM (registers)+72
227        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
228#endif
229
230        lea     SYM (registers),a5    /* get address of registers     */
231        movel   sp@+,d2        /* pop return address           */
232        addl    IMM (1530),d2  /* convert return addr to        */
233        divs    IMM (6),d2     /*  exception number             */
234        extl    d2   
235
236        moveql  IMM (3),d3     /* assume a three word frame     */
237
238        cmpiw   IMM (3),d2     /* bus error or address error ? */
239        bgt     normal         /* if >3 then normal error      */
240        movel   sp@+,a0@-      /* copy error info to frame buff*/
241        movel   sp@+,a0@-      /* these are never used         */
242        moveql  IMM (7),d3     /* this is a 7 word frame       */
243     
244normal:   
245        movew   sp@+,d1        /* pop status register          */
246        movel   sp@+,a4        /* pop program counter          */
247        movew   d1,a5@(66)     /* save sr                       */     
248        movel   a4,a5@(68)     /* save pc in _regisers[]        */
249        movel   a4,a0@-        /* copy pc to frame buffer      */
250        movew   d1,a0@-        /* copy sr to frame buffer      */
251
252        movel   sp,SYM (superStack)   /* save supervisor sp          */
253
254        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
255        beq     userMode       
256        movel   a7,a5@(60)      /* save a7                  */
257        bra     saveDone             
258userMode:
259        movel   usp,a1           /* save user stack pointer     */
260        movel   a1,a5@(60)     /* save user stack pointer       */
261saveDone:
262
263        movew   d3,a0@-        /* push frame size in words     */
264        movel   d2,a0@-        /* push vector number           */
265        movel   a4,a0@-        /* push exception pc            */
266
267/* save old frame link and set the new value */
268        movel   SYM (lastFrame),a1       /* last frame pointer */
269        movel   a1,a0@-  /* save pointer to prev frame  */
270        movel   a0,SYM (lastFrame)
271
272        movel   d2,sp@-         /* push exception num           */
273        movel   SYM (exceptionHook),a0   /* get address of handler */
274        jbsr    a0@             /* and call it */
275        clrl    sp@             /* replace exception num parm with frame ptr */
276        jbsr     SYM (_returnFromException)   /* jbsr, but never returns */
277
278#endif /* m68000 */
279
280/*
281 * remcomHandler is a front end for handle_exception.  It moves the
282 * stack pointer into an area reserved for debugger use in case the
283 * breakpoint happened in supervisor mode.
284 */
285.globl SYM (remcomHandler)
286SYM (remcomHandler):
287        addl    IMM (4),sp      /* pop off return address     */
288        movel   sp@+,d0         /* get the exception number   */
289        movel   SYM (stackPtr),sp       /* move to remcom stack area  */
290        movel   d0,sp@-         /* push exception onto stack  */
291        jbsr    SYM (handle_exception)  /* this never returns */
292        rts                     /* return */
Note: See TracBrowser for help on using the repository browser.