2 * Copyright (c) 1997 Jonathan Lemon
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
26 * $FreeBSD: src/sys/i386/i386/bioscall.s,v 1.6.2.1 2000/07/07 00:38:46 obrien Exp $
27 * $DragonFly: src/sys/i386/i386/Attic/bioscall.s,v 1.2 2003/06/17 04:28:35 dillon Exp $
31 * Functions for calling x86 BIOS functions from the BSD kernel
34 #include <machine/asmacros.h>
38 #define data16 .byte 0x66
42 bioscall_frame: .long 0
43 bioscall_stack: .long 0
47 * bios32(regs, offset, segment)
48 * struct bios_regs *regs;
55 mov %bp,_bioscall_vector+4
57 movl %ebp,_bioscall_vector
69 lcall *_bioscall_vector
77 movl $0,%eax /* presume success */
79 movl $1,%eax /* nope */
89 * bios16_call(regs, stack)
90 * struct bios_regs *regs;
96 addl $4,%ebp /* frame pointer */
97 movl %ebp,bioscall_frame /* ... save it */
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.
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.
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.
114 movl %esp,bioscall_stack /* save current stack location */
115 movl 8(%ebp),%esp /* switch to page 0 stack */
117 movl 4(%ebp),%ebp /* regs */
127 leal CNAME(bios16_jmp),%ebp
129 pushl %ebp /* reload %cs and */
130 lret /* ...continue below */
131 .globl CNAME(bios16_jmp)
134 lcall *_bioscall_vector /* 16-bit call */
137 pushl $0 /* success */
140 pushl $1 /* failure */
142 movl bioscall_frame,%ebp
144 movl 4(%ebp),%ebp /* regs */
153 popl %eax /* recover return value */
154 movl bioscall_stack,%esp /* return to normal stack */
162 pushl %ecx /* return address */
164 lret /* reload %cs on the way out */