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