This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

putting a function in a specific address in ROM

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

  • Why do you not start by telling why you want your function located at a fixed location?

    A lot of people why try to place a function at an absolute location tries this without really needing it!

  • "A lot of people why try to place a function at an absolute location tries this without really needing it!"

    Very true!

    But, even if you are one of the rare cases where it really is necessary, people still need to know the reason in order to give appropriate suggestions.

    Some possible approaches may not be appropriate to your specific requirements - which may also be why what you've tried so far hasn't "worked".

    It'd also be helpful if you explained what you'd tried and why (you think) it didn't "work"...

    As ever, the more effort you put into giving a complete question, the more likely you are to get a useful answer!

  • The reason why i need it is:
    The compiled code is be placed in a ROM.
    Fixing bugs will be done by fixing the bugged function in a RAM (and dedicated hardware will make sure to bring data from the RAM instead of the ROM when approaching the bugged function).
    This RAM is located in address 0xa000 (the ROM's address space is from 0x0000 to 0x9fff).
    I need to recompile the original code (with the bugged function) but to add to it a fixed function that is written in C (that MUST be placed in address 0xa000).

    This is the reson why i need to place a certain function in a specific address.
    BR,
    Noam

  • Wouldn't it be easier just to have the entire code in RAM for debugging?

    The more "special cases" you have to make just to debug, the less representative your debugging becomes!

    This was the whole point of the "ROM Emulator" concept...

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