diff options
Diffstat (limited to 'board/MAI/bios_emulator/scitech/src/pm/qnx')
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/_mtrrqnx.asm | 226 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/cpuinfo.c | 64 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/event.c | 602 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/mtrrqnx.c | 182 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/oshdr.h | 103 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/pm.c | 891 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/vflat.c | 49 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/qnx/ztimer.c | 91 |
8 files changed, 2208 insertions, 0 deletions
diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/_mtrrqnx.asm b/board/MAI/bios_emulator/scitech/src/pm/qnx/_mtrrqnx.asm new file mode 100644 index 0000000..5a3fe10 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/_mtrrqnx.asm @@ -0,0 +1,226 @@ +;**************************************************************************** +;* +;* SciTech OS Portability Manager Library +;* +;* ======================================================================== +;* +;* The contents of this file are subject to the SciTech MGL Public +;* License Version 1.0 (the "License"); you may not use this file +;* except in compliance with the License. You may obtain a copy of +;* the License at http://www.scitechsoft.com/mgl-license.txt +;* +;* Software distributed under the License is distributed on an +;* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +;* implied. See the License for the specific language governing +;* rights and limitations under the License. +;* +;* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +;* +;* The Initial Developer of the Original Code is SciTech Software, Inc. +;* All Rights Reserved. +;* +;* ======================================================================== +;* +;* Language: NASM +;* Environment: QNX +;* +;* Description: Assembler support routines for the Memory Type Range Register +;* (MTRR) module for QNX. +;* +;**************************************************************************** + + IDEAL + +include "scitech.mac" ; Memory model macros + +header _mtrrqnx ; Set up memory model + +begdataseg _mtrrqnx ; Start of code segment + +ifdef USE_NASM +%define R0_FLUSH_TLB 0 +%define R0_SAVE_CR4 1 +%define R0_RESTORE_CR4 2 +%define R0_READ_MSR 3 +%define R0_WRITE_MSR 4 +else +R0_FLUSH_TLB EQU 0 +R0_SAVE_CR4 EQU 1 +R0_RESTORE_CR4 EQU 2 +R0_READ_MSR EQU 3 +R0_WRITE_MSR EQU 4 +endif + +cpublic _PM_R0 +_PM_R0_service dd 0 +_PM_R0_reg dd 0 +_PM_R0_eax dd 0 +_PM_R0_edx dd 0 + +enddataseg _mtrrqnx ; Start of code segment + +begcodeseg _mtrrqnx ; Start of code segment + +P586 + +;---------------------------------------------------------------------------- +; ulong _MTRR_disableInt(void); +;---------------------------------------------------------------------------- +; Return processor interrupt status and disable interrupts. +;---------------------------------------------------------------------------- +cprocstart _MTRR_disableInt + + pushfd ; Put flag word on stack +; cli ; Disable interrupts! + pop eax ; deposit flag word in return register + ret + +cprocend + +;---------------------------------------------------------------------------- +; void _MTRR_restoreInt(ulong ps); +;---------------------------------------------------------------------------- +; Restore processor interrupt status. +;---------------------------------------------------------------------------- +cprocstart _MTRR_restoreInt + + ARG ps:ULONG + + push ebp + mov ebp,esp ; Set up stack frame + push [ULONG ps] + popfd ; Restore processor status (and interrupts) + pop ebp + ret + +cprocend + +;---------------------------------------------------------------------------- +; uchar _MTRR_getCx86(uchar reg); +;---------------------------------------------------------------------------- +; Read a Cyrix CPU indexed register +;---------------------------------------------------------------------------- +cprocstart _MTRR_getCx86 + + ARG reg:UCHAR + + enter_c + mov al,[reg] + out 22h,al + in al,23h + leave_c + ret + +cprocend + +;---------------------------------------------------------------------------- +; uchar _MTRR_setCx86(uchar reg,uchar val); +;---------------------------------------------------------------------------- +; Write a Cyrix CPU indexed register +;---------------------------------------------------------------------------- +cprocstart _MTRR_setCx86 + + ARG reg:UCHAR, val:UCHAR + + enter_c + mov al,[reg] + out 22h,al + mov al,[val] + out 23h,al + leave_c + ret + +cprocend + +;---------------------------------------------------------------------------- +; ulong _PM_ring0_isr(void); +;---------------------------------------------------------------------------- +; Ring 0 clock interrupt handler that we use to execute the MTRR support +; code. +;---------------------------------------------------------------------------- +cprocnear _PM_ring0_isr + +;-------------------------------------------------------- +; void PM_flushTLB(void); +;-------------------------------------------------------- + pushad + cmp [DWORD _PM_R0_service],R0_FLUSH_TLB + jne @@1 + wbinvd ; Flush the CPU cache + mov eax,cr3 + mov cr3,eax ; Flush the TLB + jmp @@Exit + +;-------------------------------------------------------- +; ulong _MTRR_saveCR4(void); +;-------------------------------------------------------- +@@1: cmp [DWORD _PM_R0_service],R0_SAVE_CR4 + jne @@2 + +; Save value of CR4 and clear Page Global Enable (bit 7) + + mov ebx,cr4 + mov eax,ebx + and al,7Fh + mov cr4,eax + +; Disable and flush caches + + mov eax,cr0 + or eax,40000000h + wbinvd + mov cr0,eax + wbinvd + +; Return value from CR4 + + mov [_PM_R0_reg],ebx + jmp @@Exit + +;-------------------------------------------------------- +; void _MTRR_restoreCR4(ulong cr4Val) +;-------------------------------------------------------- +@@2: cmp [DWORD _PM_R0_service],R0_RESTORE_CR4 + jne @@3 + + mov eax,cr0 + and eax,0BFFFFFFFh + mov cr0,eax + mov eax,[_PM_R0_reg] + mov cr4,eax + jmp @@Exit + +;-------------------------------------------------------- +; void _MTRR_readMSR(int reg, ulong FAR *eax, ulong FAR *edx); +;-------------------------------------------------------- +@@3: cmp [DWORD _PM_R0_service],R0_READ_MSR + jne @@4 + + mov ecx,[_PM_R0_reg] + rdmsr + mov [_PM_R0_eax],eax + mov [_PM_R0_edx],edx + jmp @@Exit + +;-------------------------------------------------------- +; void _MTRR_writeMSR(int reg, ulong eax, ulong edx); +;-------------------------------------------------------- +@@4: cmp [DWORD _PM_R0_service],R0_WRITE_MSR + jne @@Exit + + mov ecx,[_PM_R0_reg] + mov eax,[_PM_R0_eax] + mov edx,[_PM_R0_edx] + wrmsr + jmp @@Exit + +@@Exit: mov [DWORD _PM_R0_service],-1 + popad + mov eax,0 + retf + +cprocend + +endcodeseg _mtrrqnx + + END ; End of module diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/cpuinfo.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/cpuinfo.c new file mode 100644 index 0000000..a878254 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/cpuinfo.c @@ -0,0 +1,64 @@ +/**************************************************************************** +* +* Ultra Long Period Timer +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: QNX specific code for the CPU detection module. +* +****************************************************************************/ + +/*----------------------------- Implementation ----------------------------*/ + +/**************************************************************************** +REMARKS: +TODO: We should implement this for QNX! +****************************************************************************/ +#define SetMaxThreadPriority() 0 + +/**************************************************************************** +REMARKS: +TODO: We should implement this for QNX! +****************************************************************************/ +#define RestoreThreadPriority(i) + +/**************************************************************************** +REMARKS: +Initialise the counter and return the frequency of the counter. +****************************************************************************/ +static void GetCounterFrequency( + CPU_largeInteger *freq) +{ + freq->low = CLOCKS_PER_SEC * 1000; + freq->high = 0; +} + +/**************************************************************************** +REMARKS: +Read the counter and return the counter value. +****************************************************************************/ +#define GetCounter(t) \ +{ \ + (t)->low = clock() * 1000; \ + (t)->high = 0; \ +} diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/event.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/event.c new file mode 100644 index 0000000..e16f8a5 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/event.c @@ -0,0 +1,602 @@ +/**************************************************************************** +* +* SciTech Multi-platform Graphics Library +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: QNX fullscreen console implementation for the SciTech +* cross platform event library. +* +****************************************************************************/ + +#include <errno.h> +#include <unistd.h> + +/*--------------------------- Global variables ----------------------------*/ + +#ifndef __QNXNTO__ +static struct _mouse_ctrl *_PM_mouse_ctl; +static int _PM_keyboard_fd = -1; +//static int _PM_modifiers, _PM_leds; +#else +static int kbd_fd = -1, mouse_fd = -1; +#endif +static int kill_pid = 0; +static ushort keyUpMsg[256] = {0};/* Table of key up messages */ +static int rangeX,rangeY; /* Range of mouse coordinates */ + +#define TIME_TO_MSEC(__t) ((__t).tv_nsec / 1000000 + (__t).tv_sec * 1000) + +#define LED_NUM 1 +#define LED_CAP 2 +#define LED_SCR 4 + +/* Scancode mappings on QNX for special keys */ + +typedef struct { + int scan; + int map; + } keymap; + +// TODO: Fix this and set it up so we can do a binary search! + +keymap keymaps[] = { + {96, KB_padEnter}, + {74, KB_padMinus}, + {78, KB_padPlus}, + {55, KB_padTimes}, + {98, KB_padDivide}, + {71, KB_padHome}, + {72, KB_padUp}, + {73, KB_padPageUp}, + {75, KB_padLeft}, + {76, KB_padCenter}, + {77, KB_padRight}, + {79, KB_padEnd}, + {80, KB_padDown}, + {81, KB_padPageDown}, + {82, KB_padInsert}, + {83, KB_padDelete}, + {105,KB_left}, + {108,KB_down}, + {106,KB_right}, + {103,KB_up}, + {110,KB_insert}, + {102,KB_home}, + {104,KB_pageUp}, + {111,KB_delete}, + {107,KB_end}, + {109,KB_pageDown}, + {125,KB_leftWindows}, + {126,KB_rightWindows}, + {127,KB_menu}, + {100,KB_rightAlt}, + {97,KB_rightCtrl}, + }; + +/* And the keypad with num lock turned on (changes the ASCII code only) */ + +keymap keypad[] = { + {71, ASCII_7}, + {72, ASCII_8}, + {73, ASCII_9}, + {75, ASCII_4}, + {76, ASCII_5}, + {77, ASCII_6}, + {79, ASCII_1}, + {80, ASCII_2}, + {81, ASCII_3}, + {82, ASCII_0}, + {83, ASCII_period}, + }; + +#define NB_KEYMAPS (sizeof(keymaps)/sizeof(keymaps[0])) +#define NB_KEYPAD (sizeof(keypad)/sizeof(keypad[0])) + +/*---------------------------- Implementation -----------------------------*/ + +/**************************************************************************** +REMARKS: +Include generic raw scancode keyboard module. +****************************************************************************/ +#include "common/keyboard.c" + +/* These are not used under QNX */ +#define _EVT_disableInt() 1 +#define _EVT_restoreInt(flags) + +/**************************************************************************** +REMARKS: +This function is used to return the number of ticks since system +startup in milliseconds. This should be the same value that is placed into +the time stamp fields of events, and is used to implement auto mouse down +events. +****************************************************************************/ +ulong _EVT_getTicks(void) +{ + struct timespec t; + clock_gettime(CLOCK_REALTIME,&t); + return (t.tv_nsec / 1000000 + t.tv_sec * 1000); +} + +/**************************************************************************** +REMARKS: +Converts a mickey movement value to a pixel adjustment value. +****************************************************************************/ +static int MickeyToPixel( + int mickey) +{ + // TODO: We can add some code in here to handle 'acceleration' for + // the mouse cursor. For now just use the mickeys. + return mickey; +} + +#ifdef __QNXNTO__ +/**************************************************************************** +REMARKS: +Retrieves all events from the mouse/keyboard event queue and stuffs them +into the MGL event queue for further processing. +****************************************************************************/ +static void _EVT_pumpMessages(void) +{ + int rc1, rc2; + struct _keyboard_packet key; + struct _mouse_packet ms; + static long old_buttons = 0; + uint message = 0, but_stat = 0, mods = 0; + event_t evt; + + while (EVT.count < EVENTQSIZE) { + rc1 = read(kbd_fd, (void *)&key, sizeof(key)); + if (rc1 == -1) { + if (errno == EAGAIN) + rc1 = 0; + else { + perror("getEvents"); + PM_fatalError("Keyboard error"); + } + } + if (rc1 > 0) { + memset(&evt, 0, sizeof(evt)); + if (key.data.modifiers & KEYMOD_SHIFT) + mods |= EVT_LEFTSHIFT; + if (key.data.modifiers & KEYMOD_CTRL) + mods |= EVT_CTRLSTATE; + if (key.data.modifiers & KEYMOD_ALT) + mods |= EVT_ALTSTATE; + + /* Now store the keyboard event data */ + evt.when = TIME_TO_MSEC(key.time); + if (key.data.flags & KEY_SCAN_VALID) + evt.message |= (key.data.key_scan & 0x7F) << 8; + if ((key.data.flags & KEY_SYM_VALID) && + (((key.data.key_sym & 0xff00) == 0xf000 && + (key.data.key_sym & 0xff) < 0x20) || + key.data.key_sym < 0x80)) + evt.message |= (key.data.key_sym & 0xFF); + evt.modifiers = mods; + if (key.data.flags & KEY_DOWN) { + evt.what = EVT_KEYDOWN; + keyUpMsg[evt.message >> 8] = (ushort)evt.message; + } + else if (key.data.flags & KEY_REPEAT) { + evt.message |= 0x10000; + evt.what = EVT_KEYREPEAT; + } + else { + evt.what = EVT_KEYUP; + evt.message = keyUpMsg[evt.message >> 8]; + if (evt.message == 0) + continue; + keyUpMsg[evt.message >> 8] = 0; + } + + /* Now add the new event to the event queue */ + addEvent(&evt); + } + rc2 = read(mouse_fd, (void *)&ms, sizeof (ms)); + if (rc2 == -1) { + if (errno == EAGAIN) + rc2 = 0; + else { + perror("getEvents"); + PM_fatalError("Mouse error"); + } + } + if (rc2 > 0) { + memset(&evt, 0, sizeof(evt)); + ms.hdr.buttons &= + (_POINTER_BUTTON_LEFT | _POINTER_BUTTON_RIGHT); + if (ms.hdr.buttons & _POINTER_BUTTON_LEFT) + but_stat = EVT_LEFTBUT; + if ((ms.hdr.buttons & _POINTER_BUTTON_LEFT) != + (old_buttons & _POINTER_BUTTON_LEFT)) + message = EVT_LEFTBMASK; + if (ms.hdr.buttons & _POINTER_BUTTON_RIGHT) + but_stat |= EVT_RIGHTBUT; + if ((ms.hdr.buttons & _POINTER_BUTTON_RIGHT) != + (old_buttons & _POINTER_BUTTON_RIGHT)) + message |= EVT_RIGHTBMASK; + if (ms.dx || ms.dy) { + ms.dy = -ms.dy; + EVT.mx += MickeyToPixel(ms.dx); + EVT.my += MickeyToPixel(ms.dy); + if (EVT.mx < 0) EVT.mx = 0; + if (EVT.my < 0) EVT.my = 0; + if (EVT.mx > rangeX) EVT.mx = rangeX; + if (EVT.my > rangeY) EVT.my = rangeY; + evt.what = EVT_MOUSEMOVE; + evt.when = TIME_TO_MSEC(ms.hdr.time); + evt.where_x = EVT.mx; + evt.where_y = EVT.my; + evt.relative_x = ms.dx; + evt.relative_y = ms.dy; + evt.modifiers = but_stat; + addEvent(&evt); + } + evt.what = ms.hdr.buttons < old_buttons ? + EVT_MOUSEUP : EVT_MOUSEDOWN; + evt.when = TIME_TO_MSEC(ms.hdr.time); + evt.where_x = EVT.mx; + evt.where_y = EVT.my; + evt.relative_x = ms.dx; + evt.relative_y = ms.dy; + evt.modifiers = but_stat; + evt.message = message; + if (ms.hdr.buttons != old_buttons) { + addEvent(&evt); + old_buttons = ms.hdr.buttons; + } + } + if (rc1 + rc2 == 0) + break; + } +} +#else +/**************************************************************************** +REMARKS: +Retrieves all events from the mouse/keyboard event queue and stuffs them +into the MGL event queue for further processing. +****************************************************************************/ +static void _EVT_pumpMessages(void) +{ + struct mouse_event ev; + int rc; + static long old_buttons = 0; + uint message = 0, but_stat = 0; + event_t evt; + char buf[32]; + int numkeys, i; + + /* Poll keyboard events */ + while ((numkeys = read(_PM_keyboard_fd, buf, sizeof buf)) > 0) { + for (i = 0; i < numkeys; i++) { + processRawScanCode(buf[i]); + } + } + + if (_PM_mouse_ctl == NULL) + return; + + /* Gobble pending mouse events */ + while (EVT.count < EVENTQSIZE) { + rc = mouse_read(_PM_mouse_ctl, &ev, 1, 0, NULL); + if (rc == -1) { + perror("getEvents"); + PM_fatalError("Mouse error (Input terminated?)"); + } + if (rc == 0) + break; + + message = 0, but_stat = 0; + memset(&evt, 0, sizeof(evt)); + + ev.buttons &= (_MOUSE_LEFT | _MOUSE_RIGHT); + if (ev.buttons & _MOUSE_LEFT) + but_stat = EVT_LEFTBUT; + if ((ev.buttons & _MOUSE_LEFT) != (old_buttons & _MOUSE_LEFT)) + message = EVT_LEFTBMASK; + if (ev.buttons & _MOUSE_RIGHT) + but_stat |= EVT_RIGHTBUT; + if ((ev.buttons & _MOUSE_RIGHT) != (old_buttons & _MOUSE_RIGHT)) + message |= EVT_RIGHTBMASK; + if (ev.dx || ev.dy) { + ev.dy = -ev.dy; + EVT.mx += MickeyToPixel(ev.dx); + EVT.my += MickeyToPixel(ev.dy); + if (EVT.mx < 0) EVT.mx = 0; + if (EVT.my < 0) EVT.my = 0; + if (EVT.mx > rangeX) EVT.mx = rangeX; + if (EVT.my > rangeY) EVT.my = rangeY; + evt.what = EVT_MOUSEMOVE; + evt.when = ev.timestamp*100; + evt.where_x = EVT.mx; + evt.where_y = EVT.my; + evt.relative_x = ev.dx; + evt.relative_y = ev.dy; + evt.modifiers = but_stat; + addEvent(&evt); + } + evt.what = ev.buttons < old_buttons ? EVT_MOUSEUP : EVT_MOUSEDOWN; + evt.when = ev.timestamp*100; + evt.where_x = EVT.mx; + evt.where_y = EVT.my; + evt.relative_x = ev.dx; + evt.relative_y = ev.dy; + evt.modifiers = but_stat; + evt.message = message; + if (ev.buttons != old_buttons) { + addEvent(&evt); + old_buttons = ev.buttons; + } + } +} +#endif /* __QNXNTO__ */ + +/**************************************************************************** +REMARKS: +This macro/function is used to converts the scan codes reported by the +keyboard to our event libraries normalised format. We only have one scan +code for the 'A' key, and use shift modifiers to determine if it is a +Ctrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way, +but the OS gives us 'cooked' scan codes, we have to translate them back +to the raw format. +****************************************************************************/ +#define _EVT_maskKeyCode(evt) + +/**************************************************************************** +REMARKS: +Safely abort the event module upon catching a fatal error. +****************************************************************************/ +void _EVT_abort( + int signo) +{ + char buf[80]; + + EVT_exit(); + sprintf(buf,"Terminating on signal %d",signo); + PM_fatalError(buf); +} + +/**************************************************************************** +PARAMETERS: +mouseMove - Callback function to call wheneve the mouse needs to be moved + +REMARKS: +Initiliase the event handling module. Here we install our mouse handling ISR +to be called whenever any button's are pressed or released. We also build +the free list of events in the event queue. + +We use handler number 2 of the mouse libraries interrupt handlers for our +event handling routines. +****************************************************************************/ +void EVTAPI EVT_init( + _EVT_mouseMoveHandler mouseMove) +{ + int i; + struct stat st; + char *iarg[16]; +#ifdef __QNXNTO__ + char buf[128]; + FILE *p; + int argno,len; +#endif + +#ifdef __QNXNTO__ + ThreadCtl(_NTO_TCTL_IO, 0); /* So joystick code won't blow up */ +#endif + + /* Initialise the event queue */ + EVT.mouseMove = mouseMove; + initEventQueue(); + memset(keyUpMsg,0,sizeof(keyUpMsg)); + +#ifdef __QNXNTO__ + /* + * User may already have input running with the right parameters. + * Thus they could start input at boot time, using the output of + * inputtrap, passing the the -r flag to make it run as a resource + * manager. + */ + if ((mouse_fd = open("/dev/mouse0", O_RDONLY | O_NONBLOCK)) < 0) { + /* Run inputtrap to get the args for input */ + if ((p = popen("inputtrap", "r")) == NULL) + PM_fatalError("Error running 'inputtrap'"); + fgets(buf, sizeof(buf), p); + pclose(p); + + /* Build the argument list */ + len = strlen(buf); + iarg[0] = buf; + for (i = 0, argno = 0; i < len && argno < 15;) { + if (argno == 1) { + /* + * Add flags to input's arg list. + * '-r' means run as resource + * manager, providing the /dev/mouse + * and /dev/keyboard interfaces. + * '-P' supresses the /dev/photon + * mechanism. + */ + iarg[argno++] = "-Pr"; + continue; + } + while (buf[i] == ' ') + i++; + if (buf[i] == '\0' || buf[i] == '\n') + break; + iarg[argno++] = &buf[i]; + while (buf[i] != ' ' + && buf[i] != '\0' && buf[i] != '\n') + i++; + buf[i++] = '\0'; + } + iarg[argno] = NULL; + + if ((kill_pid = spawnvp(P_NOWAITO, iarg[0], iarg)) == -1) { + perror("spawning input resmgr"); + PM_fatalError("Could not start input resmgr"); + } + for (i = 0; i < 10; i++) { + if (stat("/dev/mouse0", &st) == 0) + break; + sleep(1); + } + if ((mouse_fd = open("/dev/mouse0", O_RDONLY|O_NONBLOCK)) < 0) { + perror("/dev/mouse0"); + PM_fatalError("Could not open /dev/mouse0"); + } + } + if ((kbd_fd = open("/dev/keyboard0", O_RDONLY|O_NONBLOCK)) < 0) { + perror("/dev/keyboard0"); + PM_fatalError("Could not open /dev/keyboard0"); + } +#else + /* Connect to Input/Mouse for event handling */ + if (_PM_mouse_ctl == NULL) { + _PM_mouse_ctl = mouse_open(0, "/dev/mouse", 0); + + /* "Mouse" is not running; attempt to start it */ + if (_PM_mouse_ctl == NULL) { + iarg[0] = "mousetrap"; + iarg[1] = "start"; + iarg[2] = NULL; + if ((kill_pid = spawnvp(P_NOWAITO, iarg[0], (void*)iarg)) == -1) + perror("spawn (mousetrap)"); + else { + for (i = 0; i < 10; i++) { + if (stat("/dev/mouse", &st) == 0) + break; + sleep(1); + } + _PM_mouse_ctl = mouse_open(0, "/dev/mouse", 0); + } + } + } + if (_PM_keyboard_fd == -1) + _PM_keyboard_fd = open("/dev/kbd", O_RDONLY|O_NONBLOCK); +#endif + + /* Catch program termination signals so we can clean up properly */ + signal(SIGABRT, _EVT_abort); + signal(SIGFPE, _EVT_abort); + signal(SIGINT, _EVT_abort); +} + +/**************************************************************************** +REMARKS +Changes the range of coordinates returned by the mouse functions to the +specified range of values. This is used when changing between graphics +modes set the range of mouse coordinates for the new display mode. +****************************************************************************/ +void EVTAPI EVT_setMouseRange( + int xRes, + int yRes) +{ + rangeX = xRes; + rangeY = yRes; +} + +/**************************************************************************** +REMARKS +Modifes the mouse coordinates as necessary if scaling to OS coordinates, +and sets the OS mouse cursor position. +****************************************************************************/ +#define _EVT_setMousePos(x,y) + +/**************************************************************************** +REMARKS: +Initiailises the internal event handling modules. The EVT_suspend function +can be called to suspend event handling (such as when shelling out to DOS), +and this function can be used to resume it again later. +****************************************************************************/ +void EVT_resume(void) +{ + // Do nothing for QNX +} + +/**************************************************************************** +REMARKS +Suspends all of our event handling operations. This is also used to +de-install the event handling code. +****************************************************************************/ +void EVT_suspend(void) +{ + // Do nothing for QNX +} + +/**************************************************************************** +REMARKS +Exits the event module for program terminatation. +****************************************************************************/ +void EVT_exit(void) +{ +#ifdef __QNXNTO__ + char c; + int flags; + + if (kbd_fd != -1) { + close(kbd_fd); + kbd_fd = -1; + } + if (mouse_fd != -1) { + close(mouse_fd); + mouse_fd = -1; + } +#endif + + /* Restore signal handlers */ + signal(SIGABRT, SIG_DFL); + signal(SIGFPE, SIG_DFL); + signal(SIGINT, SIG_DFL); + +#ifndef __QNXNTO__ + /* Kill the Input/Mouse driver if we have spawned it */ + if (_PM_mouse_ctl != NULL) { + struct _fd_entry fde; + uint pid = 0; + + /* Find out the pid of the mouse driver */ + if (kill_pid > 0) { + if (qnx_fd_query(0, + 0, _PM_mouse_ctl->fd, &fde) != -1) + pid = fde.pid; + } + mouse_close(_PM_mouse_ctl); + _PM_mouse_ctl = NULL; + + if (pid > 0) { + /* For some reasons the PID's are different under QNX4, + * so we use the old mechanism to kill the mouse server. + */ + kill(pid, SIGTERM); + kill_pid = 0; + } + } +#endif + if (kill_pid > 0) { + kill(kill_pid, SIGTERM); + kill_pid = 0; + } +} + diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/mtrrqnx.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/mtrrqnx.c new file mode 100644 index 0000000..de749e3 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/mtrrqnx.c @@ -0,0 +1,182 @@ +/**************************************************************************** +* +* SciTech OS Portability Manager Library +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: MTRR helper functions module. To make it easier to implement +* the MTRR support under QNX, we simply put our ring 0 helper +* functions into stubs that run them at ring 0 using whatever +* mechanism is available. +* +****************************************************************************/ + +#include "pmapi.h" +#include <stdio.h> +#include <sys/mman.h> +#include <time.h> +#ifdef __QNXNTO__ +#include <sys/neutrino.h> +#include <sys/syspage.h> +#else +#include <i86.h> +#include <sys/irqinfo.h> +#endif + +/*--------------------------- Global variables ----------------------------*/ + +#define R0_FLUSH_TLB 0 +#define R0_SAVE_CR4 1 +#define R0_RESTORE_CR4 2 +#define R0_READ_MSR 3 +#define R0_WRITE_MSR 4 + +typedef struct { + int service; + int reg; + ulong eax; + ulong edx; + } R0_data; + +extern volatile R0_data _PM_R0; + +/*----------------------------- Implementation ----------------------------*/ + +#ifdef __QNXNTO__ +const struct sigevent * _ASMAPI _PM_ring0_isr(void *arg, int id); +#else +pid_t far _ASMAPI _PM_ring0_isr(); +#endif + +/**************************************************************************** +REMARKS: +Return true if ring 0 (or if we can call the helpers functions at ring 0) +****************************************************************************/ +ibool _ASMAPI _MTRR_isRing0(void) +{ +#ifdef __QNXNTO__ + return false; // Not implemented yet! +#else + return true; +#endif +} + +/**************************************************************************** +REMARKS: +Function to execute a service at ring 0. This is done using the clock +interrupt handler since the code we attach to it will always run at ring 0. +****************************************************************************/ +static void CallRing0(void) +{ +#ifdef __QNXNTO__ + uint clock_intno = SYSPAGE_ENTRY(qtime)->intr; +#else + uint clock_intno = 0; /* clock irq */ +#endif + int intrid; + +#ifdef __QNXNTO__ + mlock((void*)&_PM_R0, sizeof(_PM_R0)); + ThreadCtl(_NTO_TCTL_IO, 0); +#endif +#ifdef __QNXNTO__ + if ((intrid = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL | clock_intno, + _PM_ring0_isr, (void*)&_PM_R0, sizeof(_PM_R0), _NTO_INTR_FLAGS_END)) == -1) { +#else + if ((intrid = qnx_hint_attach(clock_intno, _PM_ring0_isr, FP_SEG(&_PM_R0))) == -1) { +#endif + perror("Attach"); + exit(-1); + } + while (_PM_R0.service != -1) + ; +#ifdef __QNXNTO__ + InterruptDetachId(intrid); +#else + qnx_hint_detach(intrid); +#endif +} + +/**************************************************************************** +REMARKS: +Flush the translation lookaside buffer. +****************************************************************************/ +void PMAPI PM_flushTLB(void) +{ + _PM_R0.service = R0_FLUSH_TLB; + CallRing0(); +} + +/**************************************************************************** +REMARKS: +Read and return the value of the CR4 register +****************************************************************************/ +ulong _ASMAPI _MTRR_saveCR4(void) +{ + _PM_R0.service = R0_SAVE_CR4; + CallRing0(); + return _PM_R0.reg; +} + +/**************************************************************************** +REMARKS: +Restore the value of the CR4 register +****************************************************************************/ +void _ASMAPI _MTRR_restoreCR4(ulong cr4Val) +{ + _PM_R0.service = R0_RESTORE_CR4; + _PM_R0.reg = cr4Val; + CallRing0(); +} + +/**************************************************************************** +REMARKS: +Read a machine status register for the CPU. +****************************************************************************/ +void _ASMAPI _MTRR_readMSR( + int reg, + ulong *eax, + ulong *edx) +{ + _PM_R0.service = R0_READ_MSR; + _PM_R0.reg = reg; + CallRing0(); + *eax = _PM_R0.eax; + *edx = _PM_R0.edx; +} + +/**************************************************************************** +REMARKS: +Write a machine status register for the CPU. +****************************************************************************/ +void _ASMAPI _MTRR_writeMSR( + int reg, + ulong eax, + ulong edx) +{ + _PM_R0.service = R0_WRITE_MSR; + _PM_R0.reg = reg; + _PM_R0.eax = eax; + _PM_R0.edx = edx; + CallRing0(); +} diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/oshdr.h b/board/MAI/bios_emulator/scitech/src/pm/qnx/oshdr.h new file mode 100644 index 0000000..0961193 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/oshdr.h @@ -0,0 +1,103 @@ +/**************************************************************************** +* +* SciTech Multi-platform Graphics Library +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: Include file to include all OS specific header files. +* +****************************************************************************/ + +#include <sys/stat.h> +#include <fcntl.h> +#include <process.h> +#include <time.h> +#ifndef __QNXNTO__ +#include <sys/mouse.h> +#include <sys/keyboard.h> +#include <sys/fd.h> +#include <conio.h> +#else +#include <sys/dcmd_input.h> + +/* Things 'borrowed' from photon/keycodes.h */ + +/* + * Keyboard modifiers + */ +#define KEYMODBIT_SHIFT 0 +#define KEYMODBIT_CTRL 1 +#define KEYMODBIT_ALT 2 +#define KEYMODBIT_ALTGR 3 +#define KEYMODBIT_SHL3 4 +#define KEYMODBIT_MOD6 5 +#define KEYMODBIT_MOD7 6 +#define KEYMODBIT_MOD8 7 + +#define KEYMODBIT_SHIFT_LOCK 8 +#define KEYMODBIT_CTRL_LOCK 9 +#define KEYMODBIT_ALT_LOCK 10 +#define KEYMODBIT_ALTGR_LOCK 11 +#define KEYMODBIT_SHL3_LOCK 12 +#define KEYMODBIT_MOD6_LOCK 13 +#define KEYMODBIT_MOD7_LOCK 14 +#define KEYMODBIT_MOD8_LOCK 15 + +#define KEYMODBIT_CAPS_LOCK 16 +#define KEYMODBIT_NUM_LOCK 17 +#define KEYMODBIT_SCROLL_LOCK 18 + +#define KEYMOD_SHIFT (1 << KEYMODBIT_SHIFT) +#define KEYMOD_CTRL (1 << KEYMODBIT_CTRL) +#define KEYMOD_ALT (1 << KEYMODBIT_ALT) +#define KEYMOD_ALTGR (1 << KEYMODBIT_ALTGR) +#define KEYMOD_SHL3 (1 << KEYMODBIT_SHL3) +#define KEYMOD_MOD6 (1 << KEYMODBIT_MOD6) +#define KEYMOD_MOD7 (1 << KEYMODBIT_MOD7) +#define KEYMOD_MOD8 (1 << KEYMODBIT_MOD8) + +#define KEYMOD_SHIFT_LOCK (1 << KEYMODBIT_SHIFT_LOCK) +#define KEYMOD_CTRL_LOCK (1 << KEYMODBIT_CTRL_LOCK) +#define KEYMOD_ALT_LOCK (1 << KEYMODBIT_ALT_LOCK) +#define KEYMOD_ALTGR_LOCK (1 << KEYMODBIT_ALTGR_LOCK) +#define KEYMOD_SHL3_LOCK (1 << KEYMODBIT_SHL3_LOCK) +#define KEYMOD_MOD6_LOCK (1 << KEYMODBIT_MOD6_LOCK) +#define KEYMOD_MOD7_LOCK (1 << KEYMODBIT_MOD7_LOCK) +#define KEYMOD_MOD8_LOCK (1 << KEYMODBIT_MOD8_LOCK) + +#define KEYMOD_CAPS_LOCK (1 << KEYMODBIT_CAPS_LOCK) +#define KEYMOD_NUM_LOCK (1 << KEYMODBIT_NUM_LOCK) +#define KEYMOD_SCROLL_LOCK (1 << KEYMODBIT_SCROLL_LOCK) + +/* + * Keyboard flags + */ +#define KEY_DOWN 0x00000001 /* Key was pressed down */ +#define KEY_REPEAT 0x00000002 /* Key was repeated */ +#define KEY_SCAN_VALID 0x00000020 /* Scancode is valid */ +#define KEY_SYM_VALID 0x00000040 /* Key symbol is valid */ +#define KEY_CAP_VALID 0x00000080 /* Key cap is valid */ +#define KEY_DEAD 0x40000000 /* Key symbol is a DEAD key */ +#define KEY_OEM_CAP 0x80000000 /* Key cap is an OEM scan code from keyboard */ + +#endif /* __QNXNTO__ */ diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/pm.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/pm.c new file mode 100644 index 0000000..c2b41eb --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/pm.c @@ -0,0 +1,891 @@ +/**************************************************************************** +* +* SciTech OS Portability Manager Library +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: Implementation for the OS Portability Manager Library, which +* contains functions to implement OS specific services in a +* generic, cross platform API. Porting the OS Portability +* Manager library is the first step to porting any SciTech +* products to a new platform. +* +****************************************************************************/ + +#include "pmapi.h" +#include "drvlib/os/os.h" +#include "mtrr.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> +#include <termios.h> +#include <fcntl.h> +#include <malloc.h> +#include <sys/mman.h> +#include "qnx/vbios.h" +#ifndef __QNXNTO__ +#include <sys/seginfo.h> +#include <sys/console.h> +#include <conio.h> +#include <i86.h> +#else +#include <sys/neutrino.h> +#include <sys/dcmd_chr.h> +#endif + +/*--------------------------- Global variables ----------------------------*/ + +static uint VESABuf_len = 1024; /* Length of the VESABuf buffer */ +static void *VESABuf_ptr = NULL; /* Near pointer to VESABuf */ +static uint VESABuf_rseg; /* Real mode segment of VESABuf */ +static uint VESABuf_roff; /* Real mode offset of VESABuf */ +static VBIOSregs_t *VRegs = NULL; /* Pointer to VBIOS registers */ +static int raw_count = 0; +static struct _console_ctrl *cc = NULL; +static int console_count = 0; +static int rmbuf_inuse = 0; + +static void (PMAPIP fatalErrorCleanup)(void) = NULL; + +/*----------------------------- Implementation ----------------------------*/ + +void PMAPI PM_init(void) +{ + char *force; + + if (VRegs == NULL) { +#ifdef __QNXNTO__ + ThreadCtl(_NTO_TCTL_IO, 0); /* Get IO privilidge */ +#endif + force = getenv("VBIOS_METHOD"); + VRegs = VBIOSinit(force ? atoi(force) : 0); + } +#ifndef __QNXNTO__ + MTRR_init(); +#endif +} + +ibool PMAPI PM_haveBIOSAccess(void) +{ return VRegs != NULL; } + +long PMAPI PM_getOSType(void) +{ return _OS_QNX; } + +int PMAPI PM_getModeType(void) +{ return PM_386; } + +void PMAPI PM_backslash(char *s) +{ + uint pos = strlen(s); + if (s[pos-1] != '/') { + s[pos] = '/'; + s[pos+1] = '\0'; + } +} + +void PMAPI PM_setFatalErrorCleanup( + void (PMAPIP cleanup)(void)) +{ + fatalErrorCleanup = cleanup; +} + +void PMAPI PM_fatalError(const char *msg) +{ + if (fatalErrorCleanup) + fatalErrorCleanup(); + fprintf(stderr,"%s\n", msg); + exit(1); +} + +static void ExitVBEBuf(void) +{ + if (VESABuf_ptr) + PM_freeRealSeg(VESABuf_ptr); + VESABuf_ptr = 0; +} + +void * PMAPI PM_getVESABuf(uint *len,uint *rseg,uint *roff) +{ + if (!VESABuf_ptr) { + /* Allocate a global buffer for communicating with the VESA VBE */ + if ((VESABuf_ptr = PM_allocRealSeg(VESABuf_len, &VESABuf_rseg, &VESABuf_roff)) == NULL) + return NULL; + atexit(ExitVBEBuf); + } + *len = VESABuf_len; + *rseg = VESABuf_rseg; + *roff = VESABuf_roff; + return VESABuf_ptr; +} + +static int term_raw(void) +{ + struct termios termios_p; + + if (raw_count++ > 0) + return 0; + + /* Go into "raw" input mode */ + if (tcgetattr(STDIN_FILENO, &termios_p)) + return -1; + + termios_p.c_cc[VMIN] = 1; + termios_p.c_cc[VTIME] = 0; + termios_p.c_lflag &= ~( ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL); + tcsetattr(STDIN_FILENO, TCSADRAIN, &termios_p); + return 0; +} + +static void term_restore(void) +{ + struct termios termios_p; + + if (raw_count-- != 1) + return; + + tcgetattr(STDIN_FILENO, &termios_p); + termios_p.c_lflag |= (ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL); + termios_p.c_oflag |= (OPOST); + tcsetattr(STDIN_FILENO, TCSADRAIN, &termios_p); +} + +int PMAPI PM_kbhit(void) +{ + int blocking, c; + + if (term_raw() == -1) + return 0; + + /* Go into non blocking mode */ + blocking = fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK; + fcntl(STDIN_FILENO, F_SETFL, blocking); + c = getc(stdin); + + /* restore blocking mode */ + fcntl(STDIN_FILENO, F_SETFL, blocking & ~O_NONBLOCK); + term_restore(); + if (c != EOF) { + ungetc(c, stdin); + return c; + } + clearerr(stdin); + return 0; +} + +int PMAPI PM_getch(void) +{ + int c; + + if (term_raw() == -1) + return (0); + c = getc(stdin); +#if defined(__QNX__) && !defined(__QNXNTO__) + if (c == 0xA) + c = 0x0D; + else if (c == 0x7F) + c = 0x08; +#endif + term_restore(); + return c; +} + +PM_HWND PMAPI PM_openConsole( + PM_HWND hwndUser, + int device, + int xRes, + int yRes, + int bpp, + ibool fullScreen) +{ +#ifndef __QNXNTO__ + int fd; + + if (console_count++) + return 0; + if ((fd = open("/dev/con1", O_RDWR)) == -1) + return -1; + cc = console_open(fd, O_RDWR); + close(fd); + if (cc == NULL) + return -1; +#endif + return 1; +} + +int PMAPI PM_getConsoleStateSize(void) +{ + return PM_getVGAStateSize() + sizeof(int) * 3; +} + +void PMAPI PM_saveConsoleState(void *stateBuf,int console_id) +{ +#ifdef __QNXNTO__ + int fd; + int flags; + + if ((fd = open("/dev/con1", O_RDWR)) == -1) + return; + flags = _CONCTL_INVISIBLE_CHG | _CONCTL_INVISIBLE; + devctl(fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0); + close(fd); +#else + uchar *buf = &((uchar*)stateBuf)[PM_getVGAStateSize()]; + + /* Save QNX 4 console state */ + console_read(cc, -1, 0, NULL, 0, + (int *)buf+1, (int *)buf+2, NULL); + *(int *)buf = console_ctrl(cc, -1, + CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE, + CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE); + + /* Save state of VGA registers */ + PM_saveVGAState(stateBuf); +#endif +} + +void PMAPI PM_setSuspendAppCallback(int (_ASMAPIP saveState)(int flags)) +{ + /* TODO: Implement support for console switching if possible */ +} + +void PMAPI PM_restoreConsoleState(const void *stateBuf,PM_HWND hwndConsole) +{ +#ifdef __QNXNTO__ + int fd; + int flags; + + if ((fd = open("/dev/con1", O_RDWR)) == -1) + return; + flags = _CONCTL_INVISIBLE_CHG; + devctl(fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0); + close(fd); +#else + uchar *buf = &((uchar*)stateBuf)[PM_getVGAStateSize()]; + + /* Restore the state of the VGA compatible registers */ + PM_restoreVGAState(stateBuf); + + /* Restore QNX 4 console state */ + console_ctrl(cc, -1, *(int *)buf, + CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE); + console_write(cc, -1, 0, NULL, 0, + (int *)buf+1, (int *)buf+2, NULL); +#endif +} + +void PMAPI PM_closeConsole(PM_HWND hwndConsole) +{ +#ifndef __QNXNTO__ + if (--console_count == 0) { + console_close(cc); + cc = NULL; + } +#endif +} + +void PM_setOSCursorLocation(int x,int y) +{ + if (!cc) + return; +#ifndef __QNXNTO__ + console_write(cc, -1, 0, NULL, 0, &y, &x, NULL); +#endif +} + +void PM_setOSScreenWidth(int width,int height) +{ +} + +ibool PMAPI PM_setRealTimeClockHandler(PM_intHandler ih, int frequency) +{ + // TODO: Implement this for QNX + return false; +} + +void PMAPI PM_setRealTimeClockFrequency(int frequency) +{ + // TODO: Implement this for QNX +} + +void PMAPI PM_restoreRealTimeClockHandler(void) +{ + // TODO: Implement this for QNX +} + +char * PMAPI PM_getCurrentPath( + char *path, + int maxLen) +{ + return getcwd(path,maxLen); +} + +char PMAPI PM_getBootDrive(void) +{ return '/'; } + +const char * PMAPI PM_getVBEAFPath(void) +{ return PM_getNucleusConfigPath(); } + +const char * PMAPI PM_getNucleusPath(void) +{ + char *env = getenv("NUCLEUS_PATH"); +#ifdef __QNXNTO__ +#ifdef __X86__ + return env ? env : "/nto/scitech/x86/bin"; +#elif defined (__PPC__) + return env ? env : "/nto/scitech/ppcbe/bin"; +#elif defined (__MIPS__) +#ifdef __BIGENDIAN__ + return env ? env : "/nto/scitech/mipsbe/bin"; +#else + return env ? env : "/nto/scitech/mipsle/bin"; +#endif +#elif defined (__SH__) +#ifdef __BIGENDIAN__ + return env ? env : "/nto/scitech/shbe/bin"; +#else + return env ? env : "/nto/scitech/shle/bin"; +#endif +#elif defined (__ARM__) + return env ? env : "/nto/scitech/armle/bin"; +#endif +#else /* QNX 4 */ + return env ? env : "/qnx4/scitech/bin"; +#endif +} + +const char * PMAPI PM_getNucleusConfigPath(void) +{ + static char path[512]; + char *env; +#ifdef __QNXNTO__ + char temp[64]; + gethostname(temp, sizeof (temp)); + temp[sizeof (temp) - 1] = '\0'; /* Paranoid */ + sprintf(path,"/etc/config/scitech/%s/config", temp); +#else + sprintf(path,"/etc/config/scitech/%d/config", getnid()); +#endif + if ((env = getenv("NUCLEUS_PATH")) != NULL) { + strcpy(path,env); + PM_backslash(path); + strcat(path,"config"); + } + return path; +} + +const char * PMAPI PM_getUniqueID(void) +{ + static char buf[128]; +#ifdef __QNXNTO__ + gethostname(buf, sizeof (buf)); +#else + sprintf(buf,"node%d", getnid()); +#endif + return buf; +} + +const char * PMAPI PM_getMachineName(void) +{ + static char buf[128]; +#ifdef __QNXNTO__ + gethostname(buf, sizeof (buf)); +#else + sprintf(buf,"node%d", getnid()); +#endif + return buf; +} + +void * PMAPI PM_getBIOSPointer(void) +{ + return PM_mapRealPointer(0, 0x400); +} + +void * PMAPI PM_getA0000Pointer(void) +{ + static void *ptr = NULL; + void *freeptr; + unsigned offset, i, maplen; + + if (ptr != NULL) + return ptr; + + /* Some trickery is required to get the linear address 64K aligned */ + for (i = 0; i < 5; i++) { + ptr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true); + offset = 0x10000 - ((unsigned)ptr % 0x10000); + if (!offset) + break; + munmap(ptr, 0x10000); + maplen = 0x10000 + offset; + freeptr = PM_mapPhysicalAddr(0xA0000-offset, maplen-1,true); + ptr = (void *)(offset + (unsigned)freeptr); + if (0x10000 - ((unsigned)ptr % 0x10000)) + break; + munmap(freeptr, maplen); + } + if (i == 5) { + printf("Could not get a 64K aligned linear address for A0000 region\n"); + exit(1); + } + return ptr; +} + +void * PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached) +{ + uchar_t *p; + unsigned o; + unsigned prot = PROT_READ|PROT_WRITE|(isCached?0:PROT_NOCACHE); +#ifdef __PAGESIZE + int pagesize = __PAGESIZE; +#else + int pagesize = 4096; +#endif + int rounddown = base % pagesize; +#ifndef __QNXNTO__ + static int __VidFD = -1; +#endif + + if (rounddown) { + if (base < rounddown) + return NULL; + base -= rounddown; + limit += rounddown; + } + +#ifndef __QNXNTO__ + if (__VidFD < 0) { + if ((__VidFD = shm_open( "Physical", O_RDWR, 0777 )) == -1) { + perror( "Cannot open Physical memory" ); + exit(1); + } + } + o = base & 0xFFF; + limit = (limit + o + 0xFFF) & ~0xFFF; + if ((int)(p = mmap( 0, limit, prot, MAP_SHARED, + __VidFD, base )) == -1 ) { + return NULL; + } + p += o; +#else + if ((p = mmap(0, limit, prot, MAP_PHYS | MAP_SHARED, + NOFD, base)) == MAP_FAILED) { + return (void *)-1; + } +#endif + return (p + rounddown); +} + +void PMAPI PM_freePhysicalAddr(void *ptr,ulong limit) +{ + munmap(ptr,limit+1); +} + +ulong PMAPI PM_getPhysicalAddr(void *p) +{ + // TODO: This function should find the physical address of a linear + // address. + return 0xFFFFFFFFUL; +} + +ibool PMAPI PM_getPhysicalAddrRange( + void *p, + ulong length, + ulong *physAddress) +{ + // TODO: Implement this! + return false; +} + +void PMAPI PM_sleep(ulong milliseconds) +{ + // TODO: Put the process to sleep for milliseconds +} + +int PMAPI PM_getCOMPort(int port) +{ + // TODO: Re-code this to determine real values using the Plug and Play + // manager for the OS. + switch (port) { + case 0: return 0x3F8; + case 1: return 0x2F8; + } + return 0; +} + +int PMAPI PM_getLPTPort(int port) +{ + // TODO: Re-code this to determine real values using the Plug and Play + // manager for the OS. + switch (port) { + case 0: return 0x3BC; + case 1: return 0x378; + case 2: return 0x278; + } + return 0; +} + +void * PMAPI PM_mallocShared(long size) +{ + return PM_malloc(size); +} + +void PMAPI PM_freeShared(void *ptr) +{ + PM_free(ptr); +} + +void * PMAPI PM_mapToProcess(void *base,ulong limit) +{ return (void*)base; } + +void * PMAPI PM_mapRealPointer(uint r_seg,uint r_off) +{ + void *p; + + PM_init(); + + if ((p = VBIOSgetmemptr(r_seg, r_off, VRegs)) == (void *)-1) + return NULL; + return p; +} + +void * PMAPI PM_allocRealSeg(uint size,uint *r_seg,uint *r_off) +{ + if (size > 1024) { + printf("PM_allocRealSeg: can't handle %d bytes\n", size); + return 0; + } + if (rmbuf_inuse != 0) { + printf("PM_allocRealSeg: transfer area already in use\n"); + return 0; + } + PM_init(); + rmbuf_inuse = 1; + *r_seg = VBIOS_TransBufVSeg(VRegs); + *r_off = VBIOS_TransBufVOff(VRegs); + return (void*)VBIOS_TransBufPtr(VRegs); +} + +void PMAPI PM_freeRealSeg(void *mem) +{ + if (rmbuf_inuse == 0) { + printf("PM_freeRealSeg: nothing was allocated\n"); + return; + } + rmbuf_inuse = 0; +} + +void PMAPI DPMI_int86(int intno, DPMI_regs *regs) +{ + PM_init(); + if (VRegs == NULL) + return; + + VRegs->l.eax = regs->eax; + VRegs->l.ebx = regs->ebx; + VRegs->l.ecx = regs->ecx; + VRegs->l.edx = regs->edx; + VRegs->l.esi = regs->esi; + VRegs->l.edi = regs->edi; + + VBIOSint(intno, VRegs, 1024); + + regs->eax = VRegs->l.eax; + regs->ebx = VRegs->l.ebx; + regs->ecx = VRegs->l.ecx; + regs->edx = VRegs->l.edx; + regs->esi = VRegs->l.esi; + regs->edi = VRegs->l.edi; + regs->flags = VRegs->w.flags & 0x1; +} + +int PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out) +{ + PM_init(); + if (VRegs == NULL) + return 0; + + VRegs->l.eax = in->e.eax; + VRegs->l.ebx = in->e.ebx; + VRegs->l.ecx = in->e.ecx; + VRegs->l.edx = in->e.edx; + VRegs->l.esi = in->e.esi; + VRegs->l.edi = in->e.edi; + + VBIOSint(intno, VRegs, 1024); + + out->e.eax = VRegs->l.eax; + out->e.ebx = VRegs->l.ebx; + out->e.ecx = VRegs->l.ecx; + out->e.edx = VRegs->l.edx; + out->e.esi = VRegs->l.esi; + out->e.edi = VRegs->l.edi; + out->x.cflag = VRegs->w.flags & 0x1; + + return out->x.ax; +} + +int PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out, + RMSREGS *sregs) +{ + PM_init(); + if (VRegs == NULL) + return 0; + + if (intno == 0x21) { + time_t today = time(NULL); + struct tm *t; + t = localtime(&today); + out->x.cx = t->tm_year + 1900; + out->h.dh = t->tm_mon + 1; + out->h.dl = t->tm_mday; + return 0; + } + else { + VRegs->l.eax = in->e.eax; + VRegs->l.ebx = in->e.ebx; + VRegs->l.ecx = in->e.ecx; + VRegs->l.edx = in->e.edx; + VRegs->l.esi = in->e.esi; + VRegs->l.edi = in->e.edi; + VRegs->w.es = sregs->es; + VRegs->w.ds = sregs->ds; + + VBIOSint(intno, VRegs, 1024); + + out->e.eax = VRegs->l.eax; + out->e.ebx = VRegs->l.ebx; + out->e.ecx = VRegs->l.ecx; + out->e.edx = VRegs->l.edx; + out->e.esi = VRegs->l.esi; + out->e.edi = VRegs->l.edi; + out->x.cflag = VRegs->w.flags & 0x1; + sregs->es = VRegs->w.es; + sregs->ds = VRegs->w.ds; + + return out->x.ax; + } +} + +void PMAPI PM_callRealMode(uint seg,uint off, RMREGS *in, + RMSREGS *sregs) +{ + PM_init(); + if (VRegs == NULL) + return; + + VRegs->l.eax = in->e.eax; + VRegs->l.ebx = in->e.ebx; + VRegs->l.ecx = in->e.ecx; + VRegs->l.edx = in->e.edx; + VRegs->l.esi = in->e.esi; + VRegs->l.edi = in->e.edi; + VRegs->w.es = sregs->es; + VRegs->w.ds = sregs->ds; + + VBIOScall(seg, off, VRegs, 1024); + + in->e.eax = VRegs->l.eax; + in->e.ebx = VRegs->l.ebx; + in->e.ecx = VRegs->l.ecx; + in->e.edx = VRegs->l.edx; + in->e.esi = VRegs->l.esi; + in->e.edi = VRegs->l.edi; + in->x.cflag = VRegs->w.flags & 0x1; + sregs->es = VRegs->w.es; + sregs->ds = VRegs->w.ds; +} + +void PMAPI PM_availableMemory(ulong *physical,ulong *total) +{ +#ifndef __QNXNTO__ + *physical = *total = _memavl(); +#endif +} + +void * PMAPI PM_allocLockedMem( + uint size, + ulong *physAddr, + ibool contiguous, + ibool below16M) +{ + // TODO: Implement this on QNX + return NULL; +} + +void PMAPI PM_freeLockedMem( + void *p, + uint size, + ibool contiguous) +{ + // TODO: Implement this on QNX +} + +void * PMAPI PM_allocPage( + ibool locked) +{ + // TODO: Implement this on QNX + return NULL; +} + +void PMAPI PM_freePage( + void *p) +{ + // TODO: Implement this on QNX +} + +void PMAPI PM_setBankA(int bank) +{ + PM_init(); + if (VRegs == NULL) + return; + + VRegs->l.eax = 0x4F05; + VRegs->l.ebx = 0x0000; + VRegs->l.edx = bank; + VBIOSint(0x10, VRegs, 1024); +} + +void PMAPI PM_setBankAB(int bank) +{ + PM_init(); + if (VRegs == NULL) + return; + + VRegs->l.eax = 0x4F05; + VRegs->l.ebx = 0x0000; + VRegs->l.edx = bank; + VBIOSint(0x10, VRegs, 1024); + + VRegs->l.eax = 0x4F05; + VRegs->l.ebx = 0x0001; + VRegs->l.edx = bank; + VBIOSint(0x10, VRegs, 1024); +} + +void PMAPI PM_setCRTStart(int x,int y,int waitVRT) +{ + PM_init(); + if (VRegs == NULL) + return; + + VRegs->l.eax = 0x4F07; + VRegs->l.ebx = waitVRT; + VRegs->l.ecx = x; + VRegs->l.edx = y; + VBIOSint(0x10, VRegs, 1024); +} + +ibool PMAPI PM_doBIOSPOST( + ushort axVal, + ulong BIOSPhysAddr, + void *copyOfBIOS, + ulong BIOSLen) +{ + (void)axVal; + (void)BIOSPhysAddr; + (void)copyOfBIOS; + (void)BIOSLen; + return false; +} + +int PMAPI PM_lockDataPages(void *p,uint len,PM_lockHandle *lh) +{ + p = p; len = len; + return 1; +} + +int PMAPI PM_unlockDataPages(void *p,uint len,PM_lockHandle *lh) +{ + p = p; len = len; + return 1; +} + +int PMAPI PM_lockCodePages(void (*p)(),uint len,PM_lockHandle *lh) +{ + p = p; len = len; + return 1; +} + +int PMAPI PM_unlockCodePages(void (*p)(),uint len,PM_lockHandle *lh) +{ + p = p; len = len; + return 1; +} + +PM_MODULE PMAPI PM_loadLibrary( + const char *szDLLName) +{ + // TODO: Implement this to load shared libraries! + (void)szDLLName; + return NULL; +} + +void * PMAPI PM_getProcAddress( + PM_MODULE hModule, + const char *szProcName) +{ + // TODO: Implement this! + (void)hModule; + (void)szProcName; + return NULL; +} + +void PMAPI PM_freeLibrary( + PM_MODULE hModule) +{ + // TODO: Implement this! + (void)hModule; +} + +int PMAPI PM_setIOPL( + int level) +{ + // QNX handles IOPL selection at the program link level. + return level; +} + +/**************************************************************************** +PARAMETERS: +base - The starting physical base address of the region +size - The size in bytes of the region +type - Type to place into the MTRR register + +RETURNS: +Error code describing the result. + +REMARKS: +Function to enable write combining for the specified region of memory. +****************************************************************************/ +int PMAPI PM_enableWriteCombine( + ulong base, + ulong size, + uint type) +{ +#ifndef __QNXNTO__ + return MTRR_enableWriteCombine(base,size,type); +#else + return PM_MTRR_NOT_SUPPORTED; +#endif +} diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/vflat.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/vflat.c new file mode 100644 index 0000000..579ef2c --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/vflat.c @@ -0,0 +1,49 @@ +/**************************************************************************** +* +* SciTech OS Portability Manager Library +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: Any +* +* Description: Dummy module; no virtual framebuffer for this OS +* +****************************************************************************/ + +#include "pmapi.h" + +ibool PMAPI VF_available(void) +{ + return false; +} + +void * PMAPI VF_init(ulong baseAddr,int bankSize,int codeLen,void *bankFunc) +{ + baseAddr = baseAddr; + bankSize = bankSize; + codeLen = codeLen; + bankFunc = bankFunc; + return NULL; +} + +void PMAPI VF_exit(void) +{ +} diff --git a/board/MAI/bios_emulator/scitech/src/pm/qnx/ztimer.c b/board/MAI/bios_emulator/scitech/src/pm/qnx/ztimer.c new file mode 100644 index 0000000..d274097 --- /dev/null +++ b/board/MAI/bios_emulator/scitech/src/pm/qnx/ztimer.c @@ -0,0 +1,91 @@ +/**************************************************************************** +* +* Ultra Long Period Timer +* +* ======================================================================== +* +* The contents of this file are subject to the SciTech MGL Public +* License Version 1.0 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.scitechsoft.com/mgl-license.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. +* +* The Initial Developer of the Original Code is SciTech Software, Inc. +* All Rights Reserved. +* +* ======================================================================== +* +* Language: ANSI C +* Environment: QNX +* +* Description: QNX specific implementation for the Zen Timer functions. +* +****************************************************************************/ + +/*----------------------------- Implementation ----------------------------*/ + +/**************************************************************************** +REMARKS: +Initialise the Zen Timer module internals. +****************************************************************************/ +void __ZTimerInit(void) +{ +} + +/**************************************************************************** +REMARKS: +Use the gettimeofday() function to get microsecond precision (probably less +though) +****************************************************************************/ +static ulong __ULZReadTime(void) +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return (ts.tv_nsec / 1000 + ts.tv_sec * 1000000); +} + +/**************************************************************************** +REMARKS: +Start the Zen Timer counting. +****************************************************************************/ +#define __LZTimerOn(tm) tm->start.low = __ULZReadTime() + +/**************************************************************************** +REMARKS: +Compute the lap time since the timer was started. +****************************************************************************/ +#define __LZTimerLap(tm) (__ULZReadTime() - tm->start.low) + +/**************************************************************************** +REMARKS: +Call the assembler Zen Timer functions to do the timing. +****************************************************************************/ +#define __LZTimerOff(tm) tm->end.low = __ULZReadTime() + +/**************************************************************************** +REMARKS: +Call the assembler Zen Timer functions to do the timing. +****************************************************************************/ +#define __LZTimerCount(tm) (tm->end.low - tm->start.low) + +/**************************************************************************** +REMARKS: +Define the resolution of the long period timer as microseconds per timer tick. +****************************************************************************/ +#define ULZTIMER_RESOLUTION 1 + +/**************************************************************************** +REMARKS: +Compute the elapsed time from the BIOS timer tick. Note that we check to see +whether a midnight boundary has passed, and if so adjust the finish time to +account for this. We cannot detect if more that one midnight boundary has +passed, so if this happens we will be generating erronous results. +****************************************************************************/ +ulong __ULZElapsedTime(ulong start,ulong finish) +{ return finish - start; } |