1/ 2/ Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3/ Use is subject to license terms. 4/ 5 6/ XX64 - fix me - this is a copy of the x86 version 7 8 .ident "%Z%%M% %I% %E% SMI" 9 10/ -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 11/ 12/ The contents of this file are subject to the Mozilla Public 13/ License Version 1.1 (the "License"); you may not use this file 14/ except in compliance with the License. You may obtain a copy of 15/ the License at http://www.mozilla.org/MPL/ 16/ 17/ Software distributed under the License is distributed on an "AS 18/ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 19/ implied. See the License for the specific language governing 20/ rights and limitations under the License. 21/ 22/ The Original Code is the Netscape Portable Runtime (NSPR). 23/ 24/ The Initial Developer of the Original Code is Netscape 25/ Communications Corporation. Portions created by Netscape are 26/ Copyright (C) 1998-2000 Netscape Communications Corporation. All 27/ Rights Reserved. 28/ 29/ Contributor(s): 30/ 31/ Alternatively, the contents of this file may be used under the 32/ terms of the GNU General Public License Version 2 or later (the 33/ "GPL"), in which case the provisions of the GPL are applicable 34/ instead of those above. If you wish to allow use of your 35/ version of this file only under the terms of the GPL and not to 36/ allow others to use your version of this file under the MPL, 37/ indicate your decision by deleting the provisions above and 38/ replace them with the notice and other provisions required by 39/ the GPL. If you do not delete the provisions above, a recipient 40/ may use your version of this file under either the MPL or the 41/ GPL. 42/ 43 44 .text 45 46 .globl getedi 47getedi: 48 movl %edi,%eax 49 ret 50 .type getedi,@function 51 .size getedi,.-getedi 52 53 .globl setedi 54setedi: 55 movl 4(%rsp),%edi 56 ret 57 .type setedi,@function 58 .size setedi,.-setedi 59 60 .globl __MD_FlushRegisterWindows 61 .globl _MD_FlushRegisterWindows 62 63__MD_FlushRegisterWindows: 64_MD_FlushRegisterWindows: 65 66 ret 67 68/ 69/ sol_getsp() 70/ 71/ Return the current sp (for debugging) 72/ 73 .globl sol_getsp 74sol_getsp: 75 movl %esp, %eax 76 ret 77 78/ 79/ sol_curthread() 80/ 81/ Return a unique identifier for the currently active thread. 82/ 83 .globl sol_curthread 84sol_curthread: 85 movl %ecx, %eax 86 ret 87 88/ PRInt32 _MD_AtomicIncrement(PRInt32 *val) 89/ 90/ Atomically increment the integer pointed to by 'val' and return 91/ the result of the increment. 92/ 93 .text 94 .globl _MD_AtomicIncrement 95 .align 4 96_MD_AtomicIncrement: 97 movl 4(%rsp), %ecx 98 movl $1, %eax 99 lock 100 xaddl %eax, (%rcx) 101 incl %eax 102 ret 103 104/ PRInt32 _MD_AtomicDecrement(PRInt32 *val) 105/ 106/ Atomically decrement the integer pointed to by 'val' and return 107/ the result of the decrement. 108/ 109 .text 110 .globl _MD_AtomicDecrement 111 .align 4 112_MD_AtomicDecrement: 113 movl 4(%rsp), %ecx 114 movl $-1, %eax 115 lock 116 xaddl %eax, (%rcx) 117 decl %eax 118 ret 119 120/ PRInt32 _MD_AtomicSet(PRInt32 *val, PRInt32 newval) 121/ 122/ Atomically set the integer pointed to by 'val' to the new 123/ value 'newval' and return the old value. 124/ 125/ An alternative implementation: 126/ .text 127/ .globl _MD_AtomicSet 128/ .align 4 129/_MD_AtomicSet: 130/ movl 4(%rsp), %ecx 131/ movl 8(%rsp), %edx 132/ movl (%rcx), %eax 133/retry: 134/ lock 135/ cmpxchgl %edx, (%rcx) 136/ jne retry 137/ ret 138/ 139 .text 140 .globl _MD_AtomicSet 141 .align 4 142_MD_AtomicSet: 143 movl 4(%rsp), %ecx 144 movl 8(%rsp), %eax 145 lock 146 xchgl %eax, (%rcx) 147 ret 148 149/ PRInt32 _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val) 150/ 151/ Atomically add 'val' to the integer pointed to by 'ptr' 152/ and return the result of the addition. 153/ 154 .text 155 .globl _MD_AtomicAdd 156 .align 4 157_MD_AtomicAdd: 158 movl 4(%rsp), %ecx 159 movl 8(%rsp), %eax 160 movl %eax, %edx 161 lock 162 xaddl %eax, (%rcx) 163 addl %edx, %eax 164 ret 165 166/ 167/ PR_StackPush(listp, elementp) 168/ 169/ Atomically push ElementP onto linked list ListP. 170/ 171 .text 172 .globl PR_StackPush 173 .align 4 174PR_StackPush: 175 movl 4(%rsp), %ecx 176 movl $-1,%eax 177pulock: 178/ Already locked? 179 cmpl %eax,(%rcx) 180 je pulock 181 182/ Attempt to lock it 183 lock 184 xchgl %eax, (%rcx) 185 186/ Did we set the lock? 187 cmpl $-1, %eax 188 je pulock 189 190/ We now have the lock. Update pointers 191 movl 8(%rsp), %edx 192 movl %eax, (%rdx) 193 movl %edx, (%rcx) 194 195/ Done 196 ret 197 198 199/ 200/ elementp = PR_StackPop(listp) 201/ 202/ Atomically pop ElementP off linked list ListP 203/ 204 .text 205 .globl PR_StackPop 206 .align 4 207PR_StackPop: 208 movl 4(%rsp), %ecx 209 movl $-1, %eax 210polock: 211/ Already locked? 212 cmpl %eax, (%rcx) 213 je polock 214 215/ Attempt to lock it 216 lock 217 xchgl %eax, (%rcx) 218 219/ Did we set the lock? 220 cmpl $-1, %eax 221 je polock 222 223/ We set the lock so now update pointers 224 225/ Was it empty? 226 movl $0, %edx 227 cmpl %eax,%edx 228 je empty 229 230/ Get element "next" pointer 231 movl (%rax), %edx 232 233/ Write NULL to the element "next" pointer 234 movl $0, (%rax) 235 236empty: 237/ Put elements previous "next" value into listp 238/ NOTE: This also unlocks the listp 239 movl %edx, (%rcx) 240 241/ Return previous listp value (already in eax) 242 ret 243