Question

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.

Was it helpful?

Solution

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 a a 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!

OTHER TIPS

The location of a function is up to the linker, not the compiler.

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 ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top