SASC-NG
DVBSoftCAM

cST20 Class Reference

#include <st20.h>

List of all members.

Public Member Functions

 cST20 (void)
 ~cST20 ()
void Init (unsigned int IPtr, unsigned int WPtr)
void SetCallFrame (unsigned int raddr, int p1, int p2, int p3)
void SetFlash (unsigned char *m, int len)
void SetRam (unsigned char *m, int len)
int Decode (int count)
unsigned int GetReg (int reg) const
void SetReg (int reg, unsigned int val)
unsigned int ReadWord (unsigned int off)
unsigned short ReadShort (unsigned int off)
unsigned char ReadByte (unsigned int off)
void WriteWord (unsigned int off, unsigned int val)
void WriteShort (unsigned int off, unsigned short val)
void WriteByte (unsigned int off, unsigned char val)

Detailed Description

Definition at line 48 of file st20.h.


Constructor & Destructor Documentation

cST20::cST20 ( void  )

Definition at line 73 of file st20.c.

{
  flash=ram=0;
  loglb=new cLineBuff(128);
}
cST20::~cST20 ( )

Definition at line 79 of file st20.c.

References free.

{
  free(flash);
  free(ram);
  delete loglb;
}

Member Function Documentation

int cST20::Decode ( int  count)

Definition at line 255 of file st20.c.

References AAA, b, BBB, CCC, CLEAR_OP, DROP, ERR_CNT, ERR_ILL_OP, GET_OP, JUMP, L_SYS_DISASM, L_SYS_ST20, LOG_OP, MOSTNEG, POP, POP64, cLineBuff::Printf(), PRINTF, PUSH, PUSHPOP, PUTLB, RB, ReadByte(), ReadShort(), RW, WriteByte(), and WW.

Referenced by cTPSDecrypt::Handle80008003().

