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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [i386/] [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
##      i386 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):   jskov
43
## Contributors:jskov, pjo, nickg
44
## Date:        1999-01-20
45
## Purpose:     i386 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
##              Based on PowerPC context.S, using data from SYSV ABI4, i386
50
##              supplement (page 37-38)
51
##         http://www.sco.com/products/layered/develop/devspecs/abi386-4.pdf
52
##
53
######DESCRIPTIONEND####
54
##
55
##=============================================================================
56
 
57
#include 
58
 
59
#include 
60
 
61
#include 
62
 
63
#------------------------------------------------------------------------------
64
# function declaration macro
65
 
66
#define FUNC_START(name)                        \
67
        .globl name;                            \
68
name:
69
 
70
#------------------------------------------------------------------------------
71
# hal_thread_switch_context
72
# Switch thread contexts
73
# :     0(%esp) :     return address
74
# :     4(%esp) :     address of sp of next thread to execute
75
# :     8(%esp) :     address of sp save location of current thread
76
#
77
# %eax, %ecx, and %edx are ours to abuse.
78
 
79
FUNC_START(hal_thread_switch_context)
80
 
81
        # Pop the return address from the stack, but leave the
82
        # arguments there so that the caller can remove them
83
        # itself when we return.
84
 
85
        popl    %ecx            # pop return eip
86
        movl    0(%esp),%eax    # get next context ptr
87
        movl    4(%esp),%edx    # get this context ptr
88
 
89
        # Save context in the same format as an
90
        # exception
91
 
92
        pushfl                  # save eflags
93
        pushl   %cs             # save cs
94
        pushl   %ecx            # save eip
95
        pushl   $-1             # push fake vector
96
        pushal                  # push general registers
97
        hal_fpu_push_ctx        # push FPU state
98
 
99
        # Store the context ptr
100
        movl    %esp,(%edx)
101
 
102
hal_thread_switch_context_load:
103
 
104
        # The pointer to the next context is in EAX
105
 
106
        movl    (%eax),%esp     # Point ESP at new state
107
 
108
        # Merge the IF bit in the saved EFLAGS with the rest of the
109
        # bits currently in EFLAGS.
110
 
111
        movl    i386reg_eflags(%esp),%ebx # EBX = saved EFLAGS
112
        andl    $0x0200,%ebx    # isolate IF bit
113
        pushfl                  # push current flags
114
        popl    %ecx            # pop into ECX
115
        btrl    $9,%ecx         # clear IF flag in current EFLAGS
116
        orl     %ebx,%ecx       # Or in saved IF bit
117
        movl    %ecx,i386reg_eflags(%esp) # Restore to saved state for use by iret
118
 
119
        # Now we can load the state and enter next thread
120
 
121
        hal_fpu_pop_ctx         # Pop FPU state
122
        popal                   # unstack general registers
123
        add     $4,%esp         # skip vector number
124
 
125
        iret                    # And return
126
 
127
#------------------------------------------------------------------------------
128
# hal_thread_load_context
129
# Load thread context
130
# : 4(%esp) = address of sp of thread to execute
131
#
132
# %eax, %ecx, and %edx are ours to abuse.
133
 
134
FUNC_START(hal_thread_load_context)
135
 
136
        movl    4(%esp),%eax    # get new context ptr
137
 
138
        # Jump into hal_thread_switch_context at the right
139
        # point to load this context.
140
 
141
        jmp     hal_thread_switch_context_load
142
 
143
#------------------------------------------------------------------------------
144
# HAL longjmp, setjmp implementations
145
# hal_setjmp saves only to callee save registers ebp, ebx, esi, edi and
146
# and esp+pc into buffer supplied in 4(esp)
147
# Note: These definitions are repeated in hal_arch.h. If changes are required
148
# remember to update both sets.
149
 
150
#define CYGARC_JMP_BUF_SP        0
151
#define CYGARC_JMP_BUF_EBP       1
152
#define CYGARC_JMP_BUF_EBX       2
153
#define CYGARC_JMP_BUF_ESI       3
154
#define CYGARC_JMP_BUF_EDI       4
155
#define CYGARC_JMP_BUF_PC        5
156
 
157
#define CYGARC_JMP_BUF_SIZE      6
158
 
159
FUNC_START(hal_setjmp)
160
        # Get jmpbuf pointer
161
        movl    4(%esp),%eax
162
 
163
        # Save regular registers
164
        movl    %ebp,CYGARC_JMP_BUF_EBP*4(%eax)
165
        movl    %ebx,CYGARC_JMP_BUF_EBX*4(%eax)
166
        movl    %esi,CYGARC_JMP_BUF_ESI*4(%eax)
167
        movl    %edi,CYGARC_JMP_BUF_EDI*4(%eax)
168
 
169
        # Stack and PC
170
        movl    %esp,CYGARC_JMP_BUF_SP*4(%eax)
171
        movl    0(%esp),%edx
172
        movl    %edx,CYGARC_JMP_BUF_PC*4(%eax)
173
 
174
        # Return 0
175
        xor     %eax,%eax
176
        ret
177
 
178
 
179
# hal_longjmp loads state from 4(esp) and returns to PC stored in state
180
 
181
FUNC_START(hal_longjmp)
182
        # Get return value
183
        movl    8(%esp),%eax
184
 
185
        # Get jmpbuf pointer
186
        movl    4(%esp),%ecx
187
 
188
        # Restore regular registers
189
        movl    CYGARC_JMP_BUF_EBP*4(%ecx),%ebp
190
        movl    CYGARC_JMP_BUF_EBX*4(%ecx),%ebx
191
        movl    CYGARC_JMP_BUF_ESI*4(%ecx),%esi
192
        movl    CYGARC_JMP_BUF_EDI*4(%ecx),%edi
193
 
194
        # Restore stack pointer
195
        movl    CYGARC_JMP_BUF_SP*4(%ecx),%esp
196
 
197
        # Put return address on stack
198
        movl    CYGARC_JMP_BUF_PC*4(%ecx),%edx
199
        movl    %edx,0(%esp)
200
 
201
        ret
202
 
203
#-----------------------------------------------------------------------------
204
# End of context.S

powered by: WebSVN 2.1.0

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