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