how to place more than one functions to specific areas

afrain
2013-04-19
2013-06-06
  • afrain

    afrain - 2013-04-19

    Hi,

    I want to place functions (at least 2) to specific areas for 8051.

    There is codeseg option but it works only for 1 partition.

    Is there any solution to this?

    Thanks,

     
  • Maarten Brock

    Maarten Brock - 2013-04-23

    I think named code segments and assembly are the only options. In assembly you can use the org statement in an ABSolute CONcatenating area. But in general I think it is better to use an absolutely located jumptable than locating each function.

     
  • afrain

    afrain - 2013-04-24

    Thanks for answering,

    I didn't know how "absolutely located jumptable" works.
    But as I understand it is a table which has function addresses.
    Still functions will be placed as default.

    In my project I am changing the hardware and I will put different functions to different roms. (In the same address space)

    I tried the asm coding:
    .area name (CODE,CON,ABS)
    .org address.

    However I can't place the whole function below this.

     
  • Maarten Brock

    Maarten Brock - 2013-04-26

    A bit pedantic but:
    A jumptable is not a table with function addresses but a table with jump instructions. If the table only contains addresses it's called a vector table. The advantage of using a table is that you don't have to allocate a specific amount of rom for the implementation of each function. Instead the linker just places them and fills in the table addresses.

    SDCC can not generate jumptables, so you would have to use assembly. Or if you can live with some inefficiency you can use an array of function pointers at an absolute address (using __at) and use that.

    I do not understand why you can't place a function (in asm) below the .org as you state.

     
  • afrain

    afrain - 2013-05-02

    you can only place this statement like his:

    int exfunction(int a , int b){

    .area name (CODE,CON,ABS)
    .org address.
    ...
    ..code

    return res;
    }

    In this case, linker puts the start address anywhere it wants and put the body of the code to the specified address.

    so when you call function, program will call it from 1st Rom for my case.

     
  • Maarten Brock

    Maarten Brock - 2013-05-03

    When I mentioned in asm I meant you should put the whole function in asm, not just the body. So indeed you cannot use .area and .org inside a C function implementation.

    You could let the compiler generate the asm and modify its .area and add the .org statement.

     
  • afrain

    afrain - 2013-05-31

    Hi,

    I would be appreciated if you can tell me How to compile the asm code?

    I could managed by using ASX8051
    ASX8051 -losg "mycode.ASM"

    Hovewer I see that asx8051 is changed with sdas8051 after version 3.

    I couldn't use this in linux.
    And I coudn't see the executable file in my "usr/bin" location.
    Hovewer, there is an sdas8051.exe file in windows "../pogramfiles/.."

    So is sdas8051 is for windows?

     
  • Maarten Brock

    Maarten Brock - 2013-06-06

    I suggest to use C for now. Something like this:

    MyLib.h

    typedef struct
    {
        void (*func1)(void);
        int  (*func2)(int);
        int  (*func3)(int, char*, long);
    } jumptable_t;
    
    extern const jumptable_t __at(0x1234) theTable;
    

    MyLib.c

    #include "MyLib.h"
    
    void myfunc1(void)
    {
    }
    
    int myfunc2(int a)
    {
        return a;
    }
    
    int myfunc3(int a, char* b, long c)
    {
        return a + b[0] + c;
    }
    
    const jumptable_t __at(0x1234) theTable =
    {
        myfunc1,
        myfunc2,
        myfunc3
    };
    

    MyApp.c

    #include "MyLib.h"
    
    void MyFunc(void)
    {
        theTable.func1();
    }
    
     
    Last edit: Maarten Brock 2013-06-06

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks