]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/h8300/arch/v2_0/src/context.S
RedBoot TX53 Release 2012-02-15
[karo-tx-redboot.git] / packages / hal / h8300 / arch / v2_0 / src / context.S
1 ##=============================================================================
2 ##
3 ##      context.S
4 ##
5 ##      H8/300 context switch code
6 ##
7 ##=============================================================================
8 #####ECOSGPLCOPYRIGHTBEGIN####
9 ## -------------------------------------------
10 ## This file is part of eCos, the Embedded Configurable Operating System.
11 ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 ##
13 ## eCos is free software; you can redistribute it and/or modify it under
14 ## the terms of the GNU General Public License as published by the Free
15 ## Software Foundation; either version 2 or (at your option) any later version.
16 ##
17 ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 ## for more details.
21 ##
22 ## You should have received a copy of the GNU General Public License along
23 ## with eCos; if not, write to the Free Software Foundation, Inc.,
24 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 ##
26 ## As a special exception, if other files instantiate templates or use macros
27 ## or inline functions from this file, or you compile this file and link it
28 ## with other works to produce a work based on this file, this file does not
29 ## by itself cause the resulting work to be covered by the GNU General Public
30 ## License. However the source code for this file must still be made available
31 ## in accordance with section (3) of the GNU General Public License.
32 ##
33 ## This exception does not invalidate any other reasons why a work based on
34 ## this file might be covered by the GNU General Public License.
35 ##
36 ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 ## at http://sources.redhat.com/ecos/ecos-license/
38 ## -------------------------------------------
39 #####ECOSGPLCOPYRIGHTEND####
40 ##=============================================================================
41 #######DESCRIPTIONBEGIN####
42 ##
43 ## Author(s):   yoshinori sato
44 ## Contributors:        yoshinori sato
45 ## Date:        2002-02-17
46 ## Purpose:     H8/300 context switch code
47 ## Description: This file contains implementations of the thread context 
48 ##              switch routines. It also contains the longjmp() and setjmp()
49 ##              routines.
50 ##
51 ######DESCRIPTIONEND####
52 ##
53 ##=============================================================================
54
55 #include <pkgconf/hal.h>
56
57 #include <cyg/hal/arch.inc>
58 #include <cyg/hal/basetype.h>
59
60
61 #ifdef CYGPKG_HAL_H8300_H8300H
62         .h8300h
63 #endif
64 #ifdef CYGPKG_HAL_H8300_H8S
65         .h8300s
66 #endif
67         
68 #------------------------------------------------------------------------------
69 # hal_thread_switch_context
70 # Switch thread contexts
71 # er0 = address of sp of next thread to execute
72 # er1 = address of sp save location of current thread
73
74         .global CYG_LABEL_DEFN(hal_thread_switch_context)
75 CYG_LABEL_DEFN(hal_thread_switch_context):
76         mov.w   @sp,r2          ; save ccr
77         stc     ccr,r2h
78         mov.w   r2,@sp
79         hal_cpu_save_context
80         mov.l   sp,@er1
81         
82         # Now load the destination thread by dropping through
83         # to hal_thread_load_context
84         
85 #------------------------------------------------------------------------------
86 # hal_thread_load_context
87 # Load thread context
88 # D0 = address of sp of next thread to execute
89 # Note that this function is also the second half of hal_thread_switch_context
90 # and is simply dropped into from it.
91         
92         .global CYG_LABEL_DEFN(hal_thread_load_context)
93 CYG_LABEL_DEFN(hal_thread_load_context):
94
95         mov.l   @er0,sp
96         hal_cpu_load_all
97         rte
98         
99 ##-----------------------------------------------------------------------------
100 ## HAL longjmp(), setjmp() implementations
101 ## These implementations omit the usual movm [d2,d3,a2,a3],(sp)
102 ## Which is the first instruction of all C compiled functions.  
103 ## Note: These definitions are repeated in hal_arch.h. If changes are required
104 ## remember to update both sets.
105
106 #define CYGARC_JMP_BUF_SP        0
107 #define CYGARC_JMP_BUF_ER3       1
108 #define CYGARC_JMP_BUF_ER4       2
109 #define CYGARC_JMP_BUF_ER5       3
110 #define CYGARC_JMP_BUF_ER6       4
111 #define CYGARC_JMP_BUF_PC        5
112
113 #define CYGARC_JMP_BUF_SIZE      6
114
115         
116         # This just preserves the callee save registers 
117         # namely a2,a3,d2,d3
118         # setjmp cannot use movm to do this as we need to keep 
119         # the sp underneath all live data at all times.
120         .globl CYG_LABEL_DEFN(hal_setjmp)
121 CYG_LABEL_DEFN(hal_setjmp):                              ; er0=env  
122         mov.l   er3,@(CYGARC_JMP_BUF_ER3*4,er0)
123         mov.l   er4,@(CYGARC_JMP_BUF_ER4*4,er0)
124         mov.l   er5,@(CYGARC_JMP_BUF_ER5*4,er0)
125         mov.l   er6,@(CYGARC_JMP_BUF_ER6*4,er0)
126         mov.l   @sp,er1
127         mov.l   er1,@(CYGARC_JMP_BUF_PC*4,er0)  
128         mov     sp,er1
129         mov     er1,@(CYGARC_JMP_BUF_SP*4,er0)
130         sub.l   er0,er0
131         rts
132
133         # longjmp returns to caller of setjmp
134         # after restoring callee save registers
135         .globl CYG_LABEL_DEFN(hal_longjmp)
136 CYG_LABEL_DEFN(hal_longjmp):    
137         mov.l   @(CYGARC_JMP_BUF_ER3*4,er0),er3
138         mov.l   @(CYGARC_JMP_BUF_ER4*4,er0),er4
139         mov.l   @(CYGARC_JMP_BUF_ER5*4,er0),er5
140         mov.l   @(CYGARC_JMP_BUF_ER6*4,er0),er6
141         mov.l   @(CYGARC_JMP_BUF_PC*4,er0),er2
142         mov.l   @(CYGARC_JMP_BUF_SP*4,er0),sp
143         mov.l   er2,@sp
144         mov.l   er1,er0
145         rts
146
147         
148 #------------------------------------------------------------------------------
149 # end of context.S
150
151