caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Using OCaml in a kernel
@ 2004-12-06  0:48 Jonathan Roewen
  2004-12-06  1:03 ` [Caml-list] " Sachin Shah
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Jonathan Roewen @ 2004-12-06  0:48 UTC (permalink / raw)
  To: caml-list

Hi All,

I'm developing an operating system, and I want to write as much of it
as possible in OCaml. I had hoped to use the ocamlopt compiler, and
have it target i586-elf, like my gcc (3.4.1) cross-compiler. I'm using
newlib with my cross-compiler, so I have a C library available.

However, I'm lost at how to get OCaml into the mix. Anyone able to
offer some suggestions of the sorts of things I could try?

Currently I have a single .ml file that will hopefully start all the
major tasks, and a couple of supporting C files, and I'm trying to
jump into OCaml from my main function in C-land.

Regards,

Jonathan Roewen


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-06  0:48 Using OCaml in a kernel Jonathan Roewen
@ 2004-12-06  1:03 ` Sachin Shah
  2004-12-06  8:09 ` Ville-Pertti Keinonen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Sachin Shah @ 2004-12-06  1:03 UTC (permalink / raw)
  To: caml-list

Take a look at some of the projects at
http://caml.inria.fr/humps/caml_Interfaces_with_other_languages.html. 
Camouflage and Cigen are a good point to start.  They will primarily
show you how to get OCaml working with C/C++.  The rest is up to you.

Regards,

Sachin.

On Mon, 6 Dec 2004 13:48:23 +1300, Jonathan Roewen
<jonathan.roewen@gmail.com> wrote:
> Hi All,
> 
> I'm developing an operating system, and I want to write as much of it
> as possible in OCaml. I had hoped to use the ocamlopt compiler, and
> have it target i586-elf, like my gcc (3.4.1) cross-compiler. I'm using
> newlib with my cross-compiler, so I have a C library available.
> 
> However, I'm lost at how to get OCaml into the mix. Anyone able to
> offer some suggestions of the sorts of things I could try?
> 
> Currently I have a single .ml file that will hopefully start all the
> major tasks, and a couple of supporting C files, and I'm trying to
> jump into OCaml from my main function in C-land.
> 
> Regards,
> 
> Jonathan Roewen
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-06  0:48 Using OCaml in a kernel Jonathan Roewen
  2004-12-06  1:03 ` [Caml-list] " Sachin Shah
@ 2004-12-06  8:09 ` Ville-Pertti Keinonen
  2004-12-10 21:26   ` Jonathan Roewen
  2004-12-06  9:08 ` Vincenzo Ciancia
  2004-12-06 10:00 ` Frédéric Gava
  3 siblings, 1 reply; 12+ messages in thread
From: Ville-Pertti Keinonen @ 2004-12-06  8:09 UTC (permalink / raw)
  To: Jonathan Roewen; +Cc: caml-list

On Mon, 2004-12-06 at 13:48 +1300, Jonathan Roewen wrote:

> I'm developing an operating system, and I want to write as much of it
> as possible in OCaml. I had hoped to use the ocamlopt compiler, and
> have it target i586-elf, like my gcc (3.4.1) cross-compiler. I'm using
> newlib with my cross-compiler, so I have a C library available.
> 
> However, I'm lost at how to get OCaml into the mix. Anyone able to
> offer some suggestions of the sorts of things I could try?

You should familiarize yourself with how OCaml works in detail before
you even start to plan the capabilities; it isn't going to "just work".
OCaml is going to place a lot of restrictions on what you can and can't
do (e.g. if you want to make the system pre-emptible, multithreaded or
SMP-capable you either need to make significant changes to the OCaml
runtime or exercise unusual discipline - no sharing of data except
through non-OCaml objects).

