I'm trying to locate the INIT.A51 code in a specific spot and I cannot figure out how to do it. I can locate STARTUP.A51 where I want it by added this to the BL51 tab in UV2: ?C_C51STARTUP(2000h) It does locate there as expected, but then in that code there is this asm instruction towards the end of the file: LJMP ?C_START which jumps to the file INIT.A51 (which eventually jumps to MAIN) The order of the code in memory is roughly like this: C_C51STARTUP MAIN C_START Every time I edit the size of MAIN(), the address of C_START changes. I need them to be in this order: C_C51STARTUP C_START MAIN so the two assembly files are next to each other and before MAIN(). How can I do that? I've looked at the map file and I don't even see the starting address for C_START.
Why is this important to you? I'm afraid I can't answer your actual question, but if you tell us your reason/requirement, someone may be able to suggest an alternative approach.
Ok, If I have to spell it out I suppose I will. I have a Cypress AN2131 system and I need to run code from flash ROM. I also need to be able to update the flash ROM in the field through a 'serial' port. There is about 6KB of RAM internal to the device. There are two basic modes of this part EA=1, and EA=0. If EA=1, then ALL PM space is external. If EA=0, then the internal RAM can be used for PM or DM space. I need to use this internal RAM to execute flash updating code on the external flash ROM. I cannot run code in the internal RAM if EA=1. Therefore, I must run with EA=0. However, with EA=0 I cannot boot from the flash ROM, so I'm booting from a serial EEPROM instead. I want to locate the startup code (the two A51 files mentioned in the start of this thread) and my main function in a known spot and never have it move. My main function will basically contain some code that will never change and it basically will jump into the "main" system code. I can't have any of this move around because I'm soft protecting an area of the flash. So, can you tell me how to locate the INIT.A51? I played around last night with the order of the files in the project. If I put INIT.A51 right after STARTUP.A51 it 'seems' to work, but am I guaranteed it will always work?
The startup code STARTUP.A51 and the initialization code INIT.A51 are both stored in the same segment (?C_C51STARTUP). The C_START is a label used in the initialization code. However, C_START is a label and not a segment. That's why you can't locate it to a different address. If the STARTUP.OBJ and INIT.OBJ files are not linked together, the linker MAY be locating them non-contiguously. Have you tried including both files in your project one right after the other? I created a simple program:
unsigned char bigbuf [] = "This is a test"; void main (void) { }
* * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE 0003H 3FFDH *** GAP *** CODE 4000H 008CH UNIT ?C_C51STARTUP CODE 408CH 0012H UNIT ?C_INITSEG CODE 409EH 0001H UNIT ?PR?MAIN?MAIN
Well the thing you mentioned I guess is my only hope: "including both files in your project one right after the other." By keeping STARTUP.A51 and INIT.A51 next to each other in the project source group list, it seems to be working ok. When they were separated in th list, they located around my main code instead of before it. Thanks.
In the linker, you can use the CODE directive to specify the location & order of segments in the program. See Chapter 1 of the 8051 Utilities manual. This gives an explanation and examples. Then you don't have to rely on the order of files in uVision.