This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
[PATCH] microblaze: Fix big endian struct handling
- From: Nathan Rossi <nathan dot rossi at xilinx dot com>
- To: <libffi-discuss at sourceware dot org>
- Cc: Nathan Rossi <nathan dot rossi at xilinx dot com>
- Date: Fri, 8 Feb 2013 14:11:25 +1000
- Subject: [PATCH] microblaze: Fix big endian struct handling
Fix handling of big endian structures on MicroBlaze. This patch fixes the
accessing of structs that are smaller then 4 bytes, structs can be allocated
on the stack with non-word aligned addresses, replace word read/write accesses
with byte read/write accesses.
This fixes MicroBlaze big endian so that the cls_3_1byte test case functions
correctly.
Signed-off-by: Nathan Rossi <nathan.rossi@xilinx.com>
---
ChangeLog | 3 +++
src/microblaze/ffi.c | 22 ++--------------------
2 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bf2c179..0da827b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2013-02-08 Nathan Rossi <nathan.rossi@xilinx.com>
+ * src/microblaze/ffi.c: Fixed issue.
+
2013-02-07 Anthony Green <green@moxielogic.com>
* configure.ac: Update bug reporting address.
diff --git a/src/microblaze/ffi.c b/src/microblaze/ffi.c
index 86ea37d..2689cb0 100644
--- a/src/microblaze/ffi.c
+++ b/src/microblaze/ffi.c
@@ -119,16 +119,7 @@ void ffi_prep_args(void* stack, extended_cif* ecif)
*/
if (size < WORD_SIZE)
{
- if (size == 1) {
- *(unsigned int *)addr =
- (unsigned int)*(UINT8*)(value);
- } else if (size == 2) {
- *(unsigned int *)addr =
- (unsigned int)*(UINT16*)(value);
- } else {
- *(unsigned int *)addr =
- ((unsigned int)*(UINT32*)(value)) >> 8;
- }
+ memcpy(addr + (WORD_SIZE - size), value, size);
break;
}
#endif
@@ -250,16 +241,7 @@ void ffi_closure_call_SYSV(void* register_args, void* stack_args,
*/
if (arg_types[i]->size < WORD_SIZE)
{
- if (arg_types[i]->size == 1) {
- *(unsigned int *)ptr =
- ((unsigned int)*(UINT32*)(ptr)) << 24;
- } else if (arg_types[i]->size == 2) {
- *(unsigned int *)ptr =
- ((unsigned int)*(UINT32*)(ptr)) << 16;
- } else {
- *(unsigned int *)ptr =
- ((unsigned int)*(UINT32*)(ptr)) << 8;
- }
+ memcpy(ptr, ptr + (WORD_SIZE - arg_types[i]->size), arg_types[i]->size);
}
#endif
avalue[i] = (void*)ptr;
--
1.7.5.4