Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: mutex.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)mutex.fth 1.5 01/05/11 | |
43 | purpose: | |
44 | copyright: Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | headers transient | |
47 | ||
48 | : mutex-create ( -- ) \ name | |
49 | label -1 l, end-code | |
50 | ; | |
51 | ||
52 | : sema-create ( -- ) \ name | |
53 | label 1 l, end-code | |
54 | ; | |
55 | ||
56 | also assembler definitions | |
57 | hex | |
58 | ||
59 | : mutex-exit ( scr sc1 sc2 -- ) \ which? | |
60 | dup get-mid | |
61 | over ' >body origin- aligned swap set \ offset of mutex | |
62 | over base over add \ Address of mutex | |
63 | rot >r | |
64 | %g0 1 r@ sub \ -1 | |
65 | \ h# 80 swap r> casa | |
66 | h# 04 swap r> casa | |
67 | ; immediate | |
68 | ||
69 | : mutex-set ( value-reg scr -- ) \ which? | |
70 | ' >body origin- aligned over set | |
71 | dup base over add | |
72 | %g0 st | |
73 | ; immediate | |
74 | ||
75 | \ | |
76 | \ if scr = -1 then you got the lock (ie the lock was -1), otherwise | |
77 | \ it is the current owner. | |
78 | \ | |
79 | : mutex-try-enter ( scr sc1 sc2 -- scr ) \ which? | |
80 | dup get-mid | |
81 | over ' >body origin- aligned swap set \ offset of mutex | |
82 | over base over add \ Address of mutex | |
83 | rot >r | |
84 | %g0 1 r@ sub \ -1 | |
85 | h# 04 r@ rot >r r@ casa | |
86 | \ h# 80 r@ rot >r r@ casa | |
87 | r> 0 r> sra | |
88 | ; immediate | |
89 | ||
90 | : mutex-enter ( scr sc1 sc2 sc3 -- ) \ which? | |
91 | over get-mid | |
92 | 2dup move >r | |
93 | over ' >body origin- aligned swap set \ offset of mutex | |
94 | over base over add \ Address of mutex | |
95 | rot >r | |
96 | [ also assembler ] | |
97 | begin -rot | |
98 | nop nop nop \ allow a little slack time. | |
99 | 2r@ drop over move \ restore mid | |
100 | %g0 1 r@ sub \ -1 | |
101 | \ h# 80 r> rot dup >r casa | |
102 | h# 04 r> rot dup >r casa | |
103 | r@ 0 r@ sra | |
104 | r@ -1 cmp | |
105 | 0= if | |
106 | r> r> cmp | |
107 | %g0 %g0 %g0 subcc \ aquired lock | |
108 | then | |
109 | 0= until nop | |
110 | [ previous ] | |
111 | ; immediate | |
112 | ||
113 | 0 value sema-scr | |
114 | 0 value sema-sc1 | |
115 | 0 value sema-sc2 | |
116 | ||
117 | \ src contains the value to init the semaphore with | |
118 | : init-sema ( scr sc1 -- ) \ name | |
119 | to sema-sc1 | |
120 | to sema-scr | |
121 | ' >body origin- aligned sema-sc1 set \ sc1 = offset of semaphore | |
122 | sema-scr sema-sc1 base st \ store | |
123 | ; immediate | |
124 | ||
125 | : sema-atsub ( -- ) | |
126 | sema-scr base sema-scr add \ VA of semaphore | |
127 | sema-scr %g0 sema-sc1 ld | |
128 | begin | |
129 | sema-sc1 1 sema-sc2 sub | |
130 | sema-scr h# 04 sema-sc1 sema-sc2 casa | |
131 | sema-sc1 sema-sc2 %g0 subcc | |
132 | 0= until annul | |
133 | sema-scr %g0 sema-sc1 ld | |
134 | sema-sc1 1 sema-scr sub | |
135 | ; | |
136 | ||
137 | \ decremented value is returned in scr. | |
138 | : decr-sema ( scr sc1 sc2 -- ) \ name | |
139 | to sema-sc2 | |
140 | to sema-sc1 | |
141 | to sema-scr | |
142 | ' >body origin- aligned sema-scr set \ scr = offset of semaphore | |
143 | sema-atsub | |
144 | ; immediate | |
145 | ||
146 | : wait-sema ( scr sc1 sc2 -- ) \ name | |
147 | to sema-sc2 | |
148 | to sema-sc1 | |
149 | to sema-scr | |
150 | ' >body origin- aligned sema-scr set \ scr = offset of semaphore | |
151 | sema-scr >r | |
152 | sema-atsub | |
153 | begin | |
154 | sema-scr %g0 %g0 subcc | |
155 | 0= until annul | |
156 | r> base sema-scr ld | |
157 | ; immediate | |
158 | ||
159 | resident | |
160 | previous definitions |