static void sd_reset(SDState *sd, BlockDriverState *bdrv)

{

    uint64_t size;

    uint64_t sect;



    if (bdrv) {

        bdrv_get_geometry(bdrv, &sect);

    } else {

        sect = 0;

    }

    sect <<= 9;



    size = sect + 1;



    sect = (size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)) + 1;



    sd->state = sd_idle_state;

    sd->rca = 0x0000;

    sd_set_ocr(sd);

    sd_set_scr(sd);

    sd_set_cid(sd);

    sd_set_csd(sd, size);

    sd_set_cardstatus(sd);

    sd_set_sdstatus(sd);



    sd->bdrv = bdrv;



    if (sd->wp_groups)

        qemu_free(sd->wp_groups);

    sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0;

    sd->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect);

    memset(sd->function_group, 0, sizeof(int) * 6);

    sd->erase_start = 0;

    sd->erase_end = 0;

    sd->size = size;

    sd->blk_len = 0x200;

    sd->pwd_len = 0;

}

static void sd_reset(SDState *sd, BlockDriverState *bdrv)

{

    uint64_t size;

    uint64_t sect;



    if (bdrv) {

        bdrv_get_geometry(bdrv, &sect);

    } else {

        sect = 0;

    }

    sect <<= 9;



    size = sect + 1;



    sect = (size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)) + 1;



    sd->state = sd_idle_state;

    sd->rca = 0x0000;

    sd_set_ocr(sd);

    sd_set_scr(sd);

    sd_set_cid(sd);

    sd_set_csd(sd, size);

    sd_set_cardstatus(sd);

    sd_set_sdstatus(sd);



    sd->bdrv = bdrv;



    if (sd->wp_groups)

        qemu_free(sd->wp_groups);

    sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0;

    sd->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect);

    memset(sd->function_group, 0, sizeof(int) * 6);

    sd->erase_start = 0;

    sd->erase_end = 0;

    sd->size = size;

    sd->blk_len = 0x200;

    sd->pwd_len = 0;

}

    sect <<= 9;     size = sect + 1;
static void FUNC_0(SDState *VAR_0, BlockDriverState *VAR_1)

{

    uint64_t size;

    uint64_t sect;



    if (VAR_1) {

        bdrv_get_geometry(VAR_1, &sect);

    } else {

        sect = 0;

    }

    sect <<= 9;



    size = sect + 1;



    sect = (size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)) + 1;



    VAR_0->state = sd_idle_state;

    VAR_0->rca = 0x0000;

    sd_set_ocr(VAR_0);

    sd_set_scr(VAR_0);

    sd_set_cid(VAR_0);

    sd_set_csd(VAR_0, size);

    sd_set_cardstatus(VAR_0);

    sd_set_sdstatus(VAR_0);



    VAR_0->VAR_1 = VAR_1;



    if (VAR_0->wp_groups)

        qemu_free(VAR_0->wp_groups);

    VAR_0->wp_switch = VAR_1 ? bdrv_is_read_only(VAR_1) : 0;

    VAR_0->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect);

    memset(VAR_0->function_group, 0, sizeof(int) * 6);

    VAR_0->erase_start = 0;

    VAR_0->erase_end = 0;

    VAR_0->size = size;

    VAR_0->blk_len = 0x200;

    VAR_0->pwd_len = 0;

}

static void FUNC_0(SDState *VAR_0, BlockDriverState *VAR_1)
{ uint64_t size; uint64_t sect; if (VAR_1) { bdrv_get_geometry(VAR_1, &sect); } else { sect = 0; } sect <<= 9; size = sect + 1; sect = (size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)) + 1; VAR_0->state = sd_idle_state; VAR_0->rca = 0x0000; sd_set_ocr(VAR_0); sd_set_scr(VAR_0); sd_set_cid(VAR_0); sd_set_csd(VAR_0, size); sd_set_cardstatus(VAR_0); sd_set_sdstatus(VAR_0); VAR_0->VAR_1 = VAR_1; if (VAR_0->wp_groups)
qemu_free(VAR_0->wp_groups); VAR_0->wp_switch = VAR_1 ? bdrv_is_read_only(VAR_1) : 0; VAR_0->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect); memset(VAR_0->function_group, 0, sizeof(int) * 6); VAR_0->erase_start = 0; VAR_0->erase_end = 0; VAR_0->size = size; VAR_0->blk_len = 0x200; VAR_0->pwd_len = 0; }