Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] RE: GCC C runtime help

2005-05-18 by Dave Hylands

Hi Larry,

On 5/17/05, Larry Barello <yahoo@barello.net> wrote:
> Anyone know how I can tell GCC linker to skip the C runtime (e.g. crtm128.o)
> so I can roll my own specialized version?

It's important to not have the main entry point be "main" as this
causes a bunch of "extra" stuff to be pulled in. You may wish to make
the actual entry point be an assembler function which calls your
MyMain, or you may be able to live with C. You'll need to setup your
vectors and stuff as well.

I was able to get this combination to work:

simple.c:

int MyMain()
{
    return 5;
}

avr-gcc -mmcu=atmega128 -o simple.o -c simple.c
avr-gcc -v -Wl,-Map=simple.map -mmcu=atmega128 -o simple.elf -nostdlib
-Wl,-e,MyMain simple.o
avr-objdump -S simple.elf

simple.elf:     file format elf32-avr

Disassembly of section .text:

00000000 <MyMain>:
   0:   cf 93           push    r28
   2:   df 93           push    r29
   4:   cd b7           in      r28, 0x3d       ; 61
   6:   de b7           in      r29, 0x3e       ; 62
   8:   85 e0           ldi     r24, 0x05       ; 5
   a:   90 e0           ldi     r25, 0x00       ; 0
   c:   df 91           pop     r29
   e:   cf 91           pop     r28
  10:   08 95           ret

-- 
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.