context_iar.S 2.2 KB
Newer Older
D
dzzxzz 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * File      : context.asm
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2009, 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-04-09     fify         the first version
 * 2010-04-19     fify         rewrite rt_hw_interrupt_disable/enable fuction
 * 2010-04-20     fify         move peripheral ISR to bsp/interrupts.s34 
 *
 * For       : Renesas M16C
 * Toolchain : IAR's EW for M16C v3.401
D
dzzxzz 已提交
18
 */
D
dzzxzz 已提交
19

D
dzzxzz 已提交
20
    RSEG    CSTACK
D
dzzxzz 已提交
21

D
dzzxzz 已提交
22
    RSEG    ISTACK
D
dzzxzz 已提交
23

D
dzzxzz 已提交
24
    RSEG    CODE(1)
D
dzzxzz 已提交
25

D
dzzxzz 已提交
26 27 28
    EXTERN  rt_thread_switch_interrput_flag
    EXTERN  rt_interrupt_from_thread
    EXTERN  rt_interrupt_to_thread
D
dzzxzz 已提交
29

D
dzzxzz 已提交
30 31 32 33 34 35
    PUBLIC  rt_hw_interrupt_disable
    PUBLIC  rt_hw_interrupt_enable
    PUBLIC  rt_hw_context_switch_to
    PUBLIC  rt_hw_context_switch
    PUBLIC  rt_hw_context_switch_interrupt
    PUBLIC  os_context_switch
D
dzzxzz 已提交
36

D
dzzxzz 已提交
37 38 39
rt_hw_interrupt_disable:
    STC     FLG, R0    ;fify 20100419
    FCLR    I
D
dzzxzz 已提交
40 41
    RTS

D
dzzxzz 已提交
42 43
rt_hw_interrupt_enable:
    LDC     R0, FLG    ;fify 20100419
D
dzzxzz 已提交
44 45 46 47
    RTS
    
    .EVEN
os_context_switch:
D
dzzxzz 已提交
48 49 50 51 52 53 54 55 56
    PUSHM   R0,R1,R2,R3,A0,A1,SB,FB
    
    MOV.W   rt_interrupt_from_thread, A0
    STC     ISP, [A0]
    MOV.W   rt_interrupt_to_thread, A0
    LDC     [A0], ISP

    POPM    R0,R1,R2,R3,A0,A1,SB,FB             ; Restore registers from the new task's stack
    REIT                                        ; Return from interrup    
D
dzzxzz 已提交
57 58 59 60 61 62
    
/*
 * void rt_hw_context_switch_to(rt_uint32 to);
 * r0 --> to
 * this fucntion is used to perform the first thread switch
 */
D
dzzxzz 已提交
63 64 65 66
rt_hw_context_switch_to:
    MOV.W   R0, A0
    LDC     [A0], ISP
    POPM    R0,R1,R2,R3,A0,A1,SB,FB
D
dzzxzz 已提交
67 68
    REIT

D
dzzxzz 已提交
69 70 71 72
rt_hw_context_switch:
    MOV.W   R0, rt_interrupt_from_thread
    MOV.W   R1, rt_interrupt_to_thread
    INT     #0                                   ;software interrupt 0
D
dzzxzz 已提交
73 74
    RTS
  
D
dzzxzz 已提交
75 76 77 78 79
rt_hw_context_switch_interrupt:
    CMP.W   #1, rt_thread_switch_interrput_flag
    JEQ     jump
    MOV.W   #1, rt_thread_switch_interrput_flag
    MOV.W   R0, rt_interrupt_from_thread
D
dzzxzz 已提交
80
jump
D
dzzxzz 已提交
81
    MOV.W   R1, rt_interrupt_to_thread
D
dzzxzz 已提交
82 83 84
    RTS

    END