static void rtas_nvram_fetch(sPAPREnvironment *spapr,

                             uint32_t token, uint32_t nargs,

                             target_ulong args,

                             uint32_t nret, target_ulong rets)

{

    sPAPRNVRAM *nvram = spapr->nvram;

    hwaddr offset, buffer, len;

    int alen;

    void *membuf;



    if ((nargs != 3) || (nret != 2)) {

        rtas_st(rets, 0, -3);

        return;

    }



    if (!nvram) {

        rtas_st(rets, 0, -1);

        rtas_st(rets, 1, 0);

        return;

    }



    offset = rtas_ld(args, 0);

    buffer = rtas_ld(args, 1);

    len = rtas_ld(args, 2);



    if (((offset + len) < offset)

        || ((offset + len) > nvram->size)) {

        rtas_st(rets, 0, -3);

        rtas_st(rets, 1, 0);

        return;

    }



    membuf = cpu_physical_memory_map(buffer, &len, 1);

    if (nvram->drive) {

        alen = bdrv_pread(nvram->drive, offset, membuf, len);

    } else {

        assert(nvram->buf);



        memcpy(membuf, nvram->buf + offset, len);

        alen = len;

    }

    cpu_physical_memory_unmap(membuf, len, 1, len);



    rtas_st(rets, 0, (alen < len) ? -1 : 0);

    rtas_st(rets, 1, (alen < 0) ? 0 : alen);

}

static void rtas_nvram_fetch(sPAPREnvironment *spapr,

                             uint32_t token, uint32_t nargs,

                             target_ulong args,

                             uint32_t nret, target_ulong rets)

{

    sPAPRNVRAM *nvram = spapr->nvram;

    hwaddr offset, buffer, len;

    int alen;

    void *membuf;



    if ((nargs != 3) || (nret != 2)) {

        rtas_st(rets, 0, -3);

        return;

    }



    if (!nvram) {

        rtas_st(rets, 0, -1);

        rtas_st(rets, 1, 0);

        return;

    }



    offset = rtas_ld(args, 0);

    buffer = rtas_ld(args, 1);

    len = rtas_ld(args, 2);



    if (((offset + len) < offset)

        || ((offset + len) > nvram->size)) {

        rtas_st(rets, 0, -3);

        rtas_st(rets, 1, 0);

        return;

    }



    membuf = cpu_physical_memory_map(buffer, &len, 1);

    if (nvram->drive) {

        alen = bdrv_pread(nvram->drive, offset, membuf, len);

    } else {

        assert(nvram->buf);



        memcpy(membuf, nvram->buf + offset, len);

        alen = len;

    }

    cpu_physical_memory_unmap(membuf, len, 1, len);



    rtas_st(rets, 0, (alen < len) ? -1 : 0);

    rtas_st(rets, 1, (alen < 0) ? 0 : alen);

}

static void FUNC_0(sPAPREnvironment *VAR_0,

                             uint32_t VAR_1, uint32_t VAR_2,

                             target_ulong VAR_3,

                             uint32_t VAR_4, target_ulong VAR_5)

{

    sPAPRNVRAM *nvram = VAR_0->nvram;

    hwaddr offset, buffer, len;

    int VAR_6;

    void *VAR_7;



    if ((VAR_2 != 3) || (VAR_4 != 2)) {

        rtas_st(VAR_5, 0, -3);

        return;

    }



    if (!nvram) {

        rtas_st(VAR_5, 0, -1);

        rtas_st(VAR_5, 1, 0);

        return;

    }



    offset = rtas_ld(VAR_3, 0);

    buffer = rtas_ld(VAR_3, 1);

    len = rtas_ld(VAR_3, 2);



    if (((offset + len) < offset)

        || ((offset + len) > nvram->size)) {

        rtas_st(VAR_5, 0, -3);

        rtas_st(VAR_5, 1, 0);

        return;

    }



    VAR_7 = cpu_physical_memory_map(buffer, &len, 1);

    if (nvram->drive) {

        VAR_6 = bdrv_pread(nvram->drive, offset, VAR_7, len);

    } else {

        assert(nvram->buf);



        memcpy(VAR_7, nvram->buf + offset, len);

        VAR_6 = len;

    }

    cpu_physical_memory_unmap(VAR_7, len, 1, len);



    rtas_st(VAR_5, 0, (VAR_6 < len) ? -1 : 0);

    rtas_st(VAR_5, 1, (VAR_6 < 0) ? 0 : VAR_6);

}

static void FUNC_0(sPAPREnvironment *VAR_0,
uint32_t VAR_1, uint32_t VAR_2,
target_ulong VAR_3,
uint32_t VAR_4, target_ulong VAR_5)
{ sPAPRNVRAM *nvram = VAR_0->nvram; hwaddr offset, buffer, len; int VAR_6; void *VAR_7; if ((VAR_2 != 3) || (VAR_4 != 2)) { rtas_st(VAR_5, 0, -3); return; } if (!nvram) { rtas_st(VAR_5, 0, -1); rtas_st(VAR_5, 1, 0); return; } offset = rtas_ld(VAR_3, 0); buffer = rtas_ld(VAR_3, 1); len = rtas_ld(VAR_3, 2); if (((offset + len) < offset)
|| ((offset + len) > nvram->size)) { rtas_st(VAR_5, 0, -3); rtas_st(VAR_5, 1, 0); return; } VAR_7 = cpu_physical_memory_map(buffer, &len, 1); if (nvram->drive) { VAR_6 = bdrv_pread(nvram->drive, offset, VAR_7, len); } else { assert(nvram->buf); memcpy(VAR_7, nvram->buf + offset, len); VAR_6 = len; } cpu_physical_memory_unmap(VAR_7, len, 1, len); rtas_st(VAR_5, 0, (VAR_6 < len) ? -1 : 0); rtas_st(VAR_5, 1, (VAR_6 < 0) ? 0 : VAR_6); }