Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jlgVX-0002Og-Vh for mharc-qemu-trivial@gnu.org; Wed, 17 Jun 2020 18:26:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlgVV-0002Lx-Dj; Wed, 17 Jun 2020 18:26:09 -0400 Received: from mta-out1.inet.fi ([62.71.2.226]:54262 helo=julia1.inet.fi) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlgVS-0006He-UP; Wed, 17 Jun 2020 18:26:09 -0400 Received: from [91.154.154.51] (91.154.154.51) by julia1.inet.fi (9.0.019.26-1) (authenticated as perall-2) id 5EEA260E00020150; Thu, 18 Jun 2020 01:25:28 +0300 Subject: Re: [PATCH] hw/audio/gus: Fix registers 32-bit access To: Peter Maydell Cc: QEMU Developers , QEMU Trivial , Gerd Hoffmann References: <20200615201757.16868-1-aperamak@pp1.inet.fi> From: Allan Peramaki Message-ID: <87e628f4-6c0e-c4a2-daba-57cb1e508b77@pp1.inet.fi> Date: Thu, 18 Jun 2020 01:25:27 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=62.71.2.226; envelope-from=aperamak@pp1.inet.fi; helo=julia1.inet.fi X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 18:26:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2020 22:26:09 -0000 On 17/06/2020 23:23, Peter Maydell wrote: > > This patch is quite difficult to read because it mixes some > whitespace only changes with some actual changes of > behaviour. Sorry about that. I had to put some whitespace in the two lines I modified because of checkpatch.pl, but then the nearby lines would have had inconsistent style if left unmodified. On the other hand, QEMU wiki said it is ok to fix style issues in the immediate area. > So, I think the actual bugfix change here is just the changing > of uint16_t to uint32_t in the GUSregd definition... > >> -#define GUSregb(position) (* (gusptr+(position))) >> -#define GUSregw(position) (*(uint16_t *) (gusptr+(position))) >> -#define GUSregd(position) (*(uint16_t *)(gusptr+(position))) >> +#define GUSregb(position) (*(gusptr + (position))) >> +#define GUSregw(position) (*(uint16_t *)(gusptr + (position))) >> +#define GUSregd(position) (*(uint32_t *)(gusptr + (position))) > > ...and similarly here, and all the other changes are purely > cleaning up the spaces. Is that right? That's right. The only real change is uint16_t -> uint32_t in GUSregd. This reverses what seems to be an accident in commit 135f5ae1974c, where GUSdword (defined as "unsigned int" or "uint32_t" depending on compiler) was replaced with uint16_t. That change broke applications that read/write DRAM above 64k via I/O ports (in lieu of using DMA.) > >> -#define GUSvoice(position) (*(uint16_t *)(voiceptr+(position))) >> +#define GUSvoice(position) (*(uint16_t *)(voiceptr + (position))) > > Are these accesses all guaranteed to be correctly aligned > to be 16 or 32 bit loads/stores ? Otherwise it would be > better to use the ldl_p/stl_p/ldw_p/stw_p/etc accessors, > which correctly handle possibly misaligned pointers. Yes (assuming compiler aligns struct fields properly.) It is not obvious though (and easy to break), so I suppose refactoring much of the GUS code would be nice. For example, the few places where GUSregd(position) is used, position is 2 (mod 4). On the other hand, gusptr is also 2 (mod 4) bytes (making gusptr+position = 0 (mod 4)), because we have the struct typedef struct GUSState { ISADevice dev; GUSEmuState emu; QEMUSoundCard card; uint32_t freq; uint32_t port; int pos, left, shift, irqs; int16_t *mixbuf; uint8_t himem[1024 * 1024 + 32 + 4096]; int samples; SWVoiceOut *voice; int64_t last_ticks; qemu_irq pic; IsaDma *isa_dma; PortioList portio_list1; PortioList portio_list2; } GUSState; where himem is 2 (mod 4). When GUSregd() is used, gusptr is (himem + 1024 * 1024 + 32), so gusptr is also 2 (mod 4). Similar applies to GUSvoice(position). Best regards, Allan