typedef struct cache_line_t{
ARMword tag; /* cache line align address |
bit2: last half dirty
bit1: first half dirty
bit0: cache valid flag
*/
ARMword pa; /*physical address*/
ARMword *data; /*array of cached data*/
}cache_line_t;
#define TAG_VALID_FLAG 0x00000001
#define TAG_FIRST_HALF_DIRTY 0x00000002
#define TAG_LAST_HALF_DIRTY 0x00000004
Cache 组
typedef struct cache_set_s{
cache_line_t *lines;
int cycle; /*used for cache line allocation*/
}cache_set_t;
Cache 结构
typedef struct cache_s{
int width; /*bytes in a line*/
int way; /*way of set asscociate*/
int set; /*num of set*/
int w_mode; /*write back or write through*/
//int a_mode; /*alloc mode: random or round-bin*/
cache_set_t *sets;
}cache_t;
typedef struct wb_entry_s{
ARMword pa; //phy_addr
ARMbyte *data;//data
int nb; //number byte to write
}wb_entry_t;
typedef struct wb_s{
int num; //wb_entry_t的总数
int nb; //wb_entry_t中最大字节数
int first; //循环队列头
int last; //循环队列尾
int used; //循环队列中已用wb_entry_t的个数
wb_entry_t *entrys;
}wb_t;
接口函数
/*初始化和释放*/
int mmu_wb_init(wb_t *wb_t, int num, int nb);
void mmu_wb_exit(wb_t *wb);
/*数据入Write Buffer*/
void mmu_wb_write_bytess(ARMul_State *state, wb_t *wb_t, ARMword pa,
ARMbyte *data, int n);
/*将Write Buffer中数据全部写入内存*/
void mmu_wb_drain_all(ARMul_State *state, wb_t *wb_t);
Read Buffer的实现(mmu/rb.[hc])
数据结构
typedef struct rb_entry_s{
ARMword data[RB_WORD_NUM];//array to store data
ARMword va; //first word va
int type; //rb type
fault_t fault; //fault set by rb alloc
}rb_entry_t;
typedef struct rb_s{
int num;
rb_entry_t *entrys;
}rb_t;
接口函数
/*初始化和释放*/
int mmu_rb_init(rb_t *rb_t, int num);
void mmu_rb_exit(rb_t *rb_t);
rb_entry_t *mmu_rb_search(rb_t *rb_t, ARMword va);/*查找*/
void mmu_rb_invalidate_entry(rb_t *rb_t, int i);/*无效*/
void mmu_rb_invalidate_all(rb_t *rb_t);
void mmu_rb_load(ARMul_State *state, rb_t *rb_t, int i_rb, int type, ARMword va);/*装入*/