CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Placing code at location 0

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Josh_AB



Joined: 15 Jan 2004
Posts: 2

View user's profile Send private message

Placing code at location 0
PostPosted: Wed Feb 25, 2004 6:07 pm     Reply with quote

I'm working with an 18F6520 and it has a protected bootblock from 0x0000 to 0x0800 so I'm working at placing a boot loader in this region. I know this has been discussed repeatedly but so far I haven't seen this problem addressed. While I'm able to relocate the reset vector using the #build directive any code I try to put in it's place by #org 0x0000, 0x0007 does not generate code.

Here is simplified example code:
Code:

#include <18F6520.h>

#build(reset=0x0800)


#org 0x0000, 0x0007                  //RESET VECTOR---GOES TO BOOTLOADER
void MY_RESET(void)
{
#asm
   goto 0x0018                     //BOOTLOADER LOCATION
#endasm   
}

#org 0x0018,0x07FF
void MY_BOOTLOADER(void)
{
#asm
   goto 0x0800                     //BOOTLOADER--STUB--FOR NOW ASSUME ALL
                              //IS GOOD AND JUST GO TO RELOCATED
                              //RESET VECTOR
#endasm
}



void main()
{
   int i;
   while(1)i++;   
}


Complied as above no code is generated for MY_RESET but all other functions generate code as expected. My compiler is version PCH 3.182.

If I change the code so that MY_RESET is org'ed to the range 0x0002 to 0x0007 it will generate code for the function but leaves address 0x0000 free. By default it places a nop there which would be fine except when I'm actually working on the project any function stub ends up being placed there so it then becomes a retlw 0 (very bad!).

Any help would be greatly appreciated. Thanks for your time.

Josh
Paul Routlley
Guest







Need a redundant call to generate code
PostPosted: Mon Sep 13, 2004 9:11 am     Reply with quote

I had a similar problem.
Try adding a call to MY_RESET() and MT_BOOTLOADER() at the end of main
(The code does not have to be reachable).
Without this the optimiser removes the code it thinks is unused!
Josh_AB



Joined: 15 Jan 2004
Posts: 2

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 11:28 am     Reply with quote

Thanks for the suggestion but it doesn't seem to fix my problem (given my version of the compiler etc.) With or without the calls it works if I place the code at adress 2 and it fails(silently of course) if I place it at address 0.

Josh
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 12:25 pm     Reply with quote

In my notes on this topic, I have the following code.
It just shows how we worked around the problem.

Code:
// We can't org our reset_vector() function at 0x0000. 
// So we org it at 0x0002 instead, and put a NOP at 0.
#org 0,1 {}   // Reserve ROM word 0
#ROM 0 = {0}  // Then put a NOP there

#org 2, NEW_RESET_VECTOR-1     // Reserve the entire 512-byte boot block
void reset_vector(void)
{
#asm
GOTO BOOT_SEGMENT_START       // This code is at address 0x0002
NOP                           // The nop forces next line to be at 0x0008
GOTO NEW_INTERRUPT_VECTOR     // This code is at address 0x0008
#endasm
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group