xref: /netbsd/sys/arch/i386/stand/lib/biosvbe.S (revision 6550d01e)
1/* $NetBSD: biosvbe.S,v 1.1 2009/02/16 22:39:30 jmcneill Exp $ */
2
3/*-
4 * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <machine/asm.h>
30
31	.text
32
33/*
34 * VESA BIOS Extensions routines
35 */
36
37/*
38 * Function 00h - Return VBE Controller Information
39 *
40 * int biosvbe_info(struct vbeinfoblock *)
41 * return: VBE call status
42 */
43ENTRY(biosvbe_info)
44	pushl	%ebp
45	movl	%esp,%ebp
46	pushl	%ebx
47	pushl	%ecx
48	pushl	%edx
49	push	%esi
50	push	%edi
51
52	movl	8(%ebp), %edi	/* vbe info block address*/
53
54	call	_C_LABEL(prot_to_real)
55	.code16
56
57	push	%es
58
59	push	%di
60	shrl	$4, %edi
61	mov	%ds, %ax
62	add	%di, %ax
63	mov	%ax, %es
64	pop	%di
65	and	$0xf, %di	/* mode info block address now in es:di */
66
67	movw	$0x4f00, %ax	/* get vbe info block */
68	int	$0x10
69
70	pop	%es
71
72	calll	_C_LABEL(real_to_prot)
73	.code32
74
75	andl	$0xffff,%eax
76
77	pop	%edi
78	pop	%esi
79	popl	%edx
80	popl	%ecx
81	popl	%ebx
82	popl	%ebp
83	ret
84
85/*
86 * Function 01h - Return VBE Mode Information
87 *
88 * int biosvbe_get_mode_info(int mode, struct modeinfoblock *mi)
89 * return: VBE call status
90 */
91ENTRY(biosvbe_get_mode_info)
92	pushl	%ebp
93	movl	%esp,%ebp
94	pushl	%ebx
95	pushl	%ecx
96	pushl	%edx
97	push	%esi
98	push	%edi
99
100	movl	8(%ebp), %ecx	/* mode number */
101	movl	12(%ebp), %edi	/* mode info block address */
102
103	call	_C_LABEL(prot_to_real)
104	.code16
105
106	push	%es
107
108	push	%di
109	shrl	$4, %edi
110	mov	%ds, %ax
111	add	%di, %ax
112	mov	%ax, %es
113	pop	%di
114	and	$0xf, %di	/* mode info block address now in es:di */
115
116	movw	$0x4f01, %ax	/* get mode info block */
117	int	$0x10
118
119	pop	%es
120
121	calll	_C_LABEL(real_to_prot)
122	.code32
123
124	andl	$0xffff,%eax
125
126	pop	%edi
127	pop	%esi
128	popl	%edx
129	popl	%ecx
130	popl	%ebx
131	popl	%ebp
132	ret
133
134/*
135 * Function 02h - Set VBE Mode
136 *
137 * int biosvbe_set_mode(int mode)
138 * return: VBE call status
139 */
140ENTRY(biosvbe_set_mode)
141	pushl	%ebp
142	movl	%esp,%ebp
143	pushl	%ebx
144	pushl	%ecx
145	pushl	%edx
146	push	%esi
147	push	%edi
148
149	movl	8(%ebp), %ebx	/* mode number */
150	orl	$0x4000, %ebx
151
152	call	_C_LABEL(prot_to_real)
153	.code16
154
155	movw	$0x4f02, %ax	/* set mode */
156	int	$0x10
157
158	calll	_C_LABEL(real_to_prot)
159	.code32
160
161	andl	$0xffff,%eax
162
163	pop	%edi
164	pop	%esi
165	popl	%edx
166	popl	%ecx
167	popl	%ebx
168	popl	%ebp
169	ret
170
171/*
172 * Function 08h - Set/Get DAC Palette Format
173 *
174 * int biosvbe_palette_format(int format)
175 * return: VBE call status
176 */
177ENTRY(biosvbe_palette_format)
178	pushl	%ebp
179	movl	%esp,%ebp
180	pushl	%ebx
181	pushl	%ecx
182	pushl	%edx
183	push	%esi
184	push	%edi
185
186	movl	8(%ebp), %ebx	/* mode number */
187
188	call	_C_LABEL(prot_to_real)
189	.code16
190
191	movw	$0x4f08, %ax	/* get/set palette format */
192	int	$0x10
193
194	calll	_C_LABEL(real_to_prot)
195	.code32
196
197	andl	$0xffff,%eax
198
199	pop	%edi
200	pop	%esi
201	popl	%edx
202	popl	%ecx
203	popl	%ebx
204	popl	%ebp
205	ret
206
207/*
208 * Function 09h - Set/Get Palette Data
209 *
210 * int biosvbe_palette_data(int mode, int reg, struct paletteentry *)
211 * return: VBE call status
212 */
213ENTRY(biosvbe_palette_data)
214	pushl	%ebp
215	movl	%esp,%ebp
216	pushl	%ebx
217	pushl	%ecx
218	pushl	%edx
219	push	%esi
220	push	%edi
221
222	movl	8(%ebp), %ebx	/* mode number */
223	movl	12(%ebp), %edx	/* register */
224	movl	16(%ebp), %edi	/* palette entry address */
225	movl	$1, %ecx	/* # palette entries to update */
226
227	call	_C_LABEL(prot_to_real)
228	.code16
229
230	push	%es
231
232	push	%di
233	shrl	$4, %edi
234	mov	%ds, %ax
235	add	%di, %ax
236	mov	%ax, %es
237	pop	%di
238	and	$0xf, %di	/* palette entry address now in es:di */
239
240	movw	$0x4f09, %ax	/* get/set palette entry */
241	int	$0x10
242
243	pop	%es
244
245	calll	_C_LABEL(real_to_prot)
246	.code32
247
248	andl	$0xffff,%eax
249
250	pop	%edi
251	pop	%esi
252	popl	%edx
253	popl	%ecx
254	popl	%ebx
255	popl	%ebp
256	ret
257