void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,

                  const char *boot_device,

                  BusState *idebus0, BusState *idebus1,

                  ISADevice *s)

{

    int val, nb, nb_heads, max_track, last_sect, i;

    FDriveType fd_type[2];

    DriveInfo *fd[2];

    static pc_cmos_init_late_arg arg;



    /* various important CMOS locations needed by PC/Bochs bios */



    /* memory size */

    val = 640; /* base memory in K */

    rtc_set_memory(s, 0x15, val);

    rtc_set_memory(s, 0x16, val >> 8);



    val = (ram_size / 1024) - 1024;

    if (val > 65535)

        val = 65535;

    rtc_set_memory(s, 0x17, val);

    rtc_set_memory(s, 0x18, val >> 8);

    rtc_set_memory(s, 0x30, val);

    rtc_set_memory(s, 0x31, val >> 8);



    if (above_4g_mem_size) {

        rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);

        rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);

        rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);

    }



    if (ram_size > (16 * 1024 * 1024))

        val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);

    else

        val = 0;

    if (val > 65535)

        val = 65535;

    rtc_set_memory(s, 0x34, val);

    rtc_set_memory(s, 0x35, val >> 8);



    /* set the number of CPU */

    rtc_set_memory(s, 0x5f, smp_cpus - 1);



    /* set boot devices, and disable floppy signature check if requested */

    if (set_boot_dev(s, boot_device, fd_bootchk)) {

        exit(1);

    }



    /* floppy type */

    for (i = 0; i < 2; i++) {

        fd[i] = drive_get(IF_FLOPPY, 0, i);

        if (fd[i]) {

            bdrv_get_floppy_geometry_hint(fd[i]->bdrv, &nb_heads, &max_track,

                                          &last_sect, FDRIVE_DRV_NONE,

                                          &fd_type[i]);

        } else {

            fd_type[i] = FDRIVE_DRV_NONE;

        }

    }

    val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |

        cmos_get_fd_drive_type(fd_type[1]);

    rtc_set_memory(s, 0x10, val);



    val = 0;

    nb = 0;

    if (fd_type[0] < FDRIVE_DRV_NONE) {

        nb++;

    }

    if (fd_type[1] < FDRIVE_DRV_NONE) {

        nb++;

    }

    switch (nb) {

    case 0:

        break;

    case 1:

        val |= 0x01; /* 1 drive, ready for boot */

        break;

    case 2:

        val |= 0x41; /* 2 drives, ready for boot */

        break;

    }

    val |= 0x02; /* FPU is there */

    val |= 0x04; /* PS/2 mouse installed */

    rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);



    /* hard drives */

    arg.rtc_state = s;

    arg.idebus0 = idebus0;

    arg.idebus1 = idebus1;

    qemu_register_reset(pc_cmos_init_late, &arg);

}

void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,

                  const char *boot_device,

                  BusState *idebus0, BusState *idebus1,

                  ISADevice *s)

