ccbuluo / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

Heap initialization error with unaligned pointers on platform with 64-bit words #213

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile embedded binary
2. start platform

What is the expected output? What do you see instead?

Expected: no output, waiting for ipm to connect
Observed: "Address range crosses over cache line boundary" in 
heap_linkToFreelist as reported by the platform debugger.

What version of the product are you using? On what operating system?

latest "default" tip from repository, compiled to a new target for an 
experimental chip (not public)

Please provide any additional information below.

This chip has 64-bit words but does not support unaligned accesses. The problem 
can be fixed with the following patch:

diff -r f78fd6e58def src/vm/heap.c
--- a/src/vm/heap.c     Wed Jun 29 22:15:35 2011 -0500
+++ b/src/vm/heap.c     Mon Aug 29 12:06:36 2011 +0200
@@ -39,7 +39,7 @@
  * descriptor.  That field is nine bits with two assumed lsbs (zeros):
  * (0x1FF << 2) == 2044
  */
-#define HEAP_MAX_LIVE_CHUNK_SIZE 2044
+#define HEAP_MAX_LIVE_CHUNK_SIZE 2040 // ensure that all chunks have a size 
multiple of 8

 /**
  * The maximum size a free chunk can be (a free chunk is one that is not in use).
@@ -47,10 +47,10 @@
  * That field is fourteen bits with two assumed least significant bits (zeros):
  * (0x3FFF << 2) == 65532
  */
-#define HEAP_MAX_FREE_CHUNK_SIZE 65532
+#define HEAP_MAX_FREE_CHUNK_SIZE 65528 // ensure that the initial chunks have 
a size multiple of 8

 /** The minimum size a chunk can be (rounded up to a multiple of 4) */
-#define HEAP_MIN_CHUNK_SIZE ((sizeof(PmHeapDesc_t) + 3) & ~3)
+#define HEAP_MIN_CHUNK_SIZE ((sizeof(PmHeapDesc_t) + 7) & ~7)  // ensure 
multiple of 8

Maybe these values should be conditionalized on the newly added 
PM_PLAT_POINTER_SIZE? However I am not sure.

Original issue reported on code.google.com by k...@vodka-pomme.net on 29 Aug 2011 at 10:09

GoogleCodeExporter commented 9 years ago
Applied these suggested changes as a part of Issue 217 (default branch 
changeset rd4ed0d6d7146 and v10 branch changeset r45ec6cf29a5f).

Original comment by dwhall...@gmail.com on 30 Nov 2011 at 1:51