Skip to content

Commit a20d88c

Browse files
committed
arch/tricore: support C preprocessing for tasking asm
Support including nuttx/config.h and #if on CONFIG_* in tasking .asm sources by preprocessing them with ctc -E before assembly. 1. ctc -E runs as a pre-pass since the astc assembler has no C preprocessor of its own. 2. Comments in asm must not contain lone apostrophes since ctc -E reads them as unterminated C character constants. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
1 parent 3fd1851 commit a20d88c

5 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎arch/tricore/include/arch.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
* Public Types
7474
****************************************************************************/
7575

76+
#ifndef __ASSEMBLY__
77+
7678
/****************************************************************************
7779
* Public Function Prototypes
7880
****************************************************************************/
@@ -86,4 +88,6 @@ extern "C"
8688
}
8789
#endif
8890

91+
#endif /* __ASSEMBLY__ */
92+
8993
#endif /* __ARCH_TRICORE_INCLUDE_ARCH_H */

‎arch/tricore/include/irq.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
#define REG_LPC REG_LA11
103103

104104
#define TC_CONTEXT_REGS (16)
105-
#define TC_CONTEXT_SIZE (sizeof(void *) * TC_CONTEXT_REGS)
105+
#define TC_CONTEXT_SIZE (4 * TC_CONTEXT_REGS)
106106

107107
#define XCPTCONTEXT_REGS (TC_CONTEXT_REGS * 2)
108108
#define XCPTCONTEXT_SIZE (sizeof(void *) * XCPTCONTEXT_REGS)

‎arch/tricore/src/cmake/tasking.cmake‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ set(CMAKE_CXX_COMPILE_OBJECT
5151
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> --create <SOURCE> -o <OBJECT>"
5252
)
5353

54+
# The astc assembler has no C preprocessor and .asm files need explicit
55+
# preprocessing with ctc -E.
56+
57+
set(CMAKE_ASM_COMPILE_OBJECT
58+
"ctc -E <DEFINES> <INCLUDES> <SOURCE> -o <OBJECT>.pp.asm && <CMAKE_ASM_COMPILER> <FLAGS> -c <OBJECT>.pp.asm -o <OBJECT>"
59+
)
60+
5461
if(CMAKE_GENERATOR MATCHES "Ninja")
5562
set(CMAKE_C_RESPONSE_FILE_FLAG "-f ${CMAKE_BINARY_DIR}/")
5663
set(CMAKE_CXX_RESPONSE_FILE_FLAG "-f ${CMAKE_BINARY_DIR}/")

‎arch/tricore/src/common/ToolchainTasking.defs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,13 @@ CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden
165165

166166
LDELFFLAGS = -r -e _start
167167
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)elf$(DELIM)gnu-elf.ld)
168+
169+
# The astc assembler has no C preprocessor and .asm files need explicit preprocessing with ctc -E.
170+
171+
define ASSEMBLE
172+
$(ECHO_BEGIN)"AS: $1 "
173+
$(Q) ctc -E $(filter-out --%,$(AFLAGS)) $1 $($(strip $1)_AFLAGS) -o $2.pp.asm
174+
$(Q) $(CC) -c $(AFLAGS) $2.pp.asm $($(strip $1)_AFLAGS) -o $2
175+
$(call DELFILE,$2.pp.asm)
176+
$(ECHO_END)
177+
endef

‎libs/libc/machine/tricore/tasking/arch_setjmp.asm‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
; 32: a12 36: a13 40: a14 44: a15
3939
; 48: d12 52: d13 56: d14 60: d15
4040
;
41-
; On entry a11 holds the caller's return address (TriCore call ABI).
41+
; On entry a11 holds the return address of the caller (TriCore call ABI).
4242
; Save it into env[12] first, then repoint a11 at .Lsaveregs and execute
43-
; `ret' which jumps through a11. The fall-through at .Lsaveregs stores
43+
; `ret` which jumps through a11. The fall-through at .Lsaveregs stores
4444
; the remaining callee-saved registers and the PCXI/PSW control registers,
4545
; loads the saved return address into a2, sets d2 = 0, and jumps back
4646
; to the caller. longjmp() returns through the same path with a nonzero
@@ -98,7 +98,7 @@ setjmp: .type func
9898
; The result passed back equals max(val, 1) per POSIX.
9999
;
100100
; The unwind loop forces PSW.IO = Supervisor and PSW.PRS[2] = 0 on every
101-
; iteration so that the `ret'-released upper contexts do not drop the CPU
101+
; iteration so that the `ret`-released upper contexts do not drop the CPU
102102
; into user mode while env is still being accessed. Once the loop exits,
103103
; the original PSW saved at setjmp time is restored before the indirect
104104
; jump back to the setjmp call site.
@@ -165,7 +165,7 @@ longjmp: .type func
165165
j .Lloop
166166

167167
.Lupper:
168-
; Release one upper context via `ret' (restores the upper context
168+
; Release one upper context via `ret` (restores the upper context
169169
; from CSA and jumps through a11). Point a11 back at .Lloop so
170170
; we re-enter the depth check after the release.
171171

0 commit comments

Comments
 (0)