context.asm 4.0 KB
Newer Older
D
dzzxzz 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * 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
13
 * 2010-04-19     fify         rewrite rt_hw_interrupt_disable/enable fuction
D
dzzxzz 已提交
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
 *
 * For       : Renesas M16C
 * Toolchain : IAR's EW for M16C v3.401
*/

    RSEG        CSTACK

    RSEG        ISTACK

    RSEG        CODE(1)

    EXTERN    rt_thread_switch_interrput_flag
    EXTERN    rt_interrupt_from_thread
    EXTERN    rt_interrupt_to_thread
    EXTERN    rt_interrupt_enter
    EXTERN    rt_tick_increase
    EXTERN    rt_interrupt_leave
    EXTERN    u0rec_handler

    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    rt_hw_timer_handler
    PUBLIC    rt_hw_uart0_receive_handler
40
    PUBLIC    os_context_switch
D
dzzxzz 已提交
41 42

rt_hw_interrupt_disable
43 44
    STC      FLG, R0    ;fify 20100419
    FCLR     I
D
dzzxzz 已提交
45 46 47
    RTS

rt_hw_interrupt_enable
48
    LDC      R0, FLG    ;fify 20100419
D
dzzxzz 已提交
49 50
    RTS
    
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    .EVEN
os_context_switch:
    PUSHM    R0,R1,R2,R3,A0,A1,SB,FB
    CMP.W    #0,rt_thread_switch_interrput_flag
    JEQ      exit
    MOV.W    #0, rt_thread_switch_interrput_flag
    MOV.W    rt_interrupt_from_thread, A0
    STC      ISP, [A0]    
    MOV.W    rt_interrupt_to_thread, A0
    LDC      [A0], ISP
exit
    POPM     R0,R1,R2,R3,A0,A1,SB,FB             ; Restore registers from the new task's stack
    REIT                                         ; Return from interrup    
    
/*
 * void rt_hw_context_switch_to(rt_uint32 to);
 * r0 --> to
 * this fucntion is used to perform the first thread switch
 */
D
dzzxzz 已提交
70 71 72
rt_hw_context_switch_to
    MOV.W    R0, A0
    LDC      [A0], ISP
73
    POPM     R0,R1,R2,R3,A0,A1,SB,FB
D
dzzxzz 已提交
74
    REIT
75 76 77 78 79 80 81 82 83 84

rt_hw_context_switch
    CMP.W    #1,rt_thread_switch_interrput_flag
    JEQ      jump1
    MOV.W    #1,rt_thread_switch_interrput_flag
    MOV.W    R0, rt_interrupt_from_thread
jump1
    MOV.W    R1, rt_interrupt_to_thread
    INT      #0
    RTS
D
dzzxzz 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  
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
jump
    MOV.W    R1, rt_interrupt_to_thread
    RTS

rt_hw_context_switch_interrupt_do
    MOV.W    #0, rt_thread_switch_interrput_flag    
    MOV.W    rt_interrupt_from_thread, A0
    STC      ISP, [A0]    
    
    MOV.W    rt_interrupt_to_thread, A0
    LDC      [A0], ISP
102 103
    POPM     R0,R1,R2,R3,A0,A1,SB,FB             ; Restore all processor registers from the new task's stack
    REIT
D
dzzxzz 已提交
104 105 106 107 108 109 110 111 112 113 114
    
    .EVEN
rt_hw_timer_handler:
    PUSHM    R0,R1,R2,R3,A0,A1,SB,FB             ; Save current task's registers
    JSR      rt_interrupt_enter                   
    JSR      rt_tick_increase                           
    JSR      rt_interrupt_leave

    CMP.W    #1,rt_thread_switch_interrput_flag
    JEQ      rt_hw_context_switch_interrupt_do
    
115
    POPM     R0,R1,R2,R3,A0,A1,SB,FB             ; Restore current task's registers
D
dzzxzz 已提交
116 117 118 119 120 121 122 123 124 125 126 127
    REIT                                         ; Return from interrup

    .EVEN
rt_hw_uart0_receive_handler:
    PUSHM    R0,R1,R2,R3,A0,A1,SB,FB             ; Save current task's registers
    JSR      rt_interrupt_enter 
    JSR      u0rec_handler                         
    JSR      rt_interrupt_leave

    CMP.W    #1, rt_thread_switch_interrput_flag
    JEQ      rt_hw_context_switch_interrupt_do
    
128
    POPM     R0,R1,R2,R3,A0,A1,SB,FB             ; Restore current task's registers
D
dzzxzz 已提交
129 130 131
    REIT                                         ; Return from interrup

    END