mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Patrick Oppenlander <patrick.oppenlander@gmail.com>
To: Jesse DeGuire <jesse.a.deguire@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Musl on Cortex-M Devices
Date: Wed, 6 Jan 2021 15:01:05 +1100	[thread overview]
Message-ID: <CAEg67Gk4=pBXzah81uUWUJR21OReq-uUgPgYMBpZC6LHCOVTRQ@mail.gmail.com> (raw)
In-Reply-To: <CALqyXLh0zwXPzvoBLaKx=jQx1eiQ22S2CSjsN47FntJAryst4w@mail.gmail.com>

On Wed, Jan 6, 2021 at 2:25 PM Jesse DeGuire <jesse.a.deguire@gmail.com> wrote:
> >
> > Sorry, I missed this reply.
> >
> > qemu-user refuses to translate the instruction because cp15 is not
> > implemented on armv7-m, exactly the same issue as is being discussed
> > here. If you run the same executable but tell qemu to emulate an A
> > profile core instead it happily runs it.
> >
> > Linux will probably kill the executable with SIGILL or something like
> > that (I haven't tried, just guessing).
> >
> > It's related to this discussion as changing musl to use the syscall
> > will likely result in qemu-user working too.
> >
> > I would personally prefer to see a solution which doesn't use the
> > syscall. It's possible to implement the trap-and-emulate much more
> > efficiently than the syscall as it can quite easily be done without
> > preserving any more registers than the core pushes on exception entry
> > anyway. https://github.com/apexrtos/apex/blob/master/sys/arch/arm/v7m/emulate.S
> > is what I came up with. That implementation could be even tighter as
> > it can never run from handler mode, so the stack detection at the
> > beginning is unnecessary. However, I haven't considered v6-m or v8-m.
> >
> > trap-and-emulate also gracefully degrades when running the same
> > executable on A vs M cores.
> >
> > Patrick
>
> Any thoughts on what's shown in this patch? For your RTOS and v7m/v8m,
> I'm thinking you'd be able to get the behavior you want by setting the
> HWCAP_TLS flag early in your startup code. For my purposes, I plan to
> use the syscall because I intend to eventually make a "baremetal" arch
> in Musl that turns syscalls into simple function calls. Therefore, I'd
> clear the flag in my startup code.

What you've proposed (using HWCAP_TLS) sounds good to me. Apex tries
very hard to look like Linux to userspace, so anything that works for
Linux will work for it. As an aside, I also use a forked and reduced
musl as the kernel libc - a baremetal target could be handy there.

It might be nice to have a configure option to disable the syscall
fallback completely (compile time constant test of some kind?) to
allow inlining of the mrc instruction. If such an executable ever
tried to run on an unsupported platform it would be killed with an
invalid instruction exception.

If it's acceptable to have that type of configure-time tuning we can
also disable mutex & rwlock spins (set spins to 0) as an optimisation
for uniprocessor targets.

Patrick

  reply	other threads:[~2021-01-06  4:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 23:43 Jesse DeGuire
2020-12-17  0:23 ` Rich Felker
2020-12-17  4:55   ` Patrick Oppenlander
2020-12-17  5:10     ` Patrick Oppenlander
2020-12-18  7:17       ` Jesse DeGuire
2020-12-22 21:43         ` Patrick Oppenlander
2021-01-06  3:24           ` Jesse DeGuire
2021-01-06  4:01             ` Patrick Oppenlander [this message]
2021-01-13 23:51               ` Jesse DeGuire
2020-12-18  7:15   ` Jesse DeGuire
2020-12-18 17:30     ` Rich Felker
2020-12-21 23:58       ` Jesse DeGuire
2020-12-22  1:39         ` Rich Felker
2020-12-18 19:38   ` Markus Wichmann
2020-12-18 20:34     ` Rich Felker
2020-12-22  0:00       ` Jesse DeGuire
2020-12-22  1:40         ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEg67Gk4=pBXzah81uUWUJR21OReq-uUgPgYMBpZC6LHCOVTRQ@mail.gmail.com' \
    --to=patrick.oppenlander@gmail.com \
    --cc=jesse.a.deguire@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).