arv-gcc tools with assembler source code

View: New views
4 Messages — Rating Filter:   Alert me  

arv-gcc tools with assembler source code

by Marge Coahran-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I would appreciate some tips on building an avr program from
assembler source using the avr-gcc toolchain. My ultimate goal is to
create a .hex file that can be fed to avrdude.

Here is an excerpt from my makefile:
-----------------------
CC = avr-gcc
OBJCOPY=avr-objcopy
MCU = atmega16

# translate an .elf file into a .hex file
.SUFFIXES: .elf .hex
.elf.hex:
         $(OBJCOPY) -O ihex -R .eeprom $< $@

# Link: create ELF output file from object files.
%.elf: $(FILE).o
         $(CC) -mmcu=$(MCU) $(FILE).o --output $@

# Assemble: create object file from assembler source file
%.o: $(FILE).s
  $(CC) -mmcu=$(MCU) -x assembler-with-cpp -c $(FILE).s
----------------------

The (current) difficulty is the command to create the .elf file, for which
avr-gcc gives the following complaint:

/usr/lib/gcc/avr/4.3.2/../../../avr/lib/avr5/crtm16.o: In function
`__bad_interrupt':
../../../../crt1/gcrt1.S:193: undefined reference to `main'
make: *** [mirror.elf] Error 1

I recognize this to mean that the linker cannot find the function main(),
but I don't know how to tell it there shouldn't be one since the entire
program is the single object module, which came from assembly source.
Perhaps I should not be making the .elf file at all?

Thanks in advance for any light you can shed on this.

Marge


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

RE: arv-gcc tools with assembler source code

by Weddington, Eric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

> -----Original Message-----
> From: avr-chat-bounces+eric.weddington=atmel.com@...
> [mailto:avr-chat-bounces+eric.weddington=atmel.com@...]
>  On Behalf Of Marge Coahran
> Sent: Monday, August 03, 2009 3:33 PM
> To: avr-chat@...
> Subject: [avr-chat] arv-gcc tools with assembler source code
>
> I would appreciate some tips on building an avr program from
> assembler source using the avr-gcc toolchain. My ultimate goal is to
> create a .hex file that can be fed to avrdude.
>
> Here is an excerpt from my makefile:

If you're using Windows and WinAVR, then you can use the WinAVR Makefile Template, or alternatively you can use the MFile application to generate a working Makefile for you. Both of these Makefile templates include the ability to have assembler source code within an application.

If you're using Linux/Unix, you can still use the MFile application (as it is written in Tcl/Tk) to generate a known working Makefile. You can get it here:
<http://www.sax.de/~joerg/mfile/>


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

RE: arv-gcc tools with assembler source code

by Weddington, Eric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

> -----Original Message-----
> From: avr-chat-bounces+eric.weddington=atmel.com@...
> [mailto:avr-chat-bounces+eric.weddington=atmel.com@...]
>  On Behalf Of Marge Coahran
> Sent: Monday, August 03, 2009 3:33 PM
> To: avr-chat@...
> Subject: [avr-chat] arv-gcc tools with assembler source code
>
> I would appreciate some tips on building an avr program from
> assembler source using the avr-gcc toolchain. My ultimate goal is to
> create a .hex file that can be fed to avrdude.
>
> Here is an excerpt from my makefile:
> -----------------------
> CC = avr-gcc
> OBJCOPY=avr-objcopy
> MCU = atmega16
>
> # translate an .elf file into a .hex file
> .SUFFIXES: .elf .hex
> .elf.hex:
>          $(OBJCOPY) -O ihex -R .eeprom $< $@
>
> # Link: create ELF output file from object files.
> %.elf: $(FILE).o
>          $(CC) -mmcu=$(MCU) $(FILE).o --output $@
>
> # Assemble: create object file from assembler source file
> %.o: $(FILE).s
>   $(CC) -mmcu=$(MCU) -x assembler-with-cpp -c $(FILE).s
> ----------------------
>
> The (current) difficulty is the command to create the .elf
> file, for which
> avr-gcc gives the following complaint:
>
> /usr/lib/gcc/avr/4.3.2/../../../avr/lib/avr5/crtm16.o: In function
> `__bad_interrupt':
> ../../../../crt1/gcrt1.S:193: undefined reference to `main'
> make: *** [mirror.elf] Error 1

However, to add to my previous post: The reason why you are getting the error above, is because you are not providing a main() function in your application. You need to define this function if you are going to use the toolchain.


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: arv-gcc tools with assembler source code

by Joerg Wunsch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Weddington, Eric" <Eric.Weddington@...> wrote:

> However, to add to my previous post: The reason why you are getting
> the error above, is because you are not providing a main()
> function in your application. You need to define this function if
> you are going to use the toolchain.

More specifically: if you want to have avr-gcc link your entire job
(rather than linking it manually yourself), you have to name your
starting function main(), just like any C program does.

This is due to the code in crtXXX.o calling exactly that function as
the entry point of the actual program, after running all the usual
startup code.  Also, should main() ever return, the value returned
will then be passed to a function named exit(), which is not expected
to ever return itself.  Thus, you should also provide a symbol named
"exit".  If you're sure your main() never returns, it's fine to simply
define that symbol on the linker command-line, like

-Wl,--defsym,exit=0

The advantage of using avr-gcc to link the entire job is that that
startup code will still arrange the interrupt vector table on your
behalf, and initialize the stack pointer before calling main().  If
you don't care about these things, then better link your job manually
using avr-ld directly, rather than having avr-gcc call the linker.

--
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat