Support emulation on GNU/Linux.

This commit is contained in:
NIIBE Yutaka
2017-06-26 19:32:23 +09:00
parent 78c825afe8
commit 5419580519
2 changed files with 41 additions and 3 deletions

17
entry.c
View File

@@ -1,7 +1,7 @@
/*
* entry.c - Entry routine when reset and interrupt vectors.
*
* Copyright (C) 2013, 2014, 2015, 2016
* Copyright (C) 2013, 2014, 2015, 2016, 2017
* Flying Stone Technology
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
@@ -32,6 +32,20 @@
#include <chopstx.h>
#include "board.h"
#ifdef GNU_LINUX_EMULATION
int emulated_main (int, const char **);
void chx_init (void);
void chx_systick_init (void);
int
main (int argc, const char *argv[])
{
chx_init ();
chx_systick_init ();
emulated_main (argc, argv);
}
#else
#if defined(USE_SYS3) || defined(USE_SYS_CLOCK_GPIO_SETTING)
#define REQUIRE_CLOCK_GPIO_SETTING_IN_SYS
#include "sys.h"
@@ -225,3 +239,4 @@ handler vector_table[] __attribute__ ((section(".startup.vectors"))) = {
chx_handle_intr, chx_handle_intr, chx_handle_intr,
#endif
};
#endif

View File

@@ -10,7 +10,11 @@ ifneq ($(USE_SYS),)
CSRC += $(CHOPSTX)/mcu/sys-$(CHIP).c
endif
ifneq ($(USE_USB),)
ifeq ($(EMULATION),)
CSRC += $(CHOPSTX)/mcu/usb-$(CHIP).c
else
CSRC += $(CHOPSTX)/mcu/usb-usbip.c
endif
endif
ifneq ($(USE_ADC),)
CSRC += $(CHOPSTX)/contrib/adc-$(CHIP).c
@@ -19,10 +23,14 @@ endif
INCDIR += $(CHOPSTX)
BUILDDIR = build
ifeq ($(EMULATION),)
OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).bin
ifneq ($(ENABLE_OUTPUT_HEX),)
OUTFILES += $(BUILDDIR)/$(PROJECT).hex
endif
else
OUTFILES = $(BUILDDIR)/$(PROJECT)
endif
OPT += -ffunction-sections -fdata-sections -fno-common
@@ -34,14 +42,23 @@ LLIBDIR = $(patsubst %,-L%,$(LIBDIR))
VPATH = $(sort $(dir $(CSRC)))
###
ifeq ($(EMULATION),)
MCFLAGS = -mcpu=$(MCU)
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) \
-Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections
else
MCFLAGS =
LDFLAGS =
DEFS += -D_GNU_SOURCE
endif
CFLAGS = $(MCFLAGS) $(OPT) $(CWARN) -Wa,-alms=$(BUILDDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
LDFLAGS += $(LLIBDIR)
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)
ifeq ($(EMULATION),)
CFLAGS += -mthumb -mno-thumb-interwork -DTHUMB
LDFLAGS += -mthumb -mno-thumb-interwork
endif
CFLAGS += -MD -MP -MF .dep/$(@F).d
@@ -56,6 +73,7 @@ $(OBJS) : $(BUILDDIR)/%.o : %.c Makefile
@echo
$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
ifeq ($(EMULATION),)
%.elf: $(OBJS) $(OBJS_ADD) $(LDSCRIPT)
@echo
$(LD) $(OBJS) $(OBJS_ADD) $(LDFLAGS) $(LIBS) -o $@
@@ -65,6 +83,11 @@ $(OBJS) : $(BUILDDIR)/%.o : %.c Makefile
%.hex: %.elf $(LDSCRIPT)
$(OBJCOPY) -O ihex $< $@
else
$(BUILDDIR)/$(PROJECT): $(OBJS) $(OBJS_ADD)
@echo
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(OBJS_ADD) $(LIBS)
endif
clean:
-rm -f -r .dep $(BUILDDIR)