From owner-freebsd-smp Mon Dec 2 23:21:51 1996 Return-Path: owner-smp Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA16073 for smp-outgoing; Mon, 2 Dec 1996 23:21:51 -0800 (PST) Received: from spinner.DIALix.COM (root@spinner.DIALix.COM [192.203.228.67]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id XAA16068 for ; Mon, 2 Dec 1996 23:21:47 -0800 (PST) Received: from spinner.DIALix.COM (peter@localhost.DIALix.oz.au [127.0.0.1]) by spinner.DIALix.COM (8.8.3/8.8.3) with ESMTP id PAA01103; Tue, 3 Dec 1996 15:21:33 +0800 (WST) Message-Id: <199612030721.PAA01103@spinner.DIALix.COM> To: Chris Csanady cc: freebsd-smp@freebsd.org Subject: Re: spin locks... In-reply-to: Your message of "Tue, 03 Dec 1996 00:54:40 CST." <199612030654.AAA12221@friley216.res.iastate.edu> Date: Tue, 03 Dec 1996 15:21:32 +0800 From: Peter Wemm Sender: owner-smp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Chris Csanady wrote: > pushl %eax > pushl %ecx > pushl %edx > movl _smp_active, %eax > cmpl $0, %eax > jne 1f > jmp 4 > 1: movl 4(%esp), %edx > movl $1, %ecx > 2: lock > cmpxchg %ecx, (%edx) > je 3f > jmp 4 > 3: cmpl %ecx, (%edx) [ ... ] You've been bitten by Intel's assembler syntax.... cmpxchg actually has three arguments, %eax is implicit. The way it really works.. Given: lock; cmpxchg %ecx, (%edx), what happens is that if %eax == (%edx), it exchanges (%edx) with %ecx. ie: %eax is what you hope that it is currently set to, and %ecx is the new value if you don't loose a race. -Peter