vm86bios.s revision 76904
134840Sjlemon/*- 234840Sjlemon * Copyright (c) 1998 Jonathan Lemon 334840Sjlemon * All rights reserved. 434840Sjlemon * 534840Sjlemon * Redistribution and use in source and binary forms, with or without 634840Sjlemon * modification, are permitted provided that the following conditions 734840Sjlemon * are met: 834840Sjlemon * 1. Redistributions of source code must retain the above copyright 934840Sjlemon * notice, this list of conditions and the following disclaimer. 1034840Sjlemon * 2. Redistributions in binary form must reproduce the above copyright 1134840Sjlemon * notice, this list of conditions and the following disclaimer in the 1234840Sjlemon * documentation and/or other materials provided with the distribution. 1334840Sjlemon * 1434840Sjlemon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1534840Sjlemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1634840Sjlemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1734840Sjlemon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1834840Sjlemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1934840Sjlemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2034840Sjlemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2134840Sjlemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2234840Sjlemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2334840Sjlemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2434840Sjlemon * SUCH DAMAGE. 2534840Sjlemon * 2650477Speter * $FreeBSD: head/sys/i386/i386/vm86bios.s 76904 2001-05-20 17:01:20Z bde $ 2734840Sjlemon */ 2834840Sjlemon 2971257Speter#include "opt_npx.h" 3071256Speter 3134840Sjlemon#include <machine/asmacros.h> /* miscellaneous asm macros */ 3234840Sjlemon#include <machine/trap.h> 3334840Sjlemon 3434840Sjlemon#include "assym.s" 3534840Sjlemon 3637889Sjlemon#define SCR_NEWPTD PCB_ESI /* readability macros */ 3737889Sjlemon#define SCR_VMFRAME PCB_EBP /* see vm86.c for explanation */ 3837889Sjlemon#define SCR_STACK PCB_ESP 3937889Sjlemon#define SCR_PGTABLE PCB_EBX 4037889Sjlemon#define SCR_ARGFRAME PCB_EIP 4146129Sluoqi#define SCR_TSS0 PCB_SPARE 4246129Sluoqi#define SCR_TSS1 (PCB_SPARE+4) 4337889Sjlemon 4434840Sjlemon .data 4534840Sjlemon ALIGN_DATA 4634840Sjlemon 4773011Sjake .globl in_vm86call, vm86pcb 4834840Sjlemon 4973011Sjakein_vm86call: .long 0 5073011Sjakevm86pcb: .long 0 5134840Sjlemon 5234840Sjlemon .text 5334840Sjlemon 5434840Sjlemon/* 5534840Sjlemon * vm86_bioscall(struct trapframe_vm86 *vm86) 5634840Sjlemon */ 5734840SjlemonENTRY(vm86_bioscall) 5873011Sjake movl vm86pcb,%edx /* scratch data area */ 5934840Sjlemon movl 4(%esp),%eax 6037889Sjlemon movl %eax,SCR_ARGFRAME(%edx) /* save argument pointer */ 6134840Sjlemon pushl %ebx 6234840Sjlemon pushl %ebp 6334840Sjlemon pushl %esi 6434840Sjlemon pushl %edi 6534840Sjlemon pushl %gs 6634840Sjlemon 6771257Speter#ifdef DEV_NPX 6876904Sbde pushfl 6976904Sbde cli 7069971Sjake movl PCPU(CURPROC),%ecx 7169971Sjake cmpl %ecx,PCPU(NPXPROC) /* do we need to save fp? */ 7234840Sjlemon jne 1f 7339872Sjlemon testl %ecx,%ecx 7439872Sjlemon je 1f /* no curproc/npxproc */ 7539046Syokota pushl %edx 7634840Sjlemon movl P_ADDR(%ecx),%ecx 7734840Sjlemon addl $PCB_SAVEFPU,%ecx 7839046Syokota pushl %ecx 7973011Sjake call npxsave 8039046Syokota popl %ecx 8134840Sjlemon popl %edx /* recover our pcb */ 8276904Sbde1: 8376904Sbde popfl 8434840Sjlemon#endif 8534840Sjlemon 8637889Sjlemon movl SCR_VMFRAME(%edx),%ebx /* target frame location */ 8734840Sjlemon movl %ebx,%edi /* destination */ 8837889Sjlemon movl SCR_ARGFRAME(%edx),%esi /* source (set on entry) */ 8947080Sluoqi movl $VM86_FRAMESIZE/4,%ecx /* sizeof(struct vm86frame)/4 */ 9034840Sjlemon cld 9134840Sjlemon rep 9234840Sjlemon movsl /* copy frame to new stack */ 9334840Sjlemon 9469971Sjake movl PCPU(CURPCB),%eax 9534840Sjlemon pushl %eax /* save curpcb */ 9669971Sjake movl %edx,PCPU(CURPCB) /* set curpcb to vm86pcb */ 9734840Sjlemon 9869971Sjake movl PCPU(TSS_GDT),%ebx /* entry in GDT */ 9934840Sjlemon movl 0(%ebx),%eax 10037889Sjlemon movl %eax,SCR_TSS0(%edx) /* save first word */ 10134840Sjlemon movl 4(%ebx),%eax 10234840Sjlemon andl $~0x200, %eax /* flip 386BSY -> 386TSS */ 10337889Sjlemon movl %eax,SCR_TSS1(%edx) /* save second word */ 10434840Sjlemon 10534840Sjlemon movl PCB_EXT(%edx),%edi /* vm86 tssd entry */ 10634840Sjlemon movl 0(%edi),%eax 10734840Sjlemon movl %eax,0(%ebx) 10834840Sjlemon movl 4(%edi),%eax 10934840Sjlemon movl %eax,4(%ebx) 11047081Sluoqi movl $GPROC0_SEL*8,%esi /* GSEL(entry, SEL_KPL) */ 11134840Sjlemon ltr %si 11234840Sjlemon 11334840Sjlemon movl %cr3,%eax 11434840Sjlemon pushl %eax /* save address space */ 11573011Sjake movl IdlePTD,%ecx 11634840Sjlemon movl %ecx,%ebx 11734840Sjlemon addl $KERNBASE,%ebx /* va of Idle PTD */ 11834840Sjlemon movl 0(%ebx),%eax 11934840Sjlemon pushl %eax /* old ptde != 0 when booting */ 12034840Sjlemon pushl %ebx /* keep for reuse */ 12134840Sjlemon 12237889Sjlemon movl %esp,SCR_STACK(%edx) /* save current stack location */ 12334840Sjlemon 12437889Sjlemon movl SCR_NEWPTD(%edx),%eax /* mapping for vm86 page table */ 12534840Sjlemon movl %eax,0(%ebx) /* ... install as PTD entry 0 */ 12634840Sjlemon 12734840Sjlemon movl %ecx,%cr3 /* new page tables */ 12837889Sjlemon movl SCR_VMFRAME(%edx),%esp /* switch to new stack */ 12934840Sjlemon 13073011Sjake call vm86_prepcall /* finish setup */ 13134840Sjlemon 13273011Sjake movl $1,in_vm86call /* set flag for trap() */ 13334840Sjlemon 13434840Sjlemon /* 13573011Sjake * Return via doreti 13634840Sjlemon */ 13734840Sjlemon MEXITCOUNT 13873011Sjake jmp doreti 13934840Sjlemon 14034840Sjlemon 14134840Sjlemon/* 14234840Sjlemon * vm86_biosret(struct trapframe_vm86 *vm86) 14334840Sjlemon */ 14434840SjlemonENTRY(vm86_biosret) 14573011Sjake movl vm86pcb,%edx /* data area */ 14634840Sjlemon 14734840Sjlemon movl 4(%esp),%esi /* source */ 14837889Sjlemon movl SCR_ARGFRAME(%edx),%edi /* destination */ 14947080Sluoqi movl $VM86_FRAMESIZE/4,%ecx /* size */ 15034840Sjlemon cld 15134840Sjlemon rep 15234840Sjlemon movsl /* copy frame to original frame */ 15334840Sjlemon 15437889Sjlemon movl SCR_STACK(%edx),%esp /* back to old stack */ 15534840Sjlemon popl %ebx /* saved va of Idle PTD */ 15634840Sjlemon popl %eax 15734840Sjlemon movl %eax,0(%ebx) /* restore old pte */ 15834840Sjlemon popl %eax 15934840Sjlemon movl %eax,%cr3 /* install old page table */ 16034840Sjlemon 16173011Sjake movl $0,in_vm86call /* reset trapflag */ 16234840Sjlemon 16369971Sjake movl PCPU(TSS_GDT),%ebx /* entry in GDT */ 16437889Sjlemon movl SCR_TSS0(%edx),%eax 16534840Sjlemon movl %eax,0(%ebx) /* restore first word */ 16637889Sjlemon movl SCR_TSS1(%edx),%eax 16734840Sjlemon movl %eax,4(%ebx) /* restore second word */ 16847081Sluoqi movl $GPROC0_SEL*8,%esi /* GSEL(entry, SEL_KPL) */ 16934840Sjlemon ltr %si 17034840Sjlemon 17169971Sjake popl PCPU(CURPCB) /* restore curpcb/curproc */ 17237889Sjlemon movl SCR_ARGFRAME(%edx),%edx /* original stack frame */ 17334840Sjlemon movl TF_TRAPNO(%edx),%eax /* return (trapno) */ 17434840Sjlemon 17534840Sjlemon popl %gs 17634840Sjlemon popl %edi 17734840Sjlemon popl %esi 17834840Sjlemon popl %ebp 17934840Sjlemon popl %ebx 18034840Sjlemon ret /* back to our normal program */ 181