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

📄 jvm_cache.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   jvm_cache.cpp
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
 * Include Header Files
 ****************************************************************************/
#include "kal_release.h"
#include "cache_hw.h"
#include "cache_sw.h"
#include "jvm_interface.h"

/****************************************************************************
 * Function Definition
 ****************************************************************************/
#define _DERIVED(type, ptr, offset) ((type) (((kal_int32) (ptr))+((kal_int32) (offset))))

#if defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230))
static kal_uint8 l1cache_channels, saved_inited_channels;
static kal_uint32 last_channel;
static unsigned char *low_end, *high_start;

extern kal_uint32 SaveAndSetIRQMask(void);
extern void RestoreIRQMask(kal_uint32);
extern kal_bool CodeCacheGetChannel(kal_uint16 *channel);
extern kal_bool CodeCacheFreeChannel(kal_uint16 *channel);
extern void CodeCacheSetting(CacheMenuType *cache_setting);
void jvm_flush_cache(unsigned char *start, int size);


/*****************************************************************************
 * FUNCTION
 *  _jvm_config_codecache
 * DESCRIPTION
 *  
 * PARAMETERS
 *  start       [?]         
 *  size        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static kal_uint16 _jvm_config_codecache(unsigned char *start, kal_uint32 size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    CacheMenuType cache_setting;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    while (last_channel < 8)
    {
        for (; last_channel < 8; last_channel++)
        {
            if ((l1cache_channels & (1 << last_channel)) != 0)
            {
                break;
            }
        }
        if (CodeCacheGetChannel((kal_uint16*) & last_channel) == KAL_TRUE)
        {
            break;
        }
    }

    if (last_channel == 8)
    {
        return 0xffff;
    }

    l1cache_channels &= ~(1 < last_channel);
    cache_setting.c_channel = last_channel;
    last_channel++;
    cache_setting.c_enable = 1;
    cache_setting.c_addr = (kal_uint32) start;
    cache_setting.c_range = size;
    CodeCacheSetting(&cache_setting);

    return (kal_uint16) (last_channel - 1);
}
#endif /* defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230)) */ 


/*****************************************************************************
 * FUNCTION
 *  jvm_init_cache
 * DESCRIPTION
 *  
 * PARAMETERS
 *  start       [?]     
 *  end         [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void jvm_init_cache(unsigned char *start, unsigned char *end)
{
#if defined(__MTK_TARGET__) && (defined(MT6228) || defined(MT6229) || defined(MT6230))
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 space_size = end - start;
    kal_int32 cachealign_size = 1024;   /* minimum 1K aligned */
    kal_int32 cachealign_mask;
    kal_uint16 channel;
    kal_bool find_region;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    last_channel = saved_inited_channels = 0;

    /* if requesting size is less than minimum cache alignment, return */
    if (space_size < cachealign_size)
    {
        return;
    }
    
    /* error, can not support such large size */
    if(space_size > 8 * 1024 * 1024)
    {
        return;
    }

    if(space_size == 8 * 1024 * 1024)
    {
        channel = _jvm_config_codecache(start, 4 * 1024 * 1024);
        if (channel == 0xFFFF)
        {
            return;
        }
        else
        {
            saved_inited_channels |= (1 << channel);
        }
        channel = _jvm_config_codecache(start + 4 * 1024 * 1024, 4 * 1024 * 1024);
        if (channel != 0xFFFF)
        {
            saved_inited_channels |= (1 << channel);
        }
        return;
    }
    
    /* find largest align size */
    while (cachealign_size < space_size && cachealign_size <= 4 * 1024 * 1024)
    {
        cachealign_size <<= 1;
    }

    if (cachealign_size > 1024)
    {
        cachealign_size >>= 1;
    }

    /* if the start address is just aligned with 2 ^ n */
    if (((kal_int32) start % (cachealign_size << 1)) == 0)
    {
        cachealign_size <<= 1;
    }
    cachealign_mask = ~(cachealign_size - 1);

    while (((_DERIVED(kal_int32, start, cachealign_size - 1) & cachealign_mask) + cachealign_size) > (kal_int32) end)
    {
        if (cachealign_size > 1024)
        {
            cachealign_size >>= 1;
            cachealign_mask = ~(cachealign_size - 1);
        }
        else
        {

⌨️ 快捷键说明

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