Skip to contentSkip to conversation

720 - some progress

parisc-linux Jurij Smakov 5 participants 12 messages Sep 27, 2001 – Sep 29, 2001 PA-RISC architecture

lore
Share & tools
lore
#0 lore raw

Hi!

I hope I've got it right. It only emulates MFCTL and only when the source control register is 27. It turns out, that pt_regs does not have a member for cr26 and adding one does not look like an easy task.

Jurij.

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +12 -0
@@ -273,6 +273,7 @@
 {
        unsigned long fault_address = 0;
        unsigned long fault_space = 0;
+       int fromcr,togr;
        struct siginfo si;
 #ifdef CONFIG_KWDB
        struct save_state ssp;
@@ -363,6 +364,17 @@
                si.si_code = ILL_PRVOPC;
                goto give_sigill;
        case 11:
+               if(!(regs->iir & 0xfc000000) && (((regs->iir & 0x1fe0)>>5) == 0x45)) {
+                 /* This is MFCTL instruction */
+                 fromcr = (regs->iir & 0x03e00000)>>21;
+                 togr = (regs->iir & 0x1f);
+                 /* Emulate the instruction if the read is from cr27 */
+                 if(fromcr == 27) {
+                   regs->gr[togr] = regs->cr27;
+                   return;
+                 }
+               }
+               /* Something else is wrong */
                die_if_kernel("Privileged register - shouldn't happen!", regs, code);
                si.si_code = ILL_PRVREG;
        give_sigill:
#1 lore raw

Hi Jurij,

using your patch, the programs ls etc don't trap anymore, but they just hang.

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 373

Quoted 7 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +7 -0
+               if(!(regs->iir & 0xfc000000) && (((regs->iir & 0x1fe0)>>5) == 0x45)) {
+                 /* This is MFCTL instruction */
+                 fromcr = (regs->iir & 0x03e00000)>>21;
+                 togr = (regs->iir & 0x1f);
+                 /* Emulate the instruction if the read is from cr27 */
+                 if(fromcr == 27) {
+                   regs->gr[togr] = regs->cr27;

I guess you need to advance the PC at this place. Something like:

		regs->iaoq[0] = regs->iaoq[1];
		regs->iaoq[1] = regs->iaoq[0] + 4;

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 377

Quoted 4 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +4 -0
+                   return;
+                 }
+               }
+               /* Something else is wrong */

If i add these instructions, ls no longer hangs but traps again with a trap 15. Using show_regs(), it looks like there is always a 0 loaded to the register. So my current question is:

where does regs->cr27 get written to the stack? Does the PA-RISC CPU does this automatically on a start of a trap or does the code in entry.S need to do this?

Cheers,
Jochen

#3 lore raw
In reply to Jurij Smakov
Quoted 4 lines · Jurij Smakov

I hope I've got it right. It only emulates MFCTL and only when the source control register is 27. It turns out, that pt_regs does not have a member for cr26 and adding one does not look like an easy task.

I think the right way to do this would be...

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 371

Quoted 9 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +5 -0
@@ -363,6 +364,17 @@
                si.si_code = ILL_PRVOPC;
                goto give_sigill;
        case 11:
+               if(!(regs->iir & 0xfc000000) && (((regs->iir & 0x1fe0)>>5) == 0x45)) {
+                 /* This is MFCTL instruction */
+                 fromcr = (regs->iir & 0x03e00000)>>21;
+                 togr = (regs->iir & 0x1f);
+                 /* Emulate the instruction if the read is from cr27 */
		if (fromcr == 26 || fromcr == 27) {
			regs->gr[togr] = mfctl(fromcr);
			return;
		}

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 380

Quoted 5 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +2 -0
+               }
+               /* Something else is wrong */
                die_if_kernel("Privileged register - shouldn't happen!", regs, code);
                si.si_code = ILL_PRVREG;
        give_sigill:

Can you give this a try?

Signature · 1 line
Revolutions do not require corporate support.
#2 lore raw
In reply to Jochen Friedrich
Quoted 7 lines · Jochen Friedrich

If i add these instructions, ls no longer hangs but traps again with a trap 15. Using show_regs(), it looks like there is always a 0 loaded to the register. So my current question is:

where does regs->cr27 get written to the stack? Does the PA-RISC CPU does this automatically on a start of a trap or does the code in entry.S need to do this?

cr27 is only written to when doing fork/clone/vfork, iirc. use the mfctl() macro in place of regs->cr27 as i suggested in my other email.

Signature · 1 line
Revolutions do not require corporate support.
#4 lore raw
In reply to Matthew Wilcox

Hello,

Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Jurij Smakov

I hope I've got it right. It only emulates MFCTL and only when the source control register is 27. It turns out, that pt_regs does not have a member for cr26 and adding one does not look like an easy task.

I think the right way to do this would be...

Quoted 14 lines

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 371

Quoted 9 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +5 -0
@@ -363,6 +364,17 @@
                si.si_code = ILL_PRVOPC;
                goto give_sigill;
        case 11:
+               if(!(regs->iir & 0xfc000000) && (((regs->iir & 0x1fe0)>>5) == 0x45)) {
+                 /* This is MFCTL instruction */
+                 fromcr = (regs->iir & 0x03e00000)>>21;
+                 togr = (regs->iir & 0x1f);
+                 /* Emulate the instruction if the read is from cr27 */
		if (fromcr == 26 || fromcr == 27) {
			regs->gr[togr] = mfctl(fromcr);
			return;
		}

Making this change causes the build to fail:

make[1]: Entering directory `/tmp/.hppa/linux/arch/parisc/kernel'
hppa-linux-gcc -D__KERNEL__ -I/tmp/.hppa/linux/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common -D__linux__ -pipe -fno-strength-reduce -mno-space-regs -mfast-indirect-calls -mdisable-fpregs -ffunction-sections -march=1.1 -mschedule=7100 -c -o traps.o traps.c {standard input}: Assembler messages:
{standard input}:912: Error: Undefined absolute constant: 'fromcr'.
{standard input}:912: Error: Field out of range [0..31] (-1).
{standard input}:912: Error: Invalid operands
make[1]: *** [traps.o] Error 1
make[1]: Leaving directory `/tmp/.hppa/linux/arch/parisc/kernel'
make: *** [_dir_arch/parisc/kernel] Error 2

What gives?

Quoted 7 lines

arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 line 380

Quoted 5 lines
arch/parisc/kernel/traps.c Thu Sep 27 16:16:54 2001 renamed from arch/parisc/kernel/traps.c Wed Sep 19 12:02:30 2001 +2 -0
+               }
+               /* Something else is wrong */
                die_if_kernel("Privileged register - shouldn't happen!", regs, code);
                si.si_code = ILL_PRVREG;
        give_sigill:

Can you give this a try?

Did. I don't think I messed it up. :-) Jurij's code compiles, so I'm leaving it there for the moment and testing again.

Is your code functionally equivalent, or does it do something else entirely?

Aside, I'm working on putting all the recent patches together into one big fix720.diff.

Jochen suggested that in the case 11 handler, Jurij's

regs->gr[togr] = regs->cr27;

be replaced with

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

Is this right, or should I leave Jurij's code?

Regards,

Albert

#5 lore raw

Hello,

Some minor progress. I'm now netbooting a lifimage and then running my programs from disk. The only problem is that I can't dpkg-reconfigure the chroot I copied over to the disk after partially bootstrapping it and nfsroot booting it because I can't install libterm-readline-gnu-perl and related packages (currently the system seems to hang when I do a dpkg -i libreadline4_4.2-5_hppa.deb. libc6 and a few others dpkg -i'd fine though (running -pa22 with only the case 18: and without Jurij's patches). I'm currently running -pa27+jurij (I had to manually apply his 2nd patch... it didn't like the traps.c I had).

Another question: shutdown doesn't seem to work? Is it because I am running with init=/bin/sh (thus no init, and no runlevels to change), or is something more sinister at work here? Is there some other way I can "neatly" bring down my HP?

That's about it for now. I'm going to try booting a -pa27 without jurij's fixes and with just the case fall-through.

Regards,

Albert

#6 lore raw

Hello,

Quoted 11 lines · Albert Strasheim

Hello,

Some minor progress. I'm now netbooting a lifimage and then running my programs from disk. The only problem is that I can't dpkg-reconfigure the chroot I copied over to the disk after partially bootstrapping it and nfsroot booting it because I can't install libterm-readline-gnu-perl and related packages (currently the system seems to hang when I do a dpkg -i libreadline4_4.2-5_hppa.deb. libc6 and a few others dpkg -i'd fine though (running -pa22 with only the case 18: and without Jurij's patches). I'm currently running -pa27+jurij (I had to manually apply his 2nd patch... it didn't like the traps.c I had).

Not much luck with this one either. dpkg has just been sitting there for more than an hour now.

Could I persuade someone with a working HP to bootstrap a new nfsroot, please?

You probably also need to add the following packages:

busybox-static_0.60.1-1_hppa.deb
libc6_2.2.3-9_hppa.deb
libdb2_2.7.7.0-1_hppa.deb
libgdbmg1_1.7.3-27_hppa.deb
libncurses5_5.2.20010318-3_hppa.deb
libperl5.6_5.6.1-5_hppa.deb
libreadline4_4.2-5_hppa.deb
libterm-readline-gnu-perl_1.10-1_hppa.deb
perl_5.6.1-5_hppa.deb
perl-base_5.6.1-5_hppa.deb
perl-modules_5.6.1-5_all.deb

I think that should leave you with a system the 720/50 people can work from. :-)

Regards,

Albert

#7 lore raw
In reply to Albert Strasheim

Hi Albert,

Quoted 11 lines · Albert Strasheim
Quoted 4 lines
		if (fromcr == 26 || fromcr == 27) {
			regs->gr[togr] = mfctl(fromcr);
			return;
		}

Making this change causes the build to fail:

{standard input}:912: Error: Undefined absolute constant: 'fromcr'. {standard input}:912: Error: Field out of range [0..31] (-1). {standard input}:912: Error: Invalid operands

Quoted 8 lines

Jochen suggested that in the case 11 handler, Jurij's

regs->gr[togr] = regs->cr27;

be replaced with

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

Not replaced, but added:

if (fromcr == 26) {

 			regs->gr[togr] = mfctl(26);
			regs->iaoq[0] = regs->iaoq[1];
			regs->iaoq[1] = regs->iaoq[0] + 4;
 			return;
 		}
 		if (fromcr == 27) {
 			regs->gr[togr] = mfctl(27);
			regs->iaoq[0] = regs->iaoq[1];
			regs->iaoq[1] = regs->iaoq[0] + 4;

return;
}

These commands:

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

just advance the instruction counter of the PA-RISC CPU, so after returning from the trap, the CPU will move on instead of retrying the failed op-code (which will, of course, trap again causing an infinite loop)

Cheers,
Jochen

#8 lore raw

Hello,

Just want to make sure I got this right. I've attached:

00-traps.c.orig
01_1-traps.c.quickfix
01_2-traps.c.case18
02-traps.c.case11
03-traps.c.jochen

00-traps.c.orig is the traps.c from -pa27. quickfix is the one that simply adds a case 18: fall-through (and has worked quite well me for me).

case18 is Jurij's first patch. case11 is his 2nd patch, which I had to add in my hand. Then jochen is jochen's additions to that (please check that I understood you correctly).

I've not included a traps.c with Matthew's code:

	...

	/* Emulate the instruction if the read is from cr27 */
	if (fromcr == 26 || fromcr == 27) {
		regs->gr[togr] = mfctl(fromcr);
		return;
	}
	/* Something else is wrong */

	...

It didn't compile for me and I'm not quite sure how to fix it and still keep the original meaning intact. :-)

Regards,

Albert

Quoted 51 lines · Jochen Friedrich

Hi Albert,

Quoted 11 lines · Albert Strasheim
Quoted 4 lines
		if (fromcr == 26 || fromcr == 27) {
			regs->gr[togr] = mfctl(fromcr);
			return;
		}

Making this change causes the build to fail:

{standard input}:912: Error: Undefined absolute constant: 'fromcr'. {standard input}:912: Error: Field out of range [0..31] (-1). {standard input}:912: Error: Invalid operands

Quoted 8 lines

Jochen suggested that in the case 11 handler, Jurij's

regs->gr[togr] = regs->cr27;

be replaced with

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

Not replaced, but added:

(quoted diff) +0 -0
 		if (fromcr == 26) {
 			regs->gr[togr] = mfctl(26);
			regs->iaoq[0] = regs->iaoq[1];
			regs->iaoq[1] = regs->iaoq[0] + 4;
(quoted diff) +0 -0
 			return;
 		}
 		if (fromcr == 27) {
 			regs->gr[togr] = mfctl(27);
			regs->iaoq[0] = regs->iaoq[1];
			regs->iaoq[1] = regs->iaoq[0] + 4;
(quoted diff) +0 -0
 			return;
 		}

These commands:

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

just advance the instruction counter of the PA-RISC CPU, so after returning from the trap, the CPU will move on instead of retrying the failed op-code (which will, of course, trap again causing an infinite loop)

Cheers,
Jochen

#9 lore raw

Hi Albert,

Quoted 3 lines

case18 is Jurij's first patch. case11 is his 2nd patch, which I had to add in my hand. Then jochen is jochen's additions to that (please check that I understood you correctly).

Yes, it's exactly what i meant...

I'm currently re-evaluating the case 18 stuff. Maybe Jurijs proposal about checking for unaligned access using a decoded opcode might me faster than dereferencing 3 page tables and having to decode the opcode anyways to check for read vs write access...

The only question that remains is if the paging code will handle a recursive trap gracefully (i.e. when the unaligned access emulation code traps again because of a page fault).

Cheers,
Jochen

#10 lore raw
In reply to Albert Strasheim
Quoted 5 lines · Albert Strasheim

regs->iaoq[0] = regs->iaoq[1];
regs->iaoq[1] = regs->iaoq[0] + 4;

Is this right, or should I leave Jurij's code?

Hello Albert,

An observation:
regs->iaoq[1] is the "following instruction" - where "following" means "in execution order". So replacing the emulated instruction with this seems the obvious thing to do.

BUT...
Without examining the instruction (which was at iaoq[1] and is now at iaog[0]) I don't think it is safe to assume that the instruction following that one in execution order is at iaoq[1]+4 !! (Branches, nullified instructions, conditional instructions, etc).

Perhaps...
Instead of trying to compute (determine) what is the next instruction in execution order following iaoq[1] ; iaoq[1] could be set to a value that would cause the hardware pipeline to fetch the correct following instruction.

Or perhaps...
A way could be found to use whatever "single step" controls are available to get the return made to iaoq[1] instead of iaoq[0] and leave the queues along.

Also...
What about the space register queue? Might these instructions be in a different address space?

Mike

#11 lore raw

Albert and other 720 folks;

I have been reading the directions (please forgive me for that)...

It looks (reads) as if it possible to return to the faulting instruction (MFCTL in this case) without executing it. If so, then adjusting the instruction (and space) queues within the fault handler can be avoided; also avoiding problems with finding the correct "following instruction" address.

In general:
When executing a group 3 fault (MFCTL), the PSW register is copied into the IPSW register. The "N" bit of the PSW (now in the IPSW) is a copy of the "nullify bit" of the instruction PRECEDING the instruction at iaoq[0]. The nullify bit of the instruction preceding the MFCTL instruction was "zero" (or we wouldn't be here).
So rather than trying to adjust the addresses in the instruction/space queues, it should be possible to just set the "N" bit of the IPSW (or its representation in the interrupted registers structure). Then, when the finally makes it back to a "Return from Interrupt" instruction, our faked "N" bit will be loaded into the PSW and the processor will skip the MFCTL instruction which gets returned to.

Having zero experience with this processor and no way to test my idea; I have done some "cut and paste" from the documentation - perhaps somebody could check me on this idea.

Mike

PA-RISC 1.1 Architecture and Instruction Set Reference Manual HP Part Number: 09740-90039
Printed in U.S.A. February 1994
Third Edition

- - - -

Trap:
Traps include two sorts of possibilities: either the function requested by
the current instruction cannot or should not be carried out, or system intervention is desired by the user before or after the instruction is executed. Examples of the first type include arithmetic operations that result in signed overflow and instructions executed with insufficient privilege for their intended function. Such instructions are normally not re-executed. Examples of the second type include the debugging support traps. Traps are synchronous with respect to the instruction stream.

- - - -

Group 3:
6 Instruction TLB miss fault/Instruction page fault 7 Instruction memory protection trap
30 Instruction debug trap
8 Illegal instruction trap
9 Break instruction trap
10 Privileged operation trap
11 Privileged register trap
12 Overflow trap
13 Conditional trap
14 Assist exception trap
15 Data TLB miss fault/Data page fault
16 Non-access instruction TLB miss fault
17 Non-access data TLB miss fault/Non-access data page fault 26 Data memory access rights trap
27 Data memory protection ID trap
28 Unaligned data reference trap

- - - -

Name Privileged register trap (11)

Cause An attempt is being made to write to a privileged space register or
access a privileged control register without being at the most privileged level (priv= 0)

Parameters IIR ­ The instruction causing the trap
IIA Queue Front ­ Address of the instruction causing the trap
Back ­ Address of the following instruction

Notes This interruption may be caused by the MOVE TO SPACE REGISTER,
MOVE TO CONTROL REGISTER, or MOVE FROM CONTROL REGISTER instructions.

- - - -

Processor state is encoded in a 32-bit register called the Processor Status Word (PSW). When an interruption occurs, the old value of the PSW is saved in the Interruption Processor Status Word (IPSW) and usually all defined PSW bits are set to 0. The format of the PSW is shown in Figure 2-9.
(copy is unreadable as e-mail ... "N" is bit 10dec.)
Figure 2-9. Processor Status Word

The PSW is set to the contents of the IPSW by the RETURN FROM INTERRUPTION and RETURN FROM INTERRUPTION AND RESTORE instructions. The interruption handler may restore the original PSW, modify selected bits, or may change the PSW to an entirely new value.

- - - -

N Nullify.
The current instruction is nullified when this bit is 1. This bit is set to 1 by an instruction that nullifies the following instruction.

- - - -
I am ignoring the other 423 pages of the manual - which might be a mistake. _ _ _ _

All in all, the way I read it - we can emulate the effect of an instruction prior to the MFCTL instruction that has its "nullify" bit set by setting the "N" bit in the IPSW. With the effect that when the RFI is completed, the hardware will just skip the MFCTL which was just emulated.

Mike