xref: /minix/sys/arch/i386/stand/lib/biosvbe.S (revision 58a2b000)
1/* $NetBSD: biosvbe.S,v 1.3 2011/02/20 22:03:13 jakllsch 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
258/*
259 * Function 15h BL=00h - Report VBE/DDC Capabilities
260 *
261 * int biosvbe_ddc_caps(void)
262 * return: VBE/DDC capabilities
263 */
264ENTRY(biosvbe_ddc_caps)
265	pushl	%ebp
266	movl	%esp,%ebp
267	pushl	%ebx
268	pushl	%ecx
269	pushl	%edx
270	push	%esi
271	push	%edi
272
273	call	_C_LABEL(prot_to_real)
274	.code16
275
276	pushw	%es
277
278	xorw	%di, %di
279	movw	%di, %es	/* es:di == 0:0 */
280
281	movw	$0x4f15, %ax	/* display identification extensions */
282	mov	$0x00, %bx	/* report DDC capabilities */
283	mov	$0x00, %cx	/* controller unit number (00h = primary) */
284	int	$0x10
285
286	popw	%es
287
288	calll	_C_LABEL(real_to_prot)
289	.code32
290
291	movl	%eax,%ecx
292	movl	$0x0000,%eax
293	andl	$0xffff,%ecx
294	cmpl	$0x004f,%ecx
295	jne	1f
296	andl	$0xffff,%ebx
297	movl	%ebx,%eax
2981:
299
300	pop	%edi
301	pop	%esi
302	popl	%edx
303	popl	%ecx
304	popl	%ebx
305	popl	%ebp
306	ret
307
308/*
309 * Function 15h BL=01h - Read EDID
310 *
311 * int biosvbe_ddc_read_edid(int blockno, void *buf)
312 * return: VBE call status
313 */
314ENTRY(biosvbe_ddc_read_edid)
315	pushl	%ebp
316	movl	%esp,%ebp
317	pushl	%ebx
318	pushl	%ecx
319	pushl	%edx
320	push	%esi
321	push	%edi
322
323	movl	8(%ebp), %edx	/* EDID block number */
324	movl	12(%ebp), %edi	/* EDID block address */
325
326	call	_C_LABEL(prot_to_real)
327	.code16
328
329	push	%es
330
331	push	%di
332	shrl	$4, %edi
333	mov	%ds, %ax
334	add	%di, %ax
335	mov	%ax, %es
336	pop	%di
337	and	$0xf, %di	/* EDID block address now in es:di */
338
339	movw	$0x4f15, %ax	/* display identification extensions */
340	mov	$0x01, %bx	/* read EDID */
341	mov	$0x00, %cx	/* controller unit number (00h = primary) */
342	int	$0x10
343
344	pop	%es
345
346	calll	_C_LABEL(real_to_prot)
347	.code32
348
349	andl	$0xffff,%eax
350
351	pop	%edi
352	pop	%esi
353	popl	%edx
354	popl	%ecx
355	popl	%ebx
356	popl	%ebp
357	ret
358
359