static void cmos_init(int ram_size, const char *boot_device, BlockDriverState **hd_table)

{

    RTCState *s = rtc_state;

    int val;

    int fd0, fd1, nb;

    int i;



    /* 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 (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 boot devices, and disable floppy signature check if requested */

    rtc_set_memory(s, 0x3d,

            boot_device2nibble(boot_device[1]) << 4 |

            boot_device2nibble(boot_device[0]) );

    rtc_set_memory(s, 0x38,

            boot_device2nibble(boot_device[2]) << 4 | (fd_bootchk ?  0x0 : 0x1));



    /* floppy type */



    fd0 = fdctrl_get_drive_type(floppy_controller, 0);

    fd1 = fdctrl_get_drive_type(floppy_controller, 1);



    val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);

    rtc_set_memory(s, 0x10, val);



    val = 0;

    nb = 0;

    if (fd0 < 3)

        nb++;

    if (fd1 < 3)

        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 */



    rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));

    if (hd_table[0])

        cmos_init_hd(0x19, 0x1b, hd_table[0]);

    if (hd_table[1])

        cmos_init_hd(0x1a, 0x24, hd_table[1]);



    val = 0;

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

        if (hd_table[i]) {

            int cylinders, heads, sectors, translation;

            /* NOTE: bdrv_get_geometry_hint() returns the physical

                geometry.  It is always such that: 1 <= sects <= 63, 1

                <= heads <= 16, 1 <= cylinders <= 16383. The BIOS

                geometry can be different if a translation is done. */

            translation = bdrv_get_translation_hint(hd_table[i]);

            if (translation == BIOS_ATA_TRANSLATION_AUTO) {

                bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, &sectors);

                if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {

                    /* No translation. */

                    translation = 0;

                } else {

                    /* LBA translation. */

                    translation = 1;

                }

            } else {

                translation--;

            }

            val |= translation << (i * 2);

        }

    }

    rtc_set_memory(s, 0x39, val);

}

static void cmos_init(int ram_size, const char *boot_device, BlockDriverState **hd_table)

{

    RTCState *s = rtc_state;

    int val;

    int fd0, fd1, nb;

    int i;



    



    

    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 (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, 0x3d,

            boot_device2nibble(boot_device[1]) << 4 |

            boot_device2nibble(boot_device[0]) );

    rtc_set_memory(s, 0x38,

            boot_device2nibble(boot_device[2]) << 4 | (fd_bootchk ?  0x0 : 0x1));



    



    fd0 = fdctrl_get_drive_type(floppy_controller, 0);

    fd1 = fdctrl_get_drive_type(floppy_controller, 1);



    val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);

    rtc_set_memory(s, 0x10, val);



    val = 0;

    nb = 0;

    if (fd0 < 3)

        nb++;

    if (fd1 < 3)

        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);



    



    rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));

    if (hd_table[0])

        cmos_init_hd(0x19, 0x1b, hd_table[0]);

    if (hd_table[1])

        cmos_init_hd(0x1a, 0x24, hd_table[1]);



    val = 0;

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

        if (hd_table[i]) {

            int cylinders, heads, sectors, translation;

            







            translation = bdrv_get_translation_hint(hd_table[i]);

            if (translation == BIOS_ATA_TRANSLATION_AUTO) {

                bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, &sectors);

                if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {

                    

                    translation = 0;

                } else {

                    

                    translation = 1;

                }

            } else {

                translation--;

            }

            val |= translation << (i * 2);

        }

    }

    rtc_set_memory(s, 0x39, val);

}

static void FUNC_0(int VAR_0, const char *VAR_1, BlockDriverState **VAR_2)

