mailing list of musl libc
 help / color / mirror / code / Atom feed
* Bare metal progress and an oddity.
@ 2014-04-27 17:37 Richard Pennington
  2014-04-27 18:00 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Pennington @ 2014-04-27 17:37 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

As part of my quixotic quest to run musl on ARM bare metal I've started 
to handle interrupts and an ARM timer to implement the clock_* functions 
to prepare for pre-emptive scheduling of pthread_create'd threads. The 
current sources are here:
http://ellcc.org/viewvc/svn/ellcc/trunk/baremetal/arm/

An oddity: If I use printf() to print out values in an interrupt handler 
it sort of works. The format string prints perfectly, but it seems that 
the va_arg values are getting messed up. The stack is large enough, fp 
and sp are sane. Am I missing something in pop_arg() that is causing 
this? Come to think of it, do I have to insure a certain stack 
alignment, for example? Most of the messed up values are "long long".

Any thoughts appreciated.

-Rich

[-- Attachment #2: Type: text/html, Size: 1170 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bare metal progress and an oddity.
  2014-04-27 17:37 Bare metal progress and an oddity Richard Pennington
@ 2014-04-27 18:00 ` Rich Felker
  2014-04-27 18:00   ` Richard Pennington
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2014-04-27 18:00 UTC (permalink / raw)
  To: musl

On Sun, Apr 27, 2014 at 12:37:13PM -0500, Richard Pennington wrote:
> As part of my quixotic quest to run musl on ARM bare metal I've
> started to handle interrupts and an ARM timer to implement the
> clock_* functions to prepare for pre-emptive scheduling of
> pthread_create'd threads. The current sources are here:
> http://ellcc.org/viewvc/svn/ellcc/trunk/baremetal/arm/
> 
> An oddity: If I use printf() to print out values in an interrupt
> handler it sort of works. The format string prints perfectly, but it
> seems that the va_arg values are getting messed up. The stack is
> large enough, fp and sp are sane. Am I missing something in
> pop_arg() that is causing this? Come to think of it, do I have to
> insure a certain stack alignment, for example? Most of the messed up
> values are "long long".
> 
> Any thoughts appreciated.

Yes, ARM EABI requires the stack to be aligned to at least an 8-byte
boundary (maybe 16 but I think 8 is all that's required). If your
stack is only aligned to 4 bytes, this will mess things up badly.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bare metal progress and an oddity.
  2014-04-27 18:00 ` Rich Felker
@ 2014-04-27 18:00   ` Richard Pennington
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Pennington @ 2014-04-27 18:00 UTC (permalink / raw)
  To: musl; +Cc: Rich Felker

On 04/27/2014 01:00 PM, Rich Felker wrote:
> On Sun, Apr 27, 2014 at 12:37:13PM -0500, Richard Pennington wrote:
>> As part of my quixotic quest to run musl on ARM bare metal I've
>> started to handle interrupts and an ARM timer to implement the
>> clock_* functions to prepare for pre-emptive scheduling of
>> pthread_create'd threads. The current sources are here:
>> http://ellcc.org/viewvc/svn/ellcc/trunk/baremetal/arm/
>>
>> An oddity: If I use printf() to print out values in an interrupt
>> handler it sort of works. The format string prints perfectly, but it
>> seems that the va_arg values are getting messed up. The stack is
>> large enough, fp and sp are sane. Am I missing something in
>> pop_arg() that is causing this? Come to think of it, do I have to
>> insure a certain stack alignment, for example? Most of the messed up
>> values are "long long".
>>
>> Any thoughts appreciated.
> Yes, ARM EABI requires the stack to be aligned to at least an 8-byte
> boundary (maybe 16 but I think 8 is all that's required). If your
> stack is only aligned to 4 bytes, this will mess things up badly.
>
> Rich

Rich,

You're absolutely right. As I was writing my initial email I thought of 
the stack alignment. It turns out that my idle thread pushed 12 bytes on 
the stack making it unaligned. The idle thread is a leaf function (of 
course) so I guess clang didn't feel the need to keep the stack aligned.
After fixing the alignment, interrupt printf() works fine.

-Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-27 18:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-27 17:37 Bare metal progress and an oddity Richard Pennington
2014-04-27 18:00 ` Rich Felker
2014-04-27 18:00   ` Richard Pennington

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).