context_gcc.S 2.6 KB
Newer Older
K
kyle.hu.gz 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/*
 * File      : context.S
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2010, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-03-27     Kyle         First version
 */

#define AVR32_SR			0
#define AVR32_SR_GM_OFFSET	16

.text

/*
 * rt_base_t rt_hw_interrupt_disable()
 */
.globl rt_hw_interrupt_disable
.type rt_hw_interrupt_disable, %function
rt_hw_interrupt_disable:
	ssrf	AVR32_SR_GM_OFFSET
	mov		pc, lr

/*
 * void rt_hw_interrupt_enable(rt_base_t level)
 */
.globl rt_hw_interrupt_enable
.type rt_hw_interrupt_enable, %function
rt_hw_interrupt_enable:
	csrf	AVR32_SR_GM_OFFSET
	mov		pc, lr

/*
 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)/*
 * r8 --> from
 * r9 --> to
 */
.globl rt_hw_context_switch
.type rt_hw_context_switch, %function
rt_hw_context_switch:
	ssrf	AVR32_SR_GM_OFFSET	/* Disable global interrupt */
	stm		--sp, r8-r12, lr	/* Push R8-R12, LR */
	st.w	--sp, lr			/* Push LR (instead of PC) */
	mfsr	r8, AVR32_SR		/* Read Status Register */
	cbr		r8, AVR32_SR_GM_OFFSET	/* Clear GM bit */
	st.w	--sp, r8			/* Push SR */
	stm		--sp, r0-r7			/* Push R0-R7 */
								/* Stack layout: R8-R12, LR, PC, SR, R0-R7 */

	st.w	r12[0], sp			/* Store SP in preempted tasks TCB */
	ld.w	sp, r11[0]			/* Get new task stack pointer */

	ldm		sp++, r0-r7			/* pop R0-R7 */
	ld.w	r8, sp++			/* pop SR */
	mtsr	AVR32_SR, r8		/* Restore SR */
	ldm		sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume to thread */

/*
 * void rt_hw_context_switch_to(rt_uint32 to)/*
 * r0 --> to
 */
.globl rt_hw_context_switch_to
.type rt_hw_context_switch_to, %function
rt_hw_context_switch_to:
	ld.w	sp, r12[0]			/* Get new task stack pointer */

	ldm		sp++, r0-r7			/* pop R0-R7 */
	ld.w	r8, sp++			/* pop SR */
	mtsr	AVR32_SR, r8		/* Restore SR */
	ldm		sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume execution */

/*
 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
 */
.globl rt_thread_switch_interrupt_flag
.globl rt_interrupt_from_thread
.globl rt_interrupt_to_thread
.globl rt_hw_context_switch_interrupt
.type rt_hw_context_switch_interrupt, %function
rt_hw_context_switch_interrupt:
	lda.w	r8, rt_thread_switch_interrupt_flag
	ld.w	r9, r8[0]
	cp.w	r9, 1
	breq	_reswitch
	mov		r9, 1
	st.w	r8[0], r9
	lda.w	r8, rt_interrupt_from_thread
	st.w	r8[0], r12
_reswitch:
	lda.w	r8, rt_interrupt_to_thread
	st.w	r8[0], r11
	mov		pc, lr