ati: fix ati_cursor_define bug.
cover ati: fix ati_cursor_define bug.
Gerd Hoffmann (2):
vga: move access helpers to separate include file
ati: use vga_read_byte in ati_cursor_define
hw/display/vga-access.h | 49 ++++++++++++++++++++++++++++++++++++++++ hw/display/vga-helpers.h | 26 --------------------- hw/display/ati.c | 11 +++++---- hw/display/vga.c | 1 + 4 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 hw/display/vga-access.h
Signature · 1 line
2.18.1
PATCH 1/2 vga: move access helpers to separate include file
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/display/vga-access.h | 49 ++++++++++++++++++++++++++++++++++++++++ hw/display/vga-helpers.h | 26 --------------------- hw/display/vga.c | 1 + 3 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 hw/display/vga-access.h
hw/display/vga-access.h new file +49 -0
@@ -0,0 +1,49 @@ +/* +* QEMU VGA Emulator templates +* +* Copyright (c) 2003 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +static inline uint8_t vga_read_byte (VGACommonState *vga,uint32_t addr) +{ +return vga->vram_ptr[addr & vga->vbe_size_mask]; +} + +static inline uint16_t vga_read_word_le (VGACommonState *vga,uint32_t addr) +{ +uint32_t offset = addr & vga->vbe_size_mask & ~1 ; +uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset); +return lduw_le_p (ptr); +} + +static inline uint16_t vga_read_word_be (VGACommonState *vga,uint32_t addr) +{ +uint32_t offset = addr & vga->vbe_size_mask & ~1 ; +uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset); +return lduw_be_p (ptr); +} + +static inline uint32_t vga_read_dword_le (VGACommonState *vga,uint32_t addr) +{ +uint32_t offset = addr & vga->vbe_size_mask & ~3 ; +uint32_t *ptr = (uint32_t *)(vga->vram_ptr + offset); +return ldl_le_p (ptr); +}
hw/display/vga-helpers.h +0 -26
@@ -95,32 +95,6 @@ static void vga_draw_glyph9(uint8_t *d, int linesize, }while (--h); } -static inline uint8_t vga_read_byte (VGACommonState *vga,uint32_t addr) -{ -return vga->vram_ptr[addr & vga->vbe_size_mask]; -} - -static inline uint16_t vga_read_word_le (VGACommonState *vga,uint32_t addr) -{ -uint32_t offset = addr & vga->vbe_size_mask & ~1 ; -uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset); -return lduw_le_p (ptr); -} - -static inline uint16_t vga_read_word_be (VGACommonState *vga,uint32_t addr) -{ -uint32_t offset = addr & vga->vbe_size_mask & ~1 ; -uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset); -return lduw_be_p (ptr); -} - -static inline uint32_t vga_read_dword_le (VGACommonState *vga,uint32_t addr) -{ -uint32_t offset = addr & vga->vbe_size_mask & ~3 ; -uint32_t *ptr = (uint32_t *)(vga->vram_ptr + offset); -return ldl_le_p (ptr); -} -/* * 4 color mode */
hw/display/vga.c +1 -0
@@ -1009,6 +1009,7 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val)typedef void vga_draw_line_func (VGACommonState *s1,uint8_t *d,uint32_t srcaddr,int width); +#include "vga-access.h" #include "vga-helpers.h" /* return true if the palette was modified */
Signature · 1 line
2.18.1
PATCH 2/2 ati: use vga_read_byte in ati_cursor_define
In reply to Gerd HoffmannThis makes sure reads are confined to vga video memory.
Reported-by xu hang <[email protected]>
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/display/ati.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
hw/display/ati.c +6 -5
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "ati_int.h" #include "ati_regs.h" +#include "vga-access.h" #include "hw/qdev-properties.h" #include "vga_regs.h" #include "qemu/log.h"
@@ -135,19 +136,19 @@ static void ati_vga_switch_mode(ATIVGAState *s)static void ati_cursor_define (ATIVGAState *s) {uint8_t data[1024 ]; -uint8_t *src; +unsigned srcoff;int i, j, idx =0 ;if ((s->regs.cur_offset &BIT (31 )) || s->cursor_guest_mode) {return ;/* Do not update cursor if locked or rendered by guest */ }/* FIXME handle cur_hv_offs correctly */ - src = s->vga.vram_ptr + s->regs.cur_offset - - (s->regs.cur_hv_offs >>16 ) - (s->regs.cur_hv_offs &0xffff ) *16 ; + srcoff = s->regs.cur_offset - + (s->regs.cur_hv_offs >>16 ) - (s->regs.cur_hv_offs &0xffff ) *16 ;for (i =0 ; i <64 ; i++) {for (j =0 ; j <8 ; j++, idx++) { - data[idx] = src[i *16 + j]; - data[512 + idx] = src[i *16 + j +8 ]; + data[idx] =vga_read_byte (&s->vga, srcoff + i *16 + j); + data[512 + idx] =vga_read_byte (&s->vga, srcoff + i *16 + j +8 ); } }if (!s->cursor) {
Signature · 1 line
2.18.1
Re: [Qemu-devel] [PATCH 2/2] ati: use vga_read_byte in ati_cursor_define
Quoted 26 lines · Gerd Hoffmann
This makes sure reads are confined to vga video memory.
Reported-by xu hang <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>---
hw/display/ati.c| 11 ++++++-----1 file changed, 6 insertions(+), 5 deletions(-)hw/display/ati.c +2
-1@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "ati_int.h" #include "ati_regs.h" +#include "vga-access.h" #include "hw/qdev-properties.h" #include "vga_regs.h" #include "qemu/log.h" @@ -135,19 +136,19 @@ static void ati_vga_switch_mode(ATIVGAState *s)static void ati_cursor_define (ATIVGAState *s) {uint8_t data[1024 ]; -uint8_t *src; +unsigned srcoff;
hw/display/ati.c static void ati_vga_switch_mode(ATIVGAState *s) · line 147
Quoted 10 lines
hw/display/ati.c +2
-2int i, j, idx =0 ;if ((s->regs.cur_offset &BIT (31 )) || s->cursor_guest_mode) {return ;/* Do not update cursor if locked or rendered by guest */ }/* FIXME handle cur_hv_offs correctly */ - src = s->vga.vram_ptr + s->regs.cur_offset - - (s->regs.cur_hv_offs >>16 ) - (s->regs.cur_hv_offs &0xffff ) *16 ; + srcoff = s->regs.cur_offset - + (s->regs.cur_hv_offs >>16 ) - (s->regs.cur_hv_offs &0xffff ) *16 ;
Do we need similar fix in ati_cursor_draw_line() as well which also accesses cursor data when guest_hwcursor property is true?
Regards,
BALATON Zoltan
Quoted 10 lines
hw/display/ati.c +2
-2for (i =0 ; i <64 ; i++) {for (j =0 ; j <8 ; j++, idx++) { - data[idx] = src[i *16 + j]; - data[512 + idx] = src[i *16 + j +8 ]; + data[idx] =vga_read_byte (&s->vga, srcoff + i *16 + j); + data[512 + idx] =vga_read_byte (&s->vga, srcoff + i *16 + j +8 ); } }if (!s->cursor) {