]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/bioscall.S
unbound: Vendor import 1.19.1
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / bioscall.S
1 /*-
2  * Copyright (c) 1997 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
27 /*
28  * Functions for calling x86 BIOS functions from the BSD kernel
29  */
30         
31 #include <machine/asmacros.h>
32
33 #include "assym.inc"
34
35         .data
36         ALIGN_DATA
37 bioscall_frame:         .long   0
38 bioscall_stack:         .long   0
39
40         .text
41 /*
42  * bios32(regs, offset, segment)
43  *      struct bios_regs *regs;
44  *      u_int offset;
45  *      u_short segment;
46  */
47 ENTRY(bios32)
48         pushl   %ebp
49         movl    16(%esp),%ebp
50         mov     %bp,bioscall_vector+4
51         movl    12(%esp),%ebp
52         movl    %ebp,bioscall_vector
53         movl    8(%esp),%ebp
54         pushl   %ebx
55         pushl   %esi
56         pushl   %edi
57         movl    0(%ebp),%eax
58         movl    4(%ebp),%ebx
59         movl    8(%ebp),%ecx
60         movl    12(%ebp),%edx
61         movl    16(%ebp),%esi
62         movl    20(%ebp),%edi
63         pushl   %ebp
64         lcall   *bioscall_vector
65         popl    %ebp
66         movl    %eax,0(%ebp)
67         movl    %ebx,4(%ebp)
68         movl    %ecx,8(%ebp)
69         movl    %edx,12(%ebp)
70         movl    %esi,16(%ebp)
71         movl    %edi,20(%ebp)
72         movl    $0,%eax                 /* presume success */
73         jnc     1f
74         movl    $1,%eax                 /* nope */
75 1:
76         popl    %edi
77         popl    %esi
78         popl    %ebx
79         popl    %ebp
80         ret
81
82
83 /*
84  * bios16_call(regs, stack)
85  *      struct bios_regs *regs;
86  *      char *stack;
87  */
88 ENTRY(bios16_call)
89         pushl   %ebp
90         movl    %esp,%ebp
91         addl    $4,%ebp                 /* frame pointer */
92         movl    %ebp,bioscall_frame     /* ... save it */
93         pushl   %ebx
94         pushl   %esi
95         pushl   %edi
96 /*
97  * the problem with a full 32-bit stack segment is that 16-bit code
98  * tends to do a pushf, which only pushes %sp, not %esp.  This value
99  * is then popped off (into %esp) which causes a page fault because 
100  * it is the wrong address.
101  *
102  * the reverse problem happens for 16-bit stack addresses; the kernel
103  * code attempts to get the address of something on the stack, and the
104  * value returned is the address relative to %ss, not %ds.
105  *
106  * we fix this by installing a temporary stack at page 0, so the
107  * addresses are always valid in both 32 bit and 16 bit modes.
108  */
109         movl    %esp,bioscall_stack     /* save current stack location */
110         movl    8(%ebp),%esp            /* switch to page 0 stack */
111
112         movl    4(%ebp),%ebp            /* regs */
113
114         movl    0(%ebp),%eax
115         movl    4(%ebp),%ebx
116         movl    8(%ebp),%ecx
117         movl    12(%ebp),%edx
118         movl    16(%ebp),%esi
119         movl    20(%ebp),%edi
120
121         pushl   $BC32SEL
122         leal    CNAME(bios16_jmp),%ebp
123         andl    $PAGE_MASK,%ebp
124         pushl   %ebp                    /* reload %cs and */
125         lret                            /* ...continue below */
126         .globl  CNAME(bios16_jmp)
127 CNAME(bios16_jmp):
128         lcallw  *bioscall_vector        /* 16-bit call */
129
130         jc      1f
131         pushl   $0                      /* success */
132         jmp     2f
133 1:
134         pushl   $1                      /* failure */
135 2:
136         movl    bioscall_frame,%ebp
137
138         movl    4(%ebp),%ebp            /* regs */
139
140         movl    %eax,0(%ebp)
141         movl    %ebx,4(%ebp)
142         movl    %ecx,8(%ebp)
143         movl    %edx,12(%ebp)
144         movl    %esi,16(%ebp)
145         movl    %edi,20(%ebp)
146
147         popl    %eax                    /* recover return value */
148         movl    bioscall_stack,%esp     /* return to normal stack */
149
150         popl    %edi
151         popl    %esi
152         popl    %ebx
153         popl    %ebp
154
155         movl    (%esp),%ecx
156         pushl   %ecx                    /* return address */
157         movl    $KCSEL,4(%esp)
158         lret                            /* reload %cs on the way out */