qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE?
@ 2014-05-18 12:48 Mark Cave-Ayland
  2014-05-18 16:06 ` Olivier Danet
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Cave-Ayland @ 2014-05-18 12:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, Richard Henderson

Hi all,

I've been working on debugging a window-related OpenBIOS issue and 
noticed that the cwp register logic in QEMU appears to be backwards 
according to the SPARCv9 specification. From sections 6.3.6.1 and 6.3.6.2:

"The SAVE instruction allocates a new register window and saves the 
caller’s register window by incrementing the CWP register."

"The RESTORE instruction restores the previous register window by 
decrementing the CWP register."

In target-sparc/win_helper.c the logic in helper_save() and 
helper_restore() is inverted, i.e. executing SAVE decrements cwp while 
executing RESTORE increments cwp.

The surprise here was that executing SAVE when cwp == 0 changed cwp to 7 
rather than 1. AFAICT there should be no functional difference, but it 
would make things less confusing when debugging window traps if the 
logic from the specification was followed. Does anyone know why this is 
currently done this way?


ATB,

Mark.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE?
  2014-05-18 12:48 [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE? Mark Cave-Ayland
@ 2014-05-18 16:06 ` Olivier Danet
  2014-05-19 10:56   ` Mark Cave-Ayland
  0 siblings, 1 reply; 4+ messages in thread
From: Olivier Danet @ 2014-05-18 16:06 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel; +Cc: Blue Swirl, Richard Henderson

On 18/05/2014 14:48, Mark Cave-Ayland wrote:
> Hi all,
> 
> I've been working on debugging a window-related OpenBIOS issue and noticed that the cwp register logic in QEMU appears to be backwards according to the SPARCv9 specification. From sections 6.3.6.1 and 6.3.6.2:
> 
> "The SAVE instruction allocates a new register window and saves the caller’s register window by incrementing the CWP register."
> 
> "The RESTORE instruction restores the previous register window by decrementing the CWP register."
> 
> In target-sparc/win_helper.c the logic in helper_save() and helper_restore() is inverted, i.e. executing SAVE decrements cwp while executing RESTORE increments cwp.
> 
> The surprise here was that executing SAVE when cwp == 0 changed cwp to 7 rather than 1. AFAICT there should be no functional difference, but it would make things less confusing when debugging window traps if the logic from the specification was followed. Does anyone know why this is currently done this way?
> 
> 
> ATB,
> 
> Mark.
> 
The problem may be related to the fact that the 32bits SPARCv8 and 64bits SPARCv9 work in opposite directions !

SparcV9 standard, page 360/399 :
The SPARC-V9 CWP register is incremented during a SAVE instruction and decremented during
a RESTORE instruction. Although this is the opposite of PSR.CWP’s behavior in SPARC-V8, the
only software it should affect is a few trap handlers that operate in privileged mode, and that must
be rewritten for SPARC-V9 anyway. This change will have no effect on nonprivileged software.


Olivier

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE?
  2014-05-18 16:06 ` Olivier Danet
@ 2014-05-19 10:56   ` Mark Cave-Ayland
  2014-05-24  6:26     ` Blue Swirl
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Cave-Ayland @ 2014-05-19 10:56 UTC (permalink / raw)
  To: Olivier Danet, qemu-devel; +Cc: Blue Swirl, Richard Henderson

On 18/05/14 17:06, Olivier Danet wrote:

> The problem may be related to the fact that the 32bits SPARCv8 and 64bits SPARCv9 work in opposite directions !
>
> SparcV9 standard, page 360/399 :
> The SPARC-V9 CWP register is incremented during a SAVE instruction and decremented during
> a RESTORE instruction. Although this is the opposite of PSR.CWP’s behavior in SPARC-V8, the
> only software it should affect is a few trap handlers that operate in privileged mode, and that must
> be rewritten for SPARC-V9 anyway. This change will have no effect on nonprivileged software.

Ah I wonder if that could be it? I did try swapping the 
increment/decrement operators around in the helpers, however OpenBIOS 
crashed fairly early on so it's obviously not as simple as that. I 
suspect that because a lot of the code is shared been v8/v9 then there 
are some other assumptions that would need to be corrected for this to 
work :/


ATB,

Mark.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE?
  2014-05-19 10:56   ` Mark Cave-Ayland
@ 2014-05-24  6:26     ` Blue Swirl
  0 siblings, 0 replies; 4+ messages in thread
From: Blue Swirl @ 2014-05-24  6:26 UTC (permalink / raw)
  To: Mark Cave-Ayland; +Cc: Richard Henderson, Olivier Danet, qemu-devel

On Mon, May 19, 2014 at 1:56 PM, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> On 18/05/14 17:06, Olivier Danet wrote:
>
>> The problem may be related to the fact that the 32bits SPARCv8 and 64bits
>> SPARCv9 work in opposite directions !
>>
>> SparcV9 standard, page 360/399 :
>> The SPARC-V9 CWP register is incremented during a SAVE instruction and
>> decremented during
>> a RESTORE instruction. Although this is the opposite of PSR.CWP’s behavior
>> in SPARC-V8, the
>> only software it should affect is a few trap handlers that operate in
>> privileged mode, and that must
>> be rewritten for SPARC-V9 anyway. This change will have no effect on
>> nonprivileged software.
>
>
> Ah I wonder if that could be it? I did try swapping the increment/decrement
> operators around in the helpers, however OpenBIOS crashed fairly early on so
> it's obviously not as simple as that. I suspect that because a lot of the
> code is shared been v8/v9 then there are some other assumptions that would
> need to be corrected for this to work :/

Yes, QEMU uses v8 register window layout internally also for v9, guest
only sees fixed up CWP. IIRC using v9 layout internally would mean
adjusting a lot of places for marginal performance gains.
Alternatively v9 layout could be used, fixing up CWP for v8.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-24  6:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-18 12:48 [Qemu-devel] target-sparc has inverse cwp logic for SAVE/RESTORE? Mark Cave-Ayland
2014-05-18 16:06 ` Olivier Danet
2014-05-19 10:56   ` Mark Cave-Ayland
2014-05-24  6:26     ` Blue Swirl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).