Skip to content

Debugging – Just Shoot Me

June 8, 2017

I came back to the 1806 olduino after a break and encountered a bug that has me scratching my head.  I’m using something I call the fakeloader to emulate 1802 load mode on the 1806.   fakeloader.c gets compiled to low memory and looks to the AVR external loader like an 1802’s load mode. Fakeloader loads the code from the external loader to location 0x800 and runs it from there.   The AVR external loader does actually know what’s going on, If it sees code compiled for location 0 it puts the 1802 in load mode as usual; if it sees code compiled for a different address it puts the processor in RUN and counts on the fakeloader.

I had a little test program called hellofromtheotherside.c that i would run that could report where it was loaded and what kind of processor it was compiled for.  The trouble was it didn’t work! I could run almost anything compiling it for location 0x800 and loading it via the fakeloader but not hellofromtheotherside.  After much dinking around my simplest fail/no-fail case involves code that is never executed! The test case is below, In the function dump(which is never executed!) there’s a for loop.  I can make it fail or run depending on whether there are a couple of print statements inside the for loop or not.  Although the code is never executed, the version with the print statements inside the loop compiles to more code and ALTHOUGH THAT CODE IS NEVER EXECUTED it seems to load to low memory being overwritten as well as simply not printing. The version below is the one that fails. If I were to close out the for loop on the 12th(**A) line and comment out the } on the 15th line(**B) it would work.

Obviously, everything after dump() including main() and the library routines are in slightly different locations but I don’t know what’s leading to the failure. cr*p.

void fun(int i){}
int bar(int s,int b,int c){
	int local=42;
	return local+c;
}
#include <nstdlib.h>
#include <cpu1802spd4port7.h>
#define putc(x) out(7,x)
void dump(unsigned char* data, unsigned int len){
	unsigned int i=0;
	printf("dumping %d bytes at %x",len,data);
	for(i=0;i<len;i++){//}//**A
		if (0==(i%8)) printf("\n%x ",data);
		printf("%cx ",*data++);
	}//**B
	printf("\n");
}
void main()
{
	char* dummy=(void*) &fun;
	printf("Hello World!9!\n");
}
#include <nstdlib.c>

UPDATE:
The failing case, with the printfs outside the loop body generates LESS code than the working case(because the compiler puts i in a register). I stuck enough db’s in the bottom of dump to move main to the same place and it suddenly works! Moving them down to above the nstdlib include also works. Moving them down to below the nstdlib include also works. So something in the epilog is getting b*ggered.

Further diddling by taking out filler I can get it to work with 2 bytes of filler or fail with 1. In the guts of the epilog it works with lcc1802init: at 15EC and fails when it’s at 15E8. In any case, by the time it gets to the call routine it will be the same because there’s an align 256 that brings it to 0x1700 in either case. I give up for now.

Also, I’ve been assuming this won’t fail in the emulator but don’t really know that. worth a try tomorrow.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: