Changeset View
Changeset View
Standalone View
Standalone View
sys/i386/i386/swtch.S
| Show All 24 Lines | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
| * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| * SUCH DAMAGE. | * SUCH DAMAGE. | ||||
| */ | */ | ||||
| #include "opt_sched.h" | |||||
| #include <machine/asmacros.h> | #include <machine/asmacros.h> | ||||
| #include "assym.inc" | #include "assym.inc" | ||||
| #if defined(SMP) && defined(SCHED_ULE) | |||||
| #define SETOP xchgl | |||||
| #define BLOCK_SPIN(reg) \ | #define BLOCK_SPIN(reg) \ | ||||
| movl $blocked_lock,%eax ; \ | |||||
| 100: ; \ | |||||
| lock ; \ | |||||
| cmpxchgl %eax,TD_LOCK(reg) ; \ | |||||
| jne 101f ; \ | |||||
| pause ; \ | |||||
| jmp 100b ; \ | |||||
| 101: | |||||
| #else | |||||
| #define SETOP movl | |||||
| #define BLOCK_SPIN(reg) | |||||
| #endif | |||||
| /*****************************************************************************/ | /*****************************************************************************/ | ||||
| /* Scheduling */ | /* Scheduling */ | ||||
| /*****************************************************************************/ | /*****************************************************************************/ | ||||
| .text | .text | ||||
| /* | /* | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | #ifdef INVARIANTS | ||||
| testl %ecx,%ecx /* no thread? */ | testl %ecx,%ecx /* no thread? */ | ||||
| jz badsw3 /* no, panic */ | jz badsw3 /* no, panic */ | ||||
| #endif | #endif | ||||
| movl TD_PCB(%ecx),%edx | movl TD_PCB(%ecx),%edx | ||||
| /* Switchout td_lock */ | /* Switchout td_lock */ | ||||
| movl %esi,%eax | movl %esi,%eax | ||||
| movl PCPU(CPUID),%esi | movl PCPU(CPUID),%esi | ||||
| SETOP %eax,TD_LOCK(%edi) | xchgl %eax,TD_LOCK(%edi) | ||||
| /* Release bit from old pmap->pm_active */ | /* Release bit from old pmap->pm_active */ | ||||
| movl PCPU(CURPMAP), %ebx | movl PCPU(CURPMAP), %ebx | ||||
| #ifdef SMP | #ifdef SMP | ||||
| lock | lock | ||||
| #endif | #endif | ||||
| btrl %esi, PM_ACTIVE(%ebx) /* clear old */ | btrl %esi, PM_ACTIVE(%ebx) /* clear old */ | ||||
| /* Set bit in new pmap->pm_active */ | /* Set bit in new pmap->pm_active */ | ||||
| movl TD_PROC(%ecx),%eax /* newproc */ | movl TD_PROC(%ecx),%eax /* newproc */ | ||||
| movl P_VMSPACE(%eax), %ebx | movl P_VMSPACE(%eax), %ebx | ||||
| addl $VM_PMAP, %ebx | addl $VM_PMAP, %ebx | ||||
| movl %ebx, PCPU(CURPMAP) | movl %ebx, PCPU(CURPMAP) | ||||
| #ifdef SMP | #ifdef SMP | ||||
| lock | lock | ||||
| #endif | #endif | ||||
| btsl %esi, PM_ACTIVE(%ebx) /* set new */ | btsl %esi, PM_ACTIVE(%ebx) /* set new */ | ||||
| sw1: | sw1: | ||||
| BLOCK_SPIN(%ecx) | #ifdef SMP | ||||
| movl $blocked_lock,%eax | |||||
| 100: | |||||
| lock | |||||
| cmpxchgl %eax,TD_LOCK(reg) | |||||
| jne 101f | |||||
| pause | |||||
| jmp 100b | |||||
| 101: | |||||
| #endif | |||||
| /* | /* | ||||
| * At this point, we have managed thread locks and are ready | * At this point, we have managed thread locks and are ready | ||||
| * to load up the rest of the next context. | * to load up the rest of the next context. | ||||
| */ | */ | ||||
| /* Load a pointer to the thread kernel stack into PCPU. */ | /* Load a pointer to the thread kernel stack into PCPU. */ | ||||
| leal -VM86_STACK_SPACE(%edx), %eax /* leave space for vm86 */ | leal -VM86_STACK_SPACE(%edx), %eax /* leave space for vm86 */ | ||||
| movl %eax, PCPU(KESP0) | movl %eax, PCPU(KESP0) | ||||
| ▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines | |||||