2006-06-02 05:36:31 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2006-07-17 09:13:27 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2009-11-16 02:35:24 -06:00
|
|
|
#include "target.h"
|
2006-06-02 05:36:31 -05:00
|
|
|
#include "armv4_5_mmu.h"
|
|
|
|
|
|
|
|
|
2010-06-12 05:35:06 -05:00
|
|
|
int armv4_5_mmu_translate_va(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t va, uint32_t *cb, uint32_t *val)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-06-18 02:08:52 -05:00
|
|
|
uint32_t first_lvl_descriptor = 0x0;
|
|
|
|
uint32_t second_lvl_descriptor = 0x0;
|
2010-07-19 01:45:45 -05:00
|
|
|
uint32_t ttb;
|
2010-06-10 09:18:14 -05:00
|
|
|
int retval;
|
2010-07-19 01:45:45 -05:00
|
|
|
retval = armv4_5_mmu->get_ttb(target, &ttb);
|
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
2006-06-02 05:36:31 -05:00
|
|
|
|
2010-06-10 09:18:14 -05:00
|
|
|
retval = armv4_5_mmu_read_physical(target, armv4_5_mmu,
|
2006-06-02 05:36:31 -05:00
|
|
|
(ttb & 0xffffc000) | ((va & 0xfff00000) >> 18),
|
2009-06-18 02:04:08 -05:00
|
|
|
4, 1, (uint8_t*)&first_lvl_descriptor);
|
2010-06-10 09:18:14 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
2009-06-18 02:04:08 -05:00
|
|
|
first_lvl_descriptor = target_buffer_get_u32(target, (uint8_t*)&first_lvl_descriptor);
|
2006-06-02 05:36:31 -05:00
|
|
|
|
2009-06-20 22:15:59 -05:00
|
|
|
LOG_DEBUG("1st lvl desc: %8.8" PRIx32 "", first_lvl_descriptor);
|
2006-06-02 05:36:31 -05:00
|
|
|
|
|
|
|
if ((first_lvl_descriptor & 0x3) == 0)
|
|
|
|
{
|
2008-03-25 10:45:17 -05:00
|
|
|
LOG_ERROR("Address translation failure");
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_TARGET_TRANSLATION_FAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!armv4_5_mmu->has_tiny_pages && ((first_lvl_descriptor & 0x3) == 3))
|
|
|
|
{
|
2008-03-25 10:45:17 -05:00
|
|
|
LOG_ERROR("Address translation failure");
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_TARGET_TRANSLATION_FAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((first_lvl_descriptor & 0x3) == 2)
|
|
|
|
{
|
|
|
|
/* section descriptor */
|
|
|
|
*cb = (first_lvl_descriptor & 0xc) >> 2;
|
2010-06-10 09:18:14 -05:00
|
|
|
*val = (first_lvl_descriptor & 0xfff00000) | (va & 0x000fffff);
|
|
|
|
return ERROR_OK;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((first_lvl_descriptor & 0x3) == 1)
|
|
|
|
{
|
|
|
|
/* coarse page table */
|
2010-06-10 09:18:14 -05:00
|
|
|
retval = armv4_5_mmu_read_physical(target, armv4_5_mmu,
|
2006-06-02 05:36:31 -05:00
|
|
|
(first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10),
|
2009-06-18 02:04:08 -05:00
|
|
|
4, 1, (uint8_t*)&second_lvl_descriptor);
|
2010-06-10 09:18:14 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
2006-08-31 07:41:49 -05:00
|
|
|
else if ((first_lvl_descriptor & 0x3) == 3)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
|
|
|
/* fine page table */
|
2010-06-10 09:18:14 -05:00
|
|
|
retval = armv4_5_mmu_read_physical(target, armv4_5_mmu,
|
2006-06-02 05:36:31 -05:00
|
|
|
(first_lvl_descriptor & 0xfffff000) | ((va & 0x000ffc00) >> 8),
|
2009-06-18 02:04:08 -05:00
|
|
|
4, 1, (uint8_t*)&second_lvl_descriptor);
|
2010-06-10 09:18:14 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
2009-05-10 14:02:07 -05:00
|
|
|
|
2009-06-18 02:04:08 -05:00
|
|
|
second_lvl_descriptor = target_buffer_get_u32(target, (uint8_t*)&second_lvl_descriptor);
|
2009-05-10 14:02:07 -05:00
|
|
|
|
2009-06-20 22:15:59 -05:00
|
|
|
LOG_DEBUG("2nd lvl desc: %8.8" PRIx32 "", second_lvl_descriptor);
|
2006-06-02 05:36:31 -05:00
|
|
|
|
|
|
|
if ((second_lvl_descriptor & 0x3) == 0)
|
|
|
|
{
|
2008-03-25 10:45:17 -05:00
|
|
|
LOG_ERROR("Address translation failure");
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_TARGET_TRANSLATION_FAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cacheable/bufferable is always specified in bits 3-2 */
|
|
|
|
*cb = (second_lvl_descriptor & 0xc) >> 2;
|
|
|
|
|
|
|
|
if ((second_lvl_descriptor & 0x3) == 1)
|
|
|
|
{
|
|
|
|
/* large page descriptor */
|
2010-06-10 09:18:14 -05:00
|
|
|
*val = (second_lvl_descriptor & 0xffff0000) | (va & 0x0000ffff);
|
|
|
|
return ERROR_OK;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((second_lvl_descriptor & 0x3) == 2)
|
|
|
|
{
|
|
|
|
/* small page descriptor */
|
2010-06-10 09:18:14 -05:00
|
|
|
*val = (second_lvl_descriptor & 0xfffff000) | (va & 0x00000fff);
|
|
|
|
return ERROR_OK;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((second_lvl_descriptor & 0x3) == 3)
|
|
|
|
{
|
|
|
|
/* tiny page descriptor */
|
2010-06-10 09:18:14 -05:00
|
|
|
*val = (second_lvl_descriptor & 0xfffffc00) | (va & 0x000003ff);
|
|
|
|
return ERROR_OK;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* should not happen */
|
2008-03-25 10:45:17 -05:00
|
|
|
LOG_ERROR("Address translation failure");
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_TARGET_TRANSLATION_FAULT;
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
int armv4_5_mmu_read_physical(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (target->state != TARGET_HALTED)
|
|
|
|
return ERROR_TARGET_NOT_HALTED;
|
|
|
|
|
|
|
|
/* disable MMU and data (or unified) cache */
|
|
|
|
armv4_5_mmu->disable_mmu_caches(target, 1, 1, 0);
|
|
|
|
|
|
|
|
retval = armv4_5_mmu->read_memory(target, address, size, count, buffer);
|
|
|
|
|
|
|
|
/* reenable MMU / cache */
|
|
|
|
armv4_5_mmu->enable_mmu_caches(target, armv4_5_mmu->mmu_enabled,
|
|
|
|
armv4_5_mmu->armv4_5_cache.d_u_cache_enabled,
|
|
|
|
armv4_5_mmu->armv4_5_cache.i_cache_enabled);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
int armv4_5_mmu_write_physical(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (target->state != TARGET_HALTED)
|
|
|
|
return ERROR_TARGET_NOT_HALTED;
|
|
|
|
|
|
|
|
/* disable MMU and data (or unified) cache */
|
|
|
|
armv4_5_mmu->disable_mmu_caches(target, 1, 1, 0);
|
2009-05-10 14:02:07 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
retval = armv4_5_mmu->write_memory(target, address, size, count, buffer);
|
|
|
|
|
|
|
|
/* reenable MMU / cache */
|
|
|
|
armv4_5_mmu->enable_mmu_caches(target, armv4_5_mmu->mmu_enabled,
|
|
|
|
armv4_5_mmu->armv4_5_cache.d_u_cache_enabled,
|
|
|
|
armv4_5_mmu->armv4_5_cache.i_cache_enabled);
|
2009-05-10 14:02:07 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
return retval;
|
|
|
|
}
|