Beispiel #1
0
void
test_read16_simple(void)
{
        int i;

        CHECK_FOR_SBC;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test READ16 of 1-256 blocks at the start of the LUN");
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, 0, i * block_size,
                       block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_STATUS_GOOD);
        }


        logging(LOG_VERBOSE, "Test READ16 of 1-256 blocks at the end of the LUN");
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, num_blocks - i,
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_STATUS_GOOD);
        }
}
Beispiel #2
0
int NormalIMBase::readHeader(const unsigned char *buf)
{
	int pos=0;

	senderVersion = READ16(buf+pos);
	pos+=2;

	sender = READ32(buf+pos);
	pos+=4;

	receiver = READ32(buf+pos);
	pos+=4;
	
	memcpy(fileSessionKey, buf+pos, 16);
	pos+=16;

	type = READ16(buf+pos);
	pos+=2;

	sequence = READ16(buf+pos);
	pos+=2;
	
	sendTime = READ32(buf+pos);
	pos+=4;

	senderFace = READ16(buf+pos);
	pos+=2;
	
	return pos;
}
Beispiel #3
0
static
void xycom566isrcb(CALLBACK *cb)
{
  xy566 *card;
  epicsUInt16 csr;
  epicsUInt16 datacnt[32];
  epicsUInt16 dcnt;
  size_t i, ch;

  callbackGetUser(card,cb);

  epicsMutexMustLock(card->guard);

  /* clear number of data points */
  memset(datacnt,0,sizeof(datacnt));

  /* number of samples taken */
  dcnt=READ16(card->base, XY566_RAM);

  if(dcnt>256){
    /* Somehow the sequence was restart w/o resetting
     * the pointer, or changed by an outside program
     */
    dcnt=256;
    printf("Data longer then expected\n");
  }

  for(i=0;i<dcnt;i++){
    ch=card->seq[i]&0x1f;

    card->data[ch][datacnt[ch]]=READ16(card->data_base, XY566_DOFF(i));
    datacnt[ch]++;

    if( card->seq[i]&SEQ_END )
      break;
  }
  
  /* reset pointers */
  WRITE16(card->base, XY566_RAM, 0);
  WRITE8(card->base, XY566_SEQ, 0);

  csr=READ16(card->base, XY566_CSR);

  /* enable sequence controller */
  csr|=XY566_CSR_SEQ;

  WRITE16(card->base, XY566_CSR, csr);

  scanIoRequest(card->seq_irq);

  epicsMutexUnlock(card->guard);
}
Beispiel #4
0
// Return the size of the data in the buffer
unsigned buf_get_count( unsigned resid, unsigned resnum )
{
  BUF_CHECK_RESNUM( resid, resnum );
  BUF_GETPTR( resid, resnum );
  
  return READ16( pbuf->count );  
}
Beispiel #5
0
void i386_device::i486_cmpxchg_rm16_r16()  // Opcode 0x0f b1
{
	UINT8 modrm = FETCH();
	if( modrm >= 0xc0 ) {
		UINT16 dst = LOAD_RM16(modrm);
		UINT16 src = LOAD_REG16(modrm);

		if( REG16(AX) == dst ) {
			STORE_RM16(modrm, src);
			m_ZF = 1;
			CYCLES(CYCLES_CMPXCHG_REG_REG_T);
		} else {
			REG16(AX) = dst;
			m_ZF = 0;
			CYCLES(CYCLES_CMPXCHG_REG_REG_F);
		}
	} else {
		UINT32 ea = GetEA(modrm,0);
		UINT16 dst = READ16(ea);
		UINT16 src = LOAD_REG16(modrm);

		if( REG16(AX) == dst ) {
			WRITE16(ea, src);
			m_ZF = 1;
			CYCLES(CYCLES_CMPXCHG_REG_MEM_T);
		} else {
			REG16(AX) = dst;
			m_ZF = 0;
			CYCLES(CYCLES_CMPXCHG_REG_MEM_F);
		}
	}
}
Beispiel #6
0
static void I486OP(cmpxchg_rm16_r16)(i386_state *cpustate)	// Opcode 0x0f b1
{
	UINT8 modrm = FETCH(cpustate);
	if( modrm >= 0xc0 ) {
		UINT16 dst = LOAD_RM16(modrm);
		UINT16 src = LOAD_REG16(modrm);

		if( REG16(AX) == dst ) {
			STORE_RM16(modrm, src);
			cpustate->ZF = 1;
			CYCLES(cpustate,CYCLES_CMPXCHG_REG_REG_T);
		} else {
			REG16(AX) = dst;
			cpustate->ZF = 0;
			CYCLES(cpustate,CYCLES_CMPXCHG_REG_REG_F);
		}
	} else {
		UINT32 ea = GetEA(cpustate,modrm);
		UINT16 dst = READ16(cpustate,ea);
		UINT16 src = LOAD_REG16(modrm);

		if( REG16(AX) == dst ) {
			WRITE16(cpustate,modrm, src);
			cpustate->ZF = 1;
			CYCLES(cpustate,CYCLES_CMPXCHG_REG_MEM_T);
		} else {
			REG16(AX) = dst;
			cpustate->ZF = 0;
			CYCLES(cpustate,CYCLES_CMPXCHG_REG_MEM_F);
		}
	}
}
static void
check_lun_is_wiped(unsigned char *buf, uint64_t lba)
{
        unsigned char *rbuf = alloca(256 * block_size);

        READ16(sd, NULL, lba, 256 * block_size, block_size, 0, 0, 0, 0, 0, rbuf,
               EXPECT_STATUS_GOOD);
        if (rc16 == NULL) {
                return;
        }

        if (rc16->lbprz) {
                logging(LOG_VERBOSE, "LBPRZ==1 All blocks "
                        "should read back as 0");
                if (all_zero(rbuf, 256 * block_size) == 0) {
                        logging(LOG_NORMAL, "[FAILED] Blocks did not "
                                "read back as zero");
                        CU_FAIL("[FAILED] Blocks did not read back "
                                "as zero");
                } else {
                        logging(LOG_VERBOSE, "[SUCCESS] Blocks read "
                                "back as zero");
                }
        } else {
                logging(LOG_VERBOSE, "LBPRZ==0 Blocks should not read back as "
                        "all 'a' any more");
                if (!memcmp(buf, rbuf, 256 * block_size)) {
                        logging(LOG_NORMAL, "[FAILED] Blocks were not wiped");
                        CU_FAIL("[FAILED] Blocks were not wiped");
                } else {
                        logging(LOG_VERBOSE, "[SUCCESS] Blocks were wiped");
                }
        }
}
Beispiel #8
0
static
void xycom566isr(void *arg)
{
  xy566 *card=arg;
  epicsUInt16 csr;
  csr=READ16(card->base, XY566_CSR);
  if(!(csr&XY566_CSR_PND))
    return; /* not ours */

  if(card->use_seq_clk)
    WRITE8(card->base, XY566_STC, 0xC2); /* Disarm Seq. trig clock */
  
  /* Disable sequence controller, acknowledge
   * interrupts, and schedule further processing
   * out of interrupt context
   */

  csr&=~XY566_CSR_SEQ; /* disable seq. cont. */

  /* writing back what was read will clear any pending
   * interrupts
   */

  WRITE16(card->base, XY566_CSR, csr);

  callbackRequest(&card->cb_irq);

  return;
}
Beispiel #9
0
static void I386OP(fpu_group_d9)(void)		/* Opcode 0xd9 */
{
	UINT8 modrm = FETCH();

	if (modrm < 0xc0)
	{
		UINT32 ea = GetEA(modrm);

		switch ((modrm >> 3) & 0x7)
		{
			case 5:			/* FLDCW */
			{
				I.fpu_control_word = READ16(ea);
				CYCLES(1);		/* TODO */
				break;
			}

			case 7:			/* FSTCW */
			{
				WRITE16(ea, I.fpu_control_word);
				CYCLES(1);		/* TODO */
				break;
			}

			default:
				osd_die("I386: FPU Op D9 %02X at %08X\n", modrm, I.pc-2);
		}
	}
Beispiel #10
0
void tlcs870_device::do_ALUOP_gg_mn(const uint8_t opbyte0, const uint8_t opbyte1)
{
	/*
	    OP                (opbyte0) (immval0) (opbyte1) (immval1) (immval2)    JF ZF CF HF   cycles
	    ADDC gg, mn       1110 10gg           0011 1000 nnnn nnnn mmmm mmmm    C  Z  C  U    4
	    ADD gg, mn        1110 10gg           0011 1001 nnnn nnnn mmmm mmmm    C  Z  C  U    4
	    SUBB gg, mn       1110 10gg           0011 1010 nnnn nnnn mmmm mmmm    C  Z  C  U    4
	    SUB gg, mn        1110 10gg           0011 1011 nnnn nnnn mmmm mmmm    C  Z  C  U    4
	    AND gg, mn        1110 10gg           0011 1100 nnnn nnnn mmmm mmmm    Z  Z  -  -    4
	    XOR gg, mn        1110 10gg           0011 1101 nnnn nnnn mmmm mmmm    Z  Z  -  -    4
	    OR gg, mn         1110 10gg           0011 1110 nnnn nnnn mmmm mmmm    Z  Z  -  -    4
	    CMP gg, mn        1110 10gg           0011 1111 nnnn nnnn mmmm mmmm    Z  Z  C  U    4
	*/
	m_cycles = 4;

	const int aluop = (opbyte1 & 0x7);

	const uint16_t mn = READ16();

	const uint16_t result = do_alu_16bit(aluop, get_reg16(opbyte0 & 0x3), mn);

	if (aluop != 0x07) // CMP doesn't write back
	{
		set_reg16(opbyte0 & 0x3, result);
	}
}
void
test_verify16_mismatch_no_cmp(void)
{
        int i;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test VERIFY16 without BYTCHK for blocks 1-255");
        for (i = 1; i <= 256; i++) {
                int offset = random() % (i * block_size);

                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, 0, i * block_size,
                       block_size, 0, 0, 0, 0, 0, scratch,
                       EXPECT_STATUS_GOOD);

                /* flip a random byte in the data */
                scratch[offset] ^= 'X';
                logging(LOG_VERBOSE, "Flip some bits in the data");

                VERIFY16(sd, 0, i * block_size, block_size, 0, 0, 0, scratch,
                         EXPECT_STATUS_GOOD);
        }

        logging(LOG_VERBOSE, "Test VERIFY16 without BYTCHK of 1-256 blocks at the end of the LUN");
        for (i = 1; i <= 256; i++) {
                int offset = random() % (i * block_size);

                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, num_blocks - i,
                       i * block_size, block_size, 0, 0, 0, 0, 0, scratch,
                       EXPECT_STATUS_GOOD);

                /* flip a random byte in the data */
                scratch[offset] ^= 'X';
                logging(LOG_VERBOSE, "Flip some bits in the data");

                VERIFY16(sd, num_blocks - i,
                         i * block_size, block_size, 0, 0, 0, scratch,
                         EXPECT_STATUS_GOOD);
        }
}
Beispiel #12
0
//0x08:LD (a16), SP
int gb_exec_x0_z0_y1(struct gb *gb)
{
	addr im = READ16(REG(PC));
	REG(PC) += 2;

	logf("LD (%4x),SP | SP=%.4x", im, REG(SP));
	WRITE16(im, REG(SP));
	gb->cycle += 20;
	return RET_SUCCESS;
}
Beispiel #13
0
const PRUint8 * nsZipHeader::GetExtraField(PRUint16 aTag, bool aLocal, PRUint16 *aBlockSize)
{
    const PRUint8 *buf = aLocal ? mLocalExtraField : mExtraField;
    PRUint32 buflen = aLocal ? mLocalFieldLength : mFieldLength;
    PRUint32 pos = 0;
    PRUint16 tag, blocksize;

    while (buf && (pos + 4) <= buflen) {
      tag = READ16(buf, &pos);
      blocksize = READ16(buf, &pos);

      if (aTag == tag && (pos + blocksize) <= buflen) {
        *aBlockSize = blocksize;
        return buf + pos - 4;
      }

      pos += blocksize;
    }

    return NULL;
}
void
test_writesame16_unmap_until_end(void)
{
        unsigned int i;

        CHECK_FOR_DATALOSS;
        CHECK_FOR_THIN_PROVISIONING;
        CHECK_FOR_LBPWS;
        CHECK_FOR_SBC;

        if (inq_bl->wsnz) {
                logging(LOG_NORMAL, "WRITESAME16 does not support 0-blocks."
                        "WSNZ == 1");
                memset(scratch, 0, block_size);
                WRITESAME16(sd, 0, block_size, 0, 0, 1, 0, 0, scratch,
                            EXPECT_INVALID_FIELD_IN_CDB);
                return;
        }

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN by setting number-of-blocks==0");
        memset(scratch, 0xa6, 256 * block_size);
        for (i = 1; i <= 256; i++) {
                logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
                memset(scratch, 0xff, block_size * i);
                WRITE16(sd, num_blocks - i,
                        i * block_size, block_size, 0, 0, 0, 0, 0, scratch,
                        EXPECT_STATUS_GOOD);

                logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
                memset(scratch, 0, block_size);
                WRITESAME16(sd, num_blocks - i,
                            block_size, 0, 0, 1, 0, 0, scratch,
                            EXPECT_STATUS_GOOD);

                if (rc16->lbprz) {
                        logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
                                "blocks back and verify they are all zero");

                        logging(LOG_VERBOSE, "Read %d blocks and verify they "
                                "are now zero", i);
                        READ16(sd, NULL, num_blocks - i,
                               i * block_size, block_size,
                               0, 0, 0, 0, 0, scratch,
                               EXPECT_STATUS_GOOD);
                        ALL_ZERO(scratch, i * block_size);
                } else {
                        logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
                                "and verify zero test");
                }
        }
}
Beispiel #15
0
int ReceiveIMPacket::readHeader(const unsigned char *buf)
{
	int pos=0;
	sender = READ32(buf);
	pos+=4;

	receiver = READ32(buf+pos);
	pos+=4;

	intSequence = READ32(buf+pos);
	pos+=4;

	senderIP = READ32(buf+pos);
	pos+=4;

	senderPort = READ16(buf+pos);
	pos+=2;

	type = READ16(buf+pos);
	pos+=2;	
	return pos;
}
Beispiel #16
0
void
xycom566finish(void)
{
  ELLNODE *node;
  xy566* card;
  epicsUInt16 csr;
  

  for(node=ellFirst(&xy566s); node; node=ellNext(node))
  {
    card=node2priv(node);

    if(!card->fail){
      if(!!finish566seq(card)){
        printf("Board #%d failed to generate samping sequence and will not be used\n",card->id);
        card->fail=1;
      }
    }
    
    if(!card->clk_div){
      printf("Board #%d STC not initialized and will not be used\n",card->id);
      card->fail=1;
    }

    if(!!card->fail){
      printf("Board #%d failed to initialize and will not be used\n",card->id);

      /* Reset the board again and
       * turn off the LEDS to indicate failure
       */
      WRITE16(card->base, XY566_CSR, XY566_CSR_RST);
      WRITE16(card->base, XY566_CSR, XY566_CSR_RED);
      return;

    }
    
    WRITE16(card->base, XY566_RAM, 0);
    WRITE8(card->base, XY566_SEQ, 0);

    csr=READ16(card->base, XY566_CSR);
    csr|=XY566_CSR_SEQ|XY566_CSR_INA|XY566_CSR_SIE;
    csr|=XY566_CSR_RED|XY566_CSR_GRN;
    WRITE16(card->base, XY566_CSR, csr);
  }

  return;
}
Beispiel #17
0
static void I486OP(xadd_rm16_r16)(i386_state *cpustate)	// Opcode 0x0f c1
{
	UINT8 modrm = FETCH(cpustate);
	if( modrm >= 0xc0 ) {
		UINT16 dst = LOAD_RM16(modrm);
		UINT16 src = LOAD_REG16(modrm);
		STORE_RM16(modrm, dst + src);
		STORE_REG16(modrm, dst);
		CYCLES(cpustate,CYCLES_XADD_REG_REG);
	} else {
		UINT32 ea = GetEA(cpustate,modrm);
		UINT16 dst = READ16(cpustate,ea);
		UINT16 src = LOAD_REG16(modrm);
		WRITE16(cpustate,ea, dst + src);
		STORE_REG16(modrm, dst);
		CYCLES(cpustate,CYCLES_XADD_REG_MEM);
	}
}
Beispiel #18
0
void i386_device::i486_xadd_rm16_r16() // Opcode 0x0f c1
{
	UINT8 modrm = FETCH();
	if( modrm >= 0xc0 ) {
		UINT16 dst = LOAD_RM16(modrm);
		UINT16 src = LOAD_REG16(modrm);
		STORE_REG16(modrm, dst);
		STORE_RM16(modrm, dst + src);
		CYCLES(CYCLES_XADD_REG_REG);
	} else {
		UINT32 ea = GetEA(modrm,1);
		UINT16 dst = READ16(ea);
		UINT16 src = LOAD_REG16(modrm);
		WRITE16(ea, dst + src);
		STORE_REG16(modrm, dst);
		CYCLES(CYCLES_XADD_REG_MEM);
	}
}
Beispiel #19
0
// Get data from buffer of size dsize
// resid - resource ID (BUF_ID_UART ...)
// resnum - resource number (0, 1, 2...)
// data - pointer for where data should go
// dsize - length of data to get
// Returns PLATFORM_OK on success, PLATFORM_ERR on failure, 
//   PLATFORM_UNDERFLOW on buffer empty
int buf_read( unsigned resid, unsigned resnum, t_buf_data *data )
{
  BUF_CHECK_RESNUM( resid, resnum );
  BUF_GETPTR( resid, resnum );

  int old_status;
  const char* s = ( const char* )( pbuf->buf + pbuf->rptr );
  char* d = ( char* )data;
  
  if( pbuf->logsize == BUF_SIZE_NONE || READ16( pbuf->count ) == 0 )
    return PLATFORM_UNDERFLOW;
 
  DUFF_DEVICE_8( BUF_REALDSIZE( pbuf ),  *d++ = *s++ );

  old_status = platform_cpu_set_global_interrupts( PLATFORM_CPU_DISABLE );
  pbuf->count --;
  platform_cpu_set_global_interrupts( old_status );
  BUF_MOD_INCR( pbuf, rptr );
  
  return PLATFORM_OK;
}
void
test_read16_rdprotect(void)
{
        int i;

        /*
         * Try out different non-zero values for RDPROTECT.
         */
        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test READ16 with non-zero RDPROTECT");

        CHECK_FOR_SBC;

        if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) {
                logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail.");
                for (i = 1; i < 8; i++) {
                        READ16(sd, NULL, 0, block_size, block_size,
                               i, 0, 0, 0, 0, NULL,
                               EXPECT_INVALID_FIELD_IN_CDB);
                }
                return;
        }
        logging(LOG_NORMAL, "No tests for devices that support protection information yet.");
}
Beispiel #21
0
/* ---------------------------------------------------------------------------
 * Read a Targa image from <fp> to <dest>.
 *
 * Returns: TGA_NOERR on success, or a TGAERR_* code on failure.  In the
 *          case of failure, the contents of dest are not guaranteed to be
 *          valid.
 */
