1 ##=============================================================================
5 ## MN10300 context switch code
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.
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.
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
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.
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.
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.
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####
44 ## Contributors: nickg
46 ## Purpose: MN10300 context switch code
47 ## Description: This file contains implementations of the thread context
48 ## switch routines. It also contains the longjmp() and setjmp()
51 ######DESCRIPTIONEND####
53 ##=============================================================================
55 #include <pkgconf/hal.h>
57 #include <cyg/hal/arch.inc>
59 #------------------------------------------------------------------------------
60 # hal_thread_switch_context
61 # Switch thread contexts
62 # D0 = address of sp of next thread to execute
63 # D1 = address of sp save location of current thread
65 .global _hal_thread_switch_context
66 _hal_thread_switch_context:
67 add -8,sp # space for SP and PSW
68 mov d2,a0 # move d2->a0 since PSW can only be
69 # saved to a data register
70 hal_cpu_get_psw d2 # save PSW to d2
71 mov d2,(4,sp) # store in stack loc
72 mov a0,d2 # retrieve old d2 value
73 hal_cpu_save_all # save entire register set
74 mov d1,a2 # move save loc addr to A2
75 mov sp,(0,a2) # store SP in save location
77 # Now load the destination thread by dropping through
78 # to hal_thread_load_context
80 #------------------------------------------------------------------------------
81 # hal_thread_load_context
83 # D0 = address of sp of next thread to execute
84 # Note that this function is also the second half of hal_thread_switch_context
85 # and is simply dropped into from it.
87 .global _hal_thread_load_context
88 _hal_thread_load_context:
90 mov d0,a2 # move next sp loc to a2
91 mov (0,a2),sp # load SP with new value
92 hal_cpu_load_all # load whole register set
93 mov (4,sp),d1 # retrieve saved PSW
94 hal_cpu_set_psw d1 # and restore it
95 add 8,sp # skip saved SP and PSW
98 ##-----------------------------------------------------------------------------
99 ## HAL longjmp(), setjmp() implementations
100 ## These implementations omit the usual movm [d2,d3,a2,a3],(sp)
101 ## Which is the first instruction of all C compiled functions.
102 ## Note: These definitions are repeated in hal_arch.h. If changes are required
103 ## remember to update both sets.
105 #define CYGARC_JMP_BUF_SP 0
106 #define CYGARC_JMP_BUF_D2 1
107 #define CYGARC_JMP_BUF_D3 2
108 #define CYGARC_JMP_BUF_A2 3
109 #define CYGARC_JMP_BUF_A3 4
110 #define CYGARC_JMP_BUF_LR 5
112 #define CYGARC_JMP_BUF_SIZE 6
115 # This just preserves the callee save registers
117 # setjmp cannot use movm to do this as we need to keep
118 # the sp underneath all live data at all times.
120 _hal_setjmp: # d0=env
122 mov d2,(CYGARC_JMP_BUF_D2*4,a0)
123 mov d3,(CYGARC_JMP_BUF_D3*4,a0)
124 mov a2,(CYGARC_JMP_BUF_A2*4,a0)
125 mov a3,(CYGARC_JMP_BUF_A3*4,a0)
126 mov mdr,d1 # link saved by call (also in (0,sp))
127 mov d1,(CYGARC_JMP_BUF_LR*4,a0)
129 mov a1,(CYGARC_JMP_BUF_SP*4,a0) # a1==(caller''s sp)
133 # longjmp returns to caller of setjmp
134 # after restoring callee save registers
138 mov (CYGARC_JMP_BUF_D2*4,a0),d2
139 mov (CYGARC_JMP_BUF_D3*4,a0),d3
140 mov (CYGARC_JMP_BUF_A2*4,a0),a2
141 mov (CYGARC_JMP_BUF_A3*4,a0),a3
142 mov (CYGARC_JMP_BUF_LR*4,a0),d0
144 mov (CYGARC_JMP_BUF_SP*4,a0),a1 # stashed (caller''s sp)
146 mov d0,(0,sp) # put link on stack
147 mov d1,d0 # return arg1
148 ret [],0 # this ignores (0,sp) and does pc=mdr
151 #------------------------------------------------------------------------------