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