Merge from vendor branch LIBPCAP:
[dragonfly.git] / usr.bin / doscmd / int2f.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 int2f.c,v 2.2 1996/04/08 19:32:53 bostic Exp
31  *
32  * $FreeBSD: src/usr.bin/doscmd/int2f.c,v 1.3.2.2 2002/04/25 11:04:51 tg Exp $
33  * $DragonFly: src/usr.bin/doscmd/int2f.c,v 1.2 2003/06/17 04:29:26 dillon Exp $
34  */
35
36 #include "doscmd.h"
37 #include "dispatch.h"
38 #include "tty.h"
39
40 /*
41 ** Multiplex interrupt.
42 **
43 ** subfunctions 0-0x7f reserved for DOS, some are implemented here.
44 **
45 */
46
47 /*
48 ** 2f:00 2f:01 2f:02 2f:03
49 **
50 ** Various PRINT.COM functions
51 */
52 static int
53 int2f_printer(regcontext_t *REGS)
54 {
55     debug (D_FILE_OPS, "Called printer function 0x%02x", R_AH);
56     R_AL = FUNC_NUM_IVALID;
57     return(0);
58 }
59
60 /*
61 ** 2f:12
62 **
63 ** DOS internal functions.  Only one we support is 0x2e, and then only to
64 ** complain about it.
65 */
66 static int
67 int2f_dosinternal(regcontext_t *REGS)
68 {
69     switch (R_AL) {
70     case 0x2e:          /* XXX - GET/SET ERROR TABLE ADDRESSES */
71         switch (R_DL) {
72         case 0x00:
73         case 0x02:
74         case 0x04:
75         case 0x06:
76             debug(D_ALWAYS,"DOS program attempted to get internal error table.\n");
77             break;
78             
79         case 0x01:
80         case 0x03:
81         case 0x05:
82         case 0x07:
83         case 0x09:
84             debug(D_ALWAYS,"DOS program attempted to set error table.\n");
85             break;
86         }       
87         
88     default:
89         unknown_int4(0x2f, 0x12, R_AL, R_DL, REGS);
90         break;
91     }
92     R_AL = FUNC_NUM_IVALID;
93     return(0);
94 }
95
96 /*
97 ** 2f:16
98 **
99 ** Windows Enhanced Mode functions.  Aigh!
100 */
101 static int
102 int2f_windows(regcontext_t *REGS)
103 {
104     switch (R_AL) {
105     case 0x00:
106         R_AL = 0x00;                    /* Neither Win 3.x nor 2.x running */
107         return(0);
108
109     case 0x80:                          /* installation check */
110         tty_pause();
111         R_AL = 0x00;
112         return(0);
113
114     default:
115         unknown_int3(0x2f, 0x16, R_AL, REGS);
116         break;
117     }
118     R_AL = FUNC_NUM_IVALID;
119     return(0);
120 }
121
122 /*
123 ** 2f:43
124 **
125 ** XMS interface
126 */
127 static int
128 int2f_xms(regcontext_t *REGS)
129 {
130     switch(R_AL) {
131     case 0:                     /* installation check */
132         return(0);              /* %al = 0 */
133     default:
134         R_AL = FUNC_NUM_IVALID;
135         return(0);
136     }
137 }
138         
139
140 static struct intfunc_table int2f_table[] = {
141
142     { 0x00,     IFT_NOSUBFUNC,  int2f_printer,          "printer"},
143     { 0x01,     IFT_NOSUBFUNC,  int2f_printer,          "printer"},
144     { 0x02,     IFT_NOSUBFUNC,  int2f_printer,          "printer"},
145     { 0x03,     IFT_NOSUBFUNC,  int2f_printer,          "printer"},
146     { 0x12,     IFT_NOSUBFUNC,  int2f_dosinternal,      "DOS internal function"},
147     { 0x16,     IFT_NOSUBFUNC,  int2f_windows,          "Windows detect"},
148     { 0x43,     IFT_NOSUBFUNC,  int2f_xms,              "XMS"},
149     { -1,       0,              NULL,                   NULL}
150 };
151
152 /*
153 ** int2f (multiplex) handler.
154 **
155 ** Note that due to the widely varied and inconsistent conventions, handlers
156 ** called from here are expected to manage their own return values.
157 */
158 void
159 int2f(regcontext_t *REGS)
160 {
161     int         idx;
162    
163     /* look up the handler for the current function */
164     idx = intfunc_search(int2f_table, R_AH, R_AL);
165
166     if (idx >= 0) {             /* respond on multiplex chain */
167         int2f_table[idx].handler(REGS);
168     } else {
169         unknown_int2(0x2f, R_AH, REGS);
170     }
171 }
172
173
174