static void vmsvga_fifo_run(struct vmsvga_state_s *s)

{

    uint32_t cmd, colour;

    int args, len;

    int x, y, dx, dy, width, height;

    struct vmsvga_cursor_definition_s cursor;

    uint32_t cmd_start;



    len = vmsvga_fifo_length(s);

    while (len > 0) {

        /* May need to go back to the start of the command if incomplete */

        cmd_start = s->cmd->stop;



        switch (cmd = vmsvga_fifo_read(s)) {

        case SVGA_CMD_UPDATE:

        case SVGA_CMD_UPDATE_VERBOSE:

            len -= 5;

            if (len < 0) {

                goto rewind;

            }



            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

            vmsvga_update_rect_delayed(s, x, y, width, height);

            break;



        case SVGA_CMD_RECT_FILL:

            len -= 6;

            if (len < 0) {

                goto rewind;

            }



            colour = vmsvga_fifo_read(s);

            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

#ifdef HW_FILL_ACCEL

            if (vmsvga_fill_rect(s, colour, x, y, width, height) == 0) {

                break;

            }

#endif

            args = 0;

            goto badcmd;



        case SVGA_CMD_RECT_COPY:

            len -= 7;

            if (len < 0) {

                goto rewind;

            }



            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            dx = vmsvga_fifo_read(s);

            dy = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

#ifdef HW_RECT_ACCEL

            if (vmsvga_copy_rect(s, x, y, dx, dy, width, height) == 0) {

                break;

            }

#endif

            args = 0;

            goto badcmd;



        case SVGA_CMD_DEFINE_CURSOR:

            len -= 8;

            if (len < 0) {

                goto rewind;

            }



            cursor.id = vmsvga_fifo_read(s);

            cursor.hot_x = vmsvga_fifo_read(s);

            cursor.hot_y = vmsvga_fifo_read(s);

            cursor.width = x = vmsvga_fifo_read(s);

            cursor.height = y = vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            cursor.bpp = vmsvga_fifo_read(s);



            args = SVGA_BITMAP_SIZE(x, y) + SVGA_PIXMAP_SIZE(x, y, cursor.bpp);

            if (SVGA_BITMAP_SIZE(x, y) > sizeof cursor.mask ||

                SVGA_PIXMAP_SIZE(x, y, cursor.bpp) > sizeof cursor.image) {

                    goto badcmd;

            }



            len -= args;

            if (len < 0) {

                goto rewind;

            }



            for (args = 0; args < SVGA_BITMAP_SIZE(x, y); args++) {

                cursor.mask[args] = vmsvga_fifo_read_raw(s);

            }

            for (args = 0; args < SVGA_PIXMAP_SIZE(x, y, cursor.bpp); args++) {

                cursor.image[args] = vmsvga_fifo_read_raw(s);

            }

#ifdef HW_MOUSE_ACCEL

            vmsvga_cursor_define(s, &cursor);

            break;

#else

            args = 0;

            goto badcmd;

#endif



        /*

         * Other commands that we at least know the number of arguments

         * for so we can avoid FIFO desync if driver uses them illegally.

         */

        case SVGA_CMD_DEFINE_ALPHA_CURSOR:

            len -= 6;

            if (len < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            args = x * y;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_FILL:

            args = 6;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_COPY:

            args = 7;

            goto badcmd;

        case SVGA_CMD_DRAW_GLYPH_CLIPPED:

            len -= 4;

            if (len < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            args = 7 + (vmsvga_fifo_read(s) >> 2);

            goto badcmd;

        case SVGA_CMD_SURFACE_ALPHA_BLEND:

            args = 12;

            goto badcmd;



        /*

         * Other commands that are not listed as depending on any

         * CAPABILITIES bits, but are not described in the README either.

         */

        case SVGA_CMD_SURFACE_FILL:

        case SVGA_CMD_SURFACE_COPY:

        case SVGA_CMD_FRONT_ROP_FILL:

        case SVGA_CMD_FENCE:

        case SVGA_CMD_INVALID_CMD:

            break; /* Nop */



        default:

            args = 0;

        badcmd:

            len -= args;

            if (len < 0) {

                goto rewind;

            }

            while (args--) {

                vmsvga_fifo_read(s);

            }

            printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",

                   __func__, cmd);

            break;



        rewind:

            s->cmd->stop = cmd_start;

            break;

        }

    }



    s->syncing = 0;

}

static void vmsvga_fifo_run(struct vmsvga_state_s *s)

{

    uint32_t cmd, colour;

    int args, len;

    int x, y, dx, dy, width, height;

    struct vmsvga_cursor_definition_s cursor;

    uint32_t cmd_start;



    len = vmsvga_fifo_length(s);

    while (len > 0) {

        

        cmd_start = s->cmd->stop;



        switch (cmd = vmsvga_fifo_read(s)) {

        case SVGA_CMD_UPDATE:

        case SVGA_CMD_UPDATE_VERBOSE:

            len -= 5;

            if (len < 0) {

                goto rewind;

            }



            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

            vmsvga_update_rect_delayed(s, x, y, width, height);

            break;



        case SVGA_CMD_RECT_FILL:

            len -= 6;

            if (len < 0) {

                goto rewind;

            }



            colour = vmsvga_fifo_read(s);

            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

#ifdef HW_FILL_ACCEL

            if (vmsvga_fill_rect(s, colour, x, y, width, height) == 0) {

                break;

            }

#endif

            args = 0;

            goto badcmd;



        case SVGA_CMD_RECT_COPY:

            len -= 7;

            if (len < 0) {

                goto rewind;

            }



            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            dx = vmsvga_fifo_read(s);

            dy = vmsvga_fifo_read(s);

            width = vmsvga_fifo_read(s);

            height = vmsvga_fifo_read(s);

#ifdef HW_RECT_ACCEL

            if (vmsvga_copy_rect(s, x, y, dx, dy, width, height) == 0) {

                break;

            }

#endif

            args = 0;

            goto badcmd;



        case SVGA_CMD_DEFINE_CURSOR:

            len -= 8;

            if (len < 0) {

                goto rewind;

            }



            cursor.id = vmsvga_fifo_read(s);

            cursor.hot_x = vmsvga_fifo_read(s);

            cursor.hot_y = vmsvga_fifo_read(s);

            cursor.width = x = vmsvga_fifo_read(s);

            cursor.height = y = vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            cursor.bpp = vmsvga_fifo_read(s);



            args = SVGA_BITMAP_SIZE(x, y) + SVGA_PIXMAP_SIZE(x, y, cursor.bpp);

            if (SVGA_BITMAP_SIZE(x, y) > sizeof cursor.mask ||

                SVGA_PIXMAP_SIZE(x, y, cursor.bpp) > sizeof cursor.image) {

                    goto badcmd;

            }



            len -= args;

            if (len < 0) {

                goto rewind;

            }



            for (args = 0; args < SVGA_BITMAP_SIZE(x, y); args++) {

                cursor.mask[args] = vmsvga_fifo_read_raw(s);

            }

            for (args = 0; args < SVGA_PIXMAP_SIZE(x, y, cursor.bpp); args++) {

                cursor.image[args] = vmsvga_fifo_read_raw(s);

            }

#ifdef HW_MOUSE_ACCEL

            vmsvga_cursor_define(s, &cursor);

            break;

#else

            args = 0;

            goto badcmd;

#endif



        







        case SVGA_CMD_DEFINE_ALPHA_CURSOR:

            len -= 6;

            if (len < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            x = vmsvga_fifo_read(s);

            y = vmsvga_fifo_read(s);

            args = x * y;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_FILL:

            args = 6;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_COPY:

            args = 7;

            goto badcmd;

        case SVGA_CMD_DRAW_GLYPH_CLIPPED:

            len -= 4;

            if (len < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(s);

            vmsvga_fifo_read(s);

            args = 7 + (vmsvga_fifo_read(s) >> 2);

            goto badcmd;

        case SVGA_CMD_SURFACE_ALPHA_BLEND:

            args = 12;

            goto badcmd;



        







        case SVGA_CMD_SURFACE_FILL:

        case SVGA_CMD_SURFACE_COPY:

        case SVGA_CMD_FRONT_ROP_FILL:

        case SVGA_CMD_FENCE:

        case SVGA_CMD_INVALID_CMD:

            break; 



        default:

            args = 0;

        badcmd:

            len -= args;

            if (len < 0) {

                goto rewind;

            }

            while (args--) {

                vmsvga_fifo_read(s);

            }

            printf("%s: Unknown command 0x%02x in SVGA command FIFO\n",

                   __func__, cmd);

            break;



        rewind:

            s->cmd->stop = cmd_start;

            break;

        }

    }



    s->syncing = 0;

}

static void FUNC_0(struct vmsvga_state_s *VAR_0)

{

    uint32_t cmd, colour;

    int VAR_1, VAR_2;

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    struct vmsvga_cursor_definition_s VAR_9;

    uint32_t cmd_start;



    VAR_2 = vmsvga_fifo_length(VAR_0);

    while (VAR_2 > 0) {

        

        cmd_start = VAR_0->cmd->stop;



        switch (cmd = vmsvga_fifo_read(VAR_0)) {

        case SVGA_CMD_UPDATE:

        case SVGA_CMD_UPDATE_VERBOSE:

            VAR_2 -= 5;

            if (VAR_2 < 0) {

                goto rewind;

            }



            VAR_3 = vmsvga_fifo_read(VAR_0);

            VAR_4 = vmsvga_fifo_read(VAR_0);

            VAR_7 = vmsvga_fifo_read(VAR_0);

            VAR_8 = vmsvga_fifo_read(VAR_0);

            vmsvga_update_rect_delayed(VAR_0, VAR_3, VAR_4, VAR_7, VAR_8);

            break;



        case SVGA_CMD_RECT_FILL:

            VAR_2 -= 6;

            if (VAR_2 < 0) {

                goto rewind;

            }



            colour = vmsvga_fifo_read(VAR_0);

            VAR_3 = vmsvga_fifo_read(VAR_0);

            VAR_4 = vmsvga_fifo_read(VAR_0);

            VAR_7 = vmsvga_fifo_read(VAR_0);

            VAR_8 = vmsvga_fifo_read(VAR_0);

#ifdef HW_FILL_ACCEL

            if (vmsvga_fill_rect(VAR_0, colour, VAR_3, VAR_4, VAR_7, VAR_8) == 0) {

                break;

            }

#endif

            VAR_1 = 0;

            goto badcmd;



        case SVGA_CMD_RECT_COPY:

            VAR_2 -= 7;

            if (VAR_2 < 0) {

                goto rewind;

            }



            VAR_3 = vmsvga_fifo_read(VAR_0);

            VAR_4 = vmsvga_fifo_read(VAR_0);

            VAR_5 = vmsvga_fifo_read(VAR_0);

            VAR_6 = vmsvga_fifo_read(VAR_0);

            VAR_7 = vmsvga_fifo_read(VAR_0);

            VAR_8 = vmsvga_fifo_read(VAR_0);

#ifdef HW_RECT_ACCEL

            if (vmsvga_copy_rect(VAR_0, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8) == 0) {

                break;

            }

#endif

            VAR_1 = 0;

            goto badcmd;



        case SVGA_CMD_DEFINE_CURSOR:

            VAR_2 -= 8;

            if (VAR_2 < 0) {

                goto rewind;

            }



            VAR_9.id = vmsvga_fifo_read(VAR_0);

            VAR_9.hot_x = vmsvga_fifo_read(VAR_0);

            VAR_9.hot_y = vmsvga_fifo_read(VAR_0);

            VAR_9.VAR_7 = VAR_3 = vmsvga_fifo_read(VAR_0);

            VAR_9.VAR_8 = VAR_4 = vmsvga_fifo_read(VAR_0);

            vmsvga_fifo_read(VAR_0);

            VAR_9.bpp = vmsvga_fifo_read(VAR_0);



            VAR_1 = SVGA_BITMAP_SIZE(VAR_3, VAR_4) + SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp);

            if (SVGA_BITMAP_SIZE(VAR_3, VAR_4) > sizeof VAR_9.mask ||

                SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp) > sizeof VAR_9.image) {

                    goto badcmd;

            }



            VAR_2 -= VAR_1;

            if (VAR_2 < 0) {

                goto rewind;

            }



            for (VAR_1 = 0; VAR_1 < SVGA_BITMAP_SIZE(VAR_3, VAR_4); VAR_1++) {

                VAR_9.mask[VAR_1] = vmsvga_fifo_read_raw(VAR_0);

            }

            for (VAR_1 = 0; VAR_1 < SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp); VAR_1++) {

                VAR_9.image[VAR_1] = vmsvga_fifo_read_raw(VAR_0);

            }

#ifdef HW_MOUSE_ACCEL

            vmsvga_cursor_define(VAR_0, &VAR_9);

            break;

#else

            VAR_1 = 0;

            goto badcmd;

#endif



        







        case SVGA_CMD_DEFINE_ALPHA_CURSOR:

            VAR_2 -= 6;

            if (VAR_2 < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(VAR_0);

            vmsvga_fifo_read(VAR_0);

            vmsvga_fifo_read(VAR_0);

            VAR_3 = vmsvga_fifo_read(VAR_0);

            VAR_4 = vmsvga_fifo_read(VAR_0);

            VAR_1 = VAR_3 * VAR_4;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_FILL:

            VAR_1 = 6;

            goto badcmd;

        case SVGA_CMD_RECT_ROP_COPY:

            VAR_1 = 7;

            goto badcmd;

        case SVGA_CMD_DRAW_GLYPH_CLIPPED:

            VAR_2 -= 4;

            if (VAR_2 < 0) {

                goto rewind;

            }

            vmsvga_fifo_read(VAR_0);

            vmsvga_fifo_read(VAR_0);

            VAR_1 = 7 + (vmsvga_fifo_read(VAR_0) >> 2);

            goto badcmd;

        case SVGA_CMD_SURFACE_ALPHA_BLEND:

            VAR_1 = 12;

            goto badcmd;



        







        case SVGA_CMD_SURFACE_FILL:

        case SVGA_CMD_SURFACE_COPY:

        case SVGA_CMD_FRONT_ROP_FILL:

        case SVGA_CMD_FENCE:

        case SVGA_CMD_INVALID_CMD:

            break; 



        default:

            VAR_1 = 0;

        badcmd:

            VAR_2 -= VAR_1;

            if (VAR_2 < 0) {

                goto rewind;

            }

            while (VAR_1--) {

                vmsvga_fifo_read(VAR_0);

            }

            printf("%VAR_0: Unknown command 0x%02x in SVGA command FIFO\n",

                   __func__, cmd);

            break;



        rewind:

            VAR_0->cmd->stop = cmd_start;

            break;

        }

    }



    VAR_0->syncing = 0;

}

static void FUNC_0(struct vmsvga_state_s *VAR_0)
{ uint32_t cmd, colour; int VAR_1, VAR_2; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; struct vmsvga_cursor_definition_s VAR_9; uint32_t cmd_start; VAR_2 = vmsvga_fifo_length(VAR_0); while (VAR_2 > 0) { cmd_start = VAR_0->cmd->stop; switch (cmd = vmsvga_fifo_read(VAR_0)) { case SVGA_CMD_UPDATE:
case SVGA_CMD_UPDATE_VERBOSE:
VAR_2 -= 5; if (VAR_2 < 0) { goto rewind; } VAR_3 = vmsvga_fifo_read(VAR_0); VAR_4 = vmsvga_fifo_read(VAR_0); VAR_7 = vmsvga_fifo_read(VAR_0); VAR_8 = vmsvga_fifo_read(VAR_0); vmsvga_update_rect_delayed(VAR_0, VAR_3, VAR_4, VAR_7, VAR_8); break; case SVGA_CMD_RECT_FILL:
VAR_2 -= 6; if (VAR_2 < 0) { goto rewind; } colour = vmsvga_fifo_read(VAR_0); VAR_3 = vmsvga_fifo_read(VAR_0); VAR_4 = vmsvga_fifo_read(VAR_0); VAR_7 = vmsvga_fifo_read(VAR_0); VAR_8 = vmsvga_fifo_read(VAR_0); #ifdef HW_FILL_ACCEL
if (vmsvga_fill_rect(VAR_0, colour, VAR_3, VAR_4, VAR_7, VAR_8) == 0) { break; } #endif
VAR_1 = 0; goto badcmd; case SVGA_CMD_RECT_COPY:
VAR_2 -= 7; if (VAR_2 < 0) { goto rewind; } VAR_3 = vmsvga_fifo_read(VAR_0); VAR_4 = vmsvga_fifo_read(VAR_0); VAR_5 = vmsvga_fifo_read(VAR_0); VAR_6 = vmsvga_fifo_read(VAR_0); VAR_7 = vmsvga_fifo_read(VAR_0); VAR_8 = vmsvga_fifo_read(VAR_0); #ifdef HW_RECT_ACCEL
if (vmsvga_copy_rect(VAR_0, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8) == 0) { break; } #endif
VAR_1 = 0; goto badcmd; case SVGA_CMD_DEFINE_CURSOR:
VAR_2 -= 8; if (VAR_2 < 0) { goto rewind; } VAR_9.id = vmsvga_fifo_read(VAR_0); VAR_9.hot_x = vmsvga_fifo_read(VAR_0); VAR_9.hot_y = vmsvga_fifo_read(VAR_0); VAR_9.VAR_7 = VAR_3 = vmsvga_fifo_read(VAR_0); VAR_9.VAR_8 = VAR_4 = vmsvga_fifo_read(VAR_0); vmsvga_fifo_read(VAR_0); VAR_9.bpp = vmsvga_fifo_read(VAR_0); VAR_1 = SVGA_BITMAP_SIZE(VAR_3, VAR_4) + SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp); if (SVGA_BITMAP_SIZE(VAR_3, VAR_4) > sizeof VAR_9.mask ||
SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp) > sizeof VAR_9.image) { goto badcmd; } VAR_2 -= VAR_1; if (VAR_2 < 0) { goto rewind; } for (VAR_1 = 0; VAR_1 < SVGA_BITMAP_SIZE(VAR_3, VAR_4); VAR_1++) { VAR_9.mask[VAR_1] = vmsvga_fifo_read_raw(VAR_0); } for (VAR_1 = 0; VAR_1 < SVGA_PIXMAP_SIZE(VAR_3, VAR_4, VAR_9.bpp); VAR_1++) { VAR_9.image[VAR_1] = vmsvga_fifo_read_raw(VAR_0); } #ifdef HW_MOUSE_ACCEL
vmsvga_cursor_define(VAR_0, &VAR_9); break; #else
VAR_1 = 0; goto badcmd; #endif
case SVGA_CMD_DEFINE_ALPHA_CURSOR:
VAR_2 -= 6; if (VAR_2 < 0) { goto rewind; } vmsvga_fifo_read(VAR_0); vmsvga_fifo_read(VAR_0); vmsvga_fifo_read(VAR_0); VAR_3 = vmsvga_fifo_read(VAR_0); VAR_4 = vmsvga_fifo_read(VAR_0); VAR_1 = VAR_3 * VAR_4; goto badcmd; case SVGA_CMD_RECT_ROP_FILL:
VAR_1 = 6; goto badcmd; case SVGA_CMD_RECT_ROP_COPY:
VAR_1 = 7; goto badcmd; case SVGA_CMD_DRAW_GLYPH_CLIPPED:
VAR_2 -= 4; if (VAR_2 < 0) { goto rewind; } vmsvga_fifo_read(VAR_0); vmsvga_fifo_read(VAR_0); VAR_1 = 7 + (vmsvga_fifo_read(VAR_0) >> 2); goto badcmd; case SVGA_CMD_SURFACE_ALPHA_BLEND:
VAR_1 = 12; goto badcmd; case SVGA_CMD_SURFACE_FILL:
case SVGA_CMD_SURFACE_COPY:
case SVGA_CMD_FRONT_ROP_FILL:
case SVGA_CMD_FENCE:
case SVGA_CMD_INVALID_CMD:
break; default:
VAR_1 = 0; badcmd:
VAR_2 -= VAR_1; if (VAR_2 < 0) { goto rewind; } while (VAR_1--) { vmsvga_fifo_read(VAR_0); } printf("%VAR_0: Unknown command 0x%02x in SVGA command FIFO\n",
__func__, cmd); break; rewind:
VAR_0->cmd->stop = cmd_start; break; } } VAR_0->syncing = 0; }