Jump to content
Sign in to follow this  
John P

Jump Table Not Accepted

Recommended Posts

I'm trying to convert a program from another compiler, and I have got it to compile under BoostC. But the program includes a jump table which is entered after the PCL is changed--a computed GOTO in other words. What I'm finding is that the compiler simply generates no code for any of the GOTO statements, then it resumes at the next address after the last GOTO. Here are the last few lines before the table and the first few lines of the table:

 

   bit_set(porta, 1);	// A flag for the scope, to see how long this takes
   pclath = 1;
   pcl += bitc;     // Computed GOTO: jump 0-179 lines ahead
       // NOTE! This jump table must not span a location in code memory where the lower 8 address bits wrap from 0xFF to 0x00.
       // Also, PCLATH must hold the correct value for the memory area being used.
   goto SW0;				// Start bit, start char
   goto INCU;
   goto SW2;
   goto QX;
   goto SW2;
   goto QX;
   goto SW2;        // Many more GOTO's here

 

Any ideas on how to make the compiler accept this?

Share this post


Link to post
Share on other sites

John P,

 

I'm trying to convert a program from another compiler, and I have got it to compile under BoostC. But the program includes a jump table which is entered after the PCL is changed--a computed GOTO in other words. What I'm finding is that the compiler simply generates no code for any of the GOTO statements, then it resumes at the next address after the last GOTO. Here are the last few lines before the table and the first few lines of the table:

 

bit_set(porta, 1);	// A flag for the scope, to see how long this takes
pclath = 1;
pcl += bitc;	 // Computed GOTO: jump 0-179 lines ahead
	// NOTE! This jump table must not span a location in code memory where the lower 8 address bits wrap from 0xFF to 0x00.
	// Also, PCLATH must hold the correct value for the memory area being used.
goto SW0;				// Start bit, start char
goto INCU;
goto SW2;
goto QX;
goto SW2;
goto QX;
goto SW2;		// Many more GOTO's here

 

Any ideas on how to make the compiler accept this?

We had a few problems reported regarding this kind of issue a few months back.

A number of changes have been made to fix this problem, but a fully controlled release with these fixes in has not been created.

 

You can find a pre-release version here (this link wont be valid after BoostC V7.11 is released):

http://www.sourceboo...oost711pre1.exe

 

Let us know if this fixes your issues.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave. Thanks for the prompt response.

 

I did download 7.11, and I was all set to report back that it didn't make any difference. But it's more interesting than that. It still won't compile my block of GOTO's. But then I tried a workaround that failed with the previous version (I have 7.05). And that seems likely to work. What I did was take some of the jump table and put it in an asm{} block, like this:

 

bit_set(porta, 1);	// A flag for the scope, to see how long this takes
pclath = 1;
pcl += bitc;		// Computed GOTO: jump 0-179 lines ahead
      // NOTE! This jump table must not span a location in code memory where the lower 8 address bits wrap from 0xFF to 0x00
      // Also, PCLATH must hold the correct value for the memory area being used.
asm{
GOTO SW0
GOTO INCU
goto SW2
 	goto QX
}

 goto SW0;                // Start bit, start char
 goto INCU;
 goto SW2;
 goto QX;

 

With 7.05, this fails with

"Internal Error: Unable to resolve label ID:268436043 - 0x1000024B

failure

BUILD SUCCEEDED: Sun Nov 25 11:18:23 2012"

 

Why it says "failure" followed by "BUILD SUCCEEDED" is probably not worth pursuing. But with 7.11, it produces code, as seen in the disassembly listing (and you can also see that the GOTO's that aren't in the asm{} block produce no code):

 

497:               	bit_set(porta, 1);				// A flag for the scope, to see how long this takes
 0242    1485     BSF 0x5, 0x1
498:               	pclath = 1;
 0243    3001     MOVLW 0x1
 0244    008A     MOVWF 0xa
499:               	pcl += bitc;					// Computed GOTO: jump 0-179 lines ahead
 0245    0866     MOVF 0x66, W
 0246    0782     ADDWF 0x2, F
500:     // NOTE! This jump table must not span a location in code memory where the lower 8 address bits wrap from 0xFF to 0x00.
501:     // Also, PCLATH must hold the correct value for the memory area being used.
502:               asm{
503:               	GOTO SW0
 0247    2A4B     GOTO 0x24b
504:               	GOTO INCU
 0248    2AA0     GOTO 0x2a0
505:               	goto SW2
 0249    2A53     GOTO 0x253
506:                 	goto QX
507:               }
 024A    2ABA     GOTO 0x2ba
508:               
509:                 goto SW0;				// Start bit, start char
510:                 goto INCU;
511:                 goto SW2;
512:                 goto QX;

Share this post


Link to post
Share on other sites

John,

What I did was take some of the jump table and put it in an asm{} block...

The jump table needs to be done in ASM otherwise you are making assumption about the code that compiler/linker will generate and what optimisation may or may not be performed and that is somewhat dangerous.

 

I would also recommend fixing the address of the function (see below) containing the jump table to prevent linker placing it somewhere where it may cross a code page boundary.

 

// fix function address
void foo() @0x1230
{
   ...
}

 

Regards

Dave

Share this post


Link to post
Share on other sites

I'll stick with the assembly language block then. And thanks for the reminder about fixing the function address. That's definitely needed with the way I've written this.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...