Jump to content
Sign in to follow this  
winterhunter

Forcing A Long Jump At The Beginning Of The Progra

Recommended Posts

Hi,

 

I'm new to sourceboost (just bought a full licence for 6.6) and wanted to use the programs I'm writing with a bootloader, since my poor PIC's pins will not last much longer if I continue swapping it between my proto board and the programmer!

 

The problem I've been experiencing is that:

+ The bootloader that is on sourceboost's webpage needs hyperterminal, which I don't have (I'm running Vista). Besides, it does not support the A version of the 16F877 chip, and I I don't want to modify it to write groups of four instructions at once (I'm lazy, I know).

+ A bootloader that works nicely, and does not take much ROM can be found on the following website :

MicrochipC bootloader

However, it requires that the that the jump before the interrupt vector be a long jump (if possible also clearing the status field, just in case).

 

How can I force BoostC to do this? (Of course I could force the linker by rellocating my program to the second memory page with the -rb option, but that would be to just WASTE the first 2kwords of ROM).

 

Thanks for your answers!

Share this post


Link to post
Share on other sites

winterhunter,

 

However, it requires that the that the jump before the interrupt vector be a long jump (if possible also clearing the status field, just in case).

Please clarify further. Maybe you can post some asm that shows what low memory has got in it.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Please clarify further. Maybe you can post some asm that shows what low memory has got in it.

 

Regards

Dave

 

Most bootloaders, because of the way they are designed, need that the first 4 instructions of any program that can be uploaded be :

 

 

Address Instruction

0000 clrf STATUS

0001 movlw 0x00 // these instructions can be

0002 movwf PCLATH //replaced by a clrf PCLATH

0003 goto start

0004 beginning of interrupt vector

.....

 

since they will replace the 4 first intructions with a hook to the bootloader, and move the program's first 4 instructions (between physical adresses 0000-0003 to the top of the memory).

 

BoostC gives me

0000 goto Start

0001 unused

0002 unused

0003 unused

0004 beginning of interrupt vector

 

so it is a short jump.

 

Since this instruction will be relocated by the bootloader to another code page, the short jump will not lead to the execution of the program, but to random operation.

 

So the question is: is there any way to force BoostC to create a long jump at the beginning of the program, so even if the instruction is relocated it will lead to the main() function?

 

Thanks!

Share this post


Link to post
Share on other sites

winterhunter,

 

So the question is: is there any way to force BoostC to create a long jump at the beginning of the program, so even if the instruction is relocated it will lead to the main() function?

 

Thanks!

What about relocating code by:

1) use linker -rb option by a few locations, say 0x010

2) Use #pragama DATA 0x000, xxx, xxx, xxx ... to place some opcodes at address 0x000 with the required jump to the new offsetted start (0x010).

 

Rember that interrupt vector will also need patching to 0x010+ address.

 

Regards

Dave

Share this post


Link to post
Share on other sites
What about relocating code by:

1) use linker -rb option by a few locations, say 0x010

2) Use #pragama DATA 0x000, xxx, xxx, xxx ... to place some opcodes at address 0x000 with the required jump to the new offsetted start (0x010).

 

Rember that interrupt vector will also need patching to 0x010+ address.

 

Regards

Dave

 

I have no way to know where the main() function will end up in memory, so I cannot place a jump to it.

 

Is there no other way (a better one) to do this? If not, how do I request this feature for a next release?

 

Thanks,

 

Gonzalo Meza

Share this post


Link to post
Share on other sites
Thanks, I've already tried it, but if I read the doc correctly, it can't write to EEPROM on 16Fs, right?

 

There are a few 16F's that can self program. For example, 16F88 works, but 16F628 does not work.

 

Jake

Share this post


Link to post
Share on other sites
What about relocating code by:

1) use linker -rb option by a few locations, say 0x010

2) Use #pragama DATA 0x000, xxx, xxx, xxx ... to place some opcodes at address 0x000 with the required jump to the new offsetted start (0x010).

 

Rember that interrupt vector will also need patching to 0x010+ address.

 

Regards

Dave

 

I have no way to know where the main() function will end up in memory, so I cannot place a jump to it.

 

Is there no other way (a better one) to do this? If not, how do I request this feature for a next release?

 

Thanks,

 

Gonzalo Meza

 

Hi Gonzalo;

 

You don't need to know where the main() function is. All you need to know is where the reset and interrupt vector table moves to when you use the -rb linker option.

 

Here's what worked for me:

Set the linker option:

 

-rb 5

 

to move all the code up in ROM space by 5 bytes.

 

Then at the top of your program, before including <system.h> add the following two lines:

 

#pragma DATA 0x00, 0x2805

#pragma DATA 0x04, 0x2809

 

These are jump statements, that get located at address 0 and 4 in ROM, that point to the reset and interrupt vector table that got moved by the -rb linker option.

 

The bootloader will find these two jump statements when you download your hex file, and relocate them wherever it needs to.

 

Regards;

Steve B.

Share this post


Link to post
Share on other sites

;)-->

QUOTE(Steve B @ Sep 30 2007, 04:57 PM) <{POST_SNAPBACK}>
What about relocating code by:

1) use linker -rb option by a few locations, say 0x010

2) Use #pragama DATA 0x000, xxx, xxx, xxx ... to place some opcodes at address 0x000 with the required jump to the new offsetted start (0x010).

 

Rember that interrupt vector will also need patching to 0x010+ address.

 

Regards

Dave

 

I have no way to know where the main() function will end up in memory, so I cannot place a jump to it.

 

Is there no other way (a better one) to do this? If not, how do I request this feature for a next release?

 

Thanks,

 

Gonzalo Meza

 

Hi Gonzalo;

 

You don't need to know where the main() function is. All you need to know is where the reset and interrupt vector table moves to when you use the -rb linker option.

 

Here's what worked for me:

Set the linker option:

 

-rb 5

 

to move all the code up in ROM space by 5 bytes.

 

Then at the top of your program, before including <system.h> add the following two lines:

 

#pragma DATA 0x00, 0x2805

#pragma DATA 0x04, 0x2809

 

These are jump statements, that get located at address 0 and 4 in ROM, that point to the reset and interrupt vector table that got moved by the -rb linker option.

 

The bootloader will find these two jump statements when you download your hex file, and relocate them wherever it needs to.

 

Regards;

Steve B.

 

Steve,

 

This worked great for sparkfun's Screamer bootloader as well. Great tip!!

 

 

Thank you :)

 

Bill G.

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...