Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,251 Views

Situation with Memcpy

Hallo, 

 

I have a situation here and i will try my best to explain it.  

 

I have two pointers, both of them allocated 6 bytes of memory through alt_remap_uncached. 

 

The source pointer has the following data: 1F 00 32 FF FF FF 

And the target at this point is 00 00 00 00 00 00. 

 

Now I use memcpy and copy the 6 bytes of data from the source location to the target location.  

 

The Current statuses are 

 

Source pointer: 1F 00 32 FF FF ff 

Target Pointer: 1F 00 32 FF FF 00 

 

if you notice the last byte of the target structure remains 00 which is the value it had previously. how is this possible?? the last byte of the source does not get copied to the target. does it have to do with cache issues??  

 

I would be very grateful for your assistence with this issue.  

 

Thanks in advance.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor I
68 Views

I'd try initializing target with values other than 00, for example 11, 22 ,33 .... 

So you can see if the first byte was indeed not written or it was rather overwritten to 00 by something else.
Altera_Forum
Honored Contributor I
68 Views

Dunno what alt_remap_uncached() is supposed to do! bu I guess it might just giving you an address for the memory that bypasses the cache. 

In an mmu-less envornment this will just set the top bit (2^31). 

 

This has two problems: 

1) it doesn't invalidate the data cache - dirty lines might get written back. 

2) writes to memory before/after the requested item will dirty the cache lines. 

(altera's 'malloc uncached memory' function has the same problems) 

 

For device memory this probably isn't an issue. 

For 'real' memory you need to ensure the items are cache-line aligned. 

with gcc: char foo[32] __attribute__((aligned(16))); will align the addess of a static data item.
Altera_Forum
Honored Contributor I
68 Views

Hallo All, 

 

Thank you very much for your answers.  

 

I tried initializing the target pointer with initial values to see if any other operation is overwriting my values. But that is not the case.  

 

Here is the funny part. There is a memcpy function being called right after this and that works perfectly. All six bytes are transferred between the source and the target perfectly. I simply cant place the error.  

 

I have tried using IORD and IOWR functions so that the Cache is bypassed. That is not working out too. If you have any other suggestions however bizarre, please let me know.  

 

Thank you.
Altera_Forum
Honored Contributor I
68 Views

As I said before you've got probems with the existing cache contents and the other items that share the cache line.

Altera_Forum
Honored Contributor I
68 Views

Well I have finally solved this problem. But I still dont understand the cause. It would seem that between the source and destination addresses where the data was being copied, there were copied to some intermediate locations and the data got corrupted on the way.  

 

Thank you all for your answers and suggestions.
Reply