static void cmd_read_toc_pma_atip(IDEState *s, uint8_t* buf)

{

    int format, msf, start_track, len;

    uint64_t total_sectors = s->nb_sectors >> 2;

    int max_len;



    if (total_sectors == 0) {

        ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);

        return;

    }



    max_len = ube16_to_cpu(buf + 7);

    format = buf[9] >> 6;

    msf = (buf[1] >> 1) & 1;

    start_track = buf[6];



    switch(format) {

    case 0:

        len = cdrom_read_toc(total_sectors, buf, msf, start_track);

        if (len < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(s, len, max_len);

        break;

    case 1:

        /* multi session : only a single session defined */

        memset(buf, 0, 12);

        buf[1] = 0x0a;

        buf[2] = 0x01;

        buf[3] = 0x01;

        ide_atapi_cmd_reply(s, 12, max_len);

        break;

    case 2:

        len = cdrom_read_toc_raw(total_sectors, buf, msf, start_track);

        if (len < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(s, len, max_len);

        break;

    default:

    error_cmd:

        ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,

                            ASC_INV_FIELD_IN_CMD_PACKET);

    }

}

static void cmd_read_toc_pma_atip(IDEState *s, uint8_t* buf)

{

    int format, msf, start_track, len;

    uint64_t total_sectors = s->nb_sectors >> 2;

    int max_len;



    if (total_sectors == 0) {

        ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);

        return;

    }



    max_len = ube16_to_cpu(buf + 7);

    format = buf[9] >> 6;

    msf = (buf[1] >> 1) & 1;

    start_track = buf[6];



    switch(format) {

    case 0:

        len = cdrom_read_toc(total_sectors, buf, msf, start_track);

        if (len < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(s, len, max_len);

        break;

    case 1:

        

        memset(buf, 0, 12);

        buf[1] = 0x0a;

        buf[2] = 0x01;

        buf[3] = 0x01;

        ide_atapi_cmd_reply(s, 12, max_len);

        break;

    case 2:

        len = cdrom_read_toc_raw(total_sectors, buf, msf, start_track);

        if (len < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(s, len, max_len);

        break;

    default:

    error_cmd:

        ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,

                            ASC_INV_FIELD_IN_CMD_PACKET);

    }

}

static void FUNC_0(IDEState *VAR_0, uint8_t* VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5;

    uint64_t total_sectors = VAR_0->nb_sectors >> 2;

    int VAR_6;



    if (total_sectors == 0) {

        ide_atapi_cmd_error(VAR_0, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);

        return;

    }



    VAR_6 = ube16_to_cpu(VAR_1 + 7);

    VAR_2 = VAR_1[9] >> 6;

    VAR_3 = (VAR_1[1] >> 1) & 1;

    VAR_4 = VAR_1[6];



    switch(VAR_2) {

    case 0:

        VAR_5 = cdrom_read_toc(total_sectors, VAR_1, VAR_3, VAR_4);

        if (VAR_5 < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(VAR_0, VAR_5, VAR_6);

        break;

    case 1:

        

        memset(VAR_1, 0, 12);

        VAR_1[1] = 0x0a;

        VAR_1[2] = 0x01;

        VAR_1[3] = 0x01;

        ide_atapi_cmd_reply(VAR_0, 12, VAR_6);

        break;

    case 2:

        VAR_5 = cdrom_read_toc_raw(total_sectors, VAR_1, VAR_3, VAR_4);

        if (VAR_5 < 0)

            goto error_cmd;

        ide_atapi_cmd_reply(VAR_0, VAR_5, VAR_6);

        break;

    default:

    error_cmd:

        ide_atapi_cmd_error(VAR_0, SENSE_ILLEGAL_REQUEST,

                            ASC_INV_FIELD_IN_CMD_PACKET);

    }

}

static void FUNC_0(IDEState *VAR_0, uint8_t* VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5; uint64_t total_sectors = VAR_0->nb_sectors >> 2; int VAR_6; if (total_sectors == 0) { ide_atapi_cmd_error(VAR_0, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); return; } VAR_6 = ube16_to_cpu(VAR_1 + 7); VAR_2 = VAR_1[9] >> 6; VAR_3 = (VAR_1[1] >> 1) & 1; VAR_4 = VAR_1[6]; switch(VAR_2) { case 0:
VAR_5 = cdrom_read_toc(total_sectors, VAR_1, VAR_3, VAR_4); if (VAR_5 < 0)
goto error_cmd; ide_atapi_cmd_reply(VAR_0, VAR_5, VAR_6); break; case 1:
memset(VAR_1, 0, 12); VAR_1[1] = 0x0a; VAR_1[2] = 0x01; VAR_1[3] = 0x01; ide_atapi_cmd_reply(VAR_0, 12, VAR_6); break; case 2:
VAR_5 = cdrom_read_toc_raw(total_sectors, VAR_1, VAR_3, VAR_4); if (VAR_5 < 0)
goto error_cmd; ide_atapi_cmd_reply(VAR_0, VAR_5, VAR_6); break; default:
error_cmd:
ide_atapi_cmd_error(VAR_0, SENSE_ILLEGAL_REQUEST,
ASC_INV_FIELD_IN_CMD_PACKET); } }