Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/tricore: add support of tricore gcc toolchain #12682

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion arch/tricore/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ comment "Tricore Options"

choice
prompt "Tricore Toolchain Selection"
default TRICORE_TOOLCHAIN_TASKING
default TRICORE_TOOLCHAIN_GNU

config TRICORE_TOOLCHAIN_TASKING
bool "AURIX Tasking C/C++ toolchain"
select ARCH_TOOLCHAIN_TASKING

config TRICORE_TOOLCHAIN_GNU
bool "Generic GNU toolchain"
select ARCH_TOOLCHAIN_GNU
---help---
This option should work for any modern GNU toolchain (GCC 4.5 or newer)

endchoice # Tricore Toolchain Selection

config ARCH_TC3XX
Expand Down
4 changes: 4 additions & 0 deletions arch/tricore/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ void up_irq_enable(void);

noinstrument_function static inline uintptr_t up_getsp(void)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
return (uintptr_t)__get_sp();
#else
return __builtin_frame_address(0);
#endif
}

/****************************************************************************
Expand Down
108 changes: 108 additions & 0 deletions arch/tricore/include/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@

static inline uintptr_t sys_call0(unsigned int nbr)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -146,6 +147,17 @@ static inline uintptr_t sys_call0(unsigned int nbr)
: "i"(SYS_syscall), "d"(nbr)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -154,6 +166,7 @@ static inline uintptr_t sys_call0(unsigned int nbr)

static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -171,6 +184,18 @@ static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we share the same implementation between tasking and gcc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the syntax of tasking and gnuc is incompatible

register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -180,6 +205,7 @@ static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
uintptr_t parm2)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -198,6 +224,19 @@ static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
register long reg2 __asm__("d10") = (long)(parm2);
register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1), "d"(reg2)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -207,6 +246,7 @@ static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
uintptr_t parm2, uintptr_t parm3)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -226,6 +266,20 @@ static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
register long reg3 __asm__("d11") = (long)(parm3);
register long reg2 __asm__("d10") = (long)(parm2);
register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1), "d"(reg2), "d"(reg3)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -236,6 +290,7 @@ static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1,
uintptr_t parm2, uintptr_t parm3,
uintptr_t parm4)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -256,6 +311,22 @@ static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1,
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
register long reg4 __asm__("d12") = (long)(parm4);
register long reg3 __asm__("d11") = (long)(parm3);
register long reg2 __asm__("d10") = (long)(parm2);
register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1), "d"(reg2),
"d"(reg3), "d"(reg4)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -266,6 +337,7 @@ static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1,
uintptr_t parm2, uintptr_t parm3,
uintptr_t parm4, uintptr_t parm5)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -287,6 +359,23 @@ static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1,
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
register long reg5 __asm__("d13") = (long)(parm5);
register long reg4 __asm__("d12") = (long)(parm4);
register long reg3 __asm__("d11") = (long)(parm3);
register long reg2 __asm__("d10") = (long)(parm2);
register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1), "d"(reg2),
"d"(reg3), "d"(reg4), "d"(reg5)
: "memory", "a11"
);
#endif

return reg0;
}
Expand All @@ -298,6 +387,7 @@ static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
uintptr_t parm4, uintptr_t parm5,
uintptr_t parm6)
{
#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
register long reg0;

__asm volatile
Expand All @@ -321,6 +411,24 @@ static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
: "i"(SYS_syscall)
: "memory", "a11"
);
#else
register long reg0 __asm__("d8") = (long)(nbr);
register long reg6 __asm__("d14") = (long)(parm6);
register long reg5 __asm__("d13") = (long)(parm5);
register long reg4 __asm__("d12") = (long)(parm4);
register long reg3 __asm__("d11") = (long)(parm3);
register long reg2 __asm__("d10") = (long)(parm2);
register long reg1 __asm__("d9") = (long)(parm1);

__asm__ __volatile__
(
"syscall %1"
: "=d"(reg0)
: "i"(SYS_syscall), "d"(reg0), "d"(reg1), "d"(reg2),
"d"(reg3), "d"(reg4), "d"(reg5), "d"(reg6)
: "memory", "a11"
);
#endif

return reg0;
}
Expand Down
1 change: 1 addition & 0 deletions arch/tricore/include/tc3xx/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
****************************************************************************/

#include <nuttx/config.h>
#include <IfxCpu_Intrinsics.h>

/****************************************************************************
* Pre-processor Prototypes
Expand Down
38 changes: 34 additions & 4 deletions arch/tricore/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,29 @@ $(foreach lib,$(notdir $(wildcard $(APPDIR)$(DELIM)staging$(DELIM)*$(LIBEXT))),
EXTRA_LIBS := $(filter-out $(NAMEFULL_LIBS) $(NAMESPEC_LIBS),$(EXTRA_LIBS))
EXTRA_LIBS += $(wildcard $(APPDIR)$(DELIM)staging$(DELIM)*$(LIBEXT))

LIBPATH_OPT = --library-directory=
SCRIPT_OPT = --lsl-file=
LIBRARY_OPT = -l
ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),y)
LIBPATH_OPT = --library-directory=
SCRIPT_OPT = --lsl-file=
LIBRARY_OPT = -l
else
LDFLAGS := $(addprefix -Xlinker ,$(LDFLAGS))
LDFLAGS += $(CFLAGS)

LIBPATH_OPT = -L
SCRIPT_OPT = -T
LIBRARY_OPT = -l
endif

ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),y)
LDFLAGS += $(addprefix $(SCRIPT_OPT),$(call CONVERT_PATH,$(ARCHSCRIPT))) $(EXTRALINKCMDS)
else
ARCHSCRIPT := $(call CONVERT_PATH,$(ARCHSCRIPT))
LDFLAGS += $(addprefix $(SCRIPT_OPT),$(addsuffix .tmp,$(ARCHSCRIPT))) $(EXTRALINKCMDS)

LDSTARTGROUP ?= -Wl,--start-group
LDENDGROUP ?= -Wl,--end-group
endif

LDFLAGS += $(addprefix $(SCRIPT_OPT),$(call CONVERT_PATH,$(ARCHSCRIPT))) $(EXTRALINKCMDS)
LIBPATHS += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)staging)

BOARDMAKE = $(if $(wildcard board$(DELIM)Makefile),y,)
Expand Down Expand Up @@ -145,7 +163,16 @@ define LINK_ALLSYMS
$(Q) $(call DELFILE, allsyms.tmp allsyms$(OBJEXT))
endef

ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),)
$(addsuffix .tmp,$(ARCHSCRIPT)): $(ARCHSCRIPT)
$(call PREPROCESS, $(patsubst %.tmp,%,$@), $@)
endif

ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),y)
nuttx$(EXEEXT): $(HEAD_COBJ) board$(DELIM)libboard$(LIBEXT) $(ARCHSCRIPT) $(EXTRA_LIBS)
else
nuttx$(EXEEXT): $(HEAD_COBJ) board$(DELIM)libboard$(LIBEXT) $(EXTRA_LIBS) $(addsuffix .tmp,$(ARCHSCRIPT))
endif
$(Q) echo "LD: nuttx"
ifneq ($(CONFIG_ALLSYMS),y)
$(Q) $(LD) $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \
Expand All @@ -164,6 +191,9 @@ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
sort > $(TOPDIR)$(DELIM)System.map
endif
ifeq ($(CONFIG_TRICORE_TOOLCHAIN_TASKING),)
$(Q) $(call DELFILE, $(addsuffix .tmp,$(ARCHSCRIPT)))
endif

# This is part of the top-level export target
# Note that there may not be a head object if layout is handled
Expand Down
Loading
Loading