From 3d5ccfc3c08dd64f1923c09956406890d88fbc1f Mon Sep 17 00:00:00 2001 From: bernie Date: Sun, 10 Aug 2008 19:06:11 +0000 Subject: [PATCH] ppc: Add cooperative task switching for PowerPC git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1611 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/attr.h | 8 ++++++ bertos/emul/switch.S | 2 ++ bertos/emul/switch_ppc.S | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 bertos/emul/switch_ppc.S diff --git a/bertos/cpu/attr.h b/bertos/cpu/attr.h index bfcb705e..28986936 100644 --- a/bertos/cpu/attr.h +++ b/bertos/cpu/attr.h @@ -353,6 +353,14 @@ */ #define CPU_IDLE NOP +#elif CPU_PPC + + #define CPU_PUSH_CALL_CONTEXT(sp, func) \ + do { \ + CPU_PUSH_WORD((sp), (cpustack_t)(func)); /* LR -> 8(SP) */ \ + CPU_PUSH_WORD((sp), 0); /* CR -> 4(SP) */ \ + } while (0) + #else #define CPU_PUSH_CALL_CONTEXT(sp, func) \ CPU_PUSH_WORD((sp), (cpustack_t)(func)) diff --git a/bertos/emul/switch.S b/bertos/emul/switch.S index ce87cdce..50567d19 100644 --- a/bertos/emul/switch.S +++ b/bertos/emul/switch.S @@ -2,6 +2,8 @@ #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/emul/switch_ppc.S b/bertos/emul/switch_ppc.S new file mode 100644 index 00000000..082efa8e --- /dev/null +++ b/bertos/emul/switch_ppc.S @@ -0,0 +1,57 @@ +/** + * \file + * + * + * \version $Id: switch_i386.S 1578 2008-08-08 10:54:40Z bernie $ + * \author Bernie Innocenti + * + * \brief PowerPC context switch + */ + +#ifdef __APPLE__ + //This workaround is necessary to compile under OS X assembler. + #define SWITCH_CONTEXT _asm_switch_context +#else + #define SWITCH_CONTEXT asm_switch_context +#endif + +.balign 4 + +/* void asm_switch_context(void ** new_sp, void ** save_sp) */ +/* r3 r4 */ +.globl SWITCH_CONTEXT +SWITCH_CONTEXT: + mflr 0 /* r0 = lr */ + stw 0,8(1) /* store lr at *(sp+8) */ + stw 1,0(4) /* *save_sp = sp */ + lwz 1,0(3) /* sp = *new_sp */ + lwz 0,8(1) /* retrieve lr from *(sp+8) */ + mtlr 0 /* lr = r0 */ + blr /* return */ -- 2.25.1