summaryrefslogtreecommitdiff
path: root/ext/systemc/src/sysc/qt/md/hppa.s
blob: 84d8e875b16b16f5bf139272e28a786a2e87d3c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
; pa-risc.s -- assembly support.

; QuickThreads -- Threads-building toolkit.
; Copyright (c) 1993 by David Keppel
;
; Permission to use, copy, modify and distribute this software and
; its documentation for any purpose and without fee is hereby
; granted, provided that the above copyright notice and this notice
; appear in all copies.  This software is provided as a
; proof-of-concept and for demonstration purposes; there is no
; representation about the suitability of this software for any
; purpose.

; This file (pa-risc.s) is part of the port of QuickThreads for
; PA-RISC 1.1 architecture.  This file implements context switches
; and thread startup.  It was written in 1994 by Uwe Reder
; (`uereder@cip.informatik.uni-erlangen.de') for the Operating
; Systems Department (IMMD4) at the University of Erlangen/Nuernberg
; Germany.


; Callee saves general registers gr3..gr18,
;              floating-point registers fr12..fr21.

            .CODE

            .IMPORT $$dyncall, MILLICODE
            .IMPORT qt_error, CODE

            .EXPORT qt_blocki, ENTRY
            .EXPORT qt_block, ENTRY
            .EXPORT qt_abort, ENTRY
            .EXPORT qt_start, ENTRY
            .EXPORT qt_vstart, ENTRY


; arg0: ptr to function (helper) to call once curr is suspended
;       and control is on arg3's stack.
; arg1: 1'th arg to *arg0.
; arg2: 2'th arg to *arg0.
; arg3: sp of new thread.

qt_blocki
            .PROC
            .CALLINFO   CALLER, FRAME=0, SAVE_RP, ENTRY_GR=18
            .ENTRY

            stw         %rp,-20(%sp)    ; save rp to old frame-marker

            stwm        %r3,128(%sp)    ; save callee-saves general registers
            stw         %r4,-124(%sp)
            stw         %r5,-120(%sp)
            stw         %r6,-116(%sp)
            stw         %r7,-112(%sp)
            stw         %r8,-108(%sp)
            stw         %r9,-104(%sp)
            stw         %r10,-100(%sp)
            stw         %r11,-96(%sp)
            stw         %r12,-92(%sp)
            stw         %r13,-88(%sp)
            stw         %r14,-84(%sp)
            stw         %r15,-80(%sp)
            stw         %r16,-76(%sp)
            stw         %r17,-72(%sp)
            stw         %r18,-68(%sp)

qt_abort
            copy        %arg0,%r22      ; helper to be called by $$dyncall
            copy        %sp,%arg0       ; pass current sp as arg0 to helper
            copy        %arg3,%sp       ; set new sp

            .CALL
            bl          $$dyncall,%mrp  ; call helper
            copy        %mrp,%rp

            ldw         -68(%sp),%r18   ; restore general registers
            ldw         -72(%sp),%r17
            ldw         -76(%sp),%r16
            ldw         -80(%sp),%r15
            ldw         -84(%sp),%r14
            ldw         -88(%sp),%r13
            ldw         -92(%sp),%r12
            ldw         -96(%sp),%r11
            ldw         -100(%sp),%r10
            ldw         -104(%sp),%r9
            ldw         -108(%sp),%r8
            ldw         -112(%sp),%r7
            ldw         -116(%sp),%r6
            ldw         -120(%sp),%r5
            ldw         -124(%sp),%r4

            ldw         -148(%sp),%rp   ; restore return-pointer

            bv          %r0(%rp)        ; return to caller
            ldwm        -128(%sp),%r3

            .EXIT
            .PROCEND


qt_block
            .PROC
            .CALLINFO   CALLER, FRAME=0, SAVE_RP, ENTRY_FR=21
            .ENTRY

            stw         %rp,-20(%sp)    ; save rp to old frame-marker

            fstds,ma    %fr12,8(%sp)    ; save callee-saves float registers
            fstds,ma    %fr13,8(%sp)
            fstds,ma    %fr14,8(%sp)
            fstds,ma    %fr15,8(%sp)
            fstds,ma    %fr16,8(%sp)
            fstds,ma    %fr17,8(%sp)
            fstds,ma    %fr18,8(%sp)
            fstds,ma    %fr19,8(%sp)
            fstds,ma    %fr20,8(%sp)
            fstds,ma    %fr21,8(%sp)

            .CALL
            bl          qt_blocki,%rp
            ldo         48(%sp),%sp

            ldo         -48(%sp),%sp

            fldds,mb    -8(%sp),%fr21   ; restore callee-saves float registers
            fldds,mb    -8(%sp),%fr20
            fldds,mb    -8(%sp),%fr19
            fldds,mb    -8(%sp),%fr18
            fldds,mb    -8(%sp),%fr17
            fldds,mb    -8(%sp),%fr16
            fldds,mb    -8(%sp),%fr15
            fldds,mb    -8(%sp),%fr14
            fldds,mb    -8(%sp),%fr13

            ldw         -28(%sp),%rp    ; restore return-pointer
            
            bv          %r0(%rp)        ; return to caller.
            fldds,mb    -8(%sp),%fr12
            
            .EXIT
            .PROCEND


qt_start
            .PROC
            .CALLINFO   CALLER, FRAME=0
            .ENTRY

            copy        %r18,%arg0      ; set user arg `pu'.
            copy        %r17,%arg1      ; ... user function pt.
            copy        %r16,%arg2      ; ... user function userf.
                                        ; %r22 is a caller-saves register
            copy        %r15,%r22       ; function to be called by $$dyncall

            .CALL                       ; in=%r22
            bl          $$dyncall,%mrp  ; call `only'.
            copy        %mrp,%rp
            
            bl,n        qt_error,%r0    ; `only' erroniously returned.

            .EXIT
            .PROCEND


; Varargs
;
; First, call `startup' with the `pt' argument.
;
; Next, call the user's function with all arguments.
; We don't know whether arguments are integers, 32-bit floating-points or
; even 64-bit floating-points, so we reload all the registers, possibly
; with garbage arguments.  The thread creator provided non-garbage for
; the arguments that the callee actually uses, so the callee never gets
; garbage.
;
;            -48    -44    -40    -36    -32
;             | arg3 | arg2 | arg1 | arg0 |
;             -----------------------------
; integers:     arg3   arg2   arg1   arg0
; 32-bit fps:  farg3  farg2  farg1  farg0
; 64-bit fps:  <---farg3-->  <---farg1-->
;
; Finally, call `cleanup' with the `pt' argument and with the return value
; from the user's function.  It is an error for `cleanup' to return.

qt_vstart
            .PROC
            .CALLINFO   CALLER, FRAME=0
            .ENTRY

            ; Because the startup function may damage the fixed arguments
            ; on the stack (PA-RISC Procedure Calling Conventions Reference
            ; Manual, 2.4 Fixed Arguments Area), we allocate a seperate
            ; stack frame for it.
            ldo         64(%sp),%sp

            ; call: void startup(void *pt)

            copy        %r15,%arg0      ; `pt' is arg0 to `startup'.
            copy        %r16,%r22
            .CALL
            bl          $$dyncall,%mrp  ; Call `startup'.
            copy        %mrp,%rp

            ldo         -64(%sp),%sp

            ; call: void *qt_vuserf_t(...)

            ldw         -36(%sp),%arg0  ; Load args to integer registers.
            ldw         -40(%sp),%arg1
            ldw         -44(%sp),%arg2
            ldw         -48(%sp),%arg3
            ; Index of fld[w|d]s only ranges from -16 to 15, so we
            ; take r22 to be our new base register.
            ldo         -32(%sp),%r22
            fldws       -4(%r22),%farg0 ; Load args to floating-point registers.
            fldds       -8(%r22),%farg1
            fldws       -12(%r22),%farg2
            fldds       -16(%r22),%farg3
            copy        %r17,%r22
            .CALL
            bl          $$dyncall,%mrp  ; Call `userf'.
            copy        %mrp,%rp

            ; call: void cleanup(void *pt, void *vuserf_return)

            copy        %r15,%arg0      ; `pt' is arg0 to `cleanup'.
            copy        %ret0,%arg1     ; Return-value is arg1 to `cleanup'.
            copy        %r18,%r22
            .CALL
            bl          $$dyncall,%mrp  ; Call `cleanup'.
            copy        %mrp,%rp

            bl,n        qt_error,%r0

            .EXIT
            .PROCEND