[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: [Caml-list] Ocaml on RaspberryPi bare-metal crashes



> From: Goswin von Brederlow <goswin-v-b at web.de>
> Subject: [Caml-list] Ocaml on RaspberryPi bare-metal crashes
> Date: 4 November 2013 08:10:15 GMT-5
> To: caml-list at inria.fr
> Reply-To: Goswin von Brederlow <goswin-v-b at web.de>
> 
> 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

I since solve the crash. It was actualy 2 problems:

1) the GC uses floating point operations and I didn't have the FPU enabled.

2) malloc() needs to return blocks 8 byte aligned (not 4) or storing
   64bit values crashes.

After that ocaml works (limited to the serial for I/O).

MfG
        Goswin



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.