]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/src/pm/beos/pm.c
* Patch by Thomas Frieden, 13 Nov 2002:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / src / pm / beos / 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:  BeOS
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
41 // TODO: Include any BeOS specific headers here!
42
43 /*--------------------------- Global variables ----------------------------*/
44
45 static void (PMAPIP fatalErrorCleanup)(void) = NULL;
46
47 /*----------------------------- Implementation ----------------------------*/
48
49 void PMAPI PM_init(void)
50 {
51     // TODO: Do any initialisation in here. This includes getting IOPL
52     //       access for the process calling PM_init. This will get called
53     //       more than once.
54
55     // TODO: If you support the supplied MTRR register stuff (you need to
56     //       be at ring 0 for this!), you should initialise it in here.
57
58 /* MTRR_init(); */
59 }
60
61 long PMAPI PM_getOSType(void)
62 { return _OS_BEOS; }
63
64 int PMAPI PM_getModeType(void)
65 { return PM_386; }
66
67 void PMAPI PM_backslash(char *s)
68 {
69     uint pos = strlen(s);
70     if (s[pos-1] != '/') {
71         s[pos] = '/';
72         s[pos+1] = '\0';
73         }
74 }
75
76 void PMAPI PM_setFatalErrorCleanup(
77     void (PMAPIP cleanup)(void))
78 {
79     fatalErrorCleanup = cleanup;
80 }
81
82 void PMAPI PM_fatalError(const char *msg)
83 {
84     // TODO: If you are running in a GUI environment without a console,
85     //       this needs to be changed to bring up a fatal error message
86     //       box and terminate the program.
87     if (fatalErrorCleanup)
88         fatalErrorCleanup();
89     fprintf(stderr,"%s\n", msg);
90     exit(1);
91 }
92
93 void * PMAPI PM_getVESABuf(uint *len,uint *rseg,uint *roff)
94 {
95     // No BIOS access for the BeOS
96     return NULL;
97 }
98
99 int PMAPI PM_kbhit(void)
100 {
101     // TODO: This function checks if a key is available to be read. This
102     //       should be implemented, but is mostly used by the test programs
103     //       these days.
104     return true;
105 }
106
107 int PMAPI PM_getch(void)
108 {
109     // TODO: This returns the ASCII code of the key pressed. This
110     //       should be implemented, but is mostly used by the test programs
111     //       these days.
112     return 0xD;
113 }
114
115 int PMAPI PM_openConsole(void)
116 {
117     // TODO: Opens up a fullscreen console for graphics output. If your
118     //       console does not have graphics/text modes, this can be left
119     //       empty. The main purpose of this is to disable console switching
120     //       when in graphics modes if you can switch away from fullscreen
121     //       consoles (if you want to allow switching, this can be done
122     //       elsewhere with a full save/restore state of the graphics mode).
123     return 0;
124 }
125
126 int PMAPI PM_getConsoleStateSize(void)
127 {
128     // TODO: Returns the size of the console state buffer used to save the
129     //       state of the console before going into graphics mode. This is
130     //       used to restore the console back to normal when we are done.
131     return 1;
132 }
133
134 void PMAPI PM_saveConsoleState(void *stateBuf,int console_id)
135 {
136     // TODO: Saves the state of the console into the state buffer. This is
137     //       used to restore the console back to normal when we are done.
138     //       We will always restore 80x25 text mode after being in graphics
139     //       mode, so if restoring text mode is all you need to do this can
140     //       be left empty.
141 }
142
143 void PMAPI PM_restoreConsoleState(const void *stateBuf,int console_id)
144 {
145     // TODO: Restore the state of the console from the state buffer. This is
146     //       used to restore the console back to normal when we are done.
147     //       We will always restore 80x25 text mode after being in graphics
148     //       mode, so if restoring text mode is all you need to do this can
149     //       be left empty.
150 }
151
152 void PMAPI PM_closeConsole(int console_id)
153 {
154     // TODO: Close the console when we are done, going back to text mode.
155 }
156
157 void PM_setOSCursorLocation(int x,int y)
158 {
159     // TODO: Set the OS console cursor location to the new value. This is
160     //       generally used for new OS ports (used mostly for DOS).
161 }
162
163 void PM_setOSScreenWidth(int width,int height)
164 {
165     // TODO: Set the OS console screen width. This is generally unused for
166     //       new OS ports.
167 }
168
169 ibool PMAPI PM_setRealTimeClockHandler(PM_intHandler ih, int frequency)
170 {
171     // TODO: Install a real time clock interrupt handler. Normally this
172     //       will not be supported from most OS'es in user land, so an
173     //       alternative mechanism is needed to enable software stereo.
174     //       Hence leave this unimplemented unless you have a high priority
175     //       mechanism to call the 32-bit callback when the real time clock
176     //       interrupt fires.
177     return false;
178 }
179
180 void PMAPI PM_setRealTimeClockFrequency(int frequency)
181 {
182     // TODO: Set the real time clock interrupt frequency. Used for stereo
183     //       LC shutter glasses when doing software stereo. Usually sets
184     //       the frequency to around 2048 Hz.
185 }
186
187 void PMAPI PM_restoreRealTimeClockHandler(void)
188 {
189     // TODO: Restores the real time clock handler.
190 }
191
192 char * PMAPI PM_getCurrentPath(
193     char *path,
194     int maxLen)
195 {
196     return getcwd(path,maxLen);
197 }
198
199 char PMAPI PM_getBootDrive(void)
200 { return '/'; }
201
202 const char * PMAPI PM_getVBEAFPath(void)
203 { return PM_getNucleusConfigPath(); }
204
205 const char * PMAPI PM_getNucleusPath(void)
206 {
207     char *env = getenv("NUCLEUS_PATH");
208     return env ? env : "/usr/lib/nucleus";
209 }
210
211 const char * PMAPI PM_getNucleusConfigPath(void)
212 {
213     static char path[256];
214     strcpy(path,PM_getNucleusPath());
215     PM_backslash(path);
216     strcat(path,"config");
217     return path;
218 }
219
220 const char * PMAPI PM_getUniqueID(void)
221 {
222     // TODO: Return a unique ID for the machine. If a unique ID is not
223     //       available, return the machine name.
224     static char buf[128];
225     gethostname(buf, 128);
226     return buf;
227 }
228
229 const char * PMAPI PM_getMachineName(void)
230 {
231     // TODO: Return the network machine name for the machine.
232     static char buf[128];
233     gethostname(buf, 128);
234     return buf;
235 }
236
237 void * PMAPI PM_getBIOSPointer(void)
238 {
239     // No BIOS access on the BeOS
240     return NULL;
241 }
242
243 void * PMAPI PM_getA0000Pointer(void)
244 {
245     static void *bankPtr;
246     if (!bankPtr)
247         bankPtr = PM_mapPhysicalAddr(0xA0000,0xFFFF,true);
248     return bankPtr;
249 }
250
251 void * PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached)
252 {
253     // TODO: This function maps a physical memory address to a linear
254     //       address in the address space of the calling process.
255
256     // NOTE: This function *must* be able to handle any phsyical base
257     //       address, and hence you will have to handle rounding of
258     //       the physical base address to a page boundary (ie: 4Kb on
259     //       x86 CPU's) to be able to properly map in the memory
260     //       region.
261
262     // NOTE: If possible the isCached bit should be used to ensure that
263     //       the PCD (Page Cache Disable) and PWT (Page Write Through)
264     //       bits are set to disable caching for a memory mapping used
265     //       for MMIO register access. We also disable caching using
266     //       the MTRR registers for Pentium Pro and later chipsets so if
267     //       MTRR support is enabled for your OS then you can safely ignore
268     //       the isCached flag and always enable caching in the page
269     //       tables.
270     return NULL;
271 }
272
273 void PMAPI PM_freePhysicalAddr(void *ptr,ulong limit)
274 {
275     // TODO: This function will free a physical memory mapping previously
276     //       allocated with PM_mapPhysicalAddr() if at all possible. If
277     //       you can't free physical memory mappings, simply do nothing.
278 }
279
280 ulong PMAPI PM_getPhysicalAddr(void *p)
281 {
282     // TODO: This function should find the physical address of a linear
283     //       address.
284     return 0xFFFFFFFFUL;
285 }
286
287 void PMAPI PM_sleep(ulong milliseconds)
288 {
289     // TODO: Put the process to sleep for milliseconds
290 }
291
292 int PMAPI PM_getCOMPort(int port)
293 {
294     // TODO: Re-code this to determine real values using the Plug and Play
295     //       manager for the OS.
296     switch (port) {
297         case 0: return 0x3F8;
298         case 1: return 0x2F8;
299         }
300     return 0;
301 }
302
303 int PMAPI PM_getLPTPort(int port)
304 {
305     // TODO: Re-code this to determine real values using the Plug and Play
306     //       manager for the OS.
307     switch (port) {
308         case 0: return 0x3BC;
309         case 1: return 0x378;
310         case 2: return 0x278;
311         }
312     return 0;
313 }
314
315 void * PMAPI PM_mallocShared(long size)
316 {
317     // TODO: This is used to allocate memory that is shared between process
318     //       that all access the common Nucleus drivers via a common display
319     //       driver DLL. If your OS does not support shared memory (or if
320     //       the display driver does not need to allocate shared memory
321     //       for each process address space), this should just call PM_malloc.
322     return PM_malloc(size);
323 }
324
325 void PMAPI PM_freeShared(void *ptr)
326 {
327     // TODO: Free the shared memory block. This will be called in the context
328     //       of the original calling process that allocated the shared
329     //       memory with PM_mallocShared. Simply call free if you do not
330     //       need this.
331     PM_free(ptr);
332 }
333
334 void * PMAPI PM_mapToProcess(void *base,ulong limit)
335 {
336     // TODO: This function is used to map a physical memory mapping
337     //       previously allocated with PM_mapPhysicalAddr into the
338     //       address space of the calling process. If the memory mapping
339     //       allocated by PM_mapPhysicalAddr is global to all processes,
340     //       simply return the pointer.
341     return base;
342 }
343
344 void * PMAPI PM_mapRealPointer(uint r_seg,uint r_off)
345 {
346     // No BIOS access on the BeOS
347     return NULL;
348 }
349
350 void * PMAPI PM_allocRealSeg(uint size,uint *r_seg,uint *r_off)
351 {
352     // No BIOS access on the BeOS
353     return NULL;
354 }
355
356 void PMAPI PM_freeRealSeg(void *mem)
357 {
358     // No BIOS access on the BeOS
359 }
360
361 void PMAPI DPMI_int86(int intno, DPMI_regs *regs)
362 {
363     // No BIOS access on the BeOS
364 }
365
366 int PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out)
367 {
368     // No BIOS access on the BeOS
369     return 0;
370 }
371
372 int PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out,
373     RMSREGS *sregs)
374 {
375     // No BIOS access on the BeOS
376     return 0;
377 }
378
379 void PMAPI PM_callRealMode(uint seg,uint off, RMREGS *in,
380     RMSREGS *sregs)
381 {
382     // No BIOS access on the BeOS
383 }
384
385 void PMAPI PM_availableMemory(ulong *physical,ulong *total)
386 {
387     // TODO: Report the amount of available memory, both the amount of
388     //       physical memory left and the amount of virtual memory left.
389     //       If the OS does not provide these services, report 0's.
390     *physical = *total = 0;
391 }
392
393 void * PMAPI PM_allocLockedMem(uint size,ulong *physAddr,ibool contiguous,ibool below16Meg)
394 {
395     // TODO: Allocate a block of locked, physical memory of the specified
396     //       size. This is used for bus master operations. If this is not
397     //       supported by the OS, return NULL and bus mastering will not
398     //       be used.
399     return NULL;
400 }
401
402 void PMAPI PM_freeLockedMem(void *p,uint size,ibool contiguous)
403 {
404     // TODO: Free a memory block allocated with PM_allocLockedMem.
405 }
406
407 void PMAPI PM_setBankA(int bank)
408 {
409     // No BIOS access on the BeOS
410 }
411
412 void PMAPI PM_setBankAB(int bank)
413 {
414     // No BIOS access on the BeOS
415 }
416
417 void PMAPI PM_setCRTStart(int x,int y,int waitVRT)
418 {
419     // No BIOS access on the BeOS
420 }
421
422 ibool PMAPI PM_enableWriteCombine(ulong base,ulong length,uint type)
423 {
424     // TODO: This function should enable Pentium Pro and Pentium II MTRR
425     //       write combining for the passed in physical memory base address
426     //       and length. Normally this is done via calls to an OS specific
427     //       device driver as this can only be done at ring 0.
428     //
429     // NOTE: This is a *very* important function to implement! If you do
430     //       not implement, graphics performance on the latest Intel chips
431     //       will be severly impaired. For sample code that can be used
432     //       directly in a ring 0 device driver, see the MSDOS implementation
433     //       which includes assembler code to do this directly (if the
434     //       program is running at ring 0).
435     return false;
436 }
437
438 ibool PMAPI PM_doBIOSPOST(ushort axVal,ulong BIOSPhysAddr,void *mappedBIOS)
439 {
440     // TODO: This function is used to run the BIOS POST code on a secondary
441     //       controller to initialise it for use. This is not necessary
442     //       for multi-controller operation, but it will make it a lot
443     //       more convenicent for end users (otherwise they have to boot
444     //       the system once with the secondary controller as primary, and
445     //       then boot with both controllers installed).
446     //
447     //       Even if you don't support full BIOS access, it would be
448     //       adviseable to be able to POST the secondary controllers in the
449     //       system using this function as a minimum requirement. Some
450     //       graphics hardware has registers that contain values that only
451     //       the BIOS knows about, which makes bring up a card from cold
452     //       reset difficult if the BIOS has not POST'ed it.
453     return false;
454 }
455
456 /****************************************************************************
457 REMARKS:
458 Function to find the first file matching a search criteria in a directory.
459 ****************************************************************************/
460 ulong PMAPI PM_findFirstFile(
461     const char *filename,
462     PM_findData *findData)
463 {
464     (void)filename;
465     (void)findData;
466     return PM_FILE_INVALID;
467 }
468
469 /****************************************************************************
470 REMARKS:
471 Function to find the next file matching a search criteria in a directory.
472 ****************************************************************************/
473 ibool PMAPI PM_findNextFile(
474     ulong handle,
475     PM_findData *findData)
476 {
477     (void)handle;
478     (void)findData;
479     return false;
480 }
481
482 /****************************************************************************
483 REMARKS:
484 Function to close the find process
485 ****************************************************************************/
486 void PMAPI PM_findClose(
487     ulong handle)
488 {
489     (void)handle;
490 }
491
492 /****************************************************************************
493 REMARKS:
494 Function to determine if a drive is a valid drive or not. Under Unix this
495 function will return false for anything except a value of 3 (considered
496 the root drive, and equivalent to C: for non-Unix systems). The drive
497 numbering is:
498
499     1   - Drive A:
500     2   - Drive B:
501     3   - Drive C:
502     etc
503
504 ****************************************************************************/
505 ibool PMAPI PM_driveValid(
506     char drive)
507 {
508     if (drive == 3)
509         return true;
510     return false;
511 }
512
513 /****************************************************************************
514 REMARKS:
515 Function to get the current working directory for the specififed drive.
516 Under Unix this will always return the current working directory regardless
517 of what the value of 'drive' is.
518 ****************************************************************************/
519 void PMAPI PM_getdcwd(
520     int drive,
521     char *dir,
522     int len)
523 {
524     (void)drive;
525     getcwd(dir,len);
526 }
527
528 /****************************************************************************
529 REMARKS:
530 Function to change the file attributes for a specific file.
531 ****************************************************************************/
532 void PMAPI PM_setFileAttr(
533     const char *filename,
534     uint attrib)
535 {
536     // TODO: Set the file attributes for a file
537     (void)filename;
538     (void)attrib;
539 }