avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Pointer to a function in a structure in flash?


From: Richard Urwin
Subject: Re: [avr-gcc-list] Pointer to a function in a structure in flash?
Date: Mon, 27 Oct 2003 21:44:41 +0000
User-agent: KMail/1.5

On Monday 27 Oct 2003 6:55 pm, you wrote:
> Is there an attachment missing???
>
> On Mon, 27 Oct 2003 19:36:29 +0000, Richard Urwin
>
> <address@hidden> wrote:
> > Do these help?
> > I've taken out the parameters and simplified the structure, but I don't
> > think I've changed the logic any.
>
> I saw no new code????

You're not wrong. Try it in-line. With the PROGMEM keyword now. Not sure I 
like the lds instructions, but I'm a 1200 man. This compiles all the way to 
a.out, and str_func_entry is in .text
Now it's back to you to see if it's correct.

test.c
-------------------------------------------------------------------
#include <progmem.h>
typedef int (*functype_t)();

int fred()
{
        return 0;
}

typedef struct
{
     functype_t function;
} thestruct ;

static const  thestruct str_func_entry PROGMEM = { fred};

main ()
{
        int retval;

        retval = (*(functype_t)str_func_entry.function)();
}
-------------------------------------------------------------------

test.s
-------------------------------------------------------------------
        .file   "test.c"
        .arch at90s8535
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
_PC_ = 2
        .text
.global fred
        .type   fred,@function
fred:
/* prologue: frame size=0 */
        push r28
        push r29
        in r28,__SP_L__
        in r29,__SP_H__
/* prologue end (size=4) */
        ldi r24,lo8(0)
        ldi r25,hi8(0)
/* epilogue: frame size=0 */
        pop r29
        pop r28
        ret
/* epilogue end (size=3) */
/* function fred size 9 (2) */
.Lfe1:
        .size   fred,.Lfe1-fred
.section .progmem.data, "a", @progbits
        .type   str_func_entry,@object
        .size   str_func_entry,2
str_func_entry:
        .word pm(fred)
        .text
.global main
        .type   main,@function
main:
/* prologue: frame size=2 */
        ldi r28,lo8(__stack - 2)
        ldi r29,hi8(__stack - 2)
        out __SP_H__,r29
        out __SP_L__,r28
/* prologue end (size=4) */
        lds r30,str_func_entry
        lds r31,(str_func_entry)+1
        icall
        std Y+1,r24
        std Y+2,r25
/* epilogue: frame size=2 */
__stop_progIi__:
        rjmp __stop_progIi__
/* epilogue end (size=1) */
/* function main size 12 (7) */
.Lfe2:
        .size   main,.Lfe2-main
/* File test.c: code   21 = 0x0015 (   9), prologues   8, epilogues   4 */
-- 
Richard Urwin


reply via email to

[Prev in Thread] Current Thread [Next in Thread]