Note that you don't necessarily need to set up OCaml as a
cross-compiler.  The simplest way to start would probably be to use the
native OCaml compiler on your development platform (assuming it's also
i586-elf) to compile the OCaml parts.  The part you need to build
against newlib is the OCaml runtime (libasmrun.a) - you can do that
manually.  You can then use the -output-obj option of ocamlopt to
produce a single OCaml object, which you can link against your C
objects, newlib and your manually built libasmrun.a.

There are some changes that you're definitely going to want to make if
you're serious - rip out the signal handling and I/O altogether, modify
the memory allocation interfaces etc. - but if you have something
sufficiently functional that you can get newlib to build and work, then
you might be able to get started without doing these at first.



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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-06  0:48 Using OCaml in a kernel Jonathan Roewen
  2004-12-06  1:03 ` [Caml-list] " Sachin Shah
  2004-12-06  8:09 ` Ville-Pertti Keinonen
@ 2004-12-06  9:08 ` Vincenzo Ciancia
  2004-12-06 10:00 ` Frédéric Gava
  3 siblings, 0 replies; 12+ messages in thread
From: Vincenzo Ciancia @ 2004-12-06  9:08 UTC (permalink / raw)
  To: caml-list

On Monday 06 December 2004 01:48, Jonathan Roewen wrote:
> 01:48, 6/12/2004
>
>
> Hi All,
>
> I'm developing an operating system, and I want to write as much of it
> as possible in OCaml. I had hoped to use the ocamlopt compiler, and
> have it target i586-elf, like my gcc (3.4.1) cross-compiler. I'm
> using newlib with my cross-compiler, so I have a C library available.

You could perhaps find "linux kernel caml" interesting. It used to be 
there:

http://64.81.145.152/~arty/caml.html

but it's no longer available. However, this project is listed on the 
caml humps:

http://caml.inria.fr/humps/caml_System_programming.html

Bye

Vincenzo


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-06  0:48 Using OCaml in a kernel Jonathan Roewen
                   ` (2 preceding siblings ...)
  2004-12-06  9:08 ` Vincenzo Ciancia
@ 2004-12-06 10:00 ` Frédéric Gava
  3 siblings, 0 replies; 12+ messages in thread
From: Frédéric Gava @ 2004-12-06 10:00 UTC (permalink / raw)
  To: Jonathan Roewen, caml-list

Hi,

peraps this paper of Xavier Leroy could help you.:
http://pauillac.inria.fr/~xleroy/publi/unix-in-caml.ps.gz

Cheers,
Frédéric Gava

> Hi All,
>
> I'm developing an operating system, and I want to write as much of it
> as possible in OCaml. I had hoped to use the ocamlopt compiler, and
> have it target i586-elf, like my gcc (3.4.1) cross-compiler. I'm using
> newlib with my cross-compiler, so I have a C library available.
>
> However, I'm lost at how to get OCaml into the mix. Anyone able to
> offer some suggestions of the sorts of things I could try?
>
> Currently I have a single .ml file that will hopefully start all the
> major tasks, and a couple of supporting C files, and I'm trying to
> jump into OCaml from my main function in C-land.
>
> Regards,
>
> Jonathan Roewen
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-06  8:09 ` Ville-Pertti Keinonen
@ 2004-12-10 21:26   ` Jonathan Roewen
  2004-12-10 23:00     ` Jacques Garrigue
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Roewen @ 2004-12-10 21:26 UTC (permalink / raw)
  Cc: caml-list

I've tried manually compiling libasmrun.a, but I'm getting some
strange unresolved symbols to caml functions/declarations.

startup.o:
 caml_data_segments
 caml_code_segments
i386.o
 caml_program
 caml_apply2
 caml_apply3
fail.o:
 caml_exn_Failure (basically whole lot from the struct with these in it)
 caml_bucket_Out_of_memory
 caml_bucket_Stack_overflow
roots.o:
 caml_frametable
 caml_globals

I've used grep on the files in /asmrun, and I can't find the
definition of the symbols, just their declarations and usage. The only
file I've yet to check is fail.c, but certainly the others are using
symbols not defined anywhere I can find.

Regards,

Jonathan Roewen


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-10 21:26   ` Jonathan Roewen
@ 2004-12-10 23:00     ` Jacques Garrigue
  2004-12-14  1:43       ` Jonathan Roewen
  2004-12-28 22:35       ` Jonathan Roewen
  0 siblings, 2 replies; 12+ messages in thread
From: Jacques Garrigue @ 2004-12-10 23:00 UTC (permalink / raw)
  To: jonathan.roewen; +Cc: caml-list

From: Jonathan Roewen <jonathan.roewen@gmail.com>

> I've tried manually compiling libasmrun.a, but I'm getting some
> strange unresolved symbols to caml functions/declarations.
> 
> startup.o:
>  caml_data_segments
>  caml_code_segments
> i386.o
>  caml_program
>  caml_apply2
>  caml_apply3
> fail.o:
>  caml_exn_Failure (basically whole lot from the struct with these in it)
>  caml_bucket_Out_of_memory
>  caml_bucket_Stack_overflow
> roots.o:
>  caml_frametable
>  caml_globals

These symbols are defined at link time by the ocamlopt compiler.
You can get the assembler code defining them by using the -dstartup
option of ocamlopt while linking; it will show up in a
/tmp/camlstartup????.s file.
Note of course that some of these definitions are specific for each
program.

Jacques Garrigue


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-10 23:00     ` Jacques Garrigue
@ 2004-12-14  1:43       ` Jonathan Roewen
  2004-12-14  9:09         ` Ville-Pertti Keinonen
  2004-12-28 22:35       ` Jonathan Roewen
  1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Roewen @ 2004-12-14  1:43 UTC (permalink / raw)
  Cc: caml-list

> These symbols are defined at link time by the ocamlopt compiler.
> You can get the assembler code defining them by using the -dstartup
> option of ocamlopt while linking; it will show up in a
> /tmp/camlstartup????.s file.
> Note of course that some of these definitions are specific for each
> program.

Thanks for that =) We're getting so close ;-)

Three new undefined symbols left:

: undefined reference to `caml_compare'
: undefined reference to `caml_greaterequal'
: undefined reference to `caml_lessequal'

these are from pervasives.o, string.o, and list.o in libasmrun.a. If
can get some assembler niceties or whatever for those, then we should
hopefully be set for next phase of linker hell ;-)

Regards,

Jonathan Roewen


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-14  1:43       ` Jonathan Roewen
@ 2004-12-14  9:09         ` Ville-Pertti Keinonen
  2004-12-14 18:10           ` Jonathan Roewen
  0 siblings, 1 reply; 12+ messages in thread
From: Ville-Pertti Keinonen @ 2004-12-14  9:09 UTC (permalink / raw)
  To: Jonathan Roewen; +Cc: caml-list

On Tue, 2004-12-14 at 14:43 +1300, Jonathan Roewen wrote:

> Three new undefined symbols left:
> 
> : undefined reference to `caml_compare'
> : undefined reference to `caml_greaterequal'
> : undefined reference to `caml_lessequal'
> 
> these are from pervasives.o, string.o, and list.o in libasmrun.a. If
> can get some assembler niceties or whatever for those, then we should
> hopefully be set for next phase of linker hell ;-)

They should be in libasmrun.  These particular functions should be
coming from byterun/compare.c.



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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-14  9:09         ` Ville-Pertti Keinonen
@ 2004-12-14 18:10           ` Jonathan Roewen
  2004-12-15  2:03             ` skaller
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Roewen @ 2004-12-14 18:10 UTC (permalink / raw)
  Cc: caml-list

