|
###########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 }
|