Untitled diff

생성일 비교 결과 만료 없음
195 삭제
449 행
40 추가
294 행
/** \file
/** \file
* ARM control registers
* ARM control registers
*/
*/
/*
/*
* Copyright (C) 2009 Trammell Hudson <hudson+ml@osresearch.net>
* Copyright (C) 2009 Trammell Hudson <hudson+ml@osresearch.net>
*
*
* This program is free software; you can redistribute it and/or
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
* Boston, MA 02110-1301, USA.
*/
*/


#ifndef _arm_mcr_h_
#ifndef _arm_mcr_h_
#define _arm_mcr_h_
#define _arm_mcr_h_


#define inline inline __attribute__((always_inline))
#define inline inline __attribute__((always_inline))


asm(
asm(
".text\n"
".text\n"
".align 4\n"
".align 4\n"
);
);


#include <stdint.h>
#include <stdint.h>
#include <limits.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/types.h>
#include "compiler.h"
#include "compiler.h"


typedef void (*thunk)(void);
typedef void (*thunk)(void);




#if 0
#if 0
typedef signed long int32_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef unsigned long uint32_t;
typedef signed short int16_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef unsigned short uint16_t;
typedef signed char int8_t;
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef unsigned char uint8_t;


typedef uint32_t size_t;
typedef uint32_t size_t;
typedef int32_t ssize_t;
typedef int32_t ssize_t;
#endif
#endif


static inline uint32_t
static inline uint32_t
read_lr( void )
read_lr( void )
{
{
uint32_t lr;
uint32_t lr;
asm( "mov %0, lr" : "=r"(lr) );
asm( "mov %0, lr" : "=r"(lr) );
return lr;
return lr;
}
}




static inline void
static inline void
select_normal_vectors( void )
select_normal_vectors( void )
{
{
uint32_t reg;
uint32_t reg;
asm(
asm(
"mrc p15, 0, %0, c1, c0\n"
"mrc p15, 0, %0, c1, c0\n"
"bic %0, %0, #0x2000\n"
"bic %0, %0, #0x2000\n"
"mcr p15, 0, %0, c1, c0\n"
"mcr p15, 0, %0, c1, c0\n"
: "=r"(reg)
: "=r"(reg)
);
);
}
}


/*
/*
naming conventions
naming conventions
--------------------
--------------------
FLUSH instruction cache:
FLUSH instruction cache:
just mark all entries in the I cache as invalid. no other effect than slowing down code execution until cache is populated again.
just mark all entries in the I cache as invalid. no other effect than slowing down code execution until cache is populated again.
DRAIN write buffer:
DRAIN write buffer:
halt CPU execution until every RAM write operation has finished.
halt CPU execution until every RAM write operation has finished.
FLUSH data cache / cache entry:
FLUSH data cache / cache entry:
invalidating the cache content *without* writing back the dirty data into memory. (dangerous!)
invalidating the cache content *without* writing back the dirty data into memory. (dangerous!)
this will simply mark any data in cache (or in the line) as invalid, no matter if it was written back into RAM.
this will simply mark any data in cache (or in the line) as invalid, no matter if it was written back into RAM.
e.g.
e.g.
mcr p15, 0, Rd, c7, c6, 0 # whole D cache
mcr p15, 0, Rd, c7, c6, 0 # whole D cache
mcr p15, 0, Rd, c7, c6, 1 # single line in D cache
mcr p15, 0, Rd, c7, c6, 1 # single line in D cache
CLEAN data cache entry:
CLEAN data cache entry:
cleaning is the process of checking a single cahe entry and writing it back into RAM if it was not written yet.
cleaning is the process of checking a single cahe entry and writing it back into RAM if it was not written yet.
this will ensure that the contents of the data cache are also in RAM. only possible for a single line, so we have to loop though all lines.
this will ensure that the contents of the data cache are also in RAM. only possible for a single line, so we have to loop though all lines.
e.g.
e.g.
mcr p15, 0, Rd, c7, c10, 1 # Clean data cache entry (by address)
mcr p15, 0, Rd, c7, c10, 1 # Clean data cache entry (by address)
mcr p15, 0, Rd, c7, c14, 1 # Clean data cache entry (by index/segment)
mcr p15, 0, Rd, c7, c14, 1 # Clean data cache entry (by index/segment)
CLEAN and FLUSH data cache entry:
CLEAN and FLUSH data cache entry:
the logical consequence - write it back into RAM and mark cache entry as invalid. As if it never was in cache.
the logical consequence - write it back into RAM and mark cache entry as invalid. As if it never was in cache.