]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/boot/pc98/boot2/bios.S
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / sys / boot / pc98 / boot2 / bios.S
1 /*
2  * Mach Operating System
3  * Copyright (c) 1992, 1991 Carnegie Mellon University
4  * All Rights Reserved.
5  * 
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  * 
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  * 
16  * Carnegie Mellon requests users of this software to return to
17  * 
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  * 
23  * any improvements or extensions that they make and grant Carnegie Mellon
24  * the rights to redistribute these changes.
25  *
26  *      from: Mach, Revision 2.2  92/04/04  11:34:26  rpd
27  * $FreeBSD$
28  */
29
30 /*
31   Copyright 1988, 1989, 1990, 1991, 1992 
32    by Intel Corporation, Santa Clara, California.
33
34                 All Rights Reserved
35
36 Permission to use, copy, modify, and distribute this software and
37 its documentation for any purpose and without fee is hereby
38 granted, provided that the above copyright notice appears in all
39 copies and that both the copyright notice and this permission notice
40 appear in supporting documentation, and that the name of Intel
41 not be used in advertising or publicity pertaining to distribution
42 of the software without specific, written prior permission.
43
44 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
45 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
46 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
47 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
49 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51 */
52 /*
53  * Ported to PC-9801 by Yoshio Kimura
54  */
55
56 /*
57  * Extensions for El Torito CD-ROM booting:
58  *
59  * Copyright © 1997 Pluto Technologies International, Inc.  Boulder CO
60  * Copyright © 1997 interface business GmbH, Dresden.
61  *      All rights reserved.
62  *
63  * This code has been written by Jörg Wunsch, Dresden.
64  * Direct comments to <joerg_wunsch@interface-business.de>.
65  *
66  * Redistribution and use in source and binary forms, with or without
67  * modification, are permitted provided that the following conditions
68  * are met:
69  * 1. Redistributions of source code must retain the above copyright
70  *    notice, this list of conditions and the following disclaimer.
71  * 2. Redistributions in binary form must reproduce the above copyright
72  *    notice, this list of conditions and the following disclaimer in the
73  *    documentation and/or other materials provided with the distribution.
74  *
75  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
76  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
77  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
78  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
79  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
80  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
81  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
82  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
83  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
84  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
85  * POSSIBILITY OF SUCH DAMAGE.
86  *
87  */
88
89         .file   "bios.s"
90
91 #include "asm.h"
92         .text
93
94 #ifndef CDBOOT
95
96 /*
97  * biosread(dev, cyl, head, sec, nsec, offset)
98  *      Read "nsec" sectors from disk to offset "offset" in boot segment
99  * BIOS call "INT 0x1B Function 0xn6" to read sectors from disk into memory
100  *      Call with       %ah = 0xd6(for floppy disk) or 0x06(for hard disk)
101  *                      %al = DA/UA
102  *                      %bx = data length
103  *                      %ch = sector size(for floppy) or cylinder(for hard)
104  *                      %cl = cylinder
105  *                      %dh = head
106  *                      %dl = sector
107  *                      %es:%bp = segment:offset of buffer
108  *      Return:         
109  *                      %al = 0x0 on success; err code on failure
110  */
111
112 ENTRY(biosread)
113         push    %ebp
114         mov     %esp, %ebp
115
116         push    %ebx
117         push    %esi
118         push    %edi
119
120         movb    0x14(%ebp), %dl         /* sector */
121         movb    0x10(%ebp), %dh         /* head */
122         movw    0x0c(%ebp), %cx         /* cylinder */
123         movb    0x08(%ebp), %al         /* DA/UA */
124         movb    $0x06, %ah
125         andb    $0xf0, %al
126         cmpb    $0x30, %al
127         jz      fd
128         cmpb    $0x90, %al
129         jnz     1f
130 fd:
131         incb    %dl
132         movb    $0x02, %ch
133         movb    $0xd6, %ah
134 1:
135         movb    0x08(%ebp), %al
136         movl    %eax, %ebx
137
138         /* prot_to_real will set %es to BOOTSEG */
139         call    EXT(prot_to_real)       /* enter real mode */
140         mov     %ebx, %eax
141         xor     %ebx, %ebx
142         addr32
143         movb    0x18(%ebp), %bl         /* number of sectors */
144         data32
145         shl     $9, %ebx
146         data32
147         push    %ebx
148         addr32
149         data32
150         mov     0x1c(%ebp), %ebx
151         data32
152         mov     %ebx, %ebp
153         data32
154         pop     %ebx
155
156         int     $0x1b
157         jc      1f
158         xor     %eax, %eax
159 1:
160         /* save return value (actually movw %ax, %bx) */
161         mov     %eax, %ebx
162
163         data32
164         call    EXT(real_to_prot)       /* back to protected mode */
165
166         xor     %eax, %eax
167         movb    %bh, %al                /* return value in %ax */
168
169         pop     %edi
170         pop     %esi
171         pop     %ebx
172         pop     %ebp
173
174         ret
175
176 #else /* CDBOOT */
177
178
179 /*
180  * int
181  * getbootspec(struct specpacket *offset)
182  *
183  * Read CD-ROM boot specification packet to "offset".
184  */
185 ENTRY(getbootspec)
186         push    %ebp
187         mov     %esp, %ebp
188
189         push    %esi
190         push    %ebx
191
192         movw    0x8(%ebp), %si
193         mov     $0x7f, %edx
194
195         /* prot_to_real will set %es to BOOTSEG */
196         call    EXT(prot_to_real)       /* enter real mode */
197         movw    $0x4b01, %ax            /* (do not) terminate disk emulation */
198         movb    $0x7f, %dl              /* any drive */
199
200         sti
201         int     $0x13
202         cli
203
204         /* save return value (actually movw %ax, %bx) */
205         mov     %eax, %ebx
206
207         data32
208         call    EXT(real_to_prot)       /* back to protected mode */
209
210         xor     %eax, %eax
211         movb    %bh, %al                /* return value in %ax */
212
213         pop     %ebx
214         pop     %esi
215         pop     %ebp
216
217         ret
218
219
220 /*
221  * int
222  * biosreadlba(struct daddrpacket *daddr)
223  *      Read sectors using the BIOS "read extended" function
224  * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
225  *      Call with       %ah = 0x42
226  *                      %dl = drive (0x0 for floppy disk, or emulated CD)
227  *                      %ds:%si = ptr to disk address packet
228  *      Return:
229  *                      %ah = 0x0 on success; err code on failure
230  */
231
232 ENTRY(biosreadlba)
233         push    %ebp
234         mov     %esp, %ebp
235
236         push    %ebx
237         push    %esi
238
239         movw    8(%ebp), %si
240         movl    $0, %edx                /* emulated CD is always drive 0 */
241
242         /* prot_to_real will set %es to BOOTSEG */
243         call    EXT(prot_to_real)       /* enter real mode */
244         movw    $0x4200, %ax            /* subfunction */
245         movb    $0, %dl
246
247         sti
248         int     $0x13
249         cli
250
251         /* save return value (actually movw %ax, %bx) */
252         mov     %eax, %ebx
253
254         data32
255         call    EXT(real_to_prot)       /* back to protected mode */
256
257         xor     %eax, %eax
258         movb    %bh, %al                /* return value in %ax */
259
260         pop     %esi
261         pop     %ebx
262         pop     %ebp
263
264         ret
265
266 #endif /* !CDBOOT */
267
268 /*
269  * getc()
270  * BIOS call "INT 18H Function 00H" to read character from keyboard
271  *      Call with       %ah = 0x0
272  *      Return:         %ah = keyboard scan code
273  *                      %al = ASCII character
274  */
275
276 ENTRY(getc)
277         push    %ebp
278         mov     %esp, %ebp
279         push    %ebx                    /* save %ebx */
280         push    %esi
281         push    %edi
282
283         call    EXT(prot_to_real)
284
285         movb    $0x0, %ah
286         int     $0x18
287
288         movb    %al, %bl                /* real_to_prot uses %eax */
289
290         data32
291         call    EXT(real_to_prot)
292
293         xor     %eax, %eax
294         movb    %bl, %al
295
296         pop     %edi
297         pop     %esi
298         pop     %ebx
299         pop     %ebp
300         ret
301 /*
302  * ischar()
303  *      if there is a character pending, return it; otherwise return 0
304  * BIOS call "INT 18H Function 01H" to check whether a character is pending
305  *      Call with       %ah = 0x1
306  *      Return:
307  *              If key waiting to be input:
308  *                      %ah = keyboard scan code
309  *                      %al = ASCII character
310  *                      %bh = 1
311  *              else
312  *                      %bh = 0
313  */
314 ENTRY(ischar)
315         push    %ebp
316         mov     %esp, %ebp
317         push    %ebx
318         push    %esi
319         push    %edi
320
321         call    EXT(prot_to_real)       /* enter real mode */
322
323         xor     %ebx, %ebx
324         movb    $0x1, %ah
325         int     $0x18
326         andb    %bh, %bh
327         data32
328         jz      nochar
329         movb    %al, %bl
330
331 nochar:
332         data32
333         call    EXT(real_to_prot)
334
335         xor     %eax, %eax
336         movb    %bl, %al
337
338         pop     %edi
339         pop     %esi
340         pop     %ebx
341         pop     %ebp
342         ret
343
344 /*
345  *
346  * get_diskinfo():  return a word that represents the
347  *      max number of sectors and heads and drives for this device
348  *
349  */
350
351 ENTRY(get_diskinfo)
352         push    %ebp
353         mov     %esp, %ebp
354         push    %ebx
355         push    %esi
356         push    %edi
357
358         movb    0x8(%ebp), %dl          /* diskinfo(drive #) */
359         call    EXT(prot_to_real)       /* enter real mode */
360
361         movb    %dl, %al                /* ask for disk info */
362         andb    $0xf0, %al
363         cmpb    $0x30, %al
364         jz      fdd4
365         cmpb    $0x90, %al
366         jz      fdd
367
368         movb    %dl, %al
369         movb    $0x84, %ah
370
371         int     $0x1b
372
373         jnc     ok
374         /*
375          * Urk.  Call failed.  It is not supported for floppies by old BIOS's.
376          * Guess it's a 15-sector floppy.
377          */
378 fdd4:
379         movb    $18, %dl
380         jmp     1f
381 fdd:
382         movb    $15, %dl                /* max sector */
383 1:
384         subb    %ah, %ah                /* %ax = 0 */
385         movb    %al, %al
386         movb    %ah, %bh                /* %bh = 0 */
387         movb    $2, %bl                 /* %bl  bits 0-3 = drive type,
388                                                 bit    2 = 1.2M */
389         movb    $79, %ch                /* max track */
390         movb    $1, %cl                 /* # floppy drives installed */
391         movb    $2, %dh                 /* max head */
392         /* es:di = parameter table */
393         /* carry = 0 */
394 ok:
395
396         data32
397         call    EXT(real_to_prot)       /* back to protected mode */
398
399         /* 
400          * form a longword representing all this gunk:
401          *      16 bit cylinder
402          *       8 bit head
403          *       8 bit sector
404          */
405         mov     %ecx, %eax
406         sall    $16,%eax                /* << 16 */
407         movb    %dh, %ah                /* max head */
408         movb    %dl, %al                /* max sector (and # sectors) */
409
410         pop     %edi
411         pop     %esi
412         pop     %ebx
413         pop     %ebp
414         ret
415
416 /*
417  *
418  * memsize(i) :  return the memory size in KB. i == 0 for conventional memory,
419  *              i == 1 for extended memory
420  *              Both have the return value in AX.
421  *
422  */
423
424 ENTRY(memsize)
425         push    %ebp
426         mov     %esp, %ebp
427         push    %ebx
428         push    %esi
429         push    %edi
430
431         mov     8(%ebp), %ebx
432
433         xor     %eax, %eax
434         cmpb    $0x01, %bl
435         jnz     memcnv
436 memext:
437         movb    0xA1401 - BOOTSEG * 0x10, %al
438         shll    $7, %eax
439         xorl    %ebx, %ebx
440         movw    0xA1594 - BOOTSEG * 0x10, %bx
441         shll    $10, %ebx
442         addl    %ebx, %eax
443         jmp     xdone
444
445 memcnv:
446         movb    0xA1501 - BOOTSEG * 0x10, %al
447         andb    $0x07, %al
448         incl    %eax
449         shll    $7, %eax
450
451 xdone:
452         pop     %edi
453         pop     %esi
454         pop     %ebx
455         pop     %ebp
456         ret