Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sdd.hp.com!hplabs!hpcc01!hpcuhb!hpcllla!hpcllz2!dhandly From: dhandly@hpcllz2.HP.COM (Dennis Handly) Newsgroups: comp.sys.hp Subject: Re: HPPA Context switching code - still having problems Message-ID: <3770057@hpcllz2.HP.COM> Date: 1 Jul 90 08:12:26 GMT References: <7748@ccncsu.ColoState.EDU> Organization: Hewlett Packard Calif. Language Lab Lines: 148 > Anyway, I have included the crux of the code. There are two routines, > Save and Restore. They both take an argument of an integer array > whose elements are used to save arguments 1 & 2, the PC and the SP, in > that order. Two external variables are also used to save/restore the > SP and PC. > Matt. BTW, the correct name is now PA-RISC, not HP-PA. But since you probably paid good money for your machine, we'll let you get away with it this time. :-) I'm not sure what you are trying to do and whether you are mixing C or some other high level language with assembly, or it is all assembly. You appear to be violating some of the calling conventions. I'll point these out below. I'll also include some suggestions and questions. I assume you are somehow allocating several stacks that won't cause SP, R30, to overlap? ------------------------------------------------------------------------- .CODE Save .PROC ; declare a procedure .CALLINFO CALLER,FRAME=48 .ENTRY LDO 96(30),30 ; make room on the stack ; for saved registers. ; ; save gr registers %gr19 .. %gr22 ; Any reason why you are storing the registers in reverse order? (this is not a problem except for caching??) Any reason why you are storing these registers, caller save, instead of the callee save registers?? STW 19,-52(0,30) STW 20,-56(0,30) STW 21,-60(0,30) STW 22,-64(0,30) ; ; save fp registers %fr8 .. %fr11 ; Any reason why you are storing the registers in reverse order? (this is not a problem.) Any reason why you are storing these registers, caller save, instead of the callee save registers?? (Note you can eliminate 3 of the following LDOs by using an offset on the FSTDS. LDO -80(30),3, then FSTDS 8,8(0,3) FSTDS 9,0(0,3), etc.) A possible problem here, you are using R3, which is a callee save register, which means you must save and restore it before you exit. LDO -72(30),3 FSTDS %fr8,0(0,3) LDO -80(30),3 FSTDS %fr9,0(0,3) LDO -88(30),3 FSTDS %fr10,0(0,3) LDO -96(30),3 FSTDS %fr11,0(0,3) ; ; Store the pc and sp to the argment array, elements 2 & 3. ; STW 2,8(0,26) ; save the pc STW 30,12(0,26) ; save the sp ; ; Get new values for sp and pc from external variables ; ADDIL L%WorkerSP-$global$,27 LDW R%WorkerSP-$global$(0,1),30 ; restore the sp ADDIL L%WorkerPC-$global$,27 LDW R%WorkerPC-$global$(0,1),2 ; restore the pc ; ; Ok, now go ... ; How does the following work? Do you mean BV 0(2) or BE 0(4,2)? Are you jumping back and forth between code and data spaces?? SR0 normally contains garbage. ???? (Also you might want to nullify the instruction.) BE 0(0,2) NOP .EXIT .PROCEND .IMPORT WorkerPC,DATA .IMPORT WorkerSP,DATA .IMPORT $global$,DATA .EXPORT Save ; ***************************************************************************** .CODE Restore .PROC ; declare a procedure .CALLINFO CALLER,FRAME=0 .ENTRY ; ; Restore the pc and sp from the argument array, elements 2 & 3 ; LDW 8(0,26),2 ; reset the pc LDW 12(0,26),30 ; reset the sp ; ; restore gr registers %gr19 .. %gr22 Any reason why you are restoring these registers, caller save, instead of the callee save registers?? ; LDW -52(30),19 LDW -56(30),20 LDW -60(30),21 LDW -64(30),22 ; ; restore fp registers %fr4 .. %fr11 ; Any reason why you are restoring these registers, caller save, instead of the callee save registers?? (Note you can eliminate 3 of the following LDOs by using an offset on the FLDDS. LDO -80(30),3, then FLDDS 8,8(0,3) FLDDS 9,0(0,3), etc.) A possible problem here, you are using R3, which is a callee save register, which means you must save and restore it before you exit. LDO -72(30),3 FLDDS 0(0,3),%fr8 LDO -80(30),3 FLDDS 0(0,3),%fr9 LDO -88(30),3 FLDDS 0(0,3),%fr10 LDO -96(30),3 FLDDS 0(0,3),%fr11 ; ; Re-adjust the sp ; LDO -96(30),30 ; ; Go ... ; How does the following work? Do you mean BV 0(2) or BE 0(4,2)? Are you jumping back and forth between code and data spaces?? SR0 normally contains garbage. ???? (Also you might want to put the LDO in the delay slot.) BE 0(0,2) ; start thread NOP .EXIT .PROCEND .EXPORT Restore I hope the above comments help. I would suspect your problem is with R3 and the BE.