📄 kernelos.c
字号:
/******************************************************************** Copyright (c) 2002 Sigma Designs Inc. All rights reserved. ********************************************************************//* @file kernelos.c See licensing details in LICENSING file */// pch from HWL#include "pch.h"#include "common.h"// This are used to avoid alignment problems - should they be optimized ?DWORD OSGetDword(void *pVoid){ BYTE *pByte = (BYTE *)pVoid; return ( ( ((DWORD)*(pByte+0)) << 0 ) | ( ((DWORD)*(pByte+1)) << 8 ) | ( ((DWORD)*(pByte+2)) << 16 ) | ( ((DWORD)*(pByte+3)) << 24 ) );}WORD OSGetWord(void *pVoid){ BYTE *pByte = (BYTE *)pVoid; return ( ( ((WORD)*(pByte+0)) << 0 ) | ( ((WORD)*(pByte+1)) << 8 ) );}void OSPutDword(DWORD data, void *pVoid){ BYTE *pByte = (BYTE *)pVoid; *(pByte+0) = (data) & 0xff; *(pByte+1) = ((data) >> 8) & 0xff; *(pByte+2) = ((data) >> 16) & 0xff; *(pByte+3) = ((data) >> 24) & 0xff;}DWORD OSReadPciDword(void *pTarget) { return (*(DWORD *)(pTarget)); }void OSWritePciDword(void *pTarget, DWORD data) { (*(DWORD *)(pTarget)) = data; }void* OSmalloc (unsigned long dwBytes) { return RMMalloc(dwBytes); }void OSfree (void* pBlock) { RMFree(pBlock); }void OSmemcpy(void* dest, const void* src, size_t count) { memcpy(dest,src,count); }int OSmemcmp(void* dest, const void* src, size_t count) { return memcmp(dest,src,count); }void OSmemset (void *dest, BYTE c, size_t count) { memset(dest,c,count); }void OSstrncpy(TCHAR *Dest,TCHAR *Src,unsigned long CopySize) { strncpy(Dest,Src,CopySize); }void OSstrcpy( TCHAR* strDestination, const TCHAR* strSource ) { strcpy(strDestination,strSource); }void OSstrcat(TCHAR *Dest,TCHAR *Src) { strcat(Dest,Src); }DWORD OSstrlen(TCHAR *s) { return strlen(s); }// ``i'' stands for: case insensitive.int OSstrcmpi( const CHAR *string1, const CHAR *string2 ) { int l1=strlen(string1),l2=strlen(string2),smallest=(l1<l2)?l1:l2; // also compare final 0! smallest++; // kernel does not have stricmp sorry return strnicmp(string1,string2,smallest);}void OSTimeDelay (unsigned long dwTime) { /* soooo bad, but StreamMachine reset needs 0.5 seconds!!! (and we reset it from tasklet, so forget schedule_timeout() solution) */// if (dwTime>10000) hwlprintk("OSTimeDelay: stalling kernel for %ld microseconds, sorry\n",dwTime); mdelay(dwTime/1000); udelay(dwTime%1000); // udelay inaccurate with arg>1000 (see Rubini)} // unit is microseconds.DWORD OSTimeGetTime(void) { /* This is not very accurate (jiffies changes only every 10ms on i386 after all). It would be better to use get_cycles() but we need to know the cpu clock then... something like get_cycles()/cpu_khz (untested) */ return (unsigned long long)jiffies*1000ULL/(unsigned long long)HZ; } // unit is milliseconds.// XXX should we optimize for ARM assemblyDWORD OSDDiv (DWORD a, DWORD b, DWORD dv) { unsigned long long ua=a,ub=b,udv=dv; return ua*ub/udv;}void ChromaCalc(SHORT Cr, SHORT Cb, WORD* pRout, WORD* pGout, WORD* pBout) { SHORT R,G,B; // Red R = (1.402 * (Cr-128)); if (R>255) R=255; if (R<0) R=0; // Green G = (-0.3437* (Cb-128) - 0.715* (Cr-128) ); if (G>255) G=255; if (G<0) G=0; // Blue B = ( 1.773 * (Cb-128)); if (B>255) B=255; if (B<0) B=0; *pRout = R; *pGout = G; *pBout = B;}BYTE RGBCalc(SHORT Y, SHORT R_G_B) { SHORT rgb; rgb= (Y+ R_G_B); if (rgb>255) rgb=255; if (rgb<0) rgb=0; return rgb;}// The following function just do nothing and that's ok.void OSWritePCIReg(DWORD DevNode, DWORD AddrData) { }void OSTimeInit (void) { }// this one is VERY important for JASPER// FIXME should use selective clean & flush// XXX vincent - do not call cache flush - it degrades remote control performance// XXX vincent - we only need to call cache flush on PCM data, so do it// XXX vincent - in user modevoid OSCacheFlush(void *pData, size_t size) { /*flush_cache_all();*/ }//Manu's kernel module doesnt implement thoses - We dovoid OSMapLinearToPhysical(DWORD dwLinearAddr, DWORD* pdwPhysicalAddr){ *pdwPhysicalAddr=dwLinearAddr;}void OSCompleteIo(LONG Status, void* pEventToComplete){ unsigned char *refCount=(unsigned char *)pEventToComplete; struct quasarprivate *pQ=&Q; // Release buffer if (refCount == 0) {#ifdef VERBOSE hwlprintk("OSCompleteIo: ERROR trying to release buffer with 0 refCount\n");#endif } else { // We shouldnt need any lock here we are in the IRQ, even if in // tasklet or bottom half, we cant be interupted by user space // User Space need to disable the irq to atomically modify // the refCount (*refCount)--; if(*refCount==0) { pQ->happening |= REALMAGICHWL_HAPPENING_BUFFER_RELEASE; wake_up_interruptible(&pQ->happening_queue); } }/* hwlprintk("OSCompleteIO: released buffer %p , count = %d\n",refCount,*refCount); */}//Manu's kernel module doesnt implement thoses - We DONT either (until we need them)void OSFreePacketListEntry(void* pPackList, DWORD uiPacketIndex, DWORD uiPacketCount){ hwlprintk("UNEXPECTED KERNELOS CALL! (FreePacketListEntry)\n");}void unpack(DWORD ThreeBytes, BYTE* Y){ hwlprintk("UNEXPECTED KERNELOS CALL! (Unpack) \n");}int OSrand(void){ hwlprintk("UNEXPECTED KERNELOS CALL! (Rand) \n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -