Hi,
I'm using the keil to compile a project for the 8051.
I want to place a single function in a specific address in the rom.
I found a lot of answers, in the forum, but non of them actually worked.
How can i "tell" the keil that the specific function MUST be at address 0x1234, for example? if it helps, the function is written in a seperate file. Thanks, Noam
Life isn't that simple.
To get a fixed function to place in RAM, you must recompile.
But when you recompile, the original space for the buggy function will be reused by other functions in the recompiled binary.
Your new - fixed - function that you place in RAM, will try to access functions in ROM based on the new compilation - not the original compilation. But since you haven't reporgrammed the ROM, all references from the RAM function must also be redirected. However, they can't simply be redirected to absolute locations, but be remapped to the original location in the original ROM image.
How many redirects can your dedicated hardware support? You should be ok if you can handle maybe 10 - 100 redirects, but you have to retrieve the redirects from the map file. And you may be more or less dead if the references are not to the entry points of functions.
Remember that if the compiler/linker is smart, it may locate common function tails, and let one function jump into the middle of another function just to process the last instructions.
What happens if any function tries to jump into the middle of this modified function, expecting to find an identical tail?
Andy, the size of the RAM is 10 times smaller than the ROM (as you probably know, ROM consume significantly smaller space - this is the only reason to use it from the first place). The RAM's purpose is to fix bugs in specific functions.
Per, do you think that, assuming I didn't change anything in the original code and assuming I didn't add additional variables in the fixed function (the code with the bug). The only thing I would do is to add additional function that will placed in 0xa000. Do you think it will change the compilation of the original code? the fixed code and the original code are not even in the same address space, why should it change the compilation of the original code?
I want to give it a try. do you know how can i place the fixed function in a specific location (0xa000)?
"this is the only reason to use it from the first place"
No, in general it's not the only reason - the other reason is that it's non-volatile!
In general, for test/debug purposes, you would remove the ROM and replace it with RAM or a "ROM Emulator" or somesuch.
"do you know how can i place the fixed function in a specific location (0xa000)?"
What have you tried so far? In what way(s) did that "not work"?
Sorry, but the only way you could have enough information about the linking process is if you have access to the full source code to the Keil linker.
You may affect the call-tree optimization. You may affect the mapping from auto variables to global variables. You may affect tail optimizations. You may change the location of other functions that your recompiled function calls back to.
Another thing. You say your RAM is only one tenth the size of the ROM. How can that be? For your address translation logic to work, it must be able to see ALL code addresses. If both the ROM and RAM memory areas are external, the solution is obviously to build a prototype with just RAM, instead of building a circuit where you have ROM from 0 to 0x9fff. If the address range 0 to 0x9fff happens to be internal to the chip, you will not have any addresses to translate.
The last sentence should have been:
If the address range 0 to 0x9fff happens to be internal to the chip, you will not have any addresses to translate, unless you bought your "chip" as VHDL code and are able to redefine internal functions of the processor.
per, it's a bit difficult to explain, but in a nutshell there is a register that holds an address in the ROM. this address is the first address of the bugged function. Once the h/w recognize that the RISC got to the bugged function jumps to the first address in the RAM. in the end of the fixed function in the RAM there is a jump to the last address of the bugged function in the ROM. Therefore you don't need the RAM to be as large as the ROM. So, anyone has any idea how to place a function in a specific address in the ROM?
So, anyone has any idea how to place a function in a specific address in the ROM?
You still haven't described what you have already tried and why it did not work.
You can use the linker to locate segments and functions at certain memory locations. How to do this can be found in the documentation of the linker you are using (BL51 or LX51), for example
http://www.keil.com/support/man/docs/bl51/bl51_code.htm
"it's a bit difficult to explain, but in a nutshell there is a register that holds an address in the ROM. this address is the first address of the bugged function."
Is this a custom design in ASIC or FPGA or something?
Thank you very much. the kink that you sent me worked. I still didn't come to conclusion what happens to the original code.
yes, and the link above proved to work fine!
Noam, Per mentioned a very good point. If you recompile, you (possibly) lose all reference. But maybe you can prevent that by filling in the gaps: The C167 processor a special linker directive (I think it is called "RESERVE" by the Tasking linker) that reserves pieces of memory. If you can somehow use that thing, maybe your memory map will not change. But this has, of course, serious limitations.
The C51 linker also has a RESERVE directive that you can use to block address ranges from being used.