]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/doscmd/bios.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / usr.bin / doscmd / bios.c
1 /*
2  * Copyright (c) 1992, 1993, 1996
3  *      Berkeley Software Design, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Berkeley Software
16  *      Design, Inc.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      BSDI bios.c,v 2.3 1996/04/08 19:32:19 bostic Exp
31  *
32  * $FreeBSD$
33  */
34
35 #include "doscmd.h"
36 #include "mouse.h"
37 #include "com.h"
38
39 #define BIOS_copyright         0xfe000
40 #define BIOS_reset             0xfe05b
41 #define BIOS_nmi               0xfe2c3
42 #define BIOS_hdisk_table       0xfe401
43 #define BIOS_boot              0xfe6f2
44 #define BIOS_comm_table        0xfe729
45 #define BIOS_comm_io           0xfe739
46 #define BIOS_keyboard_io       0xfe82e
47 #define BIOS_keyboard_isr      0xfe987
48 #define BIOS_fdisk_io          0xfec59
49 #define BIOS_fdisk_isr         0xfef57
50 #define BIOS_disk_parms        0xfefc7
51 #define BIOS_printer_io        0xfefd2
52 #define BIOS_video_io          0xff065
53 #define BIOS_video_parms       0xff0a4
54 #define BIOS_mem_size          0xff841
55 #define BIOS_equipment         0xff84d
56 #define BIOS_cassette_io       0xff859
57 #define BIOS_video_font        0xffa6e
58 #define BIOS_time_of_day       0xffe6e
59 #define BIOS_timer_int         0xffea5
60 #define BIOS_vector            0xffef3
61 #define BIOS_dummy_iret        0xfff53
62 #define BIOS_print_screen      0xfff54
63 #define BIOS_hard_reset        0xffff0
64 #define BIOS_date_stamp        0xffff5
65 #define BIOS_hardware_id       0xffffe
66
67 static u_char video_parms[] = {
68     0x38, 40, 0x2d, 10, 0x1f, 6, 0x19, 0x1c, 2,  7,  6,  7, 0, 0, 0, 0,
69     0x71, 80, 0x5a, 10, 0x1f, 6, 0x19, 0x1c, 2,  7,  6,  7, 0, 0, 0, 0,
70     0x38, 40, 0x2d, 10, 0x7f, 6, 0x64, 0x70, 2,  1,  6,  7, 0, 0, 0, 0,
71     0x61, 80, 0x52, 15, 0x19, 6, 0x19, 0x19, 2, 13, 11, 12, 0, 0, 0, 0,
72 };
73
74 static u_char disk_params[] = {
75     0xdf, 2, 0x25, 2, 0x0f, 0x1b, 0xff, 0x54, 0xf6, 0x0f, 8,
76 };
77
78 static u_short comm_table[] = {
79     1047, 768, 384, 192, 96, 48, 24, 12,
80 };
81
82 /* exports */
83
84 int              nfloppies = 0;
85 int              ndisks = 0;
86 int              nserial = 0;
87 int              nparallel = 0;
88 unsigned long   rom_config;
89
90 /*
91 ** BIOS equipment list
92 */
93 static void
94 int11(regcontext_t *REGS)
95 {
96     R_AX = 
97         (nfloppies ? 1:0) |     /* do we have any floppydisks? */
98         (0x2 << 4) |            /* 80x25 colour */
99         ((nfloppies-1) << 6) |  /* how many floppies? */
100         (nserial << 9) |        /* serial ports? */
101         (nparallel << 14);      /* parallel ports? */
102 }
103
104 /*
105 ** get installed memory
106 */
107 static void
108 int12(regcontext_t *REGS)
109 {
110     R_AX = 640;
111 }
112
113 /*
114 ** assorted oddments
115 */
116 static void
117 int15(regcontext_t *REGS)
118 {
119     int cond;
120     int count;
121
122     R_FLAGS &= ~PSL_C;
123
124     switch (R_AH) {
125     case 0x00:                  /* Get Cassette Status */
126         R_AH = 0x86;
127         R_FLAGS |= PSL_C;       /* We don't support a cassette */
128         break;
129
130     case 0x04:  /* Set ABIOS table */
131         R_FLAGS |= PSL_C;       /* We don't support it */
132         break;
133
134     case 0x4f:
135         /*
136          * XXX - Check scan code in GET8L(sc->sc_eax).
137          */
138         break;
139     case 0x88:
140         get_raw_extmemory_info(REGS);
141         break;
142     case 0xc0:  /* get configuration */
143         debug (D_TRAPS|0x15, "Get configuration\n", R_DX);
144         PUTVEC(R_ES, R_BX, rom_config);
145         R_AH = 0;
146         break;
147     case 0xc1:  /* get extended BIOS data area */
148         R_FLAGS |= PSL_C;
149         break;
150     case 0xc2:  /* Pointing device */
151         R_FLAGS |= PSL_C;
152         R_AH = 5;       /* No pointer */
153         break;
154     default:
155         unknown_int2(0x15, R_AX, REGS);
156         break;
157     }
158 }
159
160
161 extern void int16(regcontext_t *REGS);
162 extern void int17(regcontext_t *REGS);
163 extern void int1a(regcontext_t *REGS);
164
165 void
166 bios_init(void)
167 {
168     int i, j, k;
169     u_char *jtab;
170     struct timeval tv;
171     time_t tv_sec;
172     struct timezone tz;
173     struct tm tm;
174     u_long vec;
175
176     if (1 || !raw_kbd) {
177         strcpy((char *)BIOS_copyright,
178                "Copyright (C) 1993 Krystal Technologies/BSDI");
179
180         *(u_short *)BIOS_reset = 0xffcd;
181         *(u_short *)BIOS_nmi = 0xffcd;
182         *(u_short *)BIOS_boot = 0xffcd;
183         *(u_short *)BIOS_comm_io = 0xffcd;
184         *(u_short *)BIOS_keyboard_io = 0xffcd;
185         *(u_short *)BIOS_keyboard_isr = 0xffcd;
186         *(u_short *)BIOS_fdisk_io = 0xffcd;
187         *(u_short *)BIOS_fdisk_isr = 0xffcd;
188         *(u_short *)BIOS_printer_io = 0xffcd;
189         *(u_short *)BIOS_video_io = 0xffcd;
190         *(u_short *)BIOS_cassette_io = 0xffcd;
191         *(u_short *)BIOS_time_of_day = 0xffcd;
192         *(u_short *)BIOS_timer_int = 0xffcd;
193         *(u_short *)BIOS_dummy_iret = 0xffcd;
194         *(u_short *)BIOS_print_screen = 0xffcd;
195         *(u_short *)BIOS_hard_reset = 0xffcd;
196         *(u_short *)BIOS_mem_size = 0xffcd;
197         *(u_short *)BIOS_equipment = 0xffcd;
198         *(u_short *)BIOS_vector = 0xffcd;
199         *(u_char *)0xffff2 = 0xcf;                      /* IRET */
200
201         /*
202          *memcpy((u_char *)BIOS_video_parms, video_parms, sizeof(video_parms));
203          */
204         memcpy((u_char *)BIOS_disk_parms, disk_params, sizeof(disk_params));
205         memcpy((u_char *)BIOS_comm_table, comm_table, sizeof(comm_table));
206
207         *(u_short *)BIOS_video_font = 0xffcd;
208         
209         jtab = (u_char *)BIOS_date_stamp;
210         *jtab++ = '1';
211         *jtab++ = '0';
212         *jtab++ = '/';
213         *jtab++ = '3';
214         *jtab++ = '1';
215         *jtab++ = '/';
216         *jtab++ = '9';
217         *jtab++ = '3';
218
219 #if 0   
220         *(u_char *)BIOS_hardware_id = 0xfe;           /* Identify as a PC/XT */
221         *(u_char *)BIOS_hardware_id = 0xff;           /* Identify as a PC */
222 #endif
223         *(u_char *)BIOS_hardware_id = 0xfc;           /* Identify as a PC/AT */
224     }
225
226     /*
227      * Interrupt revectors F000:0000 - F000:03ff
228      */
229     for (i = 0, j = 0, k = 0; i < 0x100; ++i) {
230         if ((i >= 0x60 && i < 0x68) ||
231             (i >= 0x78 && i < 0xe2))
232             continue;
233         if ((i >= 0x00 && i < 0x2f) ||
234             (i >= 0x30 && i < 0xfe)) {
235             ivec[i] = 0xF0300000L | (k * 1);
236             jtab = (u_char *)VECPTR(ivec[i]);
237             *jtab++ = 0xf4;     /* HLT */
238             ++k;
239         } else {
240             ivec[i] = 0xF0000000L | (j * 6);
241             jtab = (u_char *)VECPTR(ivec[i]);
242             *jtab++ = 0xcd;     /* INT i */
243             *jtab++ = i;
244             *jtab++ = 0xca;     /* RETF 2 */
245             *jtab++ = 2;
246             *jtab++ = 0;
247             ++j;
248         }
249     }
250
251     /*
252      * Misc variables from F000:0400 - F000:0fff
253      */
254     rom_config = 0xF0000400;
255     jtab = (u_char *)VECPTR(rom_config);
256     *jtab++ = 20;           /* length of entry */
257     *jtab++ = 0;
258     *jtab++ = *(u_char *)BIOS_hardware_id;
259     *jtab++ = 0x00;         /* Sub model */
260     *jtab++ = 0x01;         /* Bios Rev Enhanced kbd w/3.5" floppy */
261     *jtab++ = 0x20;         /* real time clock present */
262     *jtab++ = 0;            /* Reserved */
263     *jtab++ = 0;
264     *jtab++ = 0;
265     *jtab++ = 0;
266     strcpy((char *)jtab, "BSDI BIOS");
267     *jtab += 10;
268
269     InDOS = jtab++;
270     *InDOS = 0;
271
272     mouse_area = jtab;
273     jtab += 0x10;
274
275     *(u_short *)&BIOSDATA[0x10] = 
276         (1 << 0) |              /* Diskette avail for boot */
277         (1 << 1) |              /* Math co-processor */
278         (nmice << 2) |          /* No pointing device */
279         (2 << 4) |              /* Initial video (80 x 25 C) */
280         (nfloppies - 1 << 6) |  /* Number of floppies - 1 */
281         (nserial << 9) |        /* Number of serial devices */
282         (nparallel << 14);      /* Number of parallel devices */
283
284
285     *(u_short *)&BIOSDATA[0x13] = 640;  /* Amount of memory */
286     BIOSDATA[0x75] = ndisks;            /* number of fixed disks */
287     
288     BIOSDATA[0x8F] = 0;
289     if (nfloppies >= 1) {
290         BIOSDATA[0x8F] |= 0x04;
291         BIOSDATA[0x90] = 0x40;
292     }
293     if (nfloppies >= 2) {
294         BIOSDATA[0x8F] |= 0x40;
295         BIOSDATA[0x91] = 0x40;
296     }
297
298     gettimeofday(&tv, &tz);
299     tv_sec = tv.tv_sec;
300     tm = *localtime(&tv_sec);
301     *(u_long *)&BIOSDATA[0x6c] =
302         (((tm.tm_hour * 60 + tm.tm_min) * 60) + tm.tm_sec) * 182 / 10; 
303
304     vec = insert_softint_trampoline();
305     ivec[0x11] = vec;
306     register_callback(vec, int11, "int 11");
307     
308     vec = insert_softint_trampoline();
309     ivec[0x12] = vec;
310     register_callback(vec, int12, "int 12");
311
312     vec = insert_softint_trampoline();
313     ivec[0x14] = vec;
314     register_callback(vec, int14, "int 14");
315
316     vec = insert_softint_trampoline();
317     ivec[0x15] = vec;
318     register_callback(vec, int15, "int 15");
319
320     vec = insert_softint_trampoline();
321     ivec[0x16] = vec;
322     register_callback(vec, int16, "int 16");
323
324     vec = insert_softint_trampoline();
325     ivec[0x17] = vec;
326     register_callback(vec, int17, "int 17");
327
328     vec = insert_softint_trampoline();
329     ivec[0x1a] = vec;
330     register_callback(vec, int1a, "int 1a");
331 }