Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

How do you link an absolute segment?

2009-02-09
2013-03-12
  • I am attempting to build a project under SDCC which I originally developed using the Keil IDE for the 8051 series. I cannot find clear documentation on how to build an absolute segment and then link the project such that the absolute segment is located in the correct memory location. In my project, I have data tables which must live at a fixed location because they are in a portion of FLASH memory which may be reprogrammed by my application on command. I have several tables which are built as initialized structures at memory location 0x1A00. When I link, the segment name CAL_CONST is in the table at the correct address. The data is not. I am using #pragma codeseg CAL_CONST to name the segment in my calibration project. I then am linking the .REL file with my main project. The main project uses  -Wl-bCAL_CONST=0x1A00 as part of the compiler/linker options. I am sure there is a way to do this, but the documentation is not clear and I have tried several approaches based on my understanding of the SDCC Compiler User Guide. Any help will be greatly appreciated.

     
    • Todd Brown
      Todd Brown
      2009-02-09

      I was able to do this by setting up a pointer to that memory and specifying the location.  For the chip I'm using (Phillips/NXP PV98V66x, which is an 8051 architecture), the flash memory is in the code segment, so I had to use the __code decorator.  So try this:

      __code __at (0x1A00) uchar flash_memory[] = {
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      // ...make sure there are as many bytes in here as you want to reserve
      }

      This will locate that pointer at the given location, and reserve that many bytes of memory.  I was using an older version of SDCC, and it was not correctly loading the memory with defaults when I programmed the device, but an update to the latest version of SDCC fixed it.

      Best,
        Todd

       
    • Thank-you for the answer. I already tried this, but it does not accomplish all that I want. Is there a way to have multiple arrays with initialized data compile at an absolute location without specifying __code __at (0x1A00) <type> <variable name>[] for each item? Doing it the s way you suggest will require me to manually calculate how large each table is. That is best done by a compiler and was quite easy in the Keil IDE. It should be possible for my to compile the entire file containing these initialized arrays and then put them into a dedicated segment which I could then locate in a dedicated memory location. This is one of the basic functions of a linker. I just do not know how to use this one.

       
      • Todd Brown
        Todd Brown
        2009-02-09

        Ah, I can see how that would be problematic.  I'm afraid I can't help you -- hopefully someone else can, though.

         
    • I think you are taking the right approach, although you may want to declare a custom constseg rather than a codeseg. Have you tried it as a compiler command line option (section 3.2.9 in the manual) rather than a #pragma?

       
      • Maarten Brock
        Maarten Brock
        2009-02-10

        Good catch Oliver. I had missed it when reading the message.
        Of course you need to set the constseg if you want to place constants and codeseg if you want to place code (instructions).
        The command line option should do exactly the same as the pragma.

        Maarten

         
    • All:
      I have tried all of your suggestions and they all failed. I get my new segment name assigned to the correct address, but the arrays within that section are all independently relocated to the next available location in FLASH. I think this is a serious bug in SDCC. The documentation is vague and the functionality is just wrong. I have been developing software for 33 years and never had this problem, even in the early days. Either I am not understanding the documentation, or SDCC is broken. Is there a special command line syntax for doing this which was omitted from the documentation? If not, then it is time for me to report a bub. Anyone have additional thoughts?

       
      • Maarten Brock
        Maarten Brock
        2009-02-12

        "I get my new segment name assigned to the correct address, but the arrays within that section are all independently relocated to the next available location in FLASH."

        I assume that you mean that the arrays are located outside (typ. before) the segment. If that is so, I suggest you do file a bug report with sources and makefile (or instructions) to reproduce the bug.