Skip to content
Snippets Groups Projects
Commit 088606c8 authored by Stefan Siegl's avatar Stefan Siegl
Browse files

get rid of any stdlib code, declare main as naked and do avr initialization...

get rid of any stdlib code, declare main as naked and do avr initialization (stack, etc.) on our own.
parent ce512a4d
No related branches found
No related tags found
No related merge requests found
......@@ -4,18 +4,12 @@ STRIP=avr-strip
CPPFLAGS += -mmcu=atmega8 -DF_CPU=8000000UL
CFLAGS += -std=gnu99 -Os -g -Wall -W
LDFLAGS += $(CFLAGS)
#
# in order to get rid of .bss and .data initialization code,
# don't link in stdlibs but just crts8515 (for stack initialization)
#
LDFLAGS += -nostdlib `avr-gcc -print-file-name=crts8515.o`
LDFLAGS += $(CFLAGS) -nostdlib
all: funkloader.hex
funkloader: funkloader.o rfm12_trans.o rfm12_wait_read.o exit.o \
funkloader_tx_reply.o
funkloader: funkloader.o rfm12_trans.o rfm12_wait_read.o \
funkloader_tx_reply.o memconfig.o
$(CC) -o $@ $(LDFLAGS) $^
clean:
......
......@@ -29,6 +29,7 @@
#include "pinconfig.h"
#define noinline __attribute__((noinline))
#define naked __attribute__((naked))
extern unsigned short rfm12_trans (unsigned short);
extern unsigned char rfm12_wait_read (void);
......@@ -159,7 +160,8 @@ crc_check (void)
return crc_chk;
}
int
naked int
main (void)
{
spi_init ();
......@@ -188,4 +190,13 @@ main (void)
funkloader_tx_reply ();
rfm12_trans(0x8208); /* TX off */
}
/* jump into application now */
GICR = _BV(IVCE); /* prepare ivec change */
GICR = 0x00; /* change ivec */
void (*jump_to_application)(void) = 0;
jump_to_application();
}
......@@ -19,22 +19,23 @@
#define __SFR_OFFSET 0
#include <avr/io.h>
#include "pinconfig.h"
.file "exit.S"
.text
.global exit
.type exit, @function
exit:
void __attribute__ ((naked, section(".init3"))) init_avr (void);
;; change interrupt vector to application
ldi r24, (1 << IVCE)
out GICR, r24
void
init_avr (void)
{
/* clear zero-register */
__asm volatile ("eor r1, r1 \n\t");
ldi r30, 0
out GICR, r30
/* clear sreg */
__asm volatile ("out __SREG__, r1 \n\t");
;; jump to application
ldi r31, 0 ; Z = 0x0000!
icall
/* initialize stack pointer */
__asm volatile ("ldi r28, lo8(%0) \n\t"
"ldi r29, hi8(%0) \n\t"
"out __SP_H__, r29 \n\t"
"out __SP_L__, r28 \n\t"
:
: "i" (RAMEND));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment