公告

非常抱歉,由于我们的服务器提供商硬盘出错,数据丢失,网站重建中...
I am so sorry, because of our server's hard disk error, data lost, the website reconstructioning
QQ:512000523
MSN : funchip@hotmail.com

 
首页 arrow 技术文章 arrow setp arrow AVRGCC的启动代码修改
AVRGCC的启动代码修改 Recommend to my friend via E-mail(推荐给朋友)
作者: Administrator   
2007-11-14


###########FunChip整理测试修编写########


A:然后去除Avrgcc启动代码中的中断向量表?

Q:avrgcc默认下,将所有中断向量全部填满,如果你有某些原因不想用到,可以做如下修改:

   修改makefile
    # Optional compiler flags.
    #  -g:        generate debugging information (for GDB, or for COFF conversion)
    #  -O*:       optimization level
    #  -f...:     tuning, see gcc manual and avr-libc documentation
    #  -Wall...:  warning level
    #  -Wa,...:   tell GCC to pass this to the assembler.
    #    -ahlms:  create assembler listing
    CFLAGS = -g -O$(OPT) \
    -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
    -Wall -Wstrict-prototypes \
    -Wa,-ahlms=$(<:.c=.lst) \
    -nostartfiles -minit-stack=0x45F

    -minit-stack=0x45F 如果没有声明,编译器会有
    undefined reference to `__stack'的错误报警,可以通过声明-minit-stack=0x45F,或者添加程序来解决,可以做如下添加
 
    void initstack(void) __attribute__ ((section(".init9")));
    void initstack(void)
    {
        //设置堆栈
        asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
        //记得跳到main函数去
        asm volatile ( "rjmp main");
    }
    ((section(".init9"))) 这里使用init9把程序放在avrgcc其他启动初始化代码后面

A:如何去掉全部的AvrGcc的启动代码?

Q:我们还是要修改makefile
    # Optional compiler flags.
    #  -g:        generate debugging information (for GDB, or for COFF conversion)
    #  -O*:       optimization level
    #  -f...:     tuning, see gcc manual and avr-libc documentation
    #  -Wall...:  warning level
    #  -Wa,...:   tell GCC to pass this to the assembler.
    #    -ahlms:  create assembler listing
    CFLAGS = -g -O$(OPT) \
    -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
    -Wall -Wstrict-prototypes \
    -Wa,-ahlms=$(<:.c=.lst) \
    -nostartfiles -nodefaultlibs

    例子代码:
    #include <avr/io.h>
    unsigned char tmp;

    void __jumpMain     (void) __attribute__ ((naked)) __attribute__ ((section (".init0")));
    void __jumpMain(void)
    {   
        //设置堆栈
        asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
        //清r1,avrgcc会将r1默认为0,如果程序将某变量置0,就会把r1移过去
        asm volatile ( "clr __zero_reg__" );   
        //跳转到main
        asm volatile ( "rjmp main");
    }
    void main(void)
    {
        //测试r1
        tmp = 0;
        while(1);
    }

    查看反汇编:
    00000000 <__jumpMain>:
    {   
        //设置堆栈
        asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
        //清r1,avrgcc会将r1默认为0,如果程序将某变量置0,就会把r1移过去
        asm volatile ( "clr __zero_reg__" );   
        0: 11 24        eor r1, r1
        //跳转到main
        asm volatile ( "rjmp main");
        2: 00 c0        rjmp .+0       ; 0x4
    }

    void main(void)
    {
        4: cf e5        ldi r28, 0x5F ; 95
        6: d4 e0        ldi r29, 0x04 ; 4
        8: de bf        out 0x3e, r29 ; 62
        a: cd bf        out 0x3d, r28 ; 61
         //测试r1
        tmp = 0;
        c: 10 92 60 00  sts 0x0060, r1
        while(1);
        10: ff cf        rjmp .-2       ; 0x10
    }

评论 (0)Add Comment

输入评论内容
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security code
输入验证码


busy
最近更新 ( 2007-11-18 )
 
< 上一篇   下一篇 >

© 2009 杭州福芯电子 浙ICP备05040812号
Joomla!是基于GNU/GPL许可发行的免费软件.