2 * mvme162lx-asm.S -- assembler routines for the MVME stub.
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
9 /****************************************************************************
11 THIS SOFTWARE IS NOT COPYRIGHTED
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.
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.
21 ****************************************************************************/
25 .title "mvme162lx-asm.S for m68k"
27 .globl SYM (registers)
28 .globl SYM (lastFrame)
29 .globl SYM (superStack)
30 .globl SYM (exceptionHook)
31 .globl SYM (_returnFromException)
33 .globl SYM (handle_exception)
34 .globl SYM (exceptionSize)
37 .globl SYM (return_to_super)
38 SYM (return_to_super):
39 movel SYM (registers)+60,sp /* get new stack pointer */
40 movel SYM (lastFrame),a0 /* get last frame info */
43 .globl SYM (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 */
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 */
57 /* copy the stack frame */
64 fmoveml SYM (registers)+168,fpcr/fpsr/fpi
65 fmovemx SYM (registers)+72,fp0-fp7
66 cmpl IMM (-1),a0@ /* skip frestore flag set ? */
72 moveml SYM (registers),d0-d7/a0-a6
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 */
81 .globl SYM (_debug_level7)
93 bra SYM (_catchException)
97 lea sp@(4),sp /* pull off 68000 return address */
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).
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
119 .globl SYM (_catchException)
120 SYM (_catchException):
122 oriw IMM (0x0700),sr /* Disable interrupts */
124 moveml d0-d7/a0-a6,SYM (registers) /* save registers */
125 movel SYM (lastFrame),a0 /* last frame pointer */
127 #ifdef __HAVE_68881__
128 /* do an fsave, then remember the address to begin a restore from */
130 fmovemx fp0-fp7, SYM (registers)+72
131 fmoveml fpcr/fpsr/fpi, SYM (registers)+168
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[] */
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 */
160 /* now that the stack has been clenaed,
161 * save the a7 in use at time of exception
163 movel sp,SYM (superStack) /* save supervisor sp */
164 andiw IMM (0x2000),d1 /* were we in supervisor mode ? */
166 movel a7,a5@(60) /* save a7 */
170 movel a1,a5@(60) /* save user stack pointer */
174 /* save size of frame */
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 */
182 /* save pc causing exception */
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)
190 movel d2,sp@- /* push exception num */
192 movel SYM (exceptionHook),a0 /* get address of handler */
193 jbsr a0@ /* and call it */
195 jbsr SYM (remcomHandler)
197 clrl sp@ /* replace exception num parm with frame ptr */
198 jbsr SYM (_returnFromException) /* jbsr, but never returns */
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.
207 * stack on entry: stack on exit:
208 * Program counter MSWord exception # MSWord
209 * Program counter LSWord exception # MSWord
211 * Return Address MSWord
212 * Return Address LSWord
215 .globl SYM (_catchException)
216 SYM (_catchException):
218 oriw IMM (0x0700),sr /* Disable interrupts */
220 moveml d0-d7/a0-a6,SYM (registers) /* save registers */
221 movel SYM (lastFrame),a0 /* last frame pointer */
223 #ifdef __HAVE_68881__
224 /* do an fsave, then remember the address to begin a restore from */
226 fmovemx fp0-fp7, SYM (registers)+72
227 fmoveml fpcr/fpsr/fpi, SYM (registers)+168
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 */
236 moveql IMM (3),d3 /* assume a three word frame */
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 */
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 */
252 movel sp,SYM (superStack) /* save supervisor sp */
254 andiw IMM (0x2000),d1 /* were we in supervisor mode ? */
256 movel a7,a5@(60) /* save a7 */
259 movel usp,a1 /* save user stack pointer */
260 movel a1,a5@(60) /* save user stack pointer */
263 movew d3,a0@- /* push frame size in words */
264 movel d2,a0@- /* push vector number */
265 movel a4,a0@- /* push exception pc */
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)
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 */
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.
285 .globl SYM (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 */