> > Three new undefined symbols left:
> >
> > : undefined reference to `caml_compare'
> > : undefined reference to `caml_greaterequal'
> > : undefined reference to `caml_lessequal'
> >
> > these are from pervasives.o, string.o, and list.o in libasmrun.a. If
> > can get some assembler niceties or whatever for those, then we should
> > hopefully be set for next phase of linker hell ;-)
> 
> They should be in libasmrun.  These particular functions should be
> coming from byterun/compare.c.

Turns out had to specify libasmrun on linker line twice. before and
after linking against ocaml's stdlib, str, and nums libs. Bizarre, but
it works.


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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-14 18:10           ` Jonathan Roewen
@ 2004-12-15  2:03             ` skaller
  0 siblings, 0 replies; 12+ messages in thread
From: skaller @ 2004-12-15  2:03 UTC (permalink / raw)
  To: Jonathan Roewen; +Cc: caml-list

On Wed, 2004-12-15 at 05:10, Jonathan Roewen wrote:

> Turns out had to specify libasmrun on linker line twice. before and
> after linking against ocaml's stdlib, str, and nums libs. Bizarre, but
> it works.

Unix linkers don't understand transitive closure..

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




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

* Re: [Caml-list] Using OCaml in a kernel
  2004-12-10 23:00     ` Jacques Garrigue
  2004-12-14  1:43       ` Jonathan Roewen
@ 2004-12-28 22:35       ` Jonathan Roewen
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Roewen @ 2004-12-28 22:35 UTC (permalink / raw)
  Cc: caml-list

> > I've tried manually compiling libasmrun.a, but I'm getting some
> > strange unresolved symbols to caml functions/declarations.

> These symbols are defined at link time by the ocamlopt compiler.
> You can get the assembler code defining them by using the -dstartup
> option of ocamlopt while linking; it will show up in a
> /tmp/camlstartup????.s file.
> Note of course that some of these definitions are specific for each
> program.

As I have just observed ;-) We've got some new ones, and don't know
how to resolve them. They're from the generated assembler code, and is
as follows:

camlstartup.o(.data+0x1d8): In function `caml_globals':
: undefined reference to `camlStd_exit'
camlstartup.o(.data+0x360): In function `caml_data_segments':
: undefined reference to `camlCallback__data_begin'
camlstartup.o(.data+0x364): In function `caml_data_segments':
: undefined reference to `camlCallback__data_end'
camlstartup.o(.data+0x370): In function `caml_data_segments':
: undefined reference to `camlStd_exit__data_begin'
camlstartup.o(.data+0x374): In function `caml_data_segments':
: undefined reference to `camlStd_exit__data_end'
camlstartup.o(.data+0x3c4): In function `caml_code_segments':
: undefined reference to `camlCallback__code_begin'
camlstartup.o(.data+0x3c8): In function `caml_code_segments':
: undefined reference to `camlCallback__code_end'
camlstartup.o(.data+0x3d4): In function `caml_code_segments':
: undefined reference to `camlStd_exit__code_begin'
camlstartup.o(.data+0x3d8): In function `caml_code_segments':
: undefined reference to `camlStd_exit__code_end'
camlstartup.o(.data+0x408): In function `caml_frametable':
: undefined reference to `camlCallback__frametable'
camlstartup.o(.data+0x410): In function `caml_frametable':
: undefined reference to `camlStd_exit__frametable'
make: *** [kernel.bin] Error 1

I'm at a loss on this one, unfortunately. Thought would be resolved by
stdlib.a, but doesn't want to work for me.

Jon


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

end of thread, other threads:[~2004-12-28 22:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-06  0:48 Using OCaml in a kernel Jonathan Roewen
2004-12-06  1:03 ` [Caml-list] " Sachin Shah
2004-12-06  8:09 ` Ville-Pertti Keinonen
2004-12-10 21:26   ` Jonathan Roewen
2004-12-10 23:00     ` Jacques Garrigue
2004-12-14  1:43       ` Jonathan Roewen
2004-12-14  9:09         ` Ville-Pertti Keinonen
2004-12-14 18:10           ` Jonathan Roewen
2004-12-15  2:03             ` skaller
2004-12-28 22:35       ` Jonathan Roewen
2004-12-06  9:08 ` Vincenzo Ciancia
2004-12-06 10:00 ` Frédéric Gava

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