pnpbioscall.S revision 1.3 1 1.3 maxv /* $NetBSD: pnpbioscall.S,v 1.3 2018/07/14 14:29:40 maxv Exp $ */
2 1.1 fvdl /*
3 1.1 fvdl * Copyright (c) 1999
4 1.1 fvdl * Matthias Drochner. All rights reserved.
5 1.1 fvdl *
6 1.1 fvdl * Redistribution and use in source and binary forms, with or without
7 1.1 fvdl * modification, are permitted provided that the following conditions
8 1.1 fvdl * are met:
9 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
10 1.1 fvdl * notice, this list of conditions, and the following disclaimer.
11 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
13 1.1 fvdl * documentation and/or other materials provided with the distribution.
14 1.1 fvdl *
15 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 fvdl * SUCH DAMAGE.
26 1.1 fvdl */
27 1.1 fvdl
28 1.2 lukem #include <machine/asm.h>
29 1.3 maxv __KERNEL_RCSID(0, "$NetBSD: pnpbioscall.S,v 1.3 2018/07/14 14:29:40 maxv Exp $");
30 1.2 lukem
31 1.1 fvdl #include "assym.h"
32 1.1 fvdl #include <machine/segments.h>
33 1.1 fvdl
34 1.1 fvdl .data
35 1.1 fvdl saveesp:
36 1.1 fvdl .space 4
37 1.1 fvdl
38 1.3 maxv ENTRY(pnpbioscall)
39 1.1 fvdl pushl %ebp
40 1.1 fvdl movl %esp, %ebp
41 1.1 fvdl /*
42 1.1 fvdl * disable interrupts - our handlers can't deal with frames of the
43 1.1 fvdl * segment we are calling, and the BIOS can't use our IDT anyway
44 1.1 fvdl */
45 1.1 fvdl pushfl
46 1.1 fvdl cli
47 1.1 fvdl
48 1.1 fvdl /* call pnpbiostramp() */
49 1.1 fvdl lcall $GSEL(GPNPBIOSTRAMP_SEL, SEL_KPL), $0
50 1.1 fvdl
51 1.1 fvdl popfl
52 1.1 fvdl popl %ebp
53 1.1 fvdl ret
54 1.1 fvdl
55 1.3 maxv ENTRY(pnpbiostramp)
56 1.1 fvdl pushl %ebx
57 1.1 fvdl
58 1.1 fvdl /* save current stack pointer */
59 1.1 fvdl movl %esp, %eax
60 1.1 fvdl movl %eax, saveesp
61 1.1 fvdl
62 1.1 fvdl /* switch to new stack */
63 1.1 fvdl movl 8(%ebp), %esp /* call argument */
64 1.1 fvdl movl $GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL), %eax
65 1.1 fvdl mov %ax, %ss
66 1.1 fvdl
67 1.1 fvdl /* fake the call return address (16-bit frame) */
68 1.1 fvdl mov %cs, %ax
69 1.1 fvdl push %ax
70 1.1 fvdl movl $(1f - _C_LABEL(pnpbiostramp)), %eax
71 1.1 fvdl push %ax
72 1.1 fvdl
73 1.1 fvdl /* do a long jump */
74 1.1 fvdl pushl $GSEL(GPNPBIOSCODE_SEL, SEL_KPL)
75 1.1 fvdl pushl (_C_LABEL(pnpbios_entry))
76 1.1 fvdl #if 1
77 1.1 fvdl /* paranoia: don't pass our ds */
78 1.1 fvdl movl $GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL), %eax
79 1.1 fvdl mov %ax, %ds
80 1.1 fvdl #endif
81 1.1 fvdl lret
82 1.1 fvdl
83 1.1 fvdl 1: /* returned from BIOS call */
84 1.1 fvdl movl $GSEL(GDATA_SEL, SEL_KPL), %ebx
85 1.1 fvdl #if 1
86 1.1 fvdl mov %bx, %ds
87 1.1 fvdl #endif
88 1.1 fvdl /* back to old stack */
89 1.1 fvdl mov %bx, %ss
90 1.1 fvdl movl saveesp, %ebx
91 1.1 fvdl movl %ebx, %esp
92 1.1 fvdl
93 1.1 fvdl popl %ebx
94 1.1 fvdl lret
95 1.1 fvdl .globl _C_LABEL(epnpbiostramp)
96 1.1 fvdl _C_LABEL(epnpbiostramp):
97