{

    RTCState *s = rtc_state;

    int VAR_3;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7;



    



    

    VAR_3 = 640; 

    rtc_set_memory(s, 0x15, VAR_3);

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



    VAR_3 = (VAR_0 / 1024) - 1024;

    if (VAR_3 > 65535)

        VAR_3 = 65535;

    rtc_set_memory(s, 0x17, VAR_3);

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

    rtc_set_memory(s, 0x30, VAR_3);

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



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

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

    else

        VAR_3 = 0;

    if (VAR_3 > 65535)

        VAR_3 = 65535;

    rtc_set_memory(s, 0x34, VAR_3);

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



    

    rtc_set_memory(s, 0x3d,

            boot_device2nibble(VAR_1[1]) << 4 |

            boot_device2nibble(VAR_1[0]) );

    rtc_set_memory(s, 0x38,

            boot_device2nibble(VAR_1[2]) << 4 | (fd_bootchk ?  0x0 : 0x1));



    



    VAR_4 = fdctrl_get_drive_type(floppy_controller, 0);

    VAR_5 = fdctrl_get_drive_type(floppy_controller, 1);



    VAR_3 = (cmos_get_fd_drive_type(VAR_4) << 4) | cmos_get_fd_drive_type(VAR_5);

    rtc_set_memory(s, 0x10, VAR_3);



    VAR_3 = 0;

    VAR_6 = 0;

    if (VAR_4 < 3)

        VAR_6++;

    if (VAR_5 < 3)

        VAR_6++;

    switch (VAR_6) {

    case 0:

        break;

    case 1:

        VAR_3 |= 0x01; 

        break;

    case 2:

        VAR_3 |= 0x41; 

        break;

    }

    VAR_3 |= 0x02; 

    VAR_3 |= 0x04; 

    rtc_set_memory(s, REG_EQUIPMENT_BYTE, VAR_3);



    



    rtc_set_memory(s, 0x12, (VAR_2[0] ? 0xf0 : 0) | (VAR_2[1] ? 0x0f : 0));

    if (VAR_2[0])

        cmos_init_hd(0x19, 0x1b, VAR_2[0]);

    if (VAR_2[1])

        cmos_init_hd(0x1a, 0x24, VAR_2[1]);



    VAR_3 = 0;

    for (VAR_7 = 0; VAR_7 < 4; VAR_7++) {

        if (VAR_2[VAR_7]) {

            int VAR_8, VAR_9, VAR_10, VAR_11;

            







            VAR_11 = bdrv_get_translation_hint(VAR_2[VAR_7]);

            if (VAR_11 == BIOS_ATA_TRANSLATION_AUTO) {

                bdrv_get_geometry_hint(VAR_2[VAR_7], &VAR_8, &VAR_9, &VAR_10);

                if (VAR_8 <= 1024 && VAR_9 <= 16 && VAR_10 <= 63) {

                    

                    VAR_11 = 0;

                } else {

                    

                    VAR_11 = 1;

                }

            } else {

                VAR_11--;

            }

            VAR_3 |= VAR_11 << (VAR_7 * 2);

        }

    }

    rtc_set_memory(s, 0x39, VAR_3);

}

static void FUNC_0(int VAR_0, const char *VAR_1, BlockDriverState **VAR_2)
{ RTCState *s = rtc_state; int VAR_3; int VAR_4, VAR_5, VAR_6; int VAR_7; VAR_3 = 640; rtc_set_memory(s, 0x15, VAR_3); rtc_set_memory(s, 0x16, VAR_3 >> 8); VAR_3 = (VAR_0 / 1024) - 1024; if (VAR_3 > 65535)
VAR_3 = 65535; rtc_set_memory(s, 0x17, VAR_3); rtc_set_memory(s, 0x18, VAR_3 >> 8); rtc_set_memory(s, 0x30, VAR_3); rtc_set_memory(s, 0x31, VAR_3 >> 8); if (VAR_0 > (16 * 1024 * 1024))
VAR_3 = (VAR_0 / 65536) - ((16 * 1024 * 1024) / 65536); else
VAR_3 = 0; if (VAR_3 > 65535)
VAR_3 = 65535; rtc_set_memory(s, 0x34, VAR_3); rtc_set_memory(s, 0x35, VAR_3 >> 8); rtc_set_memory(s, 0x3d,
boot_device2nibble(VAR_1[1]) << 4 |
boot_device2nibble(VAR_1[0]) ); rtc_set_memory(s, 0x38,
boot_device2nibble(VAR_1[2]) << 4 | (fd_bootchk ?  0x0 : 0x1)); VAR_4 = fdctrl_get_drive_type(floppy_controller, 0); VAR_5 = fdctrl_get_drive_type(floppy_controller, 1); VAR_3 = (cmos_get_fd_drive_type(VAR_4) << 4) | cmos_get_fd_drive_type(VAR_5); rtc_set_memory(s, 0x10, VAR_3); VAR_3 = 0; VAR_6 = 0; if (VAR_4 < 3)
VAR_6++; if (VAR_5 < 3)
VAR_6++; switch (VAR_6) { case 0:
break; case 1:
VAR_3 |= 0x01; break; case 2:
VAR_3 |= 0x41; break; } VAR_3 |= 0x02; VAR_3 |= 0x04; rtc_set_memory(s, REG_EQUIPMENT_BYTE, VAR_3); rtc_set_memory(s, 0x12, (VAR_2[0] ? 0xf0 : 0) | (VAR_2[1] ? 0x0f : 0)); if (VAR_2[0])
cmos_init_hd(0x19, 0x1b, VAR_2[0]); if (VAR_2[1])
cmos_init_hd(0x1a, 0x24, VAR_2[1]); VAR_3 = 0; for (VAR_7 = 0; VAR_7 < 4; VAR_7++) { if (VAR_2[VAR_7]) { int VAR_8, VAR_9, VAR_10, VAR_11; VAR_11 = bdrv_get_translation_hint(VAR_2[VAR_7]); if (VAR_11 == BIOS_ATA_TRANSLATION_AUTO) { bdrv_get_geometry_hint(VAR_2[VAR_7], &VAR_8, &VAR_9, &VAR_10); if (VAR_8 <= 1024 && VAR_9 <= 16 && VAR_10 <= 63) { VAR_11 = 0; } else { VAR_11 = 1; } } else { VAR_11--; } VAR_3 |= VAR_11 << (VAR_7 * 2); } } rtc_set_memory(s, 0x39, VAR_3); }