vm86bios.s revision 165302
1/*- 2 * Copyright (c) 1998 Jonathan Lemon 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/i386/i386/vm86bios.s 165302 2006-12-17 05:07:01Z kmacy $ 27 */ 28 29#include "opt_npx.h" 30 31#include <machine/asmacros.h> /* miscellaneous asm macros */ 32#include <machine/trap.h> 33 34#include "assym.s" 35 36#define SCR_NEWPTD PCB_ESI /* readability macros */ 37#define SCR_VMFRAME PCB_EBP /* see vm86.c for explanation */ 38#define SCR_STACK PCB_ESP 39#define SCR_PGTABLE PCB_EBX 40#define SCR_ARGFRAME PCB_EIP 41#define SCR_TSS0 PCB_VM86 42#define SCR_TSS1 (PCB_VM86+4) 43 44 .data 45 ALIGN_DATA 46 47 .globl vm86pcb 48 49vm86pcb: .long 0 50 51 .text 52 53/* 54 * vm86_bioscall(struct trapframe_vm86 *vm86) 55 */ 56ENTRY(vm86_bioscall) 57 movl vm86pcb,%edx /* scratch data area */ 58 movl 4(%esp),%eax 59 movl %eax,SCR_ARGFRAME(%edx) /* save argument pointer */ 60 pushl %ebx 61 pushl %ebp 62 pushl %esi 63 pushl %edi 64 pushl %gs 65 66#ifdef DEV_NPX 67 pushfl 68 cli 69 movl PCPU(CURTHREAD),%ecx 70 cmpl %ecx,PCPU(FPCURTHREAD) /* do we need to save fp? */ 71 jne 1f 72 testl %ecx,%ecx 73 je 1f /* no curproc/npxproc */ 74 pushl %edx 75 movl TD_PCB(%ecx),%ecx 76 addl $PCB_SAVEFPU,%ecx 77 pushl %ecx 78 call npxsave 79 popl %ecx 80 popl %edx /* recover our pcb */ 811: 82 popfl 83#endif 84 85 movl SCR_VMFRAME(%edx),%ebx /* target frame location */ 86 movl %ebx,%edi /* destination */ 87 movl SCR_ARGFRAME(%edx),%esi /* source (set on entry) */ 88 movl $VM86_FRAMESIZE/4,%ecx /* sizeof(struct vm86frame)/4 */ 89 cld 90 rep 91 movsl /* copy frame to new stack */ 92 93 movl PCPU(CURPCB),%eax 94 pushl %eax /* save curpcb */ 95 movl %edx,PCPU(CURPCB) /* set curpcb to vm86pcb */ 96 97 movl PCPU(TSS_GDT),%ebx /* entry in GDT */ 98 movl 0(%ebx),%eax 99 movl %eax,SCR_TSS0(%edx) /* save first word */ 100 movl 4(%ebx),%eax 101 andl $~0x200, %eax /* flip 386BSY -> 386TSS */ 102 movl %eax,SCR_TSS1(%edx) /* save second word */ 103 104 movl PCB_EXT(%edx),%edi /* vm86 tssd entry */ 105 movl 0(%edi),%eax 106 movl %eax,0(%ebx) 107 movl 4(%edi),%eax 108 movl %eax,4(%ebx) 109 movl $GPROC0_SEL*8,%esi /* GSEL(entry, SEL_KPL) */ 110 ltr %si 111 112 movl %cr3,%eax 113 pushl %eax /* save address space */ 114 movl IdlePTD,%ecx 115 movl %ecx,%ebx 116 addl $KERNBASE,%ebx /* va of Idle PTD */ 117 movl 0(%ebx),%eax 118 pushl %eax /* old ptde != 0 when booting */ 119 pushl %ebx /* keep for reuse */ 120 121 movl %esp,SCR_STACK(%edx) /* save current stack location */ 122 123 movl SCR_NEWPTD(%edx),%eax /* mapping for vm86 page table */ 124 movl %eax,0(%ebx) /* ... install as PTD entry 0 */ 125 126#ifdef PAE 127 movl IdlePDPT,%ecx 128#endif 129 movl %ecx,%cr3 /* new page tables */ 130 movl SCR_VMFRAME(%edx),%esp /* switch to new stack */ 131 132 pushl %esp 133 call vm86_prepcall /* finish setup */ 134 add $4, %esp 135 136 /* 137 * Return via doreti 138 */ 139 MEXITCOUNT 140 jmp doreti 141 142 143/* 144 * vm86_biosret(struct trapframe_vm86 *vm86) 145 */ 146ENTRY(vm86_biosret) 147 movl vm86pcb,%edx /* data area */ 148 149 movl 4(%esp),%esi /* source */ 150 movl SCR_ARGFRAME(%edx),%edi /* destination */ 151 movl $VM86_FRAMESIZE/4,%ecx /* size */ 152 cld 153 rep 154 movsl /* copy frame to original frame */ 155 156 movl SCR_STACK(%edx),%esp /* back to old stack */ 157 popl %ebx /* saved va of Idle PTD */ 158 popl %eax 159 movl %eax,0(%ebx) /* restore old pte */ 160 popl %eax 161 movl %eax,%cr3 /* install old page table */ 162 163 movl PCPU(TSS_GDT),%ebx /* entry in GDT */ 164 movl SCR_TSS0(%edx),%eax 165 movl %eax,0(%ebx) /* restore first word */ 166 movl SCR_TSS1(%edx),%eax 167 movl %eax,4(%ebx) /* restore second word */ 168 movl $GPROC0_SEL*8,%esi /* GSEL(entry, SEL_KPL) */ 169 ltr %si 170 171 popl PCPU(CURPCB) /* restore curpcb/curproc */ 172 movl SCR_ARGFRAME(%edx),%edx /* original stack frame */ 173 movl TF_TRAPNO(%edx),%eax /* return (trapno) */ 174 175 popl %gs 176 popl %edi 177 popl %esi 178 popl %ebp 179 popl %ebx 180 ret /* back to our normal program */ 181