Commits

Anonymous committed 69b37db

#99: mainlining directly

  • Participants
  • Parent commits b20bd4e

Comments (0)

Files changed (13)

     """__NATIVE__
     PmReturn_t retval;
     uint8_t imgType;
-    uint8_t imgSize;
+    uint16_t imgSize;
     uint8_t *pchunk;
     pPmString_t pimg;
-    uint8_t i;
+    uint16_t i;
     uint8_t b;
 
     /* Get the image type */
         return retval;
     }
 
-    /* Get the image size */
-    retval = plat_getByte(&imgSize);
+    /* Get the image size (little endien) */
+    retval = plat_getByte(&b);
     PM_RETURN_IF_ERROR(retval);
+    imgSize = b;
+    retval = plat_getByte(&b);
+    PM_RETURN_IF_ERROR(retval);
+    imgSize |= (b << 8);
 
     /* Get space for String obj */
     retval = heap_getChunk(sizeof(PmString_t) + imgSize, &pchunk);
     /* Start the image with the bytes that have already been received */
     i = 0;
     pimg->val[i++] = imgType;
-    pimg->val[i++] = imgSize;
+    pimg->val[i++] = imgSize & 0xFF;
+    pimg->val[i++] = (imgSize >> 8) & 0xFF;
 
     /* Get the remaining bytes in the image */
     for(; i < imgSize; i++)

src/tests/system/t071.py

 #
 #   ipm> import sys; sys.putb(0x34); n=42; sys.putb(0x32)
 #
-img = '\nd\x00\x00\x03\x00\x04\x04\x03\x03sys\x03\x04putb\x03\x01n\x03\x05<ipm>\x04\x05\x01\xff\xff\xff\xff\x00\x014\x00\x00\x00\x01*\x00\x00\x00\x012\x00\x00\x00d\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x01\x00d\x02\x00\x83\x01\x00Fd\x03\x00Z\x02\x00e\x00\x00i\x01\x00d\x04\x00\x83\x01\x00Fd\x01\x00S'
+img = '\nh\x00\x00\x03\x00\x04\x04\x03\x03\x00sys\x03\x04\x00putb\x03\x01\x00n\x03\x05\x00<ipm>\x04\x05\x01\xff\xff\xff\xff\x00\x014\x00\x00\x00\x01*\x00\x00\x00\x012\x00\x00\x00d\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x01\x00d\x02\x00\x83\x01\x00Fd\x03\x00Z\x02\x00e\x00\x00i\x01\x00d\x04\x00\x83\x01\x00Fd\x01\x00S'
 
 # Convert the image to a code object and evaluate it
 co = Co(img)

src/tests/unit/ut_codeobj.c

 /* BEGIN unit tests ported from Snarf */
 /**
  * The following source code was compiled to an image using pmImgCreator.py
- * from svn revision [193] using this command line:
+ * from svn revision [195] using this command line:
  *
  *      ../../tools/pmImgCreator.py  -c -s -o utco.img.c utco.py
  * 
  */
 uint8_t test_code_image0[] =
 {
-    0x0A, 0xF8, 0x00, 0x00, 0x01, 0x00, 0x04, 0x02, 
-    0x03, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x03, 0x04, 
-    0x75, 0x74, 0x63, 0x6F, 0x04, 0x02, 0x0A, 0xCD, 
-    0x00, 0x00, 0x09, 0x05, 0x04, 0x01, 0x03, 0x04, 
-    0x6D, 0x61, 0x69, 0x6E, 0x04, 0x07, 0x00, 0x01, 
-    0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 
-    0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x01, 0x03, 
-    0x00, 0x00, 0x00, 0x04, 0x04, 0x01, 0x00, 0x00, 
-    0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 
-    0x02, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 
-    0x00, 0x04, 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 
-    0x01, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 
-    0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x64, 
-    0x01, 0x00, 0x7D, 0x00, 0x00, 0x64, 0x05, 0x00, 
-    0x7D, 0x01, 0x00, 0x64, 0x06, 0x00, 0x7D, 0x02, 
-    0x00, 0x78, 0x18, 0x00, 0x7C, 0x01, 0x00, 0x44, 
-    0x5D, 0x10, 0x00, 0x7D, 0x03, 0x00, 0x7C, 0x00, 
-    0x00, 0x7C, 0x03, 0x00, 0x37, 0x7D, 0x00, 0x00, 
-    0x71, 0x19, 0x00, 0x57, 0x78, 0x18, 0x00, 0x7C, 
-    0x02, 0x00, 0x44, 0x5D, 0x10, 0x00, 0x7D, 0x03, 
-    0x00, 0x7C, 0x00, 0x00, 0x7C, 0x03, 0x00, 0x38, 
-    0x7D, 0x00, 0x00, 0x71, 0x34, 0x00, 0x57, 0x78, 
-    0x2D, 0x00, 0x7C, 0x01, 0x00, 0x44, 0x5D, 0x25, 
-    0x00, 0x7D, 0x03, 0x00, 0x78, 0x1C, 0x00, 0x7C, 
-    0x02, 0x00, 0x44, 0x5D, 0x14, 0x00, 0x7D, 0x04, 
-    0x00, 0x7C, 0x00, 0x00, 0x7C, 0x03, 0x00, 0x7C, 
-    0x04, 0x00, 0x14, 0x37, 0x7D, 0x00, 0x00, 0x71, 
-    0x5C, 0x00, 0x57, 0x71, 0x4F, 0x00, 0x57, 0x7C, 
-    0x00, 0x00, 0x53, 0x00, 0x64, 0x00, 0x00, 0x84, 
-    0x00, 0x00, 0x5A, 0x00, 0x00, 0x65, 0x00, 0x00, 
-    0x83, 0x00, 0x00, 0x01, 0x64, 0x01, 0x00, 0x53, 
+    0x0A, 0xFB, 0x00, 0x00, 0x01, 0x00, 0x04, 0x02, 
+    0x03, 0x04, 0x00, 0x6D, 0x61, 0x69, 0x6E, 0x03, 
+    0x04, 0x00, 0x75, 0x74, 0x63, 0x6F, 0x04, 0x02, 
+    0x0A, 0xCE, 0x00, 0x00, 0x09, 0x05, 0x04, 0x01, 
+    0x03, 0x04, 0x00, 0x6D, 0x61, 0x69, 0x6E, 0x04, 
+    0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 
+    0x01, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 
+    0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x04, 
+    0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 
+    0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x01, 
+    0x03, 0x00, 0x00, 0x00, 0x04, 0x04, 0x01, 0x03, 
+    0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 
+    0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 
+    0x00, 0x00, 0x64, 0x01, 0x00, 0x7D, 0x00, 0x00, 
+    0x64, 0x05, 0x00, 0x7D, 0x01, 0x00, 0x64, 0x06, 
+    0x00, 0x7D, 0x02, 0x00, 0x78, 0x18, 0x00, 0x7C, 
+    0x01, 0x00, 0x44, 0x5D, 0x10, 0x00, 0x7D, 0x03, 
+    0x00, 0x7C, 0x00, 0x00, 0x7C, 0x03, 0x00, 0x37, 
+    0x7D, 0x00, 0x00, 0x71, 0x19, 0x00, 0x57, 0x78, 
+    0x18, 0x00, 0x7C, 0x02, 0x00, 0x44, 0x5D, 0x10, 
+    0x00, 0x7D, 0x03, 0x00, 0x7C, 0x00, 0x00, 0x7C, 
+    0x03, 0x00, 0x38, 0x7D, 0x00, 0x00, 0x71, 0x34, 
+    0x00, 0x57, 0x78, 0x2D, 0x00, 0x7C, 0x01, 0x00, 
+    0x44, 0x5D, 0x25, 0x00, 0x7D, 0x03, 0x00, 0x78, 
+    0x1C, 0x00, 0x7C, 0x02, 0x00, 0x44, 0x5D, 0x14, 
+    0x00, 0x7D, 0x04, 0x00, 0x7C, 0x00, 0x00, 0x7C, 
+    0x03, 0x00, 0x7C, 0x04, 0x00, 0x14, 0x37, 0x7D, 
+    0x00, 0x00, 0x71, 0x5C, 0x00, 0x57, 0x71, 0x4F, 
+    0x00, 0x57, 0x7C, 0x00, 0x00, 0x53, 0x00, 0x64, 
+    0x00, 0x00, 0x84, 0x00, 0x00, 0x5A, 0x00, 0x00, 
+    0x65, 0x00, 0x00, 0x83, 0x00, 0x00, 0x01, 0x64, 
+    0x01, 0x00, 0x53, 
 };
 
 

src/tests/unit/ut_heap.c

 #include "CuTest.h"
 #include "pm.h"
 
+#define HEAP_MAX_CHUNK_SIZE 1020
+
 
 /**
  * Tests heap_init():
 
 
 /**
+ * Tests heap_getChunk():
+ *      checks that MAX_CHUNK_SIZE can be allocated
+ */
+void
+ut_heap_getChunk_001(CuTest *tc)
+{
+    uint8_t *pchunk;
+    PmReturn_t retval;
+    pPmObj_t pobj;
+
+    retval = heap_init();
+    retval = heap_getChunk(HEAP_MAX_CHUNK_SIZE, &pchunk);
+    pobj = (pPmObj_t)pchunk;
+
+    CuAssertTrue(tc, retval == PM_RET_OK);
+    CuAssertPtrNotNull(tc, pchunk);
+    CuAssertTrue(tc, OBJ_GET_SIZE(*pobj) >= HEAP_MAX_CHUNK_SIZE);
+}
+
+
+/**
  * Tests heap_getAvail():
  *      retval is OK
  *      avail is reduced by amount obtained in getChunk
 
     SUITE_ADD_TEST(suite, ut_heap_init_000);
     SUITE_ADD_TEST(suite, ut_heap_getChunk_000);
+    SUITE_ADD_TEST(suite, ut_heap_getChunk_001);
     SUITE_ADD_TEST(suite, ut_heap_getAvail_000);
     SUITE_ADD_TEST(suite, ut_heap_freeChunk_000);
     SUITE_ADD_TEST(suite, ut_heap_freeChunk_001);
         # Otherwise send the image and print the reply
         else:
 
+            # DEBUG: Uncomment the next line to print the size of the code image
+            # print "DEBUG: len(codeimg) = ", len(codeimg)
             # DEBUG: Uncomment the next line to print the code image
-            # print "codeimg = ", repr(codeimg)
+            # print "DEBUG: codeimg = ", repr(codeimg)
 
             try:
                 self.conn.write(codeimg)

src/tools/pmImgCreator.py

 NATIVE_IMG_SIZE = 4
 
 # Maximum number of objs in a tuple
-MAX_TUPLE_LEN = 127
+MAX_TUPLE_LEN = 253
 
 # Maximum number of chars in a string (XXX bytes vs UTF-8 chars?)
-MAX_STRING_LEN = 127
+MAX_STRING_LEN = 999
 
 # Maximum number of chars in a code img
 MAX_IMG_LEN = 32767
                 assert len(obj) <= MAX_STRING_LEN
                 # marker, string length, string itself
                 imgstr += _U8_to_str(OBJ_TYPE_STR) + \
-                          _U8_to_str(len(obj)) + obj
+                          self._U16_to_str(len(obj)) + obj
 
             # if its an integer
             elif objtype == types.IntType:
 
 /**
  * The maximum size a chunk can be.
- * Must be less than 256 since uint8_t is used to keep its size.
- * Set to 252 so it is 4 less than 256.
- * This helps with alignment for targets that need aligned
- * pointers such as TARGET_DESKTOP and TARGET_ARM and it doesn't
- * harm other targets.
+ * The chunk size is limited by the od_size field in the object descriptor.
+ * Currently, that field is 8 bits.  Since the heap allocator already rounds
+ * requested chunk sizes up to the next multiple of four, the lower two bits
+ * are alway zero.  So, we can shift this adjusted size value to the right
+ * two places which allows larger effective sizes.
+ * The maximum size is now (2^10 - 1 == 1023), but it must be a multiple of
+ * four to maintain alignment on some 32-bit platforms, so it becomes 1020.
  */
-#define HEAP_MAX_CHUNK_SIZE 252
+#define HEAP_MAX_CHUNK_SIZE 1020
 
 /** The minimum size a chunk can be */
 #define HEAP_MIN_CHUNK_SIZE sizeof(PmHeapDesc_t)
  */
 static
 PmReturn_t
-heap_getChunkImpl(uint8_t size, uint8_t **r_pchunk)
+heap_getChunkImpl(uint16_t size, uint8_t **r_pchunk)
 {
     PmReturn_t retval;
     pPmHeapDesc_t pchunk1;
  * Obtains a chunk of at least the desired size.
  */
 PmReturn_t
-heap_getChunk(uint8_t size, uint8_t **r_pchunk)
+heap_getChunk(uint16_t requestedsize, uint8_t **r_pchunk)
 {
     PmReturn_t retval;
+    uint16_t adjustedsize;
 
     /* Ensure size request is valid */
-    C_ASSERT(size < HEAP_MAX_CHUNK_SIZE);
+    if (requestedsize > HEAP_MAX_CHUNK_SIZE)
+    {
+        PM_RAISE(retval, PM_RET_EX_MEM);
+        return retval;
+    }
 
-    if (size < HEAP_MIN_CHUNK_SIZE)
+    if (requestedsize < HEAP_MIN_CHUNK_SIZE)
     {
-        size = HEAP_MIN_CHUNK_SIZE;
+        requestedsize = HEAP_MIN_CHUNK_SIZE;
     }
 
     /*
      * have a like size.  This also creates discrete chunk sizes that may help
      * search for chunk sizes quickly (depending on the implementation).
      */
-    size = ((size + 3) & ~3);
+    adjustedsize = ((requestedsize + 3) & ~3);
 
     /* Attempt to get a chunk */
-    retval = heap_getChunkImpl(size, r_pchunk);
+    retval = heap_getChunkImpl(adjustedsize, r_pchunk);
 
     /* Ensure that the pointer is 4-byte aligned */
     C_ASSERT(((int)*r_pchunk & 3) == 0);
  * chunk's od.od_size.
  * Garbage will be collected if necessary.
  *
- * @param   size Size of the chunk in bytes.
+ * @param   requestedsize Requested size of the chunk in bytes.
  * @param   r_pchunk Addr of ptr to chunk (return).
  * @return  Return code
  */
-PmReturn_t heap_getChunk(uint8_t size, uint8_t **r_pchunk);
+PmReturn_t heap_getChunk(uint16_t requestedsize, uint8_t **r_pchunk);
 
 /**
  * Place the chunk back in the heap.
             pPmObj_t *r_pname)
 {
     PmType_t type;
-    uint8_t b;
+    uint16_t len;
     PmReturn_t retval;
 
     /* XXX ensure it's a tuple */
         /* skip type byte, assuming string */
         (*paddr)++;
         /* skip the length of the string */
-        b = mem_getByte(memspace, paddr);
-        (*paddr) += b;
+        len = mem_getWord(memspace, paddr);
+        (*paddr) += len;
     }
 
     /* ensure it's a string */
 #define OBJ_SET_GCVAL(obj, gcval) (obj).od.od_gcval = (gcval)
 #define OBJ_GET_GCFREE(obj) ((obj).od.od_gcfree)
 #define OBJ_SET_GCFREE(obj, free) ((obj).od.od_gcfree = (uint8_t)free)
-#define OBJ_GET_SIZE(obj) ((obj).od.od_size)
-#define OBJ_SET_SIZE(obj, size) (obj).od.od_size = (size)
+/* 
+ * od_size bits are shifted because size is a scaled value 
+ * True size is always a multiple of 4, so the lower two bits are ignored
+ * and two more significant bits are gained.
+ */
+#define OBJ_GET_SIZE(obj) ((obj).od.od_size << 2)
+#define OBJ_SET_SIZE(obj, size) (obj).od.od_size = (uint8_t)((size) >> 2)
 #define OBJ_GET_TYPE(obj) ((obj).od.od_type)
 #define OBJ_SET_TYPE(obj, type) (obj).od.od_type = (type)
 
               pPmObj_t * r_pstring)
 {
     PmReturn_t retval = PM_RET_OK;
-    uint8_t len = 0;
+    uint16_t len = 0;
     pPmString_t pstr = C_NULL;
     uint8_t *pdst = C_NULL;
 #if USE_STRING_CACHE
     else
     {
         /* get length of string */
-        len = mem_getByte(memspace, paddr);
+        len = mem_getWord(memspace, paddr);
     }
 
     /* get space for String obj */
 PmReturn_t
 string_print(pPmObj_t pstr, uint8_t marshall)
 {
-    uint8_t i;
+    uint16_t i;
     uint8_t ch;
     uint8_t nibble;
     PmReturn_t retval = PM_RET_OK;
     PmObjDesc_t od;
 
     /** length of string */
-    uint8_t length;
+    uint16_t length;
 
 #if USE_STRING_CACHE
     /** ptr to next string in cache */
  * If n is zero, load from a String image.
  *      A string image has the following structure:
  *          -type:      S8 - OBJ_TYPE_STRING
- *          -length:    U8 - number of bytes in the string
+ *          -length:    U16 - number of bytes in the string
  *          -string:    U8[] - array of chars with null term
  *
  * If n is not zero, create from a C string.
  * Constants
  **************************************************************/
 
+/* The follwing value should match that in pmImgCreator.py */
+#define MAX_TUPLE_LEN 253
+
+
 /***************************************************************
  * Macros
  **************************************************************/
     PmReturn_t retval = PM_RET_OK;
     uint16_t size = 0;
 
-    /* this size tuple not yet supported */
-    /* XXX for larger tuple, break into segments */
-    /* #99: Remove this restriction, let num items be determined by max chunk size */
-    if (n > 100)
+    /* Raise a SystemError for a Tuple that is too large */
+    if (n > MAX_TUPLE_LEN)
     {
         PM_RAISE(retval, PM_RET_EX_SYS);
         return retval;
         PM_RAISE(retval, PM_RET_EX_TYPE);
         return retval;
     }
-    
+
     plat_putByte('(');
-    
+
     for (index = 0; index < ((pPmTuple_t)ptup)->length; index++)
     {
         if (index != 0)