Wrong value when loading a half word into arm7tdmi register (ldrh)

1 view
Skip to first unread message

Thomas Olsen

unread,
Aug 29, 2009, 3:19:29 PM8/29/09
to skyeye-simulator
I am experiencing problems in method mem_read(short size, int offset,
uint32_t * value) from the file memory/ram.c (skyeye 1.2.8) when my
executable has a ldrh instruction. During debugging I can tell that
the upper 16 bits are not cleared when loading the value from memory.

I have compiled skyeye with gcc 4.2.4 on ubuntu 8.04 and I am not sure
if that has anything to say.

The problem is fixed for arm7tdmi if I provide the below version of
mem_read. I am not aware if it has anything to say for the other
platforms or if this fix will cause any problems for the other
platforms.

char mem_read(short size, int offset, uint32_t * value) {



switch(size){

case 8:

*value = mem_read_byte (offset);

break;

case 16:

*value = mem_read_halfword(offset);

break;

case 32:

*value = mem_read_word(offset);

break;

default:

fprintf(stderr, "In %s, invalid data length %d\n", __FUNCTION__,
size);

return -1;

}



return 0;

}

cheers,
Thomas

Thomas Olsen

unread,
Sep 11, 2009, 9:33:08 AM9/11/09
to skyeye-simulator
I have been researching the problem a bit further and can tell that my
initial solution is not valid as the skyeye test does not run.

I have assumed that the load halfword method has only been used by ldr
instructions to load the values into a register. According to the arm7
documentation a ldrh should clear the upper 16 bits (if I have not
misunderstood something) so that should also be ok, and my program
only works when the upper bits are cleared (I use the codesourcery
compiler).

I did not realize that there is actually another version of the method
“ARMul_LoadHalfWord” in file armvirt.c (should have been a bit more
awake). This version that is left out, is actually doing what I am
looking for. I have had a look in the svn source view on the home
page, but I have not been able to locate why this method is not used.

I would appreciate any information about why the old method is not
used any more or if somebody has an idea about where I can continue to
look for a solution.

Thanks,
Thomas
Reply all
Reply to author
Forward
0 new messages