Date: Wed, 6 Jan 2021 15:01:05 +1100 From: Patrick Oppenlander <patrick.oppenlander@...il.com> To: Jesse DeGuire <jesse.a.deguire@...il.com> Cc: musl@...ts.openwall.com Subject: Re: Musl on Cortex-M Devices On Wed, Jan 6, 2021 at 2:25 PM Jesse DeGuire <jesse.a.deguire@...il.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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.