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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [libgloss/] [m68k/] [mvme162lx-asm.S] - Diff between revs 158 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 158 Rev 816
/*
/*
 * mvme162lx-asm.S -- assembler routines for the MVME stub.
 * mvme162lx-asm.S -- assembler routines for the MVME stub.
 *
 *
 * This code was pulled out of mvme162lx-stub.c by Ian Taylor so that I
 * This code was pulled out of mvme162lx-stub.c by Ian Taylor so that I
 * could handle different register and label prefixes in a sensible
 * could handle different register and label prefixes in a sensible
 * way.
 * way.
 */
 */
/****************************************************************************
/****************************************************************************
                THIS SOFTWARE IS NOT COPYRIGHTED
                THIS SOFTWARE IS NOT COPYRIGHTED
   HP offers the following for use in the public domain.  HP makes no
   HP offers the following for use in the public domain.  HP makes no
   warranty with regard to the software or it's performance and the
   warranty with regard to the software or it's performance and the
   user accepts the software "AS IS" with all faults.
   user accepts the software "AS IS" with all faults.
   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
****************************************************************************/
****************************************************************************/
#include "asm.h"
#include "asm.h"
        .title "mvme162lx-asm.S for m68k"
        .title "mvme162lx-asm.S for m68k"
        .globl SYM (registers)
        .globl SYM (registers)
        .globl SYM (lastFrame)
        .globl SYM (lastFrame)
        .globl SYM (superStack)
        .globl SYM (superStack)
        .globl SYM (exceptionHook)
        .globl SYM (exceptionHook)
        .globl SYM (_returnFromException)
        .globl SYM (_returnFromException)
        .globl SYM (stackPtr)
        .globl SYM (stackPtr)
        .globl SYM (handle_exception)
        .globl SYM (handle_exception)
        .globl SYM (exceptionSize)
        .globl SYM (exceptionSize)
.text
.text
.globl SYM (return_to_super)
.globl SYM (return_to_super)
SYM (return_to_super):
SYM (return_to_super):
        movel   SYM (registers)+60,sp /* get new stack pointer */
        movel   SYM (registers)+60,sp /* get new stack pointer */
        movel   SYM (lastFrame),a0    /* get last frame info  */
        movel   SYM (lastFrame),a0    /* get last frame info  */
        bra     return_to_any
        bra     return_to_any
.globl SYM (return_to_user)
.globl SYM (return_to_user)
SYM (return_to_user):
SYM (return_to_user):
        movel   SYM (registers)+60,a0   /* get usp */
        movel   SYM (registers)+60,a0   /* get usp */
        movel   a0,usp           /* set usp */
        movel   a0,usp           /* set usp */
        movel   SYM (superStack),sp    /* get original stack pointer */
        movel   SYM (superStack),sp    /* get original stack pointer */
return_to_any:
return_to_any:
        movel   SYM (lastFrame),a0     /* get last frame info  */
        movel   SYM (lastFrame),a0     /* get last frame info  */
        movel   a0@+,SYM (lastFrame)   /* link in previous frame     */
        movel   a0@+,SYM (lastFrame)   /* link in previous frame     */
        addql   IMM (8),a0            /* skip over pc, vector#*/
        addql   IMM (8),a0            /* skip over pc, vector#*/
        movew   a0@+,d0         /* get # of words in cpu frame */
        movew   a0@+,d0         /* get # of words in cpu frame */
        addw    d0,a0           /* point to end of data        */
        addw    d0,a0           /* point to end of data        */
        addw    d0,a0           /* point to end of data        */
        addw    d0,a0           /* point to end of data        */
        movel   a0,a1
        movel   a0,a1
/* copy the stack frame */
/* copy the stack frame */
        subql   IMM (1),d0
        subql   IMM (1),d0
copyUserLoop:
copyUserLoop:
        movew   a1@-,sp@-
        movew   a1@-,sp@-
        dbf     d0,copyUserLoop
        dbf     d0,copyUserLoop
