Find out if an object on a specific address is a pointer

Roel Balink Source

I Have a PC Program that is communicating over a TCP/IP Connection to an Embedded board (Infineon XE169 (C166 Family)).

This PC Program request what data is stored on a certain address. The PC Program is uC/Probe, and I cannot change how this program is working.

uC/Probe for example sends this message:

|     Prefix         | Length    |Pkt_nr|Unused| Format    | read size | Address to read      |Unused|Postfix|
|0x75 0x43 0x50 0x72 | 0x00 0x08 | 0x00 | 0x00 | 0x02 0x00 | 0x04 0x00 | 0xDC  0x3E 0x61 0x00 | 0x00 | 0x2F  |
|u    C    P    r    |   8       | 0    |  0   | 2         | 4         | 0x613EDC             | 0    | /     |   

This is a message to request the data from address 0x613EDC and read 4 bytes from there.

When looking in the .map file I can see that at this location the OSTCBCurPtr variable is placed. This variable is an OS_TCB* thus at the requested address is the address placed where this variable is pointing to.

I've now manually looked in the .map file what kind of variable is placed on the address. But can I get the variable type trough the C code on the Embedded board. All I want to know is if the object that lies on that specific location is a pointer or not, if it's an uint16_t, uint8_t, char or whatever is unimportant to me.

Background information, why I want to know this

The Embedded board will sent back the requested data to the uC/Probe program. But the pointers are stored in a strange way in the XE169 chip. The pointer of above example is for example stored like this:

| Address   |  0   |   1  |  2   |  3   |
|0x00613EDC | 0xE6 | 0x1F | 0x84 | 0x01 |

Because the value's are stored little endian this would result in the number 0x01841FE6. This number is currently send back to uC/Probe. But his number isn't the correct location of the, a little calculation has to be done to get to the actual address location.

We have to take apart this 32bits number and split it into 2 16 bit numbers. Then we get:

Hex:  0x0184             and 0x1FE6
Bits: 0b0000000110000100 and 0001111111100110

Now the 16 upper bits have to move 2 bits to the right. The 2 least significant bits of these upper 16 bits become the 2 most significant bits on the lower 16 bits.

This results into:

Hex:  0x0061             and 0x1FE6
Bits: 0b0000000001100001 and 0001111111100110

When we paste these 2 16 bit numbers back to the 32 bit number we have the address where the pointer is pointing to: 0x00611FE6

And this is the number I have to sent back to uC/Probe. This calculation only has to happen for when uC/Probe requests pointers, for non pointers it just needs to send back the data read from the given address. That's why I need to know if the requested data is a pointer, hopefully someone can help me with this.



comments powered by Disqus