objects conflicting
jstjohnz
Posts: 91
in Propeller 1
It's late, I'm punchy, so this may not be terribly coherent.
I'll try to be brief. I am seeing some sort of weird conflict between 2 objects. I have 2 objects that start a cog and run some PASM code. It started out as a single object, but I just didn't have room to cram all of the PASM into one cog, so I split the code into 2 separate objects.
At least half of the PASM is identical between the 2 objects. The idea is to load one object or the other depending on what hardware needs to be controlled.
Here's the rub. If I just define one object in the OBJ section of my SPIN code, and start that object, all is well. But, as soon as I even define the 2nd object in the OBJ block, without ever even referring to it anywhere else, the first object starts acting flaky.
I know from past experience that the Propeller Tool loads all defined objects even if they are never used, so I get that it's loading the 2nd PASM object even though I don't actually use it. But for some reason, just loading that 2nd object is corrupting the first object.
I assume that I am doing something stupid and somehow I'm inadvertently creating a situation where the compiler is sharing some code or data between the 2 objects but like I say it's late and my brain isn't functioning well.
I'll try to be brief. I am seeing some sort of weird conflict between 2 objects. I have 2 objects that start a cog and run some PASM code. It started out as a single object, but I just didn't have room to cram all of the PASM into one cog, so I split the code into 2 separate objects.
At least half of the PASM is identical between the 2 objects. The idea is to load one object or the other depending on what hardware needs to be controlled.
Here's the rub. If I just define one object in the OBJ section of my SPIN code, and start that object, all is well. But, as soon as I even define the 2nd object in the OBJ block, without ever even referring to it anywhere else, the first object starts acting flaky.
I know from past experience that the Propeller Tool loads all defined objects even if they are never used, so I get that it's loading the 2nd PASM object even though I don't actually use it. But for some reason, just loading that 2nd object is corrupting the first object.
I assume that I am doing something stupid and somehow I'm inadvertently creating a situation where the compiler is sharing some code or data between the 2 objects but like I say it's late and my brain isn't functioning well.
Comments
The 2 objects in question are 100% PASM code, except for the standard START and STOP procedures at the head:
VAR
long cog
long _clkmskptr
PUB Start(clkmskptr) : okay
_clkmskptr:=clkmskptr
okay := cog := cognew(@entry, _clkmskptr) + 1
PUB Stop
' Stop Pixel Driver, frees cog
if cog
cogstop(cog~ - 1)
DAT
org 0
'everything above this line is identical in the 2 objects, 'as is a significant part of the PASM code.
<<pasm code>>
I'm thinking that this is an errant spin write, possibly an array index out of bounds.
I did try a couple of things. I created a dummy object with the exact same structure and length as the object that's causing the problem. Just a series of "LONG 1" commands in the DAT block to force it to the proper length. Referencing this dummy object in the OBJ block instead of the real object caused the problem to disappear. I found that a bit surprising since everything should have been in the same locations in memory.
I also discovered that simply swapping the order of the 2 statements in the OBJ block also causes the problem to disappear. At least it's not showing itself in an obvious way. I don't mean to imply that this is a fix.
I do have one web page form that's acting strangely, I think I will look into that spin code as it may be related.
If you have plenty of space then the issue is somewhere else (obviously).
As others have suggested, attaching an archive of the program would let us take a look at it.
What sort of pointer is passed to the Start method? If "clkmskptr" points to anything other than a long address (or at least a long aligned address), then this is likely causing the problem.
I will try to pin this down a bit more. I know it's difficult to work with what I've given you.
To summarize, if I have:
OBJ
object1: "firstobject.spin"
object2: "secondobject.spin"
then object2 fails to run properly even if object1 is never referenced in the spin code.
If I have:
OBJ
object2: "secondobject.spin"
object1: "firstobject.spin"
then everything appears to work properly.
The only difference is where objects 1 and 2 reside in hub ram. I think I need to focus on the SPIN code that executes before those objects are loaded. I suspect that in the first scenario object2 is being corrupted before it is started in a cog.
If you can't post your code then I would suggest adding debug prints in your code to determine where the program stops working. This should give you an idea of where the failure is occurring.
Appreciate all of the help.