#ifdef __HAVE_68881__
#ifdef __HAVE_68881__
        fmoveml  SYM (registers)+168,fpcr/fpsr/fpi
        fmoveml  SYM (registers)+168,fpcr/fpsr/fpi
        fmovemx  SYM (registers)+72,fp0-fp7
        fmovemx  SYM (registers)+72,fp0-fp7
        cmpl     IMM (-1),a0@     /* skip frestore flag set ? */
        cmpl     IMM (-1),a0@     /* skip frestore flag set ? */
        beq      skip_frestore
        beq      skip_frestore
        frestore a0@+
        frestore a0@+
skip_frestore:
skip_frestore:
#endif
#endif
        moveml  SYM (registers),d0-d7/a0-a6
        moveml  SYM (registers),d0-d7/a0-a6
        rte  /* pop and go! */
        rte  /* pop and go! */
/* this function is called immediately when a level 7 interrupt occurs */
/* this function is called immediately when a level 7 interrupt occurs */
/* if the previous interrupt level was 7 then we're already servicing  */
/* if the previous interrupt level was 7 then we're already servicing  */
/* this interrupt and an rte is in order to return to the debugger.    */
/* this interrupt and an rte is in order to return to the debugger.    */
/* For the 68000, the offset for sr is 6 due to the jsr return address */
/* For the 68000, the offset for sr is 6 due to the jsr return address */
.text
.text
.globl SYM (_debug_level7)
.globl SYM (_debug_level7)
SYM (_debug_level7):
SYM (_debug_level7):
        movew   d0,sp@-
        movew   d0,sp@-
#ifdef mc68020
#ifdef mc68020
        movew   sp@(2),d0
        movew   sp@(2),d0
#else
#else
        movew   sp@(6),d0
        movew   sp@(6),d0
#endif
#endif
        andiw   IMM (0x700),d0
        andiw   IMM (0x700),d0
        cmpiw   IMM (0x700),d0
        cmpiw   IMM (0x700),d0
        beq     _already7
        beq     _already7
        movew   sp@+,d0
        movew   sp@+,d0
        bra     SYM (_catchException)
        bra     SYM (_catchException)
_already7:
_already7:
        movew   sp@+,d0
        movew   sp@+,d0
#ifndef mc68020
#ifndef mc68020
        lea     sp@(4),sp     /* pull off 68000 return address */
        lea     sp@(4),sp     /* pull off 68000 return address */
#endif
#endif
        rte
        rte
#ifdef mc68020
#ifdef mc68020
/* This function is called when a 68020 exception occurs.  It saves
/* This function is called when a 68020 exception occurs.  It saves
 * all the cpu and fpcp regs in the _registers array, creates a frame on a
 * all the cpu and fpcp regs in the _registers array, creates a frame on a
 * linked list of frames which has the cpu and fpcp stack frames needed
 * linked list of frames which has the cpu and fpcp stack frames needed
 * to properly restore the context of these processors, and invokes
 * to properly restore the context of these processors, and invokes
 * an exception handler (remcom_handler).
 * an exception handler (remcom_handler).
 *
 *
 * stack on entry:                       stack on exit:
 * stack on entry:                       stack on exit:
 *   N bytes of junk                     exception # MSWord
 *   N bytes of junk                     exception # MSWord
 *   Exception Format Word               exception # MSWord
 *   Exception Format Word               exception # MSWord
 *   Program counter LSWord
 *   Program counter LSWord
 *   Program counter MSWord
 *   Program counter MSWord
 *   Status Register
 *   Status Register
 *
 *
 *
 *
 */
 */
.text
.text
.globl SYM (_catchException)
.globl SYM (_catchException)
SYM (_catchException):
SYM (_catchException):
        oriw   IMM (0x0700),sr  /* Disable interrupts */
        oriw   IMM (0x0700),sr  /* Disable interrupts */
        moveml  d0-d7/a0-a6,SYM (registers) /* save registers        */
        moveml  d0-d7/a0-a6,SYM (registers) /* save registers        */
        movel   SYM (lastFrame),a0      /* last frame pointer */
        movel   SYM (lastFrame),a0      /* last frame pointer */
#ifdef __HAVE_68881__
#ifdef __HAVE_68881__
        /* do an fsave, then remember the address to begin a restore from */
        /* do an fsave, then remember the address to begin a restore from */
        fsave   a0@-
        fsave   a0@-
        fmovemx fp0-fp7, SYM (registers)+72
        fmovemx fp0-fp7, SYM (registers)+72
        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
