Received: from eggs.gnu.org ([2001:4830:134:3::10]:36553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiA1Q-0003bH-Af for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UiA1L-0001hF-LM for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:32 -0400 Received: from mail-ea0-x231.google.com ([2a00:1450:4013:c01::231]:37628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UiA1L-0001h9-FZ for qemu-devel@nongnu.org; Thu, 30 May 2013 17:04:27 -0400 Received: by mail-ea0-f177.google.com with SMTP id q14so834681eaj.36 for ; Thu, 30 May 2013 14:04:26 -0700 (PDT) Received: from playground.lan (net-37-116-217-184.cust.dsl.vodafone.it. [37.116.217.184]) by mx.google.com with ESMTPSA id y2sm62707218eeu.2.2013.05.30.14.04.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 30 May 2013 14:04:26 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 30 May 2013 23:03:46 +0200 Message-Id: <1369947836-2638-13-git-send-email-pbonzini@redhat.com> In-Reply-To: <1369947836-2638-1-git-send-email-pbonzini@redhat.com> References: <1369947836-2638-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 12/22] exec: introduce memory_access_size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This will be used by address_space_access_valid too. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- exec.c | 27 +++++++++++++++++---------- 1 files changed, 17 insertions(+), 10 deletions(-) diff --git a/exec.c b/exec.c index 881f6ec..d640d07 100644 --- a/exec.c +++ b/exec.c @@ -1868,6 +1868,17 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) return false; } +static inline int memory_access_size(int l, hwaddr addr) +{ + if (l >= 4 && ((addr & 3) == 0)) { + return 4; + } + if (l >= 2 && ((addr & 1) == 0)) { + return 2; + } + return 1; +} + void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, int len, bool is_write) { @@ -1883,23 +1894,21 @@ void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, if (is_write) { if (!memory_access_is_direct(section->mr, is_write)) { + l = memory_access_size(l, addr1); /* XXX: could force cpu_single_env to NULL to avoid potential bugs */ - if (l >= 4 && ((addr1 & 3) == 0)) { + if (l == 4) { /* 32 bit write access */ val = ldl_p(buf); io_mem_write(section->mr, addr1, val, 4); - l = 4; - } else if (l >= 2 && ((addr1 & 1) == 0)) { + } else if (l == 2) { /* 16 bit write access */ val = lduw_p(buf); io_mem_write(section->mr, addr1, val, 2); - l = 2; } else { /* 8 bit write access */ val = ldub_p(buf); io_mem_write(section->mr, addr1, val, 1); - l = 1; } } else { addr1 += memory_region_get_ram_addr(section->mr); @@ -1911,21 +1920,19 @@ void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, } else { if (!memory_access_is_direct(section->mr, is_write)) { /* I/O case */ - if (l >= 4 && ((addr1 & 3) == 0)) { + l = memory_access_size(l, addr1); + if (l == 4) { /* 32 bit read access */ val = io_mem_read(section->mr, addr1, 4); stl_p(buf, val); - l = 4; - } else if (l >= 2 && ((addr1 & 1) == 0)) { + } else if (l == 2) { /* 16 bit read access */ val = io_mem_read(section->mr, addr1, 2); stw_p(buf, val); - l = 2; } else { /* 8 bit read access */ val = io_mem_read(section->mr, addr1, 1); stb_p(buf, val); - l = 1; } } else { /* RAM case */ -- 1.7.4.1