diff --git a/demos/ARM7-LPC214x-GCC-minimal/Makefile b/demos/ARM7-LPC214x-GCC-minimal/Makefile index 3514a9090..1fe22d71a 100644 --- a/demos/ARM7-LPC214x-GCC-minimal/Makefile +++ b/demos/ARM7-LPC214x-GCC-minimal/Makefile @@ -127,16 +127,16 @@ ODFLAGS = -x --syms # Thumb interwork enabled only if needed because it kills performance. ifneq ($(TSRC),) + CPFLAGS += -D THUMB_PRESENT ifneq ($(ASRC),) - # Both ARM and THUMB case - CPFLAGS += -mthumb-interwork -D THUMB + # Mixed ARM and THUMB case. + CPFLAGS += -mthumb-interwork LDFLAGS += -mthumb-interwork - ASFLAGS += -mthumb-interwork -D THUMB else - # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly - CPFLAGS += -D THUMB + # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly. + CPFLAGS += -D THUMB_NO_INTERWORKING LDFLAGS += -mthumb - ASFLAGS += -mthumb-interwork -D THUMB -D THUMB_NO_INTERWORKING + ASFLAGS += -D THUMB_NO_INTERWORKING endif endif diff --git a/demos/ARM7-LPC214x-GCC-minimal/Makefile.thumb b/demos/ARM7-LPC214x-GCC-minimal/Makefile.thumb index 76b3fd296..b00adef75 100644 --- a/demos/ARM7-LPC214x-GCC-minimal/Makefile.thumb +++ b/demos/ARM7-LPC214x-GCC-minimal/Makefile.thumb @@ -91,7 +91,7 @@ ULIBS = AOPT = # THUMB-specific options here -TOPT = -mthumb +TOPT = -mthumb -D THUMB # Common options here # NOTE: -ffixed-r7 is only needed if you enabled CH_CURRP_REGISTER_CACHE in @@ -127,16 +127,16 @@ ODFLAGS = -x --syms # Thumb interwork enabled only if needed because it kills performance. ifneq ($(TSRC),) + CPFLAGS += -D THUMB_PRESENT ifneq ($(ASRC),) - # Both ARM and THUMB case - CPFLAGS += -mthumb-interwork -D THUMB + # Mixed ARM and THUMB case. + CPFLAGS += -mthumb-interwork LDFLAGS += -mthumb-interwork - ASFLAGS += -mthumb-interwork -D THUMB else - # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly - CPFLAGS += -D THUMB -D THUMB_NO_INTERWORKING + # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly. + CPFLAGS += -D THUMB_NO_INTERWORKING LDFLAGS += -mthumb - ASFLAGS += -mthumb-interwork -D THUMB -D THUMB_NO_INTERWORKING + ASFLAGS += -D THUMB_NO_INTERWORKING endif endif diff --git a/demos/ARM7-LPC214x-GCC/Makefile b/demos/ARM7-LPC214x-GCC/Makefile index 13c32b4dc..5e49defda 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile +++ b/demos/ARM7-LPC214x-GCC/Makefile @@ -130,16 +130,16 @@ ODFLAGS = -x --syms # Thumb interwork enabled only if needed because it kills performance. ifneq ($(TSRC),) + CPFLAGS += -D THUMB_PRESENT ifneq ($(ASRC),) - # Both ARM and THUMB case - CPFLAGS += -mthumb-interwork -D THUMB + # Mixed ARM and THUMB case. + CPFLAGS += -mthumb-interwork LDFLAGS += -mthumb-interwork - ASFLAGS += -mthumb-interwork -D THUMB else - # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly - CPFLAGS += -D THUMB + # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly. + CPFLAGS += -D THUMB_NO_INTERWORKING LDFLAGS += -mthumb - ASFLAGS += -mthumb-interwork -D THUMB -D THUMB_NO_INTERWORKING + ASFLAGS += -D THUMB_NO_INTERWORKING endif endif @@ -158,7 +158,7 @@ $(AOBJS) : %.o : %.c $(TOBJS) : %.o : %.c @echo - $(CC) -c $(CPFLAGS) $(TOPT) -mthumb -I . $(INCDIR) $< -o $@ + $(CC) -c $(CPFLAGS) $(TOPT) -I . $(INCDIR) $< -o $@ $(ASMOBJS) : %.o : %.s @echo diff --git a/demos/ARM7-LPC214x-GCC/Makefile.thumb b/demos/ARM7-LPC214x-GCC/Makefile.thumb index 93188a528..89ccdfdc2 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile.thumb +++ b/demos/ARM7-LPC214x-GCC/Makefile.thumb @@ -94,7 +94,7 @@ ULIBS = AOPT = # THUMB-specific options here -TOPT = -mthumb +TOPT = -mthumb -D THUMB # Common options here # NOTE: -ffixed-r7 is only needed if you enabled CH_CURRP_REGISTER_CACHE in @@ -130,16 +130,16 @@ ODFLAGS = -x --syms # Thumb interwork enabled only if needed because it kills performance. ifneq ($(TSRC),) + CPFLAGS += -D THUMB_PRESENT ifneq ($(ASRC),) - # Both ARM and THUMB case - CPFLAGS += -mthumb-interwork -D THUMB + # Mixed ARM and THUMB case. + CPFLAGS += -mthumb-interwork LDFLAGS += -mthumb-interwork - ASFLAGS += -mthumb-interwork -D THUMB else - # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly - CPFLAGS += -D THUMB -D THUMB_NO_INTERWORKING + # Pure THUMB case, THUMB C code cannot be called by ARM asm code directly. + CPFLAGS += -D THUMB_NO_INTERWORKING LDFLAGS += -mthumb - ASFLAGS += -mthumb-interwork -D THUMB -D THUMB_NO_INTERWORKING + ASFLAGS += -D THUMB_NO_INTERWORKING endif endif diff --git a/ports/ARM7-LPC214x/GCC/chcore.c b/ports/ARM7-LPC214x/GCC/chcore.c index c8e2c61f7..fc4c01942 100644 --- a/ports/ARM7-LPC214x/GCC/chcore.c +++ b/ports/ARM7-LPC214x/GCC/chcore.c @@ -33,64 +33,71 @@ void _IdleThread(void *p) { } } -#ifdef THUMB +/* + * The following functions are present only if there is in the system any + * code compiled as THUMB that may invoke them. + * NOTE: The undefs are there in case this module is compiled in ARM mode but + * there are THUMB modules in the system. + */ +#ifdef THUMB_PRESENT +#undef chSysLock void chSysLock(void) { +#ifdef THUMB asm(".p2align 2,, \n\t" \ "mov r0, pc \n\t" \ "bx r0 \n\t" \ - ".code 32 \n\t" \ - "msr CPSR_c, #0x9F \n\t" \ + ".code 32 \n\t"); +#endif + + asm("msr CPSR_c, #0x9F \n\t" \ "bx lr \n\t"); } +#undef chSysUnlock void chSysUnlock(void) { +#ifdef THUMB asm(".p2align 2,, \n\t" \ "mov r0, pc \n\t" \ "bx r0 \n\t" \ - ".code 32 \n\t" \ - "msr CPSR_c, #0x1F \n\t" \ + ".code 32 \n\t"); +#endif + + asm("msr CPSR_c, #0x1F \n\t" \ "bx lr \n\t"); } #endif void chSysSwitchI(Context *oldp, Context *newp) { -#ifdef CH_CURRP_REGISTER_CACHE #ifdef THUMB asm(".p2align 2,, \n\t" \ "mov r2, pc \n\t" \ "bx r2 \n\t" \ - ".code 32 \n\t" \ - "stmfd sp!, {r4, r5, r6, r8, r9, r10, r11, lr} \n\t" \ - "str sp, [r0, #0] \n\t" \ - "ldr sp, [r1, #0] \n\t" \ - "ldmfd sp!, {r4, r5, r6, r8, r9, r10, r11, lr} \n\t" \ - "bx lr \n\t"); -#else /* !THUMB */ + ".code 32 \n\t"); +#endif + +#ifdef CH_CURRP_REGISTER_CACHE asm("stmfd sp!, {r4, r5, r6, r8, r9, r10, r11, lr} \n\t" \ "str sp, [r0, #0] \n\t" \ - "ldr sp, [r1, #0] \n\t" \ - "ldmfd sp!, {r4, r5, r6, r8, r9, r10, r11, pc} \n\t"); -#endif /* !THUMB */ -#else /* !CH_CURRP_REGISTER_CACHE */ -#ifdef THUMB - asm(".p2align 2,, \n\t" \ - "mov r2, pc \n\t" \ - "bx r2 \n\t" \ - ".code 32 \n\t" \ - "stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" \ - "str sp, [r0, #0] \n\t" \ - "ldr sp, [r1, #0] \n\t" \ - "ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" \ + "ldr sp, [r1, #0] \n\t"); +#ifdef THUMB_PRESENT + asm("ldmfd sp!, {r4, r5, r6, r8, r9, r10, r11, lr} \n\t" \ "bx lr \n\t"); -#else /* !THUMB */ +#else /* !THUMB_PRESENT */ + asm("ldmfd sp!, {r4, r5, r6, r8, r9, r10, r11, pc} \n\t"); +#endif /* !THUMB_PRESENT */ +#else /* !CH_CURRP_REGISTER_CACHE */ asm("stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" \ "str sp, [r0, #0] \n\t" \ - "ldr sp, [r1, #0] \n\t" \ - "ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, pc} \n\t"); -#endif /* !THUMB */ + "ldr sp, [r1, #0] \n\t"); +#ifdef THUMB_PRESENT + asm("ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr} \n\t" \ + "bx lr \n\t"); +#else /* !THUMB_PRESENT */ + asm("ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, pc} \n\t"); +#endif /* !THUMB_PRESENT */ #endif /* !CH_CURRP_REGISTER_CACHE */ } @@ -151,7 +158,7 @@ void IrqCommon(void) { */ asm(".set MODE_IRQ, 0x12 \n\t" \ ".set MODE_SYS, 0x1F \n\t" \ - ".set F_BIT, 0x40 \n\t" \ + ".set F_BIT, 0x40 \n\t" \ ".set I_BIT, 0x80 \n\t" \ "ldmfd sp!, {r0-r3, r12, lr} \n\t" \ "msr CPSR_c, #MODE_SYS | I_BIT \n\t" \ diff --git a/readme.txt b/readme.txt index 5b9082822..f8ad8dbcc 100644 --- a/readme.txt +++ b/readme.txt @@ -50,16 +50,22 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet. various mechanisms and the correct use cases. - RT Semaphores subsystem removed, the Mutexes implements a better solution for the same problem. +- Added mutexes test cases to the test suite. - Modified the test suite in order to have each test case to have the same alignment enforced on functions. This is done to reduce MAM/Cache alignment effects on the measurement. - IRQ entry/exit code is now encapsulated into two new macros, see chcore.h for details. - All the asm code previously in chcore2.s is now inline asm code in chcore.c - (ARM port). + (ARM port), chcore2.s removed. - Moved all the board specific definitions/code into two new files: board.c and board.h. Moved all the files no more board-dependent under ports/ (ARM port). +- Improved the kernel performance in THUMB mode by better exploiting MAM + locality in some critical functions. The context switch benchmark shows 5% + improved speed. + NOTE: The interworking code generated by GCC (or any other compiler as far + I know) is not MAM-aware. *** 0.4.5 *** - Moved the serial IRQ handlers and VIC vectors initialization inside the