static int dma_buf_rw(BMDMAState *bm, int is_write)

{

    IDEState *s = bmdma_active_if(bm);

    struct {

        uint32_t addr;

        uint32_t size;

    } prd;

    int l, len;



    for(;;) {

        l = s->io_buffer_size - s->io_buffer_index;

        if (l <= 0)

            break;

        if (bm->cur_prd_len == 0) {

            /* end of table (with a fail safe of one page) */

            if (bm->cur_prd_last ||

                (bm->cur_addr - bm->addr) >= 4096)

                return 0;

            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);

            bm->cur_addr += 8;

            prd.addr = le32_to_cpu(prd.addr);

            prd.size = le32_to_cpu(prd.size);

            len = prd.size & 0xfffe;

            if (len == 0)

                len = 0x10000;

            bm->cur_prd_len = len;

            bm->cur_prd_addr = prd.addr;

            bm->cur_prd_last = (prd.size & 0x80000000);

        }

        if (l > bm->cur_prd_len)

            l = bm->cur_prd_len;

        if (l > 0) {

            if (is_write) {

                cpu_physical_memory_write(bm->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, l);

            } else {

                cpu_physical_memory_read(bm->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, l);

            }

            bm->cur_prd_addr += l;

            bm->cur_prd_len -= l;

            s->io_buffer_index += l;

        }

    }

    return 1;

}

static int dma_buf_rw(BMDMAState *bm, int is_write)

{

    IDEState *s = bmdma_active_if(bm);

    struct {

        uint32_t addr;

        uint32_t size;

    } prd;

    int l, len;



    for(;;) {

        l = s->io_buffer_size - s->io_buffer_index;

        if (l <= 0)

            break;

        if (bm->cur_prd_len == 0) {

            

            if (bm->cur_prd_last ||

                (bm->cur_addr - bm->addr) >= 4096)

                return 0;

            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);

            bm->cur_addr += 8;

            prd.addr = le32_to_cpu(prd.addr);

            prd.size = le32_to_cpu(prd.size);

            len = prd.size & 0xfffe;

            if (len == 0)

                len = 0x10000;

            bm->cur_prd_len = len;

            bm->cur_prd_addr = prd.addr;

            bm->cur_prd_last = (prd.size & 0x80000000);

        }

        if (l > bm->cur_prd_len)

            l = bm->cur_prd_len;

        if (l > 0) {

            if (is_write) {

                cpu_physical_memory_write(bm->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, l);

            } else {

                cpu_physical_memory_read(bm->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, l);

            }

            bm->cur_prd_addr += l;

            bm->cur_prd_len -= l;

            s->io_buffer_index += l;

        }

    }

    return 1;

}

static int FUNC_0(BMDMAState *VAR_0, int VAR_1)

{

    IDEState *s = bmdma_active_if(VAR_0);

    struct {

        uint32_t addr;

        uint32_t size;

    } VAR_2;

    int VAR_3, VAR_4;



    for(;;) {

        VAR_3 = s->io_buffer_size - s->io_buffer_index;

        if (VAR_3 <= 0)

            break;

        if (VAR_0->cur_prd_len == 0) {

            

            if (VAR_0->cur_prd_last ||

                (VAR_0->cur_addr - VAR_0->addr) >= 4096)

                return 0;

            cpu_physical_memory_read(VAR_0->cur_addr, (uint8_t *)&VAR_2, 8);

            VAR_0->cur_addr += 8;

            VAR_2.addr = le32_to_cpu(VAR_2.addr);

            VAR_2.size = le32_to_cpu(VAR_2.size);

            VAR_4 = VAR_2.size & 0xfffe;

            if (VAR_4 == 0)

                VAR_4 = 0x10000;

            VAR_0->cur_prd_len = VAR_4;

            VAR_0->cur_prd_addr = VAR_2.addr;

            VAR_0->cur_prd_last = (VAR_2.size & 0x80000000);

        }

        if (VAR_3 > VAR_0->cur_prd_len)

            VAR_3 = VAR_0->cur_prd_len;

        if (VAR_3 > 0) {

            if (VAR_1) {

                cpu_physical_memory_write(VAR_0->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, VAR_3);

            } else {

                cpu_physical_memory_read(VAR_0->cur_prd_addr,

                                          s->io_buffer + s->io_buffer_index, VAR_3);

            }

            VAR_0->cur_prd_addr += VAR_3;

            VAR_0->cur_prd_len -= VAR_3;

            s->io_buffer_index += VAR_3;

        }

    }

    return 1;

}

static int FUNC_0(BMDMAState *VAR_0, int VAR_1)
{ IDEState *s = bmdma_active_if(VAR_0); struct { uint32_t addr; uint32_t size; } VAR_2; int VAR_3, VAR_4; for(;;) { VAR_3 = s->io_buffer_size - s->io_buffer_index; if (VAR_3 <= 0)
break; if (VAR_0->cur_prd_len == 0) { if (VAR_0->cur_prd_last ||
(VAR_0->cur_addr - VAR_0->addr) >= 4096)
return 0; cpu_physical_memory_read(VAR_0->cur_addr, (uint8_t *)&VAR_2, 8); VAR_0->cur_addr += 8; VAR_2.addr = le32_to_cpu(VAR_2.addr); VAR_2.size = le32_to_cpu(VAR_2.size); VAR_4 = VAR_2.size & 0xfffe; if (VAR_4 == 0)
VAR_4 = 0x10000; VAR_0->cur_prd_len = VAR_4; VAR_0->cur_prd_addr = VAR_2.addr; VAR_0->cur_prd_last = (VAR_2.size & 0x80000000); } if (VAR_3 > VAR_0->cur_prd_len)
VAR_3 = VAR_0->cur_prd_len; if (VAR_3 > 0) { if (VAR_1) { cpu_physical_memory_write(VAR_0->cur_prd_addr,
s->io_buffer + s->io_buffer_index, VAR_3); } else { cpu_physical_memory_read(VAR_0->cur_prd_addr,
s->io_buffer + s->io_buffer_index, VAR_3); } VAR_0->cur_prd_addr += VAR_3; VAR_0->cur_prd_len -= VAR_3; s->io_buffer_index += VAR_3; } } return 1; }