]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/MAI/bios_emulator/scitech/src/pm/rttarget/pm.c
* Code cleanup:
[people/ms/u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / rttarget / pm.c
CommitLineData
c7de829c
WD
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: RTTarget-32
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 <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#define WIN32_LEAN_AND_MEAN
41#define STRICT
42#include <windows.h>
43#include <mmsystem.h>
44#ifdef __BORLANDC__
45#pragma warn -par
46#endif
47
48/*--------------------------- Global variables ----------------------------*/
49
50static void (PMAPIP fatalErrorCleanup)(void) = NULL;
51
52/*----------------------------- Implementation ----------------------------*/
53
54void MTRR_init(void);
55
56/****************************************************************************
57REMARKS:
58Initialise the PM library.
59****************************************************************************/
60void PMAPI PM_init(void)
61{
8bde7f77 62 /* TODO: dO any special init code in here. */
c7de829c
WD
63 MTRR_init();
64}
65
66/****************************************************************************
67REMARKS:
68Return the operating system type identifier.
69****************************************************************************/
70long PMAPI PM_getOSType(void)
71{
72 return _OS_RTTARGET;
73}
74
75/****************************************************************************
76REMARKS:
77Return the runtime type identifier.
78****************************************************************************/
79int PMAPI PM_getModeType(void)
80{
81 return PM_386;
82}
83
84/****************************************************************************
85REMARKS:
86Add a file directory separator to the end of the filename.
87****************************************************************************/
88void PMAPI PM_backslash(
89 char *s)
90{
91 uint pos = strlen(s);
92 if (s[pos-1] != '\\') {
8bde7f77
WD
93 s[pos] = '\\';
94 s[pos+1] = '\0';
95 }
c7de829c
WD
96}
97
98/****************************************************************************
99REMARKS:
100Add a user defined PM_fatalError cleanup function.
101****************************************************************************/
102void PMAPI PM_setFatalErrorCleanup(
103 void (PMAPIP cleanup)(void))
104{
105 fatalErrorCleanup = cleanup;
106}
107
108/****************************************************************************
109REMARKS:
110Report a fatal error condition and halt the program.
111****************************************************************************/
112void PMAPI PM_fatalError(
113 const char *msg)
114{
115 if (fatalErrorCleanup)
8bde7f77
WD
116 fatalErrorCleanup();
117 /* TODO: Display a fatal error message and exit! */
118/* MessageBox(NULL,msg,"Fatal Error!", MB_ICONEXCLAMATION); */
c7de829c
WD
119 exit(1);
120}
121
122/****************************************************************************
123REMARKS:
124Allocate the real mode VESA transfer buffer for communicating with the BIOS.
125****************************************************************************/
126void * PMAPI PM_getVESABuf(
127 uint *len,
128 uint *rseg,
129 uint *roff)
130{
131 /* No BIOS access for the RTTarget */
132 return NULL;
133}
134
135/****************************************************************************
136REMARKS:
137Check if a key has been pressed.
138****************************************************************************/
139int PMAPI PM_kbhit(void)
140{
8bde7f77 141 /* TODO: Need to check if a key is waiting on the keyboard queue */
c7de829c
WD
142 return true;
143}
144
145/****************************************************************************
146REMARKS:
147Wait for and return the next keypress.
148****************************************************************************/
149int PMAPI PM_getch(void)
150{
8bde7f77 151 /* TODO: Need to obtain the next keypress, and block until one is hit */
c7de829c
WD
152 return 0xD;
153}
154
155/****************************************************************************
156REMARKS:
157Set the location of the OS console cursor.
158****************************************************************************/
159void PM_setOSCursorLocation(
160 int x,
161 int y)
162{
163 /* Nothing to do for RTTarget-32 */
164}
165
166/****************************************************************************
167REMARKS:
168Set the width of the OS console.
169****************************************************************************/
170void PM_setOSScreenWidth(
171 int width,
172 int height)
173{
174 /* Nothing to do for RTTarget-32 */
175}
176
177/****************************************************************************
178REMARKS:
179Set the real time clock handler (used for software stereo modes).
180****************************************************************************/
181ibool PMAPI PM_setRealTimeClockHandler(
182 PM_intHandler ih,
183 int frequency)
184{
185 /* Not supported for RTTarget-32 */
186 return false;
187}
188
189/****************************************************************************
190REMARKS:
191Set the real time clock frequency (for stereo modes).
192****************************************************************************/
193void PMAPI PM_setRealTimeClockFrequency(
194 int frequency)
195{
196 /* Not supported under RTTarget-32 */
197}
198
199/****************************************************************************
200REMARKS:
201Restore the original real time clock handler.
202****************************************************************************/
203void PMAPI PM_restoreRealTimeClockHandler(void)
204{
205 /* Not supported under RTTarget-32 */
206}
207
208/****************************************************************************
209REMARKS:
210Return the current operating system path or working directory.
211****************************************************************************/
212char * PMAPI PM_getCurrentPath(
213 char *path,
214 int maxLen)
215{
216 return getcwd(path,maxLen);
217}
218
219/****************************************************************************
220REMARKS:
221Return the drive letter for the boot drive.
222****************************************************************************/
223char PMAPI PM_getBootDrive(void)
224{
225 return 'c';
226}
227
228/****************************************************************************
229REMARKS:
230Return the path to the VBE/AF driver files.
231****************************************************************************/
232const char * PMAPI PM_getVBEAFPath(void)
233{
234 return "c:\\";
235}
236
237/****************************************************************************
238REMARKS:
239Return the path to the Nucleus driver files.
240****************************************************************************/
241const char * PMAPI PM_getNucleusPath(void)
242{
8bde7f77 243 /* TODO: Point this at the path when the Nucleus drivers will be found */
c7de829c
WD
244 return "c:\\nucleus";
245}
246
247/****************************************************************************
248REMARKS:
249Return the path to the Nucleus configuration files.
250****************************************************************************/
251const char * PMAPI PM_getNucleusConfigPath(void)
252{
253 static char path[256];
254 strcpy(path,PM_getNucleusPath());
255 PM_backslash(path);
256 strcat(path,"config");
257 return path;
258}
259
260/****************************************************************************
261REMARKS:
262Return a unique identifier for the machine if possible.
263****************************************************************************/
264const char * PMAPI PM_getUniqueID(void)
265{
266 return PM_getMachineName();
267}
268
269/****************************************************************************
270REMARKS:
271Get the name of the machine on the network.
272****************************************************************************/
273const char * PMAPI PM_getMachineName(void)
274{
275 /* Not necessary for RTTarget-32 */
276 return "Unknown";
277}
278
279/****************************************************************************
280REMARKS:
281Return a pointer to the real mode BIOS data area.
282****************************************************************************/
283void * PMAPI PM_getBIOSPointer(void)
284{
285 /* Not used for RTTarget-32 */
286 return NULL;
287}
288
289/****************************************************************************
290REMARKS:
291Return a pointer to 0xA0000 physical VGA graphics framebuffer.
292****************************************************************************/
293void * PMAPI PM_getA0000Pointer(void)
294{
295 static void *bankPtr;
296 if (!bankPtr)
8bde7f77 297 bankPtr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true);
c7de829c
WD
298 return bankPtr;
299}
300
301/****************************************************************************
302REMARKS:
303Map a physical address to a linear address in the callers process.
304****************************************************************************/
305void * PMAPI PM_mapPhysicalAddr(
306 ulong base,
307 ulong limit,
308 ibool isCached)
309{
8bde7f77 310 /* TODO: Map a physical memory address to a linear address */
c7de829c
WD
311 return NULL;
312}
313
314/****************************************************************************
315REMARKS:
316Free a physical address mapping allocated by PM_mapPhysicalAddr.
317****************************************************************************/
318void PMAPI PM_freePhysicalAddr(
319 void *ptr,
320 ulong limit)
321{
8bde7f77 322 /* TODO: Free the physical address mapping */
c7de829c
WD
323}
324
325ulong PMAPI PM_getPhysicalAddr(void *p)
326{
8bde7f77
WD
327 /* TODO: This function should find the physical address of a linear */
328 /* address. */
c7de829c
WD
329 return 0xFFFFFFFFUL;
330}
331
332void PMAPI PM_sleep(ulong milliseconds)
333{
334 Sleep(milliseconds);
335}
336
337int PMAPI PM_getCOMPort(int port)
338{
8bde7f77
WD
339 /* TODO: Re-code this to determine real values using the Plug and Play */
340 /* manager for the OS. */
c7de829c 341 switch (port) {
8bde7f77
WD
342 case 0: return 0x3F8;
343 case 1: return 0x2F8;
344 }
c7de829c
WD
345 return 0;
346}
347
348int PMAPI PM_getLPTPort(int port)
349{
8bde7f77
WD
350 /* TODO: Re-code this to determine real values using the Plug and Play */
351 /* manager for the OS. */
c7de829c 352 switch (port) {
8bde7f77
WD
353 case 0: return 0x3BC;
354 case 1: return 0x378;
355 case 2: return 0x278;
356 }
c7de829c
WD
357 return 0;
358}
359
360/****************************************************************************
361REMARKS:
362Allocate a block of (unnamed) shared memory.
363****************************************************************************/
364void * PMAPI PM_mallocShared(
365 long size)
366{
367 return PM_malloc(size);
368}
369
370/****************************************************************************
371REMARKS:
372Free a block of shared memory.
373****************************************************************************/
374void PMAPI PM_freeShared(
375 void *ptr)
376{
377 PM_free(ptr);
378}
379
380/****************************************************************************
381REMARKS:
382Map a linear memory address to the calling process address space. The
383address will have been allocated in another process using the
384PM_mapPhysicalAddr function.
385****************************************************************************/
386void * PMAPI PM_mapToProcess(
387 void *base,
388 ulong limit)
389{
390 return base;
391}
392
393/****************************************************************************
394REMARKS:
395Map a real mode pointer to a protected mode pointer.
396****************************************************************************/
397void * PMAPI PM_mapRealPointer(
398 uint r_seg,
399 uint r_off)
400{
401 /* Not used for RTTarget-32 */
402 return NULL;
403}
404
405/****************************************************************************
406REMARKS:
407Allocate a block of real mode memory
408****************************************************************************/
409void * PMAPI PM_allocRealSeg(
410 uint size,
411 uint *r_seg,
412 uint *r_off)
413{
414 /* Not used for RTTarget-32 */
415 return NULL;
416}
417
418/****************************************************************************
419REMARKS:
420Free a block of real mode memory.
421****************************************************************************/
422void PMAPI PM_freeRealSeg(
423 void *mem)
424{
425 /* Not used for RTTarget-32 */
426}
427
428/****************************************************************************
429REMARKS:
430Issue a real mode interrupt (parameters in DPMI compatible structure)
431****************************************************************************/
432void PMAPI DPMI_int86(
433 int intno,
434 DPMI_regs *regs)
435{
436 /* Not used for RTTarget-32 */
437}
438
439/****************************************************************************
440REMARKS:
441Issue a real mode interrupt.
442****************************************************************************/
443int PMAPI PM_int86(
444 int intno,
445 RMREGS *in,
446 RMREGS *out)
447{
448 /* Not used for RTTarget-32 */
449 return 0;
450}
451
452/****************************************************************************
453REMARKS:
454Issue a real mode interrupt.
455****************************************************************************/
456int PMAPI PM_int86x(
457 int intno,
458 RMREGS *in,
459 RMREGS *out,
460 RMSREGS *sregs)
461{
462 /* Not used for RTTarget-32 */
463 return 0;
464}
465
466/****************************************************************************
467REMARKS:
468Call a real mode far function.
469****************************************************************************/
470void PMAPI PM_callRealMode(
471 uint seg,
472 uint off,
473 RMREGS *in,
474 RMSREGS *sregs)
475{
476 /* Not used for RTTarget-32 */
477}
478
479/****************************************************************************
480REMARKS:
481Return the amount of available memory.
482****************************************************************************/
483void PMAPI PM_availableMemory(
484 ulong *physical,
485 ulong *total)
486{
8bde7f77
WD
487 /* TODO: Figure out how to determine the available memory. Not entirely */
488 /* critical so returning 0 is OK. */
c7de829c
WD
489 *physical = *total = 0;
490}
491
492/****************************************************************************
493REMARKS:
494Allocate a block of locked, physical memory for DMA operations.
495****************************************************************************/
496void * PMAPI PM_allocLockedMem(
497 uint size,
498 ulong *physAddr,
499 ibool contiguous,
500 ibool below16M)
501{
8bde7f77 502 /* TODO: Allocate a block of locked, phsyically contigous memory for DMA */
c7de829c
WD
503 return 0;
504}
505
506/****************************************************************************
507REMARKS:
508Free a block of locked physical memory.
509****************************************************************************/
510void PMAPI PM_freeLockedMem(
511 void *p,
512 uint size,
8bde7f77 513
c7de829c
WD
514 ibool contiguous)
515{
8bde7f77 516 /* TODO: Free a locked memory buffer */
c7de829c
WD
517}
518
519/****************************************************************************
520REMARKS:
521Call the VBE/Core software interrupt to change display banks.
522****************************************************************************/
523void PMAPI PM_setBankA(
524 int bank)
525{
526 /* Not used for RTTarget-32 */
527}
528
529/****************************************************************************
530REMARKS:
531Call the VBE/Core software interrupt to change display banks.
532****************************************************************************/
533void PMAPI PM_setBankAB(
534 int bank)
535{
536 /* Not used for RTTarget-32 */
537}
538
539/****************************************************************************
540REMARKS:
541Call the VBE/Core software interrupt to change display start address.
542****************************************************************************/
543void PMAPI PM_setCRTStart(
544 int x,
545 int y,
546 int waitVRT)
547{
548 /* Not used for RTTarget-32 */
549}
550
551/****************************************************************************
552REMARKS:
553Execute the POST on the secondary BIOS for a controller.
554****************************************************************************/
555ibool PMAPI PM_doBIOSPOST(
556 ushort axVal,
557 ulong BIOSPhysAddr,
558 void *mappedBIOS)
559{
560 /* Not used for RTTarget-32 */
561 return false;
562}
563
564PM_MODULE PMAPI PM_loadLibrary(
565 const char *szDLLName)
566{
8bde7f77 567 /* TODO: Implement this to load shared libraries! */
c7de829c
WD
568 (void)szDLLName;
569 return NULL;
570}
571
572void * PMAPI PM_getProcAddress(
573 PM_MODULE hModule,
574 const char *szProcName)
575{
8bde7f77 576 /* TODO: Implement this! */
c7de829c
WD
577 (void)hModule;
578 (void)szProcName;
579 return NULL;
580}
581
582void PMAPI PM_freeLibrary(
583 PM_MODULE hModule)
584{
8bde7f77 585 /* TODO: Implement this! */
c7de829c
WD
586 (void)hModule;
587}
588
589/****************************************************************************
590REMARKS:
591Function to find the first file matching a search criteria in a directory.
592****************************************************************************/
593ulong PMAPI PM_findFirstFile(
594 const char *filename,
595 PM_findData *findData)
596{
8bde7f77
WD
597 /* TODO: This function should start a directory enumeration search */
598 /* given the filename (with wildcards). The data should be */
599 /* converted and returned in the findData standard form. */
c7de829c
WD
600 (void)filename;
601 (void)findData;
602 return PM_FILE_INVALID;
603}
604
605/****************************************************************************
606REMARKS:
607Function to find the next file matching a search criteria in a directory.
608****************************************************************************/
609ibool PMAPI PM_findNextFile(
610 ulong handle,
611 PM_findData *findData)
612{
8bde7f77
WD
613 /* TODO: This function should find the next file in directory enumeration */
614 /* search given the search criteria defined in the call to */
615 /* PM_findFirstFile. The data should be converted and returned */
616 /* in the findData standard form. */
c7de829c
WD
617 (void)handle;
618 (void)findData;
619 return false;
620}
621
622/****************************************************************************
623REMARKS:
624Function to close the find process
625****************************************************************************/
626void PMAPI PM_findClose(
627 ulong handle)
628{
8bde7f77
WD
629 /* TODO: This function should close the find process. This may do */
630 /* nothing for some OS'es. */
c7de829c
WD
631 (void)handle;
632}
633
634/****************************************************************************
635REMARKS:
636Function to determine if a drive is a valid drive or not. Under Unix this
637function will return false for anything except a value of 3 (considered
638the root drive, and equivalent to C: for non-Unix systems). The drive
639numbering is:
640
641 1 - Drive A:
642 2 - Drive B:
643 3 - Drive C:
644 etc
645
646****************************************************************************/
647ibool PMAPI PM_driveValid(
648 char drive)
649{
650 if (drive == 3)
8bde7f77 651 return true;
c7de829c
WD
652 return false;
653}
654
655/****************************************************************************
656REMARKS:
657Function to get the current working directory for the specififed drive.
658Under Unix this will always return the current working directory regardless
659of what the value of 'drive' is.
660****************************************************************************/
661void PMAPI PM_getdcwd(
662 int drive,
663 char *dir,
664 int len)
665{
666 (void)drive;
667 getcwd(dir,len);
668}
669
670/****************************************************************************
671REMARKS:
672Function to change the file attributes for a specific file.
673****************************************************************************/
674void PMAPI PM_setFileAttr(
675 const char *filename,
676 uint attrib)
677{
8bde7f77 678 /* TODO: Set the file attributes for a file */
c7de829c
WD
679 (void)filename;
680 (void)attrib;
681}
682
683/****************************************************************************
684REMARKS:
685Function to create a directory.
686****************************************************************************/
687ibool PMAPI PM_mkdir(
688 const char *filename)
689{
690 return mkdir(filename) == 0;
691}
692
693/****************************************************************************
694REMARKS:
695Function to remove a directory.
696****************************************************************************/
697ibool PMAPI PM_rmdir(
698 const char *filename)
699{
700 return rmdir(filename) == 0;
701}