/* Register counts include SREG too */
#define CPU_REG_BITS 32
#define CPU_REGS_CNT 16
- #define CPU_SAVED_REGS_CNT FIXME
+ #define CPU_SAVED_REGS_CNT 9
#define CPU_STACK_GROWS_UPWARD 0
#define CPU_SP_ON_EMPTY_SLOT 0
#define CPU_BYTE_ORDER (__BIG_ENDIAN__ ? CPU_BIG_ENDIAN : CPU_LITTLE_ENDIAN)
); \
} while (0)
- #define IRQ_GETSTATE() \
+ #define CPU_READ_FLAGS() \
({ \
uint32_t sreg; \
asm volatile ( \
: "=r" (sreg) \
: /* no inputs */ \
); \
- !((sreg & 0xc0) == 0xc0); \
+ sreg; \
})
+ #define IRQ_GETSTATE() (!((CPU_READ_FLAGS() & 0xc0) == 0xc0))
+
+ /**
+ * Initialization value for registers in stack frame.
+ * The register index is not directly corrispondent to CPU
+ * register numbers, but is related to how are pushed to stack (\see asm_switch_context).
+ * Index (CPU_SAVED_REGS_CNT - 1) is the CPSR register:
+ * the initial value is taken from current CPSR.
+ */
+ #define CPU_REG_INIT_VALUE(reg) (reg == (CPU_SAVED_REGS_CNT - 1) ? CPU_READ_FLAGS() : 0)
+
#endif /* !__IAR_SYSTEMS_ICC_ */
#elif CPU_PPC
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2001,2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999,2000,2001 Bernardo Innocenti <bernie@develer.com>
+ *
+ * -->
+ *
+ * \brief ARM context switch
+ *
+ * \version $Id: proc.c 18271 2007-10-11 14:51:31Z batt $
+ *
+ * \author Stefano Fedrigo <aleph@develer.com>
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+
+/*
+ * NOTE: At each change of this function affecting proc.c
+ * (i.e. arguments, data stored in the stack) bump up version
+ * number in asm_switch_version().
+ */
+
+/* void asm_switch_context(void **new_sp, void **save_sp) */
+.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
+
+
+/* int asm_switch_version(void) */
+.globl asm_switch_version
+asm_switch_version:
+ mov r0, #1
+ mov pc, lr