112027Sjungma@eit.uni-kl.de; pa-risc.s -- assembly support.
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de; QuickThreads -- Threads-building toolkit.
412027Sjungma@eit.uni-kl.de; Copyright (c) 1993 by David Keppel
512027Sjungma@eit.uni-kl.de;
612027Sjungma@eit.uni-kl.de; Permission to use, copy, modify and distribute this software and
712027Sjungma@eit.uni-kl.de; its documentation for any purpose and without fee is hereby
812027Sjungma@eit.uni-kl.de; granted, provided that the above copyright notice and this notice
912027Sjungma@eit.uni-kl.de; appear in all copies.  This software is provided as a
1012027Sjungma@eit.uni-kl.de; proof-of-concept and for demonstration purposes; there is no
1112027Sjungma@eit.uni-kl.de; representation about the suitability of this software for any
1212027Sjungma@eit.uni-kl.de; purpose.
1312027Sjungma@eit.uni-kl.de
1412027Sjungma@eit.uni-kl.de; This file (pa-risc.s) is part of the port of QuickThreads for
1512027Sjungma@eit.uni-kl.de; PA-RISC 1.1 architecture.  This file implements context switches
1612027Sjungma@eit.uni-kl.de; and thread startup.  It was written in 1994 by Uwe Reder
1712027Sjungma@eit.uni-kl.de; (`uereder@cip.informatik.uni-erlangen.de') for the Operating
1812027Sjungma@eit.uni-kl.de; Systems Department (IMMD4) at the University of Erlangen/Nuernberg
1912027Sjungma@eit.uni-kl.de; Germany.
2012027Sjungma@eit.uni-kl.de
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de; Callee saves general registers gr3..gr18,
2312027Sjungma@eit.uni-kl.de;              floating-point registers fr12..fr21.
2412027Sjungma@eit.uni-kl.de
2512027Sjungma@eit.uni-kl.de            .CODE
2612027Sjungma@eit.uni-kl.de
2712027Sjungma@eit.uni-kl.de            .IMPORT $$dyncall, MILLICODE
2812027Sjungma@eit.uni-kl.de            .IMPORT qt_error, CODE
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.de            .EXPORT qt_blocki, ENTRY
3112027Sjungma@eit.uni-kl.de            .EXPORT qt_block, ENTRY
3212027Sjungma@eit.uni-kl.de            .EXPORT qt_abort, ENTRY
3312027Sjungma@eit.uni-kl.de            .EXPORT qt_start, ENTRY
3412027Sjungma@eit.uni-kl.de            .EXPORT qt_vstart, ENTRY
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.de
3712027Sjungma@eit.uni-kl.de; arg0: ptr to function (helper) to call once curr is suspended
3812027Sjungma@eit.uni-kl.de;       and control is on arg3's stack.
3912027Sjungma@eit.uni-kl.de; arg1: 1'th arg to *arg0.
4012027Sjungma@eit.uni-kl.de; arg2: 2'th arg to *arg0.
4112027Sjungma@eit.uni-kl.de; arg3: sp of new thread.
4212027Sjungma@eit.uni-kl.de
4312027Sjungma@eit.uni-kl.deqt_blocki
4412027Sjungma@eit.uni-kl.de            .PROC
4512027Sjungma@eit.uni-kl.de            .CALLINFO   CALLER, FRAME=0, SAVE_RP, ENTRY_GR=18
4612027Sjungma@eit.uni-kl.de            .ENTRY
4712027Sjungma@eit.uni-kl.de
4812027Sjungma@eit.uni-kl.de            stw         %rp,-20(%sp)    ; save rp to old frame-marker
4912027Sjungma@eit.uni-kl.de
5012027Sjungma@eit.uni-kl.de            stwm        %r3,128(%sp)    ; save callee-saves general registers
5112027Sjungma@eit.uni-kl.de            stw         %r4,-124(%sp)
5212027Sjungma@eit.uni-kl.de            stw         %r5,-120(%sp)
5312027Sjungma@eit.uni-kl.de            stw         %r6,-116(%sp)
5412027Sjungma@eit.uni-kl.de            stw         %r7,-112(%sp)
5512027Sjungma@eit.uni-kl.de            stw         %r8,-108(%sp)
5612027Sjungma@eit.uni-kl.de            stw         %r9,-104(%sp)
5712027Sjungma@eit.uni-kl.de            stw         %r10,-100(%sp)
5812027Sjungma@eit.uni-kl.de            stw         %r11,-96(%sp)
5912027Sjungma@eit.uni-kl.de            stw         %r12,-92(%sp)
6012027Sjungma@eit.uni-kl.de            stw         %r13,-88(%sp)
6112027Sjungma@eit.uni-kl.de            stw         %r14,-84(%sp)
6212027Sjungma@eit.uni-kl.de            stw         %r15,-80(%sp)
6312027Sjungma@eit.uni-kl.de            stw         %r16,-76(%sp)
6412027Sjungma@eit.uni-kl.de            stw         %r17,-72(%sp)
6512027Sjungma@eit.uni-kl.de            stw         %r18,-68(%sp)
6612027Sjungma@eit.uni-kl.de
6712027Sjungma@eit.uni-kl.deqt_abort
6812027Sjungma@eit.uni-kl.de            copy        %arg0,%r22      ; helper to be called by $$dyncall
6912027Sjungma@eit.uni-kl.de            copy        %sp,%arg0       ; pass current sp as arg0 to helper
7012027Sjungma@eit.uni-kl.de            copy        %arg3,%sp       ; set new sp
7112027Sjungma@eit.uni-kl.de
7212027Sjungma@eit.uni-kl.de            .CALL
7312027Sjungma@eit.uni-kl.de            bl          $$dyncall,%mrp  ; call helper
7412027Sjungma@eit.uni-kl.de            copy        %mrp,%rp
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.de            ldw         -68(%sp),%r18   ; restore general registers
7712027Sjungma@eit.uni-kl.de            ldw         -72(%sp),%r17
7812027Sjungma@eit.uni-kl.de            ldw         -76(%sp),%r16
7912027Sjungma@eit.uni-kl.de            ldw         -80(%sp),%r15
8012027Sjungma@eit.uni-kl.de            ldw         -84(%sp),%r14
8112027Sjungma@eit.uni-kl.de            ldw         -88(%sp),%r13
8212027Sjungma@eit.uni-kl.de            ldw         -92(%sp),%r12
8312027Sjungma@eit.uni-kl.de            ldw         -96(%sp),%r11
8412027Sjungma@eit.uni-kl.de            ldw         -100(%sp),%r10
8512027Sjungma@eit.uni-kl.de            ldw         -104(%sp),%r9
8612027Sjungma@eit.uni-kl.de            ldw         -108(%sp),%r8
8712027Sjungma@eit.uni-kl.de            ldw         -112(%sp),%r7
8812027Sjungma@eit.uni-kl.de            ldw         -116(%sp),%r6
8912027Sjungma@eit.uni-kl.de            ldw         -120(%sp),%r5
9012027Sjungma@eit.uni-kl.de            ldw         -124(%sp),%r4
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de            ldw         -148(%sp),%rp   ; restore return-pointer
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.de            bv          %r0(%rp)        ; return to caller
9512027Sjungma@eit.uni-kl.de            ldwm        -128(%sp),%r3
9612027Sjungma@eit.uni-kl.de
9712027Sjungma@eit.uni-kl.de            .EXIT
9812027Sjungma@eit.uni-kl.de            .PROCEND
9912027Sjungma@eit.uni-kl.de
10012027Sjungma@eit.uni-kl.de
10112027Sjungma@eit.uni-kl.deqt_block
10212027Sjungma@eit.uni-kl.de            .PROC
10312027Sjungma@eit.uni-kl.de            .CALLINFO   CALLER, FRAME=0, SAVE_RP, ENTRY_FR=21
10412027Sjungma@eit.uni-kl.de            .ENTRY
10512027Sjungma@eit.uni-kl.de
10612027Sjungma@eit.uni-kl.de            stw         %rp,-20(%sp)    ; save rp to old frame-marker
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de            fstds,ma    %fr12,8(%sp)    ; save callee-saves float registers
10912027Sjungma@eit.uni-kl.de            fstds,ma    %fr13,8(%sp)
11012027Sjungma@eit.uni-kl.de            fstds,ma    %fr14,8(%sp)
11112027Sjungma@eit.uni-kl.de            fstds,ma    %fr15,8(%sp)
11212027Sjungma@eit.uni-kl.de            fstds,ma    %fr16,8(%sp)
11312027Sjungma@eit.uni-kl.de            fstds,ma    %fr17,8(%sp)
11412027Sjungma@eit.uni-kl.de            fstds,ma    %fr18,8(%sp)
11512027Sjungma@eit.uni-kl.de            fstds,ma    %fr19,8(%sp)
11612027Sjungma@eit.uni-kl.de            fstds,ma    %fr20,8(%sp)
11712027Sjungma@eit.uni-kl.de            fstds,ma    %fr21,8(%sp)
11812027Sjungma@eit.uni-kl.de
11912027Sjungma@eit.uni-kl.de            .CALL
12012027Sjungma@eit.uni-kl.de            bl          qt_blocki,%rp
12112027Sjungma@eit.uni-kl.de            ldo         48(%sp),%sp
12212027Sjungma@eit.uni-kl.de
12312027Sjungma@eit.uni-kl.de            ldo         -48(%sp),%sp
12412027Sjungma@eit.uni-kl.de
12512027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr21   ; restore callee-saves float registers
12612027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr20
12712027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr19
12812027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr18
12912027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr17
13012027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr16
13112027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr15
13212027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr14
13312027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr13
13412027Sjungma@eit.uni-kl.de
13512027Sjungma@eit.uni-kl.de            ldw         -28(%sp),%rp    ; restore return-pointer
13612027Sjungma@eit.uni-kl.de
13712027Sjungma@eit.uni-kl.de            bv          %r0(%rp)        ; return to caller.
13812027Sjungma@eit.uni-kl.de            fldds,mb    -8(%sp),%fr12
13912027Sjungma@eit.uni-kl.de
14012027Sjungma@eit.uni-kl.de            .EXIT
14112027Sjungma@eit.uni-kl.de            .PROCEND
14212027Sjungma@eit.uni-kl.de
14312027Sjungma@eit.uni-kl.de
14412027Sjungma@eit.uni-kl.deqt_start
14512027Sjungma@eit.uni-kl.de            .PROC
14612027Sjungma@eit.uni-kl.de            .CALLINFO   CALLER, FRAME=0
14712027Sjungma@eit.uni-kl.de            .ENTRY
14812027Sjungma@eit.uni-kl.de
14912027Sjungma@eit.uni-kl.de            copy        %r18,%arg0      ; set user arg `pu'.
15012027Sjungma@eit.uni-kl.de            copy        %r17,%arg1      ; ... user function pt.
15112027Sjungma@eit.uni-kl.de            copy        %r16,%arg2      ; ... user function userf.
15212027Sjungma@eit.uni-kl.de                                        ; %r22 is a caller-saves register
15312027Sjungma@eit.uni-kl.de            copy        %r15,%r22       ; function to be called by $$dyncall
15412027Sjungma@eit.uni-kl.de
15512027Sjungma@eit.uni-kl.de            .CALL                       ; in=%r22
15612027Sjungma@eit.uni-kl.de            bl          $$dyncall,%mrp  ; call `only'.
15712027Sjungma@eit.uni-kl.de            copy        %mrp,%rp
15812027Sjungma@eit.uni-kl.de
15912027Sjungma@eit.uni-kl.de            bl,n        qt_error,%r0    ; `only' erroniously returned.
16012027Sjungma@eit.uni-kl.de
16112027Sjungma@eit.uni-kl.de            .EXIT
16212027Sjungma@eit.uni-kl.de            .PROCEND
16312027Sjungma@eit.uni-kl.de
16412027Sjungma@eit.uni-kl.de
16512027Sjungma@eit.uni-kl.de; Varargs
16612027Sjungma@eit.uni-kl.de;
16712027Sjungma@eit.uni-kl.de; First, call `startup' with the `pt' argument.
16812027Sjungma@eit.uni-kl.de;
16912027Sjungma@eit.uni-kl.de; Next, call the user's function with all arguments.
17012027Sjungma@eit.uni-kl.de; We don't know whether arguments are integers, 32-bit floating-points or
17112027Sjungma@eit.uni-kl.de; even 64-bit floating-points, so we reload all the registers, possibly
17212027Sjungma@eit.uni-kl.de; with garbage arguments.  The thread creator provided non-garbage for
17312027Sjungma@eit.uni-kl.de; the arguments that the callee actually uses, so the callee never gets
17412027Sjungma@eit.uni-kl.de; garbage.
17512027Sjungma@eit.uni-kl.de;
17612027Sjungma@eit.uni-kl.de;            -48    -44    -40    -36    -32
17712027Sjungma@eit.uni-kl.de;             | arg3 | arg2 | arg1 | arg0 |
17812027Sjungma@eit.uni-kl.de;             -----------------------------
17912027Sjungma@eit.uni-kl.de; integers:     arg3   arg2   arg1   arg0
18012027Sjungma@eit.uni-kl.de; 32-bit fps:  farg3  farg2  farg1  farg0
18112027Sjungma@eit.uni-kl.de; 64-bit fps:  <---farg3-->  <---farg1-->
18212027Sjungma@eit.uni-kl.de;
18312027Sjungma@eit.uni-kl.de; Finally, call `cleanup' with the `pt' argument and with the return value
18412027Sjungma@eit.uni-kl.de; from the user's function.  It is an error for `cleanup' to return.
18512027Sjungma@eit.uni-kl.de
18612027Sjungma@eit.uni-kl.deqt_vstart
18712027Sjungma@eit.uni-kl.de            .PROC
18812027Sjungma@eit.uni-kl.de            .CALLINFO   CALLER, FRAME=0
18912027Sjungma@eit.uni-kl.de            .ENTRY
19012027Sjungma@eit.uni-kl.de
19112027Sjungma@eit.uni-kl.de            ; Because the startup function may damage the fixed arguments
19212027Sjungma@eit.uni-kl.de            ; on the stack (PA-RISC Procedure Calling Conventions Reference
19312027Sjungma@eit.uni-kl.de            ; Manual, 2.4 Fixed Arguments Area), we allocate a seperate
19412027Sjungma@eit.uni-kl.de            ; stack frame for it.
19512027Sjungma@eit.uni-kl.de            ldo         64(%sp),%sp
19612027Sjungma@eit.uni-kl.de
19712027Sjungma@eit.uni-kl.de            ; call: void startup(void *pt)
19812027Sjungma@eit.uni-kl.de
19912027Sjungma@eit.uni-kl.de            copy        %r15,%arg0      ; `pt' is arg0 to `startup'.
20012027Sjungma@eit.uni-kl.de            copy        %r16,%r22
20112027Sjungma@eit.uni-kl.de            .CALL
20212027Sjungma@eit.uni-kl.de            bl          $$dyncall,%mrp  ; Call `startup'.
20312027Sjungma@eit.uni-kl.de            copy        %mrp,%rp
20412027Sjungma@eit.uni-kl.de
20512027Sjungma@eit.uni-kl.de            ldo         -64(%sp),%sp
20612027Sjungma@eit.uni-kl.de
20712027Sjungma@eit.uni-kl.de            ; call: void *qt_vuserf_t(...)
20812027Sjungma@eit.uni-kl.de
20912027Sjungma@eit.uni-kl.de            ldw         -36(%sp),%arg0  ; Load args to integer registers.
21012027Sjungma@eit.uni-kl.de            ldw         -40(%sp),%arg1
21112027Sjungma@eit.uni-kl.de            ldw         -44(%sp),%arg2
21212027Sjungma@eit.uni-kl.de            ldw         -48(%sp),%arg3
21312027Sjungma@eit.uni-kl.de            ; Index of fld[w|d]s only ranges from -16 to 15, so we
21412027Sjungma@eit.uni-kl.de            ; take r22 to be our new base register.
21512027Sjungma@eit.uni-kl.de            ldo         -32(%sp),%r22
21612027Sjungma@eit.uni-kl.de            fldws       -4(%r22),%farg0 ; Load args to floating-point registers.
21712027Sjungma@eit.uni-kl.de            fldds       -8(%r22),%farg1
21812027Sjungma@eit.uni-kl.de            fldws       -12(%r22),%farg2
21912027Sjungma@eit.uni-kl.de            fldds       -16(%r22),%farg3
22012027Sjungma@eit.uni-kl.de            copy        %r17,%r22
22112027Sjungma@eit.uni-kl.de            .CALL
22212027Sjungma@eit.uni-kl.de            bl          $$dyncall,%mrp  ; Call `userf'.
22312027Sjungma@eit.uni-kl.de            copy        %mrp,%rp
22412027Sjungma@eit.uni-kl.de
22512027Sjungma@eit.uni-kl.de            ; call: void cleanup(void *pt, void *vuserf_return)
22612027Sjungma@eit.uni-kl.de
22712027Sjungma@eit.uni-kl.de            copy        %r15,%arg0      ; `pt' is arg0 to `cleanup'.
22812027Sjungma@eit.uni-kl.de            copy        %ret0,%arg1     ; Return-value is arg1 to `cleanup'.
22912027Sjungma@eit.uni-kl.de            copy        %r18,%r22
23012027Sjungma@eit.uni-kl.de            .CALL
23112027Sjungma@eit.uni-kl.de            bl          $$dyncall,%mrp  ; Call `cleanup'.
23212027Sjungma@eit.uni-kl.de            copy        %mrp,%rp
23312027Sjungma@eit.uni-kl.de
23412027Sjungma@eit.uni-kl.de            bl,n        qt_error,%r0
23512027Sjungma@eit.uni-kl.de
23612027Sjungma@eit.uni-kl.de            .EXIT
23712027Sjungma@eit.uni-kl.de            .PROCEND
238