OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [arch/] [current/] [src/] [context.S] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
##=============================================================================
2
##
3
##      context.S
4
##
5
##      MN10300 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 Free Software Foundation, 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
16
## version.
17
##
18
## eCos is distributed in the hope that it will be useful, but WITHOUT
19
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
## for more details.
22
##
23
## You should have received a copy of the GNU General Public License
24
## along with eCos; if not, write to the Free Software Foundation, Inc.,
25
## 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
##
27
## As a special exception, if other files instantiate templates or use
28
## macros or inline functions from this file, or you compile this file
29
## and link it with other works to produce a work based on this file,
30
## this file does not by itself cause the resulting work to be covered by
31
## the GNU General Public License. However the source code for this file
32
## must still be made available in accordance with section (3) of the GNU
33
## General Public License v2.
34
##
35
## This exception does not invalidate any other reasons why a work based
36
## on this file might be covered by the GNU General Public License.
37
## -------------------------------------------
38
## ####ECOSGPLCOPYRIGHTEND####
39
##=============================================================================
40
#######DESCRIPTIONBEGIN####
41
##
42
## Author(s):   nickg
43
## Contributors:        nickg
44
## Date:        1998-04-27
45
## Purpose:     MN10300 context switch code
46
## Description: This file contains implementations of the thread context
47
##              switch routines. It also contains the longjmp() and setjmp()
48
##              routines.
49
##
50
######DESCRIPTIONEND####
51
##
52
##=============================================================================
53
 
54
#include 
55
 
56
#include 
57
 
58
#------------------------------------------------------------------------------
59
# hal_thread_switch_context
60
# Switch thread contexts
61
# D0 = address of sp of next thread to execute
62
# D1 = address of sp save location of current thread
63
 
64
        .global _hal_thread_switch_context
65
_hal_thread_switch_context:
66
        add     -8,sp           # space for SP and PSW
67
        mov     d2,a0           # move d2->a0 since PSW can only be
68
                                # saved to a data register
69
        hal_cpu_get_psw d2      # save PSW to d2
70
        mov     d2,(4,sp)       # store in stack loc
71
        mov     a0,d2           # retrieve old d2 value
72
        hal_cpu_save_all        # save entire register set
73
        mov     d1,a2           # move save loc addr to A2
74
        mov     sp,(0,a2)       # store SP in save location
75
 
76
        # Now load the destination thread by dropping through
77
        # to hal_thread_load_context
78
 
79
#------------------------------------------------------------------------------
80
# hal_thread_load_context
81
# Load thread context
82
# D0 = address of sp of next thread to execute
83
# Note that this function is also the second half of hal_thread_switch_context
84
# and is simply dropped into from it.
85
 
86
        .global _hal_thread_load_context
87
_hal_thread_load_context:
88
 
89
        mov     d0,a2           # move next sp loc to a2
90
        mov     (0,a2),sp       # load SP with new value
91
        hal_cpu_load_all        # load whole register set
92
        mov     (4,sp),d1       # retrieve saved PSW
93
        hal_cpu_set_psw d1      # and restore it
94
        add     8,sp            # skip saved SP and PSW
95
        ret     [],0            # and return
96
 
97
##-----------------------------------------------------------------------------
98
## HAL longjmp(), setjmp() implementations
99
## These implementations omit the usual movm [d2,d3,a2,a3],(sp)
100
## Which is the first instruction of all C compiled functions.
101
## Note: These definitions are repeated in hal_arch.h. If changes are required
102
## remember to update both sets.
103
 
104
#define CYGARC_JMP_BUF_SP        0
105
#define CYGARC_JMP_BUF_D2        1
106
#define CYGARC_JMP_BUF_D3        2
107
#define CYGARC_JMP_BUF_A2        3
108
#define CYGARC_JMP_BUF_A3        4
109
#define CYGARC_JMP_BUF_LR        5
110
 
111
#define CYGARC_JMP_BUF_SIZE      6
112
 
113
 
114
        # This just preserves the callee save registers
115
        # namely a2,a3,d2,d3
116
        # setjmp cannot use movm to do this as we need to keep
117
        # the sp underneath all live data at all times.
118
        .globl _hal_setjmp
119
_hal_setjmp:                    # d0=env
120
        mov     d0,a0           # env
121
        mov     d2,(CYGARC_JMP_BUF_D2*4,a0)
122
        mov     d3,(CYGARC_JMP_BUF_D3*4,a0)
123
        mov     a2,(CYGARC_JMP_BUF_A2*4,a0)
124
        mov     a3,(CYGARC_JMP_BUF_A3*4,a0)
125
        mov     mdr,d1          # link saved by call (also in (0,sp))
126
        mov     d1,(CYGARC_JMP_BUF_LR*4,a0)
127
        mov     sp,a1
128
        mov     a1,(CYGARC_JMP_BUF_SP*4,a0) # a1==(caller''s sp)
129
        clr     d0              # return 0
130
        ret     [],0
131
 
132
        # longjmp returns to caller of setjmp
133
        # after restoring callee save registers
134
        .globl _hal_longjmp
135
_hal_longjmp:
136
        mov     d0,a0
137
        mov     (CYGARC_JMP_BUF_D2*4,a0),d2
138
        mov     (CYGARC_JMP_BUF_D3*4,a0),d3
139
        mov     (CYGARC_JMP_BUF_A2*4,a0),a2
140
        mov     (CYGARC_JMP_BUF_A3*4,a0),a3
141
        mov     (CYGARC_JMP_BUF_LR*4,a0),d0
142
##      mov     d0,mdr
143
        mov     (CYGARC_JMP_BUF_SP*4,a0),a1 # stashed (caller''s sp)
144
        mov     a1,sp
145
        mov     d0,(0,sp)       # put link on stack
146
        mov     d1,d0           # return arg1
147
        ret     [],0            # this ignores (0,sp) and does pc=mdr
148
 
149
 
150
#------------------------------------------------------------------------------
151
# end of context.S
152
 
153
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.