Discussion:
Question about coprocessor 15 and exceptions
(too old to reply)
Jonathan
2004-12-03 17:26:34 UTC
Permalink
Hello. I'm learning how the ARM CPU runs to work with it but I've a
question. As you would know, the access to the coprocessor #15 is only
allowed in a privileged run mode. So I'd made a program (silly
program, just with an mrc instruction) that tried to read the
translation table base register address (register #2) in a not
privileged run mode and then executed it in user mode in Linux. The
program exited with an error message (Invalid operation).That's right,
but I surprised when I tried to write to the same register (register
#2, coprocessor #15) and the program exited with no error message. Of
course, I suppose that the writing wasn't done, but why it didn't
throw an exception? Anybody understand what I've explained ;-) and
could help me? Thanks.

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Russell King - ARM Linux
2004-12-03 17:32:16 UTC
Permalink
Post by Jonathan
Hello. I'm learning how the ARM CPU runs to work with it but I've a
question. As you would know, the access to the coprocessor #15 is only
allowed in a privileged run mode. So I'd made a program (silly
program, just with an mrc instruction) that tried to read the
translation table base register address (register #2) in a not
privileged run mode and then executed it in user mode in Linux. The
program exited with an error message (Invalid operation).That's right,
but I surprised when I tried to write to the same register (register
#2, coprocessor #15) and the program exited with no error message. Of
course, I suppose that the writing wasn't done, but why it didn't
throw an exception? Anybody understand what I've explained ;-) and
could help me? Thanks.
Please send program source. 8)

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Jonathan
2004-12-03 17:57:22 UTC
Permalink
On Fri, 3 Dec 2004 17:32:16 +0000, Russell King - ARM Linux
Post by Russell King - ARM Linux
Post by Jonathan
Hello. I'm learning how the ARM CPU runs to work with it but I've a
question. As you would know, the access to the coprocessor #15 is only
allowed in a privileged run mode. So I'd made a program (silly
program, just with an mrc instruction) that tried to read the
translation table base register address (register #2) in a not
privileged run mode and then executed it in user mode in Linux. The
program exited with an error message (Invalid operation).That's right,
but I surprised when I tried to write to the same register (register
#2, coprocessor #15) and the program exited with no error message. Of
course, I suppose that the writing wasn't done, but why it didn't
throw an exception? Anybody understand what I've explained ;-) and
could help me? Thanks.
Please send program source. 8)
Here they are.

This code try to read de register 2 and its execution exits with the
error message "Illegal instruction":

int main(){

register unsigned int r5 asm("r5");


r5 = 0x00000000;

printf("Value R5 before: %X\n", r5);
asm("mrc p15,0,r5,c2,c0,0");
printf("Value R5 after: %X\n", r5);

return 0;



This is trying to write the register 2, and it exits without any error:

int main(){

register unsigned int r5 asm("r5");

r5 = 0x00000000;

printf("Then I go\n");
asm("mcr p15,0,r5,c2,c0,0");
printf("The new base address was updated \n");

return 0;
}

What do you think?

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Russell King - ARM Linux
2004-12-03 20:02:58 UTC
Permalink
Post by Jonathan
What do you think?
Very interesting. The write does appear to be ignored though.
Moreover, any write to any co-processor register appears so, and
in fact appears that nwfpe accepts any aborted MCR instruction
for any coprocessor register and treats it as if it owns it.

The interesting thing is that the following program doesn't
fault:

int main()
{
register unsigned int r5 asm("r5");
float f;

r5 = 0x00000001;

printf("Then I go\n");
asm("mvfs f0, #0.0");
asm("mrc p15,0,r5,c0,c0,0");
asm("mcr p15,0,r5,c0,c0,0");
asm("mvfs %0, f0" : "=f" (f));
printf("The new base address was updated %08x\n", *(unsigned int*)&f);

return 0;
}

because the mrc and mcr instructions are interpreted as the
floating point fixs and flts instructions by nwfpe.

Note: this works correctly (and faults) under 2.6 kernels.
Yet another reason not to use the buggy 2.4 versions.

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Peter Teichmann
2004-12-03 20:31:54 UTC
Permalink
Post by Russell King - ARM Linux
Post by Jonathan
What do you think?
Very interesting. The write does appear to be ignored though.
Moreover, any write to any co-processor register appears so, and
in fact appears that nwfpe accepts any aborted MCR instruction
for any coprocessor register and treats it as if it owns it.
[...]
Post by Russell King - ARM Linux
Note: this works correctly (and faults) under 2.6 kernels.
Yet another reason not to use the buggy 2.4 versions.
You could also use FastFPE, which doesn't have any of these problems in both
kernel version 2.4 and 2.6.

Peter Teichmann

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Jonathan
2004-12-04 12:50:09 UTC
Permalink
Thanks for your answer. Just a few questions (excuse me if of some of
them are silly, but I'm new in the ARM world):

- What does the mvfs instruction do/mean? Because I can't recognise it
as an ARM instruction.

- What is the newfpe? Something about the Float Point Extension??


On Fri, 3 Dec 2004 20:02:58 +0000, Russell King - ARM Linux
Post by Russell King - ARM Linux
Post by Jonathan
What do you think?
Very interesting. The write does appear to be ignored though.
Moreover, any write to any co-processor register appears so, and
in fact appears that nwfpe accepts any aborted MCR instruction
for any coprocessor register and treats it as if it owns it.
The interesting thing is that the following program doesn't
int main()
{
register unsigned int r5 asm("r5");
float f;
r5 = 0x00000001;
printf("Then I go\n");
asm("mvfs f0, #0.0");
asm("mrc p15,0,r5,c0,c0,0");
asm("mcr p15,0,r5,c0,c0,0");
asm("mvfs %0, f0" : "=f" (f));
printf("The new base address was updated %08x\n", *(unsigned int*)&f);
return 0;
}
because the mrc and mcr instructions are interpreted as the
floating point fixs and flts instructions by nwfpe.
Note: this works correctly (and faults) under 2.6 kernels.
Yet another reason not to use the buggy 2.4 versions.
-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php
Peter Teichmann
2004-12-04 17:02:30 UTC
Permalink
Post by Jonathan
Thanks for your answer. Just a few questions (excuse me if of some of
- What does the mvfs instruction do/mean? Because I can't recognise it
as an ARM instruction.
MVFS is an instruction from the FPA floating point instruction set. The FPA is
a floating point coprocessor. The instruction set is implemented using the
coprocessor instructions of coprocessor 1 and 2. There were only few devices
which contained the FPA (ARM7500FE which is a complete system-on-chip, and
FPA11 as external coprocessor to ARM3 if I remember correctly). Despite still
being widely used, this instruction set is not documented in the ARM ARM. The
only source for documentation about it that I know is the ARM7500FE data
sheet.
Post by Jonathan
- What is the newfpe? Something about the Float Point Extension??
NWFPE is the "Netwinder Floating Point Emulator". It emulates the FPA
instruction set in software.

Peter Teichmann

-------------------------------------------------------------------
Subscription options: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ: http://www.arm.linux.org.uk/armlinux/mlfaq.php
Etiquette: http://www.arm.linux.org.uk/armlinux/mletiquette.php

Loading...