I'd like to reposition my code so all code starts at 0800h. The only things I want below that are the startup vector and interrupt vectors. Am I right in assuming that the vector at locn 0000 (actually an LJMP address) cannot be relocated as this is the start point after a reset? Is it also true that the interrupt vectors are similarly fixed? Using uVision.
if you relocate the vectors to, say, 0x800 there will/must be in location 0 be a ljmp 0x800.
Erik
Erik; Please read the app note. You will see that an entry (x0000) in startup.a51 will contain an LJMP to the location defined either in startup.a51 or at the location the user can define in the uVision IDE. In both cases it will result in creating a new vector jump table and setting the reset LJMP destination location. Bradford
Sorry! Can't type hex correctly. Should be 0x0000.
Bradford
Thanks for that. A useful document. I actually need to have two pieces of code, one (main) piece starting at (e.g) $1000 and the other starting at $0080. I'm using an Atmel 89C51RC2 flash based device and I'm seeing some product returned with the first half page of Flash (0000 to 007F) corrupted to FF. I've determined that this is probably due to poor power supply management. A solution would require some hardware modification which will happen at the next cycle of product review but I need to find a software solution for now. I thought that if I put a piece of code at $0080 (immediately after the area that I've seen corrupted) which rewrites the vectors at the bottom of page zero I can recover the situation. I already use the 'write to flash' routines built into the RC2. 'FF' is a benign instruction which sets up one of the registers so I recon that when the processor starts running from 0000 it will eventually hit the code at $0080, correct the corrupt flash and restart itself. An uncorrupted chip will never see the extra code as it will have a correct reset vector taking it to (e.g) $1000. Does this sound plausible (or possibly naive)?
I've determined that this is probably due to poor power supply management more likely the abscence of a supervisor chip.
Please read the app note. You will see that an entry (x0000) in startup.a51 will contain an LJMP to the location defined either in startup.a51 or at the location the user can define in the uVision IDE. In both cases it will result in creating a new vector jump table and setting the reset LJMP destination location. of course, it does. But that is NOT what I refer to. If you locate the vector table anywhere but at 0.... there will STILL be a (call it a 'shadow') vector table at 0x00 .....
there have been several posts in the past that assumed that relocating the vector table actually relocated it, i.e. power on would not affect address 0x0000
Thanks for all the comments. I have so far not got the code relocated and all vectors produced in zero page. I have changed the CSEG AT 0 in STARTUP.A51 to CSEG AT 1000h. Also set the Code Address in the linker to $1000. This produces the correct interrupt vectors in zero page pointing within code that starts at $1000. BUT the reset vector is at $1000 and points to code at $1003. It is not placed in zero page! How do I achieve this?
I have tried this from the Knowledgebase http://www.keil.com/support/docs/76.htm But I used $1000 as my code start address. This produced a reset vector at $1000, Interrupt vectors from $1003 and code after the int vectors. I figured I didn't need the interrupt vectors relocated to set the interrupt vector offset back to zero. This produced a reset vector at $1000, interrupt vectors at $0003 and code at $1003 (after reset vector.) I have played around with the C51 and BL51 options and cannot get ALL vectors in zero page and code from $1000. The only way I have found of achieving this is by setting CSEG AT 0 in STARTUP and location the code at $1000 in the BL51 size/location. This doesn't seem right to me. I have yet to test it as I don't have my programmer at the moment.
the easy way would be to get another PC (trying this on a PC with licenced Keil may/will get you in trouble) and download the Keil software in eval mode. Everything will have the vectors relocated to 0x800
CSEG at XXXX in the startup code specifies where the reset and interrupt vectors are located (relative to XXXX). So, CSEG at 0000h locates the reset vector at 0000h, interrupt 0 at 0003h, interrupt 1 at 000Bh, and so on. These are ABSOLUTE segments that are located at absolute (physical) addresses.
The CODE linker directive specifies where to start locating the RELOCATABLE code (the stuff generated by the compiler and from the library files). So, if you specify CODE(0x1000) the linker will put all of the relocatable code segments starting up at 1000h.
If you look inside the STARTUP.A51 file you'll find that the "startup code" that's in there is placed in a relocatable segment most likely with an RSEG (from what I recall). That code will get lumped in with all the other relocatable code and stored up at 1000h.
Hopefully, these tips help. I think I got it all correct.
Jon Ward