Mercurial > ecos
annotate packages/hal/i386/arch/current/src/context.S @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | da3908c9cd10 |
| rev | line source |
|---|---|
| 2 | 1 ##============================================================================= |
| 2 ## | |
| 3 ## context.S | |
| 4 ## | |
| 5 ## i386 context switch code | |
| 6 ## | |
| 7 ##============================================================================= | |
| 8 #####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 # |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 # ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 # The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 # Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 # compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 # http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 # |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 # Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 # License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 # the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 # |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 # The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 # released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 # |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 # The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 # Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 # Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 # All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 # ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 # |
| 2 | 30 #####COPYRIGHTEND#### |
| 31 ##============================================================================= | |
| 32 #######DESCRIPTIONBEGIN#### | |
| 33 ## | |
| 34 ## Author(s): jskov | |
| 35 ## Contributors:jskov | |
| 36 ## Date: 1999-01-20 | |
| 37 ## Purpose: i386 context switch code | |
| 38 ## Description: This file contains implementations of the thread context | |
| 39 ## switch routines. It also contains the longjmp() and setjmp() | |
| 40 ## routines. | |
| 41 ## Based on PowerPC context.S, using data from SYSV ABI4, i386 | |
| 42 ## supplement (page 37-38) | |
| 43 ## http://www.sco.com/products/layered/develop/devspecs/abi386-4.pdf | |
| 44 ## | |
| 45 ######DESCRIPTIONEND#### | |
| 46 ## | |
| 47 ##============================================================================= | |
| 48 | |
| 49 #include <pkgconf/hal.h> | |
| 50 | |
| 51 #include "cyg/hal/i386.inc" | |
| 52 | |
| 53 #------------------------------------------------------------------------------ | |
| 54 # function declaration macro | |
| 55 | |
| 56 #define FUNC_START(name) \ | |
| 57 .globl name; \ | |
| 58 name: | |
| 59 | |
| 60 #------------------------------------------------------------------------------ | |
| 61 # hal_thread_switch_context | |
| 62 # Switch thread contexts | |
| 63 # : 0(%esp) : return address | |
| 64 # : 4(%esp) : address of sp of next thread to execute | |
| 65 # : 8(%esp) : address of sp save location of current thread | |
| 66 # | |
| 67 # %eax, %ecx, and %edx are ours to abuse. | |
| 68 | |
| 69 FUNC_START(hal_thread_switch_context) | |
| 70 movl 4(%esp),%eax # next context ptr | |
| 71 movl 8(%esp),%edx # this context ptr | |
| 72 | |
| 73 # Make room on the stack for the context | |
| 74 movl %esp,%ecx # keep original SP | |
| 75 sub $i386reg_context_size,%esp | |
| 76 | |
| 77 # Save next context ptr in this context. Necessary because | |
| 78 # hal_thread_load_context expects to find the ptr on the stack, | |
| 79 # not in a register as on PPC. | |
| 80 movl %eax,i386reg_next_context(%esp) | |
| 81 | |
| 82 # Save registers | |
| 83 movl %ecx,i386reg_esp(%esp) # original esp | |
| 84 movl %ebp,i386reg_ebp(%esp) | |
| 85 movl %ebx,i386reg_ebx(%esp) | |
| 86 movl %esi,i386reg_esi(%esp) | |
| 87 movl %edi,i386reg_edi(%esp) | |
| 88 | |
| 89 # Store the context ptr | |
| 90 movl %esp,(%edx) | |
| 91 | |
| 92 # Now fall through to hal_thread_load_context | |
| 93 | |
| 94 | |
| 95 #------------------------------------------------------------------------------ | |
| 96 # hal_thread_load_context | |
| 97 # Load thread context | |
| 98 # : 4(%esp) = i386reg_next_context(%esp) = address of sp of thread to execute | |
| 99 # Note that this function is also the second half of hal_thread_switch_context | |
| 100 # and is simply dropped into from it. | |
| 101 # | |
| 102 # %eax, %ecx, and %edx are ours to abuse. | |
| 103 | |
| 104 FUNC_START(hal_thread_load_context) | |
| 105 movl i386reg_next_context(%esp),%eax # get new context ptr | |
| 106 movl (%eax),%eax | |
| 107 | |
| 108 # Restore registers | |
| 109 movl i386reg_ebp(%eax),%ebp | |
| 110 movl i386reg_ebx(%eax),%ebx | |
| 111 movl i386reg_esi(%eax),%esi | |
| 112 movl i386reg_edi(%eax),%edi | |
| 113 movl i386reg_esp(%eax),%esp | |
| 114 | |
| 115 ret | |
| 116 | |
| 117 | |
| 118 #------------------------------------------------------------------------------ | |
| 119 # HAL longjmp, setjmp implementations | |
| 120 # hal_setjmp saves only to callee save registers ebp, ebx, esi, edi and | |
| 121 # and esp+pc into buffer supplied in 4(esp) | |
| 122 # Note: These definitions are repeated in hal_arch.h. If changes are required | |
| 123 # remember to update both sets. | |
| 124 | |
| 125 #define CYGARC_JMP_BUF_SP 0 | |
| 126 #define CYGARC_JMP_BUF_EBP 1 | |
| 127 #define CYGARC_JMP_BUF_EBX 2 | |
| 128 #define CYGARC_JMP_BUF_ESI 3 | |
| 129 #define CYGARC_JMP_BUF_EDI 4 | |
| 130 #define CYGARC_JMP_BUF_PC 5 | |
| 131 | |
| 132 #define CYGARC_JMP_BUF_SIZE 6 | |
| 133 | |
| 134 FUNC_START(hal_setjmp) | |
| 135 # Get jmpbuf pointer | |
| 136 movl 4(%esp),%eax | |
| 137 | |
| 138 # Save regular registers | |
| 139 movl %ebp,CYGARC_JMP_BUF_EBP*4(%eax) | |
| 140 movl %ebx,CYGARC_JMP_BUF_EBX*4(%eax) | |
| 141 movl %esi,CYGARC_JMP_BUF_ESI*4(%eax) | |
| 142 movl %edi,CYGARC_JMP_BUF_EDI*4(%eax) | |
| 143 | |
| 144 # Stack and PC | |
| 145 movl %esp,CYGARC_JMP_BUF_SP*4(%eax) | |
| 146 movl 0(%esp),%ebx | |
| 147 movl %ebx,CYGARC_JMP_BUF_PC*4(%eax) | |
| 148 | |
| 149 # Return 0 | |
| 150 xor %eax,%eax | |
| 151 ret | |
| 152 | |
| 153 | |
| 154 # hal_longjmp loads state from 4(esp) and returns to PC stored in state | |
| 155 | |
| 156 FUNC_START(hal_longjmp) | |
| 157 # Get return value | |
| 158 movl 8(%esp),%eax | |
| 159 | |
| 160 # Get jmpbuf pointer | |
| 161 movl 4(%esp),%ecx | |
| 162 | |
| 163 # Restore regular registers | |
| 164 movl CYGARC_JMP_BUF_EBP*4(%ecx),%ebp | |
| 165 movl CYGARC_JMP_BUF_EBX*4(%ecx),%ebx | |
| 166 movl CYGARC_JMP_BUF_ESI*4(%ecx),%esi | |
| 167 movl CYGARC_JMP_BUF_EDI*4(%ecx),%edi | |
| 168 | |
| 169 # Restore stack pointer | |
| 170 movl CYGARC_JMP_BUF_SP*4(%ecx),%esp | |
| 171 | |
| 172 # Put return address on stack | |
| 173 movl CYGARC_JMP_BUF_PC*4(%ecx),%edx | |
| 174 movl %edx,0(%esp) | |
| 175 | |
| 176 ret | |
| 177 | |
| 178 #----------------------------------------------------------------------------- | |
| 179 # End of context.S |
