📄 dspmmu_tlb.c
字号:
/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted
* by Texas Instruments is distributed as "freeware". You may,
* only under TI's copyright in the Program, use and modify the
* Program without any charge or restriction. You may
* distribute to third parties, provided that you transfer a
* copy of this license to the third party and the third party
* agrees to these terms by its first use of the Program. You
* must reproduce the copyright notice and any other legend of
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains
* copyrighted material, trade secrets and other TI proprietary
* information and is protected by copyright laws,
* international copyright treaties, and trade secret laws, as
* well as other intellectual property laws. To protect TI's
* rights in the Program, you agree not to decompile, reverse
* engineer, disassemble or otherwise translate any object code
* versions of the Program to a human-readable form. You agree
* that in no event will you alter, remove or destroy any
* copyright notice included in the Program. TI reserves all
* rights not specifically granted under this license. Except
* as specifically provided herein, nothing in this agreement
* shall be construed as conferring by implication, estoppel,
* or otherwise, upon you, any license or other right under any
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* ********************************************************* */
#include "DSPMMU.h"
#include <stdio.h>
void MMU_WriteTlbEntry(TLB_ENTRY entry, short EntryNumber);
void MMU_Reset();
void MMU_ReleaseReset();
void MMU_Enable();
void MMU_Disable();
short MMU_CheckError();
short MMU_ReadFaultType();
int MMU_ReadFaultAddress();
TLB_ENTRY MMU_ReadTlbEntry(short EntryNumber);
void MMU_DisplayTlbEntry(short entryNumber);
void MMU_WriteTlbEntry(TLB_ENTRY entry, short EntryNumber)
{
unsigned int VirtualTag;
unsigned short CamHighReg;
unsigned short CamLowReg;
unsigned short RamHighReg;
unsigned short RamLowReg;
// The 14 MSB of the 24-bit DSP virtual address form the virtual tag
VirtualTag = ((entry.VirtualAddress >> 10) & 0x3FFF);
// Calculate CAM register content
// The 2 MSB go into the 2 LSB of CAM_H_REG
CamHighReg= ((VirtualTag >> 12) & 0x3);
// The 12 LSB go into the 12 MSB of CAM_L_REG */
CamLowReg = ((VirtualTag & 0xFFF)<<4);
// Entry is valid and shall be preserved
CamLowReg |= VALID | PRESERVED;
// Select entry type
CamLowReg = CamLowReg | entry.Type;
// Calculate RAM registers content
// The 16 MSB of the physical address go into RAM_H_REG
RamHighReg = entry.PhysicalAddress >> 16;
// The next 6 significant bits go into RAM_L_REG
RamLowReg = entry.PhysicalAddress & 0xFC00;
// Bits 9 and 8 of RAM_L_REG are access permission bits
RamLowReg = RamLowReg | entry.AccessPermission;
/* Write to MMU */
/* Step 1 - Write CAM_H_REG */
CAM_H_REG = CamHighReg;
/* Step 2 - Write CAM_L_REG */
CAM_L_REG = CamLowReg;
/* Step 3 - Write RAM_H_REG */
RAM_H_REG = RamHighReg;
/* Step 4 - Write RAM_L_REG */
RAM_L_REG = RamLowReg;
/* Step 5 - Update current entry and protected entry pointers */
LOCK_REG = ((EntryNumber << 4) | (EntryNumber << 10));
/* Step 6 - Set LD_TLB_REG to write TLB */
LD_TLB_REG = WRITE;
}
TLB_ENTRY MMU_ReadTlbEntry(short EntryNumber)
{
TLB_ENTRY entry;
// Clear victim pointer (Bits 9..4 of LOCK_REG)
LOCK_REG &=0xFC0F;
// Set victim pointer to the entry that shall be read
LOCK_REG |= EntryNumber << 4;
// Set LD_TLB_REG to read TLB entry
LD_TLB_REG = READ;
// Extract entry parameters
entry.VirtualAddress = (READ_CAM_H_REG & 0x3) << 22;
entry.VirtualAddress += (READ_CAM_L_REG & 0xFFF0) << 6;
entry.PhysicalAddress = READ_RAM_H_REG << 16;
entry.PhysicalAddress += READ_RAM_L_REG & 0xFC00;
entry.Type = READ_CAM_L_REG & 0x3;
entry.AccessPermission = READ_RAM_L_REG & 0x300;
return entry;
}
void MMU_DisplayTlbEntry(short entryNumber)
{
TLB_ENTRY entry;
entry=MMU_ReadTlbEntry(entryNumber);
printf("Entry %d : Virtual Address = 0x%x, Physical Address = 0x%x \n", entryNumber, entry.VirtualAddress, entry.PhysicalAddress);
}
short MMU_CheckError()
{
short i;
int addr;
i = MMU_ReadFaultType();
if (i!=0)
{
if (i & 0x1)
printf("Translation Fault! \n");
if (i & 0x2)
printf("TLB Miss! \n");
if (i & 0x4)
printf("Permission Fault! \n");
if (i & 0x8)
printf("Error during prefetch! \n");
addr = MMU_ReadFaultAddress();
printf("Fault address : 0x%x (Byte) / 0x%x (Word) \n", addr, addr>>1);
}
return i;
}
void MMU_Reset()
{
// Reset DSP MMU to default parameters
CNTL_REG = RESET;
}
void MMU_ReleaseReset()
{
// Release MMU from Reset
CNTL_REG = REL_RESET;
}
void MMU_Enable()
{
// Enable MMU
CNTL_REG |= ENABLE;
}
void MMU_Disable()
{
CNTL_REG &= DISABLE;
}
short MMU_ReadFaultType()
{
return F_ST_REG;
}
int MMU_ReadFaultAddress()
{
int i;
i = FAULT_AD_H_REG << 16;
i += FAULT_AD_L_REG;
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -