• AVR Freaks

Hot!Can't locate an object in program memory with restricted rom range

Author
jswanson
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2003/11/07 12:44:05
  • Status: offline
2019/06/18 02:22:31 (permalink)
0

Can't locate an object in program memory with restricted rom range

Hi,
 
XC8 PRO 2.05 (C99),  PIC18F26K83.
 
I'm trying to locate an object in program memory using the example from the user guide:

const int settings[] __at(0x200) = { 1, 5, 10, 50, 100 };

 
This works OK, but when I restrict the ROM ranges in the linker to 0-0FFF, I get the following error:

:0:: error: (500) undefined symbols:
__mediumconst(dist/default/production\I2C_Bootloader.X.production.o) __smallconst(dist/default/production\I2C_Bootloader.X.production.o)
(908) exit status = 1

 
It is a bootloader that is loaded into another project, so I need to restrict the range.
 
Any ideas why this is?
 
Jeremy.
#1

16 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3170
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 05:05:50 (permalink)
    -1 (1)
    It's maybe a bit late to restrict the memory range in the linker.
    I'd suggest to start with restricting the memory range for the compiler!

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 05:12:40 (permalink)
    +1 (1)
    Except that it is the linker that decides where to put things in memory, not the compiler!
    #3
    du00000001
    Just Some Member
    • Total Posts : 3170
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 06:43:07 (permalink)
    0
    Oh yeah. With all that you know: why do you think you have these issues ?  wink: wink
    With the "mechanisms" to access ROM data, the PIC16 is somewhat different. Thus I'd expect to have "something" to set in the compiler options as well.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 07:22:30 (permalink)
    0
    What option are you referring to?  In my OP I said it was PIC18.
    #5
    Jim Nickerson
    User 452
    • Total Posts : 6330
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 08:10:25 (permalink)
    0
    Like this, or did I not understand something ?

    Attached Image(s)

    #6
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 08:33:58 (permalink)
    0
    Yes, I'm using that option in the linker.
    I'm trying to restrict the code to the first 4k (bytes), so I was using:
    default,-1000-FFFF
    or
    0-0FFF
    both give the error.
    default,-0-0FFF
    makes sure the code is not in the first 4K I think?
     
    If I try to place a const either inside or outside the range I get the error.  If I don't specify an address for the const it compiles ok.
    #7
    Jim Nickerson
    User 452
    • Total Posts : 6330
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 08:40:42 (permalink)
    0
    My packaged project is attached, does it work for you ?
    #8
    JPortici
    Super Member
    • Total Posts : 816
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 08:57:22 (permalink)
    0
    I had a very simillar issue. Try to ask jeff (user mad_c) for possible solutions
    In a bootloader i also wanted to restrict the range, but soon found out that the linker was failing to allocate memory.
    It should have been able to (because the total program size was well within the range) but there is a limitation in how much memory the linker needs to perform its operations.
     
    My workaround was to increase the rom range until i could compile and make sure that NO instructions were placed outside the required area.
    Luckily, this was easier than expected as the linker will try to keep everything together if you cooperate with it :)
     
    https://www.microchip.com/forums/m1082084.aspx
    #9
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 09:17:45 (permalink)
    0
    Hi,
    Yes it compiles, but the code is written to the top of flash memory (0xFFe2-0xFFFF).  when I try to restrict the range to 0-4k with 0-0fff or deafult,-1000-ffff it gives the undefined symbols error.
    #10
    JPortici
    Super Member
    • Total Posts : 816
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 09:23:40 (permalink)
    0
    mm.. maybe i don't understand, but if you have the bootloader already written (at bottom) and you want the application to be at the top, then just use --codeoffset
    I think that the same can be done the other way (app at the bottom, bootloader at the top with --codeoffset)
     
    Mixed approach, i don't know. It would be best to see some code that exibit the issue
    #11
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 09:40:35 (permalink)
    0
    This is the bootloader.  I use codeoffset in the main program.
    #12
    davekw7x
    Entropy++
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 10:40:55 (permalink)
    +1 (1)
    jswanson
     
    This works OK, but when I restrict the ROM ranges in the linker to 0-0FFF, I get the following error:
     
    :0:: error: (500) undefined symbols:
    __mediumconst(dist/default/production\I2C_Bootloader.X.production.o) __smallconst(dist/default/production\I2C_Bootloader.X.production.o)
    (908) exit status = 1
     

    It is telling you that it doesn't have anywhere to put the smallconst and mediumconst psects.  It needs them to store your const array (and any string literals that you may have).
     
    (I get the same error for any const array with your ROM restrictions, not just one at a particular address.)
     
    A real head-scratcher---requires a little insight as to how XC8 distinguishes between pointers to data memory and pointers to program memory.
     
    Here's the deal:
    For XC8, program memory pointers always have a bit set in some bit position that makes the value greater than the highest data address.

    This explains (to me, at least) why there is the (seemingly) strange requirement for XC8 that the smallconst and mediumconst sections must be placed in program memory at addresses that are higher than the last RAM address.
     
    In other words, for the '26K83, pointers to program memory must have values greater than 0xFFF.

    By putting linker options to exclude ROM addresses 0x1000-0xffff, XC8 can't do its job.

    My solution: Set exclusion region 0x1100-0xffff.  (If you have more than 256 bytes of const data and string literals, you will have to set the lower limit to a larger value.)
    See attachment.
     
    Then I get good results with stuff like this:

    const int settings[] __at(0x200) = { 1, 5, 10, 50, 100 };

    void main()
    {
        init_system();
        uint8_t i;
        for (i = 0; i < 5; i++) {
            printf("settings[%u] = %u\r\n", i, settings[i]);
        }
    .
    .
    .

     
    Reference XC8 User's Guide:
     

    smallconst – these psects hold objects that are declared const and string literals.
    Used when the total amount of const data in a program is less than 255
    bytes.
    This psect can be linked anywhere in the program memory, provided it does
    not cross a 0x100 boundary and it does not interfere with the requirements
    of other psects. For PIC18 devices, the location of the psect must be above
    the highest RAM address.

    And

    mediumconst – these PIC18-only psects hold objects that are declared const and
    string literals. Used when the total amount of const data in a program exceeds
    255 bytes, but is less than 64k.
    This psect can be linked anywhere in the lower 64k of program memory, provided
    it does not interfere with the requirements of other psects. For PIC18
    devices, the location of the psect must be above the highest RAM address.


    Regards,

    Dave
     
    post edited by davekw7x - 2019/06/18 10:44:58

    Attached Image(s)


    Sometimes I just can't help myself...
    #13
    du00000001
    Just Some Member
    • Total Posts : 3170
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 10:49:46 (permalink)
    0
    With the restriction that ROM constants must be at a higher address than RAM:
    there's an option to limit RAM availability as well!
    Provided you do not need all the RAM, this should be an option...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #14
    davekw7x
    Entropy++
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 11:48:01 (permalink)
    +1 (1)
    du00000001
    With the restriction that ROM constants must be at a higher address than RAM:
    there's an option to limit RAM availability as well!
    Provided you do not need all the RAM, this should be an option...


    No, The array itself is exactly where you put it: starting at 0x200.  Because of the way XC8 implements pointers, when you have a const array it thinks it needs psects for smallconst and/or mediumconst.   For my simple "toy" project, it puts both psects at 0x10f0-0x10ff but doesn't actually put any const data there (code is put into memory just below 0x1100).  It still thinks it needs the const psects, and won't work without 256 bytes of program memory available above 0x1000..
     
    If you have other arrays not defined at specific addresses or if you have string literals, they will be placed in one of the const psects in program memory starting somewhere above 0x1000.
     
    RAM addresses 0-FFF are still all available.
     
    It really means if your bootloader would fit in program memory below 0x1000, you have some wastage above 0x1000.
     
    However...
     
    I usually put copyright notices, Bootloader revision and date/time codes up there anyhow and let the linker do its best job fitting code in program memory.  Given the way it works, I see no value in trying to put things in program memory at low absolute addresses.
     
    On the  other hand put them where the heck you want to:  Chacun à son goût!
    Regards,

    Dave
    post edited by davekw7x - 2019/06/18 13:20:32

    Sometimes I just can't help myself...
    #15
    mad_c
    Super Member
    • Total Posts : 1202
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/18 13:23:41 (permalink)
    +2 (2)
    Hi,
     
    It looks like people are on the right track but just to clarify: Yes, the compiler uses the top-of-RAM address as a boundary to differentiate between RAM and ROM addresses when a pointer can have targets in mixed spaces. So, any const psects must be linked above this address.
     
    You can tell the compiler that it has less RAM than it really does, to bring this address lower, but you will have to use a specific form of the -mram option, like: -mram=0-ff,100-1ff,200-2ff, rather than the normal form, which would be something like: -mram=default,-300-fff. In the first case, you are redefining the memory; in the second you are just subtracting from the default memory.
     
    Check the map file to ensure that this has worked as expected. Search for __ramtop and ensure it has the new top-of-RAM address, for example 300 if I had used the above option.
     
    Jeff.
     
    #16
    jswanson
    Super Member
    • Total Posts : 355
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: Can't locate an object in program memory with restricted rom range 2019/06/19 06:37:45 (permalink)
    0
    Thanks for your help.
    Interesting to know about the address space.  Much better to do this than the rom/ram qualifiers in C18.
    All I was trying to do was place a few bytes at a know location.  I increased the bootloader space to 0x1080, but then it placed most of the code outside of the 4k boot block.  I then tried restricting most of the extra 128 bytes.  This seemed to work, but it always appended 2 extra zero bytes on the end.  I looked at the listing file, but couldn't work out what they related to.  Finally, I moved the definition to the mainline (which placed them below the codeoffset address) and it seems to do what I expected.
    I know linker errors aren't always easy to decipher, but the error message associated with this problem is a bit arcane.
    Jeremy.
     
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5