• AVR Freaks

Hot!Where can I go to learn relocatable coding?

Author
CVRIV
Super Member
  • Total Posts : 164
  • Reward points : 0
  • Joined: 2017/09/06 13:49:25
  • Location: 0
  • Status: offline
2020/08/05 21:30:16 (permalink)
0

Where can I go to learn relocatable coding?

I saw a section in the PIC Assembler manual, but I doubt that will be enough. Does anyone know of a good place to read about how to code in relocatable mode?

This is a bit off topic but I was unable to log in using my PC. The verify text thing kept saying I was entering the text wrong. I'm trying this via my phone, which was already logged in.
#1

14 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28378
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/05 23:24:28 (permalink)
    +1 (1)
    Which PIC family, or better still, which PIC?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    atferrari
    Super Member
    • Total Posts : 1450
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/06 02:38:09 (permalink)
    +2 (2)
    If you are talking of working in Assembly with pic-as 2.20, the paradigma has changed: you are, de facto, working in relocatable mode. Think of it this way: whatever you want to be in absolute you must specify it expressly (search abs and ORG).
     
    Given the way it works with the Assembler/linker doing its think (and eventually what you could see as a "salad" with the resulting machine code), you only have to care of keeping your source organized that you could understand it, making sure of what you actually need to be in absolute location. The reset vectors, at power ON and interrupts are a good example and, most probably nothing else.
     
    Simpler, eh?

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #3
    CVRIV
    Super Member
    • Total Posts : 164
    • Reward points : 0
    • Joined: 2017/09/06 13:49:25
    • Location: 0
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/06 02:51:43 (permalink)
    0
    Well, right now I'm working with a PIC16F883, but will very soon move to a PIC18F57Q43.

    All this seems so complicated. I'm reading through the linker section of the pic-as user guide not knowing what it is im reading with all the linker codes. Im going to read through the entire guide but I feel like I'm going to need more of an explanation as to whats going on with all that. When I was taught how to code in absolute code, that was easy as hell. I just need to understand whats going on.

    A psect is a section of code in program memory? I was thinking that sections of code in program memory.... Ahhh I dont know. There isnt much on youtube about this or anywhere. This is frustrating. I'm just going to keep reading the pic-as guides.
    #4
    NorthGuy
    Super Member
    • Total Posts : 6291
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/06 07:07:59 (permalink)
    +2 (2)
    It's not that difficult. In absolute mode you use ORG. You're responsible for making sure that different fragments of your code don't overlap. IMHO this is a good thing, but many people see it as a problem.
     
    Relocatable code solves this problem. You create sections and write code (or place data) within sections. This is then given to the linker which places the sections at its own will and corrects all the dependencies between them. The drawback is that the assembler doesn't know the exact location of the section at the compile time. Thus some things, e.g. difference between addresses from different sections, cannot be used.
     
     
    #5
    atferrari
    Super Member
    • Total Posts : 1450
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/06 07:56:20 (permalink)
    +1 (1)
    Hola CVRIV
     
    I can feel your pain facing something like that. I am not experienced with that famous linker; until two months ago I was working in pure Assembly in absolute mode and since I run across pic-as 2.20 I approached the whole thing avoiding any reference to previous MPASM. It worked well for me.
     
    I did, with exception of a single instruction to the linker, everything inside the IDE MPLABX 5.40. Managed to complete a project in few days. Even through a painful debugging. (Outstanding flaw of MPLABX 5.40).
     
    Me, as you now, had no idea what a psect was. Here below you have the list of the psects you are likely to need. Compiling this apriori helped me a lot in clearing doubts before starting to rewrite my code. Buena suerte.
     
    /*
    Psects du jour as suggested by the Chef.
    -----------------------------
    Data in RAM
    Full: Psect..udata,global,class=RAM,SPACE_DATA,delta=1,noexec
    Use: Psect udata

    Full: Psect udata_acs,global,class=COMRAM,SPACE_DATA,delta=1,noexec
    Use: Psect udata_acs

    Full: Psect udata_bank0,global,class=BANK0,SPACE_DATA,delta=1,noexec
    Use: Psect udata_bank0

    Full: Psect..udata_bank1,global,class=BANK1,SPACE_DATA,delta=1,noexec
    Use: Psect udata_bank1

    (BANKx depends of your micro) this is for the 18F2321
    ;-----------------------------------------------------------------------

    Data in EEPROM
    Full: Psect eedata,global,class=EEDATA,space=SPACE_EEPROM,delta=2,noexec
    -----------------------------------------------------------------------

    Data in program memory
    Full: Psect data,global,class=CONST,space=SPACE_CODE,delta=1,noexec
    -----------------------------------------------------------------------

    Absolute code
    Full: Psect code,abs,global,class=CODE,space=SPACE_CODE,delta=1,reloc=2

    Relocatable code
    Full: Psect code,global,class=CODE,space=SPACE_CODE,delta=1,reloc=2
    Use: Psect code
    -----------------------------------------------------------------------

    Flags in RAM (Access bank)
    Full: Psect bitflags,bit,global,space=SPACE_DATA,class=COMRAM

    Flags in RAM (BANKX)
    Full: Psect bitflags,bit,global,space=SPACE_DATA,class=BANKX
    ------------------------------------------------------------------------------
    */

     
     
     
    post edited by atferrari - 2020/08/06 10:57:11

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #6
    CVRIV
    Super Member
    • Total Posts : 164
    • Reward points : 0
    • Joined: 2017/09/06 13:49:25
    • Location: 0
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 01:24:48 (permalink)
    0
    Thanks to everyone trying to clear things up for me.
     
    atferrari
    Hola CVRIV
     
    I can feel your pain facing something like that. I am not experienced with that famous linker; until two months ago I was working in pure Assembly in absolute mode and since I run across pic-as 2.20 I approached the whole thing avoiding any reference to previous MPASM. It worked well for me.
     
    I did, with exception of a single instruction to the linker, everything inside the IDE MPLABX 5.40. Managed to complete a project in few days. Even through a painful debugging. (Outstanding flaw of MPLABX 5.40).
     
    Me, as you now, had no idea what a psect was. Here below you have the list of the psects you are likely to need. Compiling this apriori helped me a lot in clearing doubts before starting to rewrite my code. Buena suerte.

     
    Thanks you so much. I'll study this code to better understand whats going on. Thank you so much.
    #7
    atferrari
    Super Member
    • Total Posts : 1450
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 01:46:31 (permalink)
    0
    It is not even "code"
    It is a list of all the psects you could be using.
    I keep it in my library to have handy when writing code.
    Read the list to understand the options you have.

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #8
    CVRIV
    Super Member
    • Total Posts : 164
    • Reward points : 0
    • Joined: 2017/09/06 13:49:25
    • Location: 0
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 02:20:26 (permalink)
    0
    atferrari
    It is not even "code"
    It is a list of all the psects you could be using.
    I keep it in my library to have handy when writing code.
    Read the list to understand the options you have.


    I'm reading through the PIC Assembler Manual now. I think everything I need to understand all of this might be in this manual, but Im not sure. I just have to keep reading. It's mentioning so much and most of it I have no idea what it is I'm reading. I think I will better understand the more I read into this. So many options, and files, and memory this and memory that..... wow. Absolute coding was so easy to grasp. LOL.
    #9
    atferrari
    Super Member
    • Total Posts : 1450
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 07:09:25 (permalink)
    0
    CVRIV
    I'm reading through the PIC Assembler Manual now. I think everything I need to understand all of this might be in this manual, but Im not sure. I just have to keep reading. It's mentioning so much and most of it I have no idea what it is I'm reading. I think I will better understand the more I read into this. So many options, and files, and memory this and memory that..... wow. Absolute coding was so easy to grasp. LOL.

     
    At a certain moment I stopped outright the reading of the transition manual.
     
    What I did: read again the chapter about Assembly in the XC8's manual, then, again the Engineer's Manual and finally took my last project (still under development) and started to re write it.
     
    Suggestion: solve upfront how to set the reset vectors (POR and interrupts). The rest will come easily. 
     
    Suggestion bis: stop saying this is difficult. Be used to the idea: life is not fair.
     
    Now, here you have what I did. Before any critics, be aware that it works:
     
     
    ;000_Modelo_para_CVRIV_01.S

      Title "000_Modelo_para_CVRIV_011"
      Subtitle "Started 04.07.20 - Buenos Aires"
      Subtitle "Updated "
      Subtitle "Agustín Tomás Ferrari Nicolay"
    ;------------------------------------------------------------------------------

      List C=140,N=59,T=OFF
    ;------------------------------------------------------------------------------
    /*
    Project: Modelo_para_CVRIV_01

    Description of the project goes here.

    /*
    DESIGN DETAILS

    Clock: Internal Oscillator Block = 4 MHz, thus Fosc = 4 MHz.
    Clock period (T)= 1/4.000.000 Hz = 250 nsec.
    Instruction cycle (Tcy)= 4*T = 4*250 nsec = 1 usec.
    Software clock tick = 1 ms
    Pins RA6 & RA7 enabled as I/O.

    Ports to service:
    ADC
    Debug LEDs & pin
    LCD control
    LCD data
    Keypad
    Serial comms
    -------------------------------------------------------------------------------
    */

    Psects du jour as suggested by the Chef.
    -----------------------------
    Data in RAM
    Full: Psect..udata,global,class=RAM,SPACE_DATA,delta=1,noexec
    Use: Psect udata

    Full: Psect udata_acs,global,class=COMRAM,SPACE_DATA,delta=1,noexec
    Use: Psect udata_acs

    Full: Psect udata_bank0,global,class=BANK0,SPACE_DATA,delta=1,noexec
    Use: Psect udata_bank0

    Full: Psect..udata_bank1,global,class=BANK1,SPACE_DATA,delta=1,noexec
    Use: Psect udata_bank1
    ;-----------------------------------------------------------------------

    Data in EEPROM
    Full: Psect eedata,global,class=EEDATA,space=SPACE_EEPROM,delta=2,noexec
    -----------------------------------------------------------------------

    Data in program memory
    Full: Psect data,global,class=CONST,space=SPACE_CODE,delta=1,noexec
    -----------------------------------------------------------------------

    Absolute code
    Full: Psect code,abs,global,class=CODE,space=SPACE_CODE,delta=1,reloc=2

    Relocatable code
    Full: Psect code,global,class=CODE,space=SPACE_CODE,delta=1,reloc=2
    Use: Psect code
    -----------------------------------------------------------------------

    Flags in RAM (Access bank)
    Full: Psect bitflags,bit,global,space=SPACE_DATA,class=COMRAM

    Flags in RAM (BANKX)
    Full: Psect bitflags,bit,global,space=SPACE_DATA,class=BANKX
    ------------------------------------------------------------------------------
    */

      Processor 18F2321
      Radix dec
      Expand

      #include "001_CONFIGURATION_18F2321.INC"

      ;"space" flags for Psects From the MCHP dove.
      #define SPACE_CODE 0
      #define SPACE_DATA 1
      #define SPACE_EEPROM 3

      #include <xc.inc>

      #include "002_CONSTANTS_18F2321.S"
      #include "003_CONSTANTS_XXX.S"
      #include "004_CONSTANTS_LCD.S"
      #include "006_VARIABLES_ACC.S"
      #include "008_VARIABLES_BNK.S"
      #include "010_MACROS_18F.S"
      #include "011_MACROS_DEBUG.S"
      #include "012_MACROS_LCD.S"
      #include "013_MACROS_SERIAL.S"
    ;------------------------------------------------------------------------------

      Psect code,abs,global,class=CODE,space=SPACE_CODE,delta=1,reloc=2
      global POR_VECTOR,INIPROG,ISR_HIGH_OR_COMPATIBLE

    POR_VECTOR:
      ORG 00000H ;reset vector
      BRA INIPROG

      ORG 00008H ;high priority/compatible mode interrupt vector
      BRA ISR_HIGH_OR_COMPATIBLE ;Little space for an ISR here.

      ORG 00018H ;low priority interrupt vector
    ; #include "015_ISR_LOW.S"

    ISR_HIGH_OR_COMPATIBLE:
    ; #include "016_ISR_COMPATIBLE_MODE.S"
      #include "017_ISR_HIGH.S"

      Psect code

    INIPROG: ;real men's land - action starts here

    ;initialization starts here

      #include "020_INIT_HARDWARE.S"
      #include "021_INIT_LCD.S"
      #include "022_INIT_GPR_AND_FLAGS.S"
      #include "023_INIT_FIRST_INFO.S"
      #include "024_INIT_INTERRUPTS.S"

    ;initialization ends here
    ;------------------------------------------------------------------------------

      #include "026_MAIN_LOOP.S"
    ;------------------------------------------------------------------------------

    ;Routines

      #include "ROUT CONVERSIONS_TSTS_N_CHKS.S"
      #include "ROUT_DECR_COUNTERS.S"
      #include "ROUT_DELAYS.S"
      #include "ROUT_DISPLAY.S"
    ; #include "ROUT_EEPROM.S"
      #include "ROUT_FOR_DEBUG.s"
      #include "ROUT_KEYP_MANAGER.S"
      #include "ROUT_KEYP_SERV.S"
      #include "ROUT_LCD.S"
      #include "ROUT_MATHS.S"
      #include "ROUT_SERIAL.S"
      #include "TABLES_DATA.S"
      #include "TABLES_TEXT.S"

    ;Done my friend. Nice to work with you.
      END POR_VECTOR


    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #10
    CVRIV
    Super Member
    • Total Posts : 164
    • Reward points : 0
    • Joined: 2017/09/06 13:49:25
    • Location: 0
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 07:47:08 (permalink)
    0

    At a certain moment I stopped outright the reading of the transition manual.

     
    I agree with this. I think I'm going to just read a little bit more and then just reference the manuals as I go. 
     

    Suggestion: solve upfront how to set the reset vectors (POR and interrupts). The rest will come easily. 

     
    Sounds good. Those have absolute addresses right? The reset vector is 0x0000 and the interrupts start at 0x0004. 
     

    Suggestion bis: stop saying this is difficult. Be used to the idea: life is not fair.

     
    Will do. Life isn't fair. Just to be honest, if this was to easy, I might feel like I'd be limited with what I can do with it. I like complicated because life is complicated. We have to figure it out. I'll examine your work to better understand. Thank you so much.
    #11
    1and0
    Access is Denied
    • Total Posts : 11140
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/07 08:26:37 (permalink)
    0
    CVRIV
    Absolute coding was so easy to grasp. LOL.

    Relocatable mode is easier in MPASM than in PIC-AS. So, it is not issue with relocatable mode; but rather it's issue with PIC-AS, which IMO Microchip released before it is ready for prime time.
    #12
    PStechPaul
    Super Member
    • Total Posts : 2919
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/08 12:00:18 (permalink)
    +1 (1)
    atferrari: It looks like you have improperly nested comment pairs, /* and */
     
    However, the assembler might accept the code and build properly.

     
    #13
    atferrari
    Super Member
    • Total Posts : 1450
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/08 12:43:01 (permalink)
    0 (2)
    PStechPaul
    atferrari: It looks like you have improperly nested comment pairs, /* and */ However, the assembler might accept the code and build properly.

    No surprise. I prepared the excerpt on the fly for replying to the OP.

    As I said, it works. Running on my desk right now.

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #14
    CVRIV
    Super Member
    • Total Posts : 164
    • Reward points : 0
    • Joined: 2017/09/06 13:49:25
    • Location: 0
    • Status: offline
    Re: Where can I go to learn relocatable coding? 2020/08/11 03:39:26 (permalink)
    0
    Ok. I think I'm starting to understand this whole relocatable mode thing.
     
    Based on what I've read so far in the pic-as manual, relocatable mode is a style of coding that allows you to more easily reuse your code across a wide range of devices with minimal editing of your code required to get it working properly. I don't know what I was thinking it was before I started reading the manual. I have it so over complicated in my head that I was thinking I had to learn a whole new language or something. 
     
    I don't have all ironed out yet, I'm still reading though the manual. I do have a few questions and just want to verify a few things.
     
    So a module is basically an assembly file with specific code capable of carrying out a single task? This module is written in a such a way that it can be included within a project's main assembly file and used with minimal editing, if any editing is even needed at all?
     
    When I include many assembly files, each include is replaced with the associated code during compiling? So doing that increases the program counter right?
     
    When I read about FCALL and LJMP and how to they expand to include instructions needed to change the PCLATH register, that's when all of this relocatable mode stuff hit me. It's not absolute. It's automatic. I dont have to worry about page selecting when using those directives. 
     
    When I read through section 6 (Linker), I didn't understand the purpose to reserving memory and everything is section 6 has to do with using command prompt right?
     
    Also, modules can be object files (.o), hex files(.h), and library files(.a)? I haven't read chapter 7 yet. 
     
    Am I on track?
    #15
    Jump to:
    © 2020 APG vNext Commercial Version 4.5