struct rb_node node;
/* base register handled by this block */
unsigned int base_reg;
- /* number of bytes needed to represent the register index */
- unsigned int word_size;
/* block of adjacent registers */
void *block;
/* number of registers available in the block */
}
static unsigned int regcache_rbtree_get_register(
- struct regcache_rbtree_node *rbnode, unsigned int idx)
+ struct regcache_rbtree_node *rbnode, unsigned int idx,
+ unsigned int word_size)
{
unsigned int val;
- switch (rbnode->word_size) {
+ switch (word_size) {
case 1: {
u8 *p = rbnode->block;
val = p[idx];
}
static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode,
- unsigned int idx, unsigned int val)
+ unsigned int idx, unsigned int val,
+ unsigned int word_size)
{
- switch (rbnode->word_size) {
+ switch (word_size) {
case 1: {
u8 *p = rbnode->block;
p[idx] = val;
regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg);
if (reg >= base_reg && reg <= top_reg) {
reg_tmp = reg - base_reg;
- *value = regcache_rbtree_get_register(rbnode, reg_tmp);
+ *value = regcache_rbtree_get_register(rbnode, reg_tmp,
+ map->cache_word_size);
return 0;
}
}
rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg);
if (rbnode) {
reg_tmp = reg - rbnode->base_reg;
- *value = regcache_rbtree_get_register(rbnode, reg_tmp);
+ *value = regcache_rbtree_get_register(rbnode, reg_tmp,
+ map->cache_word_size);
rbtree_ctx->cached_rbnode = rbnode;
} else {
/* uninitialized registers default to 0 */
static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode,
unsigned int pos, unsigned int reg,
- unsigned int value)
+ unsigned int value, unsigned int word_size)
{
u8 *blk;
blk = krealloc(rbnode->block,
- (rbnode->blklen + 1) * rbnode->word_size, GFP_KERNEL);
+ (rbnode->blklen + 1) * word_size, GFP_KERNEL);
if (!blk)
return -ENOMEM;
/* insert the register value in the correct place in the rbnode block */
- memmove(blk + (pos + 1) * rbnode->word_size,
- blk + pos * rbnode->word_size,
- (rbnode->blklen - pos) * rbnode->word_size);
+ memmove(blk + (pos + 1) * word_size,
+ blk + pos * word_size,
+ (rbnode->blklen - pos) * word_size);
/* update the rbnode block, its size and the base register */
rbnode->block = blk;
if (!pos)
rbnode->base_reg = reg;
- regcache_rbtree_set_register(rbnode, pos, value);
+ regcache_rbtree_set_register(rbnode, pos, value, word_size);
return 0;
}
regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg);
if (reg >= base_reg && reg <= top_reg) {
reg_tmp = reg - base_reg;
- val = regcache_rbtree_get_register(rbnode, reg_tmp);
+ val = regcache_rbtree_get_register(rbnode, reg_tmp,
+ map->cache_word_size);
if (val == value)
return 0;
- regcache_rbtree_set_register(rbnode, reg_tmp, value);
+ regcache_rbtree_set_register(rbnode, reg_tmp, value,
+ map->cache_word_size);
return 0;
}
}
rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg);
if (rbnode) {
reg_tmp = reg - rbnode->base_reg;
- val = regcache_rbtree_get_register(rbnode, reg_tmp);
+ val = regcache_rbtree_get_register(rbnode, reg_tmp,
+ map->cache_word_size);
if (val == value)
return 0;
- regcache_rbtree_set_register(rbnode, reg_tmp, value);
+ regcache_rbtree_set_register(rbnode, reg_tmp, value,
+ map->cache_word_size);
rbtree_ctx->cached_rbnode = rbnode;
} else {
/* bail out early, no need to create the rbnode yet */
else
pos = i;
ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos,
- reg, value);
+ reg, value,
+ map->cache_word_size);
if (ret)
return ret;
rbtree_ctx->cached_rbnode = rbnode_tmp;
return -ENOMEM;
rbnode->blklen = 1;
rbnode->base_reg = reg;
- rbnode->word_size = map->cache_word_size;
- rbnode->block = kmalloc(rbnode->blklen * rbnode->word_size,
+ rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size,
GFP_KERNEL);
if (!rbnode->block) {
kfree(rbnode);
return -ENOMEM;
}
- regcache_rbtree_set_register(rbnode, 0, value);
+ regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size);
regcache_rbtree_insert(&rbtree_ctx->root, rbnode);
rbtree_ctx->cached_rbnode = rbnode;
}
rbnode = rb_entry(node, struct regcache_rbtree_node, node);
for (i = 0; i < rbnode->blklen; i++) {
regtmp = rbnode->base_reg + i;
- val = regcache_rbtree_get_register(rbnode, i);
+ val = regcache_rbtree_get_register(rbnode, i,
+ map->cache_word_size);
ret = regcache_lookup_reg(map, i);
if (ret < 0)
def = 0;