diff mbox

[kvm-unit-tests,3/5] powerpc: check 64bit mode

Message ID 1458141183-27207-4-git-send-email-lvivier@redhat.com
State Superseded
Headers show

Commit Message

Laurent Vivier March 16, 2016, 3:13 p.m. UTC
Check in MSR if the SF bit is set (64bit mode is enabled)

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 powerpc/emulator.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Thomas Huth March 18, 2016, 8:28 a.m. UTC | #1
On 16.03.2016 16:13, Laurent Vivier wrote:
> Check in MSR if the SF bit is set (64bit mode is enabled)
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  powerpc/emulator.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/powerpc/emulator.c b/powerpc/emulator.c
> index 1215c4f..b66c1d7 100644
> --- a/powerpc/emulator.c
> +++ b/powerpc/emulator.c
> @@ -32,12 +32,26 @@ static void test_illegal(void)
>  	report_prefix_pop();
>  }
>  
> +static void test_64bit(void)
> +{
> +	uint64_t msr;
> +
> +	report_prefix_push("64bit");
> +
> +	asm("mfmsr %[msr]": [msr] "=r" (msr));
> +
> +	report("detected", msr & 0x8000000000000000UL);
> +
> +	report_prefix_pop();
> +}
> +
>  int main(void)
>  {
>  	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
>  
>  	report_prefix_push("emulator");
>  
> +	test_64bit();
>  	test_illegal();
>  
>  	report_prefix_pop();

Reviewed-by: Thomas Huth <thuth@redhat.com>

But I still wonder how kvm-unit-tests worked at all before the 64-bit
mode has been fixed in QEMU ... I mean kvm-unit-tests is compiled with
64-bit code, but it's still working when run in 32-bit? Something really
strange was going on here...

 Thomas

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paul Mackerras March 18, 2016, 8:38 a.m. UTC | #2
On Fri, Mar 18, 2016 at 09:28:33AM +0100, Thomas Huth wrote:
> On 16.03.2016 16:13, Laurent Vivier wrote:
> > Check in MSR if the SF bit is set (64bit mode is enabled)
> > 
> > Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> > ---
> >  powerpc/emulator.c | 14 ++++++++++++++f958ee745f70
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/powerpc/emulator.c b/powerpc/emulator.c
> > index 1215c4f..b66c1d7 100644
> > --- a/powerpc/emulator.c
> > +++ b/powerpc/emulator.c
> > @@ -32,12 +32,26 @@ static void test_illegal(void)
> >  	report_prefix_pop();
> >  }
> >  
> > +static void test_64bit(void)
> > +{
> > +	uint64_t msr;
> > +
> > +	report_prefix_push("64bit");
> > +
> > +	asm("mfmsr %[msr]": [msr] "=r" (msr));
> > +
> > +	report("detected", msr & 0x8000000000000000UL);
> > +
> > +	report_prefix_pop();
> > +}
> > +
> >  int main(void)
> >  {
> >  	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
> >  
> >  	report_prefix_push("emulator");
> >  
> > +	test_64bit();
> >  	test_illegal();
> >  
> >  	report_prefix_pop();
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 
> But I still wonder how kvm-unit-tests worked at all before the 64-bit
> mode has been fixed in QEMU ... I mean kvm-unit-tests is compiled with
> 64-bit code, but it's still working when run in 32-bit? Something really
> strange was going on here...

On Power processors, there's not as much difference between 32-bit and
64-bit mode as you might expect.  In 32-bit mode on a 64-bit
processor, you can use all 64 bits of the registers and execute 64-bit
instructions.  The only things that change in 32-bit mode are that (a)
effective addresses are truncated to 32 bits and (b) dot-form
instructions (e.g. "add.") set CR0 based on the 32-bit result rather
than the 64-bit result.

Paul.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thomas Huth March 18, 2016, 8:41 a.m. UTC | #3
On 18.03.2016 09:38, Paul Mackerras wrote:
> On Fri, Mar 18, 2016 at 09:28:33AM +0100, Thomas Huth wrote:
>> On 16.03.2016 16:13, Laurent Vivier wrote:
>>> Check in MSR if the SF bit is set (64bit mode is enabled)
>>>
>>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>>> ---
>>>  powerpc/emulator.c | 14 ++++++++++++++f958ee745f70
>>>  1 file changed, 14 insertions(+)
>>>
>>> diff --git a/powerpc/emulator.c b/powerpc/emulator.c
>>> index 1215c4f..b66c1d7 100644
>>> --- a/powerpc/emulator.c
>>> +++ b/powerpc/emulator.c
>>> @@ -32,12 +32,26 @@ static void test_illegal(void)
>>>  	report_prefix_pop();
>>>  }
>>>  
>>> +static void test_64bit(void)
>>> +{
>>> +	uint64_t msr;
>>> +
>>> +	report_prefix_push("64bit");
>>> +
>>> +	asm("mfmsr %[msr]": [msr] "=r" (msr));
>>> +
>>> +	report("detected", msr & 0x8000000000000000UL);
>>> +
>>> +	report_prefix_pop();
>>> +}
>>> +
>>>  int main(void)
>>>  {
>>>  	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
>>>  
>>>  	report_prefix_push("emulator");
>>>  
>>> +	test_64bit();
>>>  	test_illegal();
>>>  
>>>  	report_prefix_pop();
>>
>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>
>> But I still wonder how kvm-unit-tests worked at all before the 64-bit
>> mode has been fixed in QEMU ... I mean kvm-unit-tests is compiled with
>> 64-bit code, but it's still working when run in 32-bit? Something really
>> strange was going on here...
> 
> On Power processors, there's not as much difference between 32-bit and
> 64-bit mode as you might expect.  In 32-bit mode on a 64-bit
> processor, you can use all 64 bits of the registers and execute 64-bit
> instructions.  The only things that change in 32-bit mode are that (a)
> effective addresses are truncated to 32 bits and (b) dot-form
> instructions (e.g. "add.") set CR0 based on the 32-bit result rather
> than the 64-bit result.

Ah, ok, ... and since kvm-unit-tests normally does not use the RAM > 4
GB, we didn't notice the truncation. Makes sense.
Thanks for the clarification!

 Thomas

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/powerpc/emulator.c b/powerpc/emulator.c
index 1215c4f..b66c1d7 100644
--- a/powerpc/emulator.c
+++ b/powerpc/emulator.c
@@ -32,12 +32,26 @@  static void test_illegal(void)
 	report_prefix_pop();
 }
 
+static void test_64bit(void)
+{
+	uint64_t msr;
+
+	report_prefix_push("64bit");
+
+	asm("mfmsr %[msr]": [msr] "=r" (msr));
+
+	report("detected", msr & 0x8000000000000000UL);
+
+	report_prefix_pop();
+}
+
 int main(void)
 {
 	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
 
 	report_prefix_push("emulator");
 
+	test_64bit();
 	test_illegal();
 
 	report_prefix_pop();