From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 25363 invoked from network); 24 Apr 2020 02:30:17 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with UTF8ESMTPZ; 24 Apr 2020 02:30:17 -0000 Received: (qmail 3355 invoked by uid 550); 24 Apr 2020 02:30:15 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3337 invoked from network); 24 Apr 2020 02:30:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snnap-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=toyiuLGVAo15BijZe4e6HkYi1aTZ3Ei60AOpeLNiyOo=; b=mULrqyZBHfgD9fyIW7RhE/KG93Bck5VIakMWUi0H4PbBBnqKwvC99CcTOlVEpx1ius 9R8BwVW+hV+0pcKX0X4PC2jSw9YqWTtHvlWS4+48SCjL1vEOn6Vz296D2f4ZkTEn84cH LS3qwzONNeoyq27C8qz3qFEgZjDiCZq7k67STvwNozabI70NejY+ZxM4PHgGayEgG4gU 3O7IZRCUmB7rpRi8pD4nOoTAvpyio8/uGqP/n73ooDSLrQg1MJnckpi4N9cAAvkrthWY kKD2Zj7SEvENfa7u+kyZ4cIlAkm3EdNEvRQRn98B5b3H9quZ3bT5L1S/0S7lXaincUbp iG+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=toyiuLGVAo15BijZe4e6HkYi1aTZ3Ei60AOpeLNiyOo=; b=o7gYkIEi1n5ROAm9yS2304GwaqcefuGLTqFEriW0GOdpXc+QqA03ORorVtq07kT+k/ 0iuUbF2np5o4CYZnDQP1x3+eqFmKjWb6BAOnSwZo1Afzm6QG5pcZkyWXI0MrqdPtajyX q9cVJeTJHzD8gpdMazbXR7vq7+GGNWjg3ebaMPQ4jOdpsMAQ4getCVnTdsVazSGkk5mJ UyiFI2M8KCmOpWaR/xiyZ6DyCYFavsxyk0DL3OEHaVQxLFK0DjgX1nyA6Ly12HRY3qg0 +ksHalPWxCJRHgdTbyn0M7h/eiDIJxbGEKkbJa1D1kf8WBXR3Qqc8DFLWShlxUssUucG zGNA== X-Gm-Message-State: AGi0PuZopPOJ5RniOlZaRCxP/nAaXPCa7f0RsaJy4tmEnHbLK0pUICHJ ogXm/l3IwvfTY8plN+zm/twvORTzY5bBJ/RuNoNYVg== X-Google-Smtp-Source: APiQypLvm20Uc97F3HYgaMCMTWnlJ+cydUbrYdsCwV9NmKoubm4svwpSDtuvHgiVYLVIBp50nx952/hnfg+sdK8lonw= X-Received: by 2002:a67:bd07:: with SMTP id y7mr5898127vsq.109.1587695402343; Thu, 23 Apr 2020 19:30:02 -0700 (PDT) MIME-Version: 1.0 References: <20200423023255.GO11469@brightrain.aerifal.cx> <20200423163016.GW11469@brightrain.aerifal.cx> <20200424005101.GA11469@brightrain.aerifal.cx> <20200424012043.GB11469@brightrain.aerifal.cx> In-Reply-To: <20200424012043.GB11469@brightrain.aerifal.cx> From: Tom Storey Date: Fri, 24 Apr 2020 12:29:51 +1000 Message-ID: To: Rich Felker Cc: musl@lists.openwall.com Content-Type: multipart/alternative; boundary="000000000000780cb005a4002476" Subject: Re: [musl] Building for m68k --000000000000780cb005a4002476 Content-Type: text/plain; charset="UTF-8" Ah yeah. Cool. I did something similar in a recent Z80 based project, shouldn't be too difficult to do that on m68k. Only trouble I can see arising from this is enabling and disabling interrupts is privileged, and from the 68010 onwards you can't even see the status register to know if interrupts are on/off outside of supervisor mode, so you wouldn't be able to execute this code from any application running in user mode. I suppose that is why it's better trapped as an invalid instruction and emulated lower down? On Fri, Apr 24, 2020, 11:20 Rich Felker wrote: > On Fri, Apr 24, 2020 at 11:14:38AM +1000, Tom Storey wrote: > > Sorry to ask what sounds like a dumb question, but is > > > > cli;nonatomic_cas;sti > > > > basically "disable interrupts, do something equivalent to cas, re-enable > > interrupts"? > > Yeah. Basically: > > static inline int a_cas(volatile int *p, int t, int s) > { > __asm__ __volatile__("cli" : : : "memory"); > if (*p==t) *p=s; else t=*p; > __asm__ __volatile__("sti" : : : "memory"); > return t; > } > > where cli and sti are replaced with the m68k instructions for those > operations. Of course if you might have code that already has > interrupts disabled somewhere calling libc stuff, you may need to make > it save the old interrupt state and restore it rather than just sti. > See the sh2 version (runtime selected so it's in __sh_cas_imask in > src/thread/sh/atomics.s and atomic_arch.h just calls the > runtime-selected function) for an example of code doing this > > Rich > --000000000000780cb005a4002476 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ah yeah. Cool.
I did something similar in a recent Z80 based proj= ect, shouldn't be too difficult to do that on m68k.

Only trouble I can see arising from this is= enabling and disabling interrupts is privileged, and from the 68010 onward= s you can't even see the status register to know if interrupts are on/o= ff outside of supervisor mode, so you wouldn't be able to execute this = code from any application running in user mode.

=
I suppose that is why it's better trapped as an= invalid instruction and emulated lower down?


On Fri, Apr 24, 2020, 11:2= 0 Rich Felker <dali= as@libc.org> wrote:
On Fri, = Apr 24, 2020 at 11:14:38AM +1000, Tom Storey wrote:
> Sorry to ask what sounds like a dumb question, but is
>
> cli;nonatomic_cas;sti
>
> basically "disable interrupts, do something equivalent to cas, re= -enable
> interrupts"?

Yeah. Basically:

static inline int a_cas(volatile int *p, int t, int s)
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 __asm__ __volatile__("cli" : : : &quo= t;memory");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (*p=3D=3Dt) *p=3Ds; else t=3D*p;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 __asm__ __volatile__("sti" : : : &quo= t;memory");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;
}

where cli and sti are replaced with the m68k instructions for those
operations. Of course if you might have code that already has
interrupts disabled somewhere calling libc stuff, you may need to make
it save the old interrupt state and restore it rather than just sti.
See the sh2 version (runtime selected so it's in __sh_cas_imask in
src/thread/sh/atomics.s and atomic_arch.h just calls the
runtime-selected function) for an example of code doing this

Rich
--000000000000780cb005a4002476--