Coding style cleanup
[platform/kernel/u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / qnx / pm.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  QNX
26 *
27 * Description:  Implementation for the OS Portability Manager Library, which
28 *               contains functions to implement OS specific services in a
29 *               generic, cross platform API. Porting the OS Portability
30 *               Manager library is the first step to porting any SciTech
31 *               products to a new platform.
32 *
33 ****************************************************************************/
34
35 #include "pmapi.h"
36 #include "drvlib/os/os.h"
37 #include "mtrr.h"
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <time.h>
42 #include <unistd.h>
43 #include <termios.h>
44 #include <fcntl.h>
45 #include <malloc.h>
46 #include <sys/mman.h>
47 #include "qnx/vbios.h"
48 #ifndef __QNXNTO__
49 #include <sys/seginfo.h>
50 #include <sys/console.h>
51 #include <conio.h>
52 #include <i86.h>
53 #else
54 #include <sys/neutrino.h>
55 #include <sys/dcmd_chr.h>
56 #endif
57
58 /*--------------------------- Global variables ----------------------------*/
59
60 static uint VESABuf_len = 1024;     /* Length of the VESABuf buffer     */
61 static void *VESABuf_ptr = NULL;    /* Near pointer to VESABuf          */
62 static uint VESABuf_rseg;           /* Real mode segment of VESABuf     */
63 static uint VESABuf_roff;           /* Real mode offset of VESABuf      */
64 static VBIOSregs_t  *VRegs = NULL;  /* Pointer to VBIOS registers       */
65 static int raw_count = 0;
66 static struct _console_ctrl *cc = NULL;
67 static int console_count = 0;
68 static int rmbuf_inuse = 0;
69
70 static void (PMAPIP fatalErrorCleanup)(void) = NULL;
71
72 /*----------------------------- Implementation ----------------------------*/
73
74 void PMAPI PM_init(void)
75 {
76     char *force;
77
78     if (VRegs == NULL) {
79 #ifdef  __QNXNTO__
80         ThreadCtl(_NTO_TCTL_IO, 0); /* Get IO privilidge */
81 #endif
82         force = getenv("VBIOS_METHOD");
83         VRegs = VBIOSinit(force ? atoi(force) : 0);
84         }
85 #ifndef  __QNXNTO__
86     MTRR_init();
87 #endif
88 }
89
90 ibool PMAPI PM_haveBIOSAccess(void)
91 { return VRegs != NULL; }
92
93 long PMAPI PM_getOSType(void)
94 { return _OS_QNX; }
95
96 int PMAPI PM_getModeType(void)
97 { return PM_386; }
98
99 void PMAPI PM_backslash(char *s)
100 {
101     uint pos = strlen(s);
102     if (s[pos-1] != '/') {
103         s[pos] = '/';
104         s[pos+1] = '\0';
105         }
106 }
107
108 void PMAPI PM_setFatalErrorCleanup(
109     void (PMAPIP cleanup)(void))
110 {
111     fatalErrorCleanup = cleanup;
112 }
113
114 void PMAPI PM_fatalError(const char *msg)
115 {
116     if (fatalErrorCleanup)
117         fatalErrorCleanup();
118     fprintf(stderr,"%s\n", msg);
119     exit(1);
120 }
121
122 static void ExitVBEBuf(void)
123 {
124     if (VESABuf_ptr)
125         PM_freeRealSeg(VESABuf_ptr);
126     VESABuf_ptr = 0;
127 }
128
129 void * PMAPI PM_getVESABuf(uint *len,uint *rseg,uint *roff)
130 {
131     if (!VESABuf_ptr) {
132         /* Allocate a global buffer for communicating with the VESA VBE */
133         if ((VESABuf_ptr = PM_allocRealSeg(VESABuf_len, &VESABuf_rseg, &VESABuf_roff)) == NULL)
134             return NULL;
135         atexit(ExitVBEBuf);
136         }
137     *len = VESABuf_len;
138     *rseg = VESABuf_rseg;
139     *roff = VESABuf_roff;
140     return VESABuf_ptr;
141 }
142
143 static int term_raw(void)
144 {
145     struct termios  termios_p;
146
147     if (raw_count++ > 0)
148         return 0;
149
150     /* Go into "raw" input mode */
151     if (tcgetattr(STDIN_FILENO, &termios_p))
152         return -1;
153
154     termios_p.c_cc[VMIN] =  1;
155     termios_p.c_cc[VTIME] =  0;
156     termios_p.c_lflag &= ~( ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
157     tcsetattr(STDIN_FILENO, TCSADRAIN, &termios_p);
158     return 0;
159 }
160
161 static void term_restore(void)
162 {
163     struct termios  termios_p;
164
165     if (raw_count-- != 1)
166         return;
167
168     tcgetattr(STDIN_FILENO, &termios_p);
169     termios_p.c_lflag |= (ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL);
170     termios_p.c_oflag |= (OPOST);
171     tcsetattr(STDIN_FILENO, TCSADRAIN, &termios_p);
172 }
173
174 int PMAPI PM_kbhit(void)
175 {
176     int blocking, c;
177
178     if (term_raw() == -1)
179         return 0;
180
181     /* Go into non blocking mode */
182     blocking = fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK;
183     fcntl(STDIN_FILENO, F_SETFL, blocking);
184     c = getc(stdin);
185
186     /* restore blocking mode */
187     fcntl(STDIN_FILENO, F_SETFL, blocking & ~O_NONBLOCK);
188     term_restore();
189     if (c != EOF) {
190         ungetc(c, stdin);
191         return c;
192         }
193     clearerr(stdin);
194     return 0;
195 }
196
197 int PMAPI PM_getch(void)
198 {
199     int c;
200
201     if (term_raw() == -1)
202         return (0);
203     c = getc(stdin);
204 #if defined(__QNX__) && !defined(__QNXNTO__)
205     if (c == 0xA)
206         c = 0x0D;
207     else if (c == 0x7F)
208         c = 0x08;
209 #endif
210     term_restore();
211     return c;
212 }
213
214 PM_HWND PMAPI PM_openConsole(
215     PM_HWND hwndUser,
216     int device,
217     int xRes,
218     int yRes,
219     int bpp,
220     ibool fullScreen)
221 {
222 #ifndef __QNXNTO__
223     int fd;
224
225     if (console_count++)
226         return 0;
227     if ((fd = open("/dev/con1", O_RDWR)) == -1)
228         return -1;
229     cc = console_open(fd, O_RDWR);
230     close(fd);
231     if (cc == NULL)
232         return -1;
233 #endif
234     return 1;
235 }
236
237 int PMAPI PM_getConsoleStateSize(void)
238 {
239     return PM_getVGAStateSize() + sizeof(int) * 3;
240 }
241
242 void PMAPI PM_saveConsoleState(void *stateBuf,int console_id)
243 {
244 #ifdef __QNXNTO__
245     int     fd;
246     int     flags;
247
248     if ((fd = open("/dev/con1", O_RDWR)) == -1)
249         return;
250     flags = _CONCTL_INVISIBLE_CHG | _CONCTL_INVISIBLE;
251     devctl(fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0);
252     close(fd);
253 #else
254     uchar   *buf = &((uchar*)stateBuf)[PM_getVGAStateSize()];
255
256     /* Save QNX 4 console state */
257     console_read(cc, -1, 0, NULL, 0,
258         (int *)buf+1, (int *)buf+2, NULL);
259     *(int *)buf = console_ctrl(cc, -1,
260         CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE,
261         CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE);
262
263     /* Save state of VGA registers */
264     PM_saveVGAState(stateBuf);
265 #endif
266 }
267
268 void PMAPI PM_setSuspendAppCallback(int (_ASMAPIP saveState)(int flags))
269 {
270     /* TODO: Implement support for console switching if possible */
271 }
272
273 void PMAPI PM_restoreConsoleState(const void *stateBuf,PM_HWND hwndConsole)
274 {
275 #ifdef __QNXNTO__
276     int     fd;
277     int     flags;
278
279     if ((fd = open("/dev/con1", O_RDWR)) == -1)
280         return;
281     flags = _CONCTL_INVISIBLE_CHG;
282     devctl(fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0);
283     close(fd);
284 #else
285     uchar   *buf = &((uchar*)stateBuf)[PM_getVGAStateSize()];
286
287     /* Restore the state of the VGA compatible registers */
288     PM_restoreVGAState(stateBuf);
289
290     /* Restore QNX 4 console state */
291     console_ctrl(cc, -1, *(int *)buf,
292         CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE);
293     console_write(cc, -1, 0, NULL, 0,
294         (int *)buf+1, (int *)buf+2, NULL);
295 #endif
296 }
297
298 void PMAPI PM_closeConsole(PM_HWND hwndConsole)
299 {
300 #ifndef __QNXNTO__
301     if (--console_count == 0) {
302         console_close(cc);
303         cc = NULL;
304         }
305 #endif
306 }
307
308 void PM_setOSCursorLocation(int x,int y)
309 {
310     if (!cc)
311         return;
312 #ifndef __QNXNTO__
313     console_write(cc, -1, 0, NULL, 0, &y, &x, NULL);
314 #endif
315 }
316
317 void PM_setOSScreenWidth(int width,int height)
318 {
319 }
320
321 ibool PMAPI PM_setRealTimeClockHandler(PM_intHandler ih, int frequency)
322 {
323     /* TODO: Implement this for QNX */
324     return false;
325 }
326
327 void PMAPI PM_setRealTimeClockFrequency(int frequency)
328 {
329     /* TODO: Implement this for QNX */
330 }
331
332 void PMAPI PM_restoreRealTimeClockHandler(void)
333 {
334     /* TODO: Implement this for QNX */
335 }
336
337 char * PMAPI PM_getCurrentPath(
338     char *path,
339     int maxLen)
340 {
341     return getcwd(path,maxLen);
342 }
343
344 char PMAPI PM_getBootDrive(void)
345 { return '/'; }
346
347 const char * PMAPI PM_getVBEAFPath(void)
348 { return PM_getNucleusConfigPath(); }
349
350 const char * PMAPI PM_getNucleusPath(void)
351 {
352     char *env = getenv("NUCLEUS_PATH");
353 #ifdef __QNXNTO__
354 #ifdef __X86__
355     return env ? env : "/nto/scitech/x86/bin";
356 #elif defined (__PPC__)
357     return env ? env : "/nto/scitech/ppcbe/bin";
358 #elif defined (__MIPS__)
359 #ifdef __BIGENDIAN__
360     return env ? env : "/nto/scitech/mipsbe/bin";
361 #else
362     return env ? env : "/nto/scitech/mipsle/bin";
363 #endif
364 #elif defined (__SH__)
365 #ifdef __BIGENDIAN__
366     return env ? env : "/nto/scitech/shbe/bin";
367 #else
368     return env ? env : "/nto/scitech/shle/bin";
369 #endif
370 #elif defined (__ARM__)
371     return env ? env : "/nto/scitech/armle/bin";
372 #endif
373 #else   /* QNX 4 */
374     return env ? env : "/qnx4/scitech/bin";
375 #endif
376 }
377
378 const char * PMAPI PM_getNucleusConfigPath(void)
379 {
380     static char path[512];
381     char        *env;
382 #ifdef __QNXNTO__
383     char temp[64];
384     gethostname(temp, sizeof (temp));
385     temp[sizeof (temp) - 1] = '\0';     /* Paranoid */
386     sprintf(path,"/etc/config/scitech/%s/config", temp);
387 #else
388     sprintf(path,"/etc/config/scitech/%d/config", getnid());
389 #endif
390     if ((env = getenv("NUCLEUS_PATH")) != NULL) {
391         strcpy(path,env);
392         PM_backslash(path);
393         strcat(path,"config");
394         }
395     return path;
396 }
397
398 const char * PMAPI PM_getUniqueID(void)
399 {
400     static char buf[128];
401 #ifdef __QNXNTO__
402     gethostname(buf, sizeof (buf));
403 #else
404     sprintf(buf,"node%d", getnid());
405 #endif
406     return buf;
407 }
408
409 const char * PMAPI PM_getMachineName(void)
410 {
411     static char buf[128];
412 #ifdef __QNXNTO__
413     gethostname(buf, sizeof (buf));
414 #else
415     sprintf(buf,"node%d", getnid());
416 #endif
417     return buf;
418 }
419
420 void * PMAPI PM_getBIOSPointer(void)
421 {
422     return PM_mapRealPointer(0, 0x400);
423 }
424
425 void * PMAPI PM_getA0000Pointer(void)
426 {
427     static void *ptr = NULL;
428     void *freeptr;
429     unsigned offset, i, maplen;
430
431     if (ptr != NULL)
432         return ptr;
433
434     /* Some trickery is required to get the linear address 64K aligned */
435     for (i = 0; i < 5; i++) {
436         ptr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true);
437         offset = 0x10000 - ((unsigned)ptr % 0x10000);
438         if (!offset)
439             break;
440         munmap(ptr, 0x10000);
441         maplen = 0x10000 + offset;
442         freeptr = PM_mapPhysicalAddr(0xA0000-offset, maplen-1,true);
443         ptr = (void *)(offset + (unsigned)freeptr);
444         if (0x10000 - ((unsigned)ptr % 0x10000))
445             break;
446         munmap(freeptr, maplen);
447         }
448     if (i == 5) {
449         printf("Could not get a 64K aligned linear address for A0000 region\n");
450         exit(1);
451         }
452     return ptr;
453 }
454
455 void * PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached)
456 {
457     uchar_t *p;
458     unsigned o;
459     unsigned prot = PROT_READ|PROT_WRITE|(isCached?0:PROT_NOCACHE);
460 #ifdef __PAGESIZE
461     int pagesize = __PAGESIZE;
462 #else
463     int pagesize = 4096;
464 #endif
465     int rounddown = base % pagesize;
466 #ifndef __QNXNTO__
467     static int __VidFD = -1;
468 #endif
469
470     if (rounddown) {
471         if (base < rounddown)
472             return NULL;
473         base -= rounddown;
474         limit += rounddown;
475         }
476
477 #ifndef __QNXNTO__
478     if (__VidFD < 0) {
479         if ((__VidFD = shm_open( "Physical", O_RDWR, 0777 )) == -1) {
480             perror( "Cannot open Physical memory" );
481             exit(1);
482             }
483         }
484     o = base & 0xFFF;
485     limit = (limit + o + 0xFFF) & ~0xFFF;
486     if ((int)(p = mmap( 0, limit, prot, MAP_SHARED,
487             __VidFD, base )) == -1 ) {
488         return NULL;
489         }
490     p += o;
491 #else
492     if ((p = mmap(0, limit, prot, MAP_PHYS | MAP_SHARED,
493             NOFD, base)) == MAP_FAILED) {
494         return (void *)-1;
495         }
496 #endif
497     return (p + rounddown);
498 }
499
500 void PMAPI PM_freePhysicalAddr(void *ptr,ulong limit)
501 {
502     munmap(ptr,limit+1);
503 }
504
505 ulong PMAPI PM_getPhysicalAddr(void *p)
506 {
507     /* TODO: This function should find the physical address of a linear */
508     /*       address. */
509     return 0xFFFFFFFFUL;
510 }
511
512 ibool PMAPI PM_getPhysicalAddrRange(
513     void *p,
514     ulong length,
515     ulong *physAddress)
516 {
517     /* TODO: Implement this! */
518     return false;
519 }
520
521 void PMAPI PM_sleep(ulong milliseconds)
522 {
523     /* TODO: Put the process to sleep for milliseconds */
524 }
525
526 int PMAPI PM_getCOMPort(int port)
527 {
528     /* TODO: Re-code this to determine real values using the Plug and Play */
529     /*       manager for the OS. */
530     switch (port) {
531         case 0: return 0x3F8;
532         case 1: return 0x2F8;
533         }
534     return 0;
535 }
536
537 int PMAPI PM_getLPTPort(int port)
538 {
539     /* TODO: Re-code this to determine real values using the Plug and Play */
540     /*       manager for the OS. */
541     switch (port) {
542         case 0: return 0x3BC;
543         case 1: return 0x378;
544         case 2: return 0x278;
545         }
546     return 0;
547 }
548
549 void * PMAPI PM_mallocShared(long size)
550 {
551     return PM_malloc(size);
552 }
553
554 void PMAPI PM_freeShared(void *ptr)
555 {
556     PM_free(ptr);
557 }
558
559 void * PMAPI PM_mapToProcess(void *base,ulong limit)
560 { return (void*)base; }
561
562 void * PMAPI PM_mapRealPointer(uint r_seg,uint r_off)
563 {
564     void *p;
565
566     PM_init();
567
568     if ((p = VBIOSgetmemptr(r_seg, r_off, VRegs)) == (void *)-1)
569         return NULL;
570     return p;
571 }
572
573 void * PMAPI PM_allocRealSeg(uint size,uint *r_seg,uint *r_off)
574 {
575     if (size > 1024) {
576         printf("PM_allocRealSeg: can't handle %d bytes\n", size);
577         return 0;
578         }
579     if (rmbuf_inuse != 0) {
580         printf("PM_allocRealSeg: transfer area already in use\n");
581         return 0;
582         }
583     PM_init();
584     rmbuf_inuse = 1;
585     *r_seg = VBIOS_TransBufVSeg(VRegs);
586     *r_off = VBIOS_TransBufVOff(VRegs);
587     return (void*)VBIOS_TransBufPtr(VRegs);
588 }
589
590 void PMAPI PM_freeRealSeg(void *mem)
591 {
592     if (rmbuf_inuse == 0) {
593         printf("PM_freeRealSeg: nothing was allocated\n");
594         return;
595         }
596     rmbuf_inuse = 0;
597 }
598
599 void PMAPI DPMI_int86(int intno, DPMI_regs *regs)
600 {
601     PM_init();
602     if (VRegs == NULL)
603         return;
604
605     VRegs->l.eax = regs->eax;
606     VRegs->l.ebx = regs->ebx;
607     VRegs->l.ecx = regs->ecx;
608     VRegs->l.edx = regs->edx;
609     VRegs->l.esi = regs->esi;
610     VRegs->l.edi = regs->edi;
611
612     VBIOSint(intno, VRegs, 1024);
613
614     regs->eax = VRegs->l.eax;
615     regs->ebx = VRegs->l.ebx;
616     regs->ecx = VRegs->l.ecx;
617     regs->edx = VRegs->l.edx;
618     regs->esi = VRegs->l.esi;
619     regs->edi = VRegs->l.edi;
620     regs->flags = VRegs->w.flags & 0x1;
621 }
622
623 int PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out)
624 {
625     PM_init();
626     if (VRegs == NULL)
627         return 0;
628
629     VRegs->l.eax = in->e.eax;
630     VRegs->l.ebx = in->e.ebx;
631     VRegs->l.ecx = in->e.ecx;
632     VRegs->l.edx = in->e.edx;
633     VRegs->l.esi = in->e.esi;
634     VRegs->l.edi = in->e.edi;
635
636     VBIOSint(intno, VRegs, 1024);
637
638     out->e.eax = VRegs->l.eax;
639     out->e.ebx = VRegs->l.ebx;
640     out->e.ecx = VRegs->l.ecx;
641     out->e.edx = VRegs->l.edx;
642     out->e.esi = VRegs->l.esi;
643     out->e.edi = VRegs->l.edi;
644     out->x.cflag = VRegs->w.flags & 0x1;
645
646     return out->x.ax;
647 }
648
649 int PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out,
650     RMSREGS *sregs)
651 {
652     PM_init();
653     if (VRegs == NULL)
654         return 0;
655
656     if (intno == 0x21) {
657         time_t today = time(NULL);
658         struct tm *t;
659         t = localtime(&today);
660         out->x.cx = t->tm_year + 1900;
661         out->h.dh = t->tm_mon + 1;
662         out->h.dl = t->tm_mday;
663         return 0;
664         }
665     else {
666         VRegs->l.eax = in->e.eax;
667         VRegs->l.ebx = in->e.ebx;
668         VRegs->l.ecx = in->e.ecx;
669         VRegs->l.edx = in->e.edx;
670         VRegs->l.esi = in->e.esi;
671         VRegs->l.edi = in->e.edi;
672         VRegs->w.es = sregs->es;
673         VRegs->w.ds = sregs->ds;
674
675         VBIOSint(intno, VRegs, 1024);
676
677         out->e.eax = VRegs->l.eax;
678         out->e.ebx = VRegs->l.ebx;
679         out->e.ecx = VRegs->l.ecx;
680         out->e.edx = VRegs->l.edx;
681         out->e.esi = VRegs->l.esi;
682         out->e.edi = VRegs->l.edi;
683         out->x.cflag = VRegs->w.flags & 0x1;
684         sregs->es = VRegs->w.es;
685         sregs->ds = VRegs->w.ds;
686
687         return out->x.ax;
688         }
689 }
690
691 void PMAPI PM_callRealMode(uint seg,uint off, RMREGS *in,
692     RMSREGS *sregs)
693 {
694     PM_init();
695     if (VRegs == NULL)
696         return;
697
698     VRegs->l.eax = in->e.eax;
699     VRegs->l.ebx = in->e.ebx;
700     VRegs->l.ecx = in->e.ecx;
701     VRegs->l.edx = in->e.edx;
702     VRegs->l.esi = in->e.esi;
703     VRegs->l.edi = in->e.edi;
704     VRegs->w.es = sregs->es;
705     VRegs->w.ds = sregs->ds;
706
707     VBIOScall(seg, off, VRegs, 1024);
708
709     in->e.eax = VRegs->l.eax;
710     in->e.ebx = VRegs->l.ebx;
711     in->e.ecx = VRegs->l.ecx;
712     in->e.edx = VRegs->l.edx;
713     in->e.esi = VRegs->l.esi;
714     in->e.edi = VRegs->l.edi;
715     in->x.cflag = VRegs->w.flags & 0x1;
716     sregs->es = VRegs->w.es;
717     sregs->ds = VRegs->w.ds;
718 }
719
720 void PMAPI PM_availableMemory(ulong *physical,ulong *total)
721 {
722 #ifndef __QNXNTO__
723     *physical = *total = _memavl();
724 #endif
725 }
726
727 void * PMAPI PM_allocLockedMem(
728     uint size,
729     ulong *physAddr,
730     ibool contiguous,
731     ibool below16M)
732 {
733     /* TODO: Implement this on QNX */
734     return NULL;
735 }
736
737 void PMAPI PM_freeLockedMem(
738     void *p,
739     uint size,
740     ibool contiguous)
741 {
742     /* TODO: Implement this on QNX */
743 }
744
745 void * PMAPI PM_allocPage(
746     ibool locked)
747 {
748     /* TODO: Implement this on QNX */
749     return NULL;
750 }
751
752 void PMAPI PM_freePage(
753     void *p)
754 {
755     /* TODO: Implement this on QNX */
756 }
757
758 void PMAPI PM_setBankA(int bank)
759 {
760     PM_init();
761     if (VRegs == NULL)
762         return;
763
764     VRegs->l.eax = 0x4F05;
765     VRegs->l.ebx = 0x0000;
766     VRegs->l.edx = bank;
767     VBIOSint(0x10, VRegs, 1024);
768 }
769
770 void PMAPI PM_setBankAB(int bank)
771 {
772     PM_init();
773     if (VRegs == NULL)
774         return;
775
776     VRegs->l.eax = 0x4F05;
777     VRegs->l.ebx = 0x0000;
778     VRegs->l.edx = bank;
779     VBIOSint(0x10, VRegs, 1024);
780
781     VRegs->l.eax = 0x4F05;
782     VRegs->l.ebx = 0x0001;
783     VRegs->l.edx = bank;
784     VBIOSint(0x10, VRegs, 1024);
785 }
786
787 void PMAPI PM_setCRTStart(int x,int y,int waitVRT)
788 {
789     PM_init();
790     if (VRegs == NULL)
791         return;
792
793     VRegs->l.eax = 0x4F07;
794     VRegs->l.ebx = waitVRT;
795     VRegs->l.ecx = x;
796     VRegs->l.edx = y;
797     VBIOSint(0x10, VRegs, 1024);
798 }
799
800 ibool PMAPI PM_doBIOSPOST(
801     ushort axVal,
802     ulong BIOSPhysAddr,
803     void *copyOfBIOS,
804     ulong BIOSLen)
805 {
806     (void)axVal;
807     (void)BIOSPhysAddr;
808     (void)copyOfBIOS;
809     (void)BIOSLen;
810     return false;
811 }
812
813 int PMAPI PM_lockDataPages(void *p,uint len,PM_lockHandle *lh)
814 {
815     p = p;  len = len;
816     return 1;
817 }
818
819 int PMAPI PM_unlockDataPages(void *p,uint len,PM_lockHandle *lh)
820 {
821     p = p;  len = len;
822     return 1;
823 }
824
825 int PMAPI PM_lockCodePages(void (*p)(),uint len,PM_lockHandle *lh)
826 {
827     p = p;  len = len;
828     return 1;
829 }
830
831 int PMAPI PM_unlockCodePages(void (*p)(),uint len,PM_lockHandle *lh)
832 {
833     p = p;  len = len;
834     return 1;
835 }
836
837 PM_MODULE PMAPI PM_loadLibrary(
838     const char *szDLLName)
839 {
840     /* TODO: Implement this to load shared libraries! */
841     (void)szDLLName;
842     return NULL;
843 }
844
845 void * PMAPI PM_getProcAddress(
846     PM_MODULE hModule,
847     const char *szProcName)
848 {
849     /* TODO: Implement this! */
850     (void)hModule;
851     (void)szProcName;
852     return NULL;
853 }
854
855 void PMAPI PM_freeLibrary(
856     PM_MODULE hModule)
857 {
858     /* TODO: Implement this! */
859     (void)hModule;
860 }
861
862 int PMAPI PM_setIOPL(
863     int level)
864 {
865     /* QNX handles IOPL selection at the program link level. */
866     return level;
867 }
868
869 /****************************************************************************
870 PARAMETERS:
871 base    - The starting physical base address of the region
872 size    - The size in bytes of the region
873 type    - Type to place into the MTRR register
874
875 RETURNS:
876 Error code describing the result.
877
878 REMARKS:
879 Function to enable write combining for the specified region of memory.
880 ****************************************************************************/
881 int PMAPI PM_enableWriteCombine(
882     ulong base,
883     ulong size,
884     uint type)
885 {
886 #ifndef  __QNXNTO__
887     return MTRR_enableWriteCombine(base,size,type);
888 #else
889     return PM_MTRR_NOT_SUPPORTED;
890 #endif
891 }