TBL register permissions for PPC
Hello All,
I have a question about read permissions of TBL SPR for all ppc processors:
I have discovered that my application, compiled by WindRiver diab compiler and running in vxworks OS on ppc405 architecture bumps into exception generated when trying to read TBL or TBU registers:
program
Exception current instruction address: 0x0003eb28
Machine Status Register: 0x00088200
Condition Register: 0x40000440
<<<<<Registers>>>>>
.....
<<<<<Disassembly>>>>>
0x3eb08 4e800020 blr 0x3eb0c 3860ffff li r3,0xffff # -1 0x3eb10 4e800020 blr 0x3eb14 38a00000 li r5,0x0 # 0 0x3eb18 7cbc43a6 mtspr TBL,r5 0x3eb1c 7c7d43a6 mtspr TBU,r3 0x3eb20 7c9c43a6 mtspr TBL,r4 0x3eb24 4e800020 blr *0x3eb28 7cbd42a6 mfspr r5,TBU 0x3eb2c 7cdc42a6 mfspr r6,TBL 0x3eb30 7cfd42a6 mfspr r7,TBU 0x3eb34 7c053800 cmp crf0,0,r5,r7 0x3eb38 4082fff0 bc 0x4,2, 0x3eb28 # vxTimeBaseGet 0x3eb3c 90a30000 stw r5,0(r3) 0x3eb40 90c40000 stw r6,0(r4) 0x3eb44 4e800020 blr
<<<<<Traceback>>>>>
......
I looked into qemu mfspr instruction implementation and discovered that for some reason qemu had set NOACCESS permissions for reading this register upon CPU initialization:
/* Generic PowerPC time base */
static void gen_tbl (CPUPPCState *env)
{
spr_register(env, SPR_VTBL, "TBL",
&spr_read_tbl, SPR_NOACCESS,
&spr_read_tbl, SPR_NOACCESS,
0x00000000);
spr_register(env, SPR_TBL, "TBL",
*SPR_NOACCESS*, SPR_NOACCESS,
*SPR_NOACCESS*, &spr_write_tbl,
0x00000000);
spr_register(env, SPR_VTBU, "TBU",
&spr_read_tbu, SPR_NOACCESS,
&spr_read_tbu, SPR_NOACCESS,
0x00000000);
spr_register(env, SPR_TBU, "TBU",
*SPR_NOACCESS*, SPR_NOACCESS,
*SPR_NOACCESS*, &spr_write_tbu,
0x00000000);
}Is this a right thing to do? it's certainly either qemu bug or diab bug (which i don't think is likely, cause this code has been running on the real hw without any issues)
BR,
Dmitry I.
Signature · 2 lines
Jonathan Swift<http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html> - "May you live every day of your life."
________________________________
From: [email protected]
[mailto:[email protected]] On Behalf Of Dima Ilyevsky
Sent: Tuesday, December 01, 2009 12:33 PM
To: [email protected]
Subject: [Qemu-devel] TBL register permissions for PPC
Hello All,
I have a question about read permissions of TBL SPR for all ppc
processors:
I have discovered that my application, compiled by WindRiver
diab compiler and running in vxworks OS on ppc405 architecture bumps into exception generated when trying to read TBL or TBU registers:
Hello Dmitry,
The code in question comes from hand coded area's so this is probably not a compiler issue, now maybe there is an issue with the BSP, but that is a different question.
Does the 405 manual indicate readability of that register?
Thanks
Chris
program Exception current instruction address: 0x0003eb28 Machine Status Register: 0x00088200 Condition Register: 0x40000440 <<<<<Registers>>>>> ..... <<<<<Disassembly>>>>> 0x3eb08 4e800020 blr 0x3eb0c 3860ffff li r3,0xffff # -1 0x3eb10 4e800020 blr 0x3eb14 38a00000 li r5,0x0 # 0 0x3eb18 7cbc43a6 mtspr TBL,r5 0x3eb1c 7c7d43a6 mtspr TBU,r3 0x3eb20 7c9c43a6 mtspr TBL,r4 0x3eb24 4e800020 blr *0x3eb28 7cbd42a6 mfspr r5,TBU 0x3eb2c 7cdc42a6 mfspr r6,TBL 0x3eb30 7cfd42a6 mfspr r7,TBU 0x3eb34 7c053800 cmp crf0,0,r5,r7 0x3eb38 4082fff0 bc 0x4,2, 0x3eb28 # vxTimeBaseGet 0x3eb3c 90a30000 stw r5,0(r3) 0x3eb40 90c40000 stw r6,0(r4) 0x3eb44 4e800020 blr
<<<<<Traceback>>>>> ...... I looked into qemu mfspr instruction implementation and
discovered that for some reason qemu had set NOACCESS permissions for reading this register upon CPU initialization:
/* Generic PowerPC time base */
static void gen_tbl (CPUPPCState *env)
{
spr_register(env, SPR_VTBL, "TBL",
&spr_read_tbl, SPR_NOACCESS,
&spr_read_tbl, SPR_NOACCESS,
0x00000000);
spr_register(env, SPR_TBL, "TBL",
SPR_NOACCESS, SPR_NOACCESS,
SPR_NOACCESS, &spr_write_tbl,
0x00000000);
spr_register(env, SPR_VTBU, "TBU",
&spr_read_tbu, SPR_NOACCESS,
&spr_read_tbu, SPR_NOACCESS,
0x00000000);
spr_register(env, SPR_TBU, "TBU",
SPR_NOACCESS, SPR_NOACCESS,
SPR_NOACCESS, &spr_write_tbu,
0x00000000);
}
Is this a right thing to do? it's certainly either qemu bug ordiab bug (which i don't think is likely, cause this code has been running on the real hw without any issues)
BR, Dmitry I. -- Jonathan Swift
<http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html> -
"May you live every day of your life."
Quoted 4 lines · Dima Ilyevsky
Hello All,
I have a question about read permissions of TBL SPR for all ppc processors:
I have discovered that my application, compiled by WindRiver diab compiler and running in vxworks OS on ppc405 architecture bumps into exception generated when trying to read TBL or TBU registers:
Unless Linux does something funky, mftlb, mftbu (and mftb on 64 bit) are readable from PR=1.
int main()
{
long tbu=0, tbl=0;
asm("mftbu %0" : "=r" (tbu));
asm("mftbl %0" : "=r" (tbl));
printf("TB: %#x %#x\n", tbl, tbu);
}agraf@lychee:/tmp> ./mftb
TB: 0xc0397180 0x603
However it can't be written to:
asm("mttbl %0" : : "r" (tbl));
agraf@lychee:/tmp> ./mftb
Illegal instruction
So yes, I'd suspect a bug in qemu here. Feel free to send a patch.
Alex
Quoted 23 lines · Alexander Graf
Quoted 4 lines · Dima Ilyevsky
Hello All,
I have a question about read permissions of TBL SPR for all ppc processors:
I have discovered that my application, compiled by WindRiver diab compiler and running in vxworks OS on ppc405 architecture bumps into exception generated when trying to read TBL or TBU registers:Unless Linux does something funky, mftlb, mftbu (and mftb on 64 bit) are readable from PR=1.
int
main(){ long tbu=0, tbl=0; asm("mftbu %0" : "=r" (tbu)); asm("mftbl %0" : "=r" (tbl)); printf("TB: %#x %#x\n", tbl, tbu); }agraf@lychee:/tmp> ./mftb
TB:0xc03971800x603
Quoted 6 lines
However it can't be written to:
asm("mttbl %0" : : "r" (tbl));agraf@lychee:/tmp> ./mftb
Illegal instruction
7.2.1 Writing the Time Base
Writing the Time Base is privileged, and can be done only in hypervisor state. Reading the Time Base is not privileged; it is discussed in Chapter 4 of Book II.
Quoted 6 lines
So yes, I'd suspect a bug in qemu here. Feel free to send a patch.
Alex
Signature · 1 line
mailto:[email protected]
Hello All,
Please review patch for TBL SPR read access for generic PPC.
*Description:*
POWER specification docs define TBL/TBU SPRs as readable in user and privileged modes. Therefore SPRs permissions were changed in gen_tbl function in target-ppc/translate_init.c file.
*Testing:*
Tested with vxworks-6.2 bsp and OS on custom qemu board that includes ppc405 emulated core
BR,
Dmitry Ilyevsky
Quoted 31 lines · Alexander Graf
Quoted 3 lines · Dima Ilyevsky
Hello All,
I have a question about read permissions of TBL SPR for all ppc
processors:
Quoted 1 line
I have discovered that my application, compiled by WindRiver diab
compiler and running in vxworks OS on ppc405 architecture bumps into exception generated when trying to read TBL or TBU registers:
Unless Linux does something funky, mftlb, mftbu (and mftb on 64 bit) are readable from PR=1.
int
main(){ long tbu=0, tbl=0; asm("mftbu %0" : "=r" (tbu)); asm("mftbl %0" : "=r" (tbl)); printf("TB: %#x %#x\n", tbl, tbu); }agraf@lychee:/tmp> ./mftb
TB:0xc03971800x603However it can't be written to:
asm("mttbl %0" : : "r" (tbl));
Quoted 8 lines
agraf@lychee:/tmp> ./mftb
Illegal instructionSo yes, I'd suspect a bug in qemu here. Feel free to send a patch.
Alex
From 141bf29f5355f163205c57e98590730ed15bfb86 Mon Sep 17 00:00:00 2001
From: n/a <install@ubuntu-desktop.(none)>
Date: Thu, 25 Mar 2010 00:22:25 +0300
Subject: [PATCH] Generic PowerPC time base SPR should be accessible in user/priv modes for reading
--- target-ppc/translate_init.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
target-ppc/translate_init.c +4 -4
@@ -777,16 +777,16 @@ static void gen_tbl (CPUPPCState *env) &spr_read_tbl,SPR_NOACCESS , 0x00000000);spr_register (env,SPR_TBL ,"TBL" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbl, + &spr_read_tbl,SPR_NOACCESS , + &spr_read_tbl, &spr_write_tbl,0x00000000 );spr_register (env,SPR_VTBU ,"TBU" , &spr_read_tbu,SPR_NOACCESS , &spr_read_tbu,SPR_NOACCESS ,0x00000000 );spr_register (env,SPR_TBU ,"TBU" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbu, + &spr_read_tbu,SPR_NOACCESS , + &spr_read_tbu, &spr_write_tbu,0x00000000 ); }
Signature · 1 line
1.7.0
Quoted 5 lines · Dmitry Ilyevsky
Hello All,
Please review patch for TBL SPR read access for generic PPC.
Quoted 7 lines
Description:
POWER specification docs define TBL/TBU SPRs as readable in user and privileged modes. Therefore SPRs permissions were changed in
gen_tblfunction intarget-ppc/translate_init.cfile.Testing:
Tested with vxworks-6.2 bsp and OS on custom qemu board that includes ppc405 emulated core
A couple of comments to this patch.
1) Please don't top-post.
2) Always put a Signed-off-by: in the patch
3) Put the patch description into the patch, so git knows what to do with it
4) Don't use html features in mail :-)
The patch looks good otherwise.
Alex
Quoted 23 lines · Alexander Graf
Quoted 5 lines · Dmitry Ilyevsky
Hello All,
Please review patch for TBL SPR read access for generic PPC.
Quoted 7 lines
Description:
POWER specification docs define TBL/TBU SPRs as readable in user and privileged modes. Therefore SPRs permissions were changed in
gen_tblfunction intarget-ppc/translate_init.cfile.Testing:
Tested with vxworks-6.2 bsp and OS on custom qemu board that includes ppc405 emulated core
A couple of comments to this patch.
1) Please don't top-post.
2) Always put a Signed-off-by: in the patch
3) Put the patch description into the patch, so git knows what to do with it
4) Don't use html features in mail :-)
Quoted 6 lines
The patch looks good otherwise.
Alex
Corrected.
Thanks,
Dmitry I.
From b5846b7df136c1eff7df8dada8800c81e1799cf4 Mon Sep 17 00:00:00 2001
From: Dmitry Ilyevsky <[email protected]>
Date: Fri, 26 Mar 2010 03:25:36 +0300
Subject: Generic PowerPC TBL
Time base SPRs TBL/TBU should be accessible in user/priv modes for reading as specified in POWER ISA documentation. Therefore SPRs permissions were changed in gen_tbl function.
--- target-ppc/translate_init.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
target-ppc/translate_init.c +4 -4
@@ -777,16 +777,16 @@ static void gen_tbl (CPUPPCState *env) &spr_read_tbl,SPR_NOACCESS , 0x00000000);spr_register (env,SPR_TBL ,"TBL" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbl, + &spr_read_tbl,SPR_NOACCESS , + &spr_read_tbl, &spr_write_tbl,0x00000000 );spr_register (env,SPR_VTBU ,"TBU" , &spr_read_tbu,SPR_NOACCESS , &spr_read_tbu,SPR_NOACCESS ,0x00000000 );spr_register (env,SPR_TBU ,"TBU" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbu, + &spr_read_tbu,SPR_NOACCESS , + &spr_read_tbu, &spr_write_tbu,0x00000000 ); }
Signature · 1 line
1.7.0
Alexander Graf
Acked-byQuoted 31 lines · Dmitry Ilyevsky
Quoted 23 lines · Alexander Graf
Quoted 5 lines · Dmitry Ilyevsky
Hello All,
Please review patch for TBL SPR read access for generic PPC.
Quoted 7 lines
Description:
POWER specification docs define TBL/TBU SPRs as readable in user and privileged modes. Therefore SPRs permissions were changed in
gen_tblfunction intarget-ppc/translate_init.cfile.Testing:
Tested with vxworks-6.2 bsp and OS on custom qemu board that includes ppc405 emulated core
A couple of comments to this patch.
1) Please don't top-post.
2) Always put a Signed-off-by: in the patch
3) Put the patch description into the patch, so git knows what to do with it
4) Don't use html features in mail :-)Quoted 6 lines
The patch looks good otherwise.
Alex
Quoted 5 lines
Corrected.
Thanks,
Dmitry I.
<0001-Generic-PowerPC-TBL.patch>
Aurelien Jarno
AppliedQuoted 27 lines · Dmitry Ilyevsky
Quoted 26 lines · Alexander Graf
Quoted 5 lines · Dmitry Ilyevsky
Hello All,
Please review patch for TBL SPR read access for generic PPC.
Quoted 7 lines
Description:
POWER specification docs define TBL/TBU SPRs as readable in user and privileged modes. Therefore SPRs permissions were changed in
gen_tblfunction intarget-ppc/translate_init.cfile.Testing:
Tested with vxworks-6.2 bsp and OS on custom qemu board that includes ppc405 emulated core
A couple of comments to this patch.
1) Please don't top-post.
2) Always put a Signed-off-by: in the patch
3) Put the patch description into the patch, so git knows what to do with it
4) Don't use html features in mail :-)The patch looks good otherwise.
Quoted 8 lines
Quoted 3 lines
Alex
Corrected.
Thanks,
Dmitry I.
Thanks, applied.
Quoted 40 lines
From
b5846b7df136c1eff7df8dada8800c81e1799cf4Mon Sep 17 00:00:00 2001
From: Dmitry Ilyevsky <[email protected]>
Date: Fri, 26 Mar 2010 03:25:36 +0300
Subject: Generic PowerPC TBLTime base SPRs TBL/TBU should be accessible in user/priv modes for reading as specified in POWER ISA documentation. Therefore SPRs permissions were changed in
gen_tblfunction.Signed-off-by Dmitry Ilyevsky <[email protected]>--- target-ppc/translate_init.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)target-ppc/translate_init.c +4
-4@@ -777,16 +777,16 @@ static void gen_tbl (CPUPPCState *env) &spr_read_tbl,SPR_NOACCESS , 0x00000000);spr_register (env,SPR_TBL ,"TBL" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbl, + &spr_read_tbl,SPR_NOACCESS , + &spr_read_tbl, &spr_write_tbl,0x00000000 );spr_register (env,SPR_VTBU ,"TBU" , &spr_read_tbu,SPR_NOACCESS , &spr_read_tbu,SPR_NOACCESS ,0x00000000 );spr_register (env,SPR_TBU ,"TBU" , -SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS , &spr_write_tbu, + &spr_read_tbu,SPR_NOACCESS , + &spr_read_tbu, &spr_write_tbu,0x00000000 ); }Signature · 1 line
1.7.0
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net