Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C5kZV-0002cf-Bn for qemu-devel@nongnu.org; Fri, 10 Sep 2004 08:32:09 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C5kZO-0002a4-O8 for qemu-devel@nongnu.org; Fri, 10 Sep 2004 08:32:09 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C5kZO-0002a1-Mi for qemu-devel@nongnu.org; Fri, 10 Sep 2004 08:32:02 -0400 Received: from [206.190.39.124] (helo=web52503.mail.yahoo.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1C5kTn-0003Hu-Hv for qemu-devel@nongnu.org; Fri, 10 Sep 2004 08:26:15 -0400 Message-ID: <20040910122612.45544.qmail@web52503.mail.yahoo.com> Date: Fri, 10 Sep 2004 05:26:12 -0700 (PDT) From: Piotr Krysik Subject: Re: [Qemu-devel] [patch] incorrect VGA initialization, can provide image In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-142074114-1094819172=:45230" 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 --0-142074114-1094819172=:45230 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline Hi, Thanks for your comment. I updated the patch to factor common code from vga_mem_writeb and remove goto. The source should be easer to read now. Regards, Piotrek --- Johannes Schindelin wrote: > Hi, > > why not consolidate those identical lines (checking > if the address is in > font memory) into a function? > > Just a thought, > Dscho __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail --0-142074114-1094819172=:45230 Content-Type: text/x-patch; name="vga-update-2.patch" Content-Description: vga-update-2.patch Content-Disposition: inline; filename="vga-update-2.patch" diff -ru qemu-snapshot-2004-08-04_23/hw/vga.c qemu-snapshot-2004-08-04_23-vga-update/hw/vga.c --- qemu-snapshot-2004-08-04_23/hw/vga.c 2004-06-26 18:12:26.000000000 +0200 +++ qemu-snapshot-2004-08-04_23-vga-update/hw/vga.c 2004-09-10 13:50:36.000000000 +0200 @@ -658,12 +658,47 @@ return v; } +/* write byte to video ram */ +static inline void vram_writeb(VGAState *s, target_phys_addr_t addr, uint32_t val) +{ +#ifdef DEBUG_VGA_MEM + printf("vga: vram: [0x%x]\n", addr); +#endif + s->vram_ptr[addr] = val; + /* force full update for vga_draw_text when writing font memory */ + if (((s->font_offsets[0] ^ addr) & ~0x7ffc) == 0 || + ((s->font_offsets[1] ^ addr) & ~0x7ffc) == 0) + s->font_offsets[0] = -1; + cpu_physical_memory_set_dirty(s->vram_offset + addr); +} + +/* write to video ram using mask in sr[2] register */ +static inline void vram_writel_sr2(VGAState *s, target_phys_addr_t addr, uint32_t val) +{ + uint32_t *ptr; + uint32_t write_mask; + + ptr = (uint32_t *)(s->vram_ptr + addr); + write_mask = mask16[s->sr[2]]; +#ifdef DEBUG_VGA_MEM + printf("vga: vram latch: [0x%x] mask=0x%08x val=0x%08x\n", + addr, write_mask, val); +#endif + *ptr = (*ptr & ~write_mask) | (val & write_mask); + /* force full update for vga_draw_text when writing font memory */ + if ((s->sr[2] & 4) && + (((s->font_offsets[0] ^ (addr + 2)) & ~0x7ffc) == 0 || + ((s->font_offsets[1] ^ (addr + 2)) & ~0x7ffc) == 0)) + s->font_offsets[0] = -1; + cpu_physical_memory_set_dirty(s->vram_offset + addr); +} + /* called for accesses between 0xa0000 and 0xc0000 */ void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) { VGAState *s = opaque; int memory_map_mode, plane, write_mode, b, func_select; - uint32_t write_mask, bit_mask, set_mask; + uint32_t bit_mask, set_mask; #ifdef DEBUG_VGA_MEM printf("vga: [0x%x] = 0x%02x\n", addr, val); @@ -696,22 +731,14 @@ /* chain 4 mode : simplest access */ plane = addr & 3; if (s->sr[2] & (1 << plane)) { - s->vram_ptr[addr] = val; -#ifdef DEBUG_VGA_MEM - printf("vga: chain4: [0x%x]\n", addr); -#endif - cpu_physical_memory_set_dirty(s->vram_offset + addr); + vram_writeb(s, addr, val); } } else if (s->gr[5] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane = (s->gr[4] & 2) | (addr & 1); if (s->sr[2] & (1 << plane)) { addr = ((addr & ~1) << 1) | plane; - s->vram_ptr[addr] = val; -#ifdef DEBUG_VGA_MEM - printf("vga: odd/even: [0x%x]\n", addr); -#endif - cpu_physical_memory_set_dirty(s->vram_offset + addr); + vram_writeb(s, addr, val); } } else { /* standard VGA latched access */ @@ -732,7 +759,8 @@ break; case 1: val = s->latch; - goto do_write; + vram_writel_sr2(s, addr << 2, val); + return; case 2: val = mask16[val & 0x0f]; bit_mask = s->gr[8]; @@ -773,17 +801,7 @@ bit_mask |= bit_mask << 16; val = (val & bit_mask) | (s->latch & ~bit_mask); - do_write: - /* mask data according to sr[2] */ - write_mask = mask16[s->sr[2]]; - ((uint32_t *)s->vram_ptr)[addr] = - (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | - (val & write_mask); -#ifdef DEBUG_VGA_MEM - printf("vga: latch: [0x%x] mask=0x%08x val=0x%08x\n", - addr * 4, write_mask, val); -#endif - cpu_physical_memory_set_dirty(s->vram_offset + (addr << 2)); + vram_writel_sr2(s, addr << 2, val); } } --0-142074114-1094819172=:45230--