简体   繁体   中英

How do I get a function to be compiled at address 04 with GPLINK? (For PIC16)

I have a function which is meant to catch all the interrupt calls that will happen, But I cannot get any function to start at address 04.

Note: I dont want to use functions that are specific to interrupt types, I dont want the overhead they produce in the code.

I have tried the following codes with SDCC, maybe not quite related but I will keep them here just in case.

__code __at (4) void handler() {

And

void __at (4) handler() {

With no luck, the manual does not explain any further also.

I know it's a long time after the original question, but I am searching for the same answer and found this helpful info, confirmed working on SDCC 3.3.0: (Source: http://www.mail-archive.com/sdcc-user@lists.sourceforge.net/msg00411.html )

To cause a function to be linked aa fixed, known address, you can surround the function with two other functions: See example below. NOTE: all the _ are double _ _ characters! (You can also define the macros as in the above example, if you intend to use this multiple times throughout your code.

REPLACE #### with your function's desired address below:

test.c

void begin_absolute_code(void) __naked
{
    __asm
          .area ABSCODE (ABS,CODE)
          .org 0x####        // YOUR FUNCTION'S DESIRED ADDRESS HERE.
    __endasm;
}

void your_function(...)
{
     // Do stuff here. This code will be placed at the specified address.
}

void end_absolute_code(void) __naked
{
    __asm
        .area CSEG (REL,CODE)
    __endasm;
}

void other_functions_here(...)
    // These functions will return to relative positions determined by the linker.

Hope this is helpful!

函数的位置取决于链接器,而不是编译器。

You don't want the function to start at address 4, you want the compiler to generate a jump at that location to your isr function.

A quick look at the SDCC documentation gives this structure:

void isr(void) interrupt n { /* your code goes here */ }

Where 'n' vector slot where you want the goto instruction.

Other compilers will have similar features, you need to check the compiler documentation for the exact incantation.

For example, using HiTech C:

void interrupt isr(void) { /* code */ }

I found this in a mailing list.

Compile using sdcc --codeseg SEGNAME -c file.c
And link doing this sdcc -Wl -bSEGNAME=0x7ff0 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM