#define I_NEED_OS2_H
#define INCL_DOSFILEMGR
#define INCL_KBD
#define INCL_VIO
#define INCL_DOSMISC
#define INCL_DOSPROCESS
#define INCL_DOSSEMAPHORES
#define INCL_DOSMODULEMGR
#define INCL_DOSFILEMGR
#include <float.h>
#include "X.h"
#include "Xmd.h"
#include "input.h"
#include "scrnintstr.h"
#include "compiler.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
VIOMODEINFO OriginalVideoMode;
void os2VideoNotify();
void os2HardErrorNotify();
void os2KbdMonitorThread();
void os2KbdBitBucketThread();
HEV hevPopupPending;
extern HEV hKbdSem;
extern BOOL os2HRTimerFlag;
static unsigned short cw;
extern void os2_checkinstallation();
void xf86OpenConsole()
{
os2_checkinstallation();
if (serverGeneration == 1) {
HKBD fd;
ULONG drive;
ULONG dummy;
KBDHWID hwid;
APIRET rc;
int VioTid;
ULONG actual_handles;
LONG new_handles;
char *x11r = getenv("X11ROOT");
if (x11r == NULL){
xf86Msg(X_ERROR,
"Environment variable X11ROOT is not set! Aborting...\n");
exit(1);
}
if (_chdir2(x11r) < 0) {
xf86Msg(X_ERROR,"Cannot change to X11ROOT directory!\n");
}
xf86Msg(X_INFO,"Console opened\n");
OriginalVideoMode.cb=sizeof(VIOMODEINFO);
rc=VioGetMode(&OriginalVideoMode,(HVIO)0);
if(rc!=0)
xf86Msg(X_ERROR,
"Could not get original video mode. RC=%d\n",rc);
xf86Info.consoleFd = -1;
new_handles = 0;
rc = DosSetRelMaxFH(&new_handles,&actual_handles);
if (actual_handles < 80) {
new_handles = 80 - actual_handles;
rc = DosSetRelMaxFH(&new_handles,&actual_handles);
xf86Msg(X_INFO,"Increased number of available handles to %d\n",
actual_handles);
}
rc = KbdGetFocus(0,0);
if (rc != 0)
FatalError("xf86OpenConsole: cannot grab kbd focus, rc=%d\n",rc);
rc = KbdOpen(&fd);
if (rc != 0)
FatalError("xf86OpenConsole: cannot open keyboard, rc=%d\n",rc);
xf86Info.consoleFd = fd;
xf86Msg(X_INFO,"Keyboard opened\n");
KbdFreeFocus(0);
rc = KbdGetFocus(0,fd);
if (rc != 0)
FatalError("xf86OpenConsole: cannot set local kbd focus, rc=%d\n",rc);
rc = DosCreateEventSem(NULL,&hKbdSem,DC_SEM_SHARED,TRUE);
if (rc != 0)
FatalError("xf86OpenConsole: cannot create keyboard queue semaphore, rc=%d\n",rc);
rc = DosCreateEventSem("\\SEM32\\XF86PUP",&hevPopupPending,DC_SEM_SHARED,1);
if (rc)
xf86Msg(X_ERROR,
"Could not create popup semaphore! RC=%d\n",rc);
#if 0
rc=VioRegister("xf86vio","XF86POPUP_SUBCLASS",0x20002004L,0L);
if (rc) {
FatalError("Could not register XF86VIO.DLL module. Please install in LIBPATH! RC=%d\n",
rc);
}
#endif
VioTid=_beginthread(os2VideoNotify,NULL,0x4000,(void *)NULL);
xf86Msg(X_INFO,"Started Vio thread, Tid=%d\n",VioTid);
rc=DosSetPriority(2,3,0,VioTid);
VioTid=_beginthread(os2HardErrorNotify,NULL,0x4000,(void *)NULL);
xf86Msg(X_INFO,"Started hard error Vio mode monitor thread, Tid=%d\n",
VioTid);
rc=DosSetPriority(2,3,0,VioTid);
rc = KbdSetCp(0,0,fd);
if(rc != 0)
FatalError("xf86OpenConsole: cannot set keyboard codepage, rc=%d\n",rc);
VioTid=_beginthread(os2KbdMonitorThread,NULL,0x4000,(void *)NULL);
xf86Msg(X_INFO,"Started Kbd monitor thread, Tid=%d\n",VioTid);
rc=DosSetPriority(2,3,0,VioTid);
rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
rc = DosSuppressPopUps(0x0001L,drive+96);
hwid.cb = sizeof(hwid);
rc = KbdGetHWID(&hwid, fd);
if (rc == 0) {
switch (hwid.idKbd) {
default:
case 0xab54:
case 0:
case 1:
xf86Info.kbdType = KB_84; break;
case 0xab85:
FatalError("Unsupported extended 122key keyboard found!\n",0);
case 0xab41:
xf86Info.kbdType = KB_101; break;
}
} else
xf86Info.kbdType = KB_84;
VioTid=_beginthread(os2KbdBitBucketThread,NULL,0x2000,(void *)NULL);
xf86Msg(X_INFO,"Started Kbd bit-bucket thread, Tid=%d\n",VioTid);
#define DEFAULT_X86_FPU 0x037f
cw = _control87(DEFAULT_X86_FPU, 0xFFFF);
xf86Msg(X_INFO,"Checking FPCW: %#x\n",cw);
if (cw != DEFAULT_X86_FPU) {
cw = _control87(0,0);
xf86Msg(X_INFO,"Set FPCW to %#x\n",cw);
}
}
return;
}
void xf86CloseConsole()
{
APIRET rc;
ULONG drive;
if (xf86Info.consoleFd != -1) {
KbdClose(xf86Info.consoleFd);
}
VioSetMode(&OriginalVideoMode,(HVIO)0);
rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
rc = DosSuppressPopUps(0x0000L,drive+96);
rc = DosCloseEventSem(hevPopupPending);
rc = VioDeRegister();
return;
}
int xf86ProcessArgument (argc, argv, i)
int argc;
char *argv[];
int i;
{
return 0;
}
void xf86UseMsg()
{
return;
}