{

    int val, nb, nb_heads, max_track, last_sect, i;

    FDriveType fd_type[2];

    DriveInfo *fd[2];

    static pc_cmos_init_late_arg arg;



    



    

    val = 640; 

    rtc_set_memory(s, 0x15, val);

    rtc_set_memory(s, 0x16, val >> 8);



    val = (ram_size / 1024) - 1024;

    if (val > 65535)

        val = 65535;

    rtc_set_memory(s, 0x17, val);

    rtc_set_memory(s, 0x18, val >> 8);

    rtc_set_memory(s, 0x30, val);

    rtc_set_memory(s, 0x31, val >> 8);



    if (above_4g_mem_size) {

        rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);

        rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);

        rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);

    }



    if (ram_size > (16 * 1024 * 1024))

        val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);

    else

        val = 0;

    if (val > 65535)

        val = 65535;

    rtc_set_memory(s, 0x34, val);

    rtc_set_memory(s, 0x35, val >> 8);



    

    rtc_set_memory(s, 0x5f, smp_cpus - 1);



    

    if (set_boot_dev(s, boot_device, fd_bootchk)) {

        exit(1);

    }



    

    for (i = 0; i < 2; i++) {

        fd[i] = drive_get(IF_FLOPPY, 0, i);

        if (fd[i]) {

            bdrv_get_floppy_geometry_hint(fd[i]->bdrv, &nb_heads, &max_track,

                                          &last_sect, FDRIVE_DRV_NONE,

                                          &fd_type[i]);

        } else {

            fd_type[i] = FDRIVE_DRV_NONE;

        }

    }

    val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |

        cmos_get_fd_drive_type(fd_type[1]);

    rtc_set_memory(s, 0x10, val);



    val = 0;

    nb = 0;

    if (fd_type[0] < FDRIVE_DRV_NONE) {

        nb++;

    }

    if (fd_type[1] < FDRIVE_DRV_NONE) {

        nb++;

    }

    switch (nb) {

    case 0:

        break;

    case 1:

        val |= 0x01; 

        break;

    case 2:

        val |= 0x41; 

        break;

    }

    val |= 0x02; 

    val |= 0x04; 

    rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);



    

    arg.rtc_state = s;

    arg.idebus0 = idebus0;

    arg.idebus1 = idebus1;

    qemu_register_reset(pc_cmos_init_late, &arg);

}

void FUNC_0(ram_addr_t VAR_0, ram_addr_t VAR_1,

                  const char *VAR_2,

                  BusState *VAR_3, BusState *VAR_4,

                  ISADevice *VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    FDriveType fd_type[2];

    DriveInfo *fd[2];

    static pc_cmos_init_late_arg VAR_12;



    



    

    VAR_6 = 640; 

    rtc_set_memory(VAR_5, 0x15, VAR_6);

    rtc_set_memory(VAR_5, 0x16, VAR_6 >> 8);



    VAR_6 = (VAR_0 / 1024) - 1024;

    if (VAR_6 > 65535)

        VAR_6 = 65535;

    rtc_set_memory(VAR_5, 0x17, VAR_6);

    rtc_set_memory(VAR_5, 0x18, VAR_6 >> 8);

    rtc_set_memory(VAR_5, 0x30, VAR_6);

    rtc_set_memory(VAR_5, 0x31, VAR_6 >> 8);



    if (VAR_1) {

        rtc_set_memory(VAR_5, 0x5b, (unsigned int)VAR_1 >> 16);

        rtc_set_memory(VAR_5, 0x5c, (unsigned int)VAR_1 >> 24);

        rtc_set_memory(VAR_5, 0x5d, (uint64_t)VAR_1 >> 32);

    }



    if (VAR_0 > (16 * 1024 * 1024))

        VAR_6 = (VAR_0 / 65536) - ((16 * 1024 * 1024) / 65536);

    else

        VAR_6 = 0;

    if (VAR_6 > 65535)

        VAR_6 = 65535;

    rtc_set_memory(VAR_5, 0x34, VAR_6);

    rtc_set_memory(VAR_5, 0x35, VAR_6 >> 8);



    

    rtc_set_memory(VAR_5, 0x5f, smp_cpus - 1);



    

    if (set_boot_dev(VAR_5, VAR_2, fd_bootchk)) {

        exit(1);

    }



    

    for (VAR_11 = 0; VAR_11 < 2; VAR_11++) {

        fd[VAR_11] = drive_get(IF_FLOPPY, 0, VAR_11);

        if (fd[VAR_11]) {

            bdrv_get_floppy_geometry_hint(fd[VAR_11]->bdrv, &VAR_8, &VAR_9,

                                          &VAR_10, FDRIVE_DRV_NONE,

                                          &fd_type[VAR_11]);

        } else {

            fd_type[VAR_11] = FDRIVE_DRV_NONE;

        }

    }

    VAR_6 = (cmos_get_fd_drive_type(fd_type[0]) << 4) |

        cmos_get_fd_drive_type(fd_type[1]);

    rtc_set_memory(VAR_5, 0x10, VAR_6);



    VAR_6 = 0;

    VAR_7 = 0;

    if (fd_type[0] < FDRIVE_DRV_NONE) {

        VAR_7++;

    }

    if (fd_type[1] < FDRIVE_DRV_NONE) {

        VAR_7++;

    }

    switch (VAR_7) {

    case 0:

        break;

    case 1:

        VAR_6 |= 0x01; 

        break;

    case 2:

        VAR_6 |= 0x41; 

        break;

    }

    VAR_6 |= 0x02; 

    VAR_6 |= 0x04; 

    rtc_set_memory(VAR_5, REG_EQUIPMENT_BYTE, VAR_6);



    

    VAR_12.rtc_state = VAR_5;

    VAR_12.VAR_3 = VAR_3;

    VAR_12.VAR_4 = VAR_4;

    qemu_register_reset(pc_cmos_init_late, &VAR_12);

}

void FUNC_0(ram_addr_t VAR_0, ram_addr_t VAR_1,
const char *VAR_2,
BusState *VAR_3, BusState *VAR_4,
ISADevice *VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; FDriveType fd_type[2]; DriveInfo *fd[2]; static pc_cmos_init_late_arg VAR_12; VAR_6 = 640; rtc_set_memory(VAR_5, 0x15, VAR_6); rtc_set_memory(VAR_5, 0x16, VAR_6 >> 8); VAR_6 = (VAR_0 / 1024) - 1024; if (VAR_6 > 65535)
VAR_6 = 65535; rtc_set_memory(VAR_5, 0x17, VAR_6); rtc_set_memory(VAR_5, 0x18, VAR_6 >> 8); rtc_set_memory(VAR_5, 0x30, VAR_6); rtc_set_memory(VAR_5, 0x31, VAR_6 >> 8); if (VAR_1) { rtc_set_memory(VAR_5, 0x5b, (unsigned int)VAR_1 >> 16); rtc_set_memory(VAR_5, 0x5c, (unsigned int)VAR_1 >> 24); rtc_set_memory(VAR_5, 0x5d, (uint64_t)VAR_1 >> 32); } if (VAR_0 > (16 * 1024 * 1024))
VAR_6 = (VAR_0 / 65536) - ((16 * 1024 * 1024) / 65536); else
VAR_6 = 0; if (VAR_6 > 65535)
VAR_6 = 65535; rtc_set_memory(VAR_5, 0x34, VAR_6); rtc_set_memory(VAR_5, 0x35, VAR_6 >> 8); rtc_set_memory(VAR_5, 0x5f, smp_cpus - 1); if (set_boot_dev(VAR_5, VAR_2, fd_bootchk)) { exit(1); } for (VAR_11 = 0; VAR_11 < 2; VAR_11++) { fd[VAR_11] = drive_get(IF_FLOPPY, 0, VAR_11); if (fd[VAR_11]) { bdrv_get_floppy_geometry_hint(fd[VAR_11]->bdrv, &VAR_8, &VAR_9,
&VAR_10, FDRIVE_DRV_NONE,
&fd_type[VAR_11]); } else { fd_type[VAR_11] = FDRIVE_DRV_NONE; } } VAR_6 = (cmos_get_fd_drive_type(fd_type[0]) << 4) |
cmos_get_fd_drive_type(fd_type[1]); rtc_set_memory(VAR_5, 0x10, VAR_6); VAR_6 = 0; VAR_7 = 0; if (fd_type[0] < FDRIVE_DRV_NONE) { VAR_7++; } if (fd_type[1] < FDRIVE_DRV_NONE) { VAR_7++; } switch (VAR_7) { case 0:
break; case 1:
VAR_6 |= 0x01; break; case 2:
VAR_6 |= 0x41; break; } VAR_6 |= 0x02; VAR_6 |= 0x04; rtc_set_memory(VAR_5, REG_EQUIPMENT_BYTE, VAR_6); VAR_12.rtc_state = VAR_5; VAR_12.VAR_3 = VAR_3; VAR_12.VAR_4 = VAR_4; qemu_register_reset(pc_cmos_init_late, &VAR_12); }