*
*/
-typedef struct avr_mcu_t {
- long f_cpu; // avr is little endian
- unsigned char id[4]; // signature bytes
- unsigned char fuse[4]; // optional
+#include <stdint.h>
+
+struct avr_mcu_t
+{
+ uint32_t f_cpu; // avr is little endian
+ uint32_t reserved;
+ uint8_t mid[4]; // signature bytes
+ uint8_t fuse[4]; // optional
char name[16];
-} avr_mcu_t;
+} __attribute__((__packed__));
#define AVR_MCU(_speed, _name) \
-const avr_mcu_t _mmcu __attribute__((section(".mmcu"))) = {\
+const struct avr_mcu_t _mmcu __attribute__((section(".mmcu"))) = {\
.f_cpu = _speed, \
- .id = {SIGNATURE_0, SIGNATURE_1, SIGNATURE_2}, \
+ .mid = {SIGNATURE_0, SIGNATURE_1, SIGNATURE_2}, \
.name = _name,\
}
target = simavr
+ifeq (${shell uname}, Darwin)
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr-4/"
+else
+AVR_ROOT := /usr/lib/avr
+endif
+
CFLAGS = -g -std=gnu99 -Wall
CFLAGS += -O3 -mfpmath=sse -msse2
obj/sim_%.o : cores/sim_%.h ${wildcard cores/*.h} ${wildcard sim/*.h}
obj/sim_%.o : cores/sim_%.c
@gcc $(CFLAGS) \
- -I/usr/lib/avr/include/ \
+ -I${AVR_ROOT}/include/ \
$< -c -o $@
@echo CORE $<
firmware->bsssize = s->d_size;
} else if (!strcmp(name, ".mmcu")) {
Elf_Data *s = elf_getdata(scn, NULL);
- firmware->mmcu = *((avr_mcu_t*)s->d_buf);
- // printf("%s: setting speed to %ld\n", __FUNCTION__, f_cpu);
+ firmware->mmcu = *((struct avr_mcu_t*)s->d_buf);
+ // printf("%s: avr_mcu_t size %ld / read %ld\n", __FUNCTION__, sizeof(avr_mcu_t), s->d_size);
// avr->frequency = f_cpu;
}
#if ELF_SYMBOLS
#endif
typedef struct elf_firmware_t {
- avr_mcu_t mmcu;
+ struct avr_mcu_t mmcu;
uint8_t * flash;
uint32_t flashsize;
uint32_t datasize;
if (f_cpu)
f.mmcu.f_cpu = f_cpu;
- printf("firmware %s f=%ld mmcu=%s\n", argv[argc-1], f.mmcu.f_cpu, f.mmcu.name);
+ printf("firmware %s f=%d mmcu=%s\n", argv[argc-1], f.mmcu.f_cpu, f.mmcu.name);
avr_kind_t * maker = NULL;
for (int i = 0; avr_kind[i] && !maker; i++) {
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
+ifeq (${shell uname}, Darwin)
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/"
+else
+AVR_ROOT :=
+endif
+AVR := ${AVR_ROOT}avr-
+
+SHELL = /bin/bash
+
sources := $(wildcard at*.c)
all : ${sources:.c=.axf} ${sources:.c=.hex} ${sources:.c=.s}
%.hex: %.axf
- @avr-objcopy -j .text -j .data -O ihex ${<} ${@}
+ @${AVR}objcopy -j .text -j .data -O ihex ${<} ${@}
%.s: %.axf
- @avr-objdump -j .text -j .data -j .bss -d ${<} > ${@}
+ @${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@}
%.axf: %.c
@echo CC ${<}
@part=${<} ; part=$${part/_*}; \
- avr-gcc -Wall -g -Os -std=gnu99 \
+ ${AVR}gcc -Wall -g -Os -std=gnu99 \
-mmcu=$$part \
-DF_CPU=8000000 \
-mcall-prologues -fno-inline-small-functions \
-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
-I../include \
${<} -o ${@}
- @avr-size ${@}|sed '1d'
+ @${AVR}size ${@}|sed '1d'
clean:
rm -f *.hex *.o *.axf *.s