tga_result tga_read_from_FILE(tga_image *dest, FILE *fp)
{
    #define BARF(errcode) \
        { tga_free_buffers(dest);  return errcode; }

    #define READ(destptr, size) \
        if (fread(destptr, size, 1, fp) != 1) BARF(TGAERR_EOF)

    #define READ16(dest) \
        { if (fread(&(dest), 2, 1, fp) != 1) BARF(TGAERR_EOF); \
          dest = letoh16(dest); }

    dest->image_id = NULL;
    dest->color_map_data = NULL;
    dest->image_data = NULL;

    READ(&dest->image_id_length,1);
    READ(&dest->color_map_type,1);
    if (dest->color_map_type != TGA_COLOR_MAP_ABSENT &&
        dest->color_map_type != TGA_COLOR_MAP_PRESENT)
            BARF(TGAERR_CMAP_TYPE);

    READ(&dest->image_type, 1);
    if (dest->image_type == TGA_IMAGE_TYPE_NONE)
            BARF(TGAERR_NO_IMG);

    if (dest->image_type != TGA_IMAGE_TYPE_COLORMAP &&
        dest->image_type != TGA_IMAGE_TYPE_BGR &&
        dest->image_type != TGA_IMAGE_TYPE_MONO &&
        dest->image_type != TGA_IMAGE_TYPE_COLORMAP_RLE &&
        dest->image_type != TGA_IMAGE_TYPE_BGR_RLE &&
        dest->image_type != TGA_IMAGE_TYPE_MONO_RLE)
            BARF(TGAERR_IMG_TYPE);

    if (tga_is_colormapped(dest) &&
        dest->color_map_type == TGA_COLOR_MAP_ABSENT)
            BARF(TGAERR_CMAP_MISSING);

    if (!tga_is_colormapped(dest) &&
        dest->color_map_type == TGA_COLOR_MAP_PRESENT)
            BARF(TGAERR_CMAP_PRESENT);

    READ16(dest->color_map_origin);
    READ16(dest->color_map_length);
    READ(&dest->color_map_depth, 1);
    if (dest->color_map_type == TGA_COLOR_MAP_PRESENT)
    {
        if (dest->color_map_length == 0)
            BARF(TGAERR_CMAP_LENGTH);

        if (!UNMAP_DEPTH(dest->color_map_depth))
            BARF(TGAERR_CMAP_DEPTH);
    }

    READ16(dest->origin_x);
    READ16(dest->origin_y);
    READ16(dest->width);
    READ16(dest->height);

    if (dest->width == 0 || dest->height == 0)
            BARF(TGAERR_ZERO_SIZE);

    READ(&dest->pixel_depth, 1);
    if (!SANE_DEPTH(dest->pixel_depth) ||
       (dest->pixel_depth != 8 && tga_is_colormapped(dest)) )
            BARF(TGAERR_PIXEL_DEPTH);

    READ(&dest->image_descriptor, 1);

    if (dest->image_id_length > 0)
    {
        dest->image_id = (uint8_t*)malloc(dest->image_id_length);
        if (dest->image_id == NULL) BARF(TGAERR_NO_MEM);
        READ(dest->image_id, dest->image_id_length);
    }

    if (dest->color_map_type == TGA_COLOR_MAP_PRESENT)
    {
        dest->color_map_data = (uint8_t*)malloc(
            (dest->color_map_origin + dest->color_map_length) *
            dest->color_map_depth / 8);
        if (dest->color_map_data == NULL) BARF(TGAERR_NO_MEM);
        READ(dest->color_map_data +
            (dest->color_map_origin * dest->color_map_depth / 8),
            dest->color_map_length * dest->color_map_depth / 8);
    }

    dest->image_data = (uint8_t*) malloc(
        dest->width * dest->height * dest->pixel_depth / 8);
    if (dest->image_data == NULL)
            BARF(TGAERR_NO_MEM);

    if (tga_is_rle(dest))
    {
        /* read RLE */
        tga_result result = tga_read_rle(dest, fp);
        if (result != TGA_NOERR) BARF(result);
    }
    else
    {
        /* uncompressed */
        READ(dest->image_data,
            dest->width * dest->height * dest->pixel_depth / 8);
    }

    return TGA_NOERR;
    #undef BARF
    #undef READ
    #undef READ16
}
void
test_read16_beyond_eol(void)
{ 
        int i;

        CHECK_FOR_SBC;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test READ16 1-256 blocks one block beyond the end");
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, num_blocks + 1 - i,
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }

        logging(LOG_VERBOSE, "Test READ16 1-256 blocks at LBA==2^63");
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, 0x8000000000000000ULL,
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }

        logging(LOG_VERBOSE, "Test READ16 1-256 blocks at LBA==2^%d",
                64 - ilog2(block_size));
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, 1ULL << (64 - ilog2(block_size)),
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }

        logging(LOG_VERBOSE, "Test READ16 1-256 blocks at LBA==2^%d",
                63 - ilog2(block_size));
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, 1ULL << (63 - ilog2(block_size)),
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }

        logging(LOG_VERBOSE, "Test READ16 1-256 blocks at LBA==-1");
        for (i = 1; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, -1, i * block_size,
                       block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }

        logging(LOG_VERBOSE, "Test READ16 2-256 blocks all but one block beyond the end");
        for (i = 2; i <= 256; i++) {
                if (maximum_transfer_length && maximum_transfer_length < i) {
                        break;
                }
                READ16(sd, NULL, num_blocks - 1,
                       i * block_size, block_size, 0, 0, 0, 0, 0, NULL,
                       EXPECT_LBA_OOB);
        }
}
void
test_write16_residuals(void)
{
        struct scsi_task *task_ret;
        unsigned char buf[10000];
        struct iscsi_data data;
        int ok;
        unsigned int i;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test WRITE16 commands with residuals");
        logging(LOG_VERBOSE, "Block size is %zu", block_size);

        CHECK_FOR_DATALOSS;
        CHECK_FOR_SBC;

        if (sd->iscsi_ctx == NULL) {
                const char *err = "[SKIPPED] This WRITE16 test is only "
                        "supported for iSCSI backends";
                logging(LOG_NORMAL, "%s", err);
                CU_PASS(err);
                return;
        }

        /* Try a write16 of 1 block but xferlength == 0 */
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 0;

        /*
         * we don't want autoreconnect since some targets will drop the session
         * on this condition.
         */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 1);

        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0");

        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);
        CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */

        if (task->status        == SCSI_STATUS_CHECK_CONDITION
            && task->sense.key  == SCSI_SENSE_ILLEGAL_REQUEST
            && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
                logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented.");
                CU_PASS("WRITE16 is not implemented.");
                return;
        }        
        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size);
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        /* in case the previous test failed the session */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 0);


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 10000;

        memset(buf, 0xa6, sizeof(buf));
        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow",
                10000 - block_size);
        if (task->residual != 10000 - block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        10000 - block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, 10000 - block_size);
        scsi_free_scsi_task(task);
        task = NULL;


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==200");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 200;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        ok = task->status == SCSI_STATUS_GOOD ||
                (task->status == SCSI_STATUS_CHECK_CONDITION &&
                 task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
                 task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT);
        if (!ok) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT(ok);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size - 200);
        if (task->residual != block_size - 200) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size - 200, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size - 200);

        scsi_free_scsi_task(task);
        task = NULL;



        logging(LOG_VERBOSE, "Try writing two blocks but iSCSI expected "
                "transfer length==%zu (==one block)", block_size);
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 2;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);

        scsi_free_scsi_task(task);
        task = NULL;



        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL > SCSI TL then we only write SCSI TL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE16(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 2 * block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual underflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ16(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }


        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL < SCSI TL then we only write iSCSI EDTL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE16(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 2;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ16(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }
}
uint8_t ADMVideoSupSub::decode(uint32_t size, uint8_t *data)
{
  uint32_t odd,even,_subSize,_dataSize,next=0,date,command,dum;
  
  uint32_t _curOffset=0,doneA=0,doneB=0;
        odd=even=0;
        
        _subSize=(data[0]<<8)+data[1];
        if(!_subSize)
        {
            printf("Vobsub: error reading\n");
            return 0;
        }
        
        aprintf("Vobsub: data len =%d\n",_subSize);
        _curOffset=2;
        if(_subSize<4)
        {
          printf("[handleSub] Packet too short!\n");
          return 1; 
        }
        _dataSize=(data[2]<<8)+data[3];
        aprintf("data block=%lu\n",_dataSize);
        if(_dataSize<=4)
        {
            printf("Vobsub: data block too small\n");
            return 0;       
        }
        if(_dataSize-4>=_subSize)
        {
          printf("DataSize too large\n");
          return 0; 
        }
        _curOffset=_dataSize;
        while(2)
        {
                if(_curOffset>_subSize-5) break;
                date=READ16();
                next=READ16();
                if(next==_curOffset-4) break;            // end of command
                
                while(_curOffset<next)
                {
                      
                      
                        command=data[_curOffset++];
                        aprintf("vobsub:Command : %d date:%d next:%d cur:%lu\n",command,date,next,_curOffset);
                        int left=next-_curOffset;
                        switch(command)
                        {
                                case 00:
                                        break;
                                case 01: // start date
                                        break;
                                case 02: // stop date

                                        break;
                                case 03: // Pallette 4 nibble= 16 bits
                                         if(left<2)
                                         {
                                            printf("Command 3: Palette: Not enough bytes left\n");
                                            return 1; 
                                         }
                                         dum=READ16();
                                        _colors[0]=dum>>12;
                                        _colors[1]=0xf & (dum>>8);
                                        _colors[2]=0xf & (dum>>4);
                                        _colors[3]=0xf & (dum);
                                        printf("[SUP] Palette %x %x %x %x\n",_colors[0],_colors[1],_colors[2],_colors[3]);
                                        break;          
                                case 0xff:
                                        break;
                                case 04: // alpha channel
                                         //4 nibble= 16 bits
                                        if(left<2)
                                         {
                                            printf("Command 4: Alpha: Not enough bytes left\n");
                                            return 1; 
                                         }

                                        dum=READ16();
                                        _alpha[0]=dum>>12;
                                        _alpha[1]=0xf & (dum>>8);
                                        _alpha[2]=0xf & (dum>>4);
                                        _alpha[3]=0xf & (dum);
                                        printf("[SUP] Alpha %x %x %x %x\n",_alpha[0],_alpha[1],_alpha[2],_alpha[3]);
                                        break;
                                case 05:
                                        // Coordinates 12 bits per entry X1/X2/Y1/Y2
                                        // 48 bits total / 6 bytes
                                        {
                                                uint16_t a,b,c;
                                                uint32_t nx1,nx2,ny1,ny2;
                                                if(left<6)
                                                {
                                                    printf("Command 5: Coord: Not enough bytes left\n");
                                                    return 1; 
                                                }
                                                if(doneA) return 1;
                                                doneA++;
                                                a=READ16();
                                                b=READ16();
                                                c=READ16();
                                                nx1=a>>4;
                                                nx2=((a&0xf)<<8)+(b>>8);
                                                ny1=((b&0xf)<<4)+(c>>12);
                                                ny2=c&0xfff;
                                                
                                                aprintf("vobsuv: x1:%d x2:%d y1:%d y2:%d\n",nx1,nx2,ny1,ny2);
                                                
                                                if(bitmap && ((nx2+1-nx1)==bitmap->_width) && ((ny2+1-ny1)==bitmap->_height))
                                                {       // Reuse old bitmap
                                                        bitmap->clear();
                                                }
                                                else
                                                {
                                                  if(bitmap)
                                                        delete bitmap;
                                                  bitmap=NULL;
                                                  _subW=nx2+1-nx1;
                                                  _subH=ny2+1-ny1;
                                                  bitmap=new vobSubBitmap(_subW,_subH);
                                                }
                                                                        
                                        }
                                        break;
                                case 06: // RLE offset 
                                        // 2*16 bits : odd offset, even offset
                                        {
                                                if(doneB) return 1;
                                                doneB++;
                                                if(left<4)
                                                {
                                                    printf("Command 6: RLE: Not enough bytes left\n");
                                                    return 1; 
                                                }
                                                odd=READ16();
                                                even=READ16();
 
                                        }
                                        break;   
                                default:                                                     
                                        printf("Unknown command:%d\n",command);
                                        return 0;
                                  
                        } //End switch command     
                }// end while
        }
        /*****/
        if(bitmap && odd && even) 
        {
                bitmap->clear();
                decodeRLE(odd,0,even,data,_dataSize);
                decodeRLE(even,1,0,data,_dataSize);
        }
    return 1;
}
Beispiel #25
0
	H6280(config, m_maincpu, PCE_MAIN_CLOCK/3);
	m_maincpu->set_addrmap(AS_PROGRAM, &ggconnie_state::sgx_mem);
	m_maincpu->set_addrmap(AS_IO, &ggconnie_state::sgx_io);
	m_maincpu->port_in_cb().set_ioport("IN0");
	m_maincpu->port_out_cb().set(FUNC(ggconnie_state::lamp_w));
	m_maincpu->add_route(0, "lspeaker", 1.00);
	m_maincpu->add_route(1, "rspeaker", 1.00);

	/* video hardware */
	MCFG_SCREEN_ADD("screen", RASTER)
	MCFG_SCREEN_RAW_PARAMS(PCE_MAIN_CLOCK/3, huc6260_device::WPF, 64, 64 + 1024 + 64, huc6260_device::LPF, 18, 18 + 242)
	MCFG_SCREEN_UPDATE_DRIVER( ggconnie_state, screen_update )
	MCFG_SCREEN_PALETTE("huc6260")

	MCFG_DEVICE_ADD("huc6260", HUC6260, PCE_MAIN_CLOCK/3)
	MCFG_HUC6260_NEXT_PIXEL_DATA_CB(READ16("huc6202", huc6202_device, next_pixel))
	MCFG_HUC6260_TIME_TIL_NEXT_EVENT_CB(READ16("huc6202", huc6202_device, time_until_next_event))
	MCFG_HUC6260_VSYNC_CHANGED_CB(WRITELINE("huc6202", huc6202_device, vsync_changed))
	MCFG_HUC6260_HSYNC_CHANGED_CB(WRITELINE("huc6202", huc6202_device, hsync_changed))
	MCFG_DEVICE_ADD( "huc6270_0", HUC6270, 0 )
	MCFG_HUC6270_VRAM_SIZE(0x10000)
	MCFG_HUC6270_IRQ_CHANGED_CB(INPUTLINE("maincpu", 0))
	MCFG_DEVICE_ADD( "huc6270_1", HUC6270, 0 )
	MCFG_HUC6270_VRAM_SIZE(0x10000)
	MCFG_HUC6270_IRQ_CHANGED_CB(INPUTLINE("maincpu", 0))
	MCFG_DEVICE_ADD( "huc6202", HUC6202, 0 )
	MCFG_HUC6202_NEXT_PIXEL_0_CB(READ16("huc6270_0", huc6270_device, next_pixel))
	MCFG_HUC6202_TIME_TIL_NEXT_EVENT_0_CB(READ16("huc6270_0", huc6270_device, time_until_next_event))
	MCFG_HUC6202_VSYNC_CHANGED_0_CB(WRITELINE("huc6270_0", huc6270_device, vsync_changed))
	MCFG_HUC6202_HSYNC_CHANGED_0_CB(WRITELINE("huc6270_0", huc6270_device, hsync_changed))
	MCFG_HUC6202_READ_0_CB(READ8("huc6270_0", huc6270_device, read))
Beispiel #26
0
// many thanks to starkwong. He found the change of this bit in QQ2006
ReceivedQunIMJoinRequest::ReceivedQunIMJoinRequest(const unsigned short imType, const unsigned char * buf, const int len)
	: externalID(0),
	sender(0),
	type(0),
	message(""),
	commander(0),
	m_Code(0),
	m_CodeLen(0),
	m_Token(0),
	m_TokenLen(0)
{
	printf("ReceivedQunIMJoinRequest\n");
	for(int i=0; i<len; i++){
		if(!(i%8)) printf("\n%d: ", i);
		printf("%2x ", (uint8_t)buf[i]);
	}
	printf("\n\n");

	int pos=0;
	unsigned char exttype=0;
	externalID = ntohl(*(unsigned int*)buf);
	pos+=4;
	
	type = buf[pos++];


	switch(imType){
		case QQ_RECV_IM_ADDED_TO_QUN:
		case QQ_RECV_IM_DELETED_FROM_QUN:
			sender = READ32(buf+pos);
			pos+=4;
			exttype=buf[pos++];
			
			// LumaQQ disregard value of exttype(rootCause) when deal with QQ_RECV_IM_ADDED_TO_QUN
			// Values for exttype (For QQ_RECV_IM_DELETED_FROM_QUN, from LumaQQ Mac)
			// static const char kQQExitClusterDismissed = 0x01;
			// static const char kQQExitClusterActive = 0x02;
			// static const char kQQExitClusterPassive = 0x03;
			if(imType == QQ_RECV_IM_ADDED_TO_QUN || exttype == 3) {
				commander = READ32(buf+pos);
				pos+=4;
			}
			break;
		case QQ_RECV_IM_REQUEST_JOIN_QUN:
			sender = READ32(buf+pos);
			pos+=4;
			break;
		case QQ_RECV_IM_APPROVE_JOIN_QUN:
		case QQ_RECV_IM_REJECT_JOIN_QUN:
			commander = READ32(buf+pos);
			pos+=4;
			break;
		case QQ_RECV_IM_SET_QUN_ADMIN:
			commander = buf[pos++]; // just use the commander variable to save the action. 0:unset, 1:set
			sender = READ32(buf + pos); // sender is the persion which the action performed on
			pos += 4;
			pos++;// unknonw, probably the admin value of the above member
			break;
		case QQ_RECV_IM_CREATE_QUN:
		default:
			sender = READ32(buf+pos);
			pos+=4;
			break;
	}

	if(imType != QQ_RECV_IM_DELETED_FROM_QUN || exttype == 3){
		if(len == pos) {
			message = "";
			return;
		}
		unsigned length = (unsigned int)buf[pos++];
		char *msg = (char *)malloc((length+1) * sizeof(char));
		memcpy(msg, buf + pos, length);
		msg[length] = 0x00;
		message.assign(msg);
		free(msg);
		pos += length;
	}

	m_CodeLen = READ16(buf + pos);
	pos +=2;

	setCode(buf+pos, m_CodeLen);
	pos += m_CodeLen;

	if(imType == QQ_RECV_IM_REQUEST_JOIN_QUN){
		m_TokenLen = READ16(buf + pos);
		pos +=2;
	
		setToken(buf+pos, m_TokenLen);
		pos += m_TokenLen;
	}
}
Beispiel #27
0
static void I486OP(group0F01_16)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT16 address;
	UINT32 ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				}
				else
				{
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base & 0xffffff);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM16(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2) & 0xffffff;
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 4:			/* SMSW */
			{
				if( modrm >= 0xc0 ) {
					STORE_RM16(modrm, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm);
					WRITE16(cpustate,ea, cpustate->cr[0]);
					CYCLES(cpustate,CYCLES_SMSW_MEM);
				}
				break;
			}
		case 6:			/* LMSW */
			{
				// TODO: Check for protection fault
				UINT8 b;
				if( modrm >= 0xc0 ) {
					b = LOAD_RM8(modrm);
					CYCLES(cpustate,CYCLES_LMSW_REG);
				} else {
					ea = GetEA(cpustate,modrm);
					CYCLES(cpustate,CYCLES_LMSW_MEM);
				b = READ8(cpustate,ea);
				}
				cpustate->cr[0] &= ~0x03;
				cpustate->cr[0] |= b & 0x03;
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
void
test_extendedcopy_simple(void)
{
        int tgt_desc_len = 0, seg_desc_len = 0, offset = XCOPY_DESC_OFFSET;
        struct iscsi_data data;
        unsigned char *xcopybuf;
        unsigned int copied_blocks;
        unsigned char *buf1;
        unsigned char *buf2;


        copied_blocks = num_blocks / 2;
        if (copied_blocks > 2048)
                copied_blocks = 2048;
        buf1 = malloc(copied_blocks * block_size);
        buf2 = malloc(copied_blocks * block_size);

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE,
                "Test EXTENDED COPY of %u blocks from start of LUN to end of LUN",
                copied_blocks);

        CHECK_FOR_DATALOSS;

        logging(LOG_VERBOSE, "Write %u blocks of 'A' at LBA:0", copied_blocks);
        memset(buf1, 'A', copied_blocks * block_size);
        WRITE16(sd, 0, copied_blocks * block_size, block_size, 0, 0, 0, 0, 0,
                buf1, EXPECT_STATUS_GOOD);

        data.size = XCOPY_DESC_OFFSET +
                get_desc_len(IDENT_DESCR_TGT_DESCR) +
                get_desc_len(BLK_TO_BLK_SEG_DESCR);
        data.data = alloca(data.size);
        xcopybuf = data.data;
        memset(xcopybuf, 0, data.size);

        /* Initialize target descriptor list with one target descriptor */
        offset += populate_tgt_desc(xcopybuf+offset, IDENT_DESCR_TGT_DESCR,
                        LU_ID_TYPE_LUN, 0, 0, 0, 0, sd);
        tgt_desc_len = offset - XCOPY_DESC_OFFSET;

        /* Iniitialize segment descriptor list with one segment descriptor */
        offset += populate_seg_desc_b2b(xcopybuf+offset, 0, 0, 0, 0,
                        copied_blocks, 0, num_blocks - copied_blocks);
        seg_desc_len = offset - XCOPY_DESC_OFFSET - tgt_desc_len;

        /* Initialize the parameter list header */
        populate_param_header(xcopybuf, 1, 0, LIST_ID_USAGE_DISCARD, 0,
                        tgt_desc_len, seg_desc_len, 0);

        EXTENDEDCOPY(sd, &data, EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Read %u blocks from end of the LUN",
                copied_blocks);
        READ16(sd, NULL, num_blocks - copied_blocks, copied_blocks * block_size,
               block_size, 0, 0, 0, 0, 0, buf2,
               EXPECT_STATUS_GOOD);

        if (memcmp(buf1, buf2, copied_blocks * block_size)) {
                CU_FAIL("Blocks were not copied correctly");
        }
        
        free(buf1);
        free(buf2);
}
Beispiel #29
0
static void I486OP(group0F01_32)(i386_state *cpustate)		// Opcode 0x0f 01
{
	UINT8 modrm = FETCH(cpustate);
	UINT32 address, ea;

	switch( (modrm >> 3) & 0x7 )
	{
		case 0:			/* SGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->gdtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->gdtr.base);
				CYCLES(cpustate,CYCLES_SGDT);
				break;
			}
		case 1:			/* SIDT */
			{
				if (modrm >= 0xc0)
				{
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				}
				else
				{
					ea = GetEA(cpustate,modrm);
				}
				WRITE16(cpustate,ea, cpustate->idtr.limit);
				WRITE32(cpustate,ea + 2, cpustate->idtr.base);
				CYCLES(cpustate,CYCLES_SIDT);
				break;
			}
		case 2:			/* LGDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->gdtr.limit = READ16(cpustate,ea);
				cpustate->gdtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LGDT);
				break;
			}
		case 3:			/* LIDT */
			{
				if( modrm >= 0xc0 ) {
					address = LOAD_RM32(modrm);
					ea = i386_translate( cpustate, CS, address );
				} else {
					ea = GetEA(cpustate,modrm);
				}
				cpustate->idtr.limit = READ16(cpustate,ea);
				cpustate->idtr.base = READ32(cpustate,ea + 2);
				CYCLES(cpustate,CYCLES_LIDT);
				break;
			}
		case 7:			/* INVLPG */
			{
				// Nothing to do ?
				break;
			}
		default:
			fatalerror("i486: unimplemented opcode 0x0f 01 /%d at %08X", (modrm >> 3) & 0x7, cpustate->eip - 2);
			break;
	}
}
Beispiel #30
0
void
test_sanitize_reset(void)
{ 
        int ret;
        struct scsi_command_descriptor *cd;
        struct scsi_task *sanitize_task;
        struct scsi_task *rl_task;
        struct iscsi_data data;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test SANITIZE with Task/Lun/Target/Session reset");

        CHECK_FOR_SANITIZE;
        CHECK_FOR_DATALOSS;

        if (sd->iscsi_ctx == NULL) {
                const char *err = "[SKIPPED] This SANITIZE test is only "
                        "supported for iSCSI backends";
                logging(LOG_NORMAL, "%s", err);
                CU_PASS(err);
                return;
        }

        logging(LOG_VERBOSE, "Check that SANITIZE OVERWRITE will continue "
                "even after Task/Lun/Target/* reset.");
        cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
                                    SCSI_SANITIZE_OVERWRITE);
        if (cd == NULL) {
                logging(LOG_NORMAL, "[SKIPPED] SANITIZE OVERWRITE is not "
                        "implemented according to REPORT_SUPPORTED_OPCODES.");
                CU_PASS("SANITIZE is not implemented.");
                return;
        }

        logging(LOG_VERBOSE, "Send an asyncronous SANITIZE to the target.");
        data.size = block_size + 4;
        data.data = alloca(data.size);
        memset(&data.data[4], 0, block_size);

        data.data[0] = 0x01;
        data.data[1] = 0x00;
        data.data[2] = block_size >> 8;
        data.data[3] = block_size & 0xff;
        sanitize_task = iscsi_sanitize_task(sd->iscsi_ctx, sd->iscsi_lun,
                                            0, 0, SCSI_SANITIZE_OVERWRITE,
                                            data.size, &data,
                                            sanitize_cb, NULL);
        CU_ASSERT_NOT_EQUAL(sanitize_task, NULL);
        /* just send something so that we know the sanitize command is sent
         * to the target
         */
        rl_task = iscsi_reportluns_sync(sd->iscsi_ctx, 0, 64);
        if (rl_task) {
                scsi_free_scsi_task(rl_task);
        }


        logging(LOG_VERBOSE, "Sleep for three seconds incase the target is "
                "slow to start the SANITIZE");
        sleep(3);

        logging(LOG_VERBOSE, "Verify that the SANITIZE has started and that "
                "TESTUNITREADY fails with SANITIZE_IN_PROGRESS");
        TESTUNITREADY(sd,
                      EXPECT_SANITIZE);

        logging(LOG_VERBOSE, "Verify that STARTSTOPUNIT fails with "
                "SANITIZE_IN_PROGRESS");
        STARTSTOPUNIT(sd, 1, 0, 1, 0, 1, 0,
                      EXPECT_SANITIZE);

        logging(LOG_VERBOSE, "Verify that READ16 fails with "
                "SANITIZE_IN_PROGRESS");
        READ16(sd, NULL, 0, block_size,
               block_size, 0, 0, 0, 0, 0, NULL,
               EXPECT_SANITIZE);

        logging(LOG_VERBOSE, "Verify that INQUIRY is still allowed while "
                "SANITIZE is in progress");
        ret = inquiry(sd, NULL, 0, 0, 255,
                      EXPECT_STATUS_GOOD);
        CU_ASSERT_EQUAL(ret, 0);


        logging(LOG_VERBOSE, "Send an ABORT TASK");
        ret = iscsi_task_mgmt_abort_task_sync(sd->iscsi_ctx, sanitize_task);
        if (ret != 0) {
                logging(LOG_NORMAL, "ABORT TASK failed. %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }

        logging(LOG_VERBOSE, "Send an ABORT TASK SET");
        ret = iscsi_task_mgmt_abort_task_set_sync(sd->iscsi_ctx, sd->iscsi_lun);
        if (ret != 0) {
                logging(LOG_NORMAL, "ABORT TASK SET failed. %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }

        logging(LOG_VERBOSE, "Send a LUN Reset");
        ret = iscsi_task_mgmt_lun_reset_sync(sd->iscsi_ctx, sd->iscsi_lun);
        if (ret != 0) {
                logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(sd->iscsi_ctx));
        }

        logging(LOG_VERBOSE, "Send a Warm Reset");
        ret = iscsi_task_mgmt_target_warm_reset_sync(sd->iscsi_ctx);
        if (ret != 0) {
                logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(sd->iscsi_ctx));
        }

        logging(LOG_VERBOSE, "Send a Cold Reset");
        ret = iscsi_task_mgmt_target_cold_reset_sync(sd->iscsi_ctx);
        if (ret != 0) {
                logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(sd->iscsi_ctx));
        }

        logging(LOG_VERBOSE, "Disconnect from the target.");
        iscsi_destroy_context(sd->iscsi_ctx);

        logging(LOG_VERBOSE, "Sleep for one seconds incase the target is "
                "slow to reset");
        sleep(1);

        logging(LOG_VERBOSE, "Reconnect to target");
        sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun);
        if (sd->iscsi_ctx == NULL) {
                logging(LOG_VERBOSE, "Failed to login to target");
                return;
        }

        logging(LOG_VERBOSE, "Verify that the SANITIZE is still going.");
        TESTUNITREADY(sd,
                      EXPECT_SANITIZE);

        logging(LOG_VERBOSE, "Wait until the SANITIZE operation has finished");
        while (testunitready_clear_ua(sd)) {
                sleep(60);
        }
}