Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Ocaml on RaspberryPi bare-metal crashes
@ 2013-11-04 13:10 Goswin von Brederlow
  2013-11-04 13:41 ` Peter Zotov
  0 siblings, 1 reply; 4+ messages in thread
From: Goswin von Brederlow @ 2013-11-04 13:10 UTC (permalink / raw)
  To: caml-list

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

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

end of thread, other threads:[~2013-11-04 22:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-04 13:10 [Caml-list] Ocaml on RaspberryPi bare-metal crashes Goswin von Brederlow
2013-11-04 13:41 ` Peter Zotov
2013-11-04 20:38   ` Goswin von Brederlow
2013-11-04 22:38     ` David Scott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox