1 /* $NetBSD: apilib.c,v 1.6 2002/06/13 23:41:16 wiz Exp $ */
4 * Copyright (c) 1988 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 #if defined(__RCSID) && !defined(lint)
35 static char sccsid
[] = "@(#)apilib.c 4.2 (Berkeley) 4/26/91";
37 __RCSID("$NetBSD: apilib.c,v 1.6 2002/06/13 23:41:16 wiz Exp $");
41 #include "../ctlr/api.h"
46 api_sup_errno
= 0, /* Supervisor error number */
47 api_sup_fcn_id
= 0, /* Supervisor function id (0x12) */
48 api_fcn_errno
= 0, /* Function error number */
49 api_fcn_fcn_id
= 0; /* Function ID (0x6b, etc.) */
59 static int api_issue_regs(int, int , int , int , int , int , char *, int,
60 union REGS
*, struct SREGS
*);
61 static int api_issue(int, int , int , int , int , int , char *, int);
64 * Issue an API request, with reg structures supplied by the caller.
66 * Only certain routines need this (supervisor services come to mind).
70 api_issue_regs(ah
, al
, bh
, bl
, cx
, dx
, parms
, length
, regs
, sregs
)
71 int ah
, al
, bh
, bl
, cx
, dx
;
77 char far
*ourseg
= parms
;
85 sregs
->es
= FP_SEG(ourseg
);
86 regs
->x
.di
= FP_OFF(ourseg
);
89 int86x(API_INTERRUPT_NUMBER
, regs
, regs
, sregs
);
90 #endif /* defined(MSDOS) */
92 api_exch_api(regs
, sregs
, parms
, length
);
93 #endif /* defined(unix) */
95 if (regs
->h
.cl
!= 0) {
96 api_sup_errno
= regs
->h
.cl
;
105 * Issue an API request without requiring caller to supply
106 * registers. Most routines use this.
110 api_issue(ah
, al
, bh
, bl
, cx
, dx
, parms
, length
)
119 int length
; /* Length of parms */
124 return api_issue_regs(ah
, al
, bh
, bl
, cx
, dx
, parms
, length
, ®s
, &sregs
);
128 * Supervisor Services
132 api_name_resolve(name
)
135 NameResolveParms parms
;
140 for (i
= 0; i
< sizeof parms
.gate_name
; i
++) {
142 parms
.gate_name
[i
] = *name
++;
144 parms
.gate_name
[i
] = ' ';
148 if (api_issue_regs(NAME_RESOLUTION
, 0, 0, 0, 0, 0, (char *) &parms
,
149 sizeof parms
, ®s
, &sregs
) == -1) {
158 * Block until the oia or ps is modified.
162 api_ps_or_oia_modified()
167 if (api_issue_regs(PS_OR_OIA_MODIFIED
, 0, 0, 0, 0, 0, (char *) 0,
168 0, ®s
, &sregs
) == -1) {
174 #endif /* defined(unix) */
177 * Session Information Services
181 api_query_session_id(parms
)
182 QuerySessionIdParms
*parms
;
184 if (api_issue(0x09, QUERY_SESSION_ID
, 0x80, 0x20, 0,
185 gate_sessmgr
, (char *)parms
, sizeof *parms
) == -1) {
189 } else if (parms
->rc
== 0) {
192 api_fcn_errno
= parms
->rc
;
193 api_fcn_fcn_id
= parms
->function_id
;
200 api_query_session_parameters(parms
)
201 QuerySessionParametersParms
*parms
;
203 if (api_issue(0x09, QUERY_SESSION_PARAMETERS
, 0x80, 0x20, 0,
204 gate_sessmgr
, (char *)parms
, sizeof *parms
) == -1) {
208 } else if (parms
->rc
== 0) {
211 api_fcn_errno
= parms
->rc
;
212 api_fcn_fcn_id
= parms
->function_id
;
218 api_query_session_cursor(parms
)
219 QuerySessionCursorParms
*parms
;
221 if (api_issue(0x09, QUERY_SESSION_CURSOR
, 0x80, 0x20, 0xff,
222 gate_sessmgr
, (char *)parms
, sizeof *parms
) == -1) {
226 } else if (parms
->rc
== 0) {
229 api_fcn_errno
= parms
->rc
;
230 api_fcn_fcn_id
= parms
->function_id
;
240 api_connect_to_keyboard(parms
)
241 ConnectToKeyboardParms
*parms
;
243 if (api_issue(0x09, CONNECT_TO_KEYBOARD
, 0x80, 0x20, 0,
244 gate_keyboard
, (char *)parms
, sizeof *parms
) == -1) {
248 } else if (parms
->rc
== 0) {
251 api_fcn_errno
= parms
->rc
;
252 api_fcn_fcn_id
= parms
->function_id
;
259 api_disconnect_from_keyboard(parms
)
260 DisconnectFromKeyboardParms
*parms
;
262 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD
, 0x80, 0x20, 0,
263 gate_keyboard
, (char *)parms
, sizeof *parms
) == -1) {
267 } else if (parms
->rc
== 0) {
270 api_fcn_errno
= parms
->rc
;
271 api_fcn_fcn_id
= parms
->function_id
;
278 api_write_keystroke(parms
)
279 WriteKeystrokeParms
*parms
;
281 if (api_issue(0x09, WRITE_KEYSTROKE
, 0x80, 0x20, 0,
282 gate_keyboard
, (char *)parms
, sizeof *parms
) == -1) {
286 } else if (parms
->rc
== 0) {
289 api_fcn_errno
= parms
->rc
;
290 api_fcn_fcn_id
= parms
->function_id
;
297 api_disable_input(parms
)
298 DisableInputParms
*parms
;
300 if (api_issue(0x09, DISABLE_INPUT
, 0x80, 0x20, 0,
301 gate_keyboard
, (char *)parms
, sizeof *parms
) == -1) {
305 } else if (parms
->rc
== 0) {
308 api_fcn_errno
= parms
->rc
;
309 api_fcn_fcn_id
= parms
->function_id
;
315 api_enable_input(parms
)
316 EnableInputParms
*parms
;
318 if (api_issue(0x09, ENABLE_INPUT
, 0x80, 0x20, 0,
319 gate_keyboard
, (char *)parms
, sizeof *parms
) == -1) {
323 } else if (parms
->rc
== 0) {
326 api_fcn_errno
= parms
->rc
;
327 api_fcn_fcn_id
= parms
->function_id
;
337 api_copy_string(parms
)
338 CopyStringParms
*parms
;
340 if (api_issue(0x09, COPY_STRING
, 0x80, 0x20, 0xff,
341 gate_copy
, (char *)parms
, sizeof *parms
) == -1) {
345 } else if (parms
->rc
== 0) {
348 api_fcn_errno
= parms
->rc
;
349 api_fcn_fcn_id
= parms
->function_id
;
355 * Operator Information Area Services
359 api_read_oia_group(parms
)
360 ReadOiaGroupParms
*parms
;
362 if (api_issue(0x09, READ_OIA_GROUP
, 0x80, 0x20, 0xff,
363 gate_oiam
, (char *)parms
, sizeof *parms
) == -1) {
367 } else if (parms
->rc
== 0) {
370 api_fcn_errno
= parms
->rc
;
371 api_fcn_fcn_id
= parms
->function_id
;
377 * The "we are done" routine. This gets called last.
384 if (api_close_api() == -1) {
391 #endif /* defined(unix) */
396 * The initialization routine. Be sure to call this first.
407 regs
.h
.al
= API_INTERRUPT_NUMBER
;
408 intdosx(®s
, ®s
, &sregs
);
410 if ((regs
.x
.bx
== 0) && (sregs
.es
== 0)) {
411 return 0; /* Interrupt not being handled */
413 #endif /* defined(MSDOS) */
415 if (api_open_api((char *)0) == -1) {
418 #endif /* defined(unix) */
420 gate_sessmgr
= api_name_resolve("SESSMGR");
421 gate_keyboard
= api_name_resolve("KEYBOARD");
422 gate_copy
= api_name_resolve("COPY");
423 gate_oiam
= api_name_resolve("OIAM");
425 if ((gate_sessmgr
== gate_keyboard
) ||
426 (gate_sessmgr
== gate_copy
) ||
427 (gate_sessmgr
== gate_oiam
) ||
428 (gate_keyboard
== gate_copy
) ||
429 (gate_keyboard
== gate_oiam
) ||
430 (gate_copy
== gate_oiam
)) {
431 return 0; /* Interrupt doesn't seem correct */