little-endian ppc64 support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
diff --git a/ChangeLog b/ChangeLog
index 837fa88..866fa05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-06-24 Alan Modra <amodra@gmail.com>
+
+ * src/powerpc/ffi.c (ffi_prep_args_SYSV): Move var declaration
+ before statements.
+ (ffi_prep_args64): Support little-endian.
+ (ffi_closure_helper_SYSV, ffi_closure_helper_LINUX64): Likewise.
+ * src/powerpc/linux64_closure.S (ffi_closure_LINUX64): Likewise.
+ * src/powerpc/ppc_closure.S (ffi_closure_SYSV): Likewise.
+
2013-06-12 Mischa Jonker <mjonker@synopsys.com>
* configure.ac: Add support for ARC.
@@ -354,7 +363,7 @@
(required for shared libs on cygwin/mingw).
* Makefile.in: Rebuilt.
-2012-10-31 Alan Modra <amodra@gmail.com>
+2012-10-31 Alan Modra <amodra@gmail.co>
* src/powerpc/linux64_closure.S: Add new ABI support.
* src/powerpc/linux64.S: Likewise.
diff --git a/src/powerpc/ffi.c b/src/powerpc/ffi.c
index 54f2731..3156e9c 100644
--- a/src/powerpc/ffi.c
+++ b/src/powerpc/ffi.c
@@ -132,6 +132,9 @@ ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
int i;
ffi_type **ptr;
+#ifndef __NO_FPRS__
+ double double_tmp;
+#endif
union {
void **v;
char **c;
@@ -151,7 +154,6 @@ ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS;
intarg_count = 0;
#ifndef __NO_FPRS__
- double double_tmp;
fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS;
fparg_count = 0;
copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c);
@@ -553,11 +555,12 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
{
char *where = next_arg.c;
+#ifndef __LITTLE_ENDIAN__
/* Structures with size less than eight bytes are passed
left-padded. */
if ((*ptr)->size < 8)
where += 8 - (*ptr)->size;
-
+#endif
memcpy (where, *p_argv.c, (*ptr)->size);
next_arg.ul += words;
if (next_arg.ul == gpr_end.ul)
@@ -1236,6 +1239,7 @@ ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue,
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
+#ifndef __LITTLE_ENDIAN__
/* there are 8 gpr registers used to pass values */
if (ng < 8)
{
@@ -1249,9 +1253,11 @@ ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue,
pst++;
}
break;
+#endif
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
+#ifndef __LITTLE_ENDIAN__
/* there are 8 gpr registers used to pass values */
if (ng < 8)
{
@@ -1265,6 +1271,7 @@ ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue,
pst++;
}
break;
+#endif
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
@@ -1395,21 +1402,27 @@ ffi_closure_helper_LINUX64 (ffi_closure *closure, void *rvalue,
{
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
+#ifndef __LITTLE_ENDIAN__
avalue[i] = (char *) pst + 7;
pst++;
break;
+#endif
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
+#ifndef __LITTLE_ENDIAN__
avalue[i] = (char *) pst + 6;
pst++;
break;
+#endif
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
+#ifndef __LITTLE_ENDIAN__
avalue[i] = (char *) pst + 4;
pst++;
break;
+#endif
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
@@ -1419,11 +1432,13 @@ ffi_closure_helper_LINUX64 (ffi_closure *closure, void *rvalue,
break;
case FFI_TYPE_STRUCT:
+#ifndef __LITTLE_ENDIAN__
/* Structures with size less than eight bytes are passed
left-padded. */
if (arg_types[i]->size < 8)
avalue[i] = (char *) pst + 8 - arg_types[i]->size;
else
+#endif
avalue[i] = pst;
pst += (arg_types[i]->size + 7) / 8;
break;
diff --git a/src/powerpc/linux64_closure.S b/src/powerpc/linux64_closure.S
index b1e1219..ac4a226 100644
--- a/src/powerpc/linux64_closure.S
+++ b/src/powerpc/linux64_closure.S
@@ -132,7 +132,11 @@ ffi_closure_LINUX64:
blr
nop
# case FFI_TYPE_INT
+#ifdef __LITTLE_ENDIAN__
+ lwa %r3, 112+0(%r1)
+#else
lwa %r3, 112+4(%r1)
+#endif
mtlr %r0
addi %r1, %r1, 240
blr
@@ -152,33 +156,57 @@ ffi_closure_LINUX64:
lfd %f2, 112+8(%r1)
b .Lfinish
# case FFI_TYPE_UINT8
+#ifdef __LITTLE_ENDIAN__
+ lbz %r3, 112+0(%r1)
+#else
lbz %r3, 112+7(%r1)
+#endif
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT8
+#ifdef __LITTLE_ENDIAN__
+ lbz %r3, 112+0(%r1)
+#else
lbz %r3, 112+7(%r1)
+#endif
extsb %r3,%r3
mtlr %r0
b .Lfinish
# case FFI_TYPE_UINT16
+#ifdef __LITTLE_ENDIAN__
+ lhz %r3, 112+0(%r1)
+#else
lhz %r3, 112+6(%r1)
+#endif
mtlr %r0
.Lfinish:
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT16
+#ifdef __LITTLE_ENDIAN__
+ lha %r3, 112+0(%r1)
+#else
lha %r3, 112+6(%r1)
+#endif
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_UINT32
+#ifdef __LITTLE_ENDIAN__
+ lwz %r3, 112+0(%r1)
+#else
lwz %r3, 112+4(%r1)
+#endif
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT32
+#ifdef __LITTLE_ENDIAN__
+ lwa %r3, 112+0(%r1)
+#else
lwa %r3, 112+4(%r1)
+#endif
mtlr %r0
addi %r1, %r1, 240
blr
diff --git a/src/powerpc/ppc_closure.S b/src/powerpc/ppc_closure.S
index 41fb885..c3349df 100644
--- a/src/powerpc/ppc_closure.S
+++ b/src/powerpc/ppc_closure.S
@@ -159,25 +159,41 @@ ENTRY(ffi_closure_SYSV)
#endif
# case FFI_TYPE_UINT8
+#ifdef __LITTLE_ENDIAN__
+ lbz %r3,112+0(%r1)
+#else
lbz %r3,112+3(%r1)
+#endif
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_SINT8
+#ifdef __LITTLE_ENDIAN__
+ lbz %r3,112+0(%r1)
+#else
lbz %r3,112+3(%r1)
+#endif
extsb %r3,%r3
mtlr %r0
b .Lfinish
# case FFI_TYPE_UINT16
+#ifdef __LITTLE_ENDIAN__
+ lhz %r3,112+0(%r1)
+#else
lhz %r3,112+2(%r1)
+#endif
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_SINT16
+#ifdef __LITTLE_ENDIAN__
+ lha %r3,112+0(%r1)
+#else
lha %r3,112+2(%r1)
+#endif
mtlr %r0
addi %r1,%r1,144
blr
@@ -239,9 +255,15 @@ ENTRY(ffi_closure_SYSV)
# case FFI_SYSV_TYPE_SMALL_STRUCT + 3. Three byte struct.
lwz %r3,112+0(%r1)
+#ifdef __LITTLE_ENDIAN__
+ mtlr %r0
+ addi %r1,%r1,144
+ blr
+#else
srwi %r3,%r3,8
mtlr %r0
b .Lfinish
+#endif
# case FFI_SYSV_TYPE_SMALL_STRUCT + 4. Four byte struct.
lwz %r3,112+0(%r1)
@@ -252,20 +274,35 @@ ENTRY(ffi_closure_SYSV)
# case FFI_SYSV_TYPE_SMALL_STRUCT + 5. Five byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
+#ifdef __LITTLE_ENDIAN__
+ mtlr %r0
+ b .Lfinish
+#else
li %r5,24
b .Lstruct567
+#endif
# case FFI_SYSV_TYPE_SMALL_STRUCT + 6. Six byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
+#ifdef __LITTLE_ENDIAN__
+ mtlr %r0
+ b .Lfinish
++#else
li %r5,16
b .Lstruct567
+#endif
# case FFI_SYSV_TYPE_SMALL_STRUCT + 7. Seven byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
+#ifdef __LITTLE_ENDIAN__
+ mtlr %r0
+ b .Lfinish
+#else
li %r5,8
b .Lstruct567
+#endif
# case FFI_SYSV_TYPE_SMALL_STRUCT + 8. Eight byte struct.
lwz %r3,112+0(%r1)
@@ -273,6 +310,7 @@ ENTRY(ffi_closure_SYSV)
mtlr %r0
b .Lfinish
+#ifndef __LITTLE_ENDIAN__
.Lstruct567:
subfic %r6,%r5,32
srw %r4,%r4,%r5
@@ -288,7 +326,8 @@ ENTRY(ffi_closure_SYSV)
mtlr %r0
addi %r1,%r1,144
blr
-
+#endif
+
END(ffi_closure_SYSV)
.section ".eh_frame",EH_FRAME_FLAGS,@progbits