⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 altivec_dy4.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* dy4altivec.c - Altivec support functions *//************************************************************************** * *   Copyright (c) 2005 Curtiss-Wright Controls, Inc. All rights *   reserved.  This Source Code is the Property of Curtiss-Wright *   Controls, Inc. and can only be used in accordance with Source *   Code License Agreement(s) of Curtiss-Wright Controls, Inc. or any *   of its subsidiaries. * **************************************************************************//*  $RCSfile: altivec.c $  Copyright 2000 by Ixthos, Inc.  All Rights Reserved.  $Revision: 1.7 $  $Name: $  $State: Developmental $  $Locker: $  $Source: L:/SWRND/vx_7xx/src/drv/altivec/rcs/altivec.c $  RCS Project Name: vx_7xx  Target: IXA board, 750/7400 processors  DESCRIPTION  This library provides task hook functions that save and  restore the altivec registers during context switches.  BSP CONFIGURATION  This function must be included within the BSP.  The function  sysAltivecInit must be called first to install task switch   hooks.  This must be called after the OS is initialized but  before the first Altivec functions are called; calling from  sysHwInit2 is recommended.   Tasks wishing to use the Altivec should be created with the  option VX_ALTIVEC.  Such tasks will be allocated an Altivec  register save area, and have the Altivec enable bit in the  MSR set.  Alternately, each task wishing to use the Altivec should call  the function sysAltivecEnable.  This creates the register  save area, saves the Altivec context (if it was busy), and  sets the Altivec enable bit within the MSR.  INCLUDE FILES:  SEE ALSO:  $Log: altivec.c $  Revision 1.7  2001/12/13 13:33:13  coopertr  Modified to check for valid register save area address before  saving/restoring AltiVec registers  Revision 1.6  2001/10/17 12:45:03  coopertr  Modified for Tornado 2.1 support.  If INCLUDE_ALTIVEC is defined  (indicating OS support for the Altivec), then the functions in this source  file are configured for OS support of the AltiVec.  Revision 1.5  2001/05/16 14:55:29  seckardt  Removed PROCTYPE_MPC_7400 definition; it is already in ixa.h.  Revision 1.4  2000/10/31 18:37:09  dbratton  Updated for man pages.  Revision 1.3  2000/10/24 10:40:54  coopertr  Modified to create task in non-Java mode  Revision 1.2  2000/10/17 14:43:06  coopertr  Added altivec.h file  Revision 1.1  2000/09/26 10:39:00  coopertr  Initial revision*/ /*modification history--------------------01b,27oct04,tis  add support for PPC 744801a,04nov04,tis  add support for PPC 7447*//* includes */#include "vxWorks.h"#include "memLib.h"#include "taskLib.h"#include "taskHookLib.h"#include "intLib.h"#include "h/drv/altivec/altivec_dy4.h"/* defines */#define MSR_ALTIVEC_ENABLE	0x02000000	/* enable AV in MSR 	*/#define NJ			0x00010000	/* non-Java mode	*/#define VSCR_PTR(x)		(((unsigned long *)(x))+32*4)/*  the support method used is different for Tornado 2.1    Altivec support (indicated by INCLUDE_ALTIVEC) versus    non-Tornado support.                                  */#ifdef INCLUDE_ALTIVECLOCAL void taskCreateAV (WIND_TCB *t);LOCAL void setAltivecNonJavaMode (void);extern void *_func_altivecProbeRtn;#else  /* INCLUDE_ALTIVEC */LOCAL void taskCreateAV (WIND_TCB *t);LOCAL void taskDeleteAV (WIND_TCB *t);LOCAL void taskSwitchAV (WIND_TCB *old, WIND_TCB *new);/* *  This pointer remembers the TCB address which last owned *  the Altivec registers.  If this pointer is zero, then *  the Altivec registers contain no interesting values, *  and they may be overwritten freely.  If the pointer is *  nonzero, then the indicated task owns the register values, *  and the context switch hook must save the registers on *  behalf of that task before switching to another task  *  that uses the Altivec registers. */static WIND_TCB *currentAVTask = 0;#endif  /* INCLUDE_ALTIVEC *//************************************************************* sysAltivecProbe - Determine if the processor has AltiVec* extensions.** This function examines the processor version register to* determine if the processor includes AltiVec technology.* The function returns SUCCESS if the processor* does indeed support the AltiVec.** SEE ALSO: sysAltivecEnable()* NOMANUAL*/static int sysAltivecProbe     (    void    ){     unsigned long proctype;    __asm__ (" mfspr %0,287" : "=r" (proctype));  /* read PVR */    switch(proctype >> 16)    {        case CPU_TYPE_7400:        case CPU_TYPE_7410:        case CPU_TYPE_7450:        case CPU_TYPE_7455:        case CPU_TYPE_7457:        case CPU_TYPE_7447:        case CPU_TYPE_7448:            return (OK);	default:            return (-1);     }}/************************************************************* sysAltivecInit - Install Altivec task hooks** This function installs task management hooks for the Altivec.* This function should be called once during system initialization, * before any Altivec tasks are created.  This function has no * effect if called on a non-altivec processor.** RETURNS: None** SEE ALSO: sysAlitivecEnable()* NOMANUAL*/void sysAltivecInit    (    void    )    {    static int firsttime = 1;    unsigned long ilock;    /*     *  Verify that we are running on an Altivec.     */    if (sysAltivecProbe ())        return;    ilock = intLock ();#ifndef INCLUDE_ALTIVEC    if (firsttime)        {        firsttime = 0;        taskDeleteHookAdd ((FUNCPTR) taskDeleteAV);        taskCreateHookAdd ((FUNCPTR) taskCreateAV);        taskSwitchHookAdd ((FUNCPTR) taskSwitchAV);        }#else    if (firsttime)        {        firsttime = 0;        taskCreateHookAdd ((FUNCPTR) taskCreateAV);        _func_altivecProbeRtn = sysAltivecProbe;        altivecInit ();        }#endif    intUnlock (ilock);    return;    }    /************************************************************* sysAltivecEnable - Enable the Altivec for the calling task** This function enables the Altivec for the task that calls this* function.  This function may not be called from an ISR.* This function allocates a register save area for Altivec* registers.  If the Altivec registers are live (containing data* from another task) when this call is made, then this function* saves the altivec registers as part of the context of the task* which last used the altivec.** If INCLUDE_ALTIVEC is defined, this indicates that the OS * supports AltiVec technology.  In this case, this function* verifies that the calling task has been created with* altivec enabled, and sets the mode to non-Java mode.  If* the task was not created with AltiVec enabled, this function* returns an error status.** NOTE: This function sets the non-Java (NJ) bit within vscr.** RETURNS: 0 for success;  -1 if the processor is not an altivec,*          -2 = not called from a task, -3 = could not malloc*          register save area, -4 = task not created with altivec*          option enabled.** SEE ALSO: sysAltivecInit()*/int sysAltivecEnable     (    void    )    {#ifndef INCLUDE_ALTIVEC    unsigned long proctype, ilock;    int status = 0;    WIND_TCB *mytcb;    /*     *  Verify that we are running on an Altivec.     */    __asm__ (" mfspr %0,287" : "=r" (proctype));  /* read PVR */    switch (proctype >> 16)    {	case CPU_TYPE_7400:	case CPU_TYPE_7410:	case CPU_TYPE_7450:	case CPU_TYPE_7455:	case CPU_TYPE_7457:	case CPU_TYPE_7447:        case CPU_TYPE_7448:	    /* Altivec support */	    break;	default:            return (-1);    }    /*     *  Install task management OS hooks if needed.     */    sysAltivecInit ();    /*     *  Obtain the TCB address of the calling task.     */    if ((mytcb = taskTcb (taskIdSelf ())) == 0)        return (-2);    ilock = intLock ();    /*     *  If no register save area exists, allocate one now     */    if (mytcb->ALTIVEC_RSAVE == 0)        {        mytcb->options |= VX_ALTIVEC;        taskCreateAV (mytcb);        if (mytcb->ALTIVEC_RSAVE == 0)            status = -3;        else            {            /*             *  If an altivec task is currently active,             *  save its registers.  Reload "our" registers.             */            if (currentAVTask != 0 && currentAVTask->ALTIVEC_RSAVE != 0)                sysAltivecStore ((void *) (currentAVTask->ALTIVEC_RSAVE));            /*             *  Set NJ mode of last 32 bit word within VSCR             */            VSCR_PTR(mytcb->ALTIVEC_RSAVE)[3] |= NJ;            sysAltivecLoad ((void *) (mytcb->ALTIVEC_RSAVE));            currentAVTask = mytcb;             /*             *  Enable the Altivec bit within MSR.  Set             *  spr 256 to all 1's indicating all regs             *  are active.             */            __asm__ ("  mfmsr  3                        or     3,3,%0                        mtmsr  3                          sync                        li     3,-1                        mtspr  256,3"                        : : "r" (MSR_ALTIVEC_ENABLE) : "3");            }        }    intUnlock (ilock);    return (status);#else    /*     *  Place AltiVec in Java mode.  The calling task must be	 *  created with AltiVec enabled.     */    setAltivecNonJavaMode ();    return (0);#endif    }/************************************************************* taskCreateAV - Altivec task create hook** This local function clears the ALTIVEC RSAVE field within the TCB,* indicating the task is not altivec enabled.  If the ALTIVEC option* is set, this function creates and clears a register save area* for the Altivec, and sets the Altivec enable bit within the MSR.* The VSCR register is set to indicate non-Java mode.* Note that this hook is installed only for Altivec processors.** If INCLUDE_ALTIVEC is set, this task switch hook translates* the option field so that the older, non-vxWorks altivec* option introduced in our past BSPs is translated into the* newer vxWorks compatible option.** SEE ALSO: taskSwitchAV(), taskDeleteAV()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -