cvsuser 04/02/25 03:11:15
Modified: pf pf_items.c
src packfile.c
Log:
more PBC cleanup and changes
Revision Changes Path
1.8 +65 -58 parrot/pf/pf_items.c
Index: pf_items.c
===================================================================
RCS file: /cvs/public/parrot/pf/pf_items.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- pf_items.c 25 Feb 2004 00:16:33 -0000 1.7
+++ pf_items.c 25 Feb 2004 11:11:03 -0000 1.8
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pf_items.c,v 1.7 2004/02/25 00:16:33 scog Exp $
+$Id: pf_items.c,v 1.8 2004/02/25 11:11:03 leo Exp $
=head1 NAME
@@ -128,50 +128,58 @@
/*
* opcode fetch helper function
*
- * This is mostly wrong
- *
- * - it doesn't consider the endianess of the packfile
- * - should be separated into several different fetch functions
+ * This is mostly wrong or at least untested
*
+ * Fetch an opcode and convert to LE
*/
static opcode_t
-fetch_op_mixed(unsigned char *b)
+fetch_op_mixed_le(unsigned char *b)
{
#if OPCODE_T_SIZE == 4
union {
unsigned char buf[8];
opcode_t o[2];
} u;
+ /* wordsize = 8 then */
+ fetch_buf_le_8(u.buf, (unsigned char *) b);
+ return u.o[0]; /* or u.o[1] */
#else
union {
unsigned char buf[4];
opcode_t o;
} u;
- opcode_t o;
-#endif
-#if PARROT_BIGENDIAN
-# if OPCODE_T_SIZE == 4
- /* wordsize = 8 then */
- fetch_buf_le_8(u.buf, (unsigned char *) b);
- return u.o[1]; /* or u.o[0] */
-# else
- o = fetch_op_le(b); /* or fetch_be_le_4 and convert? */
- return o >> 32; /* or o & 0xffffffff */
+ /* wordsize = 4 */
+ u.o = 0;
+ fetch_buf_le_4(u.buf, b);
+ return u.o;
# endif
-#else
+}
+
+/*
+ * Fetch an opcode and convert to BE
+ */
+static opcode_t
+fetch_op_mixed_be(unsigned char *b)
+{
# if OPCODE_T_SIZE == 4
+ union {
+ unsigned char buf[8];
+ opcode_t o[2];
+ } u;
/* wordsize = 8 then */
fetch_buf_be_8(u.buf, (unsigned char *) b);
- return u.o[0]; /* or u.o[1] */
+ return u.o[1]; /* or u.o[0] */
# else
- /* fetch 4 bytes from a LE pbc, result 8 byte LE opcode_t */
+ union {
+ unsigned char buf[4];
+ opcode_t o;
+ } u;
+ /* wordsize = 4 */
u.o = 0;
- fetch_buf_le_4(u.buf, b);
+ fetch_buf_be_4(u.buf, b);
return u.o;
# endif
-
-#endif
}
/*
@@ -583,38 +591,45 @@
*/
void
-PackFile_assign_transforms(struct PackFile *pf) {
+PackFile_assign_transforms(struct PackFile *pf)
+{
+ int need_endianize = pf->header->byteorder != PARROT_BIGENDIAN;
+ int need_wordsize = pf->header->wordsize != sizeof(opcode_t);
+
+ pf->need_endianize = need_endianize;
+ pf->need_wordsize = need_wordsize;
#if PARROT_BIGENDIAN
- if(pf->header->byteorder != PARROT_BIGENDIAN) {
- pf->need_endianize = 1;
- if (pf->header->wordsize == sizeof(opcode_t))
- pf->fetch_op = (opcode_t (*)(unsigned char*))fetch_op_le;
+ /*
+ * this Parrot is on a BIG ENDIAN machine
+ */
+ if (need_endianize || need_wordsize) {
+ if (need_wordsize)
+ pf->fetch_op = fetch_op_mixed_be;
else {
- pf->need_wordsize = 1;
- pf->fetch_op = fetch_op_mixed;
+ pf->fetch_op = (opcode_t (*)(unsigned char*))fetch_op_be;
}
-
- pf->fetch_iv = fetch_iv_le;
+ }
+ if (need_endianize) {
if (pf->header->floattype == 0)
- pf->fetch_nv = fetch_buf_le_8;
+ pf->fetch_nv = fetch_buf_be_8;
else if (pf->header->floattype == 1)
- pf->fetch_nv = cvt_num12_num8_le;
+ pf->fetch_nv = cvt_num12_num8_be;
}
#else
- if(pf->header->byteorder != PARROT_BIGENDIAN) {
- pf->need_endianize = 1;
- if (pf->header->wordsize == sizeof(opcode_t)) {
- pf->fetch_op = (opcode_t (*)(unsigned char*))fetch_op_be;
- }
- else {
- pf->need_wordsize = 1;
- pf->fetch_op = fetch_op_mixed;
+ /*
+ * this Parrot is on a LITTLE ENDIAN machine
+ */
+ if (need_endianize || need_wordsize) {
+ if (need_wordsize)
+ pf->fetch_op = fetch_op_mixed_le;
+ else
+ pf->fetch_op = (opcode_t (*)(unsigned char*))fetch_op_le;
}
- pf->fetch_iv = (opcode_t (*)(unsigned char*))fetch_iv_be;
+ if (need_endianize) {
if (pf->header->floattype == 0)
- pf->fetch_nv = fetch_buf_be_8;
+ pf->fetch_nv = fetch_buf_le_8;
else if (pf->header->floattype == 1)
- pf->fetch_nv = cvt_num12_num8_be;
+ pf->fetch_nv = cvt_num12_num8_le;
}
else {
if (NUMVAL_SIZE == 8 && pf->header->floattype == 1)
@@ -622,15 +637,7 @@
else if (NUMVAL_SIZE != 8 && pf->header->floattype == 0)
pf->fetch_nv = fetch_buf_le_8;
}
-# if TRACE_PACKFILE
- PIO_eprintf(NULL, "header->byteorder [%d] native byteorder [%d]\n",
- pf->header->byteorder, PARROT_BIGENDIAN);
-# endif
#endif
- if (pf->header->wordsize != sizeof(opcode_t)) {
- pf->need_wordsize = 1;
- pf->fetch_op = fetch_op_mixed;
- }
}
/*
1.144 +22 -12 parrot/src/packfile.c
Index: packfile.c
===================================================================
RCS file: /cvs/public/parrot/src/packfile.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -w -r1.143 -r1.144
--- packfile.c 24 Feb 2004 14:38:07 -0000 1.143
+++ packfile.c 25 Feb 2004 11:11:15 -0000 1.144
@@ -2,7 +2,7 @@
Copyright (C) 2001-2002 Gregor N. Purdy. All rights reserved.
This program is free software. It is subject to the same license as
Parrot itself.
-$Id: packfile.c,v 1.143 2004/02/24 14:38:07 leo Exp $
+$Id: packfile.c,v 1.144 2004/02/25 11:11:15 leo Exp $
=head1 NAME
@@ -80,6 +80,11 @@
struct PackFile_Segment *self, opcode_t *);
static void pf_debug_destroy (struct PackFile_Segment *self);
+#define ROUND_16(val) ((val) & 0xf) ? 16 - ((val) & 0xf) : 0
+#define ALIGN_16(st, cursor) do { \
+ LVALUE_CAST(unsigned char*, cursor) += \
+ ROUND_16((unsigned char*)(cursor) - (unsigned char*)(st)); \
+ } while (0)
/*
@@ -475,6 +480,11 @@
header->wordsize);
return 0;
}
+ if (header->floattype != 0 && header->floattype != 1) {
+ PIO_eprintf(NULL, "PackFile_unpack: Invalid floattype %d\n",
+ header->floattype);
+ return 0;
+ }
PackFile_assign_transforms(self);
@@ -483,12 +493,18 @@
PIO_eprintf(NULL, "byteorder: %d\n", header->byteorder);
#endif
+#if 0
+ /*
+ * disable version check, so that we can fix PF platforms
+ * issues
+ */
if (header->major != PARROT_MAJOR_VERSION ||
- header->minor != (PARROT_MINOR_VERSION|PARROT_PATCH_VERSION)) {
+ header->minor != PARROT_MINOR_VERSION) {
PIO_eprintf(NULL, "PackFile_unpack: Bytecode not valid for this "
"interpreter: version mismatch\n");
return 0;
}
+#endif
/* check the fingerprint */
if (!PackFile_check_fingerprint (header->pad)) {
@@ -719,8 +735,7 @@
self->header->wordsize = sizeof(opcode_t);
self->header->byteorder = PARROT_BIGENDIAN;
self->header->major = PARROT_MAJOR_VERSION;
- /* XXX during development, we check PATCH_LEVEL too */
- self->header->minor = PARROT_MINOR_VERSION | PARROT_PATCH_VERSION;
+ self->header->minor = PARROT_MINOR_VERSION;
self->header->intvalsize = sizeof(INTVAL);
if (NUMVAL_SIZE == 8)
self->header->floattype = 0;
@@ -1134,7 +1149,6 @@
{
PackFile_Segment_unpack_func_t f =
self->pf->PackFuncs[self->type].unpack;
- size_t align = 16/sizeof(opcode_t);
cursor = default_unpack(interpreter, self, cursor);
if (!cursor)
@@ -1144,8 +1158,7 @@
if (!cursor)
return 0;
}
- if (align && (cursor - self->pf->src) % align)
- cursor += align - (cursor - self->pf->src) % align;
+ ALIGN_16(self->pf->src, cursor);
return cursor;
}
@@ -1255,7 +1268,6 @@
struct PackFile_Directory *dir = (struct PackFile_Directory *) segp;
struct PackFile * pf = dir->base.pf;
opcode_t *pos;
- size_t align;
dir->num_segments = PF_fetch_opcode (pf, &cursor);
dir->segments = mem_sys_realloc (dir->segments,
@@ -1302,9 +1314,7 @@
seg->dir = dir;
}
- align = 16/sizeof(opcode_t);
- if (align && (cursor - pf->src) % align)
- cursor += align - (cursor - pf->src) % align;
+ ALIGN_16(pf->src, cursor);
/* and now unpack contents of dir */
for (i = 0; cursor && i < dir->num_segments; i++) {
opcode_t *csave = cursor;