From: leslie Date: Sat, 14 Jun 2008 09:20:28 +0000 (+0800) Subject: nagra: more generic map IRQ & timing API X-Git-Tag: 0.9.1~66 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=c81a71f8ddd9cb61beec00a8519c676b6a18cc90;p=sasc-ng.git nagra: more generic map IRQ & timing API --- diff --git a/systems/nagra/nagra2-0101.c b/systems/nagra/nagra2-0101.c index 5bfb805..764288f 100644 --- a/systems/nagra/nagra2-0101.c +++ b/systems/nagra/nagra2-0101.c @@ -116,25 +116,17 @@ int cAuxSrv::Map(int map, unsigned char *data, int len, int outlen) // -- cMap0101 ---------------------------------------------------------------- -#define MAP_IRQ_BEGIN() interruptible=true; try { -#define MAP_IRQ_END() } catch(int) { interrupted=true; } interruptible=false; - class cMap0101 : public cMapCore { private: static const unsigned char primes[]; static const unsigned short coef22[][32]; - bool interruptible, interrupted; #ifdef HAS_AUXSRV cAuxSrv aux; #endif // void MakePrime(BIGNUM *n, unsigned char *residues); protected: - void DoMap(int f, unsigned char *data=0, int l=0); - bool Interruptible(void) { return interruptible; } - bool Interrupted(void) { return interrupted; } -public: - cMap0101(void) { interruptible=false; } + bool Map(int f, unsigned char *data, int l); }; const unsigned char cMap0101::primes[] = { @@ -166,15 +158,11 @@ void cMap0101::MakePrime(BIGNUM *n, unsigned char *residues) } while(!isPrime); } -void cMap0101::DoMap(int f, unsigned char *data, int l) +bool cMap0101::Map(int f, unsigned char *data, int l) { - PRINTF(L_SYS_MAP,"0101: calling function %02X",f); l=GetOpSize(l); - cycles=0; interrupted=false; - unsigned int startcycles=MapCycles(); switch(f) { case 0x21: - MAP_IRQ_BEGIN(); AddMapCycles(288); WS_START(1); MakeJ0(J,D,C); @@ -182,7 +170,6 @@ void cMap0101::DoMap(int f, unsigned char *data, int l) BN_clear(C); WS_END(); cycles=898; - MAP_IRQ_END(); break; case 0x22: if(BN_is_zero(D)) { cycles=639-6; break; } @@ -352,12 +339,9 @@ void cMap0101::DoMap(int f, unsigned char *data, int l) break; } default: - if(!cMapCore::DoMap(f,data,l)) - PRINTF(L_SYS_MAP,"0101: unsupported call %02x",f); - break; + return false; } - if(!interrupted && cycles) - cycles-=MapCycles()-startcycles; + return true; } // -- cN2Prov0101 -------------------------------------------------------------- @@ -401,6 +385,7 @@ cN2Prov0101::cN2Prov0101(int Id, int Flags) mecmAddr[0]=0x91d7; mecmAddr[1]=0x92d7; mecmKeyId=0x106; seedSize=10; desSize=16; hwMapper=0; + SetMapIdent(Id); } void cN2Prov0101::DynamicHD(unsigned char *hd, const unsigned char *ed) @@ -652,7 +637,6 @@ bool cN2Prov0101::ProcessMap(int f) return false; } c6805::a=0; c6805::x=0; c6805::y=0; - if(cycles>0) AddMapCycles(cycles); return true; } diff --git a/systems/nagra/nagra2-0501.c b/systems/nagra/nagra2-0501.c index 1bfe95f..c152661 100644 --- a/systems/nagra/nagra2-0501.c +++ b/systems/nagra/nagra2-0501.c @@ -26,34 +26,22 @@ // -- cMap0501 ----------------------------------------------------------------- class cMap0501 : public cMapCore { -private: - int mId; protected: - void DoMap(int f, unsigned char *data=0, int l=0); -public: - cMap0501(int Id); + bool Map(int f, unsigned char *data, int l); }; -cMap0501::cMap0501(int Id) -{ - mId=Id|0x100; -} - -void cMap0501::DoMap(int f, unsigned char *data, int l) +bool cMap0501::Map(int f, unsigned char *data, int l) { - PRINTF(L_SYS_MAP,"%04x: calling function %02X",mId,f); l=GetOpSize(l); - cycles=0; switch(f) { case 0x37: I.GetLE(data,l<<3); MonMul(B,I,B); break; default: - if(!cMapCore::DoMap(f,data,l)) - PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mId,f); - break; + return false; } + return true; } // -- cN2Prov0501 -------------------------------------------------------------- @@ -81,9 +69,9 @@ static cN2ProvLinkReg sta cN2Prov0501::cN2Prov0501(int Id, int Flags) :cN2Prov(Id,Flags) -,cMap0501(Id) { hwMapper=0; hasMaprom=false; + SetMapIdent(Id); } bool cN2Prov0501::Algo(int algo, const unsigned char *hd, unsigned char *hw) @@ -194,7 +182,6 @@ bool cN2Prov0501::ProcessMap(int f) PRINTF(L_SYS_EMU,"%04x: map call %02x not emulated",id,f); return false; } - if(cycles>0) AddMapCycles(cycles); return true; } diff --git a/systems/nagra/nagra2-4101.c b/systems/nagra/nagra2-4101.c index 4b7a81d..35a45f3 100644 --- a/systems/nagra/nagra2-4101.c +++ b/systems/nagra/nagra2-4101.c @@ -26,22 +26,12 @@ // -- cMap4101 ----------------------------------------------------------------- class cMap4101 : public cMapCore { -private: - int mId; protected: - void DoMap(int f, unsigned char *data=0, int l=0); -public: - cMap4101(int Id); + bool Map(int f, unsigned char *data, int l); }; -cMap4101::cMap4101(int Id) -{ - mId=Id|0x100; -} - -void cMap4101::DoMap(int f, unsigned char *data, int l) +bool cMap4101::Map(int f, unsigned char *data, int l) { - PRINTF(L_SYS_MAP,"%04x: calling function %02X",mId,f); switch(f) { case 0x58: { @@ -78,10 +68,9 @@ void cMap4101::DoMap(int f, unsigned char *data, int l) cMapCore::DoMap(0x44,data); break; default: - if(!cMapCore::DoMap(f,data,l)) - PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mId,f); - break; + return false; } + return true; } // -- cN2Prov4101 ---------------------------------------------------------------- @@ -99,9 +88,9 @@ static cN2ProvLinkReg staticPL4101 cN2Prov4101::cN2Prov4101(int Id, int Flags) :cN2Prov(Id,Flags) -,cMap4101(Id) { hasWriteHandler=true; + SetMapIdent(Id); } bool cN2Prov4101::PostProcAU(int id, unsigned char *data) diff --git a/systems/nagra/nagra2.c b/systems/nagra/nagra2.c index 4ed23b9..b872ff4 100644 --- a/systems/nagra/nagra2.c +++ b/systems/nagra/nagra2.c @@ -484,8 +484,9 @@ void cMapMath::MonLoop(BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BI cMapCore::cMapCore(void) { - last=1; + last=1; mapid=0; regs[0]=&J; regs[1]=&A; regs[2]=&B; regs[3]=&C; regs[4]=&D; + interruptible=false; } void cMapCore::MonInit(int bits) @@ -653,11 +654,25 @@ int cMapCore::GetOpSize(int l) return l!=0 ? l : wordsize; } -bool cMapCore::DoMap(int f, unsigned char *data, int l) +void cMapCore::DoMap(int f, unsigned char *data, int l) +{ + PRINTF(L_SYS_MAP,"%04x: calling function %02X",mapid,f); + cycles=0; + unsigned int startcycles=MapCycles(); + interrupted=false; interruptible=true; + try { + if(!Map(f,data,l) && !MapGeneric(f,data,l)) + PRINTF(L_SYS_MAP,"%04x: unsupported call %02x",mapid,f); + } catch(int) { interrupted=true; } + interruptible=false; + if(!interrupted && cycles) + AddMapCycles(MapCycles()-startcycles); +} + +bool cMapCore::MapGeneric(int f, unsigned char *data, int l) { const int l1=GetOpSize(l); const int dl=l1<<3; - cycles=0; switch(f) { case SETSIZE: cycles=(l>17 ? 459 : (l ? 475 : 454))-6; diff --git a/systems/nagra/nagra2.h b/systems/nagra/nagra2.h index 19bc507..673605d 100644 --- a/systems/nagra/nagra2.h +++ b/systems/nagra/nagra2.h @@ -140,9 +140,12 @@ public: class cMapCore : public cMapMath { private: - int last; + int mapid, last; cBN e; cMapReg *regs[5]; + bool interruptible, interrupted; + // + bool MapGeneric(int f, unsigned char *data, int l); protected: unsigned int cycles; cBN Px, Py, Pz,Qx, Qy, Qz; // 0x00,0x20,0x40,0x60,0x80,0x180 @@ -159,7 +162,11 @@ protected: void CurveInit(BIGNUM *a); // int GetOpSize(int l); - bool DoMap(int f, unsigned char *data=0, int l=0); + void DoMap(int f, unsigned char *data=0, int l=0); + virtual bool Map(int f, unsigned char *data, int l) { return false; } + void SetMapIdent(int Mapid) { mapid=Mapid; } + bool Interruptible(void) { return interruptible; } + bool Interrupted(void) { return interrupted; } virtual void AddMapCycles(unsigned int num) {} virtual unsigned int MapCycles(void) { return 0; } public: