From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LLm9J-0001RI-Qx for qemu-devel@nongnu.org; Sat, 10 Jan 2009 17:17:45 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LLm9H-0001R6-Gz for qemu-devel@nongnu.org; Sat, 10 Jan 2009 17:17:44 -0500 Received: from [199.232.76.173] (port=51367 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LLm9H-0001R3-DJ for qemu-devel@nongnu.org; Sat, 10 Jan 2009 17:17:43 -0500 Received: from smtp1-g21.free.fr ([212.27.42.1]:46983) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LLm9G-0006uE-4K for qemu-devel@nongnu.org; Sat, 10 Jan 2009 17:17:43 -0500 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id 97C86940120 for ; Sat, 10 Jan 2009 23:17:35 +0100 (CET) Received: from [192.168.0.32] (rob92-10-88-171-126-33.fbx.proxad.net [88.171.126.33]) by smtp1-g21.free.fr (Postfix) with ESMTP id 22F089400F6 for ; Sat, 10 Jan 2009 23:17:32 +0100 (CET) Message-ID: <49691E7C.3060101@reactos.org> Date: Sat, 10 Jan 2009 23:17:32 +0100 From: =?ISO-8859-1?Q?Herv=E9_Poussineau?= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080905080602000400080608" Subject: [Qemu-devel] [RESEND][PATCH] G364 video adapter enhancement Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------080905080602000400080608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Hi, Attached patch improves G364 video card emulation (used in MIPS Magnum=20 machine): - Use memory dirty tracking to not refresh whole screen each time - Use macros for debugging messages - Add support for hardware cursor - Handle Y-panning - Raise irq at each screen redraw - Support retrieving of some registers - Add load/save support The emulation has been tested in Linux 2.1 and Windows NT 3.5, in=20 640x480, 800x600, 1024x768 and 1280x1024 resolutions. Signed-off-by: Herv=E9 Poussineau Herv=E9 --------------080905080602000400080608 Content-Type: plain/text; name="g364.diff" Content-Disposition: inline; filename="g364.diff" Content-Transfer-Encoding: quoted-printable =EF=BB=BFIndex: hw/g364fb.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- hw/g364fb.c (revision 6267) +++ hw/g364fb.c (working copy) @@ -1,7 +1,7 @@ /* * QEMU G364 framebuffer Emulator. * - * Copyright (c) 2007-2008 Herv=C3=A9 Poussineau + * Copyright (c) 2007-2009 Herve Poussineau * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -25,141 +25,276 @@ =20 //#define DEBUG_G364 =20 +#ifdef DEBUG_G364 +#define DPRINTF(fmt, args...) \ +do { printf("g364: " fmt , ##args); } while (0) +#else +#define DPRINTF(fmt, args...) do {} while (0) +#endif +#define BADF(fmt, args...) \ +do { fprintf(stderr, "g364 ERROR: " fmt , ##args);} while (0) + typedef struct G364State { - unsigned int vram_size; - uint8_t *vram_buffer; + /* hardware */ + uint8_t *vram; + ram_addr_t vram_offset; + int vram_size; + qemu_irq irq; + /* registers */ + uint8_t color_palette[256][3]; + uint8_t cursor_palette[3][3]; + uint16_t cursor[512]; + uint32_t cursor_position; uint32_t ctla; - uint8_t palette[256][3]; + uint32_t top_of_screen; + uint32_t width, height; /* in pixels */ /* display refresh support */ DisplayState *ds; QEMUConsole *console; - int graphic_mode; - uint32_t scr_width, scr_height; /* in pixels */ + int depth; + int blanked; } G364State; =20 -/* - * graphic modes - */ -#define BPP 8 -#define PIXEL_WIDTH 8 -#include "g364fb_template.h" -#undef BPP -#undef PIXEL_WIDTH +#define REG_ID 0x000000 +#define REG_BOOT 0x080000 +#define REG_DISPLAY 0x080118 +#define REG_VDISPLAY 0x080150 +#define REG_CTLA 0x080300 +#define REG_TOP 0x080400 +#define REG_CURS_PAL 0x080508 +#define REG_CURS_POS 0x080638 +#define REG_CLR_PAL 0x080800 +#define REG_CURS_PAT 0x081000 +#define REG_RESET 0x180000 =20 -#define BPP 15 -#define PIXEL_WIDTH 16 -#include "g364fb_template.h" -#undef BPP -#undef PIXEL_WIDTH +#define CTLA_FORCE_BLANK 0x00000400 +#define CTLA_NO_CURSOR 0x00800000 =20 -#define BPP 16 -#define PIXEL_WIDTH 16 -#include "g364fb_template.h" -#undef BPP -#undef PIXEL_WIDTH +static inline int check_dirty(ram_addr_t page) +{ + return cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG); +} =20 -#define BPP 32 -#define PIXEL_WIDTH 32 -#include "g364fb_template.h" -#undef BPP -#undef PIXEL_WIDTH +static inline void reset_dirty(G364State *s, + ram_addr_t page_min, ram_addr_t page_max) +{ + cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZ= E - 1, + VGA_DIRTY_FLAG); +} =20 -#define REG_DISPLAYX 0x0918 -#define REG_DISPLAYY 0x0940 +static void g364fb_draw_graphic8(G364State *s) +{ + int i, w; + uint8_t *vram; + uint8_t *data_display, *dd; + ram_addr_t page, page_min, page_max; + int x, y; + int xmin, xmax; + int ymin, ymax; + int xcursor, ycursor; + unsigned int (*rgb_to_pixel)(unsigned int r, unsigned int g, unsigne= d int b); =20 -#define CTLA_FORCE_BLANK 0x400 - -static void g364fb_draw_graphic(G364State *s, int full_update) -{ switch (ds_get_bits_per_pixel(s->ds)) { case 8: - g364fb_draw_graphic8(s, full_update); + rgb_to_pixel =3D rgb_to_pixel8; + w =3D 1; break; case 15: - g364fb_draw_graphic15(s, full_update); + rgb_to_pixel =3D rgb_to_pixel15; + w =3D 2; break; case 16: - g364fb_draw_graphic16(s, full_update); + rgb_to_pixel =3D rgb_to_pixel16; + w =3D 2; break; case 32: - g364fb_draw_graphic32(s, full_update); + rgb_to_pixel =3D rgb_to_pixel32; + w =3D 4; break; default: - printf("g364fb: unknown depth %d\n", ds_get_bits_per_pixel(s= ->ds)); + BADF("unknown host depth %d\n", ds_get_bits_per_pixel(s->ds)= ); return; } =20 - dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height); + page =3D s->vram_offset; + page_min =3D (ram_addr_t)-1; + page_max =3D 0; + + x =3D y =3D 0; + xmin =3D s->width; + xmax =3D 0; + ymin =3D s->height; + ymax =3D 0; + + if (!(s->ctla & CTLA_NO_CURSOR)) { + xcursor =3D s->cursor_position >> 12; + ycursor =3D s->cursor_position & 0xfff; + } else { + xcursor =3D ycursor =3D -65; + } + + vram =3D s->vram + s->top_of_screen; + /* XXX: out of range in vram? */ + data_display =3D dd =3D ds_get_data(s->ds); + while (y < s->height) { + if (check_dirty(page)) { + if (y < ymin) + ymin =3D ymax =3D y; + if (page_min =3D=3D (ram_addr_t)-1) + page_min =3D page; + page_max =3D page; + if (x < xmin) + xmin =3D x; + for (i =3D 0; i < TARGET_PAGE_SIZE; i++) { + uint8_t index; + unsigned int color; + if (unlikely((y >=3D ycursor && y < ycursor + 64) && + (x >=3D xcursor && x < xcursor + 64))) { + /* pointer area */ + int xdiff =3D x - xcursor; + uint16_t curs =3D s->cursor[(y - ycursor) * 8 + xdif= f / 8]; + int op =3D (curs >> ((xdiff & 7) * 2)) & 3; + if (likely(op =3D=3D 0)) { + /* transparent */ + index =3D *vram; + color =3D (*rgb_to_pixel)( + s->color_palette[index][0], + s->color_palette[index][1], + s->color_palette[index][2]); + } else { + /* get cursor color */ + index =3D op - 1; + color =3D (*rgb_to_pixel)( + s->cursor_palette[index][0], + s->cursor_palette[index][1], + s->cursor_palette[index][2]); + } + } else { + /* normal area */ + index =3D *vram; + color =3D (*rgb_to_pixel)( + s->color_palette[index][0], + s->color_palette[index][1], + s->color_palette[index][2]); + } + memcpy(dd, &color, w); + dd +=3D w; + x++; + vram++; + if (x =3D=3D s->width) { + xmax =3D s->width - 1; + y++; + if (y =3D=3D s->height) { + ymax =3D s->height - 1; + goto done; + } + data_display =3D dd =3D data_display + ds_get_linesi= ze(s->ds); + xmin =3D 0; + x =3D 0; + } + } + if (x > xmax) + xmax =3D x; + if (y > ymax) + ymax =3D y; + } else { + int dy; + if (page_min !=3D (ram_addr_t)-1) { + reset_dirty(s, page_min, page_max); + page_min =3D (ram_addr_t)-1; + page_max =3D 0; + dpy_update(s->ds, xmin, ymin, xmax - xmin + 1, ymax - ym= in + 1); + xmin =3D s->width; + xmax =3D 0; + ymin =3D s->height; + ymax =3D 0; + } + x +=3D TARGET_PAGE_SIZE; + dy =3D x / s->width; + x =3D x % s->width; + y +=3D dy; + vram +=3D TARGET_PAGE_SIZE; + data_display +=3D dy * ds_get_linesize(s->ds); + dd =3D data_display + x * w; + } + page +=3D TARGET_PAGE_SIZE; + } + +done: + if (page_min !=3D (ram_addr_t)-1) { + dpy_update(s->ds, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); + reset_dirty(s, page_min, page_max); + } } =20 -static void g364fb_draw_blank(G364State *s, int full_update) +static void g364fb_draw_blank(G364State *s) { int i, w; uint8_t *d; =20 - if (!full_update) + if (s->blanked) { + /* Screen is already blank. No need to redraw it */ return; + } =20 - w =3D s->scr_width * ((ds_get_bits_per_pixel(s->ds) + 7) >> 3); + w =3D s->width * ((ds_get_bits_per_pixel(s->ds) + 7) >> 3); d =3D ds_get_data(s->ds); - for(i =3D 0; i < s->scr_height; i++) { + for (i =3D 0; i < s->height; i++) { memset(d, 0, w); d +=3D ds_get_linesize(s->ds); } =20 - dpy_update(s->ds, 0, 0, s->scr_width, s->scr_height); + dpy_update(s->ds, 0, 0, s->width, s->height); + s->blanked =3D 1; } =20 -#define GMODE_GRAPH 0 -#define GMODE_BLANK 1 - static void g364fb_update_display(void *opaque) { G364State *s =3D opaque; - int full_update, graphic_mode; =20 - if (s->scr_width =3D=3D 0 || s->scr_height =3D=3D 0) + if (s->width =3D=3D 0 || s->height =3D=3D 0) return; =20 - if (s->ctla & CTLA_FORCE_BLANK) - graphic_mode =3D GMODE_BLANK; - else - graphic_mode =3D GMODE_GRAPH; - full_update =3D 0; - if (graphic_mode !=3D s->graphic_mode) { - s->graphic_mode =3D graphic_mode; - full_update =3D 1; + if (s->width !=3D ds_get_width(s->ds) || s->height !=3D ds_get_heigh= t(s->ds)) { + qemu_console_resize(s->console, s->width, s->height); } - if (s->scr_width !=3D ds_get_width(s->ds) || s->scr_height !=3D ds_g= et_height(s->ds)) { - qemu_console_resize(s->console, s->scr_width, s->scr_height); - full_update =3D 1; + + if (s->ctla & CTLA_FORCE_BLANK) { + g364fb_draw_blank(s); + } else if (s->depth =3D=3D 8) { + g364fb_draw_graphic8(s); + } else { + BADF("unknown guest depth %d\n", s->depth); } - switch(graphic_mode) { - case GMODE_GRAPH: - g364fb_draw_graphic(s, full_update); - break; - case GMODE_BLANK: - default: - g364fb_draw_blank(s, full_update); - break; - } + + qemu_irq_raise(s->irq); } =20 -/* force a full display refresh */ -static void g364fb_invalidate_display(void *opaque) +static void inline g364fb_invalidate_display(void *opaque) { G364State *s =3D opaque; - s->graphic_mode =3D -1; /* force full update */ + int i; + + s->blanked =3D 0; + for (i =3D 0; i < s->vram_size; i +=3D TARGET_PAGE_SIZE) { + cpu_physical_memory_set_dirty(s->vram_offset + i); + } } =20 static void g364fb_reset(void *opaque) { G364State *s =3D opaque; + qemu_irq_lower(s->irq); =20 - memset(s->palette, 0, sizeof(s->palette)); - s->scr_width =3D s->scr_height =3D 0; - memset(s->vram_buffer, 0, s->vram_size); - s->graphic_mode =3D -1; /* force full update */ + memset(s->color_palette, 0, sizeof(s->color_palette)); + memset(s->cursor_palette, 0, sizeof(s->cursor_palette)); + memset(s->cursor, 0, sizeof(s->cursor)); + s->cursor_position =3D 0; + s->ctla =3D 0; + s->top_of_screen =3D 0; + s->width =3D s->height =3D 0; + memset(s->vram, 0, s->vram_size); + g364fb_invalidate_display(opaque); } =20 static void g364fb_screen_dump(void *opaque, const char *filename) @@ -170,117 +305,223 @@ uint8_t *data_buffer; FILE *f; =20 + if (s->depth !=3D 8) { + BADF("unknown guest depth %d\n", s->depth); + return; + } + f =3D fopen(filename, "wb"); if (!f) return; =20 - data_buffer =3D s->vram_buffer; - fprintf(f, "P6\n%d %d\n%d\n", - s->scr_width, s->scr_height, 255); - for(y =3D 0; y < s->scr_height; y++) - for(x =3D 0; x < s->scr_width; x++, data_buffer++) { - index =3D *data_buffer; - fputc(s->palette[index][0], f); - fputc(s->palette[index][1], f); - fputc(s->palette[index][2], f); + if (s->ctla & CTLA_FORCE_BLANK) { + /* blank screen */ + fprintf(f, "P4\n%d %d\n", + s->width, s->height); + for (y =3D 0; y < s->height; y++) + for (x =3D 0; x < s->width; x++) + fputc(0, f); + } else { + data_buffer =3D s->vram + s->top_of_screen; + fprintf(f, "P6\n%d %d\n%d\n", + s->width, s->height, 255); + for (y =3D 0; y < s->height; y++) + for (x =3D 0; x < s->width; x++, data_buffer++) { + index =3D *data_buffer; + fputc(s->color_palette[index][0], f); + fputc(s->color_palette[index][1], f); + fputc(s->color_palette[index][2], f); } + } + fclose(f); } =20 /* called for accesses to io ports */ -static uint32_t g364fb_ctrl_readb(void *opaque, target_phys_addr_t addr) +static uint32_t g364fb_ctrl_readl(void *opaque, target_phys_addr_t addr) { - //G364State *s =3D opaque; + G364State *s =3D opaque; uint32_t val; =20 - addr &=3D 0xffff; - - switch (addr) { - default: -#ifdef DEBUG_G364 - printf("g364fb/ctrl: invalid read at [" TARGET_FMT_lx "]\n",= addr); -#endif - val =3D 0; - break; + if (addr >=3D REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) { + /* cursor pattern */ + int idx =3D (addr - REG_CURS_PAT) >> 3; + val =3D s->cursor[idx]; + } else if (addr >=3D REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) { + /* cursor palette */ + int idx =3D (addr - REG_CURS_PAL) >> 3; + val =3D ((uint32_t)s->cursor_palette[idx][0] << 16); + val |=3D ((uint32_t)s->cursor_palette[idx][1] << 8); + val |=3D ((uint32_t)s->cursor_palette[idx][2] << 0); + } else { + switch (addr) { + case REG_ID: + val =3D 0x10; /* Mips G364 */ + break; + case REG_DISPLAY: + val =3D s->width / 4; + break; + case REG_VDISPLAY: + val =3D s->height * 2; + break; + case REG_CTLA: + val =3D s->ctla; + break; + default: + { + BADF("invalid read at [" TARGET_FMT_plx "]\n", addr); + val =3D 0; + break; + } + } } =20 -#ifdef DEBUG_G364 - printf("g364fb/ctrl: read 0x%02x at [" TARGET_FMT_lx "]\n", val, add= r); -#endif + DPRINTF("read 0x%08x at [" TARGET_FMT_plx "]\n", val, addr); =20 return val; } =20 static uint32_t g364fb_ctrl_readw(void *opaque, target_phys_addr_t addr) { - uint32_t v; - v =3D g364fb_ctrl_readb(opaque, addr); - v |=3D g364fb_ctrl_readb(opaque, addr + 1) << 8; - return v; + uint32_t v =3D g364fb_ctrl_readl(opaque, addr & ~0x3); + if (addr & 0x2) + return v >> 16; + else + return v & 0xffff; } =20 -static uint32_t g364fb_ctrl_readl(void *opaque, target_phys_addr_t addr) +static uint32_t g364fb_ctrl_readb(void *opaque, target_phys_addr_t addr) { - uint32_t v; - v =3D g364fb_ctrl_readb(opaque, addr); - v |=3D g364fb_ctrl_readb(opaque, addr + 1) << 8; - v |=3D g364fb_ctrl_readb(opaque, addr + 2) << 16; - v |=3D g364fb_ctrl_readb(opaque, addr + 3) << 24; - return v; + uint32_t v =3D g364fb_ctrl_readl(opaque, addr & ~0x3); + return (v >> (8 * (addr & 0x3))) & 0xff; } =20 -static void g364fb_ctrl_writeb(void *opaque, target_phys_addr_t addr, ui= nt32_t val) +static void g364fb_update_depth(G364State *s) { + const static int depths[8] =3D { 1, 2, 4, 8, 15, 16, 0 }; + s->depth =3D depths[(s->ctla & 0x00700000) >> 20]; +} + +static void g364_invalidate_cursor_position(G364State *s) +{ + int ymin, ymax, start, end, i; + + /* invalidate only near the cursor */ + ymin =3D s->cursor_position & 0xfff; + ymax =3D min(s->height, ymin + 64); + start =3D ymin * ds_get_linesize(s->ds); + end =3D (ymax + 1) * ds_get_linesize(s->ds); + + for (i =3D start; i < end; i +=3D TARGET_PAGE_SIZE) { + cpu_physical_memory_set_dirty(s->vram_offset + i); + } +} + +static void g364fb_ctrl_writel(void *opaque, target_phys_addr_t addr, ui= nt32_t val) +{ G364State *s =3D opaque; =20 - addr &=3D 0xffff; + DPRINTF("write 0x%08x at [" TARGET_FMT_plx "]\n", val, addr); =20 -#ifdef DEBUG_G364 - printf("g364fb/ctrl: write 0x%02x at [" TARGET_FMT_lx "]\n", val, ad= dr); -#endif - - if (addr < 0x0800) { + if (addr >=3D REG_CLR_PAL && addr < REG_CLR_PAL + 0x800) { /* color palette */ - int idx =3D addr >> 3; - int c =3D addr & 7; - if (c < 3) - s->palette[idx][c] =3D (uint8_t)val; + int idx =3D (addr - REG_CLR_PAL) >> 3; + s->color_palette[idx][0] =3D (val >> 16) & 0xff; + s->color_palette[idx][1] =3D (val >> 8) & 0xff; + s->color_palette[idx][2] =3D val & 0xff; + g364fb_invalidate_display(s); + } else if (addr >=3D REG_CURS_PAT && addr < REG_CURS_PAT + 0x1000) { + /* cursor pattern */ + int idx =3D (addr - REG_CURS_PAT) >> 3; + s->cursor[idx] =3D val; + g364fb_invalidate_display(s); + } else if (addr >=3D REG_CURS_PAL && addr < REG_CURS_PAL + 0x18) { + /* cursor palette */ + int idx =3D (addr - REG_CURS_PAL) >> 3; + s->cursor_palette[idx][0] =3D (val >> 16) & 0xff; + s->cursor_palette[idx][1] =3D (val >> 8) & 0xff; + s->cursor_palette[idx][2] =3D val & 0xff; + g364fb_invalidate_display(s); } else { switch (addr) { - case REG_DISPLAYX: - s->scr_width =3D (s->scr_width & 0xfffffc03) | (val << 2= ); + case REG_ID: /* Card identifier; read-only */ + case REG_BOOT: /* Boot timing */ + case 0x80108: /* Line timing: half sync */ + case 0x80110: /* Line timing: back porch */ + case 0x80120: /* Line timing: short display */ + case 0x80128: /* Frame timing: broad pulse */ + case 0x80130: /* Frame timing: v sync */ + case 0x80138: /* Frame timing: v preequalise */ + case 0x80140: /* Frame timing: v postequalise */ + case 0x80148: /* Frame timing: v blank */ + case 0x80158: /* Line timing: line time */ + case 0x80160: /* Frame store: line start */ + case 0x80168: /* vram cycle: mem init */ + case 0x80170: /* vram cycle: transfer delay */ + case 0x80200: /* vram cycle: mask register */ + /* ignore */ break; - case REG_DISPLAYX + 1: - s->scr_width =3D (s->scr_width & 0xfffc03ff) | (val << 1= 0); + case REG_TOP: + s->top_of_screen =3D val; + g364fb_invalidate_display(s); break; - case REG_DISPLAYY: - s->scr_height =3D (s->scr_height & 0xffffff80) | (val >>= 1); + case REG_DISPLAY: + s->width =3D val * 4; break; - case REG_DISPLAYY + 1: - s->scr_height =3D (s->scr_height & 0xffff801f) | (val <<= 7); + case REG_VDISPLAY: + s->height =3D val / 2; break; + case REG_CTLA: + s->ctla =3D val; + g364fb_update_depth(s); + g364fb_invalidate_display(s); + break; + case REG_CURS_POS: + g364_invalidate_cursor_position(s); + s->cursor_position =3D val; + g364_invalidate_cursor_position(s); + break; + case REG_RESET: + g364fb_reset(s); + break; default: -#ifdef DEBUG_G364 - printf("g364fb/ctrl: invalid write of 0x%02x at [" TARGE= T_FMT_lx "]\n", val, addr); -#endif + BADF("invalid write of 0x%08x at [" TARGET_FMT_plx "]\n"= , val, addr); break; } } - s->graphic_mode =3D -1; /* force full update */ + qemu_irq_lower(s->irq); } =20 static void g364fb_ctrl_writew(void *opaque, target_phys_addr_t addr, ui= nt32_t val) { - g364fb_ctrl_writeb(opaque, addr, val & 0xff); - g364fb_ctrl_writeb(opaque, addr + 1, (val >> 8) & 0xff); + uint32_t old_val =3D g364fb_ctrl_readl(opaque, addr & ~0x3); + + if (addr & 0x2) + val =3D (val << 16) | (old_val & 0x0000ffff); + else + val =3D val | (old_val & 0xffff0000); + g364fb_ctrl_writel(opaque, addr & ~0x3, val); } =20 -static void g364fb_ctrl_writel(void *opaque, target_phys_addr_t addr, ui= nt32_t val) +static void g364fb_ctrl_writeb(void *opaque, target_phys_addr_t addr, ui= nt32_t val) { - g364fb_ctrl_writeb(opaque, addr, val & 0xff); - g364fb_ctrl_writeb(opaque, addr + 1, (val >> 8) & 0xff); - g364fb_ctrl_writeb(opaque, addr + 2, (val >> 16) & 0xff); - g364fb_ctrl_writeb(opaque, addr + 3, (val >> 24) & 0xff); + uint32_t old_val =3D g364fb_ctrl_readl(opaque, addr & ~0x3); + + switch (addr & 3) { + case 0: + val =3D val | (old_val & 0xffffff00); + break; + case 1: + val =3D (val << 8) | (old_val & 0xffff00ff); + break; + case 2: + val =3D (val << 16) | (old_val & 0xff00ffff); + break; + case 3: + val =3D (val << 24) | (old_val & 0x00ffffff); + break; + } + g364fb_ctrl_writel(opaque, addr & ~0x3, val); } =20 static CPUReadMemoryFunc *g364fb_ctrl_read[3] =3D { @@ -295,93 +536,86 @@ g364fb_ctrl_writel, }; =20 -/* called for accesses to video ram */ -static uint32_t g364fb_mem_readb(void *opaque, target_phys_addr_t addr) +static int g364fb_load(QEMUFile *f, void *opaque, int version_id) { G364State *s =3D opaque; + unsigned int i, vram_size; =20 - return s->vram_buffer[addr]; -} + if (version_id !=3D 1) + return -EINVAL; =20 -static uint32_t g364fb_mem_readw(void *opaque, target_phys_addr_t addr) -{ - uint32_t v; - v =3D g364fb_mem_readb(opaque, addr); - v |=3D g364fb_mem_readb(opaque, addr + 1) << 8; - return v; -} + vram_size =3D qemu_get_be32(f); + if (vram_size < s->vram_size) + return -EINVAL; + qemu_get_buffer(f, s->vram, s->vram_size); + for (i =3D 0; i < 256; i++) + qemu_get_buffer(f, s->color_palette[i], 3); + for (i =3D 0; i < 3; i++) + qemu_get_buffer(f, s->cursor_palette[i], 3); + qemu_get_buffer(f, (uint8_t *)s->cursor, sizeof(s->cursor)); + s->cursor_position =3D qemu_get_be32(f); + s->ctla =3D qemu_get_be32(f); + s->top_of_screen =3D qemu_get_be32(f); + s->width =3D qemu_get_be32(f); + s->height =3D qemu_get_be32(f); =20 -static uint32_t g364fb_mem_readl(void *opaque, target_phys_addr_t addr) -{ - uint32_t v; - v =3D g364fb_mem_readb(opaque, addr); - v |=3D g364fb_mem_readb(opaque, addr + 1) << 8; - v |=3D g364fb_mem_readb(opaque, addr + 2) << 16; - v |=3D g364fb_mem_readb(opaque, addr + 3) << 24; - return v; + /* force refresh */ + g364fb_update_depth(s); + g364fb_invalidate_display(s); + + return 0; } =20 -static void g364fb_mem_writeb(void *opaque, target_phys_addr_t addr, uin= t32_t val) +static void g364fb_save(QEMUFile *f, void *opaque) { G364State *s =3D opaque; + int i; =20 - s->vram_buffer[addr] =3D val; + qemu_put_be32(f, s->vram_size); + qemu_put_buffer(f, s->vram, s->vram_size); + for (i =3D 0; i < 256; i++) + qemu_put_buffer(f, s->color_palette[i], 3); + for (i =3D 0; i < 3; i++) + qemu_put_buffer(f, s->cursor_palette[i], 3); + qemu_put_buffer(f, (uint8_t *)s->cursor, sizeof(s->cursor)); + qemu_put_be32(f, s->cursor_position); + qemu_put_be32(f, s->ctla); + qemu_put_be32(f, s->top_of_screen); + qemu_put_be32(f, s->width); + qemu_put_be32(f, s->height); } =20 -static void g364fb_mem_writew(void *opaque, target_phys_addr_t addr, uin= t32_t val) -{ - g364fb_mem_writeb(opaque, addr, val & 0xff); - g364fb_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff); -} - -static void g364fb_mem_writel(void *opaque, target_phys_addr_t addr, uin= t32_t val) -{ - g364fb_mem_writeb(opaque, addr, val & 0xff); - g364fb_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff); - g364fb_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff); - g364fb_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff); -} - -static CPUReadMemoryFunc *g364fb_mem_read[3] =3D { - g364fb_mem_readb, - g364fb_mem_readw, - g364fb_mem_readl, -}; - -static CPUWriteMemoryFunc *g364fb_mem_write[3] =3D { - g364fb_mem_writeb, - g364fb_mem_writew, - g364fb_mem_writel, -}; - int g364fb_mm_init(DisplayState *ds, - int vram_size, int it_shift, - target_phys_addr_t vram_base, target_phys_addr_t ctrl= _base) + uint8_t *vram, unsigned long vram_offset, + int vram_size, target_phys_addr_t vram_base, + target_phys_addr_t ctrl_base, int it_shift, + qemu_irq irq) { G364State *s; - int io_vram, io_ctrl; + int io_ctrl; =20 s =3D qemu_mallocz(sizeof(G364State)); if (!s) return -1; =20 + s->ds =3D ds; + s->vram =3D vram; + s->vram_offset =3D vram_offset; s->vram_size =3D vram_size; - s->vram_buffer =3D qemu_mallocz(s->vram_size); + s->irq =3D irq; =20 qemu_register_reset(g364fb_reset, s); + register_savevm("g364fb", 0, 1, g364fb_save, g364fb_load, s); g364fb_reset(s); =20 - s->ds =3D ds; - s->console =3D graphic_console_init(ds, g364fb_update_display, g364fb_invalidate_display, g364fb_screen_dump, NULL, s); =20 - io_vram =3D cpu_register_io_memory(0, g364fb_mem_read, g364fb_mem_wr= ite, s); - cpu_register_physical_memory(vram_base, vram_size, io_vram); + cpu_register_physical_memory(vram_base, s->vram_size, s->vram_offset= ); =20 io_ctrl =3D cpu_register_io_memory(0, g364fb_ctrl_read, g364fb_ctrl_= write, s); - cpu_register_physical_memory(ctrl_base, 0x10000, io_ctrl); + cpu_register_physical_memory(ctrl_base, 0x200000, io_ctrl); =20 return 0; } Index: hw/g364fb_template.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- hw/g364fb_template.h (revision 6267) +++ /dev/null (working copy) @@ -1,42 +0,0 @@ -/* - * QEMU G364 framebuffer Emulator. - * - * Copyright (c) 2007 Herv=C3=A9 Poussineau - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License alo= ng - * with this program; if not, write to the Free Software Foundation, Inc= ., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -static void glue(g364fb_draw_graphic, BPP)(G364State *s, int full_update= ) -{ - int i, j; - int w_display; - uint8_t *data_buffer; - uint8_t *data_display, *dd; - - data_buffer =3D s->vram_buffer; - w_display =3D s->scr_width * PIXEL_WIDTH / 8; - data_display =3D ds_get_data(s->ds); - for(i =3D 0; i < s->scr_height; i++) { - dd =3D data_display; - for (j =3D 0; j < s->scr_width; j++, dd +=3D PIXEL_WIDTH / 8, da= ta_buffer++) { - uint8_t index =3D *data_buffer; - *((glue(glue(uint, PIXEL_WIDTH), _t) *)dd) =3D glue(rgb_to_p= ixel, BPP)( - s->palette[index][0], - s->palette[index][1], - s->palette[index][2]); - } - data_display +=3D ds_get_linesize(s->ds); - } -} Index: hw/mips.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- hw/mips.h (revision 6267) +++ hw/mips.h (working copy) @@ -11,8 +11,10 @@ =20 /* g364fb.c */ int g364fb_mm_init(DisplayState *ds, - int vram_size, int it_shift, - target_phys_addr_t vram_base, target_phys_addr_t ctrl= _base); + uint8_t *vram, unsigned long vram_offset, + int vram_size, target_phys_addr_t vram_base, + target_phys_addr_t ctrl_base, int it_shift, + qemu_irq irq); =20 /* mipsnet.c */ void mipsnet_init(int base, qemu_irq irq, NICInfo *nd); Index: hw/mips_jazz.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- hw/mips_jazz.c (revision 6267) +++ hw/mips_jazz.c (working copy) @@ -201,7 +201,8 @@ /* Video card */ switch (jazz_model) { case JAZZ_MAGNUM: - g364fb_mm_init(ds, vga_ram_size, 0, 0x40000000, 0x60000000); + g364fb_mm_init(ds, phys_ram_base + ram_size, ram_size, vga_ram_s= ize, + 0x40000000, 0x60000000, 0, rc4030[3]); break; case JAZZ_PICA61: isa_vga_mm_init(ds, phys_ram_base + ram_size, ram_size, vga_ram_= size, --------------080905080602000400080608--