{
  int operand;
  bool v=verbose;
  CLEAR_OP();
  while(Iptr!=0) {
    int a, op1=RB(Iptr++);
    if(v) LogOpOper(op1,operand);
    GET_OP();
    switch(op1>>4) {
      case 0x0: // j / jump
#ifdef SAVE_DEBUG
        POP(); POP(); POP();
#endif
        JUMP(operand);
        CLEAR_OP();
        break;
      case 0x1: // ldlp
        PUSH(Wptr+(operand*4));
        CLEAR_OP();
        break;
      case 0x2: // positive prefix
        operand<<=4;
        break;
      case 0x3: // ldnl
        AAA=RW(AAA+(operand*4));
        CLEAR_OP();
        break;
      case 0x4: // ldc
        PUSH(operand);
        CLEAR_OP();
        break;
      case 0x5: // ldnlp
        PUSHPOP(+,operand*4);
        CLEAR_OP();
        break;
      case 0x6: // negative prefix
        operand=(~operand)<<4;
        break;
      case 0x7: // ldl
        PUSH(RW(Wptr+(operand*4)));
        CLEAR_OP();
        break;
      case 0x8: // adc
        PUSHPOP(+,operand);
        CLEAR_OP();
        break;
      case 0x9: // call
        Wptr-=16;
        WW(Wptr,Iptr); WW(Wptr+4,POP()); WW(Wptr+8,POP()); WW(Wptr+12,POP());
        PUSH(Iptr);
        JUMP(operand);
        CLEAR_OP();
        break;
      case 0xA: // cj / conditional jump
        if(AAA) DROP(1); else JUMP(operand);
        CLEAR_OP();
        break;
      case 0xB: // ajw / adjust workspace
        Wptr+=operand*4;
        CLEAR_OP();
        break;
      case 0xC: // eqc / equals constant
        AAA=(operand==AAA ? 1 : 0);
        CLEAR_OP();
        break;
      case 0xD: // stl
        WW(Wptr+(operand*4),POP());
        CLEAR_OP();
        break;
      case 0xE: // stnl
        a=POP(); WW(a+(operand*4),POP());
        CLEAR_OP();
        break;
      case 0xF: // opr (secondary ins)
        switch(operand) {
          case  0x00: LOG_OP("rev");   a=AAA; AAA=BBB; BBB=a; break;
          case  0x01: LOG_OP("lb");    AAA=RB(AAA); break;
          case  0x02: LOG_OP("bsub");  PUSHPOP(+,POP()); break;
          case  0x04: LOG_OP("diff");  PUSHPOP(-,POP()); break;
          case  0x05: LOG_OP("add");   PUSHPOP(+,POP()); break;
          case  0x06: LOG_OP("gcall"); a=AAA; AAA=Iptr; Iptr=a; break;
          case  0x08: LOG_OP("prod");  PUSHPOP(*,POP()); break;
          case  0x09: LOG_OP("gt");    a=POP(); AAA=(AAA>a); break;
          case  0x0A: LOG_OP("wsub");  a=POP(); AAA=a+(AAA*4); break;
          case  0x0C: LOG_OP("sub");   PUSHPOP(-,POP()); break;

          case  0x1B: LOG_OP("ldpi");  PUSHPOP(+,Iptr); break;
          case  0x20: LOG_OP("ret");   Iptr=RW(Wptr); Wptr=Wptr+16; break;
          case  0x2C: LOG_OP("div");   PUSHPOP(/,POP()); break;
          case  0x32: LOG_OP("not");   AAA=~AAA; break;
          case  0x33: LOG_OP("xor");   PUSHPOP(^,POP()); break;
          case  0x34: LOG_OP("bcnt");  PUSHPOP(*,4); break;
          case  0x3B: LOG_OP("sb");    a=POP(); WriteByte(a,POP()); break;
          case  0x3F: LOG_OP("wcnt");  a=POP(); PUSH(a&3); PUSH((unsigned int)a>>2); break;
          case  0x40: LOG_OP("shr");   a=POP(); AAA=(unsigned int)AAA>>a; break;
          case  0x41: LOG_OP("shl");   a=POP(); AAA=(unsigned int)AAA<<a; break;
          case  0x42: LOG_OP("mint");  PUSH(MOSTNEG); break;
          case  0x46: LOG_OP("and");   PUSHPOP(&,POP()); break;
          case  0x4A: LOG_OP("move");  { a=POP(); int b=POP(); int c=POP(); while(a--) WriteByte(b++,ReadByte(c++)); } break;
          case  0x4B: LOG_OP("or");    PUSHPOP(|,POP()); break;
          case  0x53: LOG_OP("mul");   PUSHPOP(*,POP()); break;
          case  0x5A: LOG_OP("dup");   PUSH(AAA); break;
          case  0x5F: LOG_OP("gtu");   a=POP(); AAA=((unsigned int)AAA>(unsigned int)a); break;
          case  0x1D: LOG_OP("xdble"); CCC=BBB; BBB=(AAA>=0 ? 0:-1); break;
          case  0x1A: LOG_OP("ldiv");  { a=POP(); unsigned long long ll=POP64(); PUSH(ll%(unsigned int)a); PUSH(ll/(unsigned int)a); } break;
          case  0x1F: LOG_OP("rem");   PUSHPOP(%,POP()); break;
          case  0x35: LOG_OP("lshr");  { a=POP(); unsigned long long ll=POP64()>>a; PUSH((ll>>32)&0xFFFFFFFF); PUSH(ll&0xFFFFFFFF); } break;

          case  0xCA: LOG_OP("ls");    AAA=ReadShort(AAA); break;
          case  0xCD: LOG_OP("gintdis"); break;
          case  0xCE: LOG_OP("gintenb"); break;

          case -0x40: LOG_OP("nop");   break;

          default: 
            if(verbose) PUTLB(L_SYS_DISASM,loglb);
            PRINTF(L_SYS_ST20,"unknown opcode %X",operand);
            return ERR_ILL_OP;
          }
        CLEAR_OP();
        break;
      }

    if(v && operand==0) {
      loglb->Printf("%08X %08X %08X W:%08X",AAA,BBB,CCC,Wptr);
      PUTLB(L_SYS_DISASM,loglb);
      }
    if(--count<=0 && operand==0) {
      PRINTF(L_SYS_ST20,"instruction counter exceeded");
      return ERR_CNT;
      }
    }
  return 0;
}
unsigned int cST20::GetReg ( int  reg) const

Definition at line 124 of file st20.c.

References AAA, AREG, BBB, BREG, CCC, CREG, ERRORVAL, IPTR, L_SYS_ST20, PRINTF, and WPTR.

{
  switch(reg) {
    case IPTR: return Iptr;
    case WPTR: return Wptr;
    case AREG: return AAA;
    case BREG: return BBB;
    case CREG: return CCC;
    default:   PRINTF(L_SYS_ST20,"getreg: unknown reg"); return ERRORVAL;
    }
}
void cST20::Init ( unsigned int  IPtr,
unsigned int  WPtr 
)

Definition at line 104 of file st20.c.

References INVALID_VALUE, L_SYS_DISASM, LOG, and STACKMAX.

Referenced by cTPSDecrypt::Handle80008003().

{
  Wptr=WPtr; Iptr=IPtr;
  memset(stack,INVALID_VALUE,sizeof(stack)); sptr=STACKMAX-3;
  memset(iram,0,sizeof(iram));
  verbose=LOG(L_SYS_DISASM);
}
unsigned char cST20::ReadByte ( unsigned int  off)

Definition at line 193 of file st20.c.

References ERRORVAL, and UINT8_LE.

Referenced by Decode(), and cTPSDecrypt::Handle80008003().

{
#ifndef SAVE_DEBUG
  return UINT8_LE(Addr(off));
#else
  unsigned char *addr=Addr(off);
  return addr ? UINT8_LE(addr) : ERRORVAL>>24;
#endif
}
unsigned short cST20::ReadShort ( unsigned int  off)

Definition at line 183 of file st20.c.

References ERRORVAL, and UINT16_LE.

Referenced by Decode().

{
#ifndef SAVE_DEBUG
  return UINT16_LE(Addr(off));
#else
  unsigned char *addr=Addr(off);
  return addr ? UINT16_LE(addr) : ERRORVAL>>16;
#endif
}
unsigned int cST20::ReadWord ( unsigned int  off)

Definition at line 173 of file st20.c.

References ERRORVAL, and UINT32_LE.

{
#ifndef SAVE_DEBUG
  return UINT32_LE(Addr(off));
#else
  unsigned char *addr=Addr(off);
  return addr ? UINT32_LE(addr) : ERRORVAL;
#endif
}
void cST20::SetCallFrame ( unsigned int  raddr,
int  p1,
int  p2,
int  p3 
)

Definition at line 112 of file st20.c.

References AREG, SetReg(), and WriteWord().

Referenced by cTPSDecrypt::Handle80008003().

{
  Wptr-=16;
  WriteWord(Wptr,raddr); // RET
  WriteWord(Wptr+4,0);
  WriteWord(Wptr+8,0);
  WriteWord(Wptr+12,p1);
  WriteWord(Wptr+16,p2);
  WriteWord(Wptr+20,p3);
  SetReg(AREG,raddr);    // RET
}
void cST20::SetFlash ( unsigned char *  m,
int  len 
)

Definition at line 86 of file st20.c.

References free, and MALLOC.

{
  free(flash);
  flash=MALLOC(unsigned char,len);
  if(flash && m) memcpy(flash,m,len);
  else memset(flash,0,len);
  flashSize=len;
}
void cST20::SetRam ( unsigned char *  m,
int  len 
)

Definition at line 95 of file st20.c.

References free, and MALLOC.

{
  free(ram);
  ram=MALLOC(unsigned char,len);
  if(ram && m) memcpy(ram,m,len);
  else memset(ram,0,len);
  ramSize=len;
}
void cST20::SetReg ( int  reg,
unsigned int  val 
)

Definition at line 136 of file st20.c.

References AAA, AREG, BBB, BREG, CCC, CREG, IPTR, L_SYS_ST20, PRINTF, and WPTR.

Referenced by SetCallFrame().

{
  switch(reg) {
    case IPTR: Iptr=val; return;
    case WPTR: Wptr=val; return;
    case AREG: AAA=val; return;
    case BREG: BBB=val; return;
    case CREG: CCC=val; return;
    default:   PRINTF(L_SYS_ST20,"setreg: unknown reg"); return;
    }
}
void cST20::WriteByte ( unsigned int  off,
unsigned char  val 
)

Definition at line 223 of file st20.c.

References BYTE1_LE.

Referenced by Decode(), and cTPSDecrypt::Handle80008003().

{
#ifndef SAVE_DEBUG
  BYTE1_LE(Addr(off),val);
#else
  unsigned char *addr=Addr(off);
  if(addr) BYTE1_LE(addr,val);
#endif
}
void cST20::WriteShort ( unsigned int  off,
unsigned short  val 
)

Definition at line 213 of file st20.c.

References BYTE2_LE.

Referenced by cTPSDecrypt::Handle80008003().

{
#ifndef SAVE_DEBUG
  BYTE2_LE(Addr(off),val);
#else
  unsigned char *addr=Addr(off);
  if(addr) BYTE2_LE(addr,val);
#endif
}
void cST20::WriteWord ( unsigned int  off,
unsigned int  val 
)

Definition at line 203 of file st20.c.

References BYTE4_LE.

Referenced by cTPSDecrypt::Handle80008003(), and SetCallFrame().

{
#ifndef SAVE_DEBUG
  BYTE4_LE(Addr(off),val);
#else
  unsigned char *addr=Addr(off);
  if(addr) BYTE4_LE(addr,val);
#endif
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines