Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: [Caml-list] Ocaml on RaspberryPi bare-metal crashes
Date: Mon, 4 Nov 2013 14:10:15 +0100	[thread overview]
Message-ID: <20131104131015.GA27957@frosties> (raw)

Hi,

over the weekend I wrote some boot code and glue to make ocaml run
bare-metal on a RaspberryPi. Here is what I did:

- Compile ocaml source into a single object file:
    ocamlopt -output-obj -o prog.o foo.ml

- Compile a boot.S and main.c file providing the hardware interface
  and libc (libm, libdl) functions needed by ocaml. A lot of stuff is
  just stubs that will return errors or nonsense (like all the math
  functions return 0). But I have memory and print functions working.
  The main() initializes the hardware and calls caml_startup().

- Add libasmrun.a and libgcc.a from the system.

- Link it all together and objcopy to binary to get a kernel image for
  booting.

Everything compiles and links without errors. And the kernel boots and
outputs its startup messages before starting ocaml. But then is where
things get tricky:

---- foo.ml ----
let () = ()
----------------
Ocaml starts and finishes and the kernel outputs its finished message.
Everything seems to be working fine.

---- foo.ml ----
let () = Printf.printf "Hello World\n%!"
----------------
Ocaml does its startup (calls the same libc functions as before) but
then the system resets before printing "Hello World\n". I don't see
any sprintf() or fputs() or fwrite() calls.

I'm not sure why it crashes and I haven't setup exception handlers yet
that would tell me what or where exactly it crashes. But the only new
bits are the initialization of the printf module and the printf call
itself. Must be one or the other.

Does anyone want to take a blind guess what could be wrong?

One idea I got while writing the email is that maybe the stack is the
problem. I only setup a 16k stack at boot. Does ocaml create its own
stack or should I make the stack larger? Would a simple printf exceed
16k stack?

MfG
	Goswin

             reply	other threads:[~2013-11-04 13:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 13:10 Goswin von Brederlow [this message]
2013-11-04 13:41 ` Peter Zotov
2013-11-04 20:38   ` Goswin von Brederlow
2013-11-04 22:38     ` David Scott

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=20131104131015.GA27957@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox