⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pm.c

📁 BIOS emulator and interface to Realmode X86 Emulator Library Can emulate a PCI Graphic Controller V
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************					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 <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <termios.h>#include <fcntl.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 MTRR_init(void);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 0;}int PMAPI PM_getConsoleStateSize(void){	return 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	console_read(cc, -1, 0, NULL, 0,	    (int *)stateBuf+1, (int *)stateBuf+2, NULL);	*(int *)stateBuf = console_ctrl(cc, -1,	    CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE,	    CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE);#endif}void PMAPI PM_changeResolution(PM_HWND hwndConsole,int xRes,int yRes,int bpp){	/* Not used for QNX fullscreen */}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	console_ctrl(cc, -1, *(int *)stateBuf,		CONSOLE_NORESIZE | CONSOLE_NOSWITCH | CONSOLE_INVISIBLE);	console_write(cc, -1, 0, NULL, 0,		(int *)stateBuf+1, (int *)stateBuf+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}const char * PMAPI PM_getCurrentPath(void){	static char cwd[512];	return getcwd(cwd,sizeof(cwd));}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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -