From: batt Date: Fri, 10 Apr 2009 18:13:22 +0000 (+0000) Subject: Refactor switch context ASM files to comply to Wizard. X-Git-Tag: 2.1.0~192 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=71743c2a5a8bf9dbf66a945fd9656baed0d16329;p=bertos.git Refactor switch context ASM files to comply to Wizard. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2490 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/hw/switch_arm.S b/bertos/cpu/arm/hw/switch_arm.S index bde843cd..38ceff8e 100644 --- a/bertos/cpu/arm/hw/switch_arm.S +++ b/bertos/cpu/arm/hw/switch_arm.S @@ -1,53 +1,2 @@ -/** - * \file - * - * - * \brief ARM context switch - * - * \version $Id: proc.c 18271 2007-10-11 14:51:31Z batt $ - * - * \author Stefano Fedrigo - * \author Francesco Sacchi - */ - -/* void asm_switch_context(void **new_sp [r0], void **save_sp [r1]) */ -.globl asm_switch_context -asm_switch_context: - mrs r2, cpsr /* Save status. */ - stmfd sp!, {r2, r4-r11, lr} /* Save registers. */ - - str sp, [r1] /* Save old stack pointer. */ - ldr sp, [r0] /* Load new stack pointer */ - - ldmfd sp!, {r2, r4-r11, lr} /* Load new registers. */ - msr cpsr, r2 /* restore flags reg. */ - - mov pc, lr +#warning This file is deprecated, use switch_ctx_arm.S +#include "switch_ctx_arm.S" diff --git a/bertos/cpu/arm/hw/switch_ctx_arm.S b/bertos/cpu/arm/hw/switch_ctx_arm.S new file mode 100644 index 00000000..bde843cd --- /dev/null +++ b/bertos/cpu/arm/hw/switch_ctx_arm.S @@ -0,0 +1,53 @@ +/** + * \file + * + * + * \brief ARM context switch + * + * \version $Id: proc.c 18271 2007-10-11 14:51:31Z batt $ + * + * \author Stefano Fedrigo + * \author Francesco Sacchi + */ + +/* void asm_switch_context(void **new_sp [r0], void **save_sp [r1]) */ +.globl asm_switch_context +asm_switch_context: + mrs r2, cpsr /* Save status. */ + stmfd sp!, {r2, r4-r11, lr} /* Save registers. */ + + str sp, [r1] /* Save old stack pointer. */ + ldr sp, [r0] /* Load new stack pointer */ + + ldmfd sp!, {r2, r4-r11, lr} /* Load new registers. */ + msr cpsr, r2 /* restore flags reg. */ + + mov pc, lr diff --git a/bertos/cpu/avr/hw/switch_avr.S b/bertos/cpu/avr/hw/switch_avr.S index 50280292..e6d0edfa 100644 --- a/bertos/cpu/avr/hw/switch_avr.S +++ b/bertos/cpu/avr/hw/switch_avr.S @@ -1,142 +1,2 @@ -/*! - * \file - * - * - * \version $Id$ - * \author Bernie Innocenti - * \author Stefano Fedrigo - * - * \brief AVR context switch - * - */ - -#include - -/* void asm_switch_context(void **new_sp [r24:r25], void **save_sp [r22:r23]) */ -.globl asm_switch_context -asm_switch_context: - -; r0 is the TEMP REG and can be used freely. -; r1 is the ZERO REG and must always contain 0. -; -; Stack frame is 19 byte, remember to update -; CPU_SAVED_REGS_CNT if you change pushed regs. - - in r0,SREG-__SFR_OFFSET - push r0 -; push r1 ;zero-reg - push r2 - push r3 - push r4 - push r5 - push r6 - push r7 - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - push r16 - push r17 -; push r18 ;caller-save -; push r19 ;caller-save -; push r20 ;caller-save -; push r21 ;caller-save -; push r22 ;caller-save -; push r23 ;caller-save -; push r24 ;caller-save -; push r25 ;caller-save -; push r26 ;caller-save -; push r27 ;caller-save - push r28 - push r29 -; push r30 ;caller-save -; push r31 ;caller-save - - in r18,SPL-__SFR_OFFSET ; r18:r19 = SP - in r19,SPH-__SFR_OFFSET - movw r26,r22 ; X = save_sp - st X+,r18 ; *save_sp = SP - st X,r19 - movw r26,r24 ; X = new_sp - ld r18,X+ - ld r19,X - -; Set new stack pointer. -; AVR is an 8 bit processor so -; care must be taken when updating -; SP that is a 16 bit reg. -; Two instructions are required to update SP -; so an IRQ can sneak in between them. -; So IRQ *MUST* be disabled and then restored. - cli ; Disable interrupt - out SPL-__SFR_OFFSET,r18 ; SP = *new_sp - out SPH-__SFR_OFFSET,r19 - out SREG-__SFR_OFFSET,r0 ; Restore previous IRQ state - -; pop r31 ;caller-save -; pop r30 ;caller-save - pop r29 - pop r28 -; pop r27 ;caller-save -; pop r26 ;caller-save -; pop r25 ;caller-save -; pop r24 ;caller-save -; pop r23 ;caller-save -; pop r22 ;caller-save -; pop r21 ;caller-save -; pop r20 ;caller-save -; pop r19 ;caller-save -; pop r18 ;caller-save - pop r17 - pop r16 - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop r7 - pop r6 - pop r5 - pop r4 - pop r3 - pop r2 -; pop r1 ;zero-reg - pop r0 - out SREG-__SFR_OFFSET,r0 - - ret +#warning This file is deprecated, use switch_ctx_avr.S +#include "switch_ctx_avr.S" diff --git a/bertos/cpu/avr/hw/switch_ctx_avr.S b/bertos/cpu/avr/hw/switch_ctx_avr.S new file mode 100644 index 00000000..50280292 --- /dev/null +++ b/bertos/cpu/avr/hw/switch_ctx_avr.S @@ -0,0 +1,142 @@ +/*! + * \file + * + * + * \version $Id$ + * \author Bernie Innocenti + * \author Stefano Fedrigo + * + * \brief AVR context switch + * + */ + +#include + +/* void asm_switch_context(void **new_sp [r24:r25], void **save_sp [r22:r23]) */ +.globl asm_switch_context +asm_switch_context: + +; r0 is the TEMP REG and can be used freely. +; r1 is the ZERO REG and must always contain 0. +; +; Stack frame is 19 byte, remember to update +; CPU_SAVED_REGS_CNT if you change pushed regs. + + in r0,SREG-__SFR_OFFSET + push r0 +; push r1 ;zero-reg + push r2 + push r3 + push r4 + push r5 + push r6 + push r7 + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push r16 + push r17 +; push r18 ;caller-save +; push r19 ;caller-save +; push r20 ;caller-save +; push r21 ;caller-save +; push r22 ;caller-save +; push r23 ;caller-save +; push r24 ;caller-save +; push r25 ;caller-save +; push r26 ;caller-save +; push r27 ;caller-save + push r28 + push r29 +; push r30 ;caller-save +; push r31 ;caller-save + + in r18,SPL-__SFR_OFFSET ; r18:r19 = SP + in r19,SPH-__SFR_OFFSET + movw r26,r22 ; X = save_sp + st X+,r18 ; *save_sp = SP + st X,r19 + movw r26,r24 ; X = new_sp + ld r18,X+ + ld r19,X + +; Set new stack pointer. +; AVR is an 8 bit processor so +; care must be taken when updating +; SP that is a 16 bit reg. +; Two instructions are required to update SP +; so an IRQ can sneak in between them. +; So IRQ *MUST* be disabled and then restored. + cli ; Disable interrupt + out SPL-__SFR_OFFSET,r18 ; SP = *new_sp + out SPH-__SFR_OFFSET,r19 + out SREG-__SFR_OFFSET,r0 ; Restore previous IRQ state + +; pop r31 ;caller-save +; pop r30 ;caller-save + pop r29 + pop r28 +; pop r27 ;caller-save +; pop r26 ;caller-save +; pop r25 ;caller-save +; pop r24 ;caller-save +; pop r23 ;caller-save +; pop r22 ;caller-save +; pop r21 ;caller-save +; pop r20 ;caller-save +; pop r19 ;caller-save +; pop r18 ;caller-save + pop r17 + pop r16 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop r7 + pop r6 + pop r5 + pop r4 + pop r3 + pop r2 +; pop r1 ;zero-reg + pop r0 + out SREG-__SFR_OFFSET,r0 + + ret diff --git a/bertos/emul/switch.S b/bertos/emul/switch.S index 50567d19..110d62f5 100644 --- a/bertos/emul/switch.S +++ b/bertos/emul/switch.S @@ -1,10 +1,2 @@ -#if defined(__i386__) - #include "switch_i386.S" -#elif defined(__x86_64__) - #include "switch_x86_64.s" -#elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) - #include "switch_ppc.S" -#else - #error Unknown CPU -#endif - +#warning This file is deprecated, use switch_ctx_emul.S +#include "switch_ctx_emul.S" diff --git a/bertos/emul/switch_ctx_emul.S b/bertos/emul/switch_ctx_emul.S new file mode 100644 index 00000000..50567d19 --- /dev/null +++ b/bertos/emul/switch_ctx_emul.S @@ -0,0 +1,10 @@ +#if defined(__i386__) + #include "switch_i386.S" +#elif defined(__x86_64__) + #include "switch_x86_64.s" +#elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) + #include "switch_ppc.S" +#else + #error Unknown CPU +#endif + diff --git a/bertos/kern/proc.h b/bertos/kern/proc.h index b270d406..7ac632ec 100644 --- a/bertos/kern/proc.h +++ b/bertos/kern/proc.h @@ -37,6 +37,7 @@ * * $WIZ$ module_name = "kernel" * $WIZ$ module_configuration = "bertos/cfg/cfg_proc.h" + * $WIZ$ module_depends = "switch_ctx" */ #ifndef KERN_PROC_H diff --git a/examples/at91sam7s/at91sam7s.mk b/examples/at91sam7s/at91sam7s.mk index 1c3660e0..90d8016a 100644 --- a/examples/at91sam7s/at91sam7s.mk +++ b/examples/at91sam7s/at91sam7s.mk @@ -33,7 +33,7 @@ at91sam7s_CSRC = \ at91sam7s_CPPASRC = \ bertos/cpu/arm/hw/crtat91sam7_rom.S \ - bertos/cpu/arm/hw/switch_arm.S + bertos/cpu/arm/hw/switch_ctx_arm.S at91sam7s_PREFIX = arm-none-eabi- diff --git a/examples/demo/demo.mk b/examples/demo/demo.mk index d2588fd4..733b52c5 100644 --- a/examples/demo/demo.mk +++ b/examples/demo/demo.mk @@ -65,7 +65,7 @@ demo_CSRC = \ bertos/verstag.c demo_CPPASRC = \ - bertos/emul/switch.S + bertos/emul/switch_ctx_emul.S # FIXME: maybe this junk should go in emul/emul.mk? $(OBJDIR)/demo/bertos/emul/emulwin.o: bertos/emul/emulwin_moc.cpp diff --git a/test/run_tests.sh b/test/run_tests.sh index 78877add..90de1f04 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -27,7 +27,7 @@ TESTS=${TESTS:-`find . \ -o -name "*_test.c" -print` } TESTOUT="testout" -SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/emul/switch.S" +SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/emul/switch_ctx_emul.S" buildout='/dev/null' runout='/dev/null'