# This makefile take each "at*" file, extracts it's part name
# And compile it into an ELF binary.
# It also disassemble it for debugging purposes.
-#
+#
# The code is compiled "optimized" to the max.
-#
+#
# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
# is used to tell the linker not to discard the .mmcu section,
# otherwise the --gc-sections will delete it.
-#
+#
# Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
#
# This file is part of simavr.
CORE_CFLAGS = -nostdinc -DAVR_CORE=1
ifeq (${shell uname}, Darwin)
- # gcc 4.2 from MacOS is really not up to scratch anymore
+ # gcc 4.2 from MacOS is really not up to scratch anymore
CC = clang
AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/"
AVR_INC := ${AVR_ROOT}/avr/
MKDIR ?= mkdir -p
INSTALL ?= install
SHELL := ${shell which bash}
-
+
OBJ := obj-${shell $(CC) -dumpmachine}
LIBDIR := ${shell pwd}/${SIMAVR}/${OBJ}
LDFLAGS += -L${LIBDIR} -lsimavr -lm
-LDFLAGS += -lelf
+LDFLAGS += -lelf
ifeq (${WIN}, Msys)
LDFLAGS += -lws2_32
endif
# The code is compiled "optimized" to the max.
-#
+#
# The weird "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
# is used to tell the linker not to discard the .mmcu section,
# otherwise the --gc-sections will delete it.
@${AVR}objdump -j .text -j .data -j .bss -d ${<} > ${@}
# --mcall-prologues can be used here, but messes up debugging a little
-%.axf: %.c
+%.axf: %.c
@echo AVR-CC ${<}
@part=${<} ; part=$${part/_*}; \
${AVR}gcc -Wall -gdwarf-2 -Os -std=gnu99 \
endif
obj: ${OBJ}
-
-${OBJ}:
+
+${OBJ}:
@mkdir -p ${OBJ}
clean-${OBJ}:
avr_irq_t * irq = avr_io_getirq(p->io.avr,
p->eint[i].port_ioctl, p->eint[i].port_pin);
- avr_connect_irq(irq, p->io.irq + i);
+ avr_connect_irq(irq, p->io.irq + i);
}
}
}
} else if (!strcmp(argv[pi], "-ee")) {
loadBase = AVR_SEGMENT_OFFSET_EEPROM;
} else if (!strcmp(argv[pi], "-ff")) {
- loadBase = AVR_SEGMENT_OFFSET_FLASH;
+ loadBase = AVR_SEGMENT_OFFSET_FLASH;
} else if (argv[pi][0] != '-') {
char * filename = argv[pi];
char * suffix = strrchr(filename, '.');
ihex_chunk_p chunk = NULL;
int cnt = read_ihex_chunks(filename, &chunk);
if (cnt <= 0) {
- fprintf(stderr, "%s: Unable to load IHEX file %s\n",
+ fprintf(stderr, "%s: Unable to load IHEX file %s\n",
argv[0], argv[pi]);
exit(1);
}
for (;;) {
int state = avr_run(avr);
- if ( state == cpu_Done || state == cpu_Crashed)
+ if (state == cpu_Done || state == cpu_Crashed)
break;
}
-
+
avr_terminate(avr);
}
/* Note: checking interrupt_state here is completely superfluous, however
as interrupt_state tells us all we really need to know, here
a simple check here may be cheaper than a call not needed. */
- if (avr->interrupt_state) avr_service_interrupts(avr);
+ if (avr->interrupt_state)
+ avr_service_interrupts(avr);
}
}
* the rest is runtime data (as little as possible)
*/
typedef struct avr_t {
- const char * mmcu; // name of the AVR
+ const char * mmcu; // name of the AVR
// these are filled by sim_core_declare from constants in /usr/lib/avr/include/avr/io*.h
- uint16_t ramend;
- uint32_t flashend;
- uint32_t e2end;
- uint8_t vector_size;
- uint8_t signature[3];
- uint8_t fuse[6];
- uint8_t lockbits;
- avr_io_addr_t rampz; // optional, only for ELPM/SPM on >64Kb cores
- avr_io_addr_t eind; // optional, only for EIJMP/EICALL on >64Kb cores
- uint8_t address_size; // 2, or 3 for cores >128KB in flash
+ uint16_t ramend;
+ uint32_t flashend;
+ uint32_t e2end;
+ uint8_t vector_size;
+ uint8_t signature[3];
+ uint8_t fuse[6];
+ uint8_t lockbits;
+ avr_io_addr_t rampz; // optional, only for ELPM/SPM on >64Kb cores
+ avr_io_addr_t eind; // optional, only for EIJMP/EICALL on >64Kb cores
+ uint8_t address_size; // 2, or 3 for cores >128KB in flash
// filled by the ELF data, this allow tracking of invalid jumps
uint32_t codeend;
* is reached, at which point sleep_usec is cleared and the sleep request
* is passed on to the operating system.
*/
- uint32_t sleep_usec;
+ uint32_t sleep_usec;
// called at init time
void (*init)(struct avr_t * avr);
00: idle (no wait, no pending interrupts) or disabled
<0: wait till zero
>0: interrupt pending */
- int8_t interrupt_state; // interrupt state
+ int8_t interrupt_state; // interrupt state
/*
* ** current PC **
* will handle this particular case, without impacting the performance of the
* other, normal cases...
*/
- int io_shared_io_count;
+ int io_shared_io_count;
struct {
int used;
struct {
} io_shared_io[4];
// flash memory (initialized to 0xff, and code loaded into it)
- uint8_t * flash;
+ uint8_t * flash;
// this is the general purpose registers, IO registers, and SRAM
- uint8_t * data;
+ uint8_t * data;
// queue of io modules
- struct avr_io_t *io_port;
+ struct avr_io_t * io_port;
// Builtin and user-defined commands
avr_cmd_table_t commands;
#ifdef NO_COLOR
#define FONT_GREEN
- #define FONT_RED
- #define FONT_DEFAULT
+ #define FONT_RED
+ #define FONT_DEFAULT
#else
#define FONT_GREEN "\e[32m"
#define FONT_RED "\e[31m"
*/
const char * avr_regname(uint8_t reg);
-/*
- * DEBUG bits follow
+/*
+ * DEBUG bits follow
* These will disappear when gdb arrives
*/
void avr_dump_state(avr_t * avr);
#define DUMP_STACK()
#define DUMP_REG();
-#endif
+#endif
/**
* Reconstructs the SREG value from avr->sreg into dst.
static inline void avr_sreg_set(avr_t * avr, uint8_t flag, uint8_t ival)
{
- /*
+ /*
* clear interrupt_state if disabling interrupts.
* set wait if enabling interrupts.
* no change if interrupt flag does not change.