#endif
#endif
        lea     SYM (registers),a5    /* get address of registers     */
        lea     SYM (registers),a5    /* get address of registers     */
        movew   sp@,d1          /* get status register          */
        movew   sp@,d1          /* get status register          */
        movew   d1,a5@(66)      /* save sr                      */
        movew   d1,a5@(66)      /* save sr                      */
        movel   sp@(2),a4       /* save pc in a4 for later use  */
        movel   sp@(2),a4       /* save pc in a4 for later use  */
        movel   a4,a5@(68)      /* save pc in _regisers[]       */
        movel   a4,a5@(68)      /* save pc in _regisers[]       */
/* figure out how many bytes in the stack frame */
/* figure out how many bytes in the stack frame */
        movew   sp@(6),d0       /* get '020 exception format    */
        movew   sp@(6),d0       /* get '020 exception format    */
        movew   d0,d2           /* make a copy of format word   */
        movew   d0,d2           /* make a copy of format word   */
        andiw   IMM (0xf000),d0 /* mask off format type         */
        andiw   IMM (0xf000),d0 /* mask off format type         */
        rolw    IMM (5),d0           /* rotate into the low byte *2  */
        rolw    IMM (5),d0           /* rotate into the low byte *2  */
        lea     SYM (exceptionSize),a1
        lea     SYM (exceptionSize),a1
        addw    d0,a1          /* index into the table         */
        addw    d0,a1          /* index into the table         */
        movew   a1@,d0         /* get number of words in frame */
        movew   a1@,d0         /* get number of words in frame */
        movew   d0,d3          /* save it                      */
        movew   d0,d3          /* save it                      */
        subw    d0,a0          /* adjust save pointer          */
        subw    d0,a0          /* adjust save pointer          */
        subw    d0,a0          /* adjust save pointer(bytes)   */
        subw    d0,a0          /* adjust save pointer(bytes)   */
        movel   a0,a1          /* copy save pointer            */
        movel   a0,a1          /* copy save pointer            */
        subql   IMM (1),d0     /* predecrement loop counter    */
        subql   IMM (1),d0     /* predecrement loop counter    */
/* copy the frame */
/* copy the frame */
saveFrameLoop:
saveFrameLoop:
        movew   sp@+,a1@+
        movew   sp@+,a1@+
        dbf     d0,saveFrameLoop
        dbf     d0,saveFrameLoop
/* now that the stack has been clenaed,
/* now that the stack has been clenaed,
 * save the a7 in use at time of exception
 * save the a7 in use at time of exception
 */
 */
        movel   sp,SYM (superStack)  /* save supervisor sp           */
        movel   sp,SYM (superStack)  /* save supervisor sp           */
        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
        beq     userMode
        beq     userMode
        movel   a7,a5@(60)      /* save a7                  */
        movel   a7,a5@(60)      /* save a7                  */
        bra     a7saveDone
        bra     a7saveDone
userMode:
userMode:
        movel   usp,a1
        movel   usp,a1
        movel   a1,a5@(60)     /* save user stack pointer       */
        movel   a1,a5@(60)     /* save user stack pointer       */
a7saveDone:
a7saveDone:
/* save size of frame */
/* save size of frame */
        movew   d3,a0@-
        movew   d3,a0@-
/* compute exception number */
/* compute exception number */
        andl    IMM (0xfff),d2          /* mask off vector offset       */
        andl    IMM (0xfff),d2          /* mask off vector offset       */
        lsrw    IMM (2),d2      /* divide by 4 to get vect num  */
        lsrw    IMM (2),d2      /* divide by 4 to get vect num  */
        movel   d2,a0@-       /* save it                      */
        movel   d2,a0@-       /* save it                      */
/* save pc causing exception */
/* save pc causing exception */
        movel   a4,a0@-
        movel   a4,a0@-
/* save old frame link and set the new value*/
/* save old frame link and set the new value*/
        movel   SYM (lastFrame),a1      /* last frame pointer */
        movel   SYM (lastFrame),a1      /* last frame pointer */
        movel   a1,a0@-         /* save pointer to prev frame   */
        movel   a1,a0@-         /* save pointer to prev frame   */
        movel   a0,SYM (lastFrame)
        movel   a0,SYM (lastFrame)
        movel   d2,sp@-         /* push exception num           */
        movel   d2,sp@-         /* push exception num           */
#ifdef TMP_HACK
#ifdef TMP_HACK
        movel   SYM (exceptionHook),a0   /* get address of handler */
        movel   SYM (exceptionHook),a0   /* get address of handler */
        jbsr    a0@            /* and call it */
        jbsr    a0@            /* and call it */
#else
#else
        jbsr    SYM (remcomHandler)
        jbsr    SYM (remcomHandler)
#endif
#endif
        clrl    sp@             /* replace exception num parm with frame ptr */
        clrl    sp@             /* replace exception num parm with frame ptr */
        jbsr    SYM (_returnFromException)    /* jbsr, but never returns */
        jbsr    SYM (_returnFromException)    /* jbsr, but never returns */
#else /* mc68000 */
#else /* mc68000 */
/* This function is called when an exception occurs.  It translates the
/* This function is called when an exception occurs.  It translates the
 * return address found on the stack into an exception vector # which
 * return address found on the stack into an exception vector # which
 * is then handled by either handle_exception or a system handler.
 * is then handled by either handle_exception or a system handler.
 * _catchException provides a front end for both.
 * _catchException provides a front end for both.
 *
 *
 * stack on entry:                       stack on exit:
 * stack on entry:                       stack on exit:
 *   Program counter MSWord              exception # MSWord
 *   Program counter MSWord              exception # MSWord
 *   Program counter LSWord              exception # MSWord
 *   Program counter LSWord              exception # MSWord
 *   Status Register
 *   Status Register
 *   Return Address  MSWord
 *   Return Address  MSWord
 *   Return Address  LSWord
 *   Return Address  LSWord
 */
 */
.text
.text
.globl SYM (_catchException)
.globl SYM (_catchException)
SYM (_catchException):
SYM (_catchException):
        oriw   IMM (0x0700),sr  /* Disable interrupts */
        oriw   IMM (0x0700),sr  /* Disable interrupts */
        moveml d0-d7/a0-a6,SYM (registers)  /* save registers               */
        moveml d0-d7/a0-a6,SYM (registers)  /* save registers               */
        movel   SYM (lastFrame),a0      /* last frame pointer */
        movel   SYM (lastFrame),a0      /* last frame pointer */
#ifdef __HAVE_68881__
#ifdef __HAVE_68881__
        /* do an fsave, then remember the address to begin a restore from */
        /* do an fsave, then remember the address to begin a restore from */
        fsave   a0@-
        fsave   a0@-
        fmovemx fp0-fp7, SYM (registers)+72
        fmovemx fp0-fp7, SYM (registers)+72
        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
        fmoveml fpcr/fpsr/fpi, SYM (registers)+168
#endif
#endif
        lea     SYM (registers),a5    /* get address of registers     */
        lea     SYM (registers),a5    /* get address of registers     */
        movel   sp@+,d2        /* pop return address           */
        movel   sp@+,d2        /* pop return address           */
        addl    IMM (1530),d2  /* convert return addr to        */
        addl    IMM (1530),d2  /* convert return addr to        */
        divs    IMM (6),d2     /*  exception number             */
        divs    IMM (6),d2     /*  exception number             */
        extl    d2
        extl    d2
        moveql  IMM (3),d3     /* assume a three word frame     */
        moveql  IMM (3),d3     /* assume a three word frame     */
        cmpiw   IMM (3),d2     /* bus error or address error ? */
        cmpiw   IMM (3),d2     /* bus error or address error ? */
        bgt     normal         /* if >3 then normal error      */
        bgt     normal         /* if >3 then normal error      */
        movel   sp@+,a0@-      /* copy error info to frame buff*/
        movel   sp@+,a0@-      /* copy error info to frame buff*/
        movel   sp@+,a0@-      /* these are never used         */
        movel   sp@+,a0@-      /* these are never used         */
        moveql  IMM (7),d3     /* this is a 7 word frame       */
        moveql  IMM (7),d3     /* this is a 7 word frame       */
normal:
normal:
        movew   sp@+,d1        /* pop status register          */
        movew   sp@+,d1        /* pop status register          */
        movel   sp@+,a4        /* pop program counter          */
        movel   sp@+,a4        /* pop program counter          */
        movew   d1,a5@(66)     /* save sr                       */
        movew   d1,a5@(66)     /* save sr                       */
        movel   a4,a5@(68)     /* save pc in _regisers[]        */
        movel   a4,a5@(68)     /* save pc in _regisers[]        */
        movel   a4,a0@-        /* copy pc to frame buffer      */
        movel   a4,a0@-        /* copy pc to frame buffer      */
        movew   d1,a0@-        /* copy sr to frame buffer      */
        movew   d1,a0@-        /* copy sr to frame buffer      */
        movel   sp,SYM (superStack)   /* save supervisor sp          */
        movel   sp,SYM (superStack)   /* save supervisor sp          */
        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
        andiw   IMM (0x2000),d1      /* were we in supervisor mode ? */
        beq     userMode
        beq     userMode
        movel   a7,a5@(60)      /* save a7                  */
        movel   a7,a5@(60)      /* save a7                  */
        bra     saveDone
        bra     saveDone
userMode:
userMode:
        movel   usp,a1           /* save user stack pointer     */
        movel   usp,a1           /* save user stack pointer     */
        movel   a1,a5@(60)     /* save user stack pointer       */
        movel   a1,a5@(60)     /* save user stack pointer       */
saveDone:
saveDone:
        movew   d3,a0@-        /* push frame size in words     */
        movew   d3,a0@-        /* push frame size in words     */
        movel   d2,a0@-        /* push vector number           */
        movel   d2,a0@-        /* push vector number           */
        movel   a4,a0@-        /* push exception pc            */
        movel   a4,a0@-        /* push exception pc            */
/* save old frame link and set the new value */
/* save old frame link and set the new value */
        movel   SYM (lastFrame),a1       /* last frame pointer */
        movel   SYM (lastFrame),a1       /* last frame pointer */
        movel   a1,a0@-  /* save pointer to prev frame  */
        movel   a1,a0@-  /* save pointer to prev frame  */
        movel   a0,SYM (lastFrame)
        movel   a0,SYM (lastFrame)
        movel   d2,sp@-         /* push exception num           */
        movel   d2,sp@-         /* push exception num           */
        movel   SYM (exceptionHook),a0   /* get address of handler */
        movel   SYM (exceptionHook),a0   /* get address of handler */
        jbsr    a0@             /* and call it */
        jbsr    a0@             /* and call it */
        clrl    sp@             /* replace exception num parm with frame ptr */
        clrl    sp@             /* replace exception num parm with frame ptr */
        jbsr     SYM (_returnFromException)   /* jbsr, but never returns */
        jbsr     SYM (_returnFromException)   /* jbsr, but never returns */
#endif /* m68000 */
#endif /* m68000 */
/*
/*
 * remcomHandler is a front end for handle_exception.  It moves the
 * remcomHandler is a front end for handle_exception.  It moves the
 * stack pointer into an area reserved for debugger use in case the
 * stack pointer into an area reserved for debugger use in case the
 * breakpoint happened in supervisor mode.
 * breakpoint happened in supervisor mode.
 */
 */
.globl SYM (remcomHandler)
.globl SYM (remcomHandler)
SYM (remcomHandler):
SYM (remcomHandler):
        addl    IMM (4),sp      /* pop off return address     */
        addl    IMM (4),sp      /* pop off return address     */
        movel   sp@+,d0         /* get the exception number   */
        movel   sp@+,d0         /* get the exception number   */
        movel   SYM (stackPtr),sp       /* move to remcom stack area  */
        movel   SYM (stackPtr),sp       /* move to remcom stack area  */
        movel   d0,sp@-         /* push exception onto stack  */
        movel   d0,sp@-         /* push exception onto stack  */
        jbsr    SYM (handle_exception)  /* this never returns */
        jbsr    SYM (handle_exception)  /* this never returns */
        rts                     /* return */
        rts                     /* return */
 
 

powered by: WebSVN